2 * Copyright © 2012 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.
20 #include <ao_lco_cmd.h>
21 #include <ao_radio_cmac.h>
23 static __xdata struct ao_pad_command command;
24 static __xdata struct ao_pad_query query;
25 static __pdata uint16_t launch_box;
26 static __pdata uint8_t launch_channels;
27 static __pdata uint16_t tick_offset;
30 launch_args(void) __reentrant
33 launch_box = ao_cmd_lex_i;
35 launch_channels = ao_cmd_lex_i;
42 int8_t r = AO_RADIO_CMAC_OK;
44 tick_offset = ao_time();
45 for (i = 0; i < 10; i++) {
46 printf ("."); flush();
47 command.tick = ao_time();
48 command.box = launch_box;
49 command.cmd = AO_LAUNCH_QUERY;
50 command.channels = launch_channels;
51 ao_radio_cmac_send(&command, sizeof (command));
52 r = ao_radio_cmac_recv(&query, sizeof (query), AO_MS_TO_TICKS(500));
53 if (r == AO_RADIO_CMAC_OK)
56 tick_offset -= query.tick;
57 printf("\n"); flush();
62 launch_report_cmd(void) __reentrant
68 if (ao_cmd_status != ao_cmd_success)
72 case AO_RADIO_CMAC_OK:
73 switch (query.arm_status) {
74 case ao_igniter_ready:
75 case ao_igniter_active:
81 for (c = 0; c < AO_PAD_MAX_CHANNELS; c++) {
82 if (query.channels & (1 << c)) {
83 printf (" pad %d ", c);
84 switch (query.igniter_status[c]) {
88 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN:
91 case AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN:
92 printf("good-igniter, ");
94 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_CLOSED:
95 printf("bad-closed, ");
100 printf("Rssi: %d\n", ao_radio_cmac_rssi);
103 printf("Error %d\n", r);
109 launch_arm(void) __reentrant
111 command.tick = ao_time() - tick_offset;
112 command.box = launch_box;
113 command.cmd = AO_LAUNCH_ARM;
114 command.channels = launch_channels;
115 ao_radio_cmac_send(&command, sizeof (command));
119 launch_ignite(void) __reentrant
121 command.tick = ao_time() - tick_offset;
122 command.box = launch_box;
123 command.cmd = AO_LAUNCH_FIRE;
124 command.channels = 0;
125 ao_radio_cmac_send(&command, sizeof (command));
129 launch_fire_cmd(void) __reentrant
131 static __xdata struct ao_pad_command command;
139 if (ao_cmd_status != ao_cmd_success)
142 if (r != AO_RADIO_CMAC_OK) {
143 printf("query failed %d\n", r);
147 for (i = 0; i < 4; i++) {
148 printf("arm %d\n", i); flush();
152 secs = secs * 10 - 5;
155 for (i = 0; i < secs; i++) {
156 printf("fire %d\n", i); flush();
158 ao_delay(AO_MS_TO_TICKS(100));
163 launch_arm_cmd(void) __reentrant
169 if (r != AO_RADIO_CMAC_OK) {
170 printf("query failed %d\n", r);
173 for (i = 0; i < 4; i++)
178 launch_ignite_cmd(void) __reentrant
182 for (i = 0; i < 4; i++)
186 static __code struct ao_cmds ao_lco_cmds[] = {
187 { launch_report_cmd, "l <box> <channel>\0Get remote launch status" },
188 { launch_fire_cmd, "F <box> <channel> <secs>\0Fire remote igniter" },
189 { launch_arm_cmd, "a <box> <channel>\0Arm remote igniter" },
190 { launch_ignite_cmd, "i <box> <channel>\0Pulse remote igniter" },
195 ao_lco_cmd_init(void)
197 ao_cmd_register(&ao_lco_cmds[0]);