-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_command.cpp
88 lines (80 loc) · 2.12 KB
/
send_command.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
/** @file send_command.cpp
*
* @author marco corvi
* @date jan 2009
*
* @brief send a command to the DistoX
*
* --------------------------------------------------------
* Copyright This sowftare is distributed under GPL-3.0 or later
* See the file COPYING.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "defaults.h"
#include "Protocol.h"
void usage()
{
fprintf(stderr,
"Usage: dump_data [-d device] command\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -d device RFCOMM serial device [%s]\n",
DEFAULT_DEVICE );
fprintf(stderr, " command command to send\n");
fprintf(stderr, " 1: start calib, 2: stop calib\n");
fprintf(stderr, " 3: start silent, 4: stop silent\n");
}
int main( int argc, char ** argv )
{
const char * device = DEFAULT_DEVICE;
int number = -1;
int ac = 1;
if ( argc > ac ) {
if ( strcmp( argv[ac], "-d" ) == 0 && argc > ac+1 ) {
device = argv[ac+1];
ac += 2;
}
}
if ( ac < argc ) {
number = atoi( argv[ac] );
ac ++;
}
if ( number < 1 || number > 4 ) {
fprintf(stderr, "ERROR: command must be between one of:\n");
fprintf(stderr, " 1 (calib) 2 (normal) 3 (silent) 4 (no-silent)\n");
return 1;
}
Protocol proto( device );
if ( ! proto.Open() ) {
fprintf(stderr, "ERROR: failed to open protocol \n");
return 1;
}
ProtoError err = PROTO_OK;
switch( number ) {
case 1:
fprintf(stderr, "... SendCommand() CALIB_START\n");
err = proto.SendCommand( CALIB_START );
break;
case 2:
fprintf(stderr, "... SendCommand() CALIB_STOP\n");
err = proto.SendCommand( CALIB_STOP );
break;
case 3:
fprintf(stderr, "... SendCommand() SILENT_START\n");
err = proto.SendCommand( SILENT_START );
break;
case 4:
fprintf(stderr, "... SendCommand() SILENT_STOP\n");
err = proto.SendCommand( SILENT_STOP );
break;
default:
break;
}
if ( err != PROTO_OK ) {
fprintf(stderr, "Command send failed: %s\n", ProtoErrorStr(err) );
return 1;
}
return 0;
}