altos: Allow flight support without logging
[fw/altos] / src / kernel / ao_config.c
index fb7d333b42b4aaef6ea1837c1fa46087a5d04ec1..e4fc73c99059aadac5c7e9360f702a43770fb7d6 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,14 +79,14 @@ 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)
 {
        ao_config_setup();
        ao_config_erase();
        ao_config_write(0, &ao_config, sizeof (ao_config));
-#if HAS_FLIGHT
+#if HAS_FLIGHT && HAS_LOG
        ao_log_write_erase(0);
 #endif
        ao_config_flush();
@@ -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
@@ -134,8 +138,8 @@ _ao_config_get(void)
 
                /* Version 0 stuff */
                ao_config.main_deploy = AO_CONFIG_DEFAULT_MAIN_DEPLOY;
-               ao_xmemset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
-               ao_xmemcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
+               memset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
+               memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
                       sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
                ao_config._legacy_radio_channel = 0;
        }
@@ -167,7 +171,7 @@ _ao_config_get(void)
                if (minor < 8)
                        ao_config.radio_enable = AO_RADIO_ENABLE_CORE;
                if (minor < 9)
-                       ao_xmemset(&ao_config.aes_key, '\0', AO_AES_LEN);
+                       memset(&ao_config.aes_key, '\0', AO_AES_LEN);
                if (minor < 10)
                        ao_config.frequency = 434550 + ao_config._legacy_radio_channel * 100;
                if (minor < 11)
@@ -234,6 +238,10 @@ _ao_config_get(void)
                        ao_config.pad_box = 1;
                if (minor < 23)
                        ao_config.pad_idle = 120;
+#endif
+#if HAS_APRS
+               if (minor < 24)
+                       ao_config.aprs_offset = 0;
 #endif
                ao_config.minor = AO_CONFIG_MINOR;
                ao_config_dirty = 1;
@@ -246,7 +254,7 @@ _ao_config_get(void)
 #if HAS_RADIO_RATE
                ao_config.radio_rate = AO_CONFIG_DEFAULT_RADIO_RATE;
 #endif
-               ao_xmemcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
+               memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
                       sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
        }
 #endif
@@ -290,7 +298,7 @@ ao_config_callsign_set(void)
        uint8_t c;
        static char callsign[AO_MAX_CALLSIGN + 1];
 
-       ao_xmemset(callsign, '\0', sizeof callsign);
+       memset(callsign, '\0', sizeof callsign);
        ao_cmd_white();
        c = 0;
        while (ao_cmd_lex_c != '\n') {
@@ -303,7 +311,7 @@ ao_config_callsign_set(void)
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       ao_xmemcpy(&ao_config.callsign, &callsign,
+       memcpy(&ao_config.callsign, &callsign,
               AO_MAX_CALLSIGN + 1);
        _ao_config_edit_finish();
 }
@@ -597,7 +605,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)
 {
@@ -665,10 +673,6 @@ ao_config_pad_orientation_show(void)
        printf("Pad orientation: %d\n", ao_config.pad_orientation);
 }
 
-#ifndef AO_ACCEL_INVERT
-#define AO_ACCEL_INVERT        0x7fff
-#endif
-
 static void
 ao_config_pad_orientation_set(void) 
 {
@@ -677,10 +681,10 @@ ao_config_pad_orientation_set(void)
                return;
        _ao_config_edit_start();
        if (ao_config.pad_orientation != r) {
-               int16_t t;
+               accel_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.accel_plus_g = ao_data_accel_invert(ao_config.accel_minus_g);
+               ao_config.accel_minus_g = ao_data_accel_invert(t);
        }
        ao_config.pad_orientation = r;
        _ao_config_edit_finish();
@@ -760,6 +764,24 @@ ao_config_aprs_set(void)
        ao_telemetry_reset_interval();
 }
 
+static void
+ao_config_aprs_offset_show(void)
+{
+       printf ("APRS offset: %d\n", ao_config.aprs_offset);
+}
+
+static void
+ao_config_aprs_offset_set(void)
+{
+       uint16_t r = ao_cmd_decimal();
+       if (ao_cmd_status != ao_cmd_success)
+               return;
+       _ao_config_edit_start();
+       ao_config.aprs_offset = r;
+       _ao_config_edit_finish();
+       ao_telemetry_reset_interval();
+}
+
 #endif /* HAS_APRS */
 
 #if HAS_RADIO_AMP
@@ -960,7 +982,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
@@ -1041,6 +1063,8 @@ const struct ao_config_var ao_config_vars[] = {
          ao_config_aprs_ssid_set, ao_config_aprs_ssid_show },
        { "C <0 compressed, 1 uncompressed>\0APRS format",
          ao_config_aprs_format_set, ao_config_aprs_format_show },
+       { "O <aprs-offset>\0APRS Offset from top of minute",
+         ao_config_aprs_offset_set, ao_config_aprs_offset_show },
 #endif
 #if HAS_FIXED_PAD_BOX
        { "B <box>\0Set pad box (1-99)",
@@ -1050,7 +1074,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
@@ -1102,7 +1126,7 @@ ao_config_show(void)
 #endif
 }
 
-#if HAS_EEPROM
+#if HAS_CONFIG_SAVE
 static void
 ao_config_save(void) 
 {