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; 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.
21 #include <ao_lco_cmd.h>
22 #include <ao_lco_func.h>
23 #include <ao_radio_cmac.h>
25 #ifndef HAS_STATIC_TEST
26 #define HAS_STATIC_TEST 1
29 static __pdata uint16_t lco_box;
30 static __pdata uint8_t lco_channels;
31 static __pdata uint16_t tick_offset;
34 lco_args(void) __reentrant
37 lco_box = ao_cmd_lex_i;
39 lco_channels = ao_cmd_lex_i;
42 static struct ao_pad_query ao_pad_query;
43 static uint16_t tick_offset;
49 int8_t r = AO_RADIO_CMAC_OK;
51 for (i = 0; i < 10; i++) {
52 printf ("."); flush();
53 r = ao_lco_query(lco_box, &ao_pad_query, &tick_offset);
54 if (r == AO_RADIO_CMAC_OK)
57 printf("\n"); flush();
64 ao_lco_arm(lco_box, lco_channels, tick_offset);
68 lco_ignite(uint8_t cmd)
74 lco_report_cmd(void) __reentrant
80 if (ao_cmd_status != ao_cmd_success)
84 case AO_RADIO_CMAC_OK:
85 switch (ao_pad_query.arm_status) {
86 case AO_PAD_ARM_STATUS_ARMED:
89 case AO_PAD_ARM_STATUS_DISARMED:
92 case AO_PAD_ARM_STATUS_UNKNOWN:
97 for (c = 0; c < AO_PAD_MAX_CHANNELS; c++) {
98 if (ao_pad_query.channels & (1 << c)) {
99 printf (" pad %d ", c);
100 switch (ao_pad_query.igniter_status[c]) {
104 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN:
105 printf("bad-open, ");
107 case AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN:
108 printf("good-igniter, ");
110 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_CLOSED:
111 printf("bad-closed, ");
116 printf("Rssi: %d\n", ao_radio_cmac_rssi);
119 printf("Error %d\n", r);
125 lco_fire_cmd(void) __reentrant
134 if (ao_cmd_status != ao_cmd_success)
137 if (r != AO_RADIO_CMAC_OK) {
138 printf("query failed %d\n", r);
142 for (i = 0; i < 4; i++) {
143 printf("arm %d\n", i); flush();
147 secs = secs * 10 - 5;
150 for (i = 0; i < secs; i++) {
151 printf("fire %d\n", i); flush();
152 lco_ignite(AO_PAD_FIRE);
153 ao_delay(AO_MS_TO_TICKS(100));
159 lco_static_cmd(void) __reentrant
168 if (ao_cmd_status != ao_cmd_success)
171 if (r != AO_RADIO_CMAC_OK) {
172 printf("query failed %d\n", r);
176 for (i = 0; i < 4; i++) {
177 printf("arm %d\n", i); flush();
181 secs = secs * 10 - 5;
184 for (i = 0; i < secs; i++) {
185 printf("fire %d\n", i); flush();
186 lco_ignite(AO_PAD_STATIC);
187 ao_delay(AO_MS_TO_TICKS(100));
193 lco_arm_cmd(void) __reentrant
199 if (r != AO_RADIO_CMAC_OK) {
200 printf("query failed %d\n", r);
203 for (i = 0; i < 4; i++)
208 lco_ignite_cmd(void) __reentrant
212 for (i = 0; i < 4; i++)
213 lco_ignite(AO_PAD_FIRE);
219 lco_endstatic_cmd(void) __reentrant
221 lco_ignite(AO_PAD_ENDSTATIC);
225 static __code struct ao_cmds ao_lco_cmds[] = {
226 { lco_report_cmd, "l <box> <channel>\0Get remote status" },
227 { lco_fire_cmd, "F <box> <channel> <secs>\0Fire remote igniters" },
229 { lco_static_cmd, "S <box> <channel> <secs>\0Initiate static test" },
230 { lco_endstatic_cmd, "D\0End static test (and download someday)" },
232 { lco_arm_cmd, "a <box> <channel>\0Arm remote igniter" },
233 { lco_ignite_cmd, "i <box> <channel>\0Pulse remote igniter" },
238 ao_lco_cmd_init(void)
240 ao_cmd_register(&ao_lco_cmds[0]);