|
@@ -21,9 +21,10 @@ int run_the_terminal(int fd_serial, char *title, WINDOW *win); /* XXX */
|
21
|
21
|
int verbosity;
|
22
|
22
|
|
23
|
23
|
/* --------------------------------------------------------------- */
|
24
|
|
-int traite_les_messages(int sfd, int nbloops)
|
|
24
|
+int traite_les_messages(int sfd, int nbloops, int notused)
|
25
|
25
|
{
|
26
|
|
-int idx, foo, key;
|
|
26
|
+int foo, key;
|
|
27
|
+int loop_forever;
|
27
|
28
|
char ligne[200];
|
28
|
29
|
int Idatas[4];
|
29
|
30
|
float Fdatas[4];
|
|
@@ -37,7 +38,16 @@ if (NULL==fp) {
|
37
|
38
|
return -1;
|
38
|
39
|
}
|
39
|
40
|
|
40
|
|
-for (idx=0; idx<nbloops; idx++) {
|
|
41
|
+if (0==nbloops) {
|
|
42
|
+ fprintf(stderr, "looping forever...\n");
|
|
43
|
+ loop_forever = 1;
|
|
44
|
+ }
|
|
45
|
+else {
|
|
46
|
+ fprintf(stderr, "looping %d rounds\n", nbloops);
|
|
47
|
+ loop_forever = 0;
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+do {
|
41
|
51
|
|
42
|
52
|
if (kbhit()) {
|
43
|
53
|
static char valid_k[] = "+-01";
|
|
@@ -107,7 +117,9 @@ for (idx=0; idx<nbloops; idx++) {
|
107
|
117
|
|
108
|
118
|
fflush(stderr); /* really WTF? here */
|
109
|
119
|
|
110
|
|
- }
|
|
120
|
+ if ( loop_forever ) nbloops = 1;
|
|
121
|
+
|
|
122
|
+ } while (0 != nbloops);
|
111
|
123
|
|
112
|
124
|
fclose(fp);
|
113
|
125
|
|
|
@@ -126,6 +138,7 @@ void help(int k)
|
126
|
138
|
puts("options : ");
|
127
|
139
|
puts("\t-d\tserial device to read.");
|
128
|
140
|
puts("\t-K\tset the K parameter.");
|
|
141
|
+puts("\t-n NN\tnumber of loops, 0 is infinity");
|
129
|
142
|
puts("\t-v\tincrease verbosity.");
|
130
|
143
|
exit(0);
|
131
|
144
|
}
|
|
@@ -138,20 +151,23 @@ int serial_in;
|
138
|
151
|
char *device = "/dev/ttyACM0";
|
139
|
152
|
int K = 0;
|
140
|
153
|
char ligne[100];
|
|
154
|
+int nbreloops;
|
|
155
|
+
|
|
156
|
+printf("\n**** %s **** compiled the %s at %s ***\n",
|
|
157
|
+ argv[0], __DATE__, __TIME__);
|
|
158
|
+
|
141
|
159
|
|
142
|
|
-while ((opt = getopt(argc, argv, "d:hv")) != -1) {
|
|
160
|
+while ((opt = getopt(argc, argv, "d:hn:v")) != -1) {
|
143
|
161
|
switch (opt) {
|
144
|
162
|
case 'd': device = optarg; break;
|
145
|
163
|
case 'h': help(0); break;
|
146
|
164
|
case 'K': K = atoi(optarg); break;
|
|
165
|
+ case 'n': nbreloops=atoi(optarg); break;
|
147
|
166
|
case 'v': verbosity++; break;
|
148
|
167
|
default: break;
|
149
|
168
|
}
|
150
|
169
|
}
|
151
|
170
|
|
152
|
|
-printf("\n**** %s **** compiled the %s at %s ***\n",
|
153
|
|
- argv[0], __DATE__, __TIME__);
|
154
|
|
-
|
155
|
171
|
serial_in = prepare_UART(device, 9600);
|
156
|
172
|
if (serial_in < 0) {
|
157
|
173
|
fprintf(stderr, "\n%s : open device : error %d on %s\n",
|
|
@@ -167,7 +183,7 @@ keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
|
167
|
183
|
sprintf(ligne, " Demonstrator pid:%d %s ", getpid(), device);
|
168
|
184
|
fond_ecran(ligne);
|
169
|
185
|
|
170
|
|
-traite_les_messages(serial_in, 50000000);
|
|
186
|
+traite_les_messages(serial_in, nbreloops, K);
|
171
|
187
|
|
172
|
188
|
/*
|
173
|
189
|
* plop, on a fini, il faut restaurer la console
|