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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/*
Copyright (C) 2014 BARRATERO Laurent
AeroUp is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Aeroup is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* Filename: main.cpp
*
* Description: command line entry point.
* lib getopt needed this is for unix users
*
*
* Version: 0.3.0.1
* Created: 20/12/2013 00:57:44
* Revision: none
* Compiler: gcc
*
* Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
* Organization: La rue Luberlu
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <getopt.h>
#include "global.hpp"
#include "main.hpp"
#include "optmanager.hpp"
#include "config.h"
using namespace std;
bool VERBOSE_AERO;
/*
* Name: main
* Description: get cmd args... gives the job to OptManager.
* and finally said to OptManager to start launch
* of what is expected.
*/
int
main ( int argc, char *argv[] )
{
int version = 0;
int help = 0;
VERBOSE_AERO = false;
int c;
OptManager manager;
while (1)
{
static struct option long_options[] =
{
{"start", required_argument, NULL, 'o'},
{"test", required_argument, NULL, 't'},
{"color", required_argument, NULL, 'c'},
{"getSerial", required_argument, NULL, 'G'},
{"setSerial", required_argument, NULL, 'S'},
{"verify", required_argument, NULL, 'i'},
{"uploadGlo", required_argument, NULL, 'u'},
{"uploadGloc", no_argument, NULL, 'U'},
{"symlink", no_argument, NULL, 'k'},
{"verbose", no_argument, NULL, 'v'},
{"thread", no_argument, NULL, 1 },
{"version", no_argument, &version, 1 },
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "o:t:c:G:S:u:U:k:i:vh",
long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch (c)
{
case 'o':
manager.addItemStart(optarg);
break;
case 't':
manager.addItemTest(optarg);
break;
case 'c':
try
{
manager.subRoutine(FLAG_COLOR);
}
catch ( const string & Msg )
{
cerr << "Error : " << Msg << endl;
return(EXIT_FAILURE);
}
break;
case 'G':
manager.addItemGetSerial(optarg);
break;
case 'S':
try
{
manager.subRoutine(FLAG_SET_SER);
}
catch ( const string & Msg )
{
cerr << "Error : " << Msg << endl;
return(EXIT_FAILURE);
}
break;
case 'i':
manager.addItemVerify(optarg);
break;
case 'u':
manager.subRoutine(FLAG_UP_GLO);
break;
case 'U':
manager.subRoutine(FLAG_UP_GLOC);
break;
case 'k':
manager.addItemSymlink(optarg);
break;
case 'v':
VERBOSE_AERO = true;
break;
case 'h':
help = 1;
break;
case '?':
/* getopt_long already printed an error message. */
puts("To get help : 'aeroup --help' or 'man aeroup'");
return EXIT_FAILURE;
break;
default:
abort ();
}
}
/* Print any remaining command line arguments (not options). */
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
putchar ('\n');
puts("To get help : 'aeroup --help' or 'man aeroup'");
return(EXIT_FAILURE);
}
if(version)
{
aeroVersion();
return(EXIT_SUCCESS);
}
if(help || argc == 1)
{
aeroHelp();
return(EXIT_SUCCESS);
}
try
{
manager.start();
}
catch( const exception & e )
{
return(EXIT_FAILURE);
}
catch( Symlink::Bad_Symlink )
{
cerr << "Error : Bad Symlink input\n"
<< "'$man aeroup' section 'Improved management driver' may be help you\n";
return(EXIT_FAILURE);
}
catch(...)
{
//return(EXIT_FAILURE);
puts("UNKNOWN ERROR, CATCHED IN MAIN");
return(EXIT_FAILURE);
}
return(EXIT_SUCCESS);
}
/*
* Name: aeroHelp
* Description: --help
*/
void
aeroHelp()
{
cout << "Usage : " << PACKAGE <<" [OPTION [SUB_OPTION]]...\n"
<< "AeroUp is an open source command line tool to control Ultimate juggling props sold by Aerotech Projects.\n\n"
<< " -t, --test=serialPort Send a test command on dev serialPort.\n"
<< " -o, --start=serialPort Send a start sequence command on dev serialPort.\n"
<< " -c, --color=R,G,B,serialPort Send a color command on dev serialPort.\n"
<< " R,G,B can be hex (0x#), dec (#) value,\n"
<< " in range of [0-255] (8bit).\n"
<< " -G, --getSerial=serialPort Get serial number on dev serialPort, and print it to standard output.\n"
<< " -S, --setSerial=serialNumber,serialPort Set serialNumber on dev serialPort. the 32 bits serialNumber value\n"
<< " can be writen in hex (0x#) or dec (#).\n"
<< " -i, --verify=gloFile Verify that syntax glo file is valid.\n"
<< " -k --symlink Return the serial name used as symlink of kernel name by udev.\n"
<< " More info in the AeroUp man.\n"
<< " -u, --uploadGloc=gloFile,serialPort Verify that syntax glo file is valid, and if this is the case,\n"
<< " upload it on dev serialPort.\n"
<< " -P, --thread Multithread mode, not implemented yet...\n"
<< " -U, --uploadGloc=glocFile,serialPort Not implemented yet...\n"
<< " -v Verbose mode.\n"
<< " -h, --help Print help.\n"
<< " --version Print version.\n\n"
<< "Each sub options have to be separate with a comma without blank.\n"
<< "you 'll find more info in the man of aeroup.\n\n"
<< "Examples\n"
<< " aeroup -t /dev/ttyACM0\n"
<< " aeroup -o /dev/ttyACM0 -o /dev/ttyACM1 -t /dev/ttyACM3\n"
<< " aeroup -c 255,69,255,/dev/ttyACM0 27,3,7,/dev/ttyACM1\n"
<< " aeroup -S 0x0b01/dev/ttyACM0\n"
<< " aeroup -G /dev/ttyACM0\n\n"
<< "AeroUp project page : " PACKAGE_URL << "\n"
<< "You can also take a look at the AeroWrite project page https://github.com/LaurentBa/AeroWrite\n"
<< "Report bugs to " << PACKAGE_BUGREPORT << "\n"
<< endl;
}
/*
* Name: aeroVersion
* Description: --version
*/
void
aeroVersion()
{
cout << PACKAGE_STRING << "\n"
"Copyright © 2014 BARATTERO Laurent\n"
"License GPLv3+: GNU GPL version 3 or later\n"
"<http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law\n";
}
|