-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtunerctl.cpp
139 lines (129 loc) · 3.04 KB
/
tunerctl.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <math.h>
#include <arpa/inet.h> // for ntohs
#include <unistd.h>
#include "serial.h"
using namespace std;
void tuneResponse( char r )
{
switch (r)
{
case 'T':
cout << "Good tune!" << endl;
break;
case 'M':
cout << "OK tune.." << endl;
break;
case 'F':
cout << "BAD tune :(" << endl;
break;
}
}
int main( int argc, char* argv[] )
{
const char toggleAntCmd = 'A';
const char memTuneCmd = 'M';
const char fullTuneCmd = 'F';
const char bypassCmd = 'P';
const char autoCmd = 'C';
const char manualCmd = 'M';
const char syncCmd = 'Z';
const char meterCmd = 'S';
const char ctlCmd = 'X';
const char wakeCmd = ' ';
if ( argc == 2 )
{
SerialPort port;
if ( port.init( "/dev/ttyUSB1", B38400) != -1 )
{
string cmd = argv[1];
const string syncResp = "000000000000000AzAz";
char resp[20];
memset( resp, 0x00, sizeof(resp) );
if ( cmd == "toggle" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &toggleAntCmd, sizeof(toggleAntCmd) );
port.readFully( resp, 1 );
cout << "Antenna " << resp << " selected." << endl;
}
else if ( cmd == "mem" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &memTuneCmd, sizeof(memTuneCmd));
port.readFully( resp, 1 );
tuneResponse( resp[0] );
}
else if ( cmd == "full" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &fullTuneCmd, sizeof(fullTuneCmd) );
port.readFully( resp, 1 );
tuneResponse( resp[0] );
}
else if ( cmd == "bypass" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &bypassCmd, sizeof(bypassCmd) );
port.readFully( resp, 1 );
cout << "bypass response: " << resp[0] << endl;
}
else if ( cmd == "auto" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &autoCmd, sizeof(autoCmd) );
port.readFully( resp, 1 );
cout << "auto response: " << resp[0] << endl;
}
else if ( cmd == "manual" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &manualCmd, sizeof(manualCmd) );
port.readFully( resp, 1 );
cout << "Manual response: " << resp[0] << endl;
}
else if ( cmd == "sync" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &syncCmd, sizeof(syncCmd) );
port.readFully( resp, 19 );
cout << "Sync Response: " << resp << endl;
}
else if ( cmd == "meter" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &meterCmd, sizeof(meterCmd) );
}
else if ( cmd == "ctl" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &ctlCmd, sizeof(ctlCmd));
}
else
{
cout << "invalid command: " << cmd << endl;
}
}
else
{
cout << "problem opening port" << endl;
}
}
else
{
cout << "incorrect number of args" << endl;
}
exit(0);
}