From 24e744f1d1e94226dda0a74ffd8bfe78b17b6e2b Mon Sep 17 00:00:00 2001 From: derskythe Date: Sat, 1 Oct 2022 08:39:51 +0400 Subject: [PATCH 01/16] Added saving DetectRAW settings, trying to write files on SD instead of memory --- .../subghz/scenes/subghz_scene_read_raw.c | 2 +- .../scenes/subghz_scene_receiver_config.c | 31 +- .../scenes/subghz_scene_receiver_info.c | 1 + .../main/subghz/scenes/subghz_scene_start.c | 6 +- applications/main/subghz/subghz.c | 7 +- applications/main/subghz/subghz_history.c | 278 ++++++++++++++++-- .../main/subghz/subghz_last_settings.c | 41 ++- .../main/subghz/subghz_last_settings.h | 9 +- 8 files changed, 305 insertions(+), 70 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 7392221dc..3eac03dec 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -341,5 +341,5 @@ void subghz_scene_read_raw_on_exit(void* context) { notification_message(subghz->notifications, &sequence_reset_rgb); //filter restoration - subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); + subghz_last_settings_set_detect_raw_values(subghz); } \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 0175cd0fd..b782f5a31 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -29,11 +29,6 @@ const char* const detect_raw_text[DETECT_RAW_COUNT] = { "ON", }; -const SubGhzProtocolFlag detect_raw_value[DETECT_RAW_COUNT] = { - SubGhzProtocolFlag_Decodable, - SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW, -}; - #define RSSI_THRESHOLD_COUNT 7 const char* const rssi_threshold_text[RSSI_THRESHOLD_COUNT] = { "-72db", @@ -105,20 +100,6 @@ uint8_t subghz_scene_receiver_config_hopper_value_index( } } -uint8_t subghz_scene_receiver_config_detect_raw_value_index( - const SubGhzProtocolFlag value, - const SubGhzProtocolFlag values[], - uint8_t values_count) { - uint8_t index = 0; - for(uint8_t i = 0; i < values_count; i++) { - if(value == values[i]) { - index = i; - break; - } - } - return index; -} - uint8_t subghz_scene_receiver_config_rssi_threshold_value_index( const int value, const int values[], @@ -186,12 +167,9 @@ static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, detect_raw_text[index]); - subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]); + subghz->last_settings->detect_raw = index; - subghz_protocol_decoder_raw_set_auto_mode( - subghz_receiver_search_decoder_base_by_name( - subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), - (index == 1)); + subghz_last_settings_set_detect_raw_values(subghz); } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -304,10 +282,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { DETECT_RAW_COUNT, subghz_scene_receiver_config_set_detect_raw, subghz); - value_index = subghz_scene_receiver_config_detect_raw_value_index( - subghz_receiver_get_filter(subghz->txrx->receiver), - detect_raw_value, - DETECT_RAW_COUNT); + value_index = subghz->last_settings->detect_raw; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, detect_raw_text[value_index]); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 5621bb847..be171f421 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -26,6 +26,7 @@ static bool subghz_scene_receiver_info_update_parser(void* context) { subghz->txrx->receiver, subghz_history_get_protocol_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen)); if(subghz->txrx->decoder_result) { + // In this case flipper format was changed to short file content subghz_protocol_decoder_base_deserialize( subghz->txrx->decoder_result, subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen)); diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index 35c7ecb9c..f64e29e0c 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -21,11 +21,7 @@ void subghz_scene_start_on_enter(void* context) { if(subghz->state_notifications == SubGhzNotificationStateStarting) { subghz->state_notifications = SubGhzNotificationStateIDLE; } - subghz_protocol_decoder_raw_set_auto_mode( - subghz_receiver_search_decoder_base_by_name( - subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), - false); - subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); + subghz_last_settings_set_detect_raw_values(subghz); submenu_add_item( subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 8b9dd399f..4b7c9077c 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -183,9 +183,10 @@ SubGhz* subghz_alloc() { #if FURI_DEBUG FURI_LOG_D( TAG, - "last frequency: %d, preset: %d", + "last frequency: %d, preset: %d, detect_raw: %d", subghz->last_settings->frequency, - subghz->last_settings->preset); + subghz->last_settings->preset, + subghz->last_settings->detect_raw); #endif subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); @@ -215,7 +216,7 @@ SubGhz* subghz_alloc() { subghz_environment_set_nice_flor_s_rainbow_table_file_name( subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); - subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); + subghz_last_settings_set_detect_raw_values(subghz); subghz_worker_set_overrun_callback( subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 0af8c0a15..29e1655f5 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -1,14 +1,18 @@ #include "subghz_history.h" #include -#include -#include +#include #define SUBGHZ_HISTORY_MAX 65 +#define SUBGHZ_HISTORY_TMP_DIR EXT_PATH("subghz/tmp_history") +#define SUBGHZ_HISTORY_TMP_EXTENSION ".tmp" +#define SUBGHZ_HISTORY_TMP_FILE_KEY "Filename" #define TAG "SubGhzHistory" typedef struct { string_t item_str; FlipperFormat* flipper_string; + string_t protocol_name; + bool is_file; uint8_t type; SubGhzPresetDefinition* preset; } SubGhzHistoryItem; @@ -26,30 +30,134 @@ struct SubGhzHistory { uint16_t last_index_write; uint8_t code_last_hash_data; string_t tmp_string; + bool write_tmp_files; + Storage* storage; SubGhzHistoryStruct* history; }; +#if FURI_DEBUG +#define LOG_DELAY 1 +#endif + +/** + * @brief Generate filename like 000.tmp + * + * @param filename + * @param index - index of file, timestamp doesn't accepted! + */ +void subghz_history_generate_temp_filename(string_t filename, uint32_t index) { + FuriHalRtcDateTime datetime = {0}; + furi_hal_rtc_get_datetime(&datetime); + string_init_printf(filename, "%03d%s", index, SUBGHZ_HISTORY_TMP_EXTENSION); +} + +/** + * @brief Check SD card, recursive delete dir and files and create new dir + * + * @param instance + * @param only_remove_dir + * @return true - if all ok + * @return false - if something failed + */ +bool subghz_history_clear_dir_or_create(SubGhzHistory* instance, bool only_remove_dir) { +#if FURI_DEBUG + FURI_LOG_D(TAG, "subghz_history_clear_dir_or_create: %s", only_remove_dir ? "true" : "false"); + furi_delay_ms(LOG_DELAY); +#endif + + // Stage 0 - SD installed? + FS_Error status = storage_sd_status(instance->storage); + if(status != FSE_OK) { + FURI_LOG_W(TAG, "SD storage not installed! Status: %d", status); + return false; + } + + // Stage 1 - delete all content if exists + FileInfo fileinfo; + storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &fileinfo); + + // This is temp + bool res = instance->write_tmp_files = true; + + // Uncomment it + // if(fileinfo.flags & FSF_DIRECTORY) { + // res = storage_simply_remove_recursive(instance->storage, SUBGHZ_HISTORY_TMP_DIR); + // } else { + // res = (storage_common_remove(instance->storage, SUBGHZ_HISTORY_TMP_DIR) == FSE_OK); + // } + +#if FURI_DEBUG + FURI_LOG_D(TAG, "storage_common_remove done: %s", res ? "true" : "false"); + furi_delay_ms(LOG_DELAY); +#endif + + // Uncomment it + // Stage 2 - create dir + // if(!only_remove_dir && res) { + // res = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); + // #if FURI_DEBUG + // FURI_LOG_D(TAG, "storage_simply_mkdir done: %s", res ? "true" : "false"); + // furi_delay_ms(LOG_DELAY); + // #endif + // } + + return res; +} + SubGhzHistory* subghz_history_alloc(void) { SubGhzHistory* instance = malloc(sizeof(SubGhzHistory)); string_init(instance->tmp_string); instance->history = malloc(sizeof(SubGhzHistoryStruct)); SubGhzHistoryItemArray_init(instance->history->data); + instance->storage = furi_record_open(RECORD_STORAGE); + instance->write_tmp_files = false; + +#if FURI_DEBUG + FURI_LOG_D(TAG, "BEFORE subghz_history_clear_dir_or_create"); + furi_delay_ms(LOG_DELAY); +#endif + // Check if we can write files on SD + instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, false); + return instance; } +/** + * @brief free all items in array + * + * @param instance + */ +void subghz_history_clean_item_array(SubGhzHistory* instance) { + for + M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) { + string_clear(item->item_str); + string_clear(item->preset->name); + string_clear(item->protocol_name); + + free(item->preset); + item->type = 0; + item->is_file = false; + + if(item->flipper_string != NULL) { + flipper_format_free(item->flipper_string); + } + } +} + void subghz_history_free(SubGhzHistory* instance) { furi_assert(instance); string_clear(instance->tmp_string); - for - M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) { - string_clear(item->item_str); - string_clear(item->preset->name); - free(item->preset); - flipper_format_free(item->flipper_string); - item->type = 0; - } + + subghz_history_clean_item_array(instance); SubGhzHistoryItemArray_clear(instance->history->data); free(instance->history); + + if(instance->write_tmp_files) { + instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, true); + } + + furi_record_close(RECORD_STORAGE); + free(instance); } @@ -74,17 +182,16 @@ const char* subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx) { void subghz_history_reset(SubGhzHistory* instance) { furi_assert(instance); string_reset(instance->tmp_string); - for - M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) { - string_clear(item->item_str); - string_clear(item->preset->name); - free(item->preset); - flipper_format_free(item->flipper_string); - item->type = 0; - } + + subghz_history_clean_item_array(instance); + SubGhzHistoryItemArray_reset(instance->history->data); instance->last_index_write = 0; instance->code_last_hash_data = 0; + + if(instance->write_tmp_files) { + instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, false); + } } uint16_t subghz_history_get_item(SubGhzHistory* instance) { @@ -101,12 +208,8 @@ uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx) const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx) { furi_assert(instance); SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx); - flipper_format_rewind(item->flipper_string); - if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) { - FURI_LOG_E(TAG, "Missing Protocol"); - string_reset(instance->tmp_string); - } - return string_get_cstr(instance->tmp_string); + + return string_get_cstr(item->protocol_name); } FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx) { @@ -115,17 +218,73 @@ FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx if(item->flipper_string) { return item->flipper_string; } else { - return NULL; + bool result_ok = false; + if(instance->write_tmp_files && item->is_file) { + // We have files! +#if FURI_DEBUG + FURI_LOG_D(TAG, "We have files!"); + furi_delay_ms(LOG_DELAY); +#endif + string_t filename; + string_t dir_path; + string_init(filename); + string_init(dir_path); + subghz_history_generate_temp_filename(filename, idx); + string_cat_printf( + dir_path, "%s/%s", SUBGHZ_HISTORY_TMP_DIR, string_get_cstr(filename)); + // string_init_printf( + // dir_path, "%s/%s", SUBGHZ_HISTORY_TMP_DIR, string_get_cstr(filename)); + + if(storage_file_exists(instance->storage, string_get_cstr(dir_path))) { +#if FURI_DEBUG + FURI_LOG_D(TAG, "Exist: %s", dir_path); + furi_delay_ms(LOG_DELAY); +#endif + // Set to current anyway it has NULL value + item->flipper_string = flipper_format_string_alloc(); + Stream* dst_stream = flipper_format_get_raw_stream(item->flipper_string); + stream_clean(dst_stream); + + size_t size = stream_load_from_file( + dst_stream, instance->storage, string_get_cstr(dir_path)); + if(size > 0) { +#if FURI_DEBUG + FURI_LOG_I(TAG, "Save ok!"); + furi_delay_ms(LOG_DELAY); +#endif + // We changed contents of file, so we no needed to load + // content from disk for the next time + item->is_file = false; + result_ok = true; + } else { + FURI_LOG_E(TAG, "Stream copy failed!"); + flipper_format_free(item->flipper_string); + } + } else { + FURI_LOG_E(TAG, "Can't convert filename to file"); + } + + string_clear(filename); + string_clear(dir_path); + } else { +#if FURI_DEBUG + FURI_LOG_W(TAG, "Write TMP files failed!"); + furi_delay_ms(LOG_DELAY); +#endif + } + return result_ok ? item->flipper_string : NULL; } } + bool subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output) { furi_assert(instance); if(instance->last_index_write == SUBGHZ_HISTORY_MAX) { if(output != NULL) string_printf(output, "Memory is FULL"); return true; } - if(output != NULL) + if(output != NULL) { string_printf(output, "%02u/%02u", instance->last_index_write, SUBGHZ_HISTORY_MAX); + } return false; } @@ -141,7 +300,9 @@ bool subghz_history_add_to_history( furi_assert(instance); furi_assert(context); - if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return false; + if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) { + return false; + } SubGhzProtocolDecoderBase* decoder_base = context; if((instance->code_last_hash_data == @@ -166,6 +327,9 @@ bool subghz_history_add_to_history( item->preset->data_size = preset->data_size; string_init(item->item_str); + string_init(item->protocol_name); + + // At this point file mapped to memory otherwise file cannot decoded item->flipper_string = flipper_format_string_alloc(); subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset); @@ -177,6 +341,11 @@ bool subghz_history_add_to_history( if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) { FURI_LOG_E(TAG, "Missing Protocol"); break; + } else { + string_init_printf(item->protocol_name, "%s", string_get_cstr(instance->tmp_string)); +#if FURI_DEBUG + FURI_LOG_I(TAG, "File protocol: %s", string_get_cstr(item->protocol_name)); +#endif } if(!strcmp(string_get_cstr(instance->tmp_string), "RAW")) { string_printf( @@ -234,7 +403,62 @@ bool subghz_history_add_to_history( } } while(false); + // Copy streams + // Thinking that some data may be saved + // Stream* src = flipper_format_get_raw_stream(flipper_string); + // stream_seek(src, 0, StreamOffsetFromStart); + + // Stream* dst = string_stream_alloc(); + // stream_clean(dst); + // stream_copy_full(src, dst); + + // If we can write to files + //bool no_close = false; + if(instance->write_tmp_files) { + string_t filename; + string_t dir_path; + string_init(filename); + string_init(dir_path); + + subghz_history_generate_temp_filename(filename, instance->last_index_write); + string_cat_printf(dir_path, "%s/%s", SUBGHZ_HISTORY_TMP_DIR, string_get_cstr(filename)); +#if FURI_DEBUG + FURI_LOG_I(TAG, "Let's do some hack. Create file %s", string_get_cstr(dir_path)); +#endif + Stream* dst = flipper_format_get_raw_stream(item->flipper_string); + stream_rewind(dst); + // stream_seek(dst, 0, StreamOffsetFromStart); + if(stream_save_to_file( + dst, instance->storage, string_get_cstr(dir_path), FSOM_CREATE_ALWAYS) > 0) { + // Free flipper_format + //flipper_format_free(flipper_string); + //flipper_string = NULL; + //stream_free(dst); + flipper_format_free(item->flipper_string); + item->flipper_string = NULL; +#if FURI_DEBUG + FURI_LOG_I(TAG, "Save done!"); +#endif + // This item contains fake data to load from SD + item->is_file = true; + } else { + FURI_LOG_E(TAG, "Stream copy failed!"); + } + string_clear(filename); + string_clear(dir_path); + + /* }*/ + } else { +#if FURI_DEBUG + FURI_LOG_I(TAG, "Old fashion way"); +#endif + // Old fashion way + //item->flipper_string = dst; + } + //flipper_format_free(flipper_string); + string_clear(text); + instance->last_index_write++; return true; } diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index b24273cf3..8dd2c165a 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -1,5 +1,6 @@ #include "subghz_last_settings.h" -#include +#include "subghz_i.h" +#include #define TAG "SubGhzLastSettings" @@ -10,6 +11,11 @@ // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 #define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 +#define SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW 0 + +#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" +#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" +#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -32,11 +38,16 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count uint32_t temp_frequency = 0; int32_t temp_preset = 0; + uint32_t temp_read_raw = 0; if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { - flipper_format_read_int32(fff_data_file, "Preset", (int32_t*)&temp_preset, 1); - flipper_format_read_uint32(fff_data_file, "Frequency", (uint32_t*)&temp_frequency, 1); + flipper_format_read_int32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1); + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1); + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, (uint32_t*)&temp_read_raw, 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } @@ -45,8 +56,10 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count FURI_LOG_W(TAG, "Last used frequency not found or can't be used!"); instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY; instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; + instance->detect_raw = SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW; } else { instance->frequency = temp_frequency; + instance->detect_raw = temp_read_raw; if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) { FURI_LOG_W(TAG, "Last used preset no found"); @@ -84,10 +97,16 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FILE_TYPE, SUBGHZ_LAST_SETTING_FILE_VERSION)) break; - if(!flipper_format_insert_or_update_int32(file, "Preset", &instance->preset, 1)) { + if(!flipper_format_insert_or_update_int32( + file, SUBGHZ_LAST_SETTING_FIELD_PRESET, &instance->preset, 1)) { break; } - if(!flipper_format_insert_or_update_uint32(file, "Frequency", &instance->frequency, 1)) { + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) { + break; + } + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, &instance->detect_raw, 1)) { break; } saved = true; @@ -102,4 +121,16 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { furi_record_close(RECORD_STORAGE); return saved; +} + +void subghz_last_settings_set_detect_raw_values(void* context) { + furi_assert(context); + SubGhz* instance = (SubGhz*)context; + bool is_detect_raw = instance->last_settings->detect_raw > 0; + subghz_receiver_set_filter( + instance->txrx->receiver, is_detect_raw ? DETECT_RAW_TRUE : DETECT_RAW_FALSE); + subghz_protocol_decoder_raw_set_auto_mode( + subghz_receiver_search_decoder_base_by_name( + instance->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), + is_detect_raw); } \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 8067bb66a..5efc7ebb0 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -4,9 +4,14 @@ #include #include #include +#include + +#define DETECT_RAW_FALSE SubGhzProtocolFlag_Decodable +#define DETECT_RAW_TRUE SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW typedef struct { uint32_t frequency; + uint32_t detect_raw; int32_t preset; } SubGhzLastSettings; @@ -16,4 +21,6 @@ void subghz_last_settings_free(SubGhzLastSettings* instance); void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count); -bool subghz_last_settings_save(SubGhzLastSettings* instance); \ No newline at end of file +bool subghz_last_settings_save(SubGhzLastSettings* instance); + +void subghz_last_settings_set_detect_raw_values(void* context); \ No newline at end of file From 230f09dddd46cfd93cd37b50b94972402f35b5f9 Mon Sep 17 00:00:00 2001 From: derskythe Date: Sat, 1 Oct 2022 08:47:44 +0400 Subject: [PATCH 02/16] enable delete temp files --- applications/main/subghz/subghz_history.c | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 29e1655f5..154bfa8f2 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -77,14 +77,14 @@ bool subghz_history_clear_dir_or_create(SubGhzHistory* instance, bool only_remov storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &fileinfo); // This is temp - bool res = instance->write_tmp_files = true; + bool res = false; //instance->write_tmp_files = true; // Uncomment it - // if(fileinfo.flags & FSF_DIRECTORY) { - // res = storage_simply_remove_recursive(instance->storage, SUBGHZ_HISTORY_TMP_DIR); - // } else { - // res = (storage_common_remove(instance->storage, SUBGHZ_HISTORY_TMP_DIR) == FSE_OK); - // } + if(fileinfo.flags & FSF_DIRECTORY) { + res = storage_simply_remove_recursive(instance->storage, SUBGHZ_HISTORY_TMP_DIR); + } else { + res = (storage_common_remove(instance->storage, SUBGHZ_HISTORY_TMP_DIR) == FSE_OK); + } #if FURI_DEBUG FURI_LOG_D(TAG, "storage_common_remove done: %s", res ? "true" : "false"); @@ -93,13 +93,13 @@ bool subghz_history_clear_dir_or_create(SubGhzHistory* instance, bool only_remov // Uncomment it // Stage 2 - create dir - // if(!only_remove_dir && res) { - // res = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); - // #if FURI_DEBUG - // FURI_LOG_D(TAG, "storage_simply_mkdir done: %s", res ? "true" : "false"); - // furi_delay_ms(LOG_DELAY); - // #endif - // } + if(!only_remove_dir && res) { + res = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); +#if FURI_DEBUG + FURI_LOG_D(TAG, "storage_simply_mkdir done: %s", res ? "true" : "false"); + furi_delay_ms(LOG_DELAY); +#endif + } return res; } From bbd3f9cf71e3644472f20b3a17ae75bd4b68e0d3 Mon Sep 17 00:00:00 2001 From: derskythe Date: Sun, 2 Oct 2022 03:18:30 +0400 Subject: [PATCH 03/16] Fixed all bugs with saving directly to file, also fixed misspeled if/ifdef in all app --- .../main/subghz/helpers/subghz_types.h | 2 + .../scenes/subghz_scene_frequency_analyzer.c | 2 +- .../subghz/scenes/subghz_scene_receiver.c | 1 + .../scenes/subghz_scene_receiver_config.c | 4 +- applications/main/subghz/subghz.c | 4 +- applications/main/subghz/subghz_history.c | 235 ++++++++++-------- .../main/subghz/subghz_last_settings.c | 6 +- .../subghz/views/subghz_frequency_analyzer.c | 8 +- 8 files changed, 143 insertions(+), 119 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_types.h b/applications/main/subghz/helpers/subghz_types.h index d6d6d025f..cf7b64fb0 100644 --- a/applications/main/subghz/helpers/subghz_types.h +++ b/applications/main/subghz/helpers/subghz_types.h @@ -86,3 +86,5 @@ typedef enum { SubGhzViewReceiverModeLive, SubGhzViewReceiverModeFile, } SubGhzViewReceiverMode; + +#define SUBGHZ_HISTORY_REMOVE_SAVED_ITEMS 1 diff --git a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c index 1f1957e32..8889dac83 100644 --- a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c +++ b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c @@ -31,7 +31,7 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e return true; } else if(event.event == SubGhzCustomEventViewReceiverUnlock) { // Don't need to save, we already saved on short event -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_W(TAG, "Goto next scene!"); #endif scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 4a35c5f2c..4fb79a8f1 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -185,6 +185,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { consumed = true; break; case SubGhzCustomEventViewReceiverOK: + // Show file info, scene: receiver_info subghz->txrx->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index b782f5a31..9919ae509 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -222,10 +222,10 @@ void subghz_scene_receiver_config_on_enter(void* context) { VariableItem* item; uint8_t value_index; -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_D( TAG, - "last frequency: %d, preset: %d", + "Last frequency: %d, Preset: %d", subghz->last_settings->frequency, subghz->last_settings->preset); #endif diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 4b7c9077c..332c3dd7a 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -180,10 +180,10 @@ SubGhz* subghz_alloc() { subghz->last_settings = subghz_last_settings_alloc(); subghz_last_settings_load( subghz->last_settings, subghz_setting_get_preset_count(subghz->setting)); -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_D( TAG, - "last frequency: %d, preset: %d, detect_raw: %d", + "Last frequency: %d, Preset: %d, Detect_RAW: %d", subghz->last_settings->frequency, subghz->last_settings->preset, subghz->last_settings->detect_raw); diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 154bfa8f2..417ebd96e 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -3,9 +3,15 @@ #include #define SUBGHZ_HISTORY_MAX 65 + +/** + * @brief Settings for temporary files + * + */ #define SUBGHZ_HISTORY_TMP_DIR EXT_PATH("subghz/tmp_history") #define SUBGHZ_HISTORY_TMP_EXTENSION ".tmp" #define SUBGHZ_HISTORY_TMP_FILE_KEY "Filename" + #define TAG "SubGhzHistory" typedef struct { @@ -35,14 +41,14 @@ struct SubGhzHistory { SubGhzHistoryStruct* history; }; -#if FURI_DEBUG -#define LOG_DELAY 1 +#ifdef FURI_DEBUG +#define LOG_DELAY 0 #endif /** * @brief Generate filename like 000.tmp * - * @param filename + * @param filename - input parameter * @param index - index of file, timestamp doesn't accepted! */ void subghz_history_generate_temp_filename(string_t filename, uint32_t index) { @@ -52,56 +58,98 @@ void subghz_history_generate_temp_filename(string_t filename, uint32_t index) { } /** - * @brief Check SD card, recursive delete dir and files and create new dir + * @brief Check if directory for temporary files is exists * - * @param instance - * @param only_remove_dir + * @param instance SubGhzHistory* + * @return true + * @return false + */ +bool subghz_history_is_tmp_dir_exists(SubGhzHistory* instance) { + FileInfo file_info; + storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &file_info); + + if(storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &file_info) == FSE_OK) { + if(file_info.flags & FSF_DIRECTORY) { + return true; + } + } + + return false; +} + +/** + * @brief Check SD card and create temporary dir if not exists, + * Result write_tmp_files without this unstable work is GUARANTEED + * + * @param instance - SubGhzHistory* + * @return - true all ok + * @return - false we have a problems + */ +bool subghz_history_check_sdcard(SubGhzHistory* instance) { +#ifdef FURI_DEBUG + FURI_LOG_I(TAG, "check_sdcard"); + uint32_t start_time = furi_get_tick(); +#endif + + bool result = false; + // Stage 0 - check SD Card + FS_Error status = storage_sd_status(instance->storage); + if(status == FSE_OK) { + result = subghz_history_is_tmp_dir_exists(instance); + if(!subghz_history_is_tmp_dir_exists(instance)) { + result = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); + } + } else { + FURI_LOG_W(TAG, "SD storage not installed! Status: %d", status); + } +#ifdef FURI_DEBUG + FURI_LOG_I(TAG, "Running time (check_sdcard): %d ms", furi_get_tick() - start_time); +#endif + + return result; +} + +/** + * @brief Recursive delete dir and files and create new temp dir + * + * @param instance - SubGhzHistory* * @return true - if all ok * @return false - if something failed */ -bool subghz_history_clear_dir_or_create(SubGhzHistory* instance, bool only_remove_dir) { -#if FURI_DEBUG - FURI_LOG_D(TAG, "subghz_history_clear_dir_or_create: %s", only_remove_dir ? "true" : "false"); - furi_delay_ms(LOG_DELAY); +void subghz_history_clear_tmp_dir(SubGhzHistory* instance) { + furi_assert(instance); +#ifdef FURI_DEBUG + FURI_LOG_I(TAG, "clear_tmp_dir"); #endif - // Stage 0 - SD installed? - FS_Error status = storage_sd_status(instance->storage); - if(status != FSE_OK) { - FURI_LOG_W(TAG, "SD storage not installed! Status: %d", status); - return false; + if(!instance->write_tmp_files) { + // Nothing to do here! + return; + } + uint32_t start_time = furi_get_tick(); + + // Stage 0 - Dir exists? + bool res = subghz_history_is_tmp_dir_exists(instance); + if(res) { + // Stage 1 - delete all content if exists + FileInfo fileinfo; + storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &fileinfo); + + if(fileinfo.flags & FSF_DIRECTORY) { + res = storage_simply_remove_recursive(instance->storage, SUBGHZ_HISTORY_TMP_DIR); + } else { + res = (storage_common_remove(instance->storage, SUBGHZ_HISTORY_TMP_DIR) == FSE_OK); + } } - // Stage 1 - delete all content if exists - FileInfo fileinfo; - storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &fileinfo); - - // This is temp - bool res = false; //instance->write_tmp_files = true; - - // Uncomment it - if(fileinfo.flags & FSF_DIRECTORY) { - res = storage_simply_remove_recursive(instance->storage, SUBGHZ_HISTORY_TMP_DIR); - } else { - res = (storage_common_remove(instance->storage, SUBGHZ_HISTORY_TMP_DIR) == FSE_OK); + // Stage 2 - create dir if necessary + res = !storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); + if(!res) { + FURI_LOG_E(TAG, "Cannot process temp dir!"); } -#if FURI_DEBUG - FURI_LOG_D(TAG, "storage_common_remove done: %s", res ? "true" : "false"); - furi_delay_ms(LOG_DELAY); -#endif - - // Uncomment it - // Stage 2 - create dir - if(!only_remove_dir && res) { - res = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); -#if FURI_DEBUG - FURI_LOG_D(TAG, "storage_simply_mkdir done: %s", res ? "true" : "false"); - furi_delay_ms(LOG_DELAY); -#endif - } - - return res; + uint32_t stop_time = furi_get_tick() - start_time; + FURI_LOG_I(TAG, "Running time (clear_tmp_dir): %d ms", stop_time); } SubGhzHistory* subghz_history_alloc(void) { @@ -110,18 +158,35 @@ SubGhzHistory* subghz_history_alloc(void) { instance->history = malloc(sizeof(SubGhzHistoryStruct)); SubGhzHistoryItemArray_init(instance->history->data); instance->storage = furi_record_open(RECORD_STORAGE); - instance->write_tmp_files = false; + instance->write_tmp_files = subghz_history_check_sdcard(instance); -#if FURI_DEBUG - FURI_LOG_D(TAG, "BEFORE subghz_history_clear_dir_or_create"); - furi_delay_ms(LOG_DELAY); -#endif - // Check if we can write files on SD - instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, false); + if(!instance->write_tmp_files) { + FURI_LOG_E(TAG, "Unstable work! Cannot use SD Card!"); + } return instance; } +/** + * @brief Free item and free all resources + * + * @param item - SubGhzHistoryItem* + */ +void subghz_history_item_free(SubGhzHistoryItem* item) { + furi_assert(item); + string_clear(item->item_str); + string_clear(item->preset->name); + string_clear(item->protocol_name); + + free(item->preset); + item->type = 0; + item->is_file = false; + + if(item->flipper_string != NULL) { + flipper_format_free(item->flipper_string); + } +} + /** * @brief free all items in array * @@ -130,17 +195,7 @@ SubGhzHistory* subghz_history_alloc(void) { void subghz_history_clean_item_array(SubGhzHistory* instance) { for M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) { - string_clear(item->item_str); - string_clear(item->preset->name); - string_clear(item->protocol_name); - - free(item->preset); - item->type = 0; - item->is_file = false; - - if(item->flipper_string != NULL) { - flipper_format_free(item->flipper_string); - } + subghz_history_item_free(item); } } @@ -152,9 +207,8 @@ void subghz_history_free(SubGhzHistory* instance) { SubGhzHistoryItemArray_clear(instance->history->data); free(instance->history); - if(instance->write_tmp_files) { - instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, true); - } + // Delete all temporary file, on exit it's ok + subghz_history_clear_tmp_dir(instance); furi_record_close(RECORD_STORAGE); @@ -188,10 +242,6 @@ void subghz_history_reset(SubGhzHistory* instance) { SubGhzHistoryItemArray_reset(instance->history->data); instance->last_index_write = 0; instance->code_last_hash_data = 0; - - if(instance->write_tmp_files) { - instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, false); - } } uint16_t subghz_history_get_item(SubGhzHistory* instance) { @@ -221,22 +271,16 @@ FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx bool result_ok = false; if(instance->write_tmp_files && item->is_file) { // We have files! -#if FURI_DEBUG - FURI_LOG_D(TAG, "We have files!"); - furi_delay_ms(LOG_DELAY); -#endif string_t filename; string_t dir_path; string_init(filename); string_init(dir_path); subghz_history_generate_temp_filename(filename, idx); - string_cat_printf( + string_init_printf( dir_path, "%s/%s", SUBGHZ_HISTORY_TMP_DIR, string_get_cstr(filename)); - // string_init_printf( - // dir_path, "%s/%s", SUBGHZ_HISTORY_TMP_DIR, string_get_cstr(filename)); if(storage_file_exists(instance->storage, string_get_cstr(dir_path))) { -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_D(TAG, "Exist: %s", dir_path); furi_delay_ms(LOG_DELAY); #endif @@ -248,7 +292,7 @@ FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx size_t size = stream_load_from_file( dst_stream, instance->storage, string_get_cstr(dir_path)); if(size > 0) { -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_I(TAG, "Save ok!"); furi_delay_ms(LOG_DELAY); #endif @@ -267,7 +311,7 @@ FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx string_clear(filename); string_clear(dir_path); } else { -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_W(TAG, "Write TMP files failed!"); furi_delay_ms(LOG_DELAY); #endif @@ -314,7 +358,6 @@ bool subghz_history_add_to_history( instance->code_last_hash_data = subghz_protocol_decoder_base_get_hash_data(decoder_base); instance->last_update_timestamp = furi_get_tick(); - string_t text; string_init(text); SubGhzHistoryItem* item = SubGhzHistoryItemArray_push_raw(instance->history->data); @@ -343,9 +386,6 @@ bool subghz_history_add_to_history( break; } else { string_init_printf(item->protocol_name, "%s", string_get_cstr(instance->tmp_string)); -#if FURI_DEBUG - FURI_LOG_I(TAG, "File protocol: %s", string_get_cstr(item->protocol_name)); -#endif } if(!strcmp(string_get_cstr(instance->tmp_string), "RAW")) { string_printf( @@ -403,17 +443,7 @@ bool subghz_history_add_to_history( } } while(false); - // Copy streams - // Thinking that some data may be saved - // Stream* src = flipper_format_get_raw_stream(flipper_string); - // stream_seek(src, 0, StreamOffsetFromStart); - - // Stream* dst = string_stream_alloc(); - // stream_clean(dst); - // stream_copy_full(src, dst); - // If we can write to files - //bool no_close = false; if(instance->write_tmp_files) { string_t filename; string_t dir_path; @@ -422,21 +452,16 @@ bool subghz_history_add_to_history( subghz_history_generate_temp_filename(filename, instance->last_index_write); string_cat_printf(dir_path, "%s/%s", SUBGHZ_HISTORY_TMP_DIR, string_get_cstr(filename)); -#if FURI_DEBUG - FURI_LOG_I(TAG, "Let's do some hack. Create file %s", string_get_cstr(dir_path)); +#ifdef FURI_DEBUG + FURI_LOG_I(TAG, "Save temp file: %s", string_get_cstr(dir_path)); #endif Stream* dst = flipper_format_get_raw_stream(item->flipper_string); stream_rewind(dst); - // stream_seek(dst, 0, StreamOffsetFromStart); if(stream_save_to_file( dst, instance->storage, string_get_cstr(dir_path), FSOM_CREATE_ALWAYS) > 0) { - // Free flipper_format - //flipper_format_free(flipper_string); - //flipper_string = NULL; - //stream_free(dst); flipper_format_free(item->flipper_string); item->flipper_string = NULL; -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_I(TAG, "Save done!"); #endif // This item contains fake data to load from SD @@ -447,18 +472,14 @@ bool subghz_history_add_to_history( string_clear(filename); string_clear(dir_path); - /* }*/ } else { -#if FURI_DEBUG - FURI_LOG_I(TAG, "Old fashion way"); +#ifdef FURI_DEBUG + FURI_LOG_W(TAG, "Old fashion way"); #endif - // Old fashion way - //item->flipper_string = dst; } - //flipper_format_free(flipper_string); string_clear(text); instance->last_index_write++; return true; -} +} \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 8dd2c165a..31467d7f2 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -29,7 +29,7 @@ void subghz_last_settings_free(SubGhzLastSettings* instance) { void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count) { furi_assert(instance); -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_I(TAG, "subghz_last_settings_load"); #endif @@ -76,8 +76,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool subghz_last_settings_save(SubGhzLastSettings* instance) { furi_assert(instance); -#if FURI_DEBUG - FURI_LOG_I(TAG, "subghz_last_settings_save"); +#ifdef FURI_DEBUG + FURI_LOG_I(TAG, "last_settings_save"); #endif bool saved = false; diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index 98b3fe01d..461b10974 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -194,7 +194,7 @@ uint32_t subghz_frequency_find_correct(uint32_t input) { uint32_t prev_freq = 0; uint32_t current = 0; uint32_t result = 0; -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_D(TAG, "input: %d", input); #endif for(size_t i = 0; i < sizeof(subghz_frequency_list); i++) { @@ -274,7 +274,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { frequency_candidate = subghz_frequency_find_correct(frequency_candidate); } if(frequency_candidate > 0 && frequency_candidate != model->frequency_to_save) { -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_D( TAG, "frequency_to_save: %d, candidate: %d", @@ -289,7 +289,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { return true; }); -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_I( TAG, "updated: %d, long: %d, type: %d", @@ -304,7 +304,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { // First device receive short, then when user release button we get long if(event->type == InputTypeLong) { -#if FURI_DEBUG +#ifdef FURI_DEBUG FURI_LOG_I(TAG, "Longpress!"); #endif // Stop blinking From cea14ae9c5843dcce3b4d36985811bd66bcb54a3 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 06:23:09 +0300 Subject: [PATCH 04/16] fix dir creation bug, save files only for RAW TODO: files are broken when they have more than 512 elements in one line Split file to 512 element chunks as it done in regular Read RAW --- applications/main/subghz/subghz_history.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 154bfa8f2..cb8550ed9 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -93,7 +93,7 @@ bool subghz_history_clear_dir_or_create(SubGhzHistory* instance, bool only_remov // Uncomment it // Stage 2 - create dir - if(!only_remove_dir && res) { + if(!only_remove_dir) { res = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); #if FURI_DEBUG FURI_LOG_D(TAG, "storage_simply_mkdir done: %s", res ? "true" : "false"); @@ -189,9 +189,9 @@ void subghz_history_reset(SubGhzHistory* instance) { instance->last_index_write = 0; instance->code_last_hash_data = 0; - if(instance->write_tmp_files) { + /*if(instance->write_tmp_files) { instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, false); - } + }*/ } uint16_t subghz_history_get_item(SubGhzHistory* instance) { @@ -329,6 +329,8 @@ bool subghz_history_add_to_history( string_init(item->item_str); string_init(item->protocol_name); + bool tmp_file_for_raw = false; + // At this point file mapped to memory otherwise file cannot decoded item->flipper_string = flipper_format_string_alloc(); subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset); @@ -357,6 +359,7 @@ bool subghz_history_add_to_history( if(!flipper_format_rewind(item->flipper_string)) { FURI_LOG_E(TAG, "Rewind error"); } + tmp_file_for_raw = true; break; } else if(!strcmp(string_get_cstr(instance->tmp_string), "KeeLoq")) { @@ -414,7 +417,7 @@ bool subghz_history_add_to_history( // If we can write to files //bool no_close = false; - if(instance->write_tmp_files) { + if(instance->write_tmp_files && tmp_file_for_raw) { string_t filename; string_t dir_path; string_init(filename); From 85eb740559a5d2b2ab57fb899952e8fdf25845ca Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 06:38:34 +0300 Subject: [PATCH 05/16] do not save detect raw on/off settings --- .../subghz/scenes/subghz_scene_read_raw.c | 2 +- .../scenes/subghz_scene_receiver_config.c | 31 +++++++++++++++++-- .../main/subghz/scenes/subghz_scene_start.c | 6 +++- applications/main/subghz/subghz.c | 7 ++--- .../main/subghz/subghz_last_settings.c | 24 -------------- .../main/subghz/subghz_last_settings.h | 7 ----- 6 files changed, 37 insertions(+), 40 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 3eac03dec..7392221dc 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -341,5 +341,5 @@ void subghz_scene_read_raw_on_exit(void* context) { notification_message(subghz->notifications, &sequence_reset_rgb); //filter restoration - subghz_last_settings_set_detect_raw_values(subghz); + subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); } \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index b782f5a31..0175cd0fd 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -29,6 +29,11 @@ const char* const detect_raw_text[DETECT_RAW_COUNT] = { "ON", }; +const SubGhzProtocolFlag detect_raw_value[DETECT_RAW_COUNT] = { + SubGhzProtocolFlag_Decodable, + SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW, +}; + #define RSSI_THRESHOLD_COUNT 7 const char* const rssi_threshold_text[RSSI_THRESHOLD_COUNT] = { "-72db", @@ -100,6 +105,20 @@ uint8_t subghz_scene_receiver_config_hopper_value_index( } } +uint8_t subghz_scene_receiver_config_detect_raw_value_index( + const SubGhzProtocolFlag value, + const SubGhzProtocolFlag values[], + uint8_t values_count) { + uint8_t index = 0; + for(uint8_t i = 0; i < values_count; i++) { + if(value == values[i]) { + index = i; + break; + } + } + return index; +} + uint8_t subghz_scene_receiver_config_rssi_threshold_value_index( const int value, const int values[], @@ -167,9 +186,12 @@ static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, detect_raw_text[index]); - subghz->last_settings->detect_raw = index; + subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]); - subghz_last_settings_set_detect_raw_values(subghz); + subghz_protocol_decoder_raw_set_auto_mode( + subghz_receiver_search_decoder_base_by_name( + subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), + (index == 1)); } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -282,7 +304,10 @@ void subghz_scene_receiver_config_on_enter(void* context) { DETECT_RAW_COUNT, subghz_scene_receiver_config_set_detect_raw, subghz); - value_index = subghz->last_settings->detect_raw; + value_index = subghz_scene_receiver_config_detect_raw_value_index( + subghz_receiver_get_filter(subghz->txrx->receiver), + detect_raw_value, + DETECT_RAW_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, detect_raw_text[value_index]); diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index f64e29e0c..35c7ecb9c 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -21,7 +21,11 @@ void subghz_scene_start_on_enter(void* context) { if(subghz->state_notifications == SubGhzNotificationStateStarting) { subghz->state_notifications = SubGhzNotificationStateIDLE; } - subghz_last_settings_set_detect_raw_values(subghz); + subghz_protocol_decoder_raw_set_auto_mode( + subghz_receiver_search_decoder_base_by_name( + subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), + false); + subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); submenu_add_item( subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 4b7c9077c..8b9dd399f 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -183,10 +183,9 @@ SubGhz* subghz_alloc() { #if FURI_DEBUG FURI_LOG_D( TAG, - "last frequency: %d, preset: %d, detect_raw: %d", + "last frequency: %d, preset: %d", subghz->last_settings->frequency, - subghz->last_settings->preset, - subghz->last_settings->detect_raw); + subghz->last_settings->preset); #endif subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); @@ -216,7 +215,7 @@ SubGhz* subghz_alloc() { subghz_environment_set_nice_flor_s_rainbow_table_file_name( subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); - subghz_last_settings_set_detect_raw_values(subghz); + subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); subghz_worker_set_overrun_callback( subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 8dd2c165a..78bb702b7 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -1,6 +1,5 @@ #include "subghz_last_settings.h" #include "subghz_i.h" -#include #define TAG "SubGhzLastSettings" @@ -11,11 +10,9 @@ // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 #define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 -#define SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW 0 #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" #define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" -#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -38,7 +35,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count uint32_t temp_frequency = 0; int32_t temp_preset = 0; - uint32_t temp_read_raw = 0; if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { @@ -46,8 +42,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1); flipper_format_read_uint32( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1); - flipper_format_read_uint32( - fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, (uint32_t*)&temp_read_raw, 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } @@ -56,10 +50,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count FURI_LOG_W(TAG, "Last used frequency not found or can't be used!"); instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY; instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; - instance->detect_raw = SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW; } else { instance->frequency = temp_frequency; - instance->detect_raw = temp_read_raw; if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) { FURI_LOG_W(TAG, "Last used preset no found"); @@ -105,10 +97,6 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) { break; } - if(!flipper_format_insert_or_update_uint32( - file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, &instance->detect_raw, 1)) { - break; - } saved = true; } while(0); @@ -122,15 +110,3 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { return saved; } - -void subghz_last_settings_set_detect_raw_values(void* context) { - furi_assert(context); - SubGhz* instance = (SubGhz*)context; - bool is_detect_raw = instance->last_settings->detect_raw > 0; - subghz_receiver_set_filter( - instance->txrx->receiver, is_detect_raw ? DETECT_RAW_TRUE : DETECT_RAW_FALSE); - subghz_protocol_decoder_raw_set_auto_mode( - subghz_receiver_search_decoder_base_by_name( - instance->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), - is_detect_raw); -} \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 5efc7ebb0..7e42650c7 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -4,14 +4,9 @@ #include #include #include -#include - -#define DETECT_RAW_FALSE SubGhzProtocolFlag_Decodable -#define DETECT_RAW_TRUE SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW typedef struct { uint32_t frequency; - uint32_t detect_raw; int32_t preset; } SubGhzLastSettings; @@ -22,5 +17,3 @@ void subghz_last_settings_free(SubGhzLastSettings* instance); void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count); bool subghz_last_settings_save(SubGhzLastSettings* instance); - -void subghz_last_settings_set_detect_raw_values(void* context); \ No newline at end of file From e2faf31b4587f18eec6ad4c15e59eb3e4a554101 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 07:34:39 +0300 Subject: [PATCH 06/16] debug in subghz only when compiled with DEBUG=1 --- applications/main/subghz/scenes/subghz_scene_config.h | 2 ++ applications/main/subghz/scenes/subghz_scene_start.c | 8 +++++++- applications/main/subghz/scenes/subghz_scene_test.c | 2 ++ .../main/subghz/scenes/subghz_scene_test_carrier.c | 2 ++ .../main/subghz/scenes/subghz_scene_test_packet.c | 2 ++ .../main/subghz/scenes/subghz_scene_test_static.c | 2 ++ applications/main/subghz/subghz.c | 5 ++++- applications/main/subghz/subghz_i.h | 5 ++++- 8 files changed, 25 insertions(+), 3 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_config.h b/applications/main/subghz/scenes/subghz_scene_config.h index c2731910b..fcc579d93 100644 --- a/applications/main/subghz/scenes/subghz_scene_config.h +++ b/applications/main/subghz/scenes/subghz_scene_config.h @@ -12,10 +12,12 @@ ADD_SCENE(subghz, show_only_rx, ShowOnlyRx) ADD_SCENE(subghz, saved_menu, SavedMenu) ADD_SCENE(subghz, delete, Delete) ADD_SCENE(subghz, delete_success, DeleteSuccess) +#if FURI_DEBUG ADD_SCENE(subghz, test, Test) ADD_SCENE(subghz, test_static, TestStatic) ADD_SCENE(subghz, test_carrier, TestCarrier) ADD_SCENE(subghz, test_packet, TestPacket) +#endif ADD_SCENE(subghz, set_type, SetType) ADD_SCENE(subghz, set_fix_faac_868, SetFixFaac868) ADD_SCENE(subghz, set_cnt_faac_868, SetCntFaac868) diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index 35c7ecb9c..f9500dc96 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -49,10 +49,12 @@ void subghz_scene_start_on_enter(void* context) { SubmenuIndexFrequencyAnalyzer, subghz_scene_start_submenu_callback, subghz); +#if FURI_DEBUG if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { submenu_add_item( subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz); } +#endif submenu_set_selected_item( subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneStart)); @@ -93,12 +95,16 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) { subghz->scene_manager, SubGhzSceneStart, SubmenuIndexFrequencyAnalyzer); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneFrequencyAnalyzer); return true; - } else if(event.event == SubmenuIndexTest) { + + } +#if FURI_DEBUG + else if(event.event == SubmenuIndexTest) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneStart, SubmenuIndexTest); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTest); return true; } +#endif } return false; } diff --git a/applications/main/subghz/scenes/subghz_scene_test.c b/applications/main/subghz/scenes/subghz_scene_test.c index 65f9bbdef..64473015b 100644 --- a/applications/main/subghz/scenes/subghz_scene_test.c +++ b/applications/main/subghz/scenes/subghz_scene_test.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" enum SubmenuIndex { @@ -59,3 +60,4 @@ void subghz_scene_test_on_exit(void* context) { SubGhz* subghz = context; submenu_reset(subghz->submenu); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_test_carrier.c b/applications/main/subghz/scenes/subghz_scene_test_carrier.c index 9677792ba..4682a627c 100644 --- a/applications/main/subghz/scenes/subghz_scene_test_carrier.c +++ b/applications/main/subghz/scenes/subghz_scene_test_carrier.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" #include "../views/subghz_test_carrier.h" @@ -28,3 +29,4 @@ bool subghz_scene_test_carrier_on_event(void* context, SceneManagerEvent event) void subghz_scene_test_carrier_on_exit(void* context) { UNUSED(context); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_test_packet.c b/applications/main/subghz/scenes/subghz_scene_test_packet.c index 99f0ab179..4757f9f3a 100644 --- a/applications/main/subghz/scenes/subghz_scene_test_packet.c +++ b/applications/main/subghz/scenes/subghz_scene_test_packet.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" #include "../views/subghz_test_packet.h" @@ -28,3 +29,4 @@ bool subghz_scene_test_packet_on_event(void* context, SceneManagerEvent event) { void subghz_scene_test_packet_on_exit(void* context) { UNUSED(context); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_test_static.c b/applications/main/subghz/scenes/subghz_scene_test_static.c index 10e6d02a1..959eb75b8 100644 --- a/applications/main/subghz/scenes/subghz_scene_test_static.c +++ b/applications/main/subghz/scenes/subghz_scene_test_static.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" #include "../views/subghz_test_static.h" @@ -28,3 +29,4 @@ bool subghz_scene_test_static_on_event(void* context, SceneManagerEvent event) { void subghz_scene_test_static_on_exit(void* context) { UNUSED(context); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 8b9dd399f..30e10b106 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -151,6 +151,7 @@ SubGhz* subghz_alloc() { SubGhzViewIdReadRAW, subghz_read_raw_get_view(subghz->subghz_read_raw)); +#if FURI_DEBUG // Carrier Test Module subghz->subghz_test_carrier = subghz_test_carrier_alloc(); view_dispatcher_add_view( @@ -171,6 +172,7 @@ SubGhz* subghz_alloc() { subghz->view_dispatcher, SubGhzViewIdStatic, subghz_test_static_get_view(subghz->subghz_test_static)); +#endif //init setting subghz->setting = subghz_setting_alloc(); @@ -239,6 +241,7 @@ void subghz_free(SubGhz* subghz) { subghz->rpc_ctx = NULL; } +#if FURI_DEBUG // Packet Test view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestPacket); subghz_test_packet_free(subghz->subghz_test_packet); @@ -250,7 +253,7 @@ void subghz_free(SubGhz* subghz) { // Static view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdStatic); subghz_test_static_free(subghz->subghz_test_static); - +#endif // Receiver view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver); subghz_view_receiver_free(subghz->subghz_receiver); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 8872d31f6..a1d68c531 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -7,10 +7,11 @@ #include "views/subghz_frequency_analyzer.h" #include "views/subghz_read_raw.h" +#if FURI_DEBUG #include "views/subghz_test_static.h" #include "views/subghz_test_carrier.h" #include "views/subghz_test_packet.h" - +#endif // #include // #include #include @@ -96,9 +97,11 @@ struct SubGhz { SubGhzFrequencyAnalyzer* subghz_frequency_analyzer; SubGhzReadRAW* subghz_read_raw; +#if FURI_DEBUG SubGhzTestStatic* subghz_test_static; SubGhzTestCarrier* subghz_test_carrier; SubGhzTestPacket* subghz_test_packet; +#endif string_t error_str; SubGhzSetting* setting; SubGhzLastSettings* last_settings; From 6bf306200ee3a30e555082cf8dd91a7c592990a2 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 08:50:41 +0300 Subject: [PATCH 07/16] make loading subghz file from favourites a bit faster --- .../subghz/scenes/subghz_scene_read_raw.c | 22 +- applications/main/subghz/subghz.c | 239 +++++++++++------- applications/main/subghz/subghz_i.h | 1 + applications/main/subghz/subghz_setting.c | 89 +++---- applications/main/subghz/subghz_setting.h | 2 +- .../main/subghz/views/subghz_read_raw.c | 52 ++-- .../main/subghz/views/subghz_read_raw.h | 2 +- applications/main/unirfremix/unirfremix_app.c | 2 +- 8 files changed, 237 insertions(+), 172 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 7392221dc..df7d21680 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -134,12 +134,22 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { //Restore default setting - subghz_preset_init( - subghz, - subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), - subghz->last_settings->frequency, - NULL, - 0); + if(subghz->raw_send_only) { + subghz_preset_init( + subghz, + "AM650", + subghz_setting_get_default_frequency(subghz->setting), + NULL, + 0); + } else { + subghz_preset_init( + subghz, + subghz_setting_get_preset_name( + subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, + NULL, + 0); + } if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneSaved)) { if(!scene_manager_search_and_switch_to_previous_scene( diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 30e10b106..284f8dc2a 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -61,7 +61,7 @@ void subghz_blink_stop(SubGhz* instance) { notification_message(instance->notifications, &sequence_blink_stop); } -SubGhz* subghz_alloc() { +SubGhz* subghz_alloc(bool alloc_for_tx_only) { SubGhz* subghz = malloc(sizeof(SubGhz)); string_init(subghz->file_path); @@ -88,38 +88,43 @@ SubGhz* subghz_alloc() { // Open Notification record subghz->notifications = furi_record_open(RECORD_NOTIFICATION); - // SubMenu - subghz->submenu = submenu_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdMenu, submenu_get_view(subghz->submenu)); - - // Receiver - subghz->subghz_receiver = subghz_view_receiver_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, - SubGhzViewIdReceiver, - subghz_view_receiver_get_view(subghz->subghz_receiver)); + if(!alloc_for_tx_only) { + // SubMenu + subghz->submenu = submenu_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, SubGhzViewIdMenu, submenu_get_view(subghz->submenu)); + // Receiver + subghz->subghz_receiver = subghz_view_receiver_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdReceiver, + subghz_view_receiver_get_view(subghz->subghz_receiver)); + } // Popup subghz->popup = popup_alloc(); view_dispatcher_add_view( subghz->view_dispatcher, SubGhzViewIdPopup, popup_get_view(subghz->popup)); + if(!alloc_for_tx_only) { + // Text Input + subghz->text_input = text_input_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdTextInput, + text_input_get_view(subghz->text_input)); - // Text Input - subghz->text_input = text_input_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdTextInput, text_input_get_view(subghz->text_input)); - - // Byte Input - subghz->byte_input = byte_input_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdByteInput, byte_input_get_view(subghz->byte_input)); - - // Custom Widget - subghz->widget = widget_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdWidget, widget_get_view(subghz->widget)); + // Byte Input + subghz->byte_input = byte_input_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdByteInput, + byte_input_get_view(subghz->byte_input)); + // Custom Widget + subghz->widget = widget_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, SubGhzViewIdWidget, widget_get_view(subghz->widget)); + } //Dialog subghz->dialogs = furi_record_open(RECORD_DIALOGS); @@ -129,23 +134,23 @@ SubGhz* subghz_alloc() { subghz->view_dispatcher, SubGhzViewIdTransmitter, subghz_view_transmitter_get_view(subghz->subghz_transmitter)); + if(!alloc_for_tx_only) { + // Variable Item List + subghz->variable_item_list = variable_item_list_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdVariableItemList, + variable_item_list_get_view(subghz->variable_item_list)); - // Variable Item List - subghz->variable_item_list = variable_item_list_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, - SubGhzViewIdVariableItemList, - variable_item_list_get_view(subghz->variable_item_list)); - - // Frequency Analyzer - subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, - SubGhzViewIdFrequencyAnalyzer, - subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer)); - + // Frequency Analyzer + subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdFrequencyAnalyzer, + subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer)); + } // Read RAW - subghz->subghz_read_raw = subghz_read_raw_alloc(); + subghz->subghz_read_raw = subghz_read_raw_alloc(alloc_for_tx_only); view_dispatcher_add_view( subghz->view_dispatcher, SubGhzViewIdReadRAW, @@ -176,38 +181,51 @@ SubGhz* subghz_alloc() { //init setting subghz->setting = subghz_setting_alloc(); - subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user")); + if(alloc_for_tx_only) { + subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"), false); + } else { + subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"), true); + } // Load last used values for Read, Read RAW, etc. or default - subghz->last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load( - subghz->last_settings, subghz_setting_get_preset_count(subghz->setting)); + if(!alloc_for_tx_only) { + subghz->last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load( + subghz->last_settings, subghz_setting_get_preset_count(subghz->setting)); #if FURI_DEBUG - FURI_LOG_D( - TAG, - "last frequency: %d, preset: %d", - subghz->last_settings->frequency, - subghz->last_settings->preset); + FURI_LOG_D( + TAG, + "last frequency: %d, preset: %d", + subghz->last_settings->frequency, + subghz->last_settings->preset); #endif - subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); - + subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); + } //init Worker & Protocol & History & KeyBoard subghz->lock = SubGhzLockOff; subghz->txrx = malloc(sizeof(SubGhzTxRx)); subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition)); string_init(subghz->txrx->preset->name); - subghz_preset_init( - subghz, - subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), - subghz->last_settings->frequency, - NULL, - 0); - + if(!alloc_for_tx_only) { + subghz_preset_init( + subghz, + subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, + NULL, + 0); + } else { + subghz_preset_init( + subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0); + } subghz->txrx->txrx_state = SubGhzTxRxStateSleep; subghz->txrx->hopper_state = SubGhzHopperStateOFF; subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; - subghz->txrx->history = subghz_history_alloc(); - subghz->txrx->worker = subghz_worker_alloc(); + if(!alloc_for_tx_only) { + subghz->txrx->history = subghz_history_alloc(); + } + if(!alloc_for_tx_only) { + subghz->txrx->worker = subghz_worker_alloc(); + } subghz->txrx->fff_data = flipper_format_string_alloc(); subghz->txrx->secure_data = malloc(sizeof(SecureData)); @@ -216,14 +234,17 @@ SubGhz* subghz_alloc() { subghz->txrx->environment, EXT_PATH("subghz/assets/came_atomo")); subghz_environment_set_nice_flor_s_rainbow_table_file_name( subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); + subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); - subghz_worker_set_overrun_callback( - subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); - subghz_worker_set_pair_callback( - subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); - subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); + if(!alloc_for_tx_only) { + subghz_worker_set_overrun_callback( + subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); + subghz_worker_set_pair_callback( + subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); + subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); + } //Init Error_str string_init(subghz->error_str); @@ -231,7 +252,7 @@ SubGhz* subghz_alloc() { return subghz; } -void subghz_free(SubGhz* subghz) { +void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { furi_assert(subghz); if(subghz->rpc_ctx) { @@ -254,45 +275,47 @@ void subghz_free(SubGhz* subghz) { view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdStatic); subghz_test_static_free(subghz->subghz_test_static); #endif - // Receiver - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver); - subghz_view_receiver_free(subghz->subghz_receiver); - // TextInput - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTextInput); - text_input_free(subghz->text_input); + if(!alloc_for_tx_only) { + // Receiver + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver); + subghz_view_receiver_free(subghz->subghz_receiver); - // ByteInput - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdByteInput); - byte_input_free(subghz->byte_input); + // TextInput + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTextInput); + text_input_free(subghz->text_input); - // Custom Widget - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdWidget); - widget_free(subghz->widget); + // ByteInput + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdByteInput); + byte_input_free(subghz->byte_input); + // Custom Widget + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdWidget); + widget_free(subghz->widget); + } //Dialog furi_record_close(RECORD_DIALOGS); // Transmitter view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTransmitter); subghz_view_transmitter_free(subghz->subghz_transmitter); + if(!alloc_for_tx_only) { + // Variable Item List + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList); + variable_item_list_free(subghz->variable_item_list); - // Variable Item List - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList); - variable_item_list_free(subghz->variable_item_list); - - // Frequency Analyzer - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer); - subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer); - + // Frequency Analyzer + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer); + subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer); + } // Read RAW view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReadRAW); subghz_read_raw_free(subghz->subghz_read_raw); - - // Submenu - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdMenu); - submenu_free(subghz->submenu); - + if(!alloc_for_tx_only) { + // Submenu + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdMenu); + submenu_free(subghz->submenu); + } // Popup view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdPopup); popup_free(subghz->popup); @@ -309,14 +332,21 @@ void subghz_free(SubGhz* subghz) { //setting subghz_setting_free(subghz->setting); - subghz_last_settings_free(subghz->last_settings); - + if(!alloc_for_tx_only) { + subghz_last_settings_free(subghz->last_settings); + } //Worker & Protocol & History + subghz_receiver_free(subghz->txrx->receiver); + subghz_environment_free(subghz->txrx->environment); - subghz_worker_free(subghz->txrx->worker); + if(!alloc_for_tx_only) { + subghz_worker_free(subghz->txrx->worker); + } flipper_format_free(subghz->txrx->fff_data); - subghz_history_free(subghz->txrx->history); + if(!alloc_for_tx_only) { + subghz_history_free(subghz->txrx->history); + } string_clear(subghz->txrx->preset->name); free(subghz->txrx->preset); free(subghz->txrx->secure_data); @@ -338,7 +368,20 @@ void subghz_free(SubGhz* subghz) { } int32_t subghz_app(void* p) { - SubGhz* subghz = subghz_alloc(); + bool alloc_for_tx; + if(p && strlen(p)) { + alloc_for_tx = true; + } else { + alloc_for_tx = false; + } + + SubGhz* subghz = subghz_alloc(alloc_for_tx); + + if(alloc_for_tx) { + subghz->raw_send_only = true; + } else { + subghz->raw_send_only = false; + } //Load database bool load_database = subghz_environment_load_keystore( @@ -397,7 +440,7 @@ int32_t subghz_app(void* p) { furi_hal_power_suppress_charge_exit(); - subghz_free(subghz); + subghz_free(subghz, alloc_for_tx); return 0; } diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index a1d68c531..b177c1ba7 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -97,6 +97,7 @@ struct SubGhz { SubGhzFrequencyAnalyzer* subghz_frequency_analyzer; SubGhzReadRAW* subghz_read_raw; + bool raw_send_only; #if FURI_DEBUG SubGhzTestStatic* subghz_test_static; SubGhzTestCarrier* subghz_test_carrier; diff --git a/applications/main/subghz/subghz_setting.c b/applications/main/subghz/subghz_setting.c index 2e94011cf..8f116322f 100644 --- a/applications/main/subghz/subghz_setting.c +++ b/applications/main/subghz/subghz_setting.c @@ -181,7 +181,7 @@ void subghz_setting_load_default(SubGhzSetting* instance) { instance, subghz_frequency_list, subghz_hopper_frequency_list); } -void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { +void subghz_setting_load(SubGhzSetting* instance, const char* file_path, bool not_skip_frequencies) { furi_assert(instance); Storage* storage = furi_record_open(RECORD_STORAGE); @@ -214,53 +214,56 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { } // Standard frequencies (optional) - temp_bool = true; - flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1); - if(!temp_bool) { - FURI_LOG_I(TAG, "Removing standard frequencies"); - FrequencyList_reset(instance->frequencies); - FrequencyList_reset(instance->hopper_frequencies); - } else { - FURI_LOG_I(TAG, "Keeping standard frequencies"); - } - - // Load frequencies - if(!flipper_format_rewind(fff_data_file)) { - FURI_LOG_E(TAG, "Rewind error"); - break; - } - while(flipper_format_read_uint32( - fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) { - if(furi_hal_subghz_is_frequency_valid(temp_data32)) { - FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32); - FrequencyList_push_back(instance->frequencies, temp_data32); + if(not_skip_frequencies) { + temp_bool = true; + flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1); + if(!temp_bool) { + FURI_LOG_I(TAG, "Removing standard frequencies"); + FrequencyList_reset(instance->frequencies); + FrequencyList_reset(instance->hopper_frequencies); } else { - FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32); + FURI_LOG_I(TAG, "Keeping standard frequencies"); } - } - // Load hopper frequencies - if(!flipper_format_rewind(fff_data_file)) { - FURI_LOG_E(TAG, "Rewind error"); - break; - } - while(flipper_format_read_uint32( - fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) { - if(furi_hal_subghz_is_frequency_valid(temp_data32)) { - FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32); - FrequencyList_push_back(instance->hopper_frequencies, temp_data32); - } else { - FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32); + // Load frequencies + if(!flipper_format_rewind(fff_data_file)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + while(flipper_format_read_uint32( + fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) { + if(furi_hal_subghz_is_frequency_valid(temp_data32)) { + FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32); + FrequencyList_push_back(instance->frequencies, temp_data32); + } else { + FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32); + } } - } - // Default frequency (optional) - if(!flipper_format_rewind(fff_data_file)) { - FURI_LOG_E(TAG, "Rewind error"); - break; - } - if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) { - subghz_setting_set_default_frequency(instance, temp_data32); + // Load hopper frequencies + if(!flipper_format_rewind(fff_data_file)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + while(flipper_format_read_uint32( + fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) { + if(furi_hal_subghz_is_frequency_valid(temp_data32)) { + FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32); + FrequencyList_push_back(instance->hopper_frequencies, temp_data32); + } else { + FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32); + } + } + + // Default frequency (optional) + if(!flipper_format_rewind(fff_data_file)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + if(flipper_format_read_uint32( + fff_data_file, "Default_frequency", &temp_data32, 1)) { + subghz_setting_set_default_frequency(instance, temp_data32); + } } // custom preset (optional) diff --git a/applications/main/subghz/subghz_setting.h b/applications/main/subghz/subghz_setting.h index d6fde1bd6..3b3b1131a 100644 --- a/applications/main/subghz/subghz_setting.h +++ b/applications/main/subghz/subghz_setting.h @@ -14,7 +14,7 @@ SubGhzSetting* subghz_setting_alloc(void); void subghz_setting_free(SubGhzSetting* instance); -void subghz_setting_load(SubGhzSetting* instance, const char* file_path); +void subghz_setting_load(SubGhzSetting* instance, const char* file_path, bool not_skip_frequencies); size_t subghz_setting_get_frequency_count(SubGhzSetting* instance); diff --git a/applications/main/subghz/views/subghz_read_raw.c b/applications/main/subghz/views/subghz_read_raw.c index ccffaf42f..2d24d9411 100644 --- a/applications/main/subghz/views/subghz_read_raw.c +++ b/applications/main/subghz/views/subghz_read_raw.c @@ -27,6 +27,7 @@ typedef struct { uint8_t ind_write; uint8_t ind_sin; SubGhzReadRAWStatus status; + bool raw_send_only; } SubGhzReadRAWModel; void subghz_read_raw_set_callback( @@ -232,9 +233,11 @@ void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) { elements_button_right(canvas, "Save"); break; case SubGhzReadRAWStatusLoadKeyIDLE: - elements_button_left(canvas, "New"); + if(!model->raw_send_only) { + elements_button_left(canvas, "New"); + elements_button_right(canvas, "More"); + } elements_button_center(canvas, "Send"); - elements_button_right(canvas, "More"); elements_text_box( canvas, 4, @@ -362,31 +365,35 @@ bool subghz_read_raw_input(InputEvent* event, void* context) { } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { with_view_model( instance->view, (SubGhzReadRAWModel * model) { - if(model->status == SubGhzReadRAWStatusStart) { - //Config - instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context); - } else if( - (model->status == SubGhzReadRAWStatusIDLE) || - (model->status == SubGhzReadRAWStatusLoadKeyIDLE)) { - //Erase - model->status = SubGhzReadRAWStatusStart; - model->rssi_history_end = false; - model->ind_write = 0; - string_set_str(model->sample_write, "0 spl."); - string_reset(model->file_name); - instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context); + if(!model->raw_send_only) { + if(model->status == SubGhzReadRAWStatusStart) { + //Config + instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context); + } else if( + (model->status == SubGhzReadRAWStatusIDLE) || + (model->status == SubGhzReadRAWStatusLoadKeyIDLE)) { + //Erase + model->status = SubGhzReadRAWStatusStart; + model->rssi_history_end = false; + model->ind_write = 0; + string_set_str(model->sample_write, "0 spl."); + string_reset(model->file_name); + instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context); + } } return true; }); } else if(event->key == InputKeyRight && event->type == InputTypeShort) { with_view_model( instance->view, (SubGhzReadRAWModel * model) { - if(model->status == SubGhzReadRAWStatusIDLE) { - //Save - instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context); - } else if(model->status == SubGhzReadRAWStatusLoadKeyIDLE) { - //More - instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context); + if(!model->raw_send_only) { + if(model->status == SubGhzReadRAWStatusIDLE) { + //Save + instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context); + } else if(model->status == SubGhzReadRAWStatusLoadKeyIDLE) { + //More + instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context); + } } return true; }); @@ -487,7 +494,7 @@ void subghz_read_raw_exit(void* context) { }); } -SubGhzReadRAW* subghz_read_raw_alloc() { +SubGhzReadRAW* subghz_read_raw_alloc(bool raw_send_only) { SubGhzReadRAW* instance = malloc(sizeof(SubGhzReadRAW)); // View allocation and configuration @@ -505,6 +512,7 @@ SubGhzReadRAW* subghz_read_raw_alloc() { string_init(model->preset_str); string_init(model->sample_write); string_init(model->file_name); + model->raw_send_only = raw_send_only; model->rssi_history = malloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t)); return true; }); diff --git a/applications/main/subghz/views/subghz_read_raw.h b/applications/main/subghz/views/subghz_read_raw.h index 1d4bb7dc0..a4e16ca98 100644 --- a/applications/main/subghz/views/subghz_read_raw.h +++ b/applications/main/subghz/views/subghz_read_raw.h @@ -25,7 +25,7 @@ void subghz_read_raw_set_callback( SubGhzReadRAWCallback callback, void* context); -SubGhzReadRAW* subghz_read_raw_alloc(); +SubGhzReadRAW* subghz_read_raw_alloc(bool raw_send_only); void subghz_read_raw_free(SubGhzReadRAW* subghz_static); diff --git a/applications/main/unirfremix/unirfremix_app.c b/applications/main/unirfremix/unirfremix_app.c index df2d318ae..13d47988c 100644 --- a/applications/main/unirfremix/unirfremix_app.c +++ b/applications/main/unirfremix/unirfremix_app.c @@ -827,7 +827,7 @@ static void input_callback(InputEvent* input_event, void* ctx) { void unirfremix_subghz_alloc(UniRFRemix* app) { // load subghz presets app->setting = subghz_setting_alloc(); - subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user")); + subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user"), false); // load mfcodes app->environment = subghz_environment_alloc(); From 63fee41a1f3db199edf5668c55bac4c20b594a57 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 09:51:27 +0300 Subject: [PATCH 08/16] enable worker back --- applications/main/subghz/subghz.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 284f8dc2a..33d93d380 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -223,9 +223,9 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { if(!alloc_for_tx_only) { subghz->txrx->history = subghz_history_alloc(); } - if(!alloc_for_tx_only) { - subghz->txrx->worker = subghz_worker_alloc(); - } + + subghz->txrx->worker = subghz_worker_alloc(); + subghz->txrx->fff_data = flipper_format_string_alloc(); subghz->txrx->secure_data = malloc(sizeof(SecureData)); @@ -238,13 +238,11 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); - if(!alloc_for_tx_only) { - subghz_worker_set_overrun_callback( - subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); - subghz_worker_set_pair_callback( - subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); - subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); - } + subghz_worker_set_overrun_callback( + subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); + subghz_worker_set_pair_callback( + subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); + subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); //Init Error_str string_init(subghz->error_str); @@ -340,9 +338,9 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { subghz_receiver_free(subghz->txrx->receiver); subghz_environment_free(subghz->txrx->environment); - if(!alloc_for_tx_only) { - subghz_worker_free(subghz->txrx->worker); - } + + subghz_worker_free(subghz->txrx->worker); + flipper_format_free(subghz->txrx->fff_data); if(!alloc_for_tx_only) { subghz_history_free(subghz->txrx->history); From 4d3f45e9112427b3b83048c5f5c3786116ab95d0 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 10:18:31 +0300 Subject: [PATCH 09/16] =?UTF-8?q?Don=E2=80=99t=20show=20temp=20history=20d?= =?UTF-8?q?ir=20in=20filebrowser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/services/gui/modules/file_browser_worker.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/applications/services/gui/modules/file_browser_worker.c b/applications/services/gui/modules/file_browser_worker.c index a316a0779..b533f3853 100644 --- a/applications/services/gui/modules/file_browser_worker.c +++ b/applications/services/gui/modules/file_browser_worker.c @@ -14,6 +14,7 @@ #define ASSETS_DIR "assets" #define BADUSB_LAYOUTS_DIR "layouts" +#define SUBGHZ_TEMP_DIR "tmp_history" #define BROWSER_ROOT STORAGE_ANY_PATH_PREFIX #define FILE_NAME_LEN_MAX 256 #define LONG_LOAD_THRESHOLD 100 @@ -80,7 +81,8 @@ static bool browser_filter_by_name(BrowserWorker* browser, string_t name, bool i // Skip assets folders (if enabled) if(browser->skip_assets) { return ((string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true)) && - ((string_cmp_str(name, BADUSB_LAYOUTS_DIR) == 0) ? (false) : (true)); + ((string_cmp_str(name, BADUSB_LAYOUTS_DIR) == 0) ? (false) : (true)) && + ((string_cmp_str(name, SUBGHZ_TEMP_DIR) == 0) ? (false) : (true)); } else { return true; } From 8af749c9650eff6a78ed7a464add8ccacacae64d Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 13:50:29 +0300 Subject: [PATCH 10/16] enable saving detect raw state via define --- .../subghz/scenes/subghz_scene_read_raw.c | 6 ++- .../scenes/subghz_scene_receiver_config.c | 14 ++++++ .../main/subghz/scenes/subghz_scene_start.c | 4 ++ applications/main/subghz/subghz.c | 13 ++++++ .../main/subghz/subghz_last_settings.c | 44 +++++++++++++++++++ .../main/subghz/subghz_last_settings.h | 14 ++++++ 6 files changed, 94 insertions(+), 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index df7d21680..b83ad700f 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -350,6 +350,10 @@ void subghz_scene_read_raw_on_exit(void* context) { subghz->state_notifications = SubGhzNotificationStateIDLE; notification_message(subghz->notifications, &sequence_reset_rgb); - //filter restoration +//filter restoration +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); +#endif } \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 0175cd0fd..6d6627743 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -29,10 +29,12 @@ const char* const detect_raw_text[DETECT_RAW_COUNT] = { "ON", }; +#ifndef SUBGHZ_SAVE_DETECT_RAW_SETTING const SubGhzProtocolFlag detect_raw_value[DETECT_RAW_COUNT] = { SubGhzProtocolFlag_Decodable, SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW, }; +#endif #define RSSI_THRESHOLD_COUNT 7 const char* const rssi_threshold_text[RSSI_THRESHOLD_COUNT] = { @@ -105,6 +107,7 @@ uint8_t subghz_scene_receiver_config_hopper_value_index( } } +#ifndef SUBGHZ_SAVE_DETECT_RAW_SETTING uint8_t subghz_scene_receiver_config_detect_raw_value_index( const SubGhzProtocolFlag value, const SubGhzProtocolFlag values[], @@ -118,6 +121,7 @@ uint8_t subghz_scene_receiver_config_detect_raw_value_index( } return index; } +#endif uint8_t subghz_scene_receiver_config_rssi_threshold_value_index( const int value, @@ -186,12 +190,18 @@ static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, detect_raw_text[index]); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz->last_settings->detect_raw = index; + + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]); subghz_protocol_decoder_raw_set_auto_mode( subghz_receiver_search_decoder_base_by_name( subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), (index == 1)); +#endif } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -304,10 +314,14 @@ void subghz_scene_receiver_config_on_enter(void* context) { DETECT_RAW_COUNT, subghz_scene_receiver_config_set_detect_raw, subghz); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + value_index = subghz->last_settings->detect_raw; +#else value_index = subghz_scene_receiver_config_detect_raw_value_index( subghz_receiver_get_filter(subghz->txrx->receiver), detect_raw_value, DETECT_RAW_COUNT); +#endif variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, detect_raw_text[value_index]); diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index f9500dc96..752fb8a92 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -21,11 +21,15 @@ void subghz_scene_start_on_enter(void* context) { if(subghz->state_notifications == SubGhzNotificationStateStarting) { subghz->state_notifications = SubGhzNotificationStateIDLE; } +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_protocol_decoder_raw_set_auto_mode( subghz_receiver_search_decoder_base_by_name( subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), false); subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); +#endif submenu_add_item( subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 33d93d380..176e9079e 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -193,11 +193,20 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_last_settings_load( subghz->last_settings, subghz_setting_get_preset_count(subghz->setting)); #if FURI_DEBUG +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + FURI_LOG_D( + TAG, + "last frequency: %d, preset: %d, detect_raw: %d", + subghz->last_settings->frequency, + subghz->last_settings->preset, + subghz->last_settings->detect_raw); +#else FURI_LOG_D( TAG, "last frequency: %d, preset: %d", subghz->last_settings->frequency, subghz->last_settings->preset); +#endif #endif subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); } @@ -236,7 +245,11 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); +#endif subghz_worker_set_overrun_callback( subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 78bb702b7..91f6fc841 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -1,5 +1,8 @@ #include "subghz_last_settings.h" #include "subghz_i.h" +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#include +#endif #define TAG "SubGhzLastSettings" @@ -11,9 +14,17 @@ #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 #define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#define SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW 0 +#endif + #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" #define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw" +#endif + SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); return instance; @@ -35,6 +46,9 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count uint32_t temp_frequency = 0; int32_t temp_preset = 0; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + uint32_t temp_read_raw = 0; +#endif if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { @@ -42,6 +56,10 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1); flipper_format_read_uint32( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, (uint32_t*)&temp_read_raw, 1); +#endif } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } @@ -50,8 +68,14 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count FURI_LOG_W(TAG, "Last used frequency not found or can't be used!"); instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY; instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + instance->detect_raw = SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW; +#endif } else { instance->frequency = temp_frequency; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + instance->detect_raw = temp_read_raw; +#endif if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) { FURI_LOG_W(TAG, "Last used preset no found"); @@ -97,6 +121,12 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) { break; } +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, &instance->detect_raw, 1)) { + break; + } +#endif saved = true; } while(0); @@ -110,3 +140,17 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { return saved; } + +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +void subghz_last_settings_set_detect_raw_values(void* context) { + furi_assert(context); + SubGhz* instance = (SubGhz*)context; + bool is_detect_raw = instance->last_settings->detect_raw > 0; + subghz_receiver_set_filter( + instance->txrx->receiver, is_detect_raw ? DETECT_RAW_TRUE : DETECT_RAW_FALSE); + subghz_protocol_decoder_raw_set_auto_mode( + subghz_receiver_search_decoder_base_by_name( + instance->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), + is_detect_raw); +} +#endif \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 7e42650c7..116eacadd 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -1,12 +1,23 @@ #pragma once +// Enable saving detect raw setting state +// #define SUBGHZ_SAVE_DETECT_RAW_SETTING 1 + #include #include #include #include +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#include +#define DETECT_RAW_FALSE SubGhzProtocolFlag_Decodable +#define DETECT_RAW_TRUE SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW +#endif typedef struct { uint32_t frequency; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + uint32_t detect_raw; +#endif int32_t preset; } SubGhzLastSettings; @@ -17,3 +28,6 @@ void subghz_last_settings_free(SubGhzLastSettings* instance); void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count); bool subghz_last_settings_save(SubGhzLastSettings* instance); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +void subghz_last_settings_set_detect_raw_values(void* context); +#endif \ No newline at end of file From cbda5d996fdef8730168fccf56a56a5b9a3131eb Mon Sep 17 00:00:00 2001 From: derskythe Date: Sun, 2 Oct 2022 16:50:03 +0400 Subject: [PATCH 11/16] Fix uncommited merge --- applications/main/subghz/subghz_history.c | 28 ++----------------- .../main/subghz/subghz_last_settings.c | 5 +--- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index ab47562bf..3484b03c2 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -148,22 +148,8 @@ void subghz_history_clear_tmp_dir(SubGhzHistory* instance) { FURI_LOG_E(TAG, "Cannot process temp dir!"); } -#if FURI_DEBUG - FURI_LOG_D(TAG, "storage_common_remove done: %s", res ? "true" : "false"); - furi_delay_ms(LOG_DELAY); -#endif - - // Uncomment it - // Stage 2 - create dir - if(!only_remove_dir) { - res = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); -#if FURI_DEBUG - FURI_LOG_D(TAG, "storage_simply_mkdir done: %s", res ? "true" : "false"); - furi_delay_ms(LOG_DELAY); -#endif - } - - return res; + uint32_t stop_time = furi_get_tick() - start_time; + FURI_LOG_I(TAG, "Running time (clear_tmp_dir): %d ms", stop_time); } SubGhzHistory* subghz_history_alloc(void) { @@ -256,10 +242,6 @@ void subghz_history_reset(SubGhzHistory* instance) { SubGhzHistoryItemArray_reset(instance->history->data); instance->last_index_write = 0; instance->code_last_hash_data = 0; - - /*if(instance->write_tmp_files) { - instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, false); - }*/ } uint16_t subghz_history_get_item(SubGhzHistory* instance) { @@ -390,8 +372,6 @@ bool subghz_history_add_to_history( string_init(item->item_str); string_init(item->protocol_name); - bool tmp_file_for_raw = false; - // At this point file mapped to memory otherwise file cannot decoded item->flipper_string = flipper_format_string_alloc(); subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset); @@ -417,8 +397,6 @@ bool subghz_history_add_to_history( if(!flipper_format_rewind(item->flipper_string)) { FURI_LOG_E(TAG, "Rewind error"); } - tmp_file_for_raw = true; - break; } else if(!strcmp(string_get_cstr(instance->tmp_string), "KeeLoq")) { string_set_str(instance->tmp_string, "KL "); @@ -466,7 +444,7 @@ bool subghz_history_add_to_history( // If we can write to files //bool no_close = false; - if(instance->write_tmp_files && tmp_file_for_raw) { + if(instance->write_tmp_files) { string_t filename; string_t dir_path; string_init(filename); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 4542ac814..6382253b8 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -16,15 +16,12 @@ #ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING #define SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW 0 +#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw" #endif #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" #define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" -#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING -#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw" -#endif - SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); return instance; From be42c390f21bc9e5f19b244b0c5bd4495cf0c6ad Mon Sep 17 00:00:00 2001 From: derskythe Date: Sun, 2 Oct 2022 16:57:32 +0400 Subject: [PATCH 12/16] Save on SD Card only RAW files --- applications/main/subghz/subghz_history.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 3484b03c2..5a9805be3 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -372,6 +372,8 @@ bool subghz_history_add_to_history( string_init(item->item_str); string_init(item->protocol_name); + bool tmp_file_for_raw = false; + // At this point file mapped to memory otherwise file cannot decoded item->flipper_string = flipper_format_string_alloc(); subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset); @@ -397,6 +399,7 @@ bool subghz_history_add_to_history( if(!flipper_format_rewind(item->flipper_string)) { FURI_LOG_E(TAG, "Rewind error"); } + tmp_file_for_raw = true; break; } else if(!strcmp(string_get_cstr(instance->tmp_string), "KeeLoq")) { string_set_str(instance->tmp_string, "KL "); @@ -444,7 +447,7 @@ bool subghz_history_add_to_history( // If we can write to files //bool no_close = false; - if(instance->write_tmp_files) { + if(instance->write_tmp_files && tmp_file_for_raw) { string_t filename; string_t dir_path; string_init(filename); @@ -474,7 +477,7 @@ bool subghz_history_add_to_history( } else { #ifdef FURI_DEBUG - FURI_LOG_W(TAG, "Old fashion way"); + FURI_LOG_I(TAG, "Old fashion way"); #endif } From 43ef4046ed93e361abf00bf25c1e2223e5ab0957 Mon Sep 17 00:00:00 2001 From: derskythe Date: Mon, 3 Oct 2022 19:00:35 +0400 Subject: [PATCH 13/16] Add stubs for split --- applications/main/subghz/subghz_history.c | 116 ++++++++---------- .../main/subghz/subghz_history_private.h | 79 ++++++++++++ 2 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 applications/main/subghz/subghz_history_private.h diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 5a9805be3..8192875dd 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -1,4 +1,5 @@ #include "subghz_history.h" +#include "subghz_history_private.h" #include #include @@ -10,7 +11,10 @@ */ #define SUBGHZ_HISTORY_TMP_DIR EXT_PATH("subghz/tmp_history") #define SUBGHZ_HISTORY_TMP_EXTENSION ".tmp" -#define SUBGHZ_HISTORY_TMP_FILE_KEY "Filename" +#define SUBGHZ_HISTORY_TMP_SIGNAL_MAX_LEVEL_DURATION 700 +#define SUBGHZ_HISTORY_TMP_SIGNAL_MIN_LEVEL_DURATION 100 +#define SUBGHZ_HISTORY_TMP_REMOVE_FILES false +#define SUBGHZ_HISTORY_TMP_RAW_KEY "RAW_Data" #define TAG "SubGhzHistory" @@ -45,25 +49,12 @@ struct SubGhzHistory { #define LOG_DELAY 0 #endif -/** - * @brief Generate filename like 000.tmp - * - * @param filename - input parameter - * @param index - index of file, timestamp doesn't accepted! - */ void subghz_history_generate_temp_filename(string_t filename, uint32_t index) { FuriHalRtcDateTime datetime = {0}; furi_hal_rtc_get_datetime(&datetime); string_init_printf(filename, "%03d%s", index, SUBGHZ_HISTORY_TMP_EXTENSION); } -/** - * @brief Check if directory for temporary files is exists - * - * @param instance SubGhzHistory* - * @return true - * @return false - */ bool subghz_history_is_tmp_dir_exists(SubGhzHistory* instance) { FileInfo file_info; storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &file_info); @@ -77,14 +68,6 @@ bool subghz_history_is_tmp_dir_exists(SubGhzHistory* instance) { return false; } -/** - * @brief Check SD card and create temporary dir if not exists, - * Result write_tmp_files without this unstable work is GUARANTEED - * - * @param instance - SubGhzHistory* - * @return - true all ok - * @return - false we have a problems - */ bool subghz_history_check_sdcard(SubGhzHistory* instance) { #ifdef FURI_DEBUG FURI_LOG_I(TAG, "check_sdcard"); @@ -109,13 +92,6 @@ bool subghz_history_check_sdcard(SubGhzHistory* instance) { return result; } -/** - * @brief Recursive delete dir and files and create new temp dir - * - * @param instance - SubGhzHistory* - * @return true - if all ok - * @return false - if something failed - */ void subghz_history_clear_tmp_dir(SubGhzHistory* instance) { furi_assert(instance); #ifdef FURI_DEBUG @@ -127,7 +103,7 @@ void subghz_history_clear_tmp_dir(SubGhzHistory* instance) { return; } uint32_t start_time = furi_get_tick(); - +#ifdef SUBGHZ_HISTORY_TMP_REMOVE_FILES // Stage 0 - Dir exists? bool res = subghz_history_is_tmp_dir_exists(instance); if(res) { @@ -135,11 +111,9 @@ void subghz_history_clear_tmp_dir(SubGhzHistory* instance) { FileInfo fileinfo; storage_common_stat(instance->storage, SUBGHZ_HISTORY_TMP_DIR, &fileinfo); - if(fileinfo.flags & FSF_DIRECTORY) { - res = storage_simply_remove_recursive(instance->storage, SUBGHZ_HISTORY_TMP_DIR); - } else { - res = (storage_common_remove(instance->storage, SUBGHZ_HISTORY_TMP_DIR) == FSE_OK); - } + res = fileinfo.flags & FSF_DIRECTORY ? + storage_simply_remove_recursive(instance->storage, SUBGHZ_HISTORY_TMP_DIR) : + (storage_common_remove(instance->storage, SUBGHZ_HISTORY_TMP_DIR) == FSE_OK); } // Stage 2 - create dir if necessary @@ -147,7 +121,7 @@ void subghz_history_clear_tmp_dir(SubGhzHistory* instance) { if(!res) { FURI_LOG_E(TAG, "Cannot process temp dir!"); } - +#endif uint32_t stop_time = furi_get_tick() - start_time; FURI_LOG_I(TAG, "Running time (clear_tmp_dir): %d ms", stop_time); } @@ -167,13 +141,9 @@ SubGhzHistory* subghz_history_alloc(void) { return instance; } -/** - * @brief Free item and free all resources - * - * @param item - SubGhzHistoryItem* - */ -void subghz_history_item_free(SubGhzHistoryItem* item) { - furi_assert(item); +void subghz_history_item_free(void* current_item) { + furi_assert(current_item); + SubGhzHistoryItem* item = (SubGhzHistoryItem*)current_item; string_clear(item->item_str); string_clear(item->preset->name); string_clear(item->protocol_name); @@ -187,11 +157,6 @@ void subghz_history_item_free(SubGhzHistoryItem* item) { } } -/** - * @brief free all items in array - * - * @param instance - */ void subghz_history_clean_item_array(SubGhzHistory* instance) { for M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) { @@ -374,7 +339,7 @@ bool subghz_history_add_to_history( bool tmp_file_for_raw = false; - // At this point file mapped to memory otherwise file cannot decoded + // At this point file mapped to memory otherwise file cannot decode item->flipper_string = flipper_format_string_alloc(); subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset); @@ -446,7 +411,6 @@ bool subghz_history_add_to_history( } while(false); // If we can write to files - //bool no_close = false; if(instance->write_tmp_files && tmp_file_for_raw) { string_t filename; string_t dir_path; @@ -458,19 +422,9 @@ bool subghz_history_add_to_history( #ifdef FURI_DEBUG FURI_LOG_I(TAG, "Save temp file: %s", string_get_cstr(dir_path)); #endif - Stream* dst = flipper_format_get_raw_stream(item->flipper_string); - stream_rewind(dst); - if(stream_save_to_file( - dst, instance->storage, string_get_cstr(dir_path), FSOM_CREATE_ALWAYS) > 0) { - flipper_format_free(item->flipper_string); - item->flipper_string = NULL; -#ifdef FURI_DEBUG - FURI_LOG_I(TAG, "Save done!"); -#endif - // This item contains fake data to load from SD - item->is_file = true; - } else { - FURI_LOG_E(TAG, "Stream copy failed!"); + if(!subghz_history_tmp_write_file_split(instance, item, dir_path)) { + // Plan B! + subghz_history_tmp_write_file_full(instance, item, dir_path); } string_clear(filename); string_clear(dir_path); @@ -485,4 +439,40 @@ bool subghz_history_add_to_history( instance->last_index_write++; return true; +} + +bool subghz_history_tmp_write_file_split( + SubGhzHistory* instance, + void* current_item, + string_t dir_path) { + furi_assert(instance); + furi_assert(current_item); + furi_assert(dir_path); + //SubGhzHistoryItem* item = (SubGhzHistoryItem*)current_item; + + return false; +} + +void subghz_history_tmp_write_file_full( + SubGhzHistory* instance, + void* current_item, + string_t dir_path) { + SubGhzHistoryItem* item = (SubGhzHistoryItem*)current_item; +#ifdef FURI_DEBUG + FURI_LOG_W(TAG, "Save temp file full: %s", string_get_cstr(dir_path)); +#endif + Stream* dst = flipper_format_get_raw_stream(item->flipper_string); + stream_rewind(dst); + if(stream_save_to_file(dst, instance->storage, string_get_cstr(dir_path), FSOM_CREATE_ALWAYS) > + 0) { + flipper_format_free(item->flipper_string); + item->flipper_string = NULL; +#ifdef FURI_DEBUG + FURI_LOG_I(TAG, "Save done!"); +#endif + // This item contains fake data to load from SD + item->is_file = true; + } else { + FURI_LOG_E(TAG, "Stream copy failed!"); + } } \ No newline at end of file diff --git a/applications/main/subghz/subghz_history_private.h b/applications/main/subghz/subghz_history_private.h new file mode 100644 index 000000000..0ff802835 --- /dev/null +++ b/applications/main/subghz/subghz_history_private.h @@ -0,0 +1,79 @@ +#pragma once + +#include "subghz_history.h" + +/** + * @brief Generate filename like 000.tmp + * + * @param filename - input parameter + * @param index - index of file, timestamp doesn't accepted! + */ +void subghz_history_generate_temp_filename(string_t filename, uint32_t index); + +/** + * @brief Check if directory for temporary files is exists + * + * @param instance SubGhzHistory* + * @return true + * @return false + */ +bool subghz_history_is_tmp_dir_exists(SubGhzHistory* instance); + +/** + * @brief Check SD card and create temporary dir if not exists, + * Result write_tmp_files without this unstable work is GUARANTEED + * + * @param instance - SubGhzHistory* + * @return - true all ok + * @return - false we have a problems + */ +bool subghz_history_check_sdcard(SubGhzHistory* instance); + +/** + * @brief Recursive delete dir and files and create new temp dir + * + * @param instance - SubGhzHistory* + * @return true - if all ok + * @return false - if something failed + */ +void subghz_history_clear_tmp_dir(SubGhzHistory* instance); + +/** + * @brief Free item and free all resources + * + * @param current_item - SubGhzHistoryItem* + */ +void subghz_history_item_free(void* current_item); + +/** + * @brief free all items in array + * + * @param instance + */ +void subghz_history_clean_item_array(SubGhzHistory* instance); + +/** + * @brief Write temp file fully, without spliting + * + * @param instance - SubGhzHistory* + * @param current_item - SubGhzHistoryItem* + * @param dir_path - full path to file + */ +void subghz_history_tmp_write_file_full( + SubGhzHistory* instance, + void* current_item, + string_t dir_path); + +/** + * @brief Write temp splited to lines + * + * @param instance - SubGhzHistory* + * @param current_item - SubGhzHistoryItem* + * @param dir_path - full path to file + * @return true - file saved + * @return false - error occured + */ +bool subghz_history_tmp_write_file_split( + SubGhzHistory* instance, + void* current_item, + string_t dir_path); \ No newline at end of file From 8dba4f25aef2f36c26092b4a532b609c3fce2426 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 3 Oct 2022 18:20:49 +0300 Subject: [PATCH 14/16] unused --- applications/main/subghz/subghz_history.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 8192875dd..6784b3a0e 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -445,9 +445,12 @@ bool subghz_history_tmp_write_file_split( SubGhzHistory* instance, void* current_item, string_t dir_path) { - furi_assert(instance); + UNUSED(instance); + UNUSED(current_item); + UNUSED(dir_path); + /*furi_assert(instance); furi_assert(current_item); - furi_assert(dir_path); + furi_assert(dir_path);*/ //SubGhzHistoryItem* item = (SubGhzHistoryItem*)current_item; return false; From fbacdc5b7b754f47b70ae5b3a6c35580740d4793 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 3 Oct 2022 18:21:18 +0300 Subject: [PATCH 15/16] fix critical bug with subghz rpc --- applications/main/subghz/scenes/subghz_scene_rpc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 652499d05..77b4783c8 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -1,4 +1,6 @@ #include "../subghz_i.h" +#include +#include typedef enum { SubGhzRpcStateIdle, @@ -97,4 +99,10 @@ void subghz_scene_rpc_on_exit(void* context) { popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); popup_set_icon(popup, 0, 0, NULL); + + // Oh shit here we go again + keeloq_reset_mfname(); + keeloq_reset_kl_type(); + star_line_reset_mfname(); + star_line_reset_kl_type(); } From dce5af5c2e517cafe74cc1f51c2b9c51f483ce9c Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 3 Oct 2022 18:22:09 +0300 Subject: [PATCH 16/16] hmm --- applications/main/subghz/scenes/subghz_scene_rpc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 77b4783c8..5d5ae235e 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -100,7 +100,6 @@ void subghz_scene_rpc_on_exit(void* context) { popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); popup_set_icon(popup, 0, 0, NULL); - // Oh shit here we go again keeloq_reset_mfname(); keeloq_reset_kl_type(); star_line_reset_mfname();