summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2019-06-18 14:50:53 -0700
committerKeith Packard <keithp@keithp.com>2019-06-18 14:50:53 -0700
commitee7a54b3215ffa1eb38f16a151c0740b14b60857 (patch)
tree877ff14d720edb879d12d7666a35977f7f6c8746 /src
parent6529fd623f0e4b921aea1110c723d7dc03954def (diff)
altos/micropeak-v2.0: expose log and config commands over USB
This lets AltosUI handle the eeprom data Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r--src/drivers/ao_ms5607.c4
-rw-r--r--src/kernel/ao_config.c18
-rw-r--r--src/kernel/ao_log.h5
-rw-r--r--src/micropeak-v2.0/Makefile1
-rw-r--r--src/micropeak-v2.0/ao_micropeak.c51
-rw-r--r--src/micropeak-v2.0/ao_pins.h7
6 files changed, 76 insertions, 10 deletions
diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c
index 288d14ed..16214111 100644
--- a/src/drivers/ao_ms5607.c
+++ b/src/drivers/ao_ms5607.c
@@ -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
diff --git a/src/kernel/ao_config.c b/src/kernel/ao_config.c
index 4de72c5c..f7c79e7d 100644
--- a/src/kernel/ao_config.c
+++ b/src/kernel/ao_config.c
@@ -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)
{
diff --git a/src/kernel/ao_log.h b/src/kernel/ao_log.h
index 0ab57448..97bfdc32 100644
--- a/src/kernel/ao_log.h
+++ b/src/kernel/ao_log.h
@@ -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;
diff --git a/src/micropeak-v2.0/Makefile b/src/micropeak-v2.0/Makefile
index 6bac3e29..f1f57440 100644
--- a/src/micropeak-v2.0/Makefile
+++ b/src/micropeak-v2.0/Makefile
@@ -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 \
diff --git a/src/micropeak-v2.0/ao_micropeak.c b/src/micropeak-v2.0/ao_micropeak.c
index c3f06207..dd86ba1c 100644
--- a/src/micropeak-v2.0/ao_micropeak.c
+++ b/src/micropeak-v2.0/ao_micropeak.c
@@ -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();
}
diff --git a/src/micropeak-v2.0/ao_pins.h b/src/micropeak-v2.0/ao_pins.h
index fa2ed804..8b0b2971 100644
--- a/src/micropeak-v2.0/ao_pins.h
+++ b/src/micropeak-v2.0/ao_pins.h
@@ -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__[];