*
* 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
{ .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=<verbose>] [--device=<device>] [-tty=<tty>]\n", program);
+ fprintf(stderr, "usage: %s [--verbose] [--device=<device>] [-tty=<tty>]\n", program);
exit(1);
}
}
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;
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);
if (!cur_cal_words || !cur_freq_words) {
printf("no response\n");
- return 0;
+ ret = 0;
+ break;
}
cur_cal = atoi(cur_cal_words[2]);
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
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;
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);
}