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_lco_func.h>
22 #include <ao_radio_cmac.h>
24 static __pdata uint16_t lco_box;
25 static __pdata uint8_t lco_channels;
26 static __pdata uint16_t tick_offset;
29 lco_args(void) __reentrant
32 lco_box = ao_cmd_lex_i;
34 lco_channels = ao_cmd_lex_i;
37 static struct ao_pad_query ao_pad_query;
38 static uint16_t tick_offset;
44 int8_t r = AO_RADIO_CMAC_OK;
46 for (i = 0; i < 10; i++) {
47 printf ("."); flush();
48 r = ao_lco_query(lco_box, &ao_pad_query, &tick_offset);
49 if (r == AO_RADIO_CMAC_OK)
52 printf("\n"); flush();
59 ao_lco_arm(lco_box, lco_channels, tick_offset);
65 ao_lco_ignite(lco_box, lco_channels, tick_offset);
69 lco_report_cmd(void) __reentrant
75 if (ao_cmd_status != ao_cmd_success)
79 case AO_RADIO_CMAC_OK:
80 switch (ao_pad_query.arm_status) {
81 case AO_PAD_ARM_STATUS_ARMED:
84 case AO_PAD_ARM_STATUS_DISARMED:
87 case AO_PAD_ARM_STATUS_UNKNOWN:
92 for (c = 0; c < AO_PAD_MAX_CHANNELS; c++) {
93 if (ao_pad_query.channels & (1 << c)) {
94 printf (" pad %d ", c);
95 switch (ao_pad_query.igniter_status[c]) {
99 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN:
100 printf("bad-open, ");
102 case AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN:
103 printf("good-igniter, ");
105 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_CLOSED:
106 printf("bad-closed, ");
111 printf("Rssi: %d\n", ao_radio_cmac_rssi);
114 printf("Error %d\n", r);
120 lco_fire_cmd(void) __reentrant
122 static __xdata struct ao_pad_command command;
130 if (ao_cmd_status != ao_cmd_success)
133 if (r != AO_RADIO_CMAC_OK) {
134 printf("query failed %d\n", r);
138 for (i = 0; i < 4; i++) {
139 printf("arm %d\n", i); flush();
143 secs = secs * 10 - 5;
146 for (i = 0; i < secs; i++) {
147 printf("fire %d\n", i); flush();
149 ao_delay(AO_MS_TO_TICKS(100));
154 lco_arm_cmd(void) __reentrant
160 if (r != AO_RADIO_CMAC_OK) {
161 printf("query failed %d\n", r);
164 for (i = 0; i < 4; i++)
169 lco_ignite_cmd(void) __reentrant
173 for (i = 0; i < 4; i++)
177 static __code struct ao_cmds ao_lco_cmds[] = {
178 { lco_report_cmd, "l <box> <channel>\0Get remote status" },
179 { lco_fire_cmd, "F <box> <channel> <secs>\0Fire remote igniters" },
180 { lco_arm_cmd, "a <box> <channel>\0Arm remote igniter" },
181 { lco_ignite_cmd, "i <box> <channel>\0Pulse remote igniter" },
186 ao_lco_cmd_init(void)
188 ao_cmd_register(&ao_lco_cmds[0]);