From be942ef7b2b480b85efe85680eaa1ff6ed83d7c0 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Fri, 12 Aug 2022 01:55:19 +0200 Subject: [PATCH 01/11] feat[unirfremix]: allow protocols other than raw --- applications/unirfremix/unirfremix_app.c | 199 +++++++++++++---------- 1 file changed, 116 insertions(+), 83 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index 000b20ef1..c7858e38e 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -12,6 +12,8 @@ #include #include +#include + #define UNIRFMAP_FOLDER "/ext/unirf" #define UNIRFMAP_EXTENSION ".txt" @@ -469,11 +471,46 @@ static void unirfremix_end_send(UniRFRemix* app) { app->processing = 0; } -static void unirfremix_send_signal( +static FuriHalSubGhzPreset str_to_preset(string_t preset) { + if(string_cmp_str(preset, "FuriHalSubGhzPresetOok270Async") == 0) { + return FuriHalSubGhzPresetOok270Async; + } + if(string_cmp_str(preset, "FuriHalSubGhzPresetOok650Async") == 0) { + return FuriHalSubGhzPresetOok650Async; + } + if(string_cmp_str(preset, "FuriHalSubGhzPreset2FSKDev238Async") == 0) { + return FuriHalSubGhzPreset2FSKDev238Async; + } + if(string_cmp_str(preset, "FuriHalSubGhzPreset2FSKDev476Async") == 0) { + return FuriHalSubGhzPreset2FSKDev476Async; + } + if(string_cmp_str(preset, "FuriHalSubGhzPresetMSK99_97KbAsync") == 0) { + return FuriHalSubGhzPresetMSK99_97KbAsync; + } + if(string_cmp_str(preset, "FuriHalSubGhzPresetMSK99_97KbAsync") == 0) { + return FuriHalSubGhzPresetMSK99_97KbAsync; + } + return FuriHalSubGhzPresetCustom; +} + +static bool unirfremix_send_sub( UniRFRemix* app, - uint32_t frequency, - string_t signal, - string_t protocol) { + FlipperFormat* fff_file, + FlipperFormat* fff_data, + string_t protocol, + string_t preset, + const char* path) { + // + if(!flipper_format_file_open_existing(fff_file, path)) { + FURI_LOG_E(TAG, "Could not open file %s", path); + return false; + } + + uint32_t frequency = 0; + if(!flipper_format_read_uint32(fff_file, "Frequency", &frequency, 1)) { + FURI_LOG_W(TAG, "Cannot read frequency. Defaulting to 433.92 MHz"); + frequency = 433920000; + } if(!furi_hal_subghz_is_tx_allowed(frequency)) { printf( "In your settings, only reception on this frequency (%lu) is allowed,\r\n" @@ -481,61 +518,84 @@ static void unirfremix_send_signal( frequency); app->tx_not_allowed = true; unirfremix_end_send(app); - return; + return false; } else { app->tx_not_allowed = false; } - for(int x = 1; x <= app->repeat; x++) { - frequency = frequency ? frequency : 433920000; - FURI_LOG_E(TAG, "file to send: %s", string_get_cstr(signal)); - string_t flipper_format_string; - if(strcmp(string_get_cstr(protocol), "RAW") == 0) { - string_init_printf(flipper_format_string, "File_name: %s", string_get_cstr(signal)); - } else { - unirfremix_end_send(app); - } - - NotificationApp* notification = furi_record_open("notification"); - - FlipperFormat* flipper_format = flipper_format_string_alloc(); - Stream* stream = flipper_format_get_raw_stream(flipper_format); - stream_clean(stream); - stream_write_cstring(stream, string_get_cstr(flipper_format_string)); - - SubGhzEnvironment* environment = subghz_environment_alloc(); - SubGhzTransmitter* transmitter = - subghz_transmitter_alloc_init(environment, string_get_cstr(protocol)); - subghz_transmitter_deserialize(transmitter, flipper_format); - - furi_hal_subghz_reset(); - furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async); - furi_hal_subghz_set_frequency_and_path(frequency); - - //printf("Transmitting at %lu, repeat %d.\r\n", frequency, x); - - furi_hal_power_suppress_charge_enter(); - furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); - - while(!(furi_hal_subghz_is_async_tx_complete())) { - notification_message(notification, &sequence_blink_magenta_10); - //printf("Sending..."); - fflush(stdout); - furi_delay_ms(333); - } - - furi_record_close("notification"); - - furi_hal_subghz_stop_async_tx(); - furi_hal_subghz_sleep(); - - furi_hal_power_suppress_charge_exit(); - - flipper_format_free(flipper_format); - subghz_transmitter_free(transmitter); - subghz_environment_free(environment); + if(!flipper_format_read_string(fff_file, "Preset", preset)) { + FURI_LOG_W(TAG, "Could not read Preset. Defaulting to Ook650Async"); + string_set(preset, "FuriHalSubGhzPresetOok650Async"); } + if(!flipper_format_read_string(fff_file, "Protocol", protocol)) { + FURI_LOG_W(TAG, "Could not read Protocol. Defaulting to RAW"); + string_set(protocol, "RAW"); + } + + if(!string_cmp_str(protocol, "RAW")) { + subghz_protocol_raw_gen_fff_data(fff_data, path); + } else { + stream_copy_full( + flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data)); + } + flipper_format_free(fff_file); + + SubGhzEnvironment* environment = subghz_environment_alloc(); + SubGhzTransmitter* transmitter = + subghz_transmitter_alloc_init(environment, string_get_cstr(protocol)); + + subghz_transmitter_deserialize(transmitter, fff_data); + + furi_hal_subghz_reset(); + furi_hal_subghz_load_preset(str_to_preset(preset)); + + frequency = furi_hal_subghz_set_frequency_and_path(frequency); + + furi_hal_power_suppress_charge_enter(); + furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); + + FURI_LOG_I(TAG, "Sending..."); + while(!furi_hal_subghz_is_async_tx_complete()) { + fflush(stdout); + furi_delay_ms(333); + } + FURI_LOG_I(TAG, " Done!"); + + furi_hal_subghz_stop_async_tx(); + furi_hal_subghz_sleep(); + + furi_hal_power_suppress_charge_exit(); + + subghz_transmitter_free(transmitter); + return true; +} + +static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, string_t signal) { + FURI_LOG_I(TAG, "Sending: %s", string_get_cstr(signal)); + + FlipperFormat* fff_data = flipper_format_string_alloc(); + + string_t preset, protocol; + string_init(preset); + string_init(protocol); + + for(int x = 0; x < app->repeat; ++x) { + FlipperFormat* fff_file = flipper_format_file_alloc(storage); + bool res = unirfremix_send_sub( + app, fff_file, fff_data, protocol, preset, string_get_cstr(signal)); + + if(!res) { // errored + flipper_format_free(fff_file); + break; + } + } + + string_clear(preset); + string_clear(protocol); + + flipper_format_free(fff_data); + unirfremix_end_send(app); } @@ -545,36 +605,9 @@ static void unirfremix_process_signal(UniRFRemix* app, string_t signal) { FURI_LOG_I(TAG, "signal = %s", string_get_cstr(signal)); if(strlen(string_get_cstr(signal)) > 12) { - string_t file_name; - string_init(file_name); - - string_t protocol; - string_init(protocol); - - uint32_t frequency_str; - - string_set(file_name, string_get_cstr(signal)); - - Storage* storage = furi_record_open("storage"); - FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - - flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name)); - - flipper_format_read_uint32(fff_data_file, "Frequency", (uint32_t*)&frequency_str, 1); - - if(!flipper_format_read_string(fff_data_file, "Protocol", protocol)) { - FURI_LOG_I(TAG, "Could not read Protocol"); - string_set(protocol, "RAW"); - } - - flipper_format_free(fff_data_file); - furi_record_close("storage"); - - FURI_LOG_I(TAG, "%lu", frequency_str); - - string_clear(file_name); - - unirfremix_send_signal(app, frequency_str, signal, protocol); + Storage* storage = furi_record_open(RECORD_STORAGE); + unirfremix_send_signal(app, storage, signal); + furi_record_close(RECORD_STORAGE); } else if(strlen(string_get_cstr(signal)) < 10) { unirfremix_end_send(app); } From 36784f95c8f393e31bc048d1bc648f58db1e9a46 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Sun, 14 Aug 2022 23:26:49 +0200 Subject: [PATCH 02/11] refactor[unirf]: dynamic protocol updates --- applications/unirfremix/unirfremix_app.c | 381 +++++++++++++++-------- 1 file changed, 257 insertions(+), 124 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index c7858e38e..eeb96028f 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -13,6 +13,8 @@ #include #include +#include +#include #define UNIRFMAP_FOLDER "/ext/unirf" #define UNIRFMAP_EXTENSION ".txt" @@ -27,6 +29,8 @@ typedef struct { ViewPort* view_port; Gui* gui; + SubGhzSetting* setting; + string_t up_file; string_t down_file; string_t left_file; @@ -68,6 +72,20 @@ typedef struct { } UniRFRemix; +typedef struct { + uint32_t frequency; + string_t name; + + uint8_t* data; + size_t data_size; +} UniRFPreset; + +UniRFPreset* unirf_preset_alloc(void) { + UniRFPreset* preset = malloc(sizeof(UniRFPreset)); + string_init(preset->name); + return preset; +} + static char* char_to_str(char* str, int i) { char* converted = malloc(sizeof(char) * i + 1); memcpy(converted, str, i); @@ -104,37 +122,6 @@ static const char* int_to_char(int number) { } } -/*Decided not to use this -//check name for special characters and length -static char* check_special(char* filename) -{ - char stripped[11]; - - //grab length of string - int len = strlen(filename); - - int c = 0; - int i; - - //remove special characters - for (i = 0; i < len; i++) - { - if (isalnum((unsigned)filename[i])) - { - if(c < 11) - { - stripped[c] = filename[i]; - c++; - } - } - } - - stripped[c] = '\0'; - - return char_to_str(stripped, 10); -} -*/ - //get filename without path static char* extract_filename(const char* name, int len) { string_t tmp; @@ -156,7 +143,7 @@ static char* extract_filename(const char* name, int len) { */ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { - Storage* storage = furi_record_open("storage"); + Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); app->file_result = 3; @@ -352,7 +339,7 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } flipper_format_free(fff_data_file); - furi_record_close("storage"); + furi_record_close(RECORD_STORAGE); //File Existence Check //Check each file definition if not already set to "N/A" @@ -374,7 +361,7 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //if button is still enabled, check that file exists if(app->up_enabled == 1) { string_set(file_name, app->up_file); - storage = furi_record_open("storage"); + storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -388,12 +375,12 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //close the file flipper_format_free(fff_data_file); - furi_record_close("storage"); + furi_record_close(RECORD_STORAGE); } if(app->down_enabled == 1) { string_set(file_name, app->down_file); - storage = furi_record_open("storage"); + storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -405,12 +392,12 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } flipper_format_free(fff_data_file); - furi_record_close("storage"); + furi_record_close(RECORD_STORAGE); } if(app->left_enabled == 1) { string_set(file_name, app->left_file); - storage = furi_record_open("storage"); + storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -422,12 +409,12 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } flipper_format_free(fff_data_file); - furi_record_close("storage"); + furi_record_close(RECORD_STORAGE); } if(app->right_enabled == 1) { string_set(file_name, app->right_file); - storage = furi_record_open("storage"); + storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -439,12 +426,12 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } flipper_format_free(fff_data_file); - furi_record_close("storage"); + furi_record_close(RECORD_STORAGE); } if(app->ok_enabled == 1) { string_set(file_name, app->ok_file); - storage = furi_record_open("storage"); + storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -456,7 +443,7 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } flipper_format_free(fff_data_file); - furi_record_close("storage"); + furi_record_close(RECORD_STORAGE); } if(app->file_blank == 5) { @@ -471,34 +458,141 @@ static void unirfremix_end_send(UniRFRemix* app) { app->processing = 0; } -static FuriHalSubGhzPreset str_to_preset(string_t preset) { - if(string_cmp_str(preset, "FuriHalSubGhzPresetOok270Async") == 0) { - return FuriHalSubGhzPresetOok270Async; +bool unirf_set_preset(UniRFPreset* p, const char* preset) { + if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { + string_set(p->name, "AM270"); + } else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) { + string_set(p->name, "AM650"); + } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) { + string_set(p->name, "FM238"); + } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) { + string_set(p->name, "FM476"); + } else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) { + string_set(p->name, "CUSTOM"); + } else { + FURI_LOG_E(TAG, "Unsupported preset"); + return false; } - if(string_cmp_str(preset, "FuriHalSubGhzPresetOok650Async") == 0) { - return FuriHalSubGhzPresetOok650Async; + return true; +} + +bool unirf_key_load( + UniRFPreset* preset, + FlipperFormat* fff_file, + FlipperFormat* fff_data, + SubGhzSetting* setting, + SubGhzReceiver* receiver, + const char* path) { + // + if(!flipper_format_rewind(fff_file)) { + FURI_LOG_E(TAG, "Rewind error"); + return NULL; } - if(string_cmp_str(preset, "FuriHalSubGhzPreset2FSKDev238Async") == 0) { - return FuriHalSubGhzPreset2FSKDev238Async; - } - if(string_cmp_str(preset, "FuriHalSubGhzPreset2FSKDev476Async") == 0) { - return FuriHalSubGhzPreset2FSKDev476Async; - } - if(string_cmp_str(preset, "FuriHalSubGhzPresetMSK99_97KbAsync") == 0) { - return FuriHalSubGhzPresetMSK99_97KbAsync; - } - if(string_cmp_str(preset, "FuriHalSubGhzPresetMSK99_97KbAsync") == 0) { - return FuriHalSubGhzPresetMSK99_97KbAsync; - } - return FuriHalSubGhzPresetCustom; + + string_t temp_str; + string_init(temp_str); + + bool res = false; + + do { + // load frequency from file + uint32_t frequency = 0; + if(!flipper_format_read_uint32(fff_file, "Frequency", &frequency, 1)) { + FURI_LOG_W(TAG, "Cannot read frequency. Defaulting to 433.92 MHz"); + frequency = 433920000; + } + preset->frequency = frequency; + + // load preset from file + if(!flipper_format_read_string(fff_file, "Preset", temp_str)) { + FURI_LOG_W(TAG, "Could not read Preset. Defaulting to Ook650Async"); + string_set(temp_str, "FuriHalSubGhzPresetOok650Async"); + } + if(!unirf_set_preset(preset, string_get_cstr(temp_str))) { + FURI_LOG_E(TAG, "Could not set preset"); + break; + } + if(!strcmp(string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) { + // TODO: check if preset is custom + } + size_t preset_index = + subghz_setting_get_inx_preset_by_name(setting, string_get_cstr(preset->name)); + FURI_LOG_I(TAG, "Preset index: %d", preset_index); + preset->data = subghz_setting_get_preset_data(setting, preset_index); + FURI_LOG_I(TAG, "Preset data: %p", preset->data); + preset->data_size = subghz_setting_get_preset_data_size(setting, preset_index); + FURI_LOG_I(TAG, "Preset data size: %d", preset->data_size); + + // load protocol from file + if(!flipper_format_read_string(fff_file, "Protocol", temp_str)) { + FURI_LOG_W(TAG, "Could not read Protocol."); + break; + } + if(!string_cmp_str(temp_str, "RAW")) { + FURI_LOG_I(TAG, "RAW protocol"); + subghz_protocol_raw_gen_fff_data(fff_data, path); + } else { + FURI_LOG_E(TAG, "Other protocol"); + stream_copy_full( + flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data)); + } + SubGhzProtocolDecoderBase* decoder_res = + subghz_receiver_search_decoder_base_by_name(receiver, string_get_cstr(temp_str)); + if(decoder_res) { + if(!subghz_protocol_decoder_base_deserialize(decoder_res, fff_data)) { + break; + } + } else { + FURI_LOG_E(TAG, "Protocol %s not found", string_get_cstr(temp_str)); + } + + res = true; + } while(0); + + string_clear(temp_str); + + return res; +} + +// method modified from subghz_i.c +bool unirf_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_file_name) { + furi_assert(fff_file); + furi_assert(dev_file_name); + + Storage* storage = furi_record_open(RECORD_STORAGE); + Stream* flipper_format_stream = flipper_format_get_raw_stream(fff_file); + + bool saved = false; + string_t file_dir; + string_init(file_dir); + + path_extract_dirname(dev_file_name, file_dir); + do { + flipper_format_delete_key(fff_file, "Repeat"); + flipper_format_delete_key(fff_file, "Manufacture"); + + if(!storage_simply_mkdir(storage, string_get_cstr(file_dir))) { + break; + } + + if(!storage_simply_remove(storage, dev_file_name)) { + break; + } + //ToDo check Write + stream_seek(flipper_format_stream, 0, StreamOffsetFromStart); + stream_save_to_file(flipper_format_stream, storage, dev_file_name, FSOM_CREATE_ALWAYS); + + saved = true; + } while(0); + string_clear(file_dir); + furi_record_close(RECORD_STORAGE); + return saved; } static bool unirfremix_send_sub( UniRFRemix* app, FlipperFormat* fff_file, FlipperFormat* fff_data, - string_t protocol, - string_t preset, const char* path) { // if(!flipper_format_file_open_existing(fff_file, path)) { @@ -506,68 +600,106 @@ static bool unirfremix_send_sub( return false; } - uint32_t frequency = 0; - if(!flipper_format_read_uint32(fff_file, "Frequency", &frequency, 1)) { - FURI_LOG_W(TAG, "Cannot read frequency. Defaulting to 433.92 MHz"); - frequency = 433920000; - } - if(!furi_hal_subghz_is_tx_allowed(frequency)) { - printf( - "In your settings, only reception on this frequency (%lu) is allowed,\r\n" - "the actual operation of the unirf app is not possible\r\n ", - frequency); - app->tx_not_allowed = true; - unirfremix_end_send(app); - return false; - } else { - app->tx_not_allowed = false; - } - - if(!flipper_format_read_string(fff_file, "Preset", preset)) { - FURI_LOG_W(TAG, "Could not read Preset. Defaulting to Ook650Async"); - string_set(preset, "FuriHalSubGhzPresetOok650Async"); - } - - if(!flipper_format_read_string(fff_file, "Protocol", protocol)) { - FURI_LOG_W(TAG, "Could not read Protocol. Defaulting to RAW"); - string_set(protocol, "RAW"); - } - - if(!string_cmp_str(protocol, "RAW")) { - subghz_protocol_raw_gen_fff_data(fff_data, path); - } else { - stream_copy_full( - flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data)); - } - flipper_format_free(fff_file); - SubGhzEnvironment* environment = subghz_environment_alloc(); - SubGhzTransmitter* transmitter = - subghz_transmitter_alloc_init(environment, string_get_cstr(protocol)); + SubGhzReceiver* subghz_receiver = subghz_receiver_alloc_init(environment); - subghz_transmitter_deserialize(transmitter, fff_data); - - furi_hal_subghz_reset(); - furi_hal_subghz_load_preset(str_to_preset(preset)); - - frequency = furi_hal_subghz_set_frequency_and_path(frequency); - - furi_hal_power_suppress_charge_enter(); - furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); - - FURI_LOG_I(TAG, "Sending..."); - while(!furi_hal_subghz_is_async_tx_complete()) { - fflush(stdout); - furi_delay_ms(333); + UniRFPreset* preset = unirf_preset_alloc(); + if(!unirf_key_load(preset, fff_file, fff_data, app->setting, subghz_receiver, path)) { + FURI_LOG_E(TAG, "Could not load key"); + return false; } - FURI_LOG_I(TAG, " Done!"); + FURI_LOG_I(TAG, "Loaded preset."); - furi_hal_subghz_stop_async_tx(); - furi_hal_subghz_sleep(); + // TODO: reimplement this later: + /* + if(!furi_hal_subghz_is_tx_allowed(frequency)) { + printf( + "In your settings, only reception on this frequency (%lu) is allowed,\r\n" + "the actual operation of the unirf app is not possible\r\n ", + frequency); + app->tx_not_allowed = true; + unirfremix_end_send(app); + return false; + } else { + app->tx_not_allowed = false; + } + */ - furi_hal_power_suppress_charge_exit(); + string_t temp_str; + string_init(temp_str); - subghz_transmitter_free(transmitter); + do { + if(!flipper_format_rewind(fff_file)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + + if(!flipper_format_read_string(fff_file, "Protocol", temp_str)) { + FURI_LOG_E(TAG, "Could not read Protocol"); + break; + } + + uint32_t repeat = 200; + if(!flipper_format_insert_or_update_uint32(fff_file, "Repeat", &repeat, 1)) { + FURI_LOG_E(TAG, "Unable to insert or update Repeat"); + break; + } + + SubGhzTransmitter* transmitter = + subghz_transmitter_alloc_init(environment, string_get_cstr(temp_str)); + FURI_LOG_I(TAG, "Got transmitter for %s", string_get_cstr(temp_str)); + + if(transmitter) { + subghz_transmitter_deserialize(transmitter, fff_data); + + furi_hal_subghz_reset(); + furi_hal_subghz_idle(); + furi_hal_subghz_load_custom_preset(preset->data); + furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow); + + furi_hal_subghz_set_frequency_and_path(preset->frequency); + furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); + furi_hal_gpio_write(&gpio_cc1101_g0, true); + + furi_hal_power_suppress_charge_enter(); + + if(furi_hal_subghz_tx()) { + furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); + + FURI_LOG_I(TAG, "Sending..."); + while(!furi_hal_subghz_is_async_tx_complete()) { + // fflush(stdout); + furi_delay_ms(33); + } + FURI_LOG_I(TAG, " Done!"); + + furi_hal_subghz_stop_async_tx(); + + subghz_transmitter_stop(transmitter); + subghz_transmitter_free(transmitter); + + FURI_LOG_I(TAG, "Checking if protocol is dynamic"); + const SubGhzProtocol* registry_protocol = + subghz_protocol_registry_get_by_name(string_get_cstr(temp_str)); + if(registry_protocol && registry_protocol->type == SubGhzProtocolTypeDynamic) { + FURI_LOG_I(TAG, " Protocol is dynamic. Updating Repeat"); + unirf_save_protocol_to_file(fff_file, path); + } + } else { + FURI_LOG_E(TAG, "Sending not allowed"); + } + + FURI_LOG_I(TAG, "Cleaning up."); + furi_hal_subghz_idle(); + furi_hal_subghz_sleep(); + furi_hal_power_suppress_charge_exit(); + } + } while(0); + + string_clear(temp_str); + unirfremix_end_send(app); + + subghz_environment_free(environment); return true; } @@ -582,8 +714,7 @@ static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, string_t s for(int x = 0; x < app->repeat; ++x) { FlipperFormat* fff_file = flipper_format_file_alloc(storage); - bool res = unirfremix_send_sub( - app, fff_file, fff_data, protocol, preset, string_get_cstr(signal)); + bool res = unirfremix_send_sub(app, fff_file, fff_data, string_get_cstr(signal)); if(!res) { // errored flipper_format_free(fff_file); @@ -709,7 +840,6 @@ static void render_callback(Canvas* canvas, void* ctx) { static void input_callback(InputEvent* input_event, void* ctx) { UniRFRemix* app = ctx; - furi_message_queue_put(app->input_queue, input_event, 0); } @@ -728,6 +858,9 @@ UniRFRemix* unirfremix_alloc() { app->gui = furi_record_open(RECORD_GUI); gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen); + app->setting = subghz_setting_alloc(); + subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user")); + return app; } @@ -780,11 +913,11 @@ int32_t unirfremix_app(void* p) { app->file_result = 3; - Storage* storage = furi_record_open("storage"); + Storage* storage = furi_record_open(RECORD_STORAGE); if(!storage_simply_mkdir(storage, UNIRFMAP_FOLDER)) { FURI_LOG_E(TAG, "Could not create folder %s", UNIRFMAP_FOLDER); } - furi_record_close("storage"); + furi_record_close(RECORD_STORAGE); string_set_str(app->file_path, UNIRFMAP_FOLDER); From 33fbf268b79c216516b59ad87524e68259004e9e Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Sun, 14 Aug 2022 23:52:05 +0200 Subject: [PATCH 03/11] fix[unirf]: close fff_file --- applications/unirfremix/unirfremix_app.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index eeb96028f..7d9979482 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -529,10 +529,10 @@ bool unirf_key_load( break; } if(!string_cmp_str(temp_str, "RAW")) { - FURI_LOG_I(TAG, "RAW protocol"); + FURI_LOG_I(TAG, "-> RAW protocol"); subghz_protocol_raw_gen_fff_data(fff_data, path); } else { - FURI_LOG_E(TAG, "Other protocol"); + FURI_LOG_I(TAG, "-> Other protocol"); stream_copy_full( flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data)); } @@ -572,10 +572,12 @@ bool unirf_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_file_n flipper_format_delete_key(fff_file, "Manufacture"); if(!storage_simply_mkdir(storage, string_get_cstr(file_dir))) { + FURI_LOG_E(TAG, "(save) Cannot mkdir"); break; } if(!storage_simply_remove(storage, dev_file_name)) { + FURI_LOG_E(TAG, "(save) Cannot remove"); break; } //ToDo check Write @@ -583,6 +585,7 @@ bool unirf_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_file_n stream_save_to_file(flipper_format_stream, storage, dev_file_name, FSOM_CREATE_ALWAYS); saved = true; + FURI_LOG_I(TAG, "(save) OK Save"); } while(0); string_clear(file_dir); furi_record_close(RECORD_STORAGE); @@ -628,6 +631,7 @@ static bool unirfremix_send_sub( string_t temp_str; string_init(temp_str); + bool res = false; do { if(!flipper_format_rewind(fff_file)) { FURI_LOG_E(TAG, "Rewind error"); @@ -678,6 +682,8 @@ static bool unirfremix_send_sub( subghz_transmitter_stop(transmitter); subghz_transmitter_free(transmitter); + flipper_format_file_close(fff_file); + FURI_LOG_I(TAG, "Checking if protocol is dynamic"); const SubGhzProtocol* registry_protocol = subghz_protocol_registry_get_by_name(string_get_cstr(temp_str)); @@ -694,13 +700,15 @@ static bool unirfremix_send_sub( furi_hal_subghz_sleep(); furi_hal_power_suppress_charge_exit(); } + + res = true; } while(0); string_clear(temp_str); unirfremix_end_send(app); subghz_environment_free(environment); - return true; + return res; } static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, string_t signal) { From 3aed4de1b4961ecabb0d529aaa5b674dd6f72913 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Mon, 15 Aug 2022 20:52:04 +0200 Subject: [PATCH 04/11] fix[unirf]: passed wrong FlipperFormat --- applications/unirfremix/unirfremix_app.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index 7d9979482..f1f21c32c 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -542,6 +542,8 @@ bool unirf_key_load( if(!subghz_protocol_decoder_base_deserialize(decoder_res, fff_data)) { break; } + subghz_protocol_decoder_base_get_string(decoder_res, temp_str); + FURI_LOG_I(TAG, "Protocol-Des: %s", string_get_cstr(temp_str)); } else { FURI_LOG_E(TAG, "Protocol %s not found", string_get_cstr(temp_str)); } @@ -661,6 +663,7 @@ static bool unirfremix_send_sub( furi_hal_subghz_load_custom_preset(preset->data); furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow); + furi_hal_subghz_idle(); furi_hal_subghz_set_frequency_and_path(preset->frequency); furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); furi_hal_gpio_write(&gpio_cc1101_g0, true); @@ -689,7 +692,7 @@ static bool unirfremix_send_sub( subghz_protocol_registry_get_by_name(string_get_cstr(temp_str)); if(registry_protocol && registry_protocol->type == SubGhzProtocolTypeDynamic) { FURI_LOG_I(TAG, " Protocol is dynamic. Updating Repeat"); - unirf_save_protocol_to_file(fff_file, path); + unirf_save_protocol_to_file(fff_data, path); } } else { FURI_LOG_E(TAG, "Sending not allowed"); From 71c27de8cc32bd17e2c46a2cd3b42e6bf8a489e8 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Fri, 19 Aug 2022 03:38:35 +0200 Subject: [PATCH 05/11] fix[unirf]: load environment mf codes --- applications/unirfremix/unirfremix_app.c | 35 ++++++++++++++---------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index f1f21c32c..b3c010f92 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -78,6 +78,8 @@ typedef struct { uint8_t* data; size_t data_size; + + SubGhzProtocolDecoderBase* decoder; } UniRFPreset; UniRFPreset* unirf_preset_alloc(void) { @@ -517,11 +519,8 @@ bool unirf_key_load( } size_t preset_index = subghz_setting_get_inx_preset_by_name(setting, string_get_cstr(preset->name)); - FURI_LOG_I(TAG, "Preset index: %d", preset_index); preset->data = subghz_setting_get_preset_data(setting, preset_index); - FURI_LOG_I(TAG, "Preset data: %p", preset->data); preset->data_size = subghz_setting_get_preset_data_size(setting, preset_index); - FURI_LOG_I(TAG, "Preset data size: %d", preset->data_size); // load protocol from file if(!flipper_format_read_string(fff_file, "Protocol", temp_str)) { @@ -529,21 +528,18 @@ bool unirf_key_load( break; } if(!string_cmp_str(temp_str, "RAW")) { - FURI_LOG_I(TAG, "-> RAW protocol"); subghz_protocol_raw_gen_fff_data(fff_data, path); } else { - FURI_LOG_I(TAG, "-> Other protocol"); stream_copy_full( flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data)); } - SubGhzProtocolDecoderBase* decoder_res = + + preset->decoder = subghz_receiver_search_decoder_base_by_name(receiver, string_get_cstr(temp_str)); - if(decoder_res) { - if(!subghz_protocol_decoder_base_deserialize(decoder_res, fff_data)) { + if(preset->decoder) { + if(!subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data)) { break; } - subghz_protocol_decoder_base_get_string(decoder_res, temp_str); - FURI_LOG_I(TAG, "Protocol-Des: %s", string_get_cstr(temp_str)); } else { FURI_LOG_E(TAG, "Protocol %s not found", string_get_cstr(temp_str)); } @@ -606,6 +602,13 @@ static bool unirfremix_send_sub( } SubGhzEnvironment* environment = subghz_environment_alloc(); + subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); + subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); + subghz_environment_set_came_atomo_rainbow_table_file_name( + environment, EXT_PATH("subghz/assets/came_atomo")); + subghz_environment_set_nice_flor_s_rainbow_table_file_name( + environment, EXT_PATH("subghz/assets/nice_flor_s")); + SubGhzReceiver* subghz_receiver = subghz_receiver_alloc_init(environment); UniRFPreset* preset = unirf_preset_alloc(); @@ -687,6 +690,10 @@ static bool unirfremix_send_sub( flipper_format_file_close(fff_file); + subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); + subghz_protocol_decoder_base_get_string(preset->decoder, temp_str); + FURI_LOG_I(TAG, "Decoded: %s", string_get_cstr(temp_str)); + FURI_LOG_I(TAG, "Checking if protocol is dynamic"); const SubGhzProtocol* registry_protocol = subghz_protocol_registry_get_by_name(string_get_cstr(temp_str)); @@ -714,8 +721,8 @@ static bool unirfremix_send_sub( return res; } -static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, string_t signal) { - FURI_LOG_I(TAG, "Sending: %s", string_get_cstr(signal)); +static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char* path) { + FURI_LOG_I(TAG, "Sending: %s", path); FlipperFormat* fff_data = flipper_format_string_alloc(); @@ -725,7 +732,7 @@ static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, string_t s for(int x = 0; x < app->repeat; ++x) { FlipperFormat* fff_file = flipper_format_file_alloc(storage); - bool res = unirfremix_send_sub(app, fff_file, fff_data, string_get_cstr(signal)); + bool res = unirfremix_send_sub(app, fff_file, fff_data, path); if(!res) { // errored flipper_format_free(fff_file); @@ -748,7 +755,7 @@ static void unirfremix_process_signal(UniRFRemix* app, string_t signal) { if(strlen(string_get_cstr(signal)) > 12) { Storage* storage = furi_record_open(RECORD_STORAGE); - unirfremix_send_signal(app, storage, signal); + unirfremix_send_signal(app, storage, string_get_cstr(signal)); furi_record_close(RECORD_STORAGE); } else if(strlen(string_get_cstr(signal)) < 10) { unirfremix_end_send(app); From 73c28437d6530bc90862ad60192b947e36360371 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Tue, 23 Aug 2022 09:13:41 +0200 Subject: [PATCH 06/11] fix[unirf]: display decoded after sending --- applications/unirfremix/unirfremix_app.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index b3c010f92..83aeaa2e8 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -690,9 +690,14 @@ static bool unirfremix_send_sub( flipper_format_file_close(fff_file); - subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); - subghz_protocol_decoder_base_get_string(preset->decoder, temp_str); - FURI_LOG_I(TAG, "Decoded: %s", string_get_cstr(temp_str)); + { + string_t decode_str; + string_init(decode_str); + subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); + subghz_protocol_decoder_base_get_string(preset->decoder, decode_str); + FURI_LOG_I(TAG, "Decoded: %s", string_get_cstr(decode_str)); + string_clear(decode_str); + } FURI_LOG_I(TAG, "Checking if protocol is dynamic"); const SubGhzProtocol* registry_protocol = From 545dabadb7cceaedd58d11c35ce32df7bece1a39 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Tue, 23 Aug 2022 14:48:08 +0200 Subject: [PATCH 07/11] refactor[unirf]: moved environment to struct --- applications/unirfremix/unirfremix_app.c | 73 +++++++++++++++--------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index 83aeaa2e8..07cd65d83 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #define UNIRFMAP_FOLDER "/ext/unirf" #define UNIRFMAP_EXTENSION ".txt" @@ -30,6 +32,7 @@ typedef struct { Gui* gui; SubGhzSetting* setting; + SubGhzEnvironment* environment; string_t up_file; string_t down_file; @@ -69,7 +72,6 @@ typedef struct { int file_blank; string_t signal; - } UniRFRemix; typedef struct { @@ -88,6 +90,11 @@ UniRFPreset* unirf_preset_alloc(void) { return preset; } +void unirf_preset_free(UniRFPreset* preset) { + string_clear(preset->name); + free(preset); +} + static char* char_to_str(char* str, int i) { char* converted = malloc(sizeof(char) * i + 1); memcpy(converted, str, i); @@ -601,17 +608,8 @@ static bool unirfremix_send_sub( return false; } - SubGhzEnvironment* environment = subghz_environment_alloc(); - subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); - subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); - subghz_environment_set_came_atomo_rainbow_table_file_name( - environment, EXT_PATH("subghz/assets/came_atomo")); - subghz_environment_set_nice_flor_s_rainbow_table_file_name( - environment, EXT_PATH("subghz/assets/nice_flor_s")); - - SubGhzReceiver* subghz_receiver = subghz_receiver_alloc_init(environment); - - UniRFPreset* preset = unirf_preset_alloc(); + SubGhzReceiver* subghz_receiver = subghz_receiver_alloc_init(app->environment); // no + UniRFPreset* preset = unirf_preset_alloc(); // no if(!unirf_key_load(preset, fff_file, fff_data, app->setting, subghz_receiver, path)) { FURI_LOG_E(TAG, "Could not load key"); return false; @@ -636,6 +634,9 @@ static bool unirfremix_send_sub( string_t temp_str; string_init(temp_str); + string_t temp_protocol_str; + string_init(temp_protocol_str); + bool res = false; do { if(!flipper_format_rewind(fff_file)) { @@ -643,7 +644,7 @@ static bool unirfremix_send_sub( break; } - if(!flipper_format_read_string(fff_file, "Protocol", temp_str)) { + if(!flipper_format_read_string(fff_file, "Protocol", temp_protocol_str)) { FURI_LOG_E(TAG, "Could not read Protocol"); break; } @@ -655,8 +656,8 @@ static bool unirfremix_send_sub( } SubGhzTransmitter* transmitter = - subghz_transmitter_alloc_init(environment, string_get_cstr(temp_str)); - FURI_LOG_I(TAG, "Got transmitter for %s", string_get_cstr(temp_str)); + subghz_transmitter_alloc_init(app->environment, string_get_cstr(temp_protocol_str)); + FURI_LOG_I(TAG, "Got transmitter for %s", string_get_cstr(temp_protocol_str)); if(transmitter) { subghz_transmitter_deserialize(transmitter, fff_data); @@ -686,22 +687,17 @@ static bool unirfremix_send_sub( furi_hal_subghz_stop_async_tx(); subghz_transmitter_stop(transmitter); - subghz_transmitter_free(transmitter); flipper_format_file_close(fff_file); - { - string_t decode_str; - string_init(decode_str); - subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); - subghz_protocol_decoder_base_get_string(preset->decoder, decode_str); - FURI_LOG_I(TAG, "Decoded: %s", string_get_cstr(decode_str)); - string_clear(decode_str); - } + subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); + subghz_protocol_decoder_base_get_string(preset->decoder, temp_str); + FURI_LOG_I(TAG, "Decoded: %s", string_get_cstr(temp_str)); FURI_LOG_I(TAG, "Checking if protocol is dynamic"); const SubGhzProtocol* registry_protocol = - subghz_protocol_registry_get_by_name(string_get_cstr(temp_str)); + subghz_protocol_registry_get_by_name(string_get_cstr(temp_protocol_str)); + FURI_LOG_I(TAG, "Protocol-TYPE %d", registry_protocol->type); if(registry_protocol && registry_protocol->type == SubGhzProtocolTypeDynamic) { FURI_LOG_I(TAG, " Protocol is dynamic. Updating Repeat"); unirf_save_protocol_to_file(fff_data, path); @@ -710,6 +706,8 @@ static bool unirfremix_send_sub( FURI_LOG_E(TAG, "Sending not allowed"); } + subghz_transmitter_free(transmitter); + FURI_LOG_I(TAG, "Cleaning up."); furi_hal_subghz_idle(); furi_hal_subghz_sleep(); @@ -719,10 +717,18 @@ static bool unirfremix_send_sub( res = true; } while(0); + unirf_preset_free(preset); + string_clear(temp_str); + string_clear(temp_protocol_str); + unirfremix_end_send(app); - subghz_environment_free(environment); + keeloq_reset_mfname(); + keeloq_reset_kl_type(); + star_line_reset_mfname(); + star_line_reset_kl_type(); + return res; } @@ -881,9 +887,20 @@ UniRFRemix* unirfremix_alloc() { app->gui = furi_record_open(RECORD_GUI); gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen); + // load subghz presets app->setting = subghz_setting_alloc(); subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user")); + // load mfcodes + app->environment = subghz_environment_alloc(); + subghz_environment_load_keystore(app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); + subghz_environment_load_keystore( + app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); + subghz_environment_set_came_atomo_rainbow_table_file_name( + app->environment, EXT_PATH("subghz/assets/came_atomo")); + subghz_environment_set_nice_flor_s_rainbow_table_file_name( + app->environment, EXT_PATH("subghz/assets/nice_flor_s")); + return app; } @@ -902,6 +919,7 @@ void unirfremix_free(UniRFRemix* app) { string_clear(app->ok_l); string_clear(app->file_path); + string_clear(app->signal); gui_remove_view_port(app->gui, app->view_port); furi_record_close(RECORD_GUI); @@ -911,6 +929,9 @@ void unirfremix_free(UniRFRemix* app) { furi_mutex_free(app->model_mutex); + subghz_setting_free(app->setting); + subghz_environment_free(app->environment); + free(app); } From 803422c18ee90cd974185e649162ea5853424942 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Tue, 23 Aug 2022 20:47:54 +0200 Subject: [PATCH 08/11] fix[unirf]: fixed dynamic protocol, refactoring --- applications/unirfremix/unirfremix_app.c | 336 ++++++++++------------- 1 file changed, 150 insertions(+), 186 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index 07cd65d83..08c0ee145 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -33,6 +33,7 @@ typedef struct { SubGhzSetting* setting; SubGhzEnvironment* environment; + SubGhzReceiver* subghz_receiver; string_t up_file; string_t down_file; @@ -78,20 +79,26 @@ typedef struct { uint32_t frequency; string_t name; + string_t protocol; + uint32_t repeat; + uint8_t* data; size_t data_size; SubGhzProtocolDecoderBase* decoder; } UniRFPreset; -UniRFPreset* unirf_preset_alloc(void) { +UniRFPreset* unirfremix_preset_alloc(void) { UniRFPreset* preset = malloc(sizeof(UniRFPreset)); string_init(preset->name); + string_init(preset->protocol); + preset->repeat = 200; return preset; } -void unirf_preset_free(UniRFPreset* preset) { +void unirfremix_preset_free(UniRFPreset* preset) { string_clear(preset->name); + string_clear(preset->protocol); free(preset); } @@ -143,13 +150,13 @@ static char* extract_filename(const char* name, int len) { } /* -*check that map file exists -*assign variables to values within map file -*set missing filenames to N/A -*set filename as label if label definitions are missing -*set error flag if all buttons are N/A -*set error flag if missing map file -*/ + * check that map file exists + * assign variables to values within map file + * set missing filenames to N/A + * set filename as label if label definitions are missing + * set error flag if all buttons are N/A + * set error flag if missing map file + */ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { Storage* storage = furi_record_open(RECORD_STORAGE); @@ -168,90 +175,68 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //check that map file exists if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { - FURI_LOG_I(TAG, "Could not open MAP file %s", string_get_cstr(file_name)); + FURI_LOG_E(TAG, "Could not open MAP file %s", string_get_cstr(file_name)); } else { //Filename Assignment/Check Start //assign variables to values within map file //set missing filenames to N/A if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) { - FURI_LOG_I(TAG, "Could not read UP string"); - + FURI_LOG_W(TAG, "Could not read UP string"); //increment file_blank for processing later app->file_blank++; - //set label to "N/A" app->up_label = "N/A"; - //disable the ability to process the signal on button press app->up_enabled = 0; - - FURI_LOG_I(TAG, "Up_Enabled: %d", app->up_enabled); } else { //check name length for proper screen fit //then set filename as label. Might be replaced with defined label later on below. app->up_label = extract_filename(string_get_cstr(app->up_file), label_len); - FURI_LOG_I(TAG, "UP file: %s", string_get_cstr(app->up_file)); } //Repeat process for Down if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) { - FURI_LOG_I(TAG, "Could not read DOWN string"); - + FURI_LOG_W(TAG, "Could not read DOWN string"); app->file_blank++; app->down_label = "N/A"; app->down_enabled = 0; - - FURI_LOG_I(TAG, "Down_Enabled: %d", app->down_enabled); } else { app->down_label = extract_filename(string_get_cstr(app->down_file), label_len); - FURI_LOG_I(TAG, "DOWN file: %s", string_get_cstr(app->down_file)); } //Repeat process for Left if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) { - FURI_LOG_I(TAG, "Could not read LEFT string"); - + FURI_LOG_W(TAG, "Could not read LEFT string"); app->file_blank++; app->left_label = "N/A"; app->left_enabled = 0; - - FURI_LOG_I(TAG, "Left_Enabled: %d", app->left_enabled); } else { app->left_label = extract_filename(string_get_cstr(app->left_file), label_len); - FURI_LOG_I(TAG, "LEFT file: %s", string_get_cstr(app->left_file)); } //Repeat process for Right if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) { - FURI_LOG_I(TAG, "Could not read RIGHT string"); - + FURI_LOG_W(TAG, "Could not read RIGHT string"); app->file_blank++; app->right_label = "N/A"; app->right_enabled = 0; - - FURI_LOG_I(TAG, "Right_Enabled: %d", app->right_enabled); } else { app->right_label = extract_filename(string_get_cstr(app->right_file), label_len); - FURI_LOG_I(TAG, "RIGHT file: %s", string_get_cstr(app->right_file)); } //Repeat process for Ok if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) { - FURI_LOG_I(TAG, "Could not read OK string"); - + FURI_LOG_W(TAG, "Could not read OK string"); app->file_blank++; app->ok_label = "N/A"; app->ok_enabled = 0; - - FURI_LOG_I(TAG, "Ok_Enabled: %d", app->ok_enabled); } else { app->ok_label = extract_filename(string_get_cstr(app->ok_file), label_len); - FURI_LOG_I(TAG, "OK file: %s", string_get_cstr(app->ok_file)); } @@ -262,8 +247,7 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //assign variables to values within map file if(!flipper_format_read_string(fff_data_file, "ULABEL", app->up_l)) { - FURI_LOG_I(TAG, "Could not read ULABEL string"); - + FURI_LOG_W(TAG, "Could not read ULABEL string"); //if Up button is disabled, set the label to "N/A"; if(app->up_enabled == 0) { app->up_label = "N/A"; @@ -276,13 +260,11 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //set label from map to variable and shrink to fit screen app->up_label = char_to_str((char*)string_get_cstr(app->up_l), label_len); } - FURI_LOG_I(TAG, "UP label: %s", app->up_label); } if(!flipper_format_read_string(fff_data_file, "DLABEL", app->down_l)) { - FURI_LOG_I(TAG, "Could not read DLABEL string"); - + FURI_LOG_W(TAG, "Could not read DLABEL string"); if(app->down_enabled == 0) { app->down_label = "N/A"; } @@ -292,13 +274,11 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } else { app->down_label = char_to_str((char*)string_get_cstr(app->down_l), label_len); } - FURI_LOG_I(TAG, "DOWN label: %s", app->down_label); } if(!flipper_format_read_string(fff_data_file, "LLABEL", app->left_l)) { - FURI_LOG_I(TAG, "Could not read LLABEL string"); - + FURI_LOG_W(TAG, "Could not read LLABEL string"); if(app->left_enabled == 0) { app->left_label = "N/A"; } @@ -308,13 +288,11 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } else { app->left_label = char_to_str((char*)string_get_cstr(app->left_l), label_len); } - FURI_LOG_I(TAG, "LEFT label: %s", app->left_label); } if(!flipper_format_read_string(fff_data_file, "RLABEL", app->right_l)) { - FURI_LOG_I(TAG, "Could not read RLABEL string"); - + FURI_LOG_W(TAG, "Could not read RLABEL string"); if(app->right_enabled == 0) { app->right_label = "N/A"; } @@ -324,13 +302,11 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } else { app->right_label = char_to_str((char*)string_get_cstr(app->right_l), label_len); } - FURI_LOG_I(TAG, "RIGHT label: %s", app->right_label); } if(!flipper_format_read_string(fff_data_file, "OKLABEL", app->ok_l)) { - FURI_LOG_I(TAG, "Could not read OKLABEL string"); - + FURI_LOG_W(TAG, "Could not read OKLABEL string"); if(app->ok_enabled == 0) { app->ok_label = "N/A"; } @@ -340,14 +316,15 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } else { app->ok_label = char_to_str((char*)string_get_cstr(app->ok_l), label_len); } - FURI_LOG_I(TAG, "OK label: %s", app->ok_label); } app->file_result = 2; } + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); + furi_record_close(RECORD_STORAGE); //File Existence Check @@ -357,7 +334,7 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //determine whether or not to continue to launch app with missing variables //if 5 files are missing, throw error - FURI_LOG_I(TAG, "app->file_blank: %d", app->file_blank); + FURI_LOG_D(TAG, "app->file_blank: %d", app->file_blank); if(app->file_blank == 5) { //trigger invalid file error screen @@ -374,7 +351,7 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { - FURI_LOG_I(TAG, "Could not open UP file %s", string_get_cstr(file_name)); + FURI_LOG_W(TAG, "Could not open UP file %s", string_get_cstr(file_name)); //disable button, and set label to "N/A" app->up_enabled = 0; @@ -383,6 +360,7 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { } //close the file + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); } @@ -393,13 +371,14 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { - FURI_LOG_I(TAG, "Could not open DOWN file %s", string_get_cstr(file_name)); + FURI_LOG_W(TAG, "Could not open DOWN file %s", string_get_cstr(file_name)); app->down_enabled = 0; app->down_label = "N/A"; app->file_blank++; } + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); } @@ -410,13 +389,14 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { - FURI_LOG_I(TAG, "Could not open LEFT file %s", string_get_cstr(file_name)); + FURI_LOG_W(TAG, "Could not open LEFT file %s", string_get_cstr(file_name)); app->left_enabled = 0; app->left_label = "N/A"; app->file_blank++; } + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); } @@ -427,13 +407,14 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { - FURI_LOG_I(TAG, "Could not open RIGHT file %s", string_get_cstr(file_name)); + FURI_LOG_W(TAG, "Could not open RIGHT file %s", string_get_cstr(file_name)); app->right_enabled = 0; app->right_label = "N/A"; app->file_blank++; } + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); } @@ -444,13 +425,14 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { - FURI_LOG_I(TAG, "Could not open OK file %s", string_get_cstr(file_name)); + FURI_LOG_W(TAG, "Could not open OK file %s", string_get_cstr(file_name)); app->ok_enabled = 0; app->ok_label = "N/A"; app->file_blank++; } + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); } @@ -467,7 +449,7 @@ static void unirfremix_end_send(UniRFRemix* app) { app->processing = 0; } -bool unirf_set_preset(UniRFPreset* p, const char* preset) { +bool unirfremix_set_preset(UniRFPreset* p, const char* preset) { if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { string_set(p->name, "AM270"); } else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) { @@ -485,7 +467,7 @@ bool unirf_set_preset(UniRFPreset* p, const char* preset) { return true; } -bool unirf_key_load( +bool unirfremix_key_load( UniRFPreset* preset, FlipperFormat* fff_file, FlipperFormat* fff_data, @@ -505,19 +487,17 @@ bool unirf_key_load( do { // load frequency from file - uint32_t frequency = 0; - if(!flipper_format_read_uint32(fff_file, "Frequency", &frequency, 1)) { + if(!flipper_format_read_uint32(fff_file, "Frequency", &preset->frequency, 1)) { FURI_LOG_W(TAG, "Cannot read frequency. Defaulting to 433.92 MHz"); - frequency = 433920000; + preset->frequency = 433920000; } - preset->frequency = frequency; // load preset from file if(!flipper_format_read_string(fff_file, "Preset", temp_str)) { FURI_LOG_W(TAG, "Could not read Preset. Defaulting to Ook650Async"); string_set(temp_str, "FuriHalSubGhzPresetOok650Async"); } - if(!unirf_set_preset(preset, string_get_cstr(temp_str))) { + if(!unirfremix_set_preset(preset, string_get_cstr(temp_str))) { FURI_LOG_E(TAG, "Could not set preset"); break; } @@ -530,19 +510,25 @@ bool unirf_key_load( preset->data_size = subghz_setting_get_preset_data_size(setting, preset_index); // load protocol from file - if(!flipper_format_read_string(fff_file, "Protocol", temp_str)) { - FURI_LOG_W(TAG, "Could not read Protocol."); + if(!flipper_format_read_string(fff_file, "Protocol", preset->protocol)) { + FURI_LOG_E(TAG, "Could not read Protocol."); break; } - if(!string_cmp_str(temp_str, "RAW")) { + if(!string_cmp_str(preset->protocol, "RAW")) { subghz_protocol_raw_gen_fff_data(fff_data, path); } else { stream_copy_full( flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data)); } - preset->decoder = - subghz_receiver_search_decoder_base_by_name(receiver, string_get_cstr(temp_str)); + // repeat + if(!flipper_format_insert_or_update_uint32(fff_file, "Repeat", &preset->repeat, 1)) { + FURI_LOG_E(TAG, "Unable to insert or update Repeat"); + break; + } + + preset->decoder = subghz_receiver_search_decoder_base_by_name( + receiver, string_get_cstr(preset->protocol)); if(preset->decoder) { if(!subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data)) { break; @@ -560,7 +546,8 @@ bool unirf_key_load( } // method modified from subghz_i.c -bool unirf_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_file_name) { +// https://github.com/flipperdevices/flipperzero-firmware/blob/b0daa601ad5b87427a45f9089c8b403a01f72c2a/applications/subghz/subghz_i.c#L417-L456 +bool unirfremix_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_file_name) { furi_assert(fff_file); furi_assert(dev_file_name); @@ -590,7 +577,7 @@ bool unirf_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_file_n stream_save_to_file(flipper_format_stream, storage, dev_file_name, FSOM_CREATE_ALWAYS); saved = true; - FURI_LOG_I(TAG, "(save) OK Save"); + FURI_LOG_D(TAG, "(save) OK Save"); } while(0); string_clear(file_dir); furi_record_close(RECORD_STORAGE); @@ -603,132 +590,112 @@ static bool unirfremix_send_sub( FlipperFormat* fff_data, const char* path) { // - if(!flipper_format_file_open_existing(fff_file, path)) { - FURI_LOG_E(TAG, "Could not open file %s", path); - return false; - } - - SubGhzReceiver* subghz_receiver = subghz_receiver_alloc_init(app->environment); // no - UniRFPreset* preset = unirf_preset_alloc(); // no - if(!unirf_key_load(preset, fff_file, fff_data, app->setting, subghz_receiver, path)) { - FURI_LOG_E(TAG, "Could not load key"); - return false; - } - FURI_LOG_I(TAG, "Loaded preset."); - - // TODO: reimplement this later: - /* - if(!furi_hal_subghz_is_tx_allowed(frequency)) { - printf( - "In your settings, only reception on this frequency (%lu) is allowed,\r\n" - "the actual operation of the unirf app is not possible\r\n ", - frequency); - app->tx_not_allowed = true; - unirfremix_end_send(app); - return false; - } else { - app->tx_not_allowed = false; - } - */ - - string_t temp_str; - string_init(temp_str); - - string_t temp_protocol_str; - string_init(temp_protocol_str); + UniRFPreset* preset = unirfremix_preset_alloc(); bool res = false; do { - if(!flipper_format_rewind(fff_file)) { - FURI_LOG_E(TAG, "Rewind error"); + // load settings/stream from .sub file + bool open_ok = false; + do { + if(!flipper_format_file_open_existing(fff_file, path)) { + FURI_LOG_E(TAG, "Could not open file %s", path); + break; + } + if(!unirfremix_key_load( + preset, fff_file, fff_data, app->setting, app->subghz_receiver, path)) { + FURI_LOG_E(TAG, "Could not load key"); + break; + } + open_ok = true; + } while(0); + flipper_format_free(fff_file); + if(!open_ok) { break; } - if(!flipper_format_read_string(fff_file, "Protocol", temp_protocol_str)) { - FURI_LOG_E(TAG, "Could not read Protocol"); - break; - } - - uint32_t repeat = 200; - if(!flipper_format_insert_or_update_uint32(fff_file, "Repeat", &repeat, 1)) { - FURI_LOG_E(TAG, "Unable to insert or update Repeat"); + if(!furi_hal_subghz_is_tx_allowed(preset->frequency)) { + printf( + "In your settings, only reception on this frequency (%lu) is allowed,\r\n" + "the actual operation of the unirf app is not possible\r\n ", + preset->frequency); + app->tx_not_allowed = true; + unirfremix_end_send(app); break; + } else { + app->tx_not_allowed = false; } SubGhzTransmitter* transmitter = - subghz_transmitter_alloc_init(app->environment, string_get_cstr(temp_protocol_str)); - FURI_LOG_I(TAG, "Got transmitter for %s", string_get_cstr(temp_protocol_str)); + subghz_transmitter_alloc_init(app->environment, string_get_cstr(preset->protocol)); + if(!transmitter) { + break; + } - if(transmitter) { - subghz_transmitter_deserialize(transmitter, fff_data); + subghz_transmitter_deserialize(transmitter, fff_data); - furi_hal_subghz_reset(); - furi_hal_subghz_idle(); - furi_hal_subghz_load_custom_preset(preset->data); - furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow); + furi_hal_subghz_reset(); + furi_hal_subghz_idle(); + furi_hal_subghz_load_custom_preset(preset->data); + furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow); - furi_hal_subghz_idle(); - furi_hal_subghz_set_frequency_and_path(preset->frequency); - furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); - furi_hal_gpio_write(&gpio_cc1101_g0, true); + furi_hal_subghz_idle(); + furi_hal_subghz_set_frequency_and_path(preset->frequency); + furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); + furi_hal_gpio_write(&gpio_cc1101_g0, true); - furi_hal_power_suppress_charge_enter(); + furi_hal_power_suppress_charge_enter(); - if(furi_hal_subghz_tx()) { - furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); + if(!furi_hal_subghz_tx()) { + FURI_LOG_E(TAG, "Sending not allowed"); + } - FURI_LOG_I(TAG, "Sending..."); - while(!furi_hal_subghz_is_async_tx_complete()) { - // fflush(stdout); - furi_delay_ms(33); - } - FURI_LOG_I(TAG, " Done!"); + FURI_LOG_I(TAG, "Sending..."); - furi_hal_subghz_stop_async_tx(); + furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); + while(!furi_hal_subghz_is_async_tx_complete()) { + furi_delay_ms(33); + } + furi_hal_subghz_stop_async_tx(); - subghz_transmitter_stop(transmitter); + FURI_LOG_I(TAG, " Done!"); - flipper_format_file_close(fff_file); + subghz_transmitter_stop(transmitter); - subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); - subghz_protocol_decoder_base_get_string(preset->decoder, temp_str); - FURI_LOG_I(TAG, "Decoded: %s", string_get_cstr(temp_str)); - - FURI_LOG_I(TAG, "Checking if protocol is dynamic"); - const SubGhzProtocol* registry_protocol = - subghz_protocol_registry_get_by_name(string_get_cstr(temp_protocol_str)); - FURI_LOG_I(TAG, "Protocol-TYPE %d", registry_protocol->type); - if(registry_protocol && registry_protocol->type == SubGhzProtocolTypeDynamic) { - FURI_LOG_I(TAG, " Protocol is dynamic. Updating Repeat"); - unirf_save_protocol_to_file(fff_data, path); - } - } else { - FURI_LOG_E(TAG, "Sending not allowed"); - } - - subghz_transmitter_free(transmitter); - - FURI_LOG_I(TAG, "Cleaning up."); - furi_hal_subghz_idle(); - furi_hal_subghz_sleep(); - furi_hal_power_suppress_charge_exit(); + // display decoded data + { + string_t temp_str; + string_init(temp_str); + subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); + subghz_protocol_decoder_base_get_string(preset->decoder, temp_str); + FURI_LOG_D(TAG, "Decoded: %s", string_get_cstr(temp_str)); + string_clear(temp_str); } res = true; + + FURI_LOG_D(TAG, "Checking if protocol is dynamic"); + const SubGhzProtocol* registry = + subghz_protocol_registry_get_by_name(string_get_cstr(preset->protocol)); + FURI_LOG_D(TAG, "Protocol-TYPE %d", registry->type); + if(registry && registry->type == SubGhzProtocolTypeDynamic) { + FURI_LOG_D(TAG, " Protocol is dynamic. Updating Repeat"); + unirfremix_save_protocol_to_file(fff_data, path); + + keeloq_reset_mfname(); + keeloq_reset_kl_type(); + star_line_reset_mfname(); + star_line_reset_kl_type(); + } + + subghz_transmitter_free(transmitter); + + furi_hal_subghz_idle(); + furi_hal_subghz_sleep(); + furi_hal_power_suppress_charge_exit(); } while(0); - unirf_preset_free(preset); - - string_clear(temp_str); - string_clear(temp_protocol_str); - + unirfremix_preset_free(preset); unirfremix_end_send(app); - - keeloq_reset_mfname(); - keeloq_reset_kl_type(); - star_line_reset_mfname(); - star_line_reset_kl_type(); - return res; } @@ -743,17 +710,11 @@ static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char for(int x = 0; x < app->repeat; ++x) { FlipperFormat* fff_file = flipper_format_file_alloc(storage); - bool res = unirfremix_send_sub(app, fff_file, fff_data, path); - - if(!res) { // errored - flipper_format_free(fff_file); - break; - } + unirfremix_send_sub(app, fff_file, fff_data, path); } - string_clear(preset); string_clear(protocol); - + string_clear(preset); flipper_format_free(fff_data); unirfremix_end_send(app); @@ -872,7 +833,7 @@ static void input_callback(InputEvent* input_event, void* ctx) { furi_message_queue_put(app->input_queue, input_event, 0); } -UniRFRemix* unirfremix_alloc() { +UniRFRemix* unirfremix_alloc(void) { UniRFRemix* app = malloc(sizeof(UniRFRemix)); app->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal); @@ -901,6 +862,8 @@ UniRFRemix* unirfremix_alloc() { subghz_environment_set_nice_flor_s_rainbow_table_file_name( app->environment, EXT_PATH("subghz/assets/nice_flor_s")); + app->subghz_receiver = subghz_receiver_alloc_init(app->environment); + return app; } @@ -930,6 +893,7 @@ void unirfremix_free(UniRFRemix* app) { furi_mutex_free(app->model_mutex); subghz_setting_free(app->setting); + subghz_receiver_free(app->subghz_receiver); subghz_environment_free(app->environment); free(app); @@ -980,7 +944,7 @@ int32_t unirfremix_app(void* p) { bool exit_loop = false; if(app->file_result == 2) { - FURI_LOG_I( + FURI_LOG_D( TAG, "U: %s - D: %s - L: %s - R: %s - O: %s ", string_get_cstr(app->up_file), @@ -1005,7 +969,7 @@ int32_t unirfremix_app(void* p) { while(1) { furi_check( furi_message_queue_get(app->input_queue, &input, FuriWaitForever) == FuriStatusOk); - FURI_LOG_I( + FURI_LOG_D( TAG, "key: %s type: %s", input_get_key_name(input.key), @@ -1093,12 +1057,12 @@ int32_t unirfremix_app(void* p) { } if(app->processing == 0) { - FURI_LOG_I(TAG, "processing 0"); + FURI_LOG_D(TAG, "processing 0"); app->send_status = "Idle"; app->send_status_c = 0; app->button = 0; } else if(app->processing == 1) { - FURI_LOG_I(TAG, "processing 1"); + FURI_LOG_D(TAG, "processing 1"); app->send_status = "Send"; @@ -1141,7 +1105,7 @@ int32_t unirfremix_app(void* p) { while(1) { furi_check( furi_message_queue_get(app->input_queue, &input, FuriWaitForever) == FuriStatusOk); - FURI_LOG_I( + FURI_LOG_D( TAG, "key: %s type: %s", input_get_key_name(input.key), From 432782344aa7fac787837988e76b134074968bdb Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:28:27 +0200 Subject: [PATCH 09/11] feat[unirf]: blinking on send * fixed a HardFault when trying to `subghz_protocol_decoder_base_get_string` * don't enter `power_suppress_charge` for each sending individually --- applications/unirfremix/unirfremix_app.c | 33 +++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index 08c0ee145..81c5fd380 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -4,6 +4,8 @@ #include #include #include + +#include #include #include @@ -34,6 +36,7 @@ typedef struct { SubGhzSetting* setting; SubGhzEnvironment* environment; SubGhzReceiver* subghz_receiver; + NotificationApp* notification; string_t up_file; string_t down_file; @@ -477,7 +480,7 @@ bool unirfremix_key_load( // if(!flipper_format_rewind(fff_file)) { FURI_LOG_E(TAG, "Rewind error"); - return NULL; + return false; } string_t temp_str; @@ -572,7 +575,7 @@ bool unirfremix_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_f FURI_LOG_E(TAG, "(save) Cannot remove"); break; } - //ToDo check Write + stream_seek(flipper_format_stream, 0, StreamOffsetFromStart); stream_save_to_file(flipper_format_stream, storage, dev_file_name, FSOM_CREATE_ALWAYS); @@ -643,13 +646,13 @@ static bool unirfremix_send_sub( furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); furi_hal_gpio_write(&gpio_cc1101_g0, true); - furi_hal_power_suppress_charge_enter(); - if(!furi_hal_subghz_tx()) { FURI_LOG_E(TAG, "Sending not allowed"); + break; } FURI_LOG_I(TAG, "Sending..."); + notification_message(app->notification, &sequence_blink_start_green); furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); while(!furi_hal_subghz_is_async_tx_complete()) { @@ -658,27 +661,20 @@ static bool unirfremix_send_sub( furi_hal_subghz_stop_async_tx(); FURI_LOG_I(TAG, " Done!"); + notification_message(app->notification, &sequence_blink_stop); subghz_transmitter_stop(transmitter); - // display decoded data - { - string_t temp_str; - string_init(temp_str); - subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data); - subghz_protocol_decoder_base_get_string(preset->decoder, temp_str); - FURI_LOG_D(TAG, "Decoded: %s", string_get_cstr(temp_str)); - string_clear(temp_str); - } - res = true; FURI_LOG_D(TAG, "Checking if protocol is dynamic"); const SubGhzProtocol* registry = subghz_protocol_registry_get_by_name(string_get_cstr(preset->protocol)); FURI_LOG_D(TAG, "Protocol-TYPE %d", registry->type); + FURI_LOG_I(TAG, "3"); if(registry && registry->type == SubGhzProtocolTypeDynamic) { FURI_LOG_D(TAG, " Protocol is dynamic. Updating Repeat"); + FURI_LOG_I(TAG, "4"); unirfremix_save_protocol_to_file(fff_data, path); keeloq_reset_mfname(); @@ -691,7 +687,6 @@ static bool unirfremix_send_sub( furi_hal_subghz_idle(); furi_hal_subghz_sleep(); - furi_hal_power_suppress_charge_exit(); } while(0); unirfremix_preset_free(preset); @@ -864,6 +859,8 @@ UniRFRemix* unirfremix_alloc(void) { app->subghz_receiver = subghz_receiver_alloc_init(app->environment); + app->notification = furi_record_open(RECORD_NOTIFICATION); + return app; } @@ -896,6 +893,8 @@ void unirfremix_free(UniRFRemix* app) { subghz_receiver_free(app->subghz_receiver); subghz_environment_free(app->environment); + furi_record_close(RECORD_NOTIFICATION); + free(app); } @@ -964,6 +963,8 @@ int32_t unirfremix_app(void* p) { furi_mutex_release(app->model_mutex); view_port_update(app->view_port); + furi_hal_power_suppress_charge_enter(); + //input detect loop start InputEvent input; while(1) { @@ -1144,5 +1145,7 @@ int32_t unirfremix_app(void* p) { // remove & free all stuff created by app unirfremix_free(app); + furi_hal_power_suppress_charge_exit(); + return 0; } \ No newline at end of file From 9ec0835012282423c6b2aea03cfad15336575cc0 Mon Sep 17 00:00:00 2001 From: Daniel <71837281+darmiel@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:36:50 +0200 Subject: [PATCH 10/11] fix[unirf]: removed leftover debug messages --- applications/unirfremix/unirfremix_app.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index 81c5fd380..459049b0c 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -671,10 +671,8 @@ static bool unirfremix_send_sub( const SubGhzProtocol* registry = subghz_protocol_registry_get_by_name(string_get_cstr(preset->protocol)); FURI_LOG_D(TAG, "Protocol-TYPE %d", registry->type); - FURI_LOG_I(TAG, "3"); if(registry && registry->type == SubGhzProtocolTypeDynamic) { FURI_LOG_D(TAG, " Protocol is dynamic. Updating Repeat"); - FURI_LOG_I(TAG, "4"); unirfremix_save_protocol_to_file(fff_data, path); keeloq_reset_mfname(); From 7abc49ea219a8cf3924858730b56913eae853286 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 24 Aug 2022 23:14:33 +0300 Subject: [PATCH 11/11] Implement TX while button is hold, other small changes Repeat functionality removed since all buttons adds event in queue to be executed after tx is finished --- applications/unirfremix/unirfremix_app.c | 299 ++++++++++++----------- 1 file changed, 156 insertions(+), 143 deletions(-) diff --git a/applications/unirfremix/unirfremix_app.c b/applications/unirfremix/unirfremix_app.c index 459049b0c..f89d19786 100644 --- a/applications/unirfremix/unirfremix_app.c +++ b/applications/unirfremix/unirfremix_app.c @@ -25,6 +25,19 @@ #define TAG "UniRF Remix" +typedef struct { + uint32_t frequency; + string_t name; + + string_t protocol; + uint32_t repeat; + + uint8_t* data; + size_t data_size; + + SubGhzProtocolDecoderBase* decoder; +} UniRFPreset; + typedef struct { FuriMutex* model_mutex; @@ -37,6 +50,7 @@ typedef struct { SubGhzEnvironment* environment; SubGhzReceiver* subghz_receiver; NotificationApp* notification; + UniRFPreset* txpreset; string_t up_file; string_t down_file; @@ -68,7 +82,11 @@ typedef struct { char* send_status; int send_status_c; int processing; - int repeat; + + SubGhzTransmitter* tx_transmitter; + FlipperFormat* tx_fff_data; + const char* tx_file_path; + //int repeat; int button; int file_result; @@ -78,19 +96,6 @@ typedef struct { string_t signal; } UniRFRemix; -typedef struct { - uint32_t frequency; - string_t name; - - string_t protocol; - uint32_t repeat; - - uint8_t* data; - size_t data_size; - - SubGhzProtocolDecoderBase* decoder; -} UniRFPreset; - UniRFPreset* unirfremix_preset_alloc(void) { UniRFPreset* preset = malloc(sizeof(UniRFPreset)); string_init(preset->name); @@ -113,7 +118,7 @@ static char* char_to_str(char* str, int i) { return converted; } - +/* static const char* int_to_char(int number) { switch(number) { case 0: @@ -140,7 +145,7 @@ static const char* int_to_char(int number) { return "0"; } } - +*/ //get filename without path static char* extract_filename(const char* name, int len) { string_t tmp; @@ -328,8 +333,6 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); - furi_record_close(RECORD_STORAGE); - //File Existence Check //Check each file definition if not already set to "N/A" @@ -350,7 +353,6 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //if button is still enabled, check that file exists if(app->up_enabled == 1) { string_set(file_name, app->up_file); - storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -365,12 +367,10 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { //close the file flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); - furi_record_close(RECORD_STORAGE); } if(app->down_enabled == 1) { string_set(file_name, app->down_file); - storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -383,12 +383,10 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); - furi_record_close(RECORD_STORAGE); } if(app->left_enabled == 1) { string_set(file_name, app->left_file); - storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -401,12 +399,10 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); - furi_record_close(RECORD_STORAGE); } if(app->right_enabled == 1) { string_set(file_name, app->right_file); - storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -419,12 +415,10 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); - furi_record_close(RECORD_STORAGE); } if(app->ok_enabled == 1) { string_set(file_name, app->ok_file); - storage = furi_record_open(RECORD_STORAGE); fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { @@ -437,9 +431,10 @@ void unirfremix_cfg_set_check(UniRFRemix* app, string_t file_name) { flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); - furi_record_close(RECORD_STORAGE); } + furi_record_close(RECORD_STORAGE); + if(app->file_blank == 5) { app->file_result = 1; } else { @@ -587,40 +582,50 @@ bool unirfremix_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_f return saved; } -static bool unirfremix_send_sub( - UniRFRemix* app, - FlipperFormat* fff_file, - FlipperFormat* fff_data, - const char* path) { - // - UniRFPreset* preset = unirfremix_preset_alloc(); +void unirfremix_tx_stop(UniRFRemix* app) { + if(!string_cmp_str(app->txpreset->protocol, "RAW")) { + while(!furi_hal_subghz_is_async_tx_complete()) { + furi_delay_ms(60); + } + } + //Stop TX + furi_hal_subghz_stop_async_tx(); + FURI_LOG_I(TAG, "TX Done!"); + subghz_transmitter_stop(app->tx_transmitter); + FURI_LOG_D(TAG, "Checking if protocol is dynamic"); + const SubGhzProtocol* registry = + subghz_protocol_registry_get_by_name(string_get_cstr(app->txpreset->protocol)); + FURI_LOG_D(TAG, "Protocol-TYPE %d", registry->type); + if(registry && registry->type == SubGhzProtocolTypeDynamic) { + FURI_LOG_D(TAG, "Protocol is dynamic. Saving key"); + unirfremix_save_protocol_to_file(app->tx_fff_data, app->tx_file_path); + + keeloq_reset_mfname(); + keeloq_reset_kl_type(); + star_line_reset_mfname(); + star_line_reset_kl_type(); + } + + subghz_transmitter_free(app->tx_transmitter); + furi_hal_subghz_idle(); + + notification_message(app->notification, &sequence_blink_stop); + + unirfremix_preset_free(app->txpreset); + flipper_format_free(app->tx_fff_data); + unirfremix_end_send(app); +} + +static bool unirfremix_send_sub(UniRFRemix* app, FlipperFormat* fff_data) { + // bool res = false; do { - // load settings/stream from .sub file - bool open_ok = false; - do { - if(!flipper_format_file_open_existing(fff_file, path)) { - FURI_LOG_E(TAG, "Could not open file %s", path); - break; - } - if(!unirfremix_key_load( - preset, fff_file, fff_data, app->setting, app->subghz_receiver, path)) { - FURI_LOG_E(TAG, "Could not load key"); - break; - } - open_ok = true; - } while(0); - flipper_format_free(fff_file); - if(!open_ok) { - break; - } - - if(!furi_hal_subghz_is_tx_allowed(preset->frequency)) { + if(!furi_hal_subghz_is_tx_allowed(app->txpreset->frequency)) { printf( "In your settings, only reception on this frequency (%lu) is allowed,\r\n" "the actual operation of the unirf app is not possible\r\n ", - preset->frequency); + app->txpreset->frequency); app->tx_not_allowed = true; unirfremix_end_send(app); break; @@ -628,21 +633,21 @@ static bool unirfremix_send_sub( app->tx_not_allowed = false; } - SubGhzTransmitter* transmitter = - subghz_transmitter_alloc_init(app->environment, string_get_cstr(preset->protocol)); - if(!transmitter) { + app->tx_transmitter = subghz_transmitter_alloc_init( + app->environment, string_get_cstr(app->txpreset->protocol)); + if(!app->tx_transmitter) { break; } - subghz_transmitter_deserialize(transmitter, fff_data); + subghz_transmitter_deserialize(app->tx_transmitter, fff_data); furi_hal_subghz_reset(); furi_hal_subghz_idle(); - furi_hal_subghz_load_custom_preset(preset->data); + furi_hal_subghz_load_custom_preset(app->txpreset->data); furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow); furi_hal_subghz_idle(); - furi_hal_subghz_set_frequency_and_path(preset->frequency); + furi_hal_subghz_set_frequency_and_path(app->txpreset->frequency); furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); furi_hal_gpio_write(&gpio_cc1101_g0, true); @@ -652,65 +657,52 @@ static bool unirfremix_send_sub( } FURI_LOG_I(TAG, "Sending..."); - notification_message(app->notification, &sequence_blink_start_green); + notification_message(app->notification, &sequence_blink_start_magenta); - furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter); - while(!furi_hal_subghz_is_async_tx_complete()) { - furi_delay_ms(33); - } - furi_hal_subghz_stop_async_tx(); - - FURI_LOG_I(TAG, " Done!"); - notification_message(app->notification, &sequence_blink_stop); - - subghz_transmitter_stop(transmitter); + furi_hal_subghz_start_async_tx(subghz_transmitter_yield, app->tx_transmitter); res = true; - - FURI_LOG_D(TAG, "Checking if protocol is dynamic"); - const SubGhzProtocol* registry = - subghz_protocol_registry_get_by_name(string_get_cstr(preset->protocol)); - FURI_LOG_D(TAG, "Protocol-TYPE %d", registry->type); - if(registry && registry->type == SubGhzProtocolTypeDynamic) { - FURI_LOG_D(TAG, " Protocol is dynamic. Updating Repeat"); - unirfremix_save_protocol_to_file(fff_data, path); - - keeloq_reset_mfname(); - keeloq_reset_kl_type(); - star_line_reset_mfname(); - star_line_reset_kl_type(); - } - - subghz_transmitter_free(transmitter); - - furi_hal_subghz_idle(); - furi_hal_subghz_sleep(); } while(0); - unirfremix_preset_free(preset); - unirfremix_end_send(app); return res; } static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char* path) { FURI_LOG_I(TAG, "Sending: %s", path); - FlipperFormat* fff_data = flipper_format_string_alloc(); + app->tx_file_path = path; - string_t preset, protocol; - string_init(preset); - string_init(protocol); + app->tx_fff_data = flipper_format_string_alloc(); - for(int x = 0; x < app->repeat; ++x) { - FlipperFormat* fff_file = flipper_format_file_alloc(storage); - unirfremix_send_sub(app, fff_file, fff_data, path); + app->txpreset = unirfremix_preset_alloc(); + + // load settings/stream from .sub file + FlipperFormat* fff_file = flipper_format_file_alloc(storage); + bool open_ok = false; + do { + if(!flipper_format_file_open_existing(fff_file, path)) { + FURI_LOG_E(TAG, "Could not open file %s", path); + break; + } + if(!unirfremix_key_load( + app->txpreset, + fff_file, + app->tx_fff_data, + app->setting, + app->subghz_receiver, + path)) { + FURI_LOG_E(TAG, "Could not load key"); + break; + } + open_ok = true; + } while(0); + flipper_format_free(fff_file); + if(!open_ok) { + FURI_LOG_E(TAG, "Could not load file!"); + return; } - string_clear(protocol); - string_clear(preset); - flipper_format_free(fff_data); - - unirfremix_end_send(app); + unirfremix_send_sub(app, app->tx_fff_data); } static void unirfremix_process_signal(UniRFRemix* app, string_t signal) { @@ -739,7 +731,7 @@ static void render_callback(Canvas* canvas, void* ctx) { canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Config is incorrect."); canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "Please configure map."); - canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Hold Back to Exit."); + canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit."); } else if(app->tx_not_allowed) { canvas_clear(canvas); canvas_set_font(canvas, FontPrimary); @@ -748,7 +740,7 @@ static void render_callback(Canvas* canvas, void* ctx) { canvas_draw_str_aligned(canvas, 62, 15, AlignCenter, AlignTop, "Frequency is outside of"); canvas_draw_str_aligned(canvas, 62, 25, AlignCenter, AlignTop, "default range."); canvas_draw_str_aligned(canvas, 62, 35, AlignCenter, AlignTop, "Check docs."); - canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Hold Back to Exit."); + canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit."); } else { //map found, draw all the things canvas_clear(canvas); @@ -779,8 +771,7 @@ static void render_callback(Canvas* canvas, void* ctx) { canvas_draw_str(canvas, 10, 40, app->right_label); canvas_draw_str(canvas, 10, 50, app->ok_label); - canvas_draw_str_aligned( - canvas, 11, 62, AlignLeft, AlignBottom, "Hold=Exit. Tap for Repeat:"); + canvas_draw_str_aligned(canvas, 11, 62, AlignLeft, AlignBottom, "Press=Exit."); //Status text and indicator canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, app->send_status); @@ -814,8 +805,7 @@ static void render_callback(Canvas* canvas, void* ctx) { //Repeat indicator //canvas_draw_str_aligned(canvas, 125, 40, AlignRight, AlignBottom, "Repeat:"); //canvas_draw_icon(canvas, 115, 39, &I_UniRFRemix_Repeat_12x14); - canvas_draw_str_aligned( - canvas, 125, 62, AlignRight, AlignBottom, int_to_char(app->repeat)); + //canvas_draw_str_aligned(canvas, 125, 62, AlignRight, AlignBottom, int_to_char(app->repeat)); } furi_mutex_release(app->model_mutex); @@ -826,6 +816,24 @@ static void input_callback(InputEvent* input_event, void* ctx) { furi_message_queue_put(app->input_queue, input_event, 0); } +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")); + + // load mfcodes + app->environment = subghz_environment_alloc(); + subghz_environment_load_keystore(app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); + subghz_environment_load_keystore( + app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); + subghz_environment_set_came_atomo_rainbow_table_file_name( + app->environment, EXT_PATH("subghz/assets/came_atomo")); + subghz_environment_set_nice_flor_s_rainbow_table_file_name( + app->environment, EXT_PATH("subghz/assets/nice_flor_s")); + + app->subghz_receiver = subghz_receiver_alloc_init(app->environment); +} + UniRFRemix* unirfremix_alloc(void) { UniRFRemix* app = malloc(sizeof(UniRFRemix)); @@ -841,22 +849,6 @@ UniRFRemix* unirfremix_alloc(void) { app->gui = furi_record_open(RECORD_GUI); gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen); - // load subghz presets - app->setting = subghz_setting_alloc(); - subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user")); - - // load mfcodes - app->environment = subghz_environment_alloc(); - subghz_environment_load_keystore(app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); - subghz_environment_load_keystore( - app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); - subghz_environment_set_came_atomo_rainbow_table_file_name( - app->environment, EXT_PATH("subghz/assets/came_atomo")); - subghz_environment_set_nice_flor_s_rainbow_table_file_name( - app->environment, EXT_PATH("subghz/assets/nice_flor_s")); - - app->subghz_receiver = subghz_receiver_alloc_init(app->environment); - app->notification = furi_record_open(RECORD_NOTIFICATION); return app; @@ -887,6 +879,7 @@ void unirfremix_free(UniRFRemix* app) { furi_mutex_free(app->model_mutex); + furi_hal_subghz_sleep(); subghz_setting_free(app->setting); subghz_receiver_free(app->subghz_receiver); subghz_environment_free(app->environment); @@ -938,6 +931,9 @@ int32_t unirfremix_app(void* p) { unirfremix_cfg_set_check(app, app->file_path); } + // init subghz stuff + unirfremix_subghz_alloc(app); + bool exit_loop = false; if(app->file_result == 2) { @@ -954,7 +950,7 @@ int32_t unirfremix_app(void* p) { app->send_status = "Idle"; app->send_status_c = 0; app->processing = 0; - app->repeat = 1; + //app->repeat = 1; app->button = 0; //refresh screen to update variables before processing main screen or error screens @@ -976,7 +972,7 @@ int32_t unirfremix_app(void* p) { switch(input.key) { case InputKeyUp: - if(input.type == InputTypeShort) { + if(input.type == InputTypePress) { if(app->up_enabled) { if(app->processing == 0) { *app->signal = *app->empty; @@ -986,10 +982,15 @@ int32_t unirfremix_app(void* p) { } } } + if(input.type == InputTypeRelease) { + if(app->up_enabled) { + unirfremix_tx_stop(app); + } + } break; case InputKeyDown: - if(input.type == InputTypeShort) { + if(input.type == InputTypePress) { if(app->down_enabled) { if(app->processing == 0) { *app->signal = *app->empty; @@ -999,10 +1000,15 @@ int32_t unirfremix_app(void* p) { } } } + if(input.type == InputTypeRelease) { + if(app->down_enabled) { + unirfremix_tx_stop(app); + } + } break; case InputKeyRight: - if(input.type == InputTypeShort) { + if(input.type == InputTypePress) { if(app->right_enabled) { if(app->processing == 0) { *app->signal = *app->empty; @@ -1012,10 +1018,15 @@ int32_t unirfremix_app(void* p) { } } } + if(input.type == InputTypeRelease) { + if(app->right_enabled) { + unirfremix_tx_stop(app); + } + } break; case InputKeyLeft: - if(input.type == InputTypeShort) { + if(input.type == InputTypePress) { if(app->left_enabled) { if(app->processing == 0) { *app->signal = *app->empty; @@ -1025,10 +1036,15 @@ int32_t unirfremix_app(void* p) { } } } + if(input.type == InputTypeRelease) { + if(app->left_enabled) { + unirfremix_tx_stop(app); + } + } break; case InputKeyOk: - if(input.type == InputTypeShort) { + if(input.type == InputTypePress) { if(app->ok_enabled) { if(app->processing == 0) { *app->signal = *app->empty; @@ -1038,18 +1054,15 @@ int32_t unirfremix_app(void* p) { } } } + if(input.type == InputTypeRelease) { + if(app->ok_enabled) { + unirfremix_tx_stop(app); + } + } break; case InputKeyBack: if(input.type == InputTypeShort) { - if(app->processing == 0) { - if(app->repeat < 5) { - app->repeat++; - } else { - app->repeat = 1; - } - } - } else if(input.type == InputTypeLong) { exit_loop = true; } break; @@ -1122,7 +1135,7 @@ int32_t unirfremix_app(void* p) { case InputKeyOk: break; case InputKeyBack: - if(input.type == InputTypeLong) { + if(input.type == InputTypeShort) { exit_loop = true; } break;