altos: Fix printf format mis-matches
[fw/altos] / src / kernel / ao_config.c
index f7c79e7da0cdbff4cdc9b1b49130eecc5b560ad1..217b0ab1a8cd5145dbc6470f2c95bede280144f1 100644 (file)
@@ -86,7 +86,7 @@ _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();
@@ -138,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;
        }
@@ -171,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)
@@ -238,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;
@@ -250,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
@@ -294,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') {
@@ -307,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();
 }
@@ -363,6 +367,8 @@ ao_config_send_frequency_set(void)
 
 #if HAS_FLIGHT
 
+#if HAS_BARO
+
 static void
 ao_config_main_deploy_show(void) 
 {
@@ -381,6 +387,8 @@ ao_config_main_deploy_set(void)
        _ao_config_edit_finish();
 }
 
+#endif
+
 #if HAS_ACCEL
 static void
 ao_config_accel_calibrate_show(void) 
@@ -498,6 +506,7 @@ ao_config_accel_calibrate_set(void)
 }
 #endif /* HAS_ACCEL */
 
+#if HAS_BARO
 static void
 ao_config_apogee_delay_show(void) 
 {
@@ -533,6 +542,7 @@ ao_config_apogee_lockout_set(void)
        ao_config.apogee_lockout = r;
        _ao_config_edit_finish();
 }
+#endif
 
 #endif /* HAS_FLIGHT */
 
@@ -619,26 +629,26 @@ static void
 ao_config_log_set(void) 
 {
 #if FLIGHT_LOG_APPEND
-       printf("Flight log fixed size %d kB\n", ao_storage_log_max >> 10);
+       printf("Flight log fixed size %u kB\n", (unsigned) (ao_storage_log_max >> 10));
 #else
-       uint16_t        block = (uint16_t) (ao_storage_block >> 10);
-       uint16_t        log_max = (uint16_t) (ao_storage_log_max >> 10);
        uint32_t        r;
 
        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 && (r & (block - 1)))
-               printf("Flight log size must be multiple of %d kB\n", block);
-       else if (r > log_max)
-               printf("Flight log max %d kB\n", log_max);
-       else {
-               _ao_config_edit_start();
-               ao_config.flight_log_max = r << 10;
-               _ao_config_edit_finish();
+       r = r << 10;
+       if (ao_log_present()) {
+               if (r != ao_config.flight_log_max)
+                       printf("Storage must be empty before changing log size\n");
+               return;
+       }
+       if (r > ao_storage_log_max) {
+               printf("Flight log max %u kB\n", (unsigned) (ao_storage_log_max >> 10));
+               return;
        }
+       _ao_config_edit_start();
+       ao_config.flight_log_max = r & ~(ao_storage_block - 1);
+       _ao_config_edit_finish();
 #endif
 }
 #endif /* HAS_LOG */
@@ -760,6 +770,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
@@ -966,7 +994,7 @@ ao_config_save(void);
 #endif
 
 const struct ao_config_var ao_config_vars[] = {
-#if HAS_FLIGHT
+#if HAS_FLIGHT && HAS_BARO
        { "m <meters>\0Main deploy (m)",
          ao_config_main_deploy_set,    ao_config_main_deploy_show, },
        { "d <delay>\0Apogee delay (s)",
@@ -1041,6 +1069,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)",