__pdata char ao_cmd_lex_c;
__pdata enum ao_cmd_status ao_cmd_status;
-#define CMD_LEN 32
+#define CMD_LEN 48
static __xdata char cmd_line[CMD_LEN];
static __pdata uint8_t cmd_len;
static __pdata uint8_t cmd_i;
-static void
-put_string(__code char *s)
+void
+ao_put_string(__code char *s)
{
char c;
- while (c = *s++)
+ while ((c = *s++))
putchar(c);
}
+static void
+backspace(void)
+{
+ ao_put_string ("\010 \010");
+}
+
static void
readline(void)
{
- __pdata char c;
+ char c;
if (ao_echo())
- put_string("> ");
+ ao_put_string("> ");
cmd_len = 0;
for (;;) {
flush();
if (c == '\010' || c == '\177') {
if (cmd_len != 0) {
if (ao_echo())
- put_string("\010 \010");
+ backspace();
--cmd_len;
}
continue;
if (c == '\025') {
while (cmd_len != 0) {
if (ao_echo())
- put_string("\010 \010");
+ backspace();
--cmd_len;
}
continue;
break;
}
- if (cmd_len >= CMD_LEN - 2) {
- if (ao_echo())
- putchar('\007');
+ if (cmd_len >= CMD_LEN - 2)
continue;
- }
cmd_line[cmd_len++] = c;
if (ao_echo())
putchar(c);
putchar(v + ('a' - 10));
}
+uint8_t
+ao_getnibble(void)
+{
+ char c;
+
+ c = getchar();
+ if ('0' <= c && c <= '9')
+ return c - '0';
+ if ('a' <= c && c <= 'f')
+ return c - ('a' - 10);
+ if ('A' <= c && c <= 'F')
+ return c - ('A' - 10);
+ ao_cmd_status = ao_cmd_lex_error;
+ return 0;
+}
+
void
ao_cmd_put16(uint16_t v)
{
putnibble(v & 0xf);
}
+uint8_t
+ao_cmd_is_white(void)
+{
+ return ao_cmd_lex_c == ' ' || ao_cmd_lex_c == '\t';
+}
+
void
ao_cmd_white(void)
{
- while (ao_cmd_lex_c == ' ' || ao_cmd_lex_c == '\t')
+ while (ao_cmd_is_white())
+ ao_cmd_lex();
+}
+
+int8_t
+ao_cmd_hexchar(char c)
+{
+ if ('0' <= c && c <= '9')
+ return (c - '0');
+ if ('a' <= c && c <= 'f')
+ return (c - 'a' + 10);
+ if ('A' <= c && c <= 'F')
+ return (c - 'A' + 10);
+ return -1;
+}
+
+void
+ao_cmd_hexbyte(void)
+{
+ uint8_t i;
+ int8_t n;
+
+ ao_cmd_lex_i = 0;
+ ao_cmd_white();
+ for (i = 0; i < 2; i++) {
+ n = ao_cmd_hexchar(ao_cmd_lex_c);
+ if (n < 0) {
+ ao_cmd_status = ao_cmd_syntax_error;
+ break;
+ }
+ ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
ao_cmd_lex();
+ }
}
void
ao_cmd_hex(void)
{
__pdata uint8_t r = ao_cmd_lex_error;
- uint8_t n;
+ int8_t n;
ao_cmd_lex_i = 0;
ao_cmd_white();
for(;;) {
- if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
- n = (ao_cmd_lex_c - '0');
- else if ('a' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'f')
- n = (ao_cmd_lex_c - 'a' + 10);
- else if ('A' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'F')
- n = (ao_cmd_lex_c - 'A' + 10);
- else
+ n = ao_cmd_hexchar(ao_cmd_lex_c);
+ if (n < 0)
break;
ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
r = ao_cmd_success;
return 1;
}
-static void
-eol(void)
-{
- while (ao_cmd_lex_c != '\n')
- ao_cmd_lex();
-}
-
static void
echo(void)
{
ao_cmd_white();
if (!ao_match_word("eboot"))
return;
- WDCTL = WDCTL_EN | WDCTL_MODE_WATCHDOG | WDCTL_INT_64;
- ao_delay(AO_SEC_TO_TICKS(2));
+ /* Delay waiting for the packet master to be turned off
+ * so that we don't end up back in idle mode because we
+ * received a packet after boot.
+ */
+ flush();
+ ao_delay(AO_SEC_TO_TICKS(1));
+ ao_arch_reboot();
ao_panic(AO_PANIC_REBOOT);
}
static void
version(void)
{
- printf("manufacturer %s\n", ao_manufacturer);
- printf("product %s\n", ao_product);
- printf("serial-number %u\n", ao_serial_number);
-#if HAS_EEPROM
- printf("log-format %u\n", ao_log_format);
+ printf("manufacturer %s\n"
+ "product %s\n"
+ "serial-number %u\n"
+#if HAS_FLIGHT
+ "current-flight %u\n"
+#endif
+#if HAS_LOG
+ "log-format %u\n"
+#endif
+ , ao_manufacturer
+ , ao_product
+ , ao_serial_number
+#if HAS_FLIGHT
+ , ao_flight_number
+#endif
+#if HAS_LOG
+ , ao_log_format
+#endif
+ );
+#if HAS_MS5607
+ ao_ms5607_info();
#endif
printf("software-version %s\n", ao_version);
}
+#ifndef NUM_CMDS
#define NUM_CMDS 11
+#endif
static __code struct ao_cmds *__xdata (ao_cmds[NUM_CMDS]);
static __pdata uint8_t ao_ncmds;
static void
help(void)
{
- register uint8_t cmds;
- register uint8_t cmd;
- register __code struct ao_cmds * cs;
+ __pdata uint8_t cmds;
+ __pdata uint8_t cmd;
+ __code struct ao_cmds * __pdata cs;
+ __code const char *h;
+ uint8_t e;
for (cmds = 0; cmds < ao_ncmds; cmds++) {
cs = ao_cmds[cmds];
- for (cmd = 0; cs[cmd].func; cmd++)
- printf("%-45s %s\n",
- cs[cmd].help,
- cs[cmd].help+1+strlen(cs[cmd].help));
+ for (cmd = 0; cs[cmd].func; cmd++) {
+ h = cs[cmd].help;
+ ao_put_string(h);
+ e = strlen(h);
+ h += e + 1;
+ e = 45 - e;
+ while (e--)
+ putchar(' ');
+ ao_put_string(h);
+ putchar('\n');
+ }
}
}
case ao_cmd_syntax_error:
puts("Syntax error");
ao_cmd_status = 0;
+ default:
break;
}
}
void
ao_cmd(void)
{
- char c;
+ __pdata char c;
uint8_t cmd, cmds;
__code struct ao_cmds * __xdata cs;
void (*__xdata func)(void);
__code struct ao_cmds ao_base_cmds[] = {
{ help, "?\0Help" },
- { ao_task_info, "T\0Show tasks" },
- { echo, "E <0 off, 1 on>\0Set echo mode" },
+ { ao_task_info, "T\0Tasks" },
+ { echo, "E <0 off, 1 on>\0Echo" },
{ ao_reboot, "r eboot\0Reboot" },
{ version, "v\0Version" },
{ 0, NULL },