-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_example.cc
105 lines (82 loc) · 2.45 KB
/
main_example.cc
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
*
*
* @author Laurent Winkler based on work by Valentin Bourqui
* @date May 2015
* @brief Example executable for the POPWIN project: The main routine shows the usage of the different C++ class of the POPWIN project.
*
*
*/
// #include <unistd.h>
// #include <termios.h>
// #include <map>
#include <fstream>
#include "POPSensor.ph"
using namespace std;
int main(int argc, char** argv)
{
if(argc != 2)
{
cout << "usage: popcrun <obj.map> ./main_example resource.json" << popcendl;
exit(0);
}
// Input a list of commands
cout << popcendl;
cout << "=======================================================================================" <<popcendl;
cout << " POPWin demo: Launching the demo " <<popcendl;
cout << "=======================================================================================" <<popcendl;
try
{
POPSensor popSensor("localhost", argv[1],0);
sleep(3);
cout<<"\nAsk the list of available commands (command 0)"<<popcendl;
popSensor.Broadcast(PUB_COMMAND, 0);
sleep(3);
cout<<"\nBroadcast a command that will generate data (command 2, 3 and 4)"<<popcendl;
popSensor.Broadcast(PUB_COMMAND, 2);
popSensor.Broadcast(PUB_COMMAND, 3);
popSensor.Broadcast(PUB_COMMAND, 4);
sleep(3);
cout<<"\nBlink all leds once"<<popcendl;
for(int i = 0 ; i < 3 ; i++)
{
popSensor.Broadcast(PUB_LED, i);
sleep(1);
popSensor.Broadcast(PUB_LED, i);
}
sleep(3);
cout<<"\nAsk for temperature readings (command 1) three times"<<popcendl;
popSensor.Broadcast(PUB_COMMAND, 1);
sleep(1);
popSensor.Broadcast(PUB_COMMAND, 1);
sleep(1);
popSensor.Broadcast(PUB_COMMAND, 1);
sleep(3);
cout<<"\nPrint the gathered data to screen"<<popcendl;
POPSensorData data = popSensor.Gather();
data.Print();
cout<<"\nTemperature average is "<<data.Reduce<double>(MSR_TEMPERATURE, POPSensorData::POPReduceF::aver)<< popcendl;
sleep(3);
cout<<"\nPrint the gathered data to out/data_demo.csv"<<popcendl;
ofstream of;
of.open("out/data_demo.csv");
of << "Time, Id, Measurement, Unit, data\n";
data.PrintToFile(of);
of.close();
sleep(3);
cout<<"\nClear data"<<popcendl;
popSensor.Clear();
cout<<"End of popwin main"<<popcendl;
}
catch(std::exception &e)
{
cerr<<"Exception caught in popwin main loop: " << e.what() << popcendl;
return 1;
}
catch(...)
{
cerr<<"Exception caught in popwin main loop" << popcendl;
return 1;
}
return 0;
}