X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fkernel%2Fao_config.c;h=ece60ad355124e4bdcf4a703b6e8434713f82433;hp=f7c79e7da0cdbff4cdc9b1b49130eecc5b560ad1;hb=568379f381dbb4bf587e95ce1d9c400e856ff6c6;hpb=ee7a54b3215ffa1eb38f16a151c0740b14b60857 diff --git a/src/kernel/ao_config.c b/src/kernel/ao_config.c index f7c79e7d..ece60ad3 100644 --- a/src/kernel/ao_config.c +++ b/src/kernel/ao_config.c @@ -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,13 +138,16 @@ _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; } minor = ao_config.minor; if (minor != AO_CONFIG_MINOR) { +#if AO_PYRO_NUM + ao_pyro_update_version(); +#endif /* Fixups for minor version 1 */ if (minor < 1) ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY; @@ -171,7 +174,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) @@ -190,7 +193,7 @@ _ao_config_get(void) if (minor < 14) ao_config.radio_amp = AO_CONFIG_DEFAULT_RADIO_AMP; #endif -#if HAS_GYRO +#if HAS_IMU if (minor < 15) { ao_config.accel_zero_along = 0; ao_config.accel_zero_across = 0; @@ -203,7 +206,7 @@ _ao_config_get(void) ao_config.accel_minus_g = 0; } #endif -#if HAS_BEEP_CONFIG +#if HAS_BEEP if (minor < 16) ao_config.mid_beep = AO_BEEP_MID_DEFAULT; #endif @@ -238,6 +241,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 +257,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 +301,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 +314,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 +370,8 @@ ao_config_send_frequency_set(void) #if HAS_FLIGHT +#if HAS_BARO + static void ao_config_main_deploy_show(void) { @@ -381,13 +390,15 @@ ao_config_main_deploy_set(void) _ao_config_edit_finish(); } +#endif + #if HAS_ACCEL static void ao_config_accel_calibrate_show(void) { printf("Accel cal +1g: %d -1g: %d\n", ao_config.accel_plus_g, ao_config.accel_minus_g); -#if HAS_GYRO +#if HAS_IMU printf ("IMU cal along %d across %d through %d\n", ao_config.accel_zero_along, ao_config.accel_zero_across, @@ -398,7 +409,7 @@ ao_config_accel_calibrate_show(void) #define ACCEL_CALIBRATE_SAMPLES 1024 #define ACCEL_CALIBRATE_SHIFT 10 -#if HAS_GYRO +#if HAS_IMU static int16_t accel_cal_along; static int16_t accel_cal_across; static int16_t accel_cal_through; @@ -410,7 +421,7 @@ ao_config_accel_calibrate_auto(char *orientation) uint16_t i; int32_t accel_total; uint8_t cal_data_ring; -#if HAS_GYRO +#if HAS_IMU int32_t accel_along_total = 0; int32_t accel_across_total = 0; int32_t accel_through_total = 0; @@ -428,7 +439,7 @@ ao_config_accel_calibrate_auto(char *orientation) ao_sleep(&ao_sample_data); while (i && cal_data_ring != ao_sample_data) { accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]); -#if HAS_GYRO +#if HAS_IMU accel_along_total += (int32_t) ao_data_along(&ao_data_ring[cal_data_ring]); accel_across_total += (int32_t) ao_data_across(&ao_data_ring[cal_data_ring]); accel_through_total += (int32_t) ao_data_through(&ao_data_ring[cal_data_ring]); @@ -437,7 +448,7 @@ ao_config_accel_calibrate_auto(char *orientation) i--; } } -#if HAS_GYRO +#if HAS_IMU accel_cal_along = accel_along_total >> ACCEL_CALIBRATE_SHIFT; accel_cal_across = accel_across_total >> ACCEL_CALIBRATE_SHIFT; accel_cal_through = accel_through_total >> ACCEL_CALIBRATE_SHIFT; @@ -449,35 +460,31 @@ static void ao_config_accel_calibrate_set(void) { int16_t up, down; - uint16_t r; -#if HAS_GYRO + bool auto_cal; +#if HAS_IMU 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 - r = ao_cmd_decimal(); + up = ao_cmd_decimal(); if (ao_cmd_status != ao_cmd_success) return; - if (r == 0) { + down = ao_cmd_decimal(); + auto_cal = (up == 0 && ao_cmd_status != ao_cmd_success); + if (auto_cal) { up = ao_config_accel_calibrate_auto("up"); -#if HAS_GYRO +#if HAS_IMU accel_along_up = accel_cal_along; accel_across_up = accel_cal_across; accel_through_up = accel_cal_through; #endif down = ao_config_accel_calibrate_auto("down"); -#if HAS_GYRO +#if HAS_IMU accel_along_down = accel_cal_along; accel_across_down = accel_cal_across; accel_through_down = accel_cal_through; #endif - } else { - up = r; - r = ao_cmd_decimal(); - if (ao_cmd_status != ao_cmd_success) - return; - down = r; } if (up >= down) { printf("Invalid accel: up (%d) down (%d)\n", @@ -487,17 +494,32 @@ ao_config_accel_calibrate_set(void) _ao_config_edit_start(); ao_config.accel_plus_g = up; ao_config.accel_minus_g = down; -#if HAS_GYRO - if (r == 0) { +#if HAS_IMU + if (auto_cal) { 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; + } else { + int16_t v; + + v = ao_cmd_decimal(); + if (ao_cmd_status == ao_cmd_success) { + ao_config.accel_zero_along = v; + v = ao_cmd_decimal(); + if (ao_cmd_status == ao_cmd_success) { + ao_config.accel_zero_across = v; + v = ao_cmd_decimal(); + if (ao_cmd_status == ao_cmd_success) + ao_config.accel_zero_through = v; + } + } } #endif _ao_config_edit_finish(); } #endif /* HAS_ACCEL */ +#if HAS_BARO static void ao_config_apogee_delay_show(void) { @@ -533,6 +555,7 @@ ao_config_apogee_lockout_set(void) ao_config.apogee_lockout = r; _ao_config_edit_finish(); } +#endif #endif /* HAS_FLIGHT */ @@ -619,26 +642,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 +783,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 @@ -804,7 +845,7 @@ ao_config_radio_power_set(void) #endif -#if HAS_BEEP_CONFIG +#if HAS_BEEP static void ao_config_beep_show(void) { @@ -966,7 +1007,7 @@ ao_config_save(void); #endif const struct ao_config_var ao_config_vars[] = { -#if HAS_FLIGHT +#if HAS_FLIGHT && HAS_BARO { "m \0Main deploy (m)", ao_config_main_deploy_set, ao_config_main_deploy_show, }, { "d \0Apogee delay (s)", @@ -1011,7 +1052,7 @@ const struct ao_config_var ao_config_vars[] = { ao_config_log_set, ao_config_log_show }, #endif #if HAS_IGNITE - { "i <0 dual, 1 apogee, 2 main>\0Igniter mode", + { "i <0 dual, 1 apogee, 2 main, 3 booster>\0Igniter mode", ao_config_ignite_mode_set, ao_config_ignite_mode_show }, #endif #if HAS_AES @@ -1028,7 +1069,7 @@ const struct ao_config_var ao_config_vars[] = { { "A \0APRS packet interval (0 disable)", ao_config_aprs_set, ao_config_aprs_show }, #endif -#if HAS_BEEP_CONFIG +#if HAS_BEEP { "b \0Beeper tone (freq = 1/2 (24e6/32) / beep", ao_config_beep_set, ao_config_beep_show }, #endif @@ -1041,6 +1082,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 \0APRS Offset from top of minute", + ao_config_aprs_offset_set, ao_config_aprs_offset_show }, #endif #if HAS_FIXED_PAD_BOX { "B \0Set pad box (1-99)",