forked from manio/skymax-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
89 lines (76 loc) · 2.22 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <thread>
#include "main.h"
#include "tools.h"
#include <pthread.h>
#include <signal.h>
cSkymax *ups = NULL;
atomic_bool ups_status_changed(false);
atomic_bool ups_data_changed(false);
int main()
{
float voltage_grid;
float freq_grid;
float voltage_out;
float freq_out;
int load_va;
int load_watt;
int load_percent;
int voltage_bus;
float voltage_batt;
int batt_charge_current;
int batt_capacity;
int temp_heatsink;
int pv1;
float pv2;
float scc;
int batt_discharge_current;
bool ups_status_changed(false);
ups = new cSkymax;
ups->runMultiThread();
lprintf("MAIN LOOP");
while (true)
{
if (ups_status_changed)
{
string *mode = ups->GetMode();
if (mode)
{
lprintf("SKYMAX: %s", mode->c_str());
delete mode;
}
ups_status_changed = false;
}
if (ups_data_changed)
{
ups_data_changed = false;
string *reply = ups->GetStatus();
if (reply)
{
//parse and display values
sscanf(reply->c_str(), "%f %f %f %f %d %d %d %d %f %d %d %d %d %f %f %d", &voltage_grid, &freq_grid, &voltage_out, &freq_out, &load_va, &load_watt, &load_percent, &voltage_bus, &voltage_batt, &batt_charge_current, &batt_capacity, &temp_heatsink, &pv1, &pv2, &scc, &batt_discharge_current);
printf("\tAC Grid voltage: %.1f\n", voltage_grid);
printf("\tAC Grid frequency: %.1f\n", freq_grid);
printf("\tAC out voltage: %.1f\n", voltage_out);
printf("\tAC out frequency: %.1f\n", freq_out);
printf("\tLoad [%]: %d\n", load_percent);
printf("\tLoad [W]: %d\n", load_watt);
printf("\tLoad [VA]: %d\n", load_va);
printf("\tBus voltage: %d\n", voltage_bus);
printf("\tHeatsink temperature: %d\n", temp_heatsink);
printf("\tBattery capacity [%]: %d\n", batt_capacity);
printf("\tBattery voltage: %.2f\n", voltage_batt);
printf("\tBattery charge current [A]: %d\n", batt_charge_current);
printf("\tBattery discharge current [A]: %d\n", batt_discharge_current);
delete reply;
}
}
sleep(1);
}
lprintf("MAIN LOOP END");
if (ups)
delete ups;
return 0;
}