2 * Copyright © 2014 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.
34 #include "ao-verbose.h"
36 static const struct option options[] = {
37 { .name = "tty", .has_arg = 1, .val = 'T' },
38 { .name = "device", .has_arg = 1, .val = 'D' },
39 { .name = "raw", .has_arg = 0, .val = 'r' },
40 { .name = "verbose", .has_arg = 1, .val = 'v' },
44 static void usage(char *program)
46 fprintf(stderr, "usage: %s [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] main|drogue\n", program);
51 done(struct cc_usb *cc, int code)
53 /* cc_usb_printf(cc, "a\n"); */
64 static struct igniter *
65 igniters(struct cc_usb *usb)
67 struct igniter *head = NULL, **tail = &head;
68 cc_usb_printf(usb, "t\nv\n");
74 cc_usb_getline(usb, line, sizeof (line));
75 if (strstr(line, "software-version"))
77 if (sscanf(line, "Igniter: %s Status: %s", name, status) == 2) {
78 struct igniter *i = malloc (sizeof (struct igniter));
79 strcpy(i->name, name);
80 strcpy(i->status, status);
90 free_igniters(struct igniter *i) {
100 static struct igniter *
101 find_igniter(struct igniter *i, char *name)
103 for (; i; i = i->next)
104 if (strcmp(i->name, name) == 0)
110 do_igniter(struct cc_usb *usb, char *name)
112 struct igniter *all = igniters(usb);
113 struct igniter *this = find_igniter(all, name);
116 printf("no igniter %s found in", name);
117 for (i = all; i; i = i->next)
118 printf(" %s", i->name);
123 if (strcmp(this->status, "ready") != 0) {
124 printf("igniter %s status is %s\n", this->name, this->status);
128 cc_usb_printf(usb, "i DoIt %s\n", this->name);
136 main (int argc, char **argv)
141 struct cc_usb *cc = NULL;
146 while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
163 ao_verbose = verbose;
166 ccdbg_add_debug(CC_DEBUG_BITBANG);
169 tty = cc_usbdevs_find_by_arg(device, "TeleMega-v1.0");
171 tty = cc_usbdevs_find_by_arg(device, "TeleMetrum-v2.0");
173 tty = cc_usbdevs_find_by_arg(device, "TeleMini-v2.0");
175 tty = cc_usbdevs_find_by_arg(device, "EasyMega-v1.0");
177 tty = cc_usbdevs_find_by_arg(device, "EasyMetrum-v1.0");
179 tty = cc_usbdevs_find_by_arg(device, "EasyMini-v1.0");
181 tty = getenv("ALTOS_TTY");
185 cc = cc_usb_open(tty);
190 for (i = optind; i < argc; i++) {
191 char *name = argv[i];
193 if (!do_igniter(cc, name))