forked from horchi/linux-p4d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc2tst.c
57 lines (41 loc) · 1.17 KB
/
c2tst.c
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
#include "unistd.h"
#include <vector>
#include "service.h"
#include "p4io.h"
//***************************************************************************
// main
//***************************************************************************
int main()
{
const char* ttyDevice = "/dev/ttyUSB1";
int status;
std::vector<Fs::Parameter>::iterator it;
P4Packet* tlg = new P4Packet();
logstdout = yes;
if (tlg->open(ttyDevice) != success)
{
tell(0, "Opening serial line '%s' failed, aborting", ttyDevice);
return 1;
}
tell(0, "Opening serial line '%s' succeeded", ttyDevice);
while (true)
{
// try serial read
if ((status = tlg->read()) != success)
{
tell(0, "Reading serial line failed with %d, try reopen in 5 seconds");
sleep(5);
tlg->reopen(ttyDevice);
continue;
}
// process parameters ..
for (it = tlg->getParameters()->begin(); it != tlg->getParameters()->end(); it++)
{
Fs::Parameter p = *it;
if (*p.name)
tell(eloAlways, "(%2d) %-17s: %.2f %s", p.index, p.name, p.value, p.unit);
}
}
tlg->close();
return success;
}