2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 static const struct option options[] = {
30 { .name = "tty", .has_arg = 1, .val = 'T' },
31 { .name = "device", .has_arg = 1, .val = 'D' },
32 { .name = "remote", .has_arg = 0, .val = 'R' },
33 { .name = "frequency", .has_arg = 1, .val = 'F' },
34 { .name = "call", .has_arg = 1, .val = 'C' },
35 { .name = "output", .has_arg = 1, .val = 'o' },
39 static void usage(char *program)
41 fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] [--remote] [--frequency <radio-frequency>] [--call <radio-callsign>]\n", program);
46 main (int argc, char **argv)
54 int serial_number = 0;
56 char *call = "N0CALL";
64 char *out_name = NULL;
66 while ((c = getopt_long(argc, argv, "T:D:F:C:o:R", options, NULL)) != -1) {
93 tty = cc_usbdevs_find_by_arg(device, "TeleDongle");
95 tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
98 tty = getenv("ALTOS_TTY");
102 cc = cc_usb_open(tty);
106 cc_usb_open_remote(cc, freq, call);
109 out = fopen(out_name, "w");
118 /* send a 'version' command followed by a 'flash' command */
119 cc_usb_printf(cc, "f\nv\n");
121 cc_usb_getline(cc, line, sizeof (line));
122 if (sscanf(line, "serial-number %u", &serial_number) == 1)
124 if (sscanf(line, "Storage size: %u", &storage_size) == 1)
126 if (!strncmp(line, "software-version", 16))
129 if (!serial_number) {
130 fprintf(stderr, "no serial number found\n");
135 fprintf(stderr, "no storage size found\n");
139 printf ("Serial number: %d\n", serial_number);
140 printf ("Storage size: %d\n", storage_size);
141 fprintf (stderr, "%7d of %7d", 0, storage_size/256);
142 for (block = 0; block < storage_size / 256; block++) {
143 cc_usb_printf(cc, "e %x\n", block);
144 fprintf (stderr, "\r%7d of %7d", block + 1, storage_size/256); fflush(stderr);
145 for (addr = 0; addr < 0x100;) {
146 cc_usb_getline(cc, line, sizeof (line));
147 if (sscanf(line, "00%x %x %x %x %x %x %x %x %x",
149 &data[0], &data[1], &data[2], &data[3],
150 &data[4], &data[5], &data[6], &data[7]) == 9)
152 if (received_addr != addr)
153 fprintf(stderr, "data out of sync at 0x%x\n",
154 block * 256 + received_addr);
156 fprintf (out, "%08x", block * 256 + addr);
157 for (i = 0; i < 8; i++)
158 fprintf (out, " %02x", data[i]);
165 fprintf(stderr, "\n");