-
Notifications
You must be signed in to change notification settings - Fork 2
/
ampctl.cpp
52 lines (45 loc) · 886 Bytes
/
ampctl.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
#include <iostream>
#include <string>
#include <unistd.h>
#include "serial.h"
using namespace std;
int main( int argc, char* argv[] )
{
const unsigned char off_cmd[] = { 0xff, 0x01, 0x01 };
const unsigned char on_cmd[] = { 0xff, 0x01, 0x00 };
SerialPort port;
if ( port.init( "/dev/ttyUSB2" ) != -1 )
{
if ( argc == 2 )
{
string status = argv[1];
if ( status == "on" )
{
port.write( on_cmd, sizeof( on_cmd ) );
}
else if ( status == "reset" )
{
port.write( off_cmd, sizeof(off_cmd) );
sleep(1);
port.write( on_cmd, sizeof( on_cmd ) );
}
else if ( status == "off" )
{
port.write( off_cmd, sizeof( off_cmd ) );
}
else
{
cout << "invalid command: " << status << endl;
}
}
else
{
cout << "invalid argument" << endl;
}
}
else
{
cout << "Error initializing port" << endl;
}
return 0;
}