-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip.cpp
64 lines (50 loc) · 1.25 KB
/
ip.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
#include<unistd.h>
#include<DataStream.hpp>
#include<VSDataConverter.hpp>
#include"ESPProtocol.hpp"
using namespace VERITAS;
using namespace VTracking;
using namespace VMessaging;
using namespace MotionControl;
int main(int argc, char** argv)
{
const char* program = *argv;
argv++,argc--;
if(argc!=1)
{
std::cerr << "Usage: " << program << " port" << '\n';
exit(EXIT_FAILURE);
}
const char* port = *argv;
argv++,argc--;
DataStream* ds = 0;
try
{
ds = ESPProtocol::makeSerialDataStream(port);
ESPProtocol esp(ds);
esp.clearAllErrorCodes();
while(1)
{
uint8_t port_a_val;
uint8_t port_b_val;
uint8_t port_c_val;
esp.getDIOPortState(port_a_val, port_b_val, port_c_val);
for(unsigned ibit=0;ibit<8;ibit++)
std::cout << (((port_a_val>>(7-ibit))&0x01)?1:0);
std::cout << ' ';
for(unsigned ibit=0;ibit<8;ibit++)
std::cout << (((port_b_val>>(7-ibit))&0x01)?1:0);
std::cout << ' ';
for(unsigned ibit=0;ibit<8;ibit++)
std::cout << (((port_c_val>>(7-ibit))&0x01)?1:0);
std::cout << '\n';
usleep(400000);
}
}
catch(const CommunicationError& x)
{
x.print(std::cerr);
std::cerr << strerror(x.errorNum()) << '\n';
}
delete ds;
}