X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fcore%2Fao_config.c;h=55fb8590eb74669eb2bf9fee6b2f62f7351cc91b;hb=f952f9c285e2718a433c8c720c9b5d9c369e7036;hp=0c10e60894e57569d18a07d870610717da95c1cb;hpb=9513be7f9d3d0b0ec29f6487fa9dc8f1ac24d0de;p=fw%2Faltos diff --git a/src/core/ao_config.c b/src/core/ao_config.c index 0c10e608..55fb8590 100644 --- a/src/core/ao_config.c +++ b/src/core/ao_config.c @@ -34,11 +34,13 @@ __xdata uint8_t ao_config_mutex; #error Please define USE_INTERNAL_FLASH #endif #endif +#ifndef AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX #if USE_INTERNAL_FLASH #define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_config #else #define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ((uint32_t) 192 * (uint32_t) 1024) #endif +#endif #if HAS_EEPROM static void @@ -47,7 +49,9 @@ _ao_config_put(void) ao_storage_setup(); ao_storage_erase(ao_storage_config); ao_storage_write(ao_storage_config, &ao_config, sizeof (ao_config)); +#if HAS_FLIGHT ao_log_write_erase(0); +#endif ao_storage_flush(); } @@ -60,6 +64,12 @@ ao_config_put(void) } #endif +void +ao_config_set_radio(void) +{ + ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal); +} + static void _ao_config_get(void) { @@ -72,13 +82,15 @@ _ao_config_get(void) if (ao_config.major != AO_CONFIG_MAJOR) { ao_config.major = AO_CONFIG_MAJOR; ao_config.minor = 0; + + /* Version 0 stuff */ ao_config.main_deploy = AO_CONFIG_DEFAULT_MAIN_DEPLOY; - ao_config.radio_channel = AO_CONFIG_DEFAULT_RADIO_CHANNEL; - memset(&ao_config.callsign, '\0', sizeof (ao_config.callsign)); - memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN, + 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) { + if (ao_config.minor != AO_CONFIG_MINOR) { /* Fixups for minor version 1 */ if (ao_config.minor < 1) ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY; @@ -98,13 +110,18 @@ _ao_config_get(void) ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE; if (ao_config.minor < 6) ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION; - if (ao_config.minor < 7) - ao_config.radio_setting = ao_config.radio_cal; if (ao_config.minor < 8) ao_config.radio_enable = TRUE; + if (ao_config.minor < 9) + ao_xmemset(&ao_config.aes_key, '\0', AO_AES_LEN); + if (ao_config.minor < 10) + ao_config.frequency = 434550; + if (ao_config.minor < 11) + ao_config.apogee_lockout = 0; ao_config.minor = AO_CONFIG_MINOR; ao_config_dirty = 1; } + ao_config_set_radio(); ao_config_loaded = 1; } @@ -141,7 +158,7 @@ ao_config_callsign_set(void) __reentrant uint8_t c; static __xdata char callsign[AO_MAX_CALLSIGN + 1]; - memset(callsign, '\0', sizeof callsign); + ao_xmemset(callsign, '\0', sizeof callsign); ao_cmd_white(); c = 0; while (ao_cmd_lex_c != '\n') { @@ -154,31 +171,32 @@ ao_config_callsign_set(void) __reentrant if (ao_cmd_status != ao_cmd_success) return; _ao_config_edit_start(); - memcpy(&ao_config.callsign, &callsign, + ao_xmemcpy(&ao_config.callsign, &callsign, AO_MAX_CALLSIGN + 1); _ao_config_edit_finish(); } void -ao_config_radio_channel_show(void) __reentrant +ao_config_frequency_show(void) __reentrant { - printf("Radio channel: %d\n", - ao_config.radio_channel); + printf("Frequency: %ld\n", + ao_config.frequency); } void -ao_config_radio_channel_set(void) __reentrant +ao_config_frequency_set(void) __reentrant { ao_cmd_decimal(); if (ao_cmd_status != ao_cmd_success) return; _ao_config_edit_start(); - ao_config.radio_channel = ao_cmd_lex_i; + ao_config.frequency = ao_cmd_lex_u32; + ao_config_set_radio(); _ao_config_edit_finish(); ao_radio_recv_abort(); } -#if HAS_ADC +#if HAS_FLIGHT void ao_config_main_deploy_show(void) __reentrant @@ -282,7 +300,25 @@ ao_config_apogee_delay_set(void) __reentrant _ao_config_edit_finish(); } -#endif /* HAS_ADC */ +void +ao_config_apogee_lockout_show(void) __reentrant +{ + printf ("Apogee lockout: %d seconds\n", + ao_config.apogee_lockout); +} + +void +ao_config_apogee_lockout_set(void) __reentrant +{ + ao_cmd_decimal(); + if (ao_cmd_status != ao_cmd_success) + return; + _ao_config_edit_start(); + ao_config.apogee_lockout = ao_cmd_lex_i; + _ao_config_edit_finish(); +} + +#endif /* HAS_FLIGHT */ void ao_config_radio_cal_show(void) __reentrant @@ -297,11 +333,12 @@ ao_config_radio_cal_set(void) __reentrant if (ao_cmd_status != ao_cmd_success) return; _ao_config_edit_start(); - ao_config.radio_setting = ao_config.radio_cal = ao_cmd_lex_u32; + ao_config.radio_cal = ao_cmd_lex_u32; + ao_config_set_radio(); _ao_config_edit_finish(); } -#if HAS_EEPROM +#if HAS_LOG void ao_config_log_show(void) __reentrant { @@ -329,7 +366,7 @@ ao_config_log_set(void) __reentrant _ao_config_edit_finish(); } } -#endif /* HAS_EEPROM */ +#endif /* HAS_LOG */ #if HAS_IGNITE void @@ -377,41 +414,49 @@ ao_config_pad_orientation_set(void) __reentrant #endif void -ao_config_radio_setting_show(void) __reentrant +ao_config_radio_enable_show(void) __reentrant { - printf("Radio setting: %ld\n", ao_config.radio_setting); + printf("Radio enable: %d\n", ao_config.radio_enable); } void -ao_config_radio_setting_set(void) __reentrant +ao_config_radio_enable_set(void) __reentrant { ao_cmd_decimal(); if (ao_cmd_status != ao_cmd_success) return; _ao_config_edit_start(); - ao_config.radio_setting = ao_cmd_lex_u32; - ao_config.radio_channel = 0; + ao_config.radio_enable = ao_cmd_lex_i; _ao_config_edit_finish(); - ao_radio_recv_abort(); } - + +#if HAS_AES void -ao_config_radio_enable_show(void) __reentrant +ao_config_key_show(void) __reentrant { - printf("Radio enable: %d\n", ao_config.radio_enable); + uint8_t i; + printf("AES key: "); + for (i = 0; i < AO_AES_LEN; i++) + printf ("%02x", ao_config.aes_key[i]); + printf("\n"); } void -ao_config_radio_enable_set(void) __reentrant +ao_config_key_set(void) __reentrant { - ao_cmd_decimal(); - if (ao_cmd_status != ao_cmd_success) - return; + uint8_t i; + _ao_config_edit_start(); - ao_config.radio_enable = ao_cmd_lex_i; + for (i = 0; i < AO_AES_LEN; i++) { + ao_cmd_hexbyte(); + if (ao_cmd_status != ao_cmd_success) + break; + ao_config.aes_key[i] = ao_cmd_lex_i; + } _ao_config_edit_finish(); } - +#endif + struct ao_config_var { __code char *str; void (*set)(void) __reentrant; @@ -428,18 +473,18 @@ static void ao_config_write(void) __reentrant; __code struct ao_config_var ao_config_vars[] = { -#if HAS_ADC - { "m \0Main deploy (in meters)", +#if HAS_FLIGHT + { "m \0Main deploy (m)", ao_config_main_deploy_set, ao_config_main_deploy_show, }, - { "d \0Apogee delay (in seconds)", + { "d \0Apogee delay (s)", ao_config_apogee_delay_set, ao_config_apogee_delay_show }, -#endif /* HAS_ADC */ - { "r \0Radio channel (freq = 434.550 + chan * .1)", - ao_config_radio_channel_set, ao_config_radio_channel_show }, + { "L \0Apogee detect lockout (s)", + ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, }, +#endif /* HAS_FLIGHT */ + { "F \0Frequency (kHz)", + ao_config_frequency_set, ao_config_frequency_show }, { "c \0Callsign (8 char max)", ao_config_callsign_set, ao_config_callsign_show }, - { "R \0Radio freq control (freq = 434.550 * setting/cal)", - ao_config_radio_setting_set, ao_config_radio_setting_show }, { "e <0 disable, 1 enable>\0Enable telemetry and RDF", ao_config_radio_enable_set, ao_config_radio_enable_show }, #if HAS_ACCEL @@ -448,8 +493,8 @@ __code struct ao_config_var ao_config_vars[] = { #endif /* HAS_ACCEL */ { "f \0Radio calib (cal = rf/(xtal/2^16))", ao_config_radio_cal_set, ao_config_radio_cal_show }, -#if HAS_EEPROM - { "l \0Flight log size in kB", +#if HAS_LOG + { "l \0Flight log size (kB)", ao_config_log_set, ao_config_log_show }, #endif #if HAS_IGNITE @@ -459,6 +504,10 @@ __code struct ao_config_var ao_config_vars[] = { #if HAS_ACCEL { "o <0 antenna up, 1 antenna down>\0Set pad orientation", ao_config_pad_orientation_set,ao_config_pad_orientation_show }, +#endif +#if HAS_AES + { "k <32 hex digits>\0Set AES encryption key", + ao_config_key_set, ao_config_key_show }, #endif { "s\0Show", ao_config_show, 0 }, @@ -497,13 +546,15 @@ ao_config_help(void) __reentrant for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++) printf("%-20s %s\n", ao_config_vars[cmd].str, - ao_config_vars[cmd].str+1+strlen(ao_config_vars[cmd].str)); + ao_config_vars[cmd].str+1+ + strlen(ao_config_vars[cmd].str)); } static void ao_config_show(void) __reentrant { uint8_t cmd; + ao_config_get(); printf("Config version: %d.%d\n", ao_config.major, ao_config.minor); for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++) @@ -531,7 +582,7 @@ ao_config_write(void) __reentrant #endif __code struct ao_cmds ao_config_cmds[] = { - { ao_config_set, "c \0Set config variable (? for help, s to show)" }, + { ao_config_set, "c \0Set config (? for help, s to show)" }, { 0, NULL }, };