From 1bb3ab87156335013f487ee6b0d9f3e72f0c1b4d Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Fri, 21 Apr 2023 06:46:10 +0300 Subject: [PATCH] New option to save signal names with timestamps --- .../scenes/subghz_scene_ext_module_settings.c | 36 +++++++++-- .../subghz/scenes/subghz_scene_save_name.c | 59 +++++++++++++++---- .../main/subghz/subghz_last_settings.c | 20 +++++++ .../main/subghz/subghz_last_settings.h | 1 + firmware/targets/f7/api_symbols.csv | 2 + .../targets/f7/furi_hal/furi_hal_subghz.c | 9 +++ .../targets/f7/furi_hal/furi_hal_subghz.h | 9 +++ 7 files changed, 119 insertions(+), 17 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c b/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c index a96208074..75a2215fc 100644 --- a/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c @@ -1,10 +1,11 @@ #include "../subghz_i.h" #include "../helpers/subghz_custom_event.h" -uint8_t value_index_exm; -uint8_t value_index_dpin; -uint8_t value_index_cnt; -uint8_t value_index_pwr; +static uint8_t value_index_exm; +static uint8_t value_index_dpin; +static uint8_t value_index_cnt; +static uint8_t value_index_pwr; +static uint8_t value_index_time; #define EXT_MODULES_COUNT (sizeof(radio_modules_variables_text) / sizeof(char* const)) const char* const radio_modules_variables_text[] = { @@ -18,6 +19,12 @@ const char* const ext_mod_power_text[EXT_MOD_POWER_COUNT] = { "OFF", }; +#define TIMESTAMP_NAMES_COUNT 2 +const char* const timestamp_names_text[TIMESTAMP_NAMES_COUNT] = { + "OFF", + "ON", +}; + #define DEBUG_P_COUNT 2 const char* const debug_pin_text[DEBUG_P_COUNT] = { "OFF", @@ -104,6 +111,17 @@ static void subghz_scene_receiver_config_set_ext_mod_power(VariableItem* item) { subghz_last_settings_save(subghz->last_settings); } +static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) { + SubGhz* subghz = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, timestamp_names_text[index]); + + furi_hal_subghz_set_timestamp_file_names((index == 1)); + subghz->last_settings->timestamp_file_names = (index == 1); + subghz_last_settings_save(subghz->last_settings); +} + void subghz_scene_ext_module_settings_on_enter(void* context) { SubGhz* subghz = context; @@ -129,6 +147,16 @@ void subghz_scene_ext_module_settings_on_enter(void* context) { variable_item_set_current_value_index(item, value_index_pwr); variable_item_set_current_value_text(item, ext_mod_power_text[value_index_pwr]); + item = variable_item_list_add( + subghz->variable_item_list, + "Time in names", + TIMESTAMP_NAMES_COUNT, + subghz_scene_receiver_config_set_timestamp_file_names, + subghz); + value_index_time = furi_hal_subghz_get_timestamp_file_names(); + variable_item_set_current_value_index(item, value_index_time); + variable_item_set_current_value_text(item, timestamp_names_text[value_index_time]); + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { item = variable_item_list_add( subghz->variable_item_list, diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index 4f37ebc0b..282e22201 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -14,18 +14,34 @@ void subghz_scene_save_name_text_input_callback(void* context) { view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneSaveName); } -void subghz_scene_save_name_get_timefilename(FuriString* name) { +void subghz_scene_save_name_get_timefilename( + FuriString* name, + const char* proto_name, + bool fulldate) { FuriHalRtcDateTime datetime = {0}; furi_hal_rtc_get_datetime(&datetime); - furi_string_printf( - name, - "RAW_%.4d%.2d%.2d-%.2d%.2d%.2d", - datetime.year, - datetime.month, - datetime.day, - datetime.hour, - datetime.minute, - datetime.second); + if(fulldate) { + furi_string_printf( + name, + "%s_%.4d%.2d%.2d-%.2d%.2d%.2d", + proto_name, + datetime.year, + datetime.month, + datetime.day, + datetime.hour, + datetime.minute, + datetime.second); + } else { + furi_string_printf( + name, + "%s_%.2d%.2d-%.2d%.2d%.2d", + proto_name, + datetime.month, + datetime.day, + datetime.hour, + datetime.minute, + datetime.second); + } } void subghz_scene_save_name_on_enter(void* context) { @@ -42,8 +58,25 @@ void subghz_scene_save_name_on_enter(void* context) { if(!subghz_path_is_file(subghz->file_path)) { char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0}; - set_random_name(file_name_buf, SUBGHZ_MAX_LEN_NAME); - furi_string_set(file_name, file_name_buf); + if(furi_hal_subghz_get_timestamp_file_names()) { + if(subghz->txrx->decoder_result->protocol->name != 0x0) { + if(subghz->txrx->decoder_result->protocol->name != NULL) { + if(strlen(subghz->txrx->decoder_result->protocol->name) != 0) { + subghz_scene_save_name_get_timefilename( + file_name, subghz->txrx->decoder_result->protocol->name, false); + } else { + subghz_scene_save_name_get_timefilename(file_name, "S", true); + } + } else { + subghz_scene_save_name_get_timefilename(file_name, "S", true); + } + } else { + subghz_scene_save_name_get_timefilename(file_name, "S", true); + } + } else { + set_random_name(file_name_buf, SUBGHZ_MAX_LEN_NAME); + furi_string_set(file_name, file_name_buf); + } furi_string_set(subghz->file_path, SUBGHZ_APP_FOLDER); //highlighting the entire filename by default dev_name_empty = true; @@ -57,7 +90,7 @@ void subghz_scene_save_name_on_enter(void* context) { if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) == SubGhzCustomEventManagerSetRAW) { dev_name_empty = true; - subghz_scene_save_name_get_timefilename(file_name); + subghz_scene_save_name_get_timefilename(file_name, "RAW", true); } } furi_string_set(subghz->file_path, dir_name); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 6fc51554d..2f4445a42 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -19,6 +19,7 @@ #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower" +#define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -45,6 +46,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count float temp_frequency_analyzer_trigger = 0; bool temp_external_module_enabled = false; bool temp_external_module_power_5v_disable = false; + bool temp_timestamp_file_names = false; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; bool frequency_analyzer_trigger_was_read = false; @@ -76,6 +78,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER, (bool*)&temp_external_module_power_5v_disable, 1); + flipper_format_read_bool( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, + (bool*)&temp_timestamp_file_names, + 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); @@ -89,6 +96,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL; instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; instance->external_module_enabled = false; + instance->timestamp_file_names = false; } else { instance->frequency = temp_frequency; @@ -109,6 +117,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_power_5v_disable = temp_external_module_power_5v_disable; + instance->timestamp_file_names = temp_timestamp_file_names; + + // Set globally + furi_hal_subghz_set_timestamp_file_names(instance->timestamp_file_names); + if(instance->external_module_power_5v_disable) { furi_hal_subghz_set_external_power_disable(true); furi_hal_subghz_disable_ext_power(); @@ -189,6 +202,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { 1)) { break; } + if(!flipper_format_insert_or_update_bool( + file, + SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, + &instance->timestamp_file_names, + 1)) { + break; + } saved = true; } while(0); diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 5e3630468..260c879f4 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -12,6 +12,7 @@ typedef struct { float frequency_analyzer_trigger; bool external_module_enabled; bool external_module_power_5v_disable; + bool timestamp_file_names; } SubGhzLastSettings; SubGhzLastSettings* subghz_last_settings_alloc(void); diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index f19310349..6bbb94a6a 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1373,6 +1373,7 @@ Function,+,furi_hal_subghz_get_lqi,uint8_t, Function,+,furi_hal_subghz_get_radio_type,SubGhzRadioType, Function,+,furi_hal_subghz_get_rolling_counter_mult,uint8_t, Function,+,furi_hal_subghz_get_rssi,float, +Function,+,furi_hal_subghz_get_timestamp_file_names,_Bool, Function,+,furi_hal_subghz_idle,void, Function,-,furi_hal_subghz_init,void, Function,+,furi_hal_subghz_init_check,_Bool, @@ -1395,6 +1396,7 @@ Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t Function,+,furi_hal_subghz_set_path,void,FuriHalSubGhzPath Function,+,furi_hal_subghz_set_radio_type,_Bool,SubGhzRadioType Function,+,furi_hal_subghz_set_rolling_counter_mult,void,uint8_t +Function,+,furi_hal_subghz_set_timestamp_file_names,void,_Bool Function,-,furi_hal_subghz_shutdown,void, Function,+,furi_hal_subghz_sleep,void, Function,+,furi_hal_subghz_start_async_rx,void,"FuriHalSubGhzCaptureCallback, void*" diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index ed9864ae9..1a4e39965 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -40,6 +40,7 @@ volatile FuriHalSubGhz furi_hal_subghz = { .cc1101_g0_pin = &gpio_cc1101_g0, .rolling_counter_mult = 1, .ext_module_power_disabled = false, + .timestamp_file_names = false, }; bool furi_hal_subghz_set_radio_type(SubGhzRadioType state) { @@ -79,6 +80,14 @@ bool furi_hal_subghz_get_external_power_disable(void) { return furi_hal_subghz.ext_module_power_disabled; } +void furi_hal_subghz_set_timestamp_file_names(bool state) { + furi_hal_subghz.timestamp_file_names = state; +} + +bool furi_hal_subghz_get_timestamp_file_names(void) { + return furi_hal_subghz.timestamp_file_names; +} + void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) { furi_hal_subghz.async_mirror_pin = pin; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.h b/firmware/targets/f7/furi_hal/furi_hal_subghz.h index ec886f693..b366e8578 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.h +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.h @@ -79,6 +79,7 @@ typedef struct { const GpioPin* cc1101_g0_pin; uint8_t rolling_counter_mult; bool ext_module_power_disabled; + bool timestamp_file_names; } FuriHalSubGhz; extern volatile FuriHalSubGhz furi_hal_subghz; @@ -330,6 +331,14 @@ void furi_hal_subghz_set_external_power_disable(bool state); */ bool furi_hal_subghz_get_external_power_disable(void); +/** If true - disable generation of random name and add timestamp to filenames instead + */ +void furi_hal_subghz_set_timestamp_file_names(bool state); + +/** Get the current state of the timestamp instead of random name flag + */ +bool furi_hal_subghz_get_timestamp_file_names(void); + #ifdef __cplusplus } #endif