2 * Copyright © 2011 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 __xdata uint16_t ao_launch_ignite;
26 while (!ao_launch_ignite)
27 ao_sleep(&ao_launch_ignite);
28 while (ao_launch_ignite) {
31 ao_ignition[ao_igniter_drogue].firing = 1;
32 ao_ignition[ao_igniter_main].firing = 1;
33 AO_IGNITER_DROGUE = 1;
34 ao_delay(AO_MS_TO_TICKS(500));
35 AO_IGNITER_DROGUE = 0;
36 ao_ignition[ao_igniter_drogue].firing = 0;
37 ao_ignition[ao_igniter_main].firing = 0;
43 ao_launch_status(void)
47 ao_delay(AO_SEC_TO_TICKS(1));
48 if (ao_igniter_status(ao_igniter_drogue) == ao_igniter_ready) {
49 if (ao_igniter_status(ao_igniter_main) == ao_igniter_ready) {
50 for (i = 0; i < 5; i++) {
51 ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(50));
52 ao_delay(AO_MS_TO_TICKS(100));
55 ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
61 static __pdata uint8_t ao_launch_armed;
62 static __pdata uint16_t ao_launch_arm_time;
67 static __xdata struct ao_launch_command command;
68 static __xdata struct ao_launch_query query;
69 int16_t time_difference;
71 ao_led_off(AO_LED_RED);
72 ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
74 if (ao_radio_cmac_recv(&command, sizeof (command), 0) != AO_RADIO_CMAC_OK)
77 printf ("tick %d serial %d cmd %d channel %d\n",
78 command.tick, command.serial, command.cmd, command.channel);
80 if (command.serial != ao_serial_number) {
81 printf ("serial number mismatch\n");
85 switch (command.cmd) {
87 if (command.channel == 0) {
89 query.arm_status = ao_igniter_status(ao_igniter_drogue);
90 query.igniter_status = ao_igniter_status(ao_igniter_main);
94 query.tick = ao_time();
95 query.serial = ao_serial_number;
96 query.channel = command.channel;
97 printf ("query tick %d serial %d channel %d valid %d arm %d igniter %d\n",
98 query.tick, query.serial, query.channel, query.valid, query.arm_status,
99 query.igniter_status);
100 ao_radio_cmac_send(&query, sizeof (query));
103 if (command.channel != 0)
105 time_difference = command.tick - ao_time();
106 printf ("arm tick %d local tick %d\n", command.tick, ao_time());
107 if (time_difference < 0)
108 time_difference = -time_difference;
109 if (time_difference > 10) {
110 printf ("time difference too large %d\n", time_difference);
115 ao_launch_arm_time = ao_time();
118 if (command.channel != 0)
120 if (!ao_launch_armed) {
121 printf ("not armed\n");
124 if ((uint16_t) (ao_launch_arm_time - ao_time()) > AO_SEC_TO_TICKS(20)) {
125 printf ("late launch arm_time %d time %d\n",
126 ao_launch_arm_time, ao_time());
129 time_difference = command.tick - ao_time();
130 if (time_difference < 0)
131 time_difference = -time_difference;
132 if (time_difference > 10) {
133 printf ("time different too large %d\n", time_difference);
137 ao_launch_ignite = 1;
138 ao_wakeup(&ao_launch_ignite);
147 switch (ao_igniter_status(ao_igniter_drogue)) {
148 case ao_igniter_ready:
149 case ao_igniter_active:
151 switch (ao_igniter_status(ao_igniter_main)) {
153 printf("unknown status\n");
155 case ao_igniter_ready:
156 printf("igniter good\n");
158 case ao_igniter_open:
159 printf("igniter bad\n");
164 printf("Disarmed\n");
169 ao_launch_manual(void)
172 if (!ao_match_word("DoIt"))
175 ao_launch_ignite = 1;
176 ao_wakeup(&ao_launch_ignite);
179 static __xdata struct ao_task ao_launch_task;
180 static __xdata struct ao_task ao_launch_ignite_task;
181 static __xdata struct ao_task ao_launch_status_task;
183 __code struct ao_cmds ao_launch_cmds[] = {
184 { ao_launch_test, "t\0Test launch continuity" },
185 { ao_launch_manual, "i <key>\0Fire igniter. <key> is doit with D&I" },
192 AO_IGNITER_DROGUE = 0;
194 AO_IGNITER_DIR |= AO_IGNITER_DROGUE_BIT | AO_IGNITER_MAIN_BIT;
195 ao_cmd_register(&ao_launch_cmds[0]);
196 ao_add_task(&ao_launch_task, ao_launch, "launch listener");
197 ao_add_task(&ao_launch_ignite_task, ao_launch_run, "launch igniter");
198 ao_add_task(&ao_launch_status_task, ao_launch_status, "launch status");