Add manual ignition and igniter test commands
authorKeith Packard <keithp@keithp.com>
Sun, 26 Apr 2009 22:38:28 +0000 (15:38 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 26 Apr 2009 22:38:28 +0000 (15:38 -0700)
ao_cmd.c
ao_ignite.c

index 91abe7f08837c6d321aecc038c868d6daf7ee1aa..abab1463e7740ddd4abffffdd890889f0d7dd9b7 100644 (file)
--- a/ao_cmd.c
+++ b/ao_cmd.c
@@ -214,7 +214,7 @@ echo(void)
 
 static const uint8_t help_txt[] = "All numbers are in hex";
 
-#define NUM_CMDS       10
+#define NUM_CMDS       11
 
 static __code struct ao_cmds   *__xdata (ao_cmds[NUM_CMDS]);
 static __xdata uint8_t         ao_ncmds;
index ece40bf3a3f0d357c43e983cde0bccb8a77f4a70..b89fd2f7fbb254c9a8e1ff012703fe4a5d909148 100644 (file)
@@ -117,6 +117,62 @@ ao_igniter(void)
        }
 }
 
+static uint8_t
+ao_match_word(__code uint8_t *word)
+{
+       while (*word) {
+               if (ao_cmd_lex_c != *word) {
+                       ao_cmd_status = ao_cmd_syntax_error;
+                       return 0;
+               }
+               word++;
+               ao_cmd_lex();
+       }
+       return 1;
+}
+
+void
+ao_ignite_manual(void)
+{
+       ao_cmd_white();
+       if (!ao_match_word("DoIt"))
+               return;
+       ao_cmd_white();
+       if (ao_cmd_lex_c == 'm') {
+               if(ao_match_word("main"))
+                       ao_igniter_fire(ao_igniter_main);
+       } else {
+               if(ao_match_word("drogue"))
+                       ao_igniter_fire(ao_igniter_drogue);
+       }
+}
+
+static __code uint8_t *igniter_status_names[] = {
+       "unknown", "ready", "active", "open"
+};
+
+void
+ao_ignite_print_status(enum ao_igniter igniter, __code uint8_t *name) __reentrant
+{
+       enum ao_igniter_status status = ao_igniter_status(igniter);
+       printf("Igniter: %6s Status: %s\n",
+              name,
+              igniter_status_names[status]);
+}
+
+void
+ao_ignite_test(void)
+{
+       ao_ignite_print_status(ao_igniter_drogue, "drogue");
+       ao_ignite_print_status(ao_igniter_main, "main");
+}
+
+__code struct ao_cmds ao_ignite_cmds[] = {
+       { 'i',  ao_ignite_manual,       "i <key> {main|drogue}              Fire igniter. <key> is doit with D&I" },
+       { 't',  ao_ignite_test,         "t                                  Test igniter continuity" },
+       { 0,    ao_ignite_manual,       NULL },
+};
+
 __xdata struct ao_task ao_igniter_task;
 
 void
@@ -125,5 +181,6 @@ ao_igniter_init(void)
        AO_IGNITER_DROGUE = 0;
        AO_IGNITER_MAIN = 0;
        AO_IGNITER_DIR |= AO_IGNITER_DROGUE_BIT | AO_IGNITER_MAIN_BIT;
+       ao_cmd_register(&ao_ignite_cmds[0]);
        ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
 }