altos/micropeak-v2.0: expose log and config commands over USB
authorKeith Packard <keithp@keithp.com>
Tue, 18 Jun 2019 21:50:53 +0000 (14:50 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 18 Jun 2019 21:50:53 +0000 (14:50 -0700)
This lets AltosUI handle the eeprom data

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_ms5607.c
src/kernel/ao_config.c
src/kernel/ao_log.h
src/micropeak-v2.0/Makefile
src/micropeak-v2.0/ao_micropeak.c
src/micropeak-v2.0/ao_pins.h

index 288d14ed23d1b00f269055423d5c3aa7bdfb6bb0..162141115c01c5f7e7f2abbab541bc9b5622b486 100644 (file)
@@ -240,6 +240,9 @@ struct ao_task ao_ms5607_task;
 void
 ao_ms5607_info(void)
 {
+#if !HAS_MS5607_TASK
+       ao_ms5607_setup();
+#endif
        printf ("ms5607 reserved: %u\n", ao_ms5607_prom.reserved);
        printf ("ms5607 sens: %u\n", ao_ms5607_prom.sens);
        printf ("ms5607 off: %u\n", ao_ms5607_prom.off);
@@ -256,7 +259,6 @@ ao_ms5607_dump(void)
        struct ao_ms5607_value value;
 
 #if !HAS_MS5607_TASK
-       ao_ms5607_setup();
        ao_ms5607_info();
        ao_ms5607_sample(&ao_ms5607_current);
 #endif
index 4de72c5cd751dbd1994f1277f873b8c7a71c82c2..f7c79e7da0cdbff4cdc9b1b49130eecc5b560ad1 100644 (file)
@@ -39,6 +39,10 @@ uint8_t ao_config_mutex;
 uint8_t ao_force_freq;
 #endif
 
+#ifndef HAS_CONFIG_SAVE
+#define HAS_CONFIG_SAVE        HAS_EEPROM
+#endif
+
 #ifndef AO_CONFIG_DEFAULT_APRS_INTERVAL
 #define AO_CONFIG_DEFAULT_APRS_INTERVAL        0
 #endif
@@ -50,7 +54,7 @@ uint8_t ao_force_freq;
 #define AO_CONFIG_DEFAULT_IGNITE_MODE  AO_IGNITE_MODE_DUAL
 #define AO_CONFIG_DEFAULT_PAD_ORIENTATION      AO_PAD_ORIENTATION_ANTENNA_UP
 #define AO_CONFIG_DEFAULT_PYRO_TIME    AO_MS_TO_TICKS(50)
-#if HAS_EEPROM
+#if HAS_CONFIG_SAVE
 #ifndef USE_INTERNAL_FLASH
 #error Please define USE_INTERNAL_FLASH
 #endif
@@ -75,7 +79,7 @@ uint8_t ao_force_freq;
 #define AO_CONFIG_DEFAULT_APRS_SSID            (ao_serial_number % 10)
 #define AO_CONFIG_DEFAULT_RADIO_RATE           AO_RADIO_RATE_38400
 
-#if HAS_EEPROM
+#if HAS_CONFIG_SAVE
 static void
 _ao_config_put(void)
 {
@@ -120,7 +124,7 @@ _ao_config_get(void)
 
        if (ao_config_loaded)
                return;
-#if HAS_EEPROM
+#if HAS_CONFIG_SAVE
        /* Yes, I know ao_storage_read calls ao_storage_setup,
         * but ao_storage_setup *also* sets ao_storage_config, which we
         * need before calling ao_storage_read here
@@ -597,7 +601,7 @@ ao_config_log_show(void)
 #endif
 }
 
-#if FLIGHT_LOG_APPEND
+#if FLIGHT_LOG_APPEND && HAS_CONFIG_SAVE
 void
 ao_config_log_fix_append(void)
 {
@@ -956,7 +960,7 @@ ao_config_help(void);
 static void
 ao_config_show(void);
 
-#if HAS_EEPROM
+#if HAS_CONFIG_SAVE
 static void
 ao_config_save(void);
 #endif
@@ -1046,7 +1050,7 @@ const struct ao_config_var ao_config_vars[] = {
 #endif
        { "s\0Show",
          ao_config_show,               0 },
-#if HAS_EEPROM
+#if HAS_CONFIG_SAVE
        { "w\0Write to eeprom",
          ao_config_save,               0 },
 #endif
@@ -1098,7 +1102,7 @@ ao_config_show(void)
 #endif
 }
 
-#if HAS_EEPROM
+#if HAS_CONFIG_SAVE
 static void
 ao_config_save(void) 
 {
index 0ab574483993dd50a537d9b95e45c55b00fc77bc..97bfdc3273076cf0ab80272fb6e4fee88e31c156 100644 (file)
@@ -57,6 +57,7 @@ extern enum ao_flight_state ao_log_state;
 #define AO_LOG_FORMAT_TELEMEGA_3       15      /* 32 byte typed telemega records with 32 bit gyro cal and mpu9250 */
 #define AO_LOG_FORMAT_EASYMEGA_2       16      /* 32 byte typed telemega records with 32 bit gyro cal, mpu9250 rotated 90° and adxl375 */
 #define AO_LOG_FORMAT_TELESTATIC       17      /* 32 byte typed telestatic records */
+#define AO_LOG_FORMAT_MICROPEAK2       18      /* 2-byte baro values with header */
 #define AO_LOG_FORMAT_NONE             127     /* No log at all */
 
 /* Return the flight number from the given log slot, 0 if none, -slot on failure */
@@ -539,6 +540,10 @@ typedef struct ao_log_record ao_log_type;
 #define AO_LOG_UNCOMMON        1
 #endif
 
+#if AO_LOG_FORMAT == AO_LOG_FORMAT_MICROPEAK2
+#define AO_LOG_UNCOMMON        1
+#endif
+
 #ifndef AO_LOG_UNCOMMON
 extern ao_log_type ao_log_data;
 
index 6bac3e2917cef292ab84ebe2d703abdbc0e0f371..f1f57440a89c30f8ad42409c1fdaaac04fa1b096 100644 (file)
@@ -32,6 +32,7 @@ ALTOS_SRC = \
        ao_mutex.c \
        ao_interrupt.c \
        ao_cmd.c \
+       ao_config.c \
        ao_task.c \
        ao_data.c \
        ao_boot_chain.c \
index c3f06207a5cd3bd4962589eb974d5f7a03d8619c..dd86ba1c70c2368fbbde98da38a7194bc79a8491 100644 (file)
@@ -171,7 +171,6 @@ static void
 ao_micropeak(void)
 {
        ao_ms5607_setup();
-       ao_storage_setup();
 
        /* Give the person a second to get their finger out of the way */
        ao_delay(AO_MS_TO_TICKS(1000));
@@ -204,7 +203,54 @@ ao_show_bat(void)
        printf("battery: %u\n", ao_battery_voltage());
 }
 
+uint8_t
+ao_log_present(void)
+{
+       uint16_t        n_samples;
+
+       ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
+
+       return n_samples != 0xffff;
+}
+
+static void
+ao_log_list(void)
+{
+       if (ao_log_present())
+               printf ("flight %d start %x end %x\n",
+                       1,
+                       0, MAX_LOG_OFFSET >> 8);
+       printf ("done\n");
+}
+
+static void
+ao_log_delete(void)
+{
+       int16_t cmd_flight = 1;
+
+       ao_cmd_white();
+       if (ao_cmd_lex_c == '-') {
+               cmd_flight = -1;
+               ao_cmd_lex();
+       }
+       cmd_flight *= ao_cmd_decimal();
+       if (ao_cmd_status != ao_cmd_success)
+               return;
+
+       /* Look for the flight log matching the requested flight */
+       if (cmd_flight == 1 && ao_log_present()) {
+               uint32_t        pos;
+               for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
+                       ao_storage_erase(pos);
+               puts("Erased");
+               return;
+       }
+       printf("No such flight: %d\n", cmd_flight);
+}
+
 static struct ao_cmds mp_cmd[] = {
+       { ao_log_list,  "l\0List logs" },
+       { ao_log_delete,        "d <flight-number>\0Delete flight" },
        { ao_show_bat, "b\0Show battery voltage" },
        { 0 }
 };
@@ -268,6 +314,8 @@ main(void)
        ao_spi_init();
        ao_exti_init();
 
+       ao_storage_setup();
+
        ao_ms5607_init();
        ao_storage_init();
 
@@ -279,6 +327,7 @@ main(void)
                ao_usb_init();
                ao_cmd_init();
                ao_cmd_register(mp_cmd);
+               ao_config_init();
        }
        ao_start_scheduler();
 }
index fa2ed804f6a6bccce59043c4f7433ae4d47f042f..8b0b29718b5cce374c4b7d3f1846edfb753f83fb 100644 (file)
@@ -65,7 +65,8 @@ extern uint8_t ao_on_battery;
 #define HAS_MS5607             1
 #define HAS_MS5611             0
 #define HAS_MS5607_TASK                0
-#define HAS_EEPROM             0
+#define HAS_EEPROM             1
+#define HAS_CONFIG_SAVE                0
 #define HAS_BEEP               0
 
 /* Logging */
@@ -73,6 +74,9 @@ extern uint8_t ao_on_battery;
 #define SAMPLE_SLEEP           AO_MS_TO_TICKS(100)
 #define BOOST_DELAY            AO_SEC_TO_TICKS(60)
 #define AO_LOG_ID              AO_LOG_ID_MICRO_PEAK2
+#define HAS_LOG                        1
+#define AO_LOG_FORMAT          AO_LOG_FORMAT_MICROPEAK2
+#define FLIGHT_LOG_APPEND      1
 
 /* Kalman filter */
 
@@ -135,6 +139,7 @@ void ao_delay_until(uint16_t target);
 #define ao_eeprom_read(pos, ptr, size) ao_storage_read(pos, ptr, size)
 #define ao_eeprom_write(pos, ptr, size) ao_storage_write(pos, ptr, size)
 #define MAX_LOG_OFFSET ao_storage_total
+#define ao_storage_log_max ao_storage_total
 
 extern uint32_t __flash__[];
 extern uint32_t __flash_end__[];