-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower.cpp
78 lines (66 loc) · 1.67 KB
/
power.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
//-*-mode:c++; mode:font-lock;-*-
#include<time.h>
#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!=3)
{
std::cerr << "Usage: " << program << " port axes [on/off]" << '\n';
exit(EXIT_FAILURE);
}
const char* port = *argv;
argv++,argc--;
const char* axes = *argv;
argv++,argc--;
for(unsigned ichar=0; axes[ichar]; ichar++)
if(axes[ichar]<'0' || axes[ichar]>'2')
{
std::cerr << "Unrecognised axis: " << axes[ichar] << " ; axes must be combination of 0, 1, and 2." << '\n';
exit(EXIT_FAILURE);
}
const char* onoff = *argv;
argv++,argc--;
bool on = true;
if(strcasecmp(onoff, "off")==0)on=false;
else if(strcasecmp(onoff, "on")!=0)
{
std::cerr << "Final argument must be on or off." << '\n';
exit(EXIT_FAILURE);
}
DataStream* ds = 0;
try
{
ds = ESPProtocol::makeSerialDataStream(port);
ESPProtocol esp(ds);
esp.clearAllErrorCodes();
bool axis_set[] = { false, false, false };
for(unsigned ichar=0; axes[ichar]; ichar++)
{
ESPProtocol::IAxis iaxis = axes[ichar]-'0';
if(axis_set[iaxis])continue;
else if(on)esp.cmdMotorOn(iaxis);
else esp.cmdMotorOff(iaxis);
axis_set[iaxis] = true;
usleep(100000);
}
}
catch(const CommunicationError& x)
{
x.print(std::cerr);
std::cerr << strerror(x.errorNum()) << '\n';
}
catch(const VMessaging::Exception& x)
{
x.print(std::cerr);
}
delete ds;
}