altos: Make cmd number parsing functions return value
authorKeith Packard <keithp@keithp.com>
Thu, 16 Aug 2018 02:13:45 +0000 (19:13 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 13 Oct 2018 15:22:50 +0000 (08:22 -0700)
Don't use a global variable to hold the result.

Signed-off-by: Keith Packard <keithp@keithp.com>
35 files changed:
src/cortexelf-v1/ao_cortexelf.c
src/drivers/ao_btm.c
src/drivers/ao_cc1120.c
src/drivers/ao_cc115l.c
src/drivers/ao_cc1200.c
src/drivers/ao_gps_ublox.c
src/drivers/ao_lco.c
src/drivers/ao_lco_cmd.c
src/drivers/ao_lco_two.c
src/drivers/ao_mpu9250.c
src/drivers/ao_pad.c
src/drivers/ao_pca9922.c
src/drivers/ao_quadrature.c
src/drivers/ao_seven_segment.c
src/drivers/ao_watchdog.c
src/kernel/ao.h
src/kernel/ao_cmd.c
src/kernel/ao_config.c
src/kernel/ao_fake_flight.c
src/kernel/ao_log.c
src/kernel/ao_log_single.c
src/kernel/ao_monitor.c
src/kernel/ao_pyro.c
src/kernel/ao_radio_cmac_cmd.c
src/kernel/ao_send_packet.c
src/kernel/ao_storage.c
src/kernel/ao_tracker.c
src/stm-vga/ao_demo.c
src/stm/ao_lcd_stm.c
src/stm/ao_pwm_stm.c
src/stmf0/ao_adc_stm.c
src/telefireone-v1.0/ao_telefireone.c
src/telelco-v2.0/ao_lco_v2.c
src/usbrelay-v0.1/ao_usbrelay.c
src/vidtime/ao_vidtime.c

index 6bc2624..1c30cd8 100644 (file)
@@ -149,17 +149,16 @@ ao_fb_init(void)
 static void
 ao_video_toggle(void)
 {
-       ao_cmd_decimal();
-       if (ao_cmd_lex_i)
+       uint16_t r = ao_cmd_decimal();
+       if (r)
                ao_fb_init();
-       ao_vga_enable(ao_cmd_lex_i);
+       ao_vga_enable(r)
 }
 
 static void
 ao_ball_toggle(void)
 {
-       ao_cmd_decimal();
-       ball_enable = ao_cmd_lex_i;
+       ball_enable = ao_cmd_decimal();
        ao_wakeup(&ball_enable);
 }
 
@@ -208,11 +207,9 @@ led_cmd(void)
 {
        uint8_t start;
        uint8_t value;
-       ao_cmd_decimal();
 
-       start = ao_cmd_lex_i;
-       ao_cmd_hex();
-       value = ao_cmd_lex_i;
+       start = ao_cmd_decimal();
+       value = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
        ao_as1107_write_8(start, value);
index 3591f8f..2930d00 100644 (file)
@@ -32,7 +32,7 @@
 int8_t                 ao_btm_stdio;
 uint8_t                ao_btm_connected;
 
-#define BT_DEBUG 0
+#define BT_DEBUG 1
 
 #if BT_DEBUG
 char           ao_btm_buffer[256];
@@ -76,6 +76,7 @@ ao_btm_dump(void)
 {
        int i;
        char c;
+       uint16_t r;
 
        for (i = 0; i < ao_btm_ptr; i++) {
                c = ao_btm_buffer[i];
@@ -85,8 +86,8 @@ ao_btm_dump(void)
                        putchar(ao_btm_buffer[i]);
        }
        putchar('\n');
-       ao_cmd_decimal();
-       if (ao_cmd_status == ao_cmd_success && ao_cmd_lex_i)
+       r = ao_cmd_decimal();
+       if (ao_cmd_status == ao_cmd_success && r)
                ao_btm_ptr = 0;
        ao_cmd_status = ao_cmd_success;
 }
@@ -94,13 +95,17 @@ ao_btm_dump(void)
 static void
 ao_btm_speed(void)
 {
-       ao_cmd_decimal();
-       if (ao_cmd_lex_u32 == 57600)
+       switch (ao_cmd_decimal()) {
+       case 57600:
                ao_serial_btm_set_speed(AO_SERIAL_SPEED_57600);
-       else if (ao_cmd_lex_u32 == 19200)
+               break;
+       case 19200:
                ao_serial_btm_set_speed(AO_SERIAL_SPEED_19200);
-       else
+               break;
+       default:
                ao_cmd_status = ao_cmd_syntax_error;
+               break;
+       }
 }
 
 static uint8_t ao_btm_enable;
index d581c24..aea0a3f 100644 (file)
@@ -805,8 +805,7 @@ ao_radio_test_cmd(void)
        static uint8_t radio_on;
        ao_cmd_white();
        if (ao_cmd_lex_c != '\n') {
-               ao_cmd_decimal();
-               mode = (uint8_t) ao_cmd_lex_u32;
+               mode = ao_cmd_decimal();
        }
        mode++;
        if ((mode & 2) && !radio_on) {
index c1c21e0..a8f2c4f 100644 (file)
@@ -700,10 +700,8 @@ ao_radio_test_cmd(void)
        uint8_t mode = 2;
        static uint8_t radio_on;
        ao_cmd_white();
-       if (ao_cmd_lex_c != '\n') {
-               ao_cmd_decimal();
-               mode = (uint8_t) ao_cmd_lex_u32;
-       }
+       if (ao_cmd_lex_c != '\n')
+               mode = ao_cmd_decimal();
        mode++;
        if ((mode & 2) && !radio_on) {
 #if HAS_MONITOR
index f2f9c37..45f5711 100644 (file)
@@ -858,10 +858,8 @@ ao_radio_test_cmd(void)
 {
        uint8_t mode = 2;
        ao_cmd_white();
-       if (ao_cmd_lex_c != '\n') {
-               ao_cmd_decimal();
-               mode = (uint8_t) ao_cmd_lex_u32;
-       }
+       if (ao_cmd_lex_c != '\n')
+               mode = ao_cmd_decimal();
        mode++;
        if ((mode & 2))
                ao_radio_test_on();
@@ -1362,14 +1360,15 @@ ao_radio_aprs(void)
 static void
 ao_radio_strobe_test(void)
 {
+       uint8_t addr;
        uint8_t r;
 
-       ao_cmd_hex();
+       addr = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       r = ao_radio_strobe(ao_cmd_lex_i);
+       r = ao_radio_strobe(addr);
        printf ("Strobe %02x -> %02x (rdy %d state %d)\n",
-               ao_cmd_lex_i,
+               addr,
                r,
                r >> 7,
                (r >> 4) & 0x7);
@@ -1381,14 +1380,12 @@ ao_radio_write_test(void)
        uint16_t        addr;
        uint8_t         data;
 
-       ao_cmd_hex();
+       addr = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       addr = ao_cmd_lex_i;
-       ao_cmd_hex();
+       data = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       data = ao_cmd_lex_i;
        printf ("Write %04x = %02x\n", addr, data);
        ao_radio_reg_write(addr, data);
 }
@@ -1399,10 +1396,9 @@ ao_radio_read_test(void)
        uint16_t        addr;
        uint8_t         data;
 
-       ao_cmd_hex();
+       addr = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       addr = ao_cmd_lex_i;
        data = ao_radio_reg_read(addr);
        printf ("Read %04x = %02x\n", addr, data);
 }
index f5268aa..a6d9308 100644 (file)
@@ -783,12 +783,12 @@ ao_gps(void)
 #if AO_UBLOX_DEBUG
 static void ao_gps_option(void)
 {
-       ao_cmd_hex();
+       uint16_t r = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success) {
                ao_cmd_status = ao_cmd_success;
                ao_gps_show();
        } else {
-               ao_gps_dbg_enable = ao_cmd_lex_i;
+               ao_gps_dbg_enable = r;
                printf ("gps debug set to %d\n", ao_gps_dbg_enable);
        }
 }
index 8663520..5f5db57 100644 (file)
@@ -319,9 +319,9 @@ ao_lco_main(void)
 void
 ao_lco_set_debug(void)
 {
-       ao_cmd_decimal();
+       uint16_t r  = ao_cmd_decimal();
        if (ao_cmd_status == ao_cmd_success)
-               ao_lco_debug = ao_cmd_lex_i != 0;
+               ao_lco_debug = r != 0;
 }
 
 const struct ao_cmds ao_lco_cmds[] = {
index 3fcdc85..6f195e5 100644 (file)
@@ -33,10 +33,8 @@ static uint16_t      tick_offset;
 static void
 lco_args(void) 
 {
-       ao_cmd_decimal();
-       lco_box = ao_cmd_lex_i;
-       ao_cmd_hex();
-       lco_channels = ao_cmd_lex_i;
+       lco_box = ao_cmd_decimal();
+       lco_channels = ao_cmd_hex();
 }
 
 static struct ao_pad_query     ao_pad_query;
@@ -129,8 +127,7 @@ lco_fire_cmd(void)
        int8_t          r;
 
        lco_args();
-       ao_cmd_decimal();
-       secs = ao_cmd_lex_i;
+       secs = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        r = lco_query();
@@ -163,8 +160,7 @@ lco_static_cmd(void)
        int8_t          r;
 
        lco_args();
-       ao_cmd_decimal();
-       secs = ao_cmd_lex_i;
+       secs = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        r = lco_query();
index 12c02e8..49ea123 100644 (file)
@@ -124,9 +124,9 @@ ao_lco_main(void)
 void
 ao_lco_set_debug(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status == ao_cmd_success)
-               ao_lco_debug = ao_cmd_lex_i;
+               ao_lco_debug = r;
 }
 
 const struct ao_cmds ao_lco_cmds[] = {
index ae8dacd..9dce9f1 100644 (file)
@@ -472,10 +472,9 @@ ao_mpu9250_read(void)
        uint8_t addr;
        uint8_t val;
 
-       ao_cmd_hex();
+       addr = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       addr = ao_cmd_lex_i;
        ao_mpu9250_spi_get();
        val = _ao_mpu9250_reg_read(addr);
        ao_mpu9250_spi_put();
@@ -488,14 +487,12 @@ ao_mpu9250_write(void)
        uint8_t addr;
        uint8_t val;
 
-       ao_cmd_hex();
+       addr = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       addr = ao_cmd_lex_i;
-       ao_cmd_hex();
+       val = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       val = ao_cmd_lex_i;
        printf("Addr %02x val %02x\n", addr, val);
        ao_mpu9250_spi_get();
        _ao_mpu9250_reg_write(addr, val);
@@ -508,10 +505,9 @@ ao_mpu9250_mag_read(void)
        uint8_t addr;
        uint8_t val;
 
-       ao_cmd_hex();
+       addr = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       addr = ao_cmd_lex_i;
        ao_mpu9250_spi_get();
        val = _ao_mpu9250_mag_reg_read(addr);
        ao_mpu9250_spi_put();
@@ -524,14 +520,12 @@ ao_mpu9250_mag_write(void)
        uint8_t addr;
        uint8_t val;
 
-       ao_cmd_hex();
+       addr = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       addr = ao_cmd_lex_i;
-       ao_cmd_hex();
+       val = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       val = ao_cmd_lex_i;
        printf("Addr %02x val %02x\n", addr, val);
        ao_mpu9250_spi_get();
        _ao_mpu9250_mag_reg_write(addr, val);
index 7e139c7..c08798a 100644 (file)
@@ -509,16 +509,14 @@ ao_pad_manual(void)
        ao_cmd_white();
        if (!ao_match_word("DoIt"))
                return;
-       ao_cmd_decimal();
+       ignite = 1 << ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       ignite = 1 << ao_cmd_lex_i;
-       ao_cmd_decimal();
+       repeat = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success) {
                repeat = 1;
                ao_cmd_status = ao_cmd_success;
-       } else
-               repeat = ao_cmd_lex_i;
+       }
        while (repeat-- > 0) {
                ao_pad_ignite = ignite;
                ao_wakeup(&ao_pad_ignite);
@@ -534,9 +532,9 @@ static struct ao_task ao_pad_monitor_task;
 void
 ao_pad_set_debug(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status == ao_cmd_success)
-               ao_pad_debug = ao_cmd_lex_i != 0;
+               ao_pad_debug = r != 0;
 }
 
 
@@ -544,14 +542,12 @@ static void
 ao_pad_alarm_debug(void)
 {
        uint8_t which, value;
-       ao_cmd_decimal();
+       which = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       which = ao_cmd_lex_i;
-       ao_cmd_decimal();
+       value = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       value = ao_cmd_lex_i;
        printf ("Set %s to %d\n", which ? "siren" : "strobe", value);
        if (which)
                ao_siren(value);
index 3516f03..91d6202 100644 (file)
@@ -72,11 +72,11 @@ ao_led_set_mask(uint8_t colors, uint8_t mask)
 static void
 ao_led_test(void)
 {
-       ao_cmd_hexbyte();
+       AO_LED_TYPE r = ao_cmd_hexbyte();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       ao_led_set(ao_cmd_lex_i);
-       printf("LEDs set to %02x\n", ao_cmd_lex_i);
+       ao_led_set(r);
+       printf("LEDs set to %x\n", r);
 }
 
 static const struct ao_cmds ao_led_cmds[] = {
index 20781c4..a5fbd1d 100644 (file)
@@ -170,8 +170,7 @@ ao_quadrature_test(void)
        int8_t t = 0;
 #endif
 
-       ao_cmd_decimal();
-       q = ao_cmd_lex_i;
+       q = ao_cmd_decimal();
        if (q >= AO_QUADRATURE_COUNT)
                ao_cmd_status = ao_cmd_syntax_error;
        if (ao_cmd_status != ao_cmd_success)
index d2e1248..1be305e 100644 (file)
@@ -209,10 +209,8 @@ static void
 ao_seven_segment_show(void)
 {
        uint8_t digit, value;
-       ao_cmd_decimal();
-       digit = ao_cmd_lex_i;
-       ao_cmd_decimal();
-       value = ao_cmd_lex_i;
+       digit = ao_cmd_decimal();
+       value = ao_cmd_decimal();
        ao_seven_segment_set(digit, value);
 }
 
index 01c3cd0..c0582c1 100644 (file)
@@ -38,9 +38,9 @@ ao_watchdog(void)
 static void
 ao_watchdog_set(void)
 {
-       ao_cmd_hex();
+       uint32_t r = ao_cmd_hex();
        if (ao_cmd_status == ao_cmd_success) {
-               ao_watchdog_enabled = ao_cmd_lex_i != 0;
+               ao_watchdog_enabled = r != 0;
                ao_wakeup(&ao_watchdog_enabled);
        }
 }
index fd1d127..3beeb88 100644 (file)
@@ -160,8 +160,6 @@ enum ao_cmd_status {
        ao_cmd_syntax_error = 2,
 };
 
-extern uint16_t ao_cmd_lex_i;
-extern uint32_t ao_cmd_lex_u32;
 extern char    ao_cmd_lex_c;
 extern enum ao_cmd_status ao_cmd_status;
 
@@ -189,13 +187,13 @@ ao_cmd_white(void);
 int8_t
 ao_cmd_hexchar(char c);
 
-void
+uint8_t
 ao_cmd_hexbyte(void);
 
-void
+uint32_t
 ao_cmd_hex(void);
 
-void
+uint32_t
 ao_cmd_decimal(void);
 
 /* Read a single hex nibble off stdin. */
index d28db5b..a72192f 100644 (file)
@@ -19,8 +19,6 @@
 #include "ao.h"
 #include "ao_task.h"
 
-uint16_t ao_cmd_lex_i;
-uint32_t ao_cmd_lex_u32;
 char   ao_cmd_lex_c;
 enum ao_cmd_status ao_cmd_status;
 
@@ -174,55 +172,49 @@ ao_cmd_hexchar(char c)
        return -1;
 }
 
-void
-ao_cmd_hexbyte(void)
+static
+uint32_t
+_ao_cmd_hex(uint8_t lim)
 {
+       uint32_t result = 0;
        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);
+       for (i = 0; i < lim; i++) {
+               int8_t n = ao_cmd_hexchar(ao_cmd_lex_c);
                if (n < 0) {
-                       ao_cmd_status = ao_cmd_syntax_error;
+                       if (i == 0 || lim != 0xff)
+                               ao_cmd_status = ao_cmd_lex_error;
                        break;
                }
-               ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
+               result = (result << 4) | n;
                ao_cmd_lex();
        }
+       return result;
 }
 
-void
-ao_cmd_hex(void)
+uint8_t
+ao_cmd_hexbyte(void)
 {
-       uint8_t r = ao_cmd_lex_error;
-       int8_t  n;
+       return _ao_cmd_hex(2);
+}
 
-       ao_cmd_lex_i = 0;
-       ao_cmd_white();
-       for(;;) {
-               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;
-               ao_cmd_lex();
-       }
-       if (r != ao_cmd_success)
-               ao_cmd_status = r;
+uint32_t
+ao_cmd_hex(void)
+{
+       return _ao_cmd_hex(0xff);
 }
 
-void
+uint32_t
 ao_cmd_decimal(void) 
 {
+       uint32_t result = 0;
        uint8_t r = ao_cmd_lex_error;
 
-       ao_cmd_lex_u32 = 0;
        ao_cmd_white();
        for(;;) {
                if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
-                       ao_cmd_lex_u32 = (ao_cmd_lex_u32 * 10) + (ao_cmd_lex_c - '0');
+                       result = result * 10 + (ao_cmd_lex_c - '0');
                else
                        break;
                r = ao_cmd_success;
@@ -230,7 +222,7 @@ ao_cmd_decimal(void)
        }
        if (r != ao_cmd_success)
                ao_cmd_status = r;
-       ao_cmd_lex_i = (uint16_t) ao_cmd_lex_u32;
+       return result;
 }
 
 uint8_t
@@ -250,9 +242,9 @@ ao_match_word(const char *word)
 static void
 echo(void)
 {
-       ao_cmd_hex();
+       uint32_t v = ao_cmd_hex();
        if (ao_cmd_status == ao_cmd_success)
-               ao_stdios[ao_cur_stdio].echo = ao_cmd_lex_i != 0;
+               ao_stdios[ao_cur_stdio].echo = v != 0;
 }
 
 static void
index 277dddd..596a041 100644 (file)
@@ -318,11 +318,11 @@ ao_config_frequency_show(void)
 void
 ao_config_frequency_set(void) 
 {
-       ao_cmd_decimal();
+       uint32_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.frequency = ao_cmd_lex_u32;
+       ao_config.frequency = r;
        ao_config_set_radio();
        _ao_config_edit_finish();
 #if HAS_RADIO_RECV
@@ -369,11 +369,11 @@ ao_config_main_deploy_show(void)
 void
 ao_config_main_deploy_set(void) 
 {
-       ao_cmd_decimal();
+       uint32_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.main_deploy = ao_cmd_lex_i;
+       ao_config.main_deploy = r;
        _ao_config_edit_finish();
 }
 
@@ -445,16 +445,17 @@ void
 ao_config_accel_calibrate_set(void) 
 {
        int16_t up, down;
+       uint16_t r;
 #if HAS_GYRO
        int16_t accel_along_up = 0, accel_along_down = 0;
        int16_t accel_across_up = 0, accel_across_down = 0;
        int16_t accel_through_up = 0, accel_through_down = 0;
 #endif
 
-       ao_cmd_decimal();
+       r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       if (ao_cmd_lex_i == 0) {
+       if (r == 0) {
                up = ao_config_accel_calibrate_auto("up");
 #if HAS_GYRO
                accel_along_up = accel_cal_along;
@@ -468,11 +469,11 @@ ao_config_accel_calibrate_set(void)
                accel_through_down = accel_cal_through;
 #endif
        } else {
-               up = ao_cmd_lex_i;
-               ao_cmd_decimal();
+               up = r;
+               r = ao_cmd_decimal();
                if (ao_cmd_status != ao_cmd_success)
                        return;
-               down = ao_cmd_lex_i;
+               down = r;
        }
        if (up >= down) {
                printf("Invalid accel: up (%d) down (%d)\n",
@@ -483,7 +484,7 @@ ao_config_accel_calibrate_set(void)
        ao_config.accel_plus_g = up;
        ao_config.accel_minus_g = down;
 #if HAS_GYRO
-       if (ao_cmd_lex_i == 0) {
+       if (r == 0) {
                ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2;
                ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2;
                ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2;
@@ -503,11 +504,11 @@ ao_config_apogee_delay_show(void)
 void
 ao_config_apogee_delay_set(void) 
 {
-       ao_cmd_decimal();
+       uint32_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.apogee_delay = ao_cmd_lex_i;
+       ao_config.apogee_delay = r;
        _ao_config_edit_finish();
 }
 
@@ -521,11 +522,11 @@ ao_config_apogee_lockout_show(void)
 void
 ao_config_apogee_lockout_set(void) 
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.apogee_lockout = ao_cmd_lex_i;
+       ao_config.apogee_lockout = r;
        _ao_config_edit_finish();
 }
 
@@ -541,11 +542,11 @@ ao_config_radio_cal_show(void)
 void
 ao_config_radio_cal_set(void) 
 {
-       ao_cmd_decimal();
+       uint32_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.radio_cal = ao_cmd_lex_u32;
+       ao_config.radio_cal = r;
        ao_config_set_radio();
        _ao_config_edit_finish();
 }
@@ -566,15 +567,15 @@ ao_config_radio_rate_show(void)
 void
 ao_config_radio_rate_set(void) 
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       if (AO_RADIO_RATE_MAX < ao_cmd_lex_i) {
+       if (AO_RADIO_RATE_MAX < r) {
                ao_cmd_status = ao_cmd_lex_error;
                return;
        }
        _ao_config_edit_start();
-       ao_config.radio_rate = ao_cmd_lex_i;
+       ao_config.radio_rate = r;
        _ao_config_edit_finish();
 #if HAS_TELEMETRY
        ao_telemetry_reset_interval();
@@ -618,19 +619,20 @@ ao_config_log_set(void)
 #else
        uint16_t        block = (uint16_t) (ao_storage_block >> 10);
        uint16_t        log_max = (uint16_t) (ao_storage_log_max >> 10);
+       uint32_t        r;
 
-       ao_cmd_decimal();
+       r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        if (ao_log_present())
                printf("Storage must be empty before changing log size\n");
-       else if (block > 1024 && (ao_cmd_lex_i & (block - 1)))
+       else if (block > 1024 && (r & (block - 1)))
                printf("Flight log size must be multiple of %d kB\n", block);
-       else if (ao_cmd_lex_i > log_max)
+       else if (r > log_max)
                printf("Flight log max %d kB\n", log_max);
        else {
                _ao_config_edit_start();
-               ao_config.flight_log_max = (uint32_t) ao_cmd_lex_i << 10;
+               ao_config.flight_log_max = r << 10;
                _ao_config_edit_finish();
        }
 #endif
@@ -647,11 +649,11 @@ ao_config_ignite_mode_show(void)
 void
 ao_config_ignite_mode_set(void) 
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.ignite_mode = ao_cmd_lex_i;
+       ao_config.ignite_mode = r;
        _ao_config_edit_finish();
 }
 #endif
@@ -670,18 +672,17 @@ ao_config_pad_orientation_show(void)
 void
 ao_config_pad_orientation_set(void) 
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal() & 1;
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_cmd_lex_i &= 1;
-       if (ao_config.pad_orientation != ao_cmd_lex_i) {
+       if (ao_config.pad_orientation != r) {
                int16_t t;
                t = ao_config.accel_plus_g;
                ao_config.accel_plus_g = AO_ACCEL_INVERT - ao_config.accel_minus_g;
                ao_config.accel_minus_g = AO_ACCEL_INVERT - t;
        }
-       ao_config.pad_orientation = ao_cmd_lex_i;
+       ao_config.pad_orientation = r;
        _ao_config_edit_finish();
 }
 #endif
@@ -696,11 +697,11 @@ ao_config_radio_enable_show(void)
 void
 ao_config_radio_enable_set(void) 
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.radio_enable = ao_cmd_lex_i;
+       ao_config.radio_enable = r;
        _ao_config_edit_finish();
 #if HAS_TELEMETRY && HAS_RADIO_RATE
        ao_telemetry_reset_interval();
@@ -729,10 +730,10 @@ ao_config_key_set(void)
 
        _ao_config_edit_start();
        for (i = 0; i < AO_AES_LEN; i++) {
-               ao_cmd_hexbyte();
+               uint8_t b = ao_cmd_hexbyte();
                if (ao_cmd_status != ao_cmd_success)
                        break;
-               ao_config.aes_key[i] = ao_cmd_lex_i;
+               ao_config.aes_key[i] = b;
        }
        ++ao_config_aes_seq;
        _ao_config_edit_finish();
@@ -750,11 +751,11 @@ ao_config_aprs_show(void)
 void
 ao_config_aprs_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.aprs_interval = ao_cmd_lex_i;
+       ao_config.aprs_interval = r;
        _ao_config_edit_finish();
        ao_telemetry_reset_interval();
 }
@@ -772,11 +773,11 @@ ao_config_radio_amp_show(void)
 void
 ao_config_radio_amp_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.radio_amp = ao_cmd_lex_i;
+       ao_config.radio_amp = r;
        _ao_config_edit_finish();
 }
 
@@ -793,11 +794,11 @@ ao_config_radio_power_show(void)
 void
 ao_config_radio_power_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.radio_power = ao_cmd_lex_i;
+       ao_config.radio_power = r;
        _ao_config_edit_finish();
 }
 
@@ -813,11 +814,11 @@ ao_config_beep_show(void)
 void
 ao_config_beep_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.mid_beep = ao_cmd_lex_i;
+       ao_config.mid_beep = r;
        _ao_config_edit_finish();
 }
 #endif
@@ -835,14 +836,12 @@ void
 ao_config_tracker_set(void)
 {
        uint16_t        m, i;
-       ao_cmd_decimal();
+       m = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       m = ao_cmd_lex_i;
-       ao_cmd_decimal();
+       i = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       i = ao_cmd_lex_i;
        _ao_config_edit_start();
        ao_config.tracker_motion = m;
        ao_config.tracker_interval = i;
@@ -863,11 +862,11 @@ ao_config_pyro_time_show(void)
 void
 ao_config_pyro_time_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.pyro_time = ao_cmd_lex_i;
+       ao_config.pyro_time = r;
        _ao_config_edit_finish();
 }
 #endif
@@ -883,26 +882,26 @@ ao_config_aprs_ssid_show(void)
 void
 ao_config_aprs_ssid_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       if (15 < ao_cmd_lex_i) {
+       if (15 < r) {
                ao_cmd_status = ao_cmd_lex_error;
                return;
        }
        _ao_config_edit_start();
-       ao_config.aprs_ssid = ao_cmd_lex_i;
+       ao_config.aprs_ssid = r;
        _ao_config_edit_finish();
 }
 
 void
 ao_config_aprs_format_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.aprs_format = ao_cmd_lex_i != 0;
+       ao_config.aprs_format = r != 0;
        _ao_config_edit_finish();
 }
 
@@ -923,11 +922,11 @@ ao_config_pad_box_show(void)
 void
 ao_config_pad_box_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.pad_box = ao_cmd_lex_i;
+       ao_config.pad_box = r;
        _ao_config_edit_finish();
 }
 
@@ -940,11 +939,11 @@ ao_config_pad_idle_show(void)
 void
 ao_config_pad_idle_set(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_config.pad_idle = ao_cmd_lex_i;
+       ao_config.pad_idle = r;
        _ao_config_edit_finish();
 }
 #endif
index 5880cf2..8da0141 100644 (file)
@@ -133,14 +133,12 @@ ao_fake_flight(void)
        enum ao_flight_state    my_state = ao_flight_invalid;
        int                     i;
 
-       ao_cmd_hex();
+       calib_size = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       calib_size = ao_cmd_lex_i;
-       ao_cmd_hex();
+       data_size = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       data_size = ao_cmd_lex_i;
        if ((unsigned) calib_size != sizeof (struct ao_fake_calib)) {
                printf ("calib size %d larger than actual size %d\n",
                        calib_size, sizeof (struct ao_fake_calib));
index 1119cce..fac211c 100644 (file)
@@ -437,10 +437,9 @@ ao_log_delete(void)
                cmd_flight = -1;
                ao_cmd_lex();
        }
-       ao_cmd_decimal();
+       cmd_flight *= ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       cmd_flight *= (int16_t) ao_cmd_lex_i;
 
        slots = ao_log_slots();
        /* Look for the flight log matching the requested flight */
index da62738..a2b63c8 100644 (file)
@@ -118,10 +118,11 @@ ao_log_single_restart(void)
 void
 ao_log_single_set(void)
 {
+       uint16_t r;
        printf("Logging currently %s\n", ao_log_running ? "on" : "off");
-       ao_cmd_hex();
+       r = ao_cmd_hex();
        if (ao_cmd_status == ao_cmd_success) {
-               if (ao_cmd_lex_i) {
+               if (r) {
                        printf("Logging from %ld to %ld\n", ao_log_current_pos, ao_log_end_pos);
                        ao_log_single_start();
                } else {
@@ -136,13 +137,12 @@ void
 ao_log_single_delete(void)
 {
        uint32_t        pos;
-
-       ao_cmd_hex();
+       uint16_t        r = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       if (ao_cmd_lex_i != 1) {
+       if (r != 1) {
                ao_cmd_status = ao_cmd_syntax_error;
-               printf("No such flight: %d\n", ao_cmd_lex_i);
+               printf("No such flight: %d\n", r);
                return;
        }
        ao_log_single_stop();
@@ -153,7 +153,7 @@ ao_log_single_delete(void)
        }
        ao_log_current_pos = ao_log_start_pos = 0;
        if (pos == 0)
-               printf("No such flight: %d\n", ao_cmd_lex_i);
+               printf("No such flight: %d\n", r);
        else
                printf ("Erased\n");
 }
index b6b8d88..3f1ff21 100644 (file)
@@ -296,8 +296,7 @@ ao_monitor_enable(void)
 static void
 set_monitor(void)
 {
-       ao_cmd_hex();
-       ao_external_monitoring = ao_cmd_lex_i;
+       ao_external_monitoring = ao_cmd_hex();
        ao_wakeup(&ao_external_monitoring);
        ao_wakeup(&ao_monitor_head);
        _ao_monitor_adjust();
index e24ab46..173cf8a 100644 (file)
@@ -484,10 +484,9 @@ ao_pyro_set(void)
        }
 #endif
 
-       ao_cmd_decimal();
+       p = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       p = ao_cmd_lex_i;
        if (AO_PYRO_NUM <= p) {
                printf ("invalid pyro channel %d\n", p);
                return;
@@ -516,25 +515,23 @@ ao_pyro_set(void)
                }
                pyro_tmp.flags |= ao_pyro_values[v].flag;
                if (ao_pyro_values[v].offset != NO_VALUE) {
-                       uint8_t negative = 0;
+                       int16_t r = 1;
                        ao_cmd_white();
                        if (ao_cmd_lex_c == '-') {
-                               negative = 1;
+                               r = -1;
                                ao_cmd_lex();
                        }
-                       ao_cmd_decimal();
+                       r *= ao_cmd_decimal();
                        if (ao_cmd_status != ao_cmd_success)
                                return;
                        if (ao_pyro_values[v].flag & AO_PYRO_8_BIT_VALUE) {
-                               if (negative) {
+                               if (r < 0) {
                                        ao_cmd_status = ao_cmd_syntax_error;
                                        return;
                                }
-                               *((uint8_t *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
+                               *((uint8_t *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = r;
                        } else {
-                               if (negative)
-                                       ao_cmd_lex_i = -ao_cmd_lex_i;
-                               *((int16_t *) (void *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
+                               *((int16_t *) (void *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = r;
                        }
                }
        }
index e5b4ffd..1433e96 100644 (file)
@@ -50,16 +50,14 @@ radio_cmac_send_cmd(void)
        uint8_t i;
        uint8_t len;
 
-       ao_cmd_decimal();
+       len = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       len = ao_cmd_lex_i;
        if (len > AO_CMAC_MAX_LEN) {
                ao_cmd_status = ao_cmd_syntax_error;
                return;
        }
        flush();
-       len = ao_cmd_lex_i;
        for (i = 0; i < len; i++) {
                cmac_data[i] = getbyte();
                if (ao_cmd_status != ao_cmd_success)
@@ -74,14 +72,12 @@ radio_cmac_recv_cmd(void)
        uint8_t         len, i;
        uint16_t        timeout;
 
-       ao_cmd_decimal();
+       len = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       len = ao_cmd_lex_i;
-       ao_cmd_decimal();
+       timeout = AO_MS_TO_TICKS(ao_cmd_decimal());
        if (ao_cmd_status != ao_cmd_success)
                return;
-       timeout = AO_MS_TO_TICKS(ao_cmd_lex_i);
        i = ao_radio_cmac_recv(cmac_data, len, timeout);
        if (i == AO_RADIO_CMAC_OK) {
                printf ("PACKET ");
index 3206b2d..cae2515 100644 (file)
@@ -29,8 +29,7 @@ ao_send_packet(void)
        uint8_t b;
        uint8_t i;
 
-       ao_cmd_hex();
-       count = ao_cmd_lex_i;
+       count = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
        if (count > AO_MAX_SEND - 2) {
index 5292e12..890bdca 100644 (file)
@@ -92,15 +92,16 @@ static uint8_t storage_data[128];
 static void
 ao_storage_dump(void) 
 {
+       uint32_t block;
        uint8_t i, j;
 
-       ao_cmd_hex();
+       block = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
        for (i = 0; ; i += 8) {
-               if (ao_storage_read(((uint32_t) (ao_cmd_lex_i) << 8) + i,
-                                 storage_data,
-                                 8)) {
+               if (ao_storage_read((block << 8) + i,
+                                   storage_data,
+                                   8)) {
                        ao_cmd_put16((uint16_t) i);
                        for (j = 0; j < 8; j++) {
                                putchar(' ');
@@ -123,23 +124,19 @@ ao_storage_store(void)
        uint16_t block;
        uint8_t i;
        uint16_t len;
-       static uint8_t b;
+       uint8_t b;
        uint32_t addr;
 
-       ao_cmd_hex();
-       block = ao_cmd_lex_i;
-       ao_cmd_hex();
-       i = ao_cmd_lex_i;
+       block = ao_cmd_hex();
+       i = ao_cmd_hex();
        addr = ((uint32_t) block << 8) | i;
-       ao_cmd_hex();
-       len = ao_cmd_lex_i;
+       len = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
        while (len--) {
-               ao_cmd_hex();
+               b = ao_cmd_hexbyte();
                if (ao_cmd_status != ao_cmd_success)
                        return;
-               b = ao_cmd_lex_i;
                ao_storage_write(addr, &b, 1);
                addr++;
        }
@@ -149,10 +146,10 @@ ao_storage_store(void)
 void
 ao_storage_zap(void) 
 {
-       ao_cmd_hex();
+       uint32_t v = ao_cmd_hex();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       ao_storage_erase((uint32_t) ao_cmd_lex_i << 8);
+       ao_storage_erase((uint32_t) v << 8);
 }
 
 void
index 4627853..f79bd18 100644 (file)
@@ -211,9 +211,9 @@ static struct ao_task ao_tracker_task;
 static void
 ao_tracker_set_telem(void)
 {
-       ao_cmd_hex();
+       uint16_t r = ao_cmd_hex();
        if (ao_cmd_status == ao_cmd_success)
-               ao_tracker_force_telem = ao_cmd_lex_i;
+               ao_tracker_force_telem = r;
        ao_cmd_status = ao_cmd_success;
        printf ("flight: %d\n", ao_flight_number);
        printf ("force_telem: %d\n", ao_tracker_force_telem);
index 63740f8..593a874 100644 (file)
@@ -159,17 +159,16 @@ ao_fb_init(void)
 static void
 ao_video_toggle(void)
 {
-       ao_cmd_decimal();
-       if (ao_cmd_lex_i)
+       uint16_t r = ao_cmd_decimal();
+       if (r)
                ao_fb_init();
-       ao_vga_enable(ao_cmd_lex_i);
+       ao_vga_enable(r);
 }
 
 static void
 ao_ball_toggle(void)
 {
-       ao_cmd_decimal();
-       ball_enable = ao_cmd_lex_i;
+       ball_enable = ao_cmd_decimal();
        ao_wakeup(&ball_enable);
 }
 
index 10d5d62..1947012 100644 (file)
@@ -326,12 +326,9 @@ ao_lcd_stm_seg_set(void)
 {
        int     com, seg, val;
        int     n, bit;
-       ao_cmd_decimal();
-       com = ao_cmd_lex_i;
-       ao_cmd_decimal();
-       seg = ao_cmd_lex_u32;
-       ao_cmd_decimal();
-       val = ao_cmd_lex_i;
+       com = ao_cmd_decimal();
+       seg = ao_cmd_decimal();
+       val = ao_cmd_decimal();
        printf ("com: %d seg: %d val: %d\n", com, seg, val);
        ao_lcd_set(com, seg, val);
        ao_lcd_flush();
index 53000a1..341f888 100644 (file)
@@ -107,10 +107,8 @@ ao_pwm_cmd(void)
        uint8_t ch;
        uint16_t val;
 
-       ao_cmd_decimal();
-       ch = ao_cmd_lex_u32;
-       ao_cmd_decimal();
-       val = ao_cmd_lex_u32;
+       ch = ao_cmd_decimal();
+       val = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
 
index 571830b..e62bb16 100644 (file)
@@ -103,10 +103,9 @@ ao_adc_one(void)
        int             ch;
        uint16_t        value;
 
-       ao_cmd_decimal();
+       ch = ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
-       ch = ao_cmd_lex_i;
        if (ch < 0 || AO_NUM_ADC <= ch) {
                ao_cmd_status = ao_cmd_syntax_error;
                return;
index 790d7a4..6506235 100644 (file)
@@ -26,8 +26,7 @@
 static void
 set_logging(void)
 {
-       ao_cmd_hex();
-       ao_log_running = ao_cmd_lex_i;
+       ao_log_running = ao_cmd_hex();
        ao_wakeup(&ao_log_running);
 }
 
index 428b1a7..90324cc 100644 (file)
@@ -282,9 +282,9 @@ ao_lco_main(void)
 void
 ao_lco_set_debug(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status == ao_cmd_success)
-               ao_lco_debug = ao_cmd_lex_i != 0;
+               ao_lco_debug = r != 0;
 }
 
 const struct ao_cmds ao_lco_cmds[] = {
index 0eacdf5..946f4b1 100644 (file)
@@ -49,10 +49,9 @@ ao_relay_select(void)
 {
        uint8_t output;
 
-       ao_cmd_decimal();
+       output = ao_cmd_decimal();
         if (ao_cmd_status != ao_cmd_success)
                 return;
-       output = ao_cmd_lex_i;
        if (output > 1) 
                printf ("Invalid relay position %u\n", output);
        else
index 1b9b9e1..e9f8b21 100644 (file)
@@ -63,9 +63,9 @@ ao_init_vidtime(void)
 static void
 ao_set_vidtime(void)
 {
-       ao_cmd_decimal();
+       uint16_t r = ao_cmd_decimal();
        if (ao_cmd_status == ao_cmd_success) {
-               vidtime_monitor = ao_cmd_lex_i != 0;
+               vidtime_monitor = r != 0;
                ao_wakeup(&vidtime_monitor);
        }
 }