X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fcore%2Fao_config.c;h=ce855ad1b51e1dcfdd6afb8d2d455fe45528e2d9;hp=a4877b069387eb54359c737bc8601be88a374e62;hb=583458772746317b98fced907ec780edff465888;hpb=4e6d96816e6604ee8d9bb49345a1c1211699a655 diff --git a/src/core/ao_config.c b/src/core/ao_config.c index a4877b06..ce855ad1 100644 --- a/src/core/ao_config.c +++ b/src/core/ao_config.c @@ -17,8 +17,11 @@ #include "ao.h" #include "ao_log.h" +#include +#if HAS_FLIGHT #include #include +#endif __xdata struct ao_config ao_config; __pdata uint8_t ao_config_loaded; @@ -78,9 +81,16 @@ ao_config_set_radio(void) static void _ao_config_get(void) { + uint8_t minor; + if (ao_config_loaded) return; #if HAS_EEPROM + /* 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 + */ + ao_storage_setup(); ao_storage_read(ao_storage_config, &ao_config, sizeof (ao_config)); #endif if (ao_config.major != AO_CONFIG_MAJOR) { @@ -92,55 +102,63 @@ _ao_config_get(void) ao_xmemset(&ao_config.callsign, '\0', sizeof (ao_config.callsign)); ao_xmemcpy(&ao_config.callsign, CODE_TO_XDATA(AO_CONFIG_DEFAULT_CALLSIGN), sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1); - ao_config_dirty = 1; } - if (ao_config.minor != AO_CONFIG_MINOR) { + minor = ao_config.minor; + if (minor != AO_CONFIG_MINOR) { /* Fixups for minor version 1 */ - if (ao_config.minor < 1) + if (minor < 1) ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY; /* Fixups for minor version 2 */ - if (ao_config.minor < 2) { + if (minor < 2) { ao_config.accel_plus_g = 0; ao_config.accel_minus_g = 0; } /* Fixups for minor version 3 */ #if HAS_RADIO - if (ao_config.minor < 3) + if (minor < 3) ao_config.radio_cal = ao_radio_cal; #endif /* Fixups for minor version 4 */ - if (ao_config.minor < 4) + if (minor < 4) ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX; /* Fixupes for minor version 5 */ - if (ao_config.minor < 5) + if (minor < 5) ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE; - if (ao_config.minor < 6) + if (minor < 6) ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION; - if (ao_config.minor < 8) + if (minor < 8) ao_config.radio_enable = TRUE; - if (ao_config.minor < 9) + if (minor < 9) ao_xmemset(&ao_config.aes_key, '\0', AO_AES_LEN); - if (ao_config.minor < 10) + if (minor < 10) ao_config.frequency = 434550; - if (ao_config.minor < 11) + if (minor < 11) ao_config.apogee_lockout = 0; +#if AO_PYRO_NUM + if (minor < 12) + memset(&ao_config.pyro, '\0', sizeof (ao_config.pyro)); +#endif ao_config.minor = AO_CONFIG_MINOR; ao_config_dirty = 1; } #if HAS_RADIO +#if HAS_FORCE_FREQ + if (ao_force_freq) + ao_config.frequency = 434550; +#endif ao_config_set_radio(); #endif ao_config_loaded = 1; } -static void +void _ao_config_edit_start(void) { ao_mutex_get(&ao_config_mutex); _ao_config_get(); } -static void +void _ao_config_edit_finish(void) { ao_config_dirty = 1; @@ -445,6 +463,9 @@ ao_config_radio_enable_set(void) __reentrant #endif /* HAS_RADIO */ #if HAS_AES + +__xdata uint8_t ao_config_aes_seq = 1; + void ao_config_key_show(void) __reentrant { @@ -467,6 +488,7 @@ ao_config_key_set(void) __reentrant break; ao_config.aes_key[i] = ao_cmd_lex_i; } + ++ao_config_aes_seq; _ao_config_edit_finish(); } #endif @@ -526,6 +548,10 @@ __code struct ao_config_var ao_config_vars[] = { #if HAS_AES { "k <32 hex digits>\0Set AES encryption key", ao_config_key_set, ao_config_key_show }, +#endif +#if AO_PYRO_NUM + { "P \0Configure pyro channels", + ao_pyro_set, ao_pyro_show }, #endif { "s\0Show", ao_config_show, 0 }, @@ -543,12 +569,10 @@ ao_config_set(void) { char c; uint8_t cmd; - void (*__xdata func)(void) __reentrant; ao_cmd_white(); c = ao_cmd_lex_c; ao_cmd_lex(); - func = 0; for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++) if (ao_config_vars[cmd].str[0] == c) { (*ao_config_vars[cmd].set)();