X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Fao-cal-freq%2Fao-cal-freq.c;h=12c2a3ae9f6c845b809025a37068844d7d1c7e8b;hb=ec319edd2cda321d7542784b997acd0da040fa3d;hp=33fe52faac5507dc4bca86c2c7e924e49fa79567;hpb=1085ec5d57e0ed5d132f2bbdac1a0b6a32c0ab4a;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 33fe52fa..12c2a3ae 100644 --- a/ao-tools/ao-cal-freq/ao-cal-freq.c +++ b/ao-tools/ao-cal-freq/ao-cal-freq.c @@ -39,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); } @@ -168,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; @@ -178,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); @@ -202,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]); @@ -218,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 @@ -232,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; @@ -270,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); }