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.
19 #include <ao_lco_cmd.h>
20 #include <ao_radio_cmac.h>
22 static __xdata struct ao_launch_command command;
23 static __xdata struct ao_launch_query query;
24 static __pdata uint16_t launch_serial;
25 static __pdata uint8_t launch_channel;
26 static __pdata uint16_t tick_offset;
29 launch_args(void) __reentrant
32 launch_serial = ao_cmd_lex_i;
34 launch_channel = ao_cmd_lex_i;
41 int8_t r = AO_RADIO_CMAC_OK;
43 tick_offset = ao_time();
44 for (i = 0; i < 10; i++) {
45 printf ("."); flush();
46 command.tick = ao_time();
47 command.serial = launch_serial;
48 command.cmd = AO_LAUNCH_QUERY;
49 command.channel = launch_channel;
50 ao_radio_cmac_send(&command, sizeof (command));
51 r = ao_radio_cmac_recv(&query, sizeof (query), AO_MS_TO_TICKS(500));
52 if (r == AO_RADIO_CMAC_OK)
55 tick_offset -= query.tick;
56 printf("\n"); flush();
61 launch_report_cmd(void) __reentrant
66 if (ao_cmd_status != ao_cmd_success)
70 case AO_RADIO_CMAC_OK:
72 switch (query.arm_status) {
73 case ao_igniter_ready:
74 case ao_igniter_active:
80 switch (query.igniter_status) {
84 case ao_igniter_ready:
85 printf("igniter good\n");
88 printf("igniter bad\n");
92 printf("Invalid channel %d\n", launch_channel);
94 printf("Rssi: %d\n", ao_radio_cmac_rssi);
97 printf("Error %d\n", r);
103 launch_arm(void) __reentrant
105 command.tick = ao_time() - tick_offset;
106 command.serial = launch_serial;
107 command.cmd = AO_LAUNCH_ARM;
108 command.channel = launch_channel;
109 ao_radio_cmac_send(&command, sizeof (command));
113 launch_ignite(void) __reentrant
115 command.tick = ao_time() - tick_offset;
116 command.serial = launch_serial;
117 command.cmd = AO_LAUNCH_FIRE;
119 ao_radio_cmac_send(&command, sizeof (command));
123 launch_fire_cmd(void) __reentrant
125 static __xdata struct ao_launch_command command;
133 if (ao_cmd_status != ao_cmd_success)
136 if (r != AO_RADIO_CMAC_OK) {
137 printf("query failed %d\n", r);
141 for (i = 0; i < 4; i++) {
142 printf("arm %d\n", i); flush();
146 secs = secs * 10 - 5;
149 for (i = 0; i < secs; i++) {
150 printf("fire %d\n", i); flush();
152 ao_delay(AO_MS_TO_TICKS(100));
157 launch_arm_cmd(void) __reentrant
163 if (r != AO_RADIO_CMAC_OK) {
164 printf("query failed %d\n", r);
167 for (i = 0; i < 4; i++)
172 launch_ignite_cmd(void) __reentrant
176 for (i = 0; i < 4; i++)
180 static __code struct ao_cmds ao_lco_cmds[] = {
181 { launch_report_cmd, "l <serial> <channel>\0Get remote launch status" },
182 { launch_fire_cmd, "f <serial> <channel> <secs>\0Fire remote igniter" },
183 { launch_arm_cmd, "a <serial> <channel>\0Arm remote igniter" },
184 { launch_ignite_cmd, "i <serial> <channel>\0Pulse remote igniter" },
189 ao_lco_cmd_init(void)
191 ao_cmd_register(&ao_lco_cmds[0]);