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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
33 #include "ao-verbose.h"
35 static const struct option options[] = {
36 { .name = "tty", .has_arg = 1, .val = 'T' },
37 { .name = "device", .has_arg = 1, .val = 'D' },
38 { .name = "raw", .has_arg = 0, .val = 'r' },
39 { .name = "verbose", .has_arg = 1, .val = 'v' },
43 static void usage(char *program)
45 fprintf(stderr, "usage: %s [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] main|drogue\n", program);
50 done(struct cc_usb *cc, int code)
52 /* cc_usb_printf(cc, "a\n"); */
58 ends_with(char *whole, char *suffix)
60 int whole_len = strlen(whole);
61 int suffix_len = strlen(suffix);
63 if (suffix_len > whole_len)
65 return strcmp(whole + whole_len - suffix_len, suffix) == 0;
69 starts_with(char *whole, char *prefix)
71 int whole_len = strlen(whole);
72 int prefix_len = strlen(prefix);
74 if (prefix_len > whole_len)
76 return strncmp(whole, prefix, prefix_len) == 0;
85 static struct igniter *
86 igniters(struct cc_usb *usb)
88 struct igniter *head = NULL, **tail = &head;
89 cc_usb_printf(usb, "t\nv\n");
95 cc_usb_getline(usb, line, sizeof (line));
96 if (strstr(line, "software-version"))
98 if (sscanf(line, "Igniter: %s Status: %s", &name, &status) == 2) {
99 struct igniter *i = malloc (sizeof (struct igniter));
100 strcpy(i->name, name);
101 strcpy(i->status, status);
111 free_igniters(struct igniter *i) {
121 static struct igniter *
122 find_igniter(struct igniter *i, char *name)
124 for (; i; i = i->next)
125 if (strcmp(i->name, name) == 0)
130 do_igniter(struct cc_usb *usb, char *name)
132 struct igniter *all = igniters(usb);
133 struct igniter *this = find_igniter(all, name);
136 printf("no igniter %s found in");
137 for (i = all; i; i = i->next)
138 printf(" %s", i->name);
143 if (strcmp(this->status, "ready") != 0) {
144 printf("igniter %s status is %s\n", this->name, this->status);
148 cc_usb_printf(usb, "i DoIt %s\n", this->name);
156 main (int argc, char **argv)
165 struct cc_usb *cc = NULL;
171 while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
188 ao_verbose = verbose;
191 ccdbg_add_debug(CC_DEBUG_BITBANG);
194 tty = cc_usbdevs_find_by_arg(device, "TeleMega-v1.0");
196 tty = cc_usbdevs_find_by_arg(device, "TeleMetrum-v2.0");
198 tty = cc_usbdevs_find_by_arg(device, "TeleMini-v2.0");
200 tty = cc_usbdevs_find_by_arg(device, "EasyMega-v1.0");
202 tty = cc_usbdevs_find_by_arg(device, "EasyMetrum-v1.0");
204 tty = cc_usbdevs_find_by_arg(device, "EasyMini-v1.0");
206 tty = getenv("ALTOS_TTY");
210 cc = cc_usb_open(tty);
215 for (i = optind; i < argc; i++) {
216 char *name = argv[i];
218 if (!do_igniter(cc, name))