X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Fao-cal-freq%2Fao-cal-freq.c;h=12c2a3ae9f6c845b809025a37068844d7d1c7e8b;hb=2f8fce1cf6ce4bd12a836cc8ee15f4edbc95c95e;hp=464faf0f8320a63587cdf79b1e4a5d441e2ad24d;hpb=c46c2c5767c6e909fa58587e6c864a4fbaa9fa20;p=fw%2Faltos diff --git a/ao-tools/ao-cal-freq/ao-cal-freq.c b/ao-tools/ao-cal-freq/ao-cal-freq.c index 464faf0f..12c2a3ae 100644 --- a/ao-tools/ao-cal-freq/ao-cal-freq.c +++ b/ao-tools/ao-cal-freq/ao-cal-freq.c @@ -3,7 +3,8 @@ * * This program 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; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -38,13 +39,13 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, { .name = "raw", .has_arg = 0, .val = 'r' }, - { .name = "verbose", .has_arg = 1, .val = 'v' }, + { .name = "verbose", .has_arg = 0, .val = 'v' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--verbose=] [--device=] [-tty=]\n", program); + fprintf(stderr, "usage: %s [--verbose] [--device=] [-tty=]\n", program); exit(1); } @@ -167,7 +168,8 @@ await_key(void) } int -do_cal(struct cc_usb *usb) { +do_cal(char *tty) { + struct cc_usb *usb = NULL; struct flash *b; char line[1024]; double measured_freq; @@ -177,10 +179,17 @@ do_cal(struct cc_usb *usb) { int cur_freq; int cur_cal; int new_cal; - - cc_usb_printf(usb, "E 0\n"); + int ret = 1; for(;;) { + usb = cc_usb_open(tty); + + if (!usb) + exit(1); + + cc_usb_printf(usb, "E 0\n"); + + cc_usb_sync(usb); cc_usb_printf(usb, "C 1\n"); cc_usb_sync(usb); @@ -201,7 +210,8 @@ do_cal(struct cc_usb *usb) { if (!cur_cal_words || !cur_freq_words) { printf("no response\n"); - return 0; + ret = 0; + break; } cur_cal = atoi(cur_cal_words[2]); @@ -217,8 +227,11 @@ do_cal(struct cc_usb *usb) { cc_usb_printf (usb, "c f %d\nc w\n", new_cal); cc_usb_sync(usb); + cc_usb_close(usb); } - return 1; + if (usb) + cc_usb_close(usb); + return ret; } int @@ -231,14 +244,13 @@ main (int argc, char **argv) int i; int c; int tries; - struct cc_usb *cc = NULL; char *tty = NULL; int success; int verbose = 0; int ret = 0; int expected_size; - while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "vrT:D:c:s:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -269,12 +281,6 @@ main (int argc, char **argv) if (!tty) tty="/dev/ttyACM0"; - cc = cc_usb_open(tty); - - if (!cc) - exit(1); - - if (!do_cal(cc)) + if (!do_cal(tty)) ret = 1; - done(cc, ret); }