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.
21 static __xdata struct ao_launch_command command;
22 static __xdata struct ao_launch_query query;
23 static __pdata uint16_t launch_serial;
24 static __pdata uint8_t launch_channel;
25 static __pdata uint16_t tick_offset;
28 launch_args(void) __reentrant
31 launch_serial = ao_cmd_lex_i;
33 launch_channel = ao_cmd_lex_i;
40 int8_t r = AO_RADIO_CMAC_OK;
42 tick_offset = ao_time();
43 for (i = 0; i < 10; i++) {
44 printf ("."); flush();
45 command.tick = ao_time();
46 command.serial = launch_serial;
47 command.cmd = AO_LAUNCH_QUERY;
48 command.channel = launch_channel;
49 ao_radio_cmac_send(&command, sizeof (command));
50 r = ao_radio_cmac_recv(&query, sizeof (query), AO_MS_TO_TICKS(500));
51 if (r == AO_RADIO_CMAC_OK)
54 tick_offset -= query.tick;
55 printf("\n"); flush();
60 launch_report_cmd(void) __reentrant
65 if (ao_cmd_status != ao_cmd_success)
69 case AO_RADIO_CMAC_OK:
71 switch (query.arm_status) {
72 case ao_igniter_ready:
73 case ao_igniter_active:
79 switch (query.igniter_status) {
83 case ao_igniter_ready:
84 printf("igniter good\n");
87 printf("igniter bad\n");
91 printf("Invalid channel %d\n", launch_channel);
93 printf("Rssi: %d\n", ao_radio_cmac_rssi);
96 printf("Error %d\n", r);
102 launch_arm(void) __reentrant
104 command.tick = ao_time() - tick_offset;
105 command.serial = launch_serial;
106 command.cmd = AO_LAUNCH_ARM;
107 command.channel = launch_channel;
108 ao_radio_cmac_send(&command, sizeof (command));
112 launch_ignite(void) __reentrant
114 command.tick = ao_time() - tick_offset;
115 command.serial = launch_serial;
116 command.cmd = AO_LAUNCH_FIRE;
118 ao_radio_cmac_send(&command, sizeof (command));
122 launch_fire_cmd(void) __reentrant
124 static __xdata struct ao_launch_command command;
132 if (ao_cmd_status != ao_cmd_success)
135 if (r != AO_RADIO_CMAC_OK) {
136 printf("query failed %d\n", r);
140 for (i = 0; i < 4; i++) {
141 printf("arm %d\n", i); flush();
145 secs = secs * 10 - 5;
148 for (i = 0; i < secs; i++) {
149 printf("fire %d\n", i); flush();
151 ao_delay(AO_MS_TO_TICKS(100));
156 launch_arm_cmd(void) __reentrant
162 if (r != AO_RADIO_CMAC_OK) {
163 printf("query failed %d\n", r);
166 for (i = 0; i < 4; i++)
171 launch_ignite_cmd(void) __reentrant
175 for (i = 0; i < 4; i++)
179 static __code struct ao_cmds ao_lco_cmds[] = {
180 { radio_cmac_send_cmd, "s <length>\0Send AES-CMAC packet. Bytes to send follow on next line" },
181 { radio_cmac_recv_cmd, "S <length> <timeout>\0Receive AES-CMAC packet. Timeout in ms" },
182 { launch_report_cmd, "l <serial> <channel>\0Get remote launch status" },
183 { launch_fire_cmd, "f <serial> <channel> <secs>\0Fire remote igniter" },
184 { launch_arm_cmd, "a <serial> <channel>\0Arm remote igniter" },
185 { launch_ignite_cmd, "i <serial> <channel>\0Pulse remote igniter" },
192 ao_cmd_register(&ao_lco_cmds[0]);