tools/antorcha.c |
16 | 16 | #include <stdio.h> |
17 | 17 | #include <unistd.h> |
18 | 18 | #include <string.h> |
| 19 | #include <signal.h> |
19 | 20 | #include <assert.h> |
20 | 21 | |
21 | 22 | #include <at86rf230.h> |
... | ... | |
280 | 281 | /* ----- Samples ----------------------------------------------------------- */ |
281 | 282 | |
282 | 283 | |
| 284 | static volatile int run = 1; |
| 285 | |
| 286 | |
| 287 | static void sigint(int sig) |
| 288 | { |
| 289 | run = 0; |
| 290 | } |
| 291 | |
| 292 | |
283 | 293 | static int read_sample(uint8_t **s, uint16_t *t_high, uint16_t *t_low, |
284 | 294 | uint16_t *last) |
285 | 295 | { |
... | ... | |
296 | 306 | } |
297 | 307 | |
298 | 308 | |
299 | | static void samples(struct atrf_dsc *dsc) |
| 309 | static void samples(struct atrf_dsc *dsc, int gui) |
300 | 310 | { |
301 | 311 | uint8_t buf[MAX_PSDU] = { 0, }; |
302 | 312 | int got; |
303 | 313 | uint8_t *s; |
304 | 314 | uint16_t t_high, t_low, last; |
305 | 315 | int x, y; |
| 316 | double t; |
306 | 317 | |
307 | 318 | buf[0] = 1; |
308 | 319 | packet(dsc, SAMPLE, 0, 0, buf, PAYLOAD); |
309 | | plot_init(); |
310 | | while (1) { |
| 320 | if (gui) |
| 321 | plot_init(); |
| 322 | else |
| 323 | signal(SIGINT, sigint); |
| 324 | while (run) { |
311 | 325 | got = rf_recv(dsc, buf, sizeof(buf)); |
312 | 326 | if (got <= 3) |
313 | 327 | continue; |
... | ... | |
328 | 342 | last = 0; |
329 | 343 | while (s < buf+got-2) { |
330 | 344 | x = read_sample(&s, &t_high, &t_low, &last); |
| 345 | t = (t_high << 16 | t_low)/1000000.0; |
331 | 346 | if (debug) |
332 | | fprintf(stderr, "\t%11.6f %d", |
333 | | (t_high << 16 | t_low)/1000000.0, x); |
| 347 | fprintf(stderr, "\t%11.6f %d", t, x); |
| 348 | if (!gui) |
| 349 | printf("%11.6f\t%d\t", t, x); |
334 | 350 | |
335 | 351 | y = read_sample(&s, &t_high, &t_low, &last); |
| 352 | t = (t_high << 16 | t_low)/1000000.0; |
336 | 353 | if (debug) |
337 | | fprintf(stderr, "\t%11.6f %d\n", |
338 | | (t_high << 16 | t_low)/1000000.0, y); |
| 354 | fprintf(stderr, "\t%11.6f %d\n", t, y); |
| 355 | if (!gui) |
| 356 | printf("%11.6f\t%d\n", t, y); |
339 | 357 | |
340 | | if (!plot(x, y)) |
| 358 | if (gui && !plot(x, y)) |
341 | 359 | goto quit; |
342 | 360 | } |
343 | 361 | } |
... | ... | |
356 | 374 | "usage: %s [-d] image_file\n" |
357 | 375 | "%6s %s [-d] -F firmware_file\n" |
358 | 376 | "%6s %s [-d] -P\n" |
359 | | "%6s %s [-d] -S\n" |
| 377 | "%6s %s [-d] -S [-S]\n" |
360 | 378 | , name, "", name, "", name, "", name); |
361 | 379 | exit(1); |
362 | 380 | } |
... | ... | |
381 | 399 | do_ping = 1; |
382 | 400 | break; |
383 | 401 | case 'S': |
384 | | do_sample = 1; |
| 402 | do_sample++; |
385 | 403 | break; |
386 | 404 | default: |
387 | 405 | usage(*argv); |
388 | 406 | } |
389 | 407 | |
390 | | if (do_ping+do_sample+!!fw > 1) |
| 408 | if (do_ping+!!do_sample+!!fw > 1) |
391 | 409 | usage(*argv); |
392 | 410 | if (do_ping || do_sample || fw) { |
393 | 411 | if (argc != optind) |
... | ... | |
405 | 423 | if (do_ping) |
406 | 424 | ping(dsc); |
407 | 425 | else if (do_sample) |
408 | | samples(dsc); |
| 426 | samples(dsc, do_sample > 1); |
409 | 427 | else if (fw) |
410 | 428 | firmware(dsc, fw); |
411 | 429 | else |