From ff24bf6829a4030764a0525dd200174c7dd92ddf Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 6 May 2023 02:00:26 +0300 Subject: [PATCH 01/36] SubGhz: add SubGhzThresholdRssi --- .../subghz/helpers/subghz_threshold_rssi.c | 60 +++++++++++++++++++ .../subghz/helpers/subghz_threshold_rssi.h | 43 +++++++++++++ .../subghz/scenes/subghz_scene_read_raw.c | 51 +++++----------- .../subghz/scenes/subghz_scene_receiver.c | 7 ++- .../scenes/subghz_scene_receiver_config.c | 6 +- applications/main/subghz/subghz.c | 11 +++- applications/main/subghz/subghz_i.h | 13 ++-- 7 files changed, 143 insertions(+), 48 deletions(-) create mode 100644 applications/main/subghz/helpers/subghz_threshold_rssi.c create mode 100644 applications/main/subghz/helpers/subghz_threshold_rssi.h diff --git a/applications/main/subghz/helpers/subghz_threshold_rssi.c b/applications/main/subghz/helpers/subghz_threshold_rssi.c new file mode 100644 index 000000000..04a06bc17 --- /dev/null +++ b/applications/main/subghz/helpers/subghz_threshold_rssi.c @@ -0,0 +1,60 @@ +#include "subghz_threshold_rssi.h" +#include +#include "../subghz_i.h" + +#define TAG "SubGhzThresholdRssi" +#define THRESHOLD_RSSI_LOW_COUNT 10 + +struct SubGhzThresholdRssi { + float threshold_rssi; + uint8_t threshold_rssi_low_count; +}; + +SubGhzThresholdRssi* subghz_threshold_rssi_alloc(void) { + SubGhzThresholdRssi* instance = malloc(sizeof(SubGhzThresholdRssi)); + instance->threshold_rssi = SUBGHZ_RAW_THRESHOLD_MIN; + instance->threshold_rssi_low_count = THRESHOLD_RSSI_LOW_COUNT; + return instance; +} + +void subghz_threshold_rssi_free(SubGhzThresholdRssi* instance) { + furi_assert(instance); + free(instance); +} + +void subghz_threshold_rssi_set(SubGhzThresholdRssi* instance, float rssi) { + furi_assert(instance); + instance->threshold_rssi = rssi; +} + +float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance) { + furi_assert(instance); + return instance->threshold_rssi; +} + +SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance) { + furi_assert(instance); + float rssi = furi_hal_subghz_get_rssi(); + SubGhzThresholdRssiData ret = {.rssi = rssi, .is_above = false}; + + if(float_is_equal(instance->threshold_rssi, SUBGHZ_RAW_THRESHOLD_MIN)) { + ret.is_above = true; + } else { + if(rssi < instance->threshold_rssi) { + instance->threshold_rssi_low_count++; + if(instance->threshold_rssi_low_count > THRESHOLD_RSSI_LOW_COUNT) { + instance->threshold_rssi_low_count = THRESHOLD_RSSI_LOW_COUNT; + } + ret.is_above = false; + } else { + instance->threshold_rssi_low_count = 0; + } + + if(instance->threshold_rssi_low_count == THRESHOLD_RSSI_LOW_COUNT) { + ret.is_above = false; + } else { + ret.is_above = true; + } + } + return ret; +} diff --git a/applications/main/subghz/helpers/subghz_threshold_rssi.h b/applications/main/subghz/helpers/subghz_threshold_rssi.h new file mode 100644 index 000000000..e28092acb --- /dev/null +++ b/applications/main/subghz/helpers/subghz_threshold_rssi.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +typedef struct { + float rssi; /**< Current RSSI */ + bool is_above; /**< Exceeded threshold level */ +} SubGhzThresholdRssiData; + +typedef struct SubGhzThresholdRssi SubGhzThresholdRssi; + +/** Allocate SubGhzThresholdRssi + * + * @return SubGhzThresholdRssi* + */ +SubGhzThresholdRssi* subghz_threshold_rssi_alloc(void); + +/** Free SubGhzThresholdRssi + * + * @param instance Pointer to a SubGhzThresholdRssi + */ +void subghz_threshold_rssi_free(SubGhzThresholdRssi* instance); + +/** Set threshold + * + * @param instance Pointer to a SubGhzThresholdRssi + * @param rssi RSSI threshold + */ +void subghz_threshold_rssi_set(SubGhzThresholdRssi* instance, float rssi); + +/** Get threshold + * + * @param instance Pointer to a SubGhzThresholdRssi + * @return float RSSI threshold + */ +float subghz_threshold_rssi_get(SubGhzThresholdRssi* instance); + +/** Check threshold + * + * @param instance Pointer to a SubGhzThresholdRssi + * @return SubGhzThresholdRssiData + */ +SubGhzThresholdRssiData subghz_threshold_get_rssi_data(SubGhzThresholdRssi* instance); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 6a881cba4..35b3fa58e 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -7,7 +7,6 @@ #define RAW_FILE_NAME "RAW_" #define TAG "SubGhzSceneReadRAW" -#define RAW_THRESHOLD_RSSI_LOW_COUNT 10 bool subghz_scene_read_raw_update_filename(SubGhz* subghz) { bool ret = false; @@ -75,7 +74,10 @@ void subghz_scene_read_raw_on_enter(void* context) { switch(subghz->txrx->rx_key_state) { case SubGhzRxKeyStateBack: subghz_read_raw_set_status( - subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, "", subghz->txrx->raw_threshold_rssi); + subghz->subghz_read_raw, + SubGhzReadRAWStatusIDLE, + "", + subghz_threshold_rssi_get(subghz->threshold_rssi)); break; case SubGhzRxKeyStateRAWLoad: path_extract_filename(subghz->file_path, file_name, true); @@ -83,7 +85,7 @@ void subghz_scene_read_raw_on_enter(void* context) { subghz->subghz_read_raw, SubGhzReadRAWStatusLoadKeyTX, furi_string_get_cstr(file_name), - subghz->txrx->raw_threshold_rssi); + subghz_threshold_rssi_get(subghz->threshold_rssi)); subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; break; case SubGhzRxKeyStateRAWSave: @@ -92,7 +94,7 @@ void subghz_scene_read_raw_on_enter(void* context) { subghz->subghz_read_raw, SubGhzReadRAWStatusSaveKey, furi_string_get_cstr(file_name), - subghz->txrx->raw_threshold_rssi); + subghz_threshold_rssi_get(subghz->threshold_rssi)); subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; break; default: @@ -100,7 +102,7 @@ void subghz_scene_read_raw_on_enter(void* context) { subghz->subghz_read_raw, SubGhzReadRAWStatusStart, "", - subghz->txrx->raw_threshold_rssi); + subghz_threshold_rssi_get(subghz->threshold_rssi)); subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; break; } @@ -238,7 +240,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, "", - subghz->txrx->raw_threshold_rssi); + subghz_threshold_rssi_get(subghz->threshold_rssi)); } else { if(scene_manager_has_previous_scene( subghz->scene_manager, SubGhzSceneSaved) || @@ -311,7 +313,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { - subghz->txrx->raw_threshold_rssi_low_count = RAW_THRESHOLD_RSSI_LOW_COUNT; if(subghz_protocol_raw_save_to_file_init( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, RAW_FILE_NAME, @@ -359,40 +360,18 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { switch(subghz->state_notifications) { case SubGhzNotificationStateRx: notification_message(subghz->notifications, &sequence_blink_cyan_10); + subghz_read_raw_update_sample_write( subghz->subghz_read_raw, subghz_protocol_raw_get_sample_write( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result)); - float rssi = furi_hal_subghz_get_rssi(); - - if(float_is_equal(subghz->txrx->raw_threshold_rssi, SUBGHZ_RAW_THRESHOLD_MIN)) { - subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, true); - subghz_protocol_raw_save_to_file_pause( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, false); - } else { - if(rssi < subghz->txrx->raw_threshold_rssi) { - subghz->txrx->raw_threshold_rssi_low_count++; - if(subghz->txrx->raw_threshold_rssi_low_count > RAW_THRESHOLD_RSSI_LOW_COUNT) { - subghz->txrx->raw_threshold_rssi_low_count = RAW_THRESHOLD_RSSI_LOW_COUNT; - } - subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, false); - } else { - subghz->txrx->raw_threshold_rssi_low_count = 0; - } - - if(subghz->txrx->raw_threshold_rssi_low_count == RAW_THRESHOLD_RSSI_LOW_COUNT) { - subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, false); - subghz_protocol_raw_save_to_file_pause( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, true); - subghz_speaker_mute(subghz); - } else { - subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, true); - subghz_protocol_raw_save_to_file_pause( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, false); - subghz_speaker_unmute(subghz); - } - } + SubGhzThresholdRssiData ret_rssi = + subghz_threshold_get_rssi_data(subghz->threshold_rssi); + subghz_read_raw_add_data_rssi( + subghz->subghz_read_raw, ret_rssi.rssi, ret_rssi.is_above); + subghz_protocol_raw_save_to_file_pause( + (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, !ret_rssi.is_above); break; case SubGhzNotificationStateTx: diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index fd8d9b70e..18008674d 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -283,10 +283,11 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { } //get RSSI - float rssi = furi_hal_subghz_get_rssi(); - subghz_receiver_rssi(subghz->subghz_receiver, rssi); + SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(subghz->threshold_rssi); + + subghz_receiver_rssi(subghz->subghz_receiver, ret_rssi.rssi); subghz_protocol_decoder_bin_raw_data_input_rssi( - (SubGhzProtocolDecoderBinRAW*)subghz->txrx->decoder_result, rssi); + (SubGhzProtocolDecoderBinRAW*)subghz->txrx->decoder_result, ret_rssi.rssi); switch(subghz->state_notifications) { case SubGhzNotificationStateRx: diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 68c5b4b7a..bd9780428 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -234,7 +234,7 @@ static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* it uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, raw_threshold_rssi_text[index]); - subghz->txrx->raw_threshold_rssi = raw_threshold_rssi_value[index]; + subghz_threshold_rssi_set(subghz->threshold_rssi, raw_threshold_rssi_value[index]); } static void subghz_scene_receiver_config_set_starline(VariableItem* item) { @@ -400,7 +400,9 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_raw_threshold_rssi, subghz); value_index = value_index_float( - subghz->txrx->raw_threshold_rssi, raw_threshold_rssi_value, RAW_THRESHOLD_RSSI_COUNT); + subghz_threshold_rssi_get(subghz->threshold_rssi), + raw_threshold_rssi_value, + RAW_THRESHOLD_RSSI_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, raw_threshold_rssi_text[value_index]); } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 47da7ae40..4bbdba6c5 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -255,6 +255,10 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { #endif subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); } + + //init threshold rssi + subghz->threshold_rssi = subghz_threshold_rssi_alloc(); + //init Worker & Protocol & History & KeyBoard subghz->lock = SubGhzLockOff; subghz->txrx = malloc(sizeof(SubGhzTxRx)); @@ -275,7 +279,6 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->history = subghz_history_alloc(); } - subghz->txrx->raw_threshold_rssi = SUBGHZ_RAW_THRESHOLD_MIN; subghz->txrx->worker = subghz_worker_alloc(); subghz->txrx->fff_data = flipper_format_string_alloc(); @@ -386,11 +389,15 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { furi_record_close(RECORD_GUI); subghz->gui = NULL; - //setting + // setting subghz_setting_free(subghz->setting); if(!alloc_for_tx_only) { subghz_last_settings_free(subghz->last_settings); } + + // threshold rssi + subghz_threshold_rssi_free(subghz->threshold_rssi); + //Worker & Protocol & History subghz_receiver_free(subghz->txrx->receiver); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index faae35fa2..9c58af7bb 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -41,6 +41,8 @@ #include "rpc/rpc_app.h" +#include "helpers/subghz_threshold_rssi.h" + #define SUBGHZ_MAX_LEN_NAME 64 #define SUBGHZ_EXT_PRESET_NAME true @@ -70,20 +72,19 @@ struct SubGhzTxRx { SubGhzRadioPreset* preset; SubGhzHistory* history; uint16_t idx_menu_chosen; + uint8_t hopper_timeout; + uint8_t hopper_idx_frequency; + SubGhzTxRxState txrx_state; SubGhzHopperState hopper_state; SubGhzSpeakerState speaker_state; bool ignore_starline; bool ignore_auto_alarms; bool ignore_magellan; - uint8_t hopper_timeout; - uint8_t hopper_idx_frequency; + SubGhzRxKeyState rx_key_state; bool debug_pin_state; - - float raw_threshold_rssi; - uint8_t raw_threshold_rssi_low_count; }; typedef struct SubGhzTxRx SubGhzTxRx; @@ -131,6 +132,8 @@ struct SubGhz { SubGhzDecodeRawState decode_raw_state; SubGhzFileEncoderWorker* decode_raw_file_worker_encoder; + SubGhzThresholdRssi* threshold_rssi; + void* rpc_ctx; }; From cb8c77ee2c3ee1bf48f33c9107ae4b6daa3808ea Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 6 May 2023 16:36:15 +0300 Subject: [PATCH 02/36] SubGhz: remove direct reading --- .../subghz/scenes/subghz_scene_read_raw.c | 101 ++++++------------ .../subghz/scenes/subghz_scene_receiver.c | 22 ++-- .../scenes/subghz_scene_receiver_info.c | 68 +++++------- .../main/subghz/scenes/subghz_scene_rpc.c | 12 +-- .../subghz/scenes/subghz_scene_transmitter.c | 36 +++---- applications/main/subghz/subghz_i.c | 25 +++++ applications/main/subghz/subghz_i.h | 8 +- 7 files changed, 116 insertions(+), 156 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 35b3fa58e..33cd2ebb6 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -127,16 +127,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case SubGhzCustomEventViewReadRAWBack: - //Stop TX - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { - subghz_tx_stop(subghz); - subghz_sleep(subghz); - } - //Stop RX - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - subghz_sleep(subghz); - }; + subghz_txrx_stop(subghz); //Stop save file subghz_protocol_raw_save_to_file_stop( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); @@ -171,16 +162,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { break; case SubGhzCustomEventViewReadRAWTXRXStop: - //Stop TX - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { - subghz_tx_stop(subghz); - subghz_sleep(subghz); - } - //Stop RX - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - subghz_sleep(subghz); - }; + subghz_txrx_stop(subghz); subghz->state_notifications = SubGhzNotificationStateIDLE; consumed = true; break; @@ -229,33 +211,27 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_file_available(subghz) && subghz_scene_read_raw_update_filename(subghz)) { //start send subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - } - if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || - (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { - if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; - subghz_read_raw_set_status( - subghz->subghz_read_raw, - SubGhzReadRAWStatusIDLE, - "", - subghz_threshold_rssi_get(subghz->threshold_rssi)); - } else { - if(scene_manager_has_previous_scene( - subghz->scene_manager, SubGhzSceneSaved) || - !scene_manager_has_previous_scene( - subghz->scene_manager, SubGhzSceneStart)) { - DOLPHIN_DEED(DolphinDeedSubGhzSend); - } - // set callback end tx - subghz_protocol_raw_file_encoder_worker_set_callback_end( - (SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance( - subghz->txrx->transmitter), - subghz_scene_read_raw_callback_end_tx, - subghz); - subghz->state_notifications = SubGhzNotificationStateTx; + + subghz_txrx_stop(subghz); + if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { + subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + subghz_read_raw_set_status( + subghz->subghz_read_raw, + SubGhzReadRAWStatusIDLE, + "", + subghz_threshold_rssi_get(subghz->threshold_rssi)); + } else { + if(scene_manager_has_previous_scene(subghz->scene_manager, SubGhzSceneSaved) || + !scene_manager_has_previous_scene(subghz->scene_manager, SubGhzSceneStart)) { + DOLPHIN_DEED(DolphinDeedSubGhzSend); } + // set callback end tx + subghz_protocol_raw_file_encoder_worker_set_callback_end( + (SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance( + subghz->txrx->transmitter), + subghz_scene_read_raw_callback_end_tx, + subghz); + subghz->state_notifications = SubGhzNotificationStateTx; } } else { if(!scene_manager_search_and_switch_to_previous_scene( @@ -269,21 +245,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWSendStop: subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { - subghz_speaker_unmute(subghz); - subghz_tx_stop(subghz); - subghz_sleep(subghz); - } + subghz_txrx_stop(subghz); subghz_read_raw_stop_send(subghz->subghz_read_raw); consumed = true; break; case SubGhzCustomEventViewReadRAWIDLE: - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - subghz_sleep(subghz); - }; - + subghz_txrx_stop(subghz); size_t spl_count = subghz_protocol_raw_get_sample_write( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); @@ -318,15 +286,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { RAW_FILE_NAME, subghz->txrx->preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); - if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || - (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { - subghz_begin( - subghz, - subghz_setting_get_preset_data_by_name( - subghz->setting, - furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); - } + subghz_txrx_stop(subghz); + subghz_begin( + subghz, + subghz_setting_get_preset_data_by_name( + subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz, subghz->txrx->preset->frequency); + subghz->state_notifications = SubGhzNotificationStateRx; subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; } else { @@ -389,10 +355,7 @@ void subghz_scene_read_raw_on_exit(void* context) { SubGhz* subghz = context; //Stop CC1101 - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - subghz_sleep(subghz); - }; + subghz_txrx_stop(subghz); subghz->state_notifications = SubGhzNotificationStateIDLE; notification_message(subghz->notifications, &sequence_reset_rgb); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 18008674d..7dd7d3993 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -190,17 +190,12 @@ void subghz_scene_receiver_on_enter(void* context) { } subghz->state_notifications = SubGhzNotificationStateRx; - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - } - if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || - (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { - subghz_begin( - subghz, - subghz_setting_get_preset_data_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); - } + subghz_txrx_stop(subghz); + subghz_begin( + subghz, + subghz_setting_get_preset_data_by_name( + subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz, subghz->txrx->preset->frequency); subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen); //to use a universal decoder, we are looking for a link to it @@ -219,10 +214,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReceiverBack: // Stop CC1101 Rx subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - subghz_sleep(subghz); - } + subghz_txrx_stop(subghz); subghz->txrx->hopper_state = SubGhzHopperStateOFF; subghz->txrx->idx_menu_chosen = 0; subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index a108132c0..13095b081 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -125,36 +125,29 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) { subghz->txrx->hopper_state = SubGhzHopperStatePause; } - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - } + + subghz_txrx_stop(subghz); + if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } - if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE || - subghz->txrx->txrx_state == SubGhzTxRxStateSleep) { - if(!subghz_tx_start( - subghz, - subghz_history_get_raw_data( - subghz->txrx->history, subghz->txrx->idx_menu_chosen))) { - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { - subghz_tx_stop(subghz); - } - if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) { - subghz_begin( - subghz, - subghz_setting_get_preset_data_by_name( - subghz->setting, - furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); - } - if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { - subghz->txrx->hopper_state = SubGhzHopperStateRunning; - } - subghz->state_notifications = SubGhzNotificationStateRx; - } else { - subghz->state_notifications = SubGhzNotificationStateTx; + + if(!subghz_tx_start( + subghz, + subghz_history_get_raw_data( + subghz->txrx->history, subghz->txrx->idx_menu_chosen))) { + subghz_txrx_stop(subghz); + subghz_begin( + subghz, + subghz_setting_get_preset_data_by_name( + subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz, subghz->txrx->preset->frequency); + if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { + subghz->txrx->hopper_state = SubGhzHopperStateRunning; } + subghz->state_notifications = SubGhzNotificationStateRx; + } else { + subghz->state_notifications = SubGhzNotificationStateTx; } return true; } else if(event.event == SubGhzCustomEventSceneReceiverInfoTxStop) { @@ -164,17 +157,14 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) widget_reset(subghz->widget); subghz_scene_receiver_info_draw_widget(subghz); - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { - subghz_tx_stop(subghz); - } + subghz_txrx_stop(subghz); if(!subghz->in_decoder_scene) { - if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) { - subghz_begin( - subghz, - subghz_setting_get_preset_data_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); - } + subghz_begin( + subghz, + subghz_setting_get_preset_data_by_name( + subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz, subghz->txrx->preset->frequency); + if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { subghz->txrx->hopper_state = SubGhzHopperStateRunning; } @@ -185,10 +175,8 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) //CC1101 Stop RX -> Save subghz->state_notifications = SubGhzNotificationStateIDLE; subghz->txrx->hopper_state = SubGhzHopperStateOFF; - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - subghz_sleep(subghz); - } + + subghz_txrx_stop(subghz); if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 8140f69a2..4d6806a9d 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -42,7 +42,7 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { view_dispatcher_stop(subghz->view_dispatcher); } else if(event.event == SubGhzCustomEventSceneRpcButtonPress) { bool result = false; - if((subghz->txrx->txrx_state == SubGhzTxRxStateSleep) && + if((subghz_txrx_get_state(subghz) == SubGhzTxRxStateSleep) && (state == SubGhzRpcStateLoaded)) { result = subghz_tx_start(subghz, subghz->txrx->fff_data); if(result) subghz_blink_start(subghz); @@ -56,10 +56,9 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result); } else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) { bool result = false; - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { + if(subghz_txrx_get_state(subghz) == SubGhzTxRxStateTx) { + subghz_txrx_stop(subghz); subghz_blink_stop(subghz); - subghz_tx_stop(subghz); - subghz_sleep(subghz); result = true; } rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonRelease, result); @@ -97,9 +96,8 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { void subghz_scene_rpc_on_exit(void* context) { SubGhz* subghz = context; - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { - subghz_tx_stop(subghz); - subghz_sleep(subghz); + if(subghz_txrx_get_state(subghz) == SubGhzTxRxStateTx) { + subghz_txrx_stop(subghz); subghz_blink_stop(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index d1fafd8ff..ed4088ec5 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -70,40 +70,28 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - } - if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || - (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { - if(subghz_tx_start(subghz, subghz->txrx->fff_data)) { - subghz->state_notifications = SubGhzNotificationStateTx; - subghz_scene_transmitter_update_data_show(subghz); - DOLPHIN_DEED(DolphinDeedSubGhzSend); - } + subghz_txrx_stop(subghz); + if(subghz_tx_start(subghz, subghz->txrx->fff_data)) { + subghz->state_notifications = SubGhzNotificationStateTx; + subghz_scene_transmitter_update_data_show(subghz); + DOLPHIN_DEED(DolphinDeedSubGhzSend); } return true; } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) { subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { - subghz_tx_stop(subghz); - subghz_sleep(subghz); - } + subghz_txrx_stop(subghz); if(subghz_custom_btn_get() != 0) { subghz_custom_btn_set(0); uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); furi_hal_subghz_set_rolling_counter_mult(0); // Calling restore! - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); + subghz_txrx_stop(subghz); + + if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); } - if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || - (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { - if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); - } - } - subghz_tx_stop(subghz); - subghz_sleep(subghz); + + subghz_txrx_stop(subghz); furi_hal_subghz_set_rolling_counter_mult(tmp_counter); } return true; diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 77eba42fb..bf9823cea 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -228,6 +228,31 @@ void subghz_tx_stop(SubGhz* subghz) { notification_message(subghz->notifications, &sequence_reset_red); } +void subghz_txrx_stop(SubGhz* subghz) { + furi_assert(subghz); + + switch(subghz->txrx->txrx_state) { + case SubGhzTxRxStateTx: + subghz_tx_stop(subghz); + subghz_speaker_unmute(subghz); + subghz_sleep(subghz); + break; + case SubGhzTxRxStateRx: + subghz_rx_end(subghz); + subghz_speaker_mute(subghz); + subghz_sleep(subghz); + break; + + default: + break; + } +} + +SubGhzTxRxState subghz_txrx_get_state(SubGhz* subghz) { + furi_assert(subghz); + return subghz->txrx->txrx_state; +} + void subghz_dialog_message_show_only_rx(SubGhz* subghz) { DialogsApp* dialogs = subghz->dialogs; DialogMessage* message = dialog_message_alloc(); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 9c58af7bb..5969d85cb 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -72,12 +72,15 @@ struct SubGhzTxRx { SubGhzRadioPreset* preset; SubGhzHistory* history; uint16_t idx_menu_chosen; + uint8_t hopper_timeout; uint8_t hopper_idx_frequency; - SubGhzTxRxState txrx_state; SubGhzHopperState hopper_state; SubGhzSpeakerState speaker_state; + + SubGhzTxRxState txrx_state; + bool ignore_starline; bool ignore_auto_alarms; bool ignore_magellan; @@ -175,5 +178,8 @@ void subghz_speaker_off(SubGhz* subghz); void subghz_speaker_mute(SubGhz* subghz); void subghz_speaker_unmute(SubGhz* subghz); +void subghz_txrx_stop(SubGhz* subghz); +SubGhzTxRxState subghz_txrx_get_state(SubGhz* subghz); + extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx_locked; From c98e76f31e52d526b9b4ba42cc1135b907639d29 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 6 May 2023 17:02:32 +0300 Subject: [PATCH 03/36] SubGhz: remove direct reading (hopper_state) --- .../subghz/scenes/subghz_scene_receiver.c | 4 ++-- .../scenes/subghz_scene_receiver_config.c | 6 ++--- .../scenes/subghz_scene_receiver_info.c | 16 ++++--------- applications/main/subghz/subghz.c | 2 +- applications/main/subghz/subghz_i.c | 24 +++++++++++++++++++ applications/main/subghz/subghz_i.h | 4 ++++ 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 7dd7d3993..8de7870a8 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -215,7 +215,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { // Stop CC1101 Rx subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz); - subghz->txrx->hopper_state = SubGhzHopperStateOFF; + subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); subghz->txrx->idx_menu_chosen = 0; subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); @@ -269,7 +269,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { break; } } else if(event.type == SceneManagerEventTypeTick) { - if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) { + if(subghz_hopper_get_state(subghz) != SubGhzHopperStateOFF) { subghz_hopper_update(subghz); subghz_scene_receiver_update_statusbar(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index bd9780428..ef8ffc9bd 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -143,7 +143,7 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) { + if(subghz_hopper_get_state(subghz) == SubGhzHopperStateOFF) { char text_buf[10] = {0}; snprintf( text_buf, @@ -209,7 +209,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) subghz_setting_get_frequency_default_index(subghz->setting)); } - subghz->txrx->hopper_state = hopping_value[index]; + subghz_hopper_set_state(subghz, hopping_value[index]); } static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { @@ -317,7 +317,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_hopping_running, subghz); value_index = subghz_scene_receiver_config_hopper_value_index( - subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz); + subghz_hopper_get_state(subghz), hopping_value, HOPPING_COUNT, subghz); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, hopping_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 13095b081..dd637c1eb 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -122,9 +122,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) { //CC1101 Stop RX -> Start TX - if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) { - subghz->txrx->hopper_state = SubGhzHopperStatePause; - } + subghz_subghz_hopper_set_pause(subghz); subghz_txrx_stop(subghz); @@ -142,9 +140,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) subghz_setting_get_preset_data_by_name( subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); subghz_rx(subghz, subghz->txrx->preset->frequency); - if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { - subghz->txrx->hopper_state = SubGhzHopperStateRunning; - } + subghz_hopper_remove_pause(subghz); subghz->state_notifications = SubGhzNotificationStateRx; } else { subghz->state_notifications = SubGhzNotificationStateTx; @@ -165,16 +161,14 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); subghz_rx(subghz, subghz->txrx->preset->frequency); - if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { - subghz->txrx->hopper_state = SubGhzHopperStateRunning; - } + subghz_hopper_remove_pause(subghz); subghz->state_notifications = SubGhzNotificationStateRx; } return true; } else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) { //CC1101 Stop RX -> Save subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz->txrx->hopper_state = SubGhzHopperStateOFF; + subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); subghz_txrx_stop(subghz); if(!subghz_scene_receiver_info_update_parser(subghz)) { @@ -193,7 +187,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) return true; } } else if(event.type == SceneManagerEventTypeTick) { - if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) { + if(subghz_hopper_get_state(subghz) != SubGhzHopperStateOFF) { subghz_hopper_update(subghz); } switch(subghz->state_notifications) { diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 4bbdba6c5..7e35346b8 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -271,7 +271,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0); } subghz->txrx->txrx_state = SubGhzTxRxStateSleep; - subghz->txrx->hopper_state = SubGhzHopperStateOFF; + subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); subghz->txrx->speaker_state = SubGhzSpeakerStateDisable; subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz->txrx->debug_pin_state = false; diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index bf9823cea..194b404db 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -629,6 +629,30 @@ void subghz_hopper_update(SubGhz* subghz) { } } +SubGhzHopperState subghz_hopper_get_state(SubGhz* subghz) { + furi_assert(subghz); + return subghz->txrx->hopper_state; +} + +void subghz_hopper_set_state(SubGhz* subghz, SubGhzHopperState state) { + furi_assert(subghz); + subghz->txrx->hopper_state = state; +} + +void subghz_hopper_remove_pause(SubGhz* subghz) { + furi_assert(subghz); + if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { + subghz->txrx->hopper_state = SubGhzHopperStateRunning; + } +} + +void subghz_subghz_hopper_set_pause(SubGhz* subghz) { + furi_assert(subghz); + if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) { + subghz->txrx->hopper_state = SubGhzHopperStatePause; + } +} + void subghz_speaker_on(SubGhz* subghz) { if(subghz->txrx->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 5969d85cb..f772c388c 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -180,6 +180,10 @@ void subghz_speaker_unmute(SubGhz* subghz); void subghz_txrx_stop(SubGhz* subghz); SubGhzTxRxState subghz_txrx_get_state(SubGhz* subghz); +SubGhzHopperState subghz_hopper_get_state(SubGhz* subghz); +void subghz_hopper_set_state(SubGhz* subghz, SubGhzHopperState state); +void subghz_hopper_remove_pause(SubGhz* subghz); +void subghz_subghz_hopper_set_pause(SubGhz* subghz); extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx_locked; From d8631d14890933e76f12df6e09756639294f46e7 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 6 May 2023 17:19:02 +0300 Subject: [PATCH 04/36] SubGhz: remove direct reading subghz->lock --- .../main/subghz/scenes/subghz_scene_decode_raw.c | 5 +++-- .../main/subghz/scenes/subghz_scene_receiver.c | 6 +++--- .../subghz/scenes/subghz_scene_receiver_config.c | 2 +- applications/main/subghz/subghz.c | 2 +- applications/main/subghz/subghz_i.c | 15 +++++++++++++++ applications/main/subghz/subghz_i.h | 4 ++++ applications/main/subghz/views/receiver.c | 14 +++++++------- applications/main/subghz/views/receiver.h | 2 +- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index b9f2d236b..639db146f 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -159,7 +159,8 @@ void subghz_scene_decode_raw_on_enter(void* context) { FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); - subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz->lock); + subghz_view_receiver_set_lock( + subghz->subghz_receiver, subghz_is_locked(subghz)); //TODO Doesn't matter in DecodeRAW subghz_view_receiver_set_mode(subghz->subghz_receiver, SubGhzViewReceiverModeFile); subghz_view_receiver_set_callback( subghz->subghz_receiver, subghz_scene_decode_raw_callback, subghz); @@ -242,7 +243,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) { consumed = true; break; case SubGhzCustomEventViewReceiverUnlock: - subghz->lock = SubGhzLockOff; + subghz_unlock(subghz); //TODO There is no such event in DecodeRAW consumed = true; break; default: diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 8de7870a8..5b525a486 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -127,7 +127,7 @@ void subghz_scene_receiver_on_enter(void* context) { subghz->txrx->rx_key_state = SubGhzRxKeyStateStart; } - subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz->lock); + subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz_is_locked(subghz)); subghz_view_receiver_set_mode(subghz->subghz_receiver, SubGhzViewReceiverModeLive); //Load history to receiver @@ -262,7 +262,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { consumed = true; break; case SubGhzCustomEventViewReceiverUnlock: - subghz->lock = SubGhzLockOff; + subghz_unlock(subghz); consumed = true; break; default: @@ -286,7 +286,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { notification_message(subghz->notifications, &sequence_blink_cyan_10); break; case SubGhzNotificationStateRxDone: - if(subghz->lock != SubGhzLockOn) { + if(!subghz_is_locked(subghz)) { notification_message(subghz->notifications, &subghz_sequence_rx); } else { notification_message(subghz->notifications, &subghz_sequence_rx_locked); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index ef8ffc9bd..7aa3d4e46 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -415,7 +415,7 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneSettingLock) { - subghz->lock = SubGhzLockOn; + subghz_lock(subghz); scene_manager_previous_scene(subghz->scene_manager); consumed = true; } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 7e35346b8..f2bb87c8a 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -260,7 +260,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->threshold_rssi = subghz_threshold_rssi_alloc(); //init Worker & Protocol & History & KeyBoard - subghz->lock = SubGhzLockOff; + subghz_unlock(subghz); subghz->txrx = malloc(sizeof(SubGhzTxRx)); subghz->txrx->preset = malloc(sizeof(SubGhzRadioPreset)); subghz->txrx->preset->name = furi_string_alloc(); diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 194b404db..e94f937bd 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -710,3 +710,18 @@ void subghz_speaker_unmute(SubGhz* subghz) { } } } + +void subghz_lock(SubGhz* subghz) { + furi_assert(subghz); + subghz->lock = SubGhzLockOn; +} + +void subghz_unlock(SubGhz* subghz) { + furi_assert(subghz); + subghz->lock = SubGhzLockOff; +} + +bool subghz_is_locked(SubGhz* subghz) { + furi_assert(subghz); + return (subghz->lock == SubGhzLockOn); +} \ No newline at end of file diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index f772c388c..7e3e9bab0 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -185,5 +185,9 @@ void subghz_hopper_set_state(SubGhz* subghz, SubGhzHopperState state); void subghz_hopper_remove_pause(SubGhz* subghz); void subghz_subghz_hopper_set_pause(SubGhz* subghz); +void subghz_lock(SubGhz* subghz); +void subghz_unlock(SubGhz* subghz); +bool subghz_is_locked(SubGhz* subghz); + extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx_locked; diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 811a46698..6f272b6a6 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -49,7 +49,7 @@ typedef enum { } SubGhzViewReceiverBarShow; struct SubGhzViewReceiver { - SubGhzLock lock; + bool lock; uint8_t lock_count; FuriTimer* timer; View* view; @@ -95,10 +95,10 @@ void subghz_receiver_rssi(SubGhzViewReceiver* instance, float rssi) { true); } -void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLock lock) { +void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, bool lock) { furi_assert(subghz_receiver); subghz_receiver->lock_count = 0; - if(lock == SubGhzLockOn) { + if(lock == true) { subghz_receiver->lock = lock; with_view_model( subghz_receiver->view, @@ -394,7 +394,7 @@ static void subghz_view_receiver_timer_callback(void* context) { subghz_receiver->callback( SubGhzCustomEventViewReceiverOffDisplay, subghz_receiver->context); } else { - subghz_receiver->lock = SubGhzLockOff; + subghz_receiver->lock = false; subghz_receiver->callback(SubGhzCustomEventViewReceiverUnlock, subghz_receiver->context); } subghz_receiver->lock_count = 0; @@ -404,7 +404,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { furi_assert(context); SubGhzViewReceiver* subghz_receiver = context; - if(subghz_receiver->lock == SubGhzLockOn) { + if(subghz_receiver->lock == true) { with_view_model( subghz_receiver->view, SubGhzViewReceiverModel * model, @@ -424,7 +424,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { SubGhzViewReceiverModel * model, { model->bar_show = SubGhzViewReceiverBarShowUnlock; }, true); - //subghz_receiver->lock = SubGhzLockOff; + //subghz_receiver->lock = false; furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(650)); } @@ -549,7 +549,7 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() { // View allocation and configuration subghz_receiver->view = view_alloc(); - subghz_receiver->lock = SubGhzLockOff; + subghz_receiver->lock = false; subghz_receiver->lock_count = 0; view_allocate_model( subghz_receiver->view, ViewModelTypeLocking, sizeof(SubGhzViewReceiverModel)); diff --git a/applications/main/subghz/views/receiver.h b/applications/main/subghz/views/receiver.h index f5ec86b4b..54c1b3e7d 100644 --- a/applications/main/subghz/views/receiver.h +++ b/applications/main/subghz/views/receiver.h @@ -14,7 +14,7 @@ void subghz_view_receiver_set_mode( void subghz_receiver_rssi(SubGhzViewReceiver* instance, float rssi); -void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLock keyboard); +void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, bool keyboard); void subghz_view_receiver_set_callback( SubGhzViewReceiver* subghz_receiver, From 1387d8d5d652c81b9eeb8c5a193dc6b0dca75718 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 6 May 2023 17:28:16 +0300 Subject: [PATCH 05/36] SubGhz: check load type file --- applications/main/subghz/helpers/subghz_types.h | 7 +++++++ applications/main/subghz/scenes/subghz_scene_saved.c | 2 +- applications/main/subghz/subghz.c | 2 +- applications/main/subghz/subghz_i.c | 7 +++++++ applications/main/subghz/subghz_i.h | 3 +++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_types.h b/applications/main/subghz/helpers/subghz_types.h index 3c5982427..700049237 100644 --- a/applications/main/subghz/helpers/subghz_types.h +++ b/applications/main/subghz/helpers/subghz_types.h @@ -80,6 +80,13 @@ typedef enum { SubGhzViewIdTestPacket, } SubGhzViewId; +/** SubGhz load type file */ +typedef enum { + SubGhzLoadTypeFileNoLoad, + SubGhzLoadTypeFileKey, + SubGhzLoadTypeFileRaw, +} SubGhzLoadTypeFile; + typedef enum { SubGhzViewReceiverModeLive, SubGhzViewReceiverModeFile, diff --git a/applications/main/subghz/scenes/subghz_scene_saved.c b/applications/main/subghz/scenes/subghz_scene_saved.c index 62ade3508..23d8ac39f 100644 --- a/applications/main/subghz/scenes/subghz_scene_saved.c +++ b/applications/main/subghz/scenes/subghz_scene_saved.c @@ -4,7 +4,7 @@ void subghz_scene_saved_on_enter(void* context) { SubGhz* subghz = context; if(subghz_load_protocol_from_file(subghz)) { - if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) { + if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); } else { diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index f2bb87c8a..6d565be5d 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -478,7 +478,7 @@ int32_t subghz_app(void* p) { if(subghz_key_load(subghz, p, true)) { furi_string_set(subghz->file_path, (const char*)p); - if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) { + if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { //Load Raw TX subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index e94f937bd..d8da55973 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -356,8 +356,10 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) { //if RAW + subghz->txrx->load_type_file = SubGhzLoadTypeFileRaw; subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, file_path); } else { + subghz->txrx->load_type_file = SubGhzLoadTypeFileKey; stream_copy_full( flipper_format_get_raw_stream(fff_data_file), flipper_format_get_raw_stream(subghz->txrx->fff_data)); @@ -412,6 +414,11 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } } +SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz) { + furi_assert(subghz); + return subghz->txrx->load_type_file; +} + bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len) { furi_assert(subghz); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 7e3e9bab0..4be2b6e5f 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -86,6 +86,7 @@ struct SubGhzTxRx { bool ignore_magellan; SubGhzRxKeyState rx_key_state; + SubGhzLoadTypeFile load_type_file; bool debug_pin_state; }; @@ -189,5 +190,7 @@ void subghz_lock(SubGhz* subghz); void subghz_unlock(SubGhz* subghz); bool subghz_is_locked(SubGhz* subghz); +SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); + extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx_locked; From 1567225a64b317f5b853e692d71b9d228293df39 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 6 May 2023 17:47:49 +0300 Subject: [PATCH 06/36] SubGhz: remove direct reading subghz->txrx->rx_key_state --- .../subghz/scenes/subghz_scene_need_saving.c | 10 +++---- .../subghz/scenes/subghz_scene_read_raw.c | 30 +++++++++---------- .../subghz/scenes/subghz_scene_receiver.c | 14 ++++----- .../subghz/scenes/subghz_scene_save_success.c | 4 +-- .../main/subghz/scenes/subghz_scene_saved.c | 2 +- .../main/subghz/scenes/subghz_scene_start.c | 2 +- applications/main/subghz/subghz.c | 4 +-- applications/main/subghz/subghz_i.c | 10 +++++++ applications/main/subghz/subghz_i.h | 5 +++- 9 files changed, 47 insertions(+), 34 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_need_saving.c b/applications/main/subghz/scenes/subghz_scene_need_saving.c index 5c6b9cc39..f6029e2c0 100644 --- a/applications/main/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/main/subghz/scenes/subghz_scene_need_saving.c @@ -37,22 +37,22 @@ void subghz_scene_need_saving_on_enter(void* context) { bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; if(event.type == SceneManagerEventTypeBack) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); scene_manager_previous_scene(subghz->scene_manager); return true; } else if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneStay) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); scene_manager_previous_scene(subghz->scene_manager); return true; } else if(event.event == SubGhzCustomEventSceneExit) { - if(subghz->txrx->rx_key_state == SubGhzRxKeyStateExit) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateExit) { + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } else { - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); scene_manager_previous_scene(subghz->scene_manager); } diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 33cd2ebb6..c2b0e5d35 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -71,7 +71,7 @@ void subghz_scene_read_raw_on_enter(void* context) { SubGhz* subghz = context; FuriString* file_name = furi_string_alloc(); - switch(subghz->txrx->rx_key_state) { + switch(subghz_rx_key_state_get(subghz)) { case SubGhzRxKeyStateBack: subghz_read_raw_set_status( subghz->subghz_read_raw, @@ -86,7 +86,7 @@ void subghz_scene_read_raw_on_enter(void* context) { SubGhzReadRAWStatusLoadKeyTX, furi_string_get_cstr(file_name), subghz_threshold_rssi_get(subghz->threshold_rssi)); - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); break; case SubGhzRxKeyStateRAWSave: path_extract_filename(subghz->file_path, file_name, true); @@ -95,7 +95,7 @@ void subghz_scene_read_raw_on_enter(void* context) { SubGhzReadRAWStatusSaveKey, furi_string_get_cstr(file_name), subghz_threshold_rssi_get(subghz->threshold_rssi)); - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); break; default: subghz_read_raw_set_status( @@ -103,7 +103,7 @@ void subghz_scene_read_raw_on_enter(void* context) { SubGhzReadRAWStatusStart, "", subghz_threshold_rssi_get(subghz->threshold_rssi)); - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); break; } furi_string_free(file_name); @@ -133,9 +133,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); subghz->state_notifications = SubGhzNotificationStateIDLE; //needed save? - if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) || - (subghz->txrx->rx_key_state == SubGhzRxKeyStateBack)) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; + if((subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) || + (subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateBack)) { + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { //Restore default setting @@ -175,13 +175,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { break; case SubGhzCustomEventViewReadRAWErase: - if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { + if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) { if(subghz_scene_read_raw_update_filename(subghz)) { furi_string_set(subghz->file_path_tmp, subghz->file_path); subghz_delete_file(subghz); } } - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); notification_message(subghz->notifications, &sequence_reset_rgb); consumed = true; break; @@ -191,7 +191,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_scene_read_raw_update_filename(subghz)) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet); - subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW); consumed = true; } else { @@ -214,7 +214,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz_txrx_stop(subghz); if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); subghz_read_raw_set_status( subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, @@ -272,13 +272,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { } subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); consumed = true; break; case SubGhzCustomEventViewReadRAWREC: - if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) { + if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateIDLE) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { if(subghz_protocol_raw_save_to_file_init( @@ -294,7 +294,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz_rx(subghz, subghz->txrx->preset->frequency); subghz->state_notifications = SubGhzNotificationStateRx; - subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); } else { furi_string_set(subghz->error_str, "Function requires\nan SD card."); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); @@ -307,7 +307,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_file_available(subghz) && subghz_scene_read_raw_update_filename(subghz)) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW); - subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); } else { if(!scene_manager_search_and_switch_to_previous_scene( diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 5b525a486..d52e37ff9 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -112,7 +112,7 @@ static void subghz_scene_add_to_history_callback( subghz_receiver_reset(receiver); furi_string_free(item_name); furi_string_free(item_time); - subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); } void subghz_scene_receiver_on_enter(void* context) { @@ -121,10 +121,10 @@ void subghz_scene_receiver_on_enter(void* context) { FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); - if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) { + if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) { subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); subghz_history_reset(subghz->txrx->history); - subghz->txrx->rx_key_state = SubGhzRxKeyStateStart; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); } subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz_is_locked(subghz)); @@ -142,7 +142,7 @@ void subghz_scene_receiver_on_enter(void* context) { furi_string_get_cstr(item_name), furi_string_get_cstr(item_time), subghz_history_get_type_protocol(subghz->txrx->history, i)); - subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); } furi_string_free(item_name); furi_string_free(item_time); @@ -219,11 +219,11 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { subghz->txrx->idx_menu_chosen = 0; subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); - if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; + if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) { + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); diff --git a/applications/main/subghz/scenes/subghz_scene_save_success.c b/applications/main/subghz/scenes/subghz_scene_save_success.c index 85be80b2a..0a7fd8686 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_success.c +++ b/applications/main/subghz/scenes/subghz_scene_save_success.c @@ -27,10 +27,10 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) if(!subghz->in_decoder_scene) { if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneReceiver)) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWSave; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWSave); if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneReadRAW)) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneSaved)) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved); diff --git a/applications/main/subghz/scenes/subghz_scene_saved.c b/applications/main/subghz/scenes/subghz_scene_saved.c index 23d8ac39f..eca5ab801 100644 --- a/applications/main/subghz/scenes/subghz_scene_saved.c +++ b/applications/main/subghz/scenes/subghz_scene_saved.c @@ -5,7 +5,7 @@ void subghz_scene_saved_on_enter(void* context) { if(subghz_load_protocol_from_file(subghz)) { if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); } else { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSavedMenu); diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index 8777d2461..ba405c737 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -93,7 +93,7 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) { } else if(event.event == SubmenuIndexReadRAW) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW); - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); return true; } else if(event.event == SubmenuIndexRead) { diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 6d565be5d..b64470860 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -273,7 +273,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->txrx_state = SubGhzTxRxStateSleep; subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); subghz->txrx->speaker_state = SubGhzSpeakerStateDisable; - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); subghz->txrx->debug_pin_state = false; if(!alloc_for_tx_only) { subghz->txrx->history = subghz_history_alloc(); @@ -480,7 +480,7 @@ int32_t subghz_app(void* p) { if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { //Load Raw TX - subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); } else { //Load transmitter TX diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index d8da55973..b2275c4d3 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -731,4 +731,14 @@ void subghz_unlock(SubGhz* subghz) { bool subghz_is_locked(SubGhz* subghz) { furi_assert(subghz); return (subghz->lock == SubGhzLockOn); +} + +void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state) { + furi_assert(subghz); + subghz->rx_key_state = state; +} + +SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz) { + furi_assert(subghz); + return subghz->rx_key_state; } \ No newline at end of file diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 4be2b6e5f..acbb1823a 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -85,7 +85,6 @@ struct SubGhzTxRx { bool ignore_auto_alarms; bool ignore_magellan; - SubGhzRxKeyState rx_key_state; SubGhzLoadTypeFile load_type_file; bool debug_pin_state; @@ -137,6 +136,7 @@ struct SubGhz { SubGhzFileEncoderWorker* decode_raw_file_worker_encoder; SubGhzThresholdRssi* threshold_rssi; + SubGhzRxKeyState rx_key_state; void* rpc_ctx; }; @@ -192,5 +192,8 @@ bool subghz_is_locked(SubGhz* subghz); SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); +void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state); +SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz); + extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx_locked; From e65a5e2b7cb8d34b15318f8aebeb528b856d01ba Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 6 May 2023 17:56:10 +0300 Subject: [PATCH 07/36] SubGhz: remove direct reading subghz->txrx->speaker_state --- .../main/subghz/scenes/subghz_scene_receiver_config.c | 5 +++-- applications/main/subghz/subghz.c | 2 +- applications/main/subghz/subghz_i.c | 10 ++++++++++ applications/main/subghz/subghz_i.h | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 7aa3d4e46..de78e002b 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -217,7 +217,7 @@ static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, speaker_text[index]); - subghz->txrx->speaker_state = speaker_value[index]; + subghz_speaker_set_state(subghz, speaker_value[index]); } static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) { @@ -378,7 +378,8 @@ void subghz_scene_receiver_config_on_enter(void* context) { SPEAKER_COUNT, subghz_scene_receiver_config_set_speaker, subghz); - value_index = value_index_uint32(subghz->txrx->speaker_state, speaker_value, SPEAKER_COUNT); + value_index = + value_index_uint32(subghz_speaker_get_state(subghz), speaker_value, SPEAKER_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, speaker_text[value_index]); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index b64470860..7e6cebe98 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -272,7 +272,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { } subghz->txrx->txrx_state = SubGhzTxRxStateSleep; subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); - subghz->txrx->speaker_state = SubGhzSpeakerStateDisable; + subghz_speaker_set_state(subghz, SubGhzSpeakerStateDisable); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); subghz->txrx->debug_pin_state = false; if(!alloc_for_tx_only) { diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index b2275c4d3..25d03915b 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -718,6 +718,16 @@ void subghz_speaker_unmute(SubGhz* subghz) { } } +void subghz_speaker_set_state(SubGhz* subghz, SubGhzSpeakerState state) { + furi_assert(subghz); + subghz->txrx->speaker_state = state; +} + +SubGhzSpeakerState subghz_speaker_get_state(SubGhz* subghz) { + furi_assert(subghz); + return subghz->txrx->speaker_state; +} + void subghz_lock(SubGhz* subghz) { furi_assert(subghz); subghz->lock = SubGhzLockOn; diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index acbb1823a..63687e97c 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -124,9 +124,10 @@ struct SubGhz { SubGhzTestStatic* subghz_test_static; SubGhzTestPacket* subghz_test_packet; #endif - FuriString* error_str; SubGhzSetting* setting; SubGhzLastSettings* last_settings; + + FuriString* error_str; SubGhzLock lock; bool in_decoder_scene; @@ -178,6 +179,8 @@ void subghz_speaker_on(SubGhz* subghz); void subghz_speaker_off(SubGhz* subghz); void subghz_speaker_mute(SubGhz* subghz); void subghz_speaker_unmute(SubGhz* subghz); +void subghz_speaker_set_state(SubGhz* subghz, SubGhzSpeakerState state); +SubGhzSpeakerState subghz_speaker_get_state(SubGhz* subghz); void subghz_txrx_stop(SubGhz* subghz); SubGhzTxRxState subghz_txrx_get_state(SubGhz* subghz); From ee85541d2a1ffcf5f3d6dffdb4b6e54aa178584d Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Mon, 8 May 2023 21:55:51 +0300 Subject: [PATCH 08/36] SubGhz: refactoring subghz_scene_set_type.csubghz_scene_set_type.c --- .../main/subghz/helpers/subghz_custom_event.h | 6 +- .../subghz/scenes/subghz_scene_set_seed.c | 83 +-- .../subghz/scenes/subghz_scene_set_type.c | 635 ++++++------------ applications/main/subghz/subghz_i.c | 341 ++++++++++ applications/main/subghz/subghz_i.h | 82 +++ 5 files changed, 643 insertions(+), 504 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_custom_event.h b/applications/main/subghz/helpers/subghz_custom_event.h index ad49bf09b..cd163a653 100644 --- a/applications/main/subghz/helpers/subghz_custom_event.h +++ b/applications/main/subghz/helpers/subghz_custom_event.h @@ -36,12 +36,12 @@ typedef enum { SubmenuIndexCAME24bit868, SubmenuIndexCAMETwee, SubmenuIndexCAMESpace, - SubmenuIndexPricenton, + SubmenuIndexPricenton433, SubmenuIndexPricenton315, SubmenuIndexBETT_433, SubmenuIndexLinear_300_00, - SubmenuIndexNeroSketch, - SubmenuIndexNeroRadio, + SubmenuIndexNeroSketch, //Deleted in OFW + SubmenuIndexNeroRadio, //Deleted in OFW SubmenuIndexGateTX, SubmenuIndexDoorHan_315_00, SubmenuIndexDoorHan_433_92, diff --git a/applications/main/subghz/scenes/subghz_scene_set_seed.c b/applications/main/subghz/scenes/subghz_scene_set_seed.c index aa2a270f3..336331126 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_seed.c +++ b/applications/main/subghz/scenes/subghz_scene_set_seed.c @@ -1,6 +1,4 @@ #include "../subghz_i.h" -#include -#include #define TAG "SubGhzSetSeed" @@ -50,34 +48,15 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { subghz->txrx->secure_data->seed[2] << 8 | subghz->txrx->secure_data->seed[3]; - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, "KeeLoq"); - if(subghz->txrx->transmitter) { - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - subghz_protocol_keeloq_bft_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - fix_part & 0x0FFFFFFF, - fix_part >> 28, - cnt, - seed, - "BFT", - subghz->txrx->preset); - - uint8_t seed_data[sizeof(uint32_t)] = {0}; - for(size_t i = 0; i < sizeof(uint32_t); i++) { - seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; - } - - flipper_format_write_hex( - subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); - - flipper_format_write_string_cstr(subghz->txrx->fff_data, "Manufacture", "BFT"); - - generated_protocol = true; - } - - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq_bft( + subghz, + "AM650", + 433920000, + fix_part & 0x0FFFFFFF, + fix_part >> 28, + cnt, + seed, + "BFT"); if(!generated_protocol) { furi_string_set( @@ -101,40 +80,28 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { subghz->txrx->secure_data->seed[2] << 8 | subghz->txrx->secure_data->seed[3]; - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, "Faac SLH"); - if(subghz->txrx->transmitter) { - SubGhzCustomEvent state = - scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType); - - if(state == SubmenuIndexFaacSLH_433) { - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - } else if(state == SubmenuIndexFaacSLH_868) { - subghz_preset_init(subghz, "AM650", 868350000, NULL, 0); - } - subghz_protocol_faac_slh_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, + if(state == SubmenuIndexFaacSLH_433) { + generated_protocol = subghz_scene_set_type_submenu_gen_data_faac_slh( + subghz, + "AM650", + 433920000, fix_part >> 4, fix_part & 0xf, (cnt & 0xFFFFF), seed, - "FAAC_SLH", - subghz->txrx->preset); - // RogueMaster dont steal! - uint8_t seed_data[sizeof(uint32_t)] = {0}; - for(size_t i = 0; i < sizeof(uint32_t); i++) { - seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; - } - - flipper_format_write_hex( - subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); - - generated_protocol = true; + "FAAC_SLH"); + } else if(state == SubmenuIndexFaacSLH_868) { + generated_protocol = subghz_scene_set_type_submenu_gen_data_faac_slh( + subghz, + "AM650", + 868350000, + fix_part >> 4, + fix_part & 0xf, + (cnt & 0xFFFFF), + seed, + "FAAC_SLH"); } - subghz_transmitter_free(subghz->txrx->transmitter); - if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index e871a6439..2ce806067 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -1,102 +1,9 @@ #include "../subghz_i.h" -#include -#include -#include -#include -#include #include -#include -#include #include #define TAG "SubGhzSetType" -bool subghz_scene_set_type_submenu_gen_data_protocol( - void* context, - const char* protocol_name, - uint64_t key, - uint32_t bit, - uint32_t frequency, - const char* preset_name) { - furi_assert(context); - SubGhz* subghz = context; - - bool res = false; - - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - subghz->txrx->decoder_result = - subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, protocol_name); - - if(subghz->txrx->decoder_result == NULL) { - furi_string_set(subghz->error_str, "Protocol not\nfound!"); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); - return false; - } - - do { - Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data); - stream_clean(fff_data_stream); - if(subghz_protocol_decoder_base_serialize( - subghz->txrx->decoder_result, subghz->txrx->fff_data, subghz->txrx->preset) != - SubGhzProtocolStatusOk) { - FURI_LOG_E(TAG, "Unable to serialize"); - break; - } - if(!flipper_format_update_uint32(subghz->txrx->fff_data, "Bit", &bit, 1)) { - FURI_LOG_E(TAG, "Unable to update Bit"); - break; - } - - uint8_t key_data[sizeof(uint64_t)] = {0}; - for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; - } - if(!flipper_format_update_hex(subghz->txrx->fff_data, "Key", key_data, sizeof(uint64_t))) { - FURI_LOG_E(TAG, "Unable to update Key"); - break; - } - res = true; - } while(false); - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_keeloq( - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - const char* manufacture_name) { - SubGhz* subghz = context; - - bool res = false; - - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - - if(subghz->txrx->transmitter && - subghz_protocol_keeloq_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - manufacture_name, - subghz->txrx->preset)) { - flipper_format_write_string_cstr(subghz->txrx->fff_data, "Manufacture", manufacture_name); - res = true; - } - - subghz_transmitter_free(subghz->txrx->transmitter); - if(!res) { - furi_string_set(subghz->error_str, "Function requires\nan SD card with\nfresh databases."); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); - } - return res; -} - void subghz_scene_set_type_submenu_callback(void* context, uint32_t index) { SubGhz* subghz = context; view_dispatcher_send_custom_event(subghz->view_dispatcher, index); @@ -306,7 +213,7 @@ void subghz_scene_set_type_on_enter(void* context) { submenu_add_item( subghz->submenu, "Princeton 433MHz", - SubmenuIndexPricenton, + SubmenuIndexPricenton433, subghz_scene_set_type_submenu_callback, subghz); submenu_add_item( @@ -385,7 +292,6 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { bool generated_protocol = false; if(event.type == SceneManagerEventTypeCustom) { - //ToDo Fix uint32_t key = subghz_random_serial(); switch(event.event) { case SubmenuIndexFaacSLH_868: @@ -397,258 +303,239 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { case SubmenuIndexBFTClone: scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFix); break; - case SubmenuIndexPricenton: + case SubmenuIndexPricenton433: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 433920000, "AM650")) { - uint32_t te = 400; - flipper_format_update_uint32(subghz->txrx->fff_data, "TE", (uint32_t*)&te, 1); - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol_and_te( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); break; case SubmenuIndexPricenton315: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 315000000, "AM650")) { - uint32_t te = 400; - flipper_format_update_uint32(subghz->txrx->fff_data, "TE", (uint32_t*)&te, 1); - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol_and_te( + subghz, "AM650", 315000000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); break; case SubmenuIndexNiceFlo12bit: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 12, 433920000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 12); break; case SubmenuIndexNiceFlo24bit: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 24, 433920000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 24); break; case SubmenuIndexCAME12bit: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 12, 433920000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); break; case SubmenuIndexCAME24bit: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 24, 433920000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); break; case SubmenuIndexCAME12bit868: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 12, 868350000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); break; case SubmenuIndexCAME24bit868: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 24, 868350000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); break; case SubmenuIndexLinear_300_00: key = (key & 0x3FF); - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10, 300000000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 300000000, SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10); break; case SubmenuIndexBETT_433: key = (key & 0x0000FFF0); - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_BETT_NAME, key, 18, 433920000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_BETT_NAME, key, 18); break; case SubmenuIndexCAMETwee: key = (key & 0x0FFFFFF0); key = 0x003FFF7200000000 | (key ^ 0xE0E0E0EE); - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_CAME_TWEE_NAME, key, 54, 433920000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_TWEE_NAME, key, 54); break; - // case SubmenuIndexNeroSketch: - // /* code */ - // break; - // case SubmenuIndexNeroRadio: - // /* code */ - // break; case SubmenuIndexGateTX: key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?) uint64_t rev_key = subghz_protocol_blocks_reverse_key(key, 24); - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24, 433920000, "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_data_protocol( + subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24); break; case SubmenuIndexBeninca433: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, - "AM650", - 433920000, - (key & 0x000FFF00) | 0x00800080, - 0x1, - 0x0005, - "Beninca")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, + "AM650", + 433920000, + (key & 0x000FFF00) | 0x00800080, + 0x1, + 0x0005, + "Beninca"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexBeninca868: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, - "AM650", - 868350000, - (key & 0x000FFF00) | 0x00800080, - 0x1, - 0x0005, - "Beninca")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, + "AM650", + 868350000, + (key & 0x000FFF00) | 0x00800080, + 0x1, + 0x0005, + "Beninca"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexAllmatic433: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, - "AM650", - 433920000, - (key & 0x00FFFF00) | 0x01000011, - 0xC, - 0x0005, - "Beninca")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, + "AM650", + 433920000, + (key & 0x00FFFF00) | 0x01000011, + 0xC, + 0x0005, + "Beninca"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexAllmatic868: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, - "AM650", - 868350000, - (key & 0x00FFFF00) | 0x01000011, - 0xC, - 0x0005, - "Beninca")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, + "AM650", + 868350000, + (key & 0x00FFFF00) | 0x01000011, + 0xC, + 0x0005, + "Beninca"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexElmesElectronic: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, - "AM650", - 433920000, - (key & 0x00FFFFFF) | 0x02000000, - 0x2, - 0x0003, - "Elmes_Poland")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, + "AM650", + 433920000, + (key & 0x00FFFFFF) | 0x02000000, + 0x2, + 0x0003, + "Elmes_Poland"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexANMotorsAT4: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, - "AM650", - 433920000, - (key & 0x000FFFFF) | 0x04700000, - 0x2, - 0x0021, - "AN-Motors")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, + "AM650", + 433920000, + (key & 0x000FFFFF) | 0x04700000, + 0x2, + 0x0021, + "AN-Motors"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexAprimatic: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, - "AM650", - 433920000, - (key & 0x000FFFFF) | 0x00600000, - 0x4, - 0x0003, - "Aprimatic")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, + "AM650", + 433920000, + (key & 0x000FFFFF) | 0x00600000, + 0x4, + 0x0003, + "Aprimatic"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexGibidi433: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Gibidi")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Gibidi"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexGSN: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "GSN")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "GSN"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexIronLogic: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFF0, 0x4, 0x0005, "IronLogic")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 433920000, key & 0x00FFFFF0, 0x4, 0x0005, "IronLogic"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexSommer_FM_434: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "FM476", 434420000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "FM476", 434420000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexSommer_FM_868: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "FM476", 868800000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "FM476", 868800000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexDTMNeo433: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0005, "DTM_Neo")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0005, "DTM_Neo"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexCAMESpace: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Came_Space")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Came_Space"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexBFTMitto: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_keeloq_bft_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key & 0x000FFFFF, - 0x2, - 0x0002, - key & 0x000FFFFF, - "BFT", - subghz->txrx->preset); - - uint8_t seed_data[sizeof(uint32_t)] = {0}; - for(size_t i = 0; i < sizeof(uint32_t); i++) { - seed_data[sizeof(uint32_t) - i - 1] = ((key & 0x000FFFFF) >> i * 8) & 0xFF; - } - - flipper_format_write_hex( - subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); - - flipper_format_write_string_cstr(subghz->txrx->fff_data, "Manufacture", "BFT"); - - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq_bft( + subghz, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0002, key & 0x000FFFFF, "BFT"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -656,22 +543,8 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAlutechAT4N: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_alutech_at_4n_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - (key & 0x000FFFFF) | 0x00100000, - 0x44, - 0x0003, - subghz->txrx->preset); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = subghz_scene_set_type_submenu_gen_data_alutech_at_4n( + subghz, "AM650", 433920000, (key & 0x000FFFFF) | 0x00100000, 0x44, 0x0003); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -679,58 +552,35 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexSomfyTelis: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_somfy_telis_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key & 0x00FFFFFF, - 0x2, - 0x0003, - subghz->txrx->preset); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); - if(!generated_protocol) { + generated_protocol = subghz_scene_set_type_submenu_gen_data_somfy_telis( + subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003); + if(!generated_protocol) { //TODO does not use databases furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexDoorHan_433_92: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexDoorHan_315_00: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 315000000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 315000000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexNiceFlorS_433_92: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_nice_flor_s_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key & 0x0FFFFFFF, - 0x1, - 0x0003, - subghz->txrx->preset, - false); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = subghz_scene_set_type_submenu_gen_data_nice_flor( + subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, false); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -738,23 +588,8 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexNiceOne_433_92: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_nice_flor_s_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key & 0x0FFFFFFF, - 0x1, - 0x0003, - subghz->txrx->preset, - true); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = subghz_scene_set_type_submenu_gen_data_nice_flor( + subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, true); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -762,124 +597,38 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexNiceSmilo_433_92: - if(subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "NICE_Smilo")) { - generated_protocol = true; + generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "NICE_Smilo"); + if(!generated_protocol) { + furi_string_set( + subghz->error_str, "Function requires\nan SD card with\nfresh databases."); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } break; case SubmenuIndexLiftMaster_315_00: - while(!subghz_protocol_secplus_v1_check_fixed(key)) { - key = subghz_random_serial(); - } - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, - SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, - (uint64_t)key << 32 | 0xE6000000, - 42, - 315000000, - "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_secplus_v1_protocol(subghz, "AM650", 315000000); break; case SubmenuIndexLiftMaster_390_00: - while(!subghz_protocol_secplus_v1_check_fixed(key)) { - key = subghz_random_serial(); - } - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, - SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, - (uint64_t)key << 32 | 0xE6000000, - 42, - 390000000, - "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_secplus_v1_protocol(subghz, "AM650", 390000000); break; case SubmenuIndexLiftMaster_433_00: - while(!subghz_protocol_secplus_v1_check_fixed(key)) { - key = subghz_random_serial(); - } - if(subghz_scene_set_type_submenu_gen_data_protocol( - subghz, - SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, - (uint64_t)key << 32 | 0xE6000000, - 42, - 433920000, - "AM650")) { - generated_protocol = true; - } + generated_protocol = subghz_gen_secplus_v1_protocol(subghz, "AM650", 433920000); break; case SubmenuIndexSecPlus_v2_310_00: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_preset_init(subghz, "AM650", 310000000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_secplus_v2_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key, - 0x68, - 0xE500000, - subghz->txrx->preset); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = + subghz_gen_secplus_v2_protocol(subghz, "AM650", 310000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_315_00: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_preset_init(subghz, "AM650", 315000000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_secplus_v2_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key, - 0x68, - 0xE500000, - subghz->txrx->preset); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = + subghz_gen_secplus_v2_protocol(subghz, "AM650", 315000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_390_00: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_preset_init(subghz, "AM650", 390000000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_secplus_v2_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key, - 0x68, - 0xE500000, - subghz->txrx->preset); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = + subghz_gen_secplus_v2_protocol(subghz, "AM650", 390000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_433_00: - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_preset_init(subghz, "AM650", 433920000, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_secplus_v2_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - key, - 0x68, - 0xE500000, - subghz->txrx->preset); - generated_protocol = true; - } else { - generated_protocol = false; - } - subghz_transmitter_free(subghz->txrx->transmitter); + generated_protocol = + subghz_gen_secplus_v2_protocol(subghz, "AM650", 433920000, key, 0x68, 0xE500000); break; default: return false; diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 25d03915b..0226921ad 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -751,4 +751,345 @@ void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state) { SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz) { furi_assert(subghz); return subghz->rx_key_state; +} + +//#############Create new Key############## +#include +#include +#include +#include +#include + +bool subghz_gen_data_protocol( + void* context, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit) { + furi_assert(context); + SubGhz* subghz = context; + + bool res = false; + + subghz_preset_init(subghz, preset_name, frequency, NULL, 0); + subghz->txrx->decoder_result = + subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, protocol_name); + + if(subghz->txrx->decoder_result == NULL) { + furi_string_set(subghz->error_str, "Protocol not\nfound!"); + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); + return false; + } + + do { + Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data); + stream_clean(fff_data_stream); + if(subghz_protocol_decoder_base_serialize( + subghz->txrx->decoder_result, subghz->txrx->fff_data, subghz->txrx->preset) != + SubGhzProtocolStatusOk) { + FURI_LOG_E(TAG, "Unable to serialize"); + break; + } + if(!flipper_format_update_uint32(subghz->txrx->fff_data, "Bit", &bit, 1)) { + FURI_LOG_E(TAG, "Unable to update Bit"); + break; + } + + uint8_t key_data[sizeof(uint64_t)] = {0}; + for(size_t i = 0; i < sizeof(uint64_t); i++) { + key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; + } + if(!flipper_format_update_hex(subghz->txrx->fff_data, "Key", key_data, sizeof(uint64_t))) { + FURI_LOG_E(TAG, "Unable to update Key"); + break; + } + res = true; + } while(false); + return res; +} + +bool subghz_gen_data_protocol_and_te( + SubGhz* subghz, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit, + uint32_t te) { + furi_assert(subghz); + bool ret = false; + if(subghz_gen_data_protocol(subghz, preset_name, frequency, protocol_name, key, bit)) { + if(!flipper_format_update_uint32(subghz->txrx->fff_data, "TE", (uint32_t*)&te, 1)) { + FURI_LOG_E(TAG, "Unable to update Te"); + } else { + ret = true; + } + } + return ret; +} + +bool subghz_scene_set_type_submenu_gen_data_keeloq( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + const char* manufacture_name) { + SubGhz* subghz = context; + + bool res = false; + + subghz->txrx->transmitter = + subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); + subghz_preset_init(subghz, preset_name, frequency, NULL, 0); + + if(subghz->txrx->transmitter && + subghz_protocol_keeloq_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + serial, + btn, + cnt, + manufacture_name, + subghz->txrx->preset)) { + flipper_format_write_string_cstr(subghz->txrx->fff_data, "Manufacture", manufacture_name); + res = true; + } + + subghz_transmitter_free(subghz->txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name) { + SubGhz* subghz = context; + + bool res = false; + + subghz->txrx->transmitter = + subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); + subghz_preset_init(subghz, preset_name, frequency, NULL, 0); + + if(subghz->txrx->transmitter && + subghz_protocol_keeloq_bft_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + serial, + btn, + cnt, + seed, + manufacture_name, + subghz->txrx->preset)) { + res = true; + } + + if(res) { + uint8_t seed_data[sizeof(uint32_t)] = {0}; + for(size_t i = 0; i < sizeof(uint32_t); i++) { + seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; + } + + flipper_format_write_hex(subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); + + flipper_format_write_string_cstr(subghz->txrx->fff_data, "Manufacture", "BFT"); + } + + subghz_transmitter_free(subghz->txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + bool nice_one) { + SubGhz* subghz = context; + + bool res = false; + + subghz->txrx->transmitter = + subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); + subghz_preset_init(subghz, preset_name, frequency, NULL, 0); + + if(subghz->txrx->transmitter && + subghz_protocol_nice_flor_s_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + serial, + btn, + cnt, + subghz->txrx->preset, + nice_one)) { + res = true; + } + + subghz_transmitter_free(subghz->txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name) { + SubGhz* subghz = context; + + bool res = false; + + subghz->txrx->transmitter = + subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME); + subghz_preset_init(subghz, preset_name, frequency, NULL, 0); + + if(subghz->txrx->transmitter && + subghz_protocol_faac_slh_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + serial, + btn, + cnt, + seed, + manufacture_name, + subghz->txrx->preset)) { + res = true; + } + + if(res) { + uint8_t seed_data[sizeof(uint32_t)] = {0}; + for(size_t i = 0; i < sizeof(uint32_t); i++) { + seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; + } + + flipper_format_write_hex(subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); + } + + subghz_transmitter_free(subghz->txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt) { + SubGhz* subghz = context; + + bool res = false; + + subghz->txrx->transmitter = subghz_transmitter_alloc_init( + subghz->txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); + subghz_preset_init(subghz, preset_name, frequency, NULL, 0); + + if(subghz->txrx->transmitter && + subghz_protocol_alutech_at_4n_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + serial, + btn, + cnt, + subghz->txrx->preset)) { + res = true; + } + + subghz_transmitter_free(subghz->txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt) { + SubGhz* subghz = context; + + bool res = false; + + subghz->txrx->transmitter = + subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); + subghz_preset_init(subghz, preset_name, frequency, NULL, 0); + + if(subghz->txrx->transmitter && + subghz_protocol_somfy_telis_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + serial, + btn, + cnt, + subghz->txrx->preset)) { + res = true; + } + + subghz_transmitter_free(subghz->txrx->transmitter); + + return res; +} + +bool subghz_gen_secplus_v2_protocol( + SubGhz* subghz, + const char* name_preset, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint32_t cnt) { + furi_assert(subghz); + + bool ret = false; + subghz->txrx->transmitter = + subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); + subghz_preset_init(subghz, name_preset, frequency, NULL, 0); + if(subghz->txrx->transmitter) { + subghz_protocol_secplus_v2_create_data( + subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), + subghz->txrx->fff_data, + serial, + btn, + cnt, + subghz->txrx->preset); + ret = true; + } + return ret; +} + +bool subghz_gen_secplus_v1_protocol(SubGhz* subghz, const char* name_preset, uint32_t frequency) { + furi_assert(subghz); + + bool ret = false; + uint32_t serial = subghz_random_serial(); + while(!subghz_protocol_secplus_v1_check_fixed(serial)) { + serial = subghz_random_serial(); + } + if(subghz_gen_data_protocol( + subghz, + name_preset, + frequency, + SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, + (uint64_t)serial << 32 | 0xE6000000, + 42)) { + ret = true; + } + return ret; } \ No newline at end of file diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 63687e97c..73b5221cb 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -198,5 +198,87 @@ SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state); SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz); +//#############Create new Key############## +bool subghz_gen_data_protocol( + void* context, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit); + +bool subghz_gen_data_protocol_and_te( + SubGhz* subghz, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit, + uint32_t te); + +bool subghz_scene_set_type_submenu_gen_data_keeloq( + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + bool nice_one); + +bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt); + +bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt); + +bool subghz_gen_secplus_v2_protocol( + SubGhz* subghz, + const char* name_preset, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint32_t cnt); + +bool subghz_gen_secplus_v1_protocol(SubGhz* subghz, const char* name_preset, uint32_t frequency); + extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx_locked; From b99d309feb9628e9c6aa910409cb735c4a31d5a2 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 12:07:36 +0300 Subject: [PATCH 09/36] SubGhz: moving "txrx" entity to a separate file --- .../subghz_frequency_analyzer_worker.c | 2 +- .../subghz/scenes/subghz_scene_decode_raw.c | 12 +- .../subghz/scenes/subghz_scene_need_saving.c | 3 +- .../subghz/scenes/subghz_scene_read_raw.c | 37 +- .../subghz/scenes/subghz_scene_receiver.c | 42 +- .../scenes/subghz_scene_receiver_config.c | 75 +- .../scenes/subghz_scene_receiver_info.c | 45 +- .../main/subghz/scenes/subghz_scene_rpc.c | 12 +- .../subghz/scenes/subghz_scene_save_name.c | 7 +- .../subghz/scenes/subghz_scene_save_success.c | 2 +- .../main/subghz/scenes/subghz_scene_set_cnt.c | 4 +- .../main/subghz/scenes/subghz_scene_set_fix.c | 2 +- .../subghz/scenes/subghz_scene_set_seed.c | 38 +- .../subghz/scenes/subghz_scene_set_type.c | 99 +-- .../subghz/scenes/subghz_scene_transmitter.c | 15 +- applications/main/subghz/subghz.c | 47 +- applications/main/subghz/subghz_i.c | 757 +----------------- applications/main/subghz/subghz_i.h | 159 +--- applications/main/subghz/subghz_radio.c | 723 +++++++++++++++++ applications/main/subghz/subghz_radio.h | 160 ++++ 20 files changed, 1161 insertions(+), 1080 deletions(-) create mode 100644 applications/main/subghz/subghz_radio.c create mode 100644 applications/main/subghz/subghz_radio.h diff --git a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c index ab90547cb..34f7e8cff 100644 --- a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c +++ b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c @@ -278,7 +278,7 @@ SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* cont furi_thread_set_callback(instance->thread, subghz_frequency_analyzer_worker_thread); SubGhz* subghz = context; - instance->setting = subghz->setting; + instance->setting = subghz->txrx->setting; instance->trigger_level = subghz->last_settings->frequency_analyzer_trigger; //instance->trigger_level = SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD; return instance; diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 639db146f..955e0df89 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -87,12 +87,13 @@ bool subghz_scene_decode_raw_start(SubGhz* subghz) { FuriString* file_name = furi_string_alloc(); bool success = false; do { - if(!flipper_format_rewind(subghz->txrx->fff_data)) { + if(!flipper_format_rewind(subghz_txtx_get_fff_data(subghz->txrx))) { FURI_LOG_E(TAG, "Rewind error"); break; } - if(!flipper_format_read_string(subghz->txrx->fff_data, "File_name", file_name)) { + if(!flipper_format_read_string( + subghz_txtx_get_fff_data(subghz->txrx), "File_name", file_name)) { FURI_LOG_E(TAG, "Missing File_name"); break; } @@ -193,7 +194,7 @@ void subghz_scene_decode_raw_on_enter(void* context) { } furi_string_free(item_name); furi_string_free(item_time); - subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen); + subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen); } subghz_scene_receiver_update_statusbar(subghz); @@ -208,7 +209,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) { switch(event.event) { case SubGhzCustomEventViewReceiverBack: subghz->decode_raw_state = SubGhzDecodeRawStateStart; - subghz->txrx->idx_menu_chosen = 0; + subghz->idx_menu_chosen = 0; subghz->in_decoder_scene = false; subghz->in_decoder_scene_skip = false; @@ -227,8 +228,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) { consumed = true; break; case SubGhzCustomEventViewReceiverOK: - subghz->txrx->idx_menu_chosen = - subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); + subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); subghz->state_notifications = SubGhzNotificationStateIDLE; subghz->in_decoder_scene = true; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo); diff --git a/applications/main/subghz/scenes/subghz_scene_need_saving.c b/applications/main/subghz/scenes/subghz_scene_need_saving.c index f6029e2c0..e64f75ef7 100644 --- a/applications/main/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/main/subghz/scenes/subghz_scene_need_saving.c @@ -48,7 +48,8 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { } else if(event.event == SubGhzCustomEventSceneExit) { if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateExit) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_preset_init( + subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } else { diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index c2b0e5d35..9abc24523 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -13,12 +13,13 @@ bool subghz_scene_read_raw_update_filename(SubGhz* subghz) { //set the path to read the file FuriString* temp_str = furi_string_alloc(); do { - if(!flipper_format_rewind(subghz->txrx->fff_data)) { + if(!flipper_format_rewind(subghz_txtx_get_fff_data(subghz->txrx))) { FURI_LOG_E(TAG, "Rewind error"); break; } - if(!flipper_format_read_string(subghz->txrx->fff_data, "File_name", temp_str)) { + if(!flipper_format_read_string( + subghz_txtx_get_fff_data(subghz->txrx), "File_name", temp_str)) { FURI_LOG_E(TAG, "Missing File_name"); break; } @@ -127,7 +128,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case SubGhzCustomEventViewReadRAWBack: - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); //Stop save file subghz_protocol_raw_save_to_file_stop( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); @@ -141,13 +142,14 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { //Restore default setting if(subghz->raw_send_only) { subghz_preset_init( - subghz, + subghz->txrx, "AM650", - subghz_setting_get_default_frequency(subghz->setting), + subghz_setting_get_default_frequency(subghz->txrx->setting), NULL, 0); } else { - subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_preset_init( + subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); } if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneSaved)) { @@ -162,7 +164,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { break; case SubGhzCustomEventViewReadRAWTXRXStop: - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateIDLE; consumed = true; break; @@ -212,8 +214,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { //start send subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_txrx_stop(subghz); - if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { + subghz_txrx_stop(subghz->txrx); + if(!subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); subghz_read_raw_set_status( subghz->subghz_read_raw, @@ -245,13 +247,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWSendStop: subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); subghz_read_raw_stop_send(subghz->subghz_read_raw); consumed = true; break; case SubGhzCustomEventViewReadRAWIDLE: - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); size_t spl_count = subghz_protocol_raw_get_sample_write( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); @@ -262,7 +264,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { furi_string_printf( temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, RAW_FILE_NAME, SUBGHZ_APP_EXTENSION); subghz_protocol_raw_gen_fff_data( - subghz->txrx->fff_data, furi_string_get_cstr(temp_str)); + subghz_txtx_get_fff_data(subghz->txrx), furi_string_get_cstr(temp_str)); furi_string_free(temp_str); if(spl_count > 0) { @@ -286,12 +288,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { RAW_FILE_NAME, subghz->txrx->preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); subghz_begin( - subghz, + subghz->txrx, subghz_setting_get_preset_data_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); + subghz->txrx->setting, + furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); subghz->state_notifications = SubGhzNotificationStateRx; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); @@ -355,7 +358,7 @@ void subghz_scene_read_raw_on_exit(void* context) { SubGhz* subghz = context; //Stop CC1101 - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateIDLE; notification_message(subghz->notifications, &sequence_reset_rgb); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index d52e37ff9..766810a04 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -122,7 +122,7 @@ void subghz_scene_receiver_on_enter(void* context) { FuriString* item_time = furi_string_alloc(); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) { - subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_preset_init(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); subghz_history_reset(subghz->txrx->history); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); } @@ -154,7 +154,7 @@ void subghz_scene_receiver_on_enter(void* context) { // TODO: Replace with proper solution based on protocol flags, remove kostily and velosipedy from here // Needs to be done after subghz refactoring merge!!! - if(subghz->txrx->ignore_starline == true) { + if(subghz->ignore_starline == true) { SubGhzProtocolDecoderBase* protocoldecoderbase = NULL; protocoldecoderbase = subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "Star Line"); @@ -163,7 +163,7 @@ void subghz_scene_receiver_on_enter(void* context) { protocoldecoderbase, NULL, subghz->txrx->receiver); } } - if(subghz->txrx->ignore_auto_alarms == true) { + if(subghz->ignore_auto_alarms == true) { SubGhzProtocolDecoderBase* protocoldecoderbase = NULL; protocoldecoderbase = subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "KIA Seed"); @@ -179,7 +179,7 @@ void subghz_scene_receiver_on_enter(void* context) { protocoldecoderbase, NULL, subghz->txrx->receiver); } } - if(subghz->txrx->ignore_magellan == true) { + if(subghz->ignore_magellan == true) { SubGhzProtocolDecoderBase* protocoldecoderbase = NULL; protocoldecoderbase = subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "Magellan"); @@ -190,13 +190,13 @@ void subghz_scene_receiver_on_enter(void* context) { } subghz->state_notifications = SubGhzNotificationStateRx; - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); subghz_begin( - subghz, + subghz->txrx, subghz_setting_get_preset_data_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); - subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen); + subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); + subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen); //to use a universal decoder, we are looking for a link to it subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name( @@ -214,9 +214,9 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReceiverBack: // Stop CC1101 Rx subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_txrx_stop(subghz); - subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); - subghz->txrx->idx_menu_chosen = 0; + subghz_txrx_stop(subghz->txrx); + subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); + subghz->idx_menu_chosen = 0; subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) { @@ -224,7 +224,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_preset_init( + subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } @@ -232,17 +233,15 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { break; case SubGhzCustomEventViewReceiverOK: // Show file info, scene: receiver_info - subghz->txrx->idx_menu_chosen = - subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); + subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo); DOLPHIN_DEED(DolphinDeedSubGhzReceiverInfo); consumed = true; break; case SubGhzCustomEventViewReceiverDeleteItem: - subghz->txrx->idx_menu_chosen = - subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); + subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); - subghz_history_delete_item(subghz->txrx->history, subghz->txrx->idx_menu_chosen); + subghz_history_delete_item(subghz->txrx->history, subghz->idx_menu_chosen); subghz_view_receiver_delete_element_callback(subghz->subghz_receiver); subghz_scene_receiver_update_statusbar(subghz); @@ -250,8 +249,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { break; case SubGhzCustomEventViewReceiverConfig: subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz->txrx->idx_menu_chosen = - subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); + subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); scene_manager_set_scene_state( subghz->scene_manager, SubGhzViewIdReceiver, SubGhzCustomEventManagerSet); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig); @@ -269,8 +267,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { break; } } else if(event.type == SceneManagerEventTypeTick) { - if(subghz_hopper_get_state(subghz) != SubGhzHopperStateOFF) { - subghz_hopper_update(subghz); + if(subghz_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { + subghz_hopper_update(subghz->txrx); subghz_scene_receiver_update_statusbar(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index de78e002b..f677739fd 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -93,12 +93,12 @@ uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* furi_assert(context); SubGhz* subghz = context; uint8_t index = 0; - for(uint8_t i = 0; i < subghz_setting_get_frequency_count(subghz->setting); i++) { - if(value == subghz_setting_get_frequency(subghz->setting, i)) { + for(uint8_t i = 0; i < subghz_setting_get_frequency_count(subghz->txrx->setting); i++) { + if(value == subghz_setting_get_frequency(subghz->txrx->setting, i)) { index = i; break; } else { - index = subghz_setting_get_frequency_default_index(subghz->setting); + index = subghz_setting_get_frequency_default_index(subghz->txrx->setting); } } return index; @@ -108,12 +108,12 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* furi_assert(context); SubGhz* subghz = context; uint8_t index = 0; - for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz->setting); i++) { - if(!strcmp(subghz_setting_get_preset_name(subghz->setting, i), preset_name)) { + for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz->txrx->setting); i++) { + if(!strcmp(subghz_setting_get_preset_name(subghz->txrx->setting, i), preset_name)) { index = i; break; } else { - // index = subghz_setting_get_frequency_default_index(subghz->setting); + // index = subghz_setting_get_frequency_default_index(subghz->txrx->setting); } } return index; @@ -143,37 +143,39 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - if(subghz_hopper_get_state(subghz) == SubGhzHopperStateOFF) { + if(subghz_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { char text_buf[10] = {0}; snprintf( text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(subghz->setting, index) / 1000000, - (subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000); + subghz_setting_get_frequency(subghz->txrx->setting, index) / 1000000, + (subghz_setting_get_frequency(subghz->txrx->setting, index) % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); - subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index); + subghz->txrx->preset->frequency = + subghz_setting_get_frequency(subghz->txrx->setting, index); subghz->last_settings->frequency = subghz->txrx->preset->frequency; - subghz_setting_set_default_frequency(subghz->setting, subghz->txrx->preset->frequency); + subghz_setting_set_default_frequency( + subghz->txrx->setting, subghz->txrx->preset->frequency); } else { variable_item_set_current_value_index( - item, subghz_setting_get_frequency_default_index(subghz->setting)); + item, subghz_setting_get_frequency_default_index(subghz->txrx->setting)); } } static void subghz_scene_receiver_config_set_preset(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - const char* preset_name = subghz_setting_get_preset_name(subghz->setting, index); + const char* preset_name = subghz_setting_get_preset_name(subghz->txrx->setting, index); variable_item_set_current_value_text(item, preset_name); //subghz->last_settings->preset = index; subghz_preset_init( - subghz, + subghz->txrx, preset_name, subghz->txrx->preset->frequency, - subghz_setting_get_preset_data(subghz->setting, index), - subghz_setting_get_preset_data_size(subghz->setting, index)); + subghz_setting_get_preset_data(subghz->txrx->setting, index), + subghz_setting_get_preset_data_size(subghz->txrx->setting, index)); } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -187,17 +189,18 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_default_frequency(subghz->setting) / 1000000, - (subghz_setting_get_default_frequency(subghz->setting) % 1000000) / 10000); + subghz_setting_get_default_frequency(subghz->txrx->setting) / 1000000, + (subghz_setting_get_default_frequency(subghz->txrx->setting) % 1000000) / 10000); variable_item_set_current_value_text( (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), text_buf); - subghz->txrx->preset->frequency = subghz_setting_get_default_frequency(subghz->setting); + subghz->txrx->preset->frequency = + subghz_setting_get_default_frequency(subghz->txrx->setting); variable_item_set_current_value_index( (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), - subghz_setting_get_frequency_default_index(subghz->setting)); + subghz_setting_get_frequency_default_index(subghz->txrx->setting)); } else { variable_item_set_current_value_text( (VariableItem*)scene_manager_get_scene_state( @@ -206,10 +209,10 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) variable_item_set_current_value_index( (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), - subghz_setting_get_frequency_default_index(subghz->setting)); + subghz_setting_get_frequency_default_index(subghz->txrx->setting)); } - subghz_hopper_set_state(subghz, hopping_value[index]); + subghz_hopper_set_state(subghz->txrx, hopping_value[index]); } static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { @@ -217,7 +220,7 @@ static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, speaker_text[index]); - subghz_speaker_set_state(subghz, speaker_value[index]); + subghz_speaker_set_state(subghz->txrx, speaker_value[index]); } static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) { @@ -242,7 +245,7 @@ static void subghz_scene_receiver_config_set_starline(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, starline_text[index]); - subghz->txrx->ignore_starline = (index == 1); + subghz->ignore_starline = (index == 1); } static void subghz_scene_receiver_config_set_auto_alarms(VariableItem* item) { @@ -250,7 +253,7 @@ static void subghz_scene_receiver_config_set_auto_alarms(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, auto_alarms_text[index]); - subghz->txrx->ignore_auto_alarms = (index == 1); + subghz->ignore_auto_alarms = (index == 1); } static void subghz_scene_receiver_config_set_magellan(VariableItem* item) { @@ -258,7 +261,7 @@ static void subghz_scene_receiver_config_set_magellan(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, magellan_text[index]); - subghz->txrx->ignore_magellan = (index == 1); + subghz->ignore_magellan = (index == 1); } static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) { @@ -278,7 +281,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { item = variable_item_list_add( subghz->variable_item_list, "Frequency:", - subghz_setting_get_frequency_count(subghz->setting), + subghz_setting_get_frequency_count(subghz->txrx->setting), subghz_scene_receiver_config_set_frequency, subghz); value_index = @@ -291,21 +294,21 @@ void subghz_scene_receiver_config_on_enter(void* context) { text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(subghz->setting, value_index) / 1000000, - (subghz_setting_get_frequency(subghz->setting, value_index) % 1000000) / 10000); + subghz_setting_get_frequency(subghz->txrx->setting, value_index) / 1000000, + (subghz_setting_get_frequency(subghz->txrx->setting, value_index) % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); item = variable_item_list_add( subghz->variable_item_list, "Modulation:", - subghz_setting_get_preset_count(subghz->setting), + subghz_setting_get_preset_count(subghz->txrx->setting), subghz_scene_receiver_config_set_preset, subghz); value_index = subghz_scene_receiver_config_next_preset( furi_string_get_cstr(subghz->txrx->preset->name), subghz); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text( - item, subghz_setting_get_preset_name(subghz->setting, value_index)); + item, subghz_setting_get_preset_name(subghz->txrx->setting, value_index)); if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerSet) { @@ -317,7 +320,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_hopping_running, subghz); value_index = subghz_scene_receiver_config_hopper_value_index( - subghz_hopper_get_state(subghz), hopping_value, HOPPING_COUNT, subghz); + subghz_hopper_get_state(subghz->txrx), hopping_value, HOPPING_COUNT, subghz); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, hopping_text[value_index]); } @@ -344,7 +347,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_starline, subghz); - value_index = subghz->txrx->ignore_starline; + value_index = subghz->ignore_starline; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, starline_text[value_index]); @@ -355,7 +358,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_auto_alarms, subghz); - value_index = subghz->txrx->ignore_auto_alarms; + value_index = subghz->ignore_auto_alarms; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, auto_alarms_text[value_index]); @@ -366,7 +369,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_magellan, subghz); - value_index = subghz->txrx->ignore_magellan; + value_index = subghz->ignore_magellan; variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, magellan_text[value_index]); } @@ -379,7 +382,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_speaker, subghz); value_index = - value_index_uint32(subghz_speaker_get_state(subghz), speaker_value, SPEAKER_COUNT); + value_index_uint32(subghz_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, speaker_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 dd637c1eb..3c53ac021 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -25,18 +25,18 @@ static bool subghz_scene_receiver_info_update_parser(void* context) { SubGhz* subghz = context; subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name( subghz->txrx->receiver, - subghz_history_get_protocol_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen)); + subghz_history_get_protocol_name(subghz->txrx->history, subghz->idx_menu_chosen)); if(subghz->txrx->decoder_result) { //todo we are trying to deserialize without checking for errors, since it is assumed that we just received this chignal subghz_protocol_decoder_base_deserialize( subghz->txrx->decoder_result, - subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen)); + subghz_history_get_raw_data(subghz->txrx->history, subghz->idx_menu_chosen)); SubGhzRadioPreset* preset = - subghz_history_get_radio_preset(subghz->txrx->history, subghz->txrx->idx_menu_chosen); + subghz_history_get_radio_preset(subghz->txrx->history, subghz->idx_menu_chosen); subghz_preset_init( - subghz, + subghz->txrx, furi_string_get_cstr(preset->name), preset->frequency, preset->data, @@ -122,25 +122,24 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) { //CC1101 Stop RX -> Start TX - subghz_subghz_hopper_set_pause(subghz); + subghz_subghz_hopper_set_pause(subghz->txrx); - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } if(!subghz_tx_start( - subghz, - subghz_history_get_raw_data( - subghz->txrx->history, subghz->txrx->idx_menu_chosen))) { - subghz_txrx_stop(subghz); + subghz->txrx, + subghz_history_get_raw_data(subghz->txrx->history, subghz->idx_menu_chosen))) { + subghz_txrx_stop(subghz->txrx); subghz_begin( - subghz, + subghz->txrx, subghz_setting_get_preset_data_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); - subghz_hopper_remove_pause(subghz); + subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); + subghz_hopper_remove_pause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; } else { subghz->state_notifications = SubGhzNotificationStateTx; @@ -153,24 +152,24 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) widget_reset(subghz->widget); subghz_scene_receiver_info_draw_widget(subghz); - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); if(!subghz->in_decoder_scene) { subghz_begin( - subghz, + subghz->txrx, subghz_setting_get_preset_data_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz, subghz->txrx->preset->frequency); + subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name))); + subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); - subghz_hopper_remove_pause(subghz); + subghz_hopper_remove_pause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; } return true; } else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) { //CC1101 Stop RX -> Save subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); + subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } @@ -187,8 +186,8 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) return true; } } else if(event.type == SceneManagerEventTypeTick) { - if(subghz_hopper_get_state(subghz) != SubGhzHopperStateOFF) { - subghz_hopper_update(subghz); + if(subghz_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { + subghz_hopper_update(subghz->txrx); } switch(subghz->state_notifications) { case SubGhzNotificationStateTx: diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 4d6806a9d..2af4112cf 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -42,9 +42,9 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { view_dispatcher_stop(subghz->view_dispatcher); } else if(event.event == SubGhzCustomEventSceneRpcButtonPress) { bool result = false; - if((subghz_txrx_get_state(subghz) == SubGhzTxRxStateSleep) && + if((subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateSleep) && (state == SubGhzRpcStateLoaded)) { - result = subghz_tx_start(subghz, subghz->txrx->fff_data); + result = subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx)); if(result) subghz_blink_start(subghz); } if(!result) { @@ -56,8 +56,8 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result); } else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) { bool result = false; - if(subghz_txrx_get_state(subghz) == SubGhzTxRxStateTx) { - subghz_txrx_stop(subghz); + if(subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateTx) { + subghz_txrx_stop(subghz->txrx); subghz_blink_stop(subghz); result = true; } @@ -96,8 +96,8 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { void subghz_scene_rpc_on_exit(void* context) { SubGhz* subghz = context; - if(subghz_txrx_get_state(subghz) == SubGhzTxRxStateTx) { - subghz_txrx_stop(subghz); + if(subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateTx) { + subghz_txrx_stop(subghz->txrx); subghz_blink_stop(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index 2bb13f184..f31d4be79 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -146,7 +146,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { SubGhzCustomEventManagerNoSet) { subghz_save_protocol_to_file( subghz, - subghz->txrx->fff_data, + subghz_txtx_get_fff_data(subghz->txrx), furi_string_get_cstr(subghz->file_path)); scene_manager_set_scene_state( subghz->scene_manager, @@ -156,7 +156,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { subghz_save_protocol_to_file( subghz, subghz_history_get_raw_data( - subghz->txrx->history, subghz->txrx->idx_menu_chosen), + subghz->txrx->history, subghz->idx_menu_chosen), furi_string_get_cstr(subghz->file_path)); } } @@ -164,7 +164,8 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerNoSet) { subghz_protocol_raw_gen_fff_data( - subghz->txrx->fff_data, furi_string_get_cstr(subghz->file_path)); + subghz_txtx_get_fff_data(subghz->txrx), + furi_string_get_cstr(subghz->file_path)); scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet); } else { diff --git a/applications/main/subghz/scenes/subghz_scene_save_success.c b/applications/main/subghz/scenes/subghz_scene_save_success.c index 0a7fd8686..ad37da086 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_success.c +++ b/applications/main/subghz/scenes/subghz_scene_save_success.c @@ -39,7 +39,7 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) } } else { subghz->decode_raw_state = SubGhzDecodeRawStateStart; - subghz->txrx->idx_menu_chosen = 0; + subghz->idx_menu_chosen = 0; subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) { diff --git a/applications/main/subghz/scenes/subghz_scene_set_cnt.c b/applications/main/subghz/scenes/subghz_scene_set_cnt.c index 62ef581ff..4faff7bbb 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_cnt.c +++ b/applications/main/subghz/scenes/subghz_scene_set_cnt.c @@ -24,7 +24,7 @@ void subghz_scene_set_cnt_on_enter(void* context) { subghz_scene_set_cnt_byte_input_callback, NULL, subghz, - subghz->txrx->secure_data->cnt, + subghz->secure_data->cnt, 2); break; case SubmenuIndexFaacSLH_433: @@ -35,7 +35,7 @@ void subghz_scene_set_cnt_on_enter(void* context) { subghz_scene_set_cnt_byte_input_callback, NULL, subghz, - subghz->txrx->secure_data->cnt, + subghz->secure_data->cnt, 3); break; default: diff --git a/applications/main/subghz/scenes/subghz_scene_set_fix.c b/applications/main/subghz/scenes/subghz_scene_set_fix.c index 01431dac6..7564fb24d 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_fix.c +++ b/applications/main/subghz/scenes/subghz_scene_set_fix.c @@ -19,7 +19,7 @@ void subghz_scene_set_fix_on_enter(void* context) { subghz_scene_set_fix_byte_input_callback, NULL, subghz, - subghz->txrx->secure_data->fix, + subghz->secure_data->fix, 4); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); } diff --git a/applications/main/subghz/scenes/subghz_scene_set_seed.c b/applications/main/subghz/scenes/subghz_scene_set_seed.c index 336331126..e416d8c2d 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_seed.c +++ b/applications/main/subghz/scenes/subghz_scene_set_seed.c @@ -19,7 +19,7 @@ void subghz_scene_set_seed_on_enter(void* context) { subghz_scene_set_seed_byte_input_callback, NULL, subghz, - subghz->txrx->secure_data->seed, + subghz->secure_data->seed, 4); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); } @@ -36,20 +36,16 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { switch(state) { case SubmenuIndexBFTClone: - fix_part = subghz->txrx->secure_data->fix[0] << 24 | - subghz->txrx->secure_data->fix[1] << 16 | - subghz->txrx->secure_data->fix[2] << 8 | - subghz->txrx->secure_data->fix[3]; + fix_part = subghz->secure_data->fix[0] << 24 | subghz->secure_data->fix[1] << 16 | + subghz->secure_data->fix[2] << 8 | subghz->secure_data->fix[3]; - cnt = subghz->txrx->secure_data->cnt[0] << 8 | subghz->txrx->secure_data->cnt[1]; + cnt = subghz->secure_data->cnt[0] << 8 | subghz->secure_data->cnt[1]; - seed = subghz->txrx->secure_data->seed[0] << 24 | - subghz->txrx->secure_data->seed[1] << 16 | - subghz->txrx->secure_data->seed[2] << 8 | - subghz->txrx->secure_data->seed[3]; + seed = subghz->secure_data->seed[0] << 24 | subghz->secure_data->seed[1] << 16 | + subghz->secure_data->seed[2] << 8 | subghz->secure_data->seed[3]; generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq_bft( - subghz, + subghz->txrx, "AM650", 433920000, fix_part & 0x0FFFFFFF, @@ -67,22 +63,18 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexFaacSLH_433: case SubmenuIndexFaacSLH_868: - fix_part = subghz->txrx->secure_data->fix[0] << 24 | - subghz->txrx->secure_data->fix[1] << 16 | - subghz->txrx->secure_data->fix[2] << 8 | - subghz->txrx->secure_data->fix[3]; + fix_part = subghz->secure_data->fix[0] << 24 | subghz->secure_data->fix[1] << 16 | + subghz->secure_data->fix[2] << 8 | subghz->secure_data->fix[3]; - cnt = subghz->txrx->secure_data->cnt[0] << 16 | - subghz->txrx->secure_data->cnt[1] << 8 | subghz->txrx->secure_data->cnt[2]; + cnt = subghz->secure_data->cnt[0] << 16 | subghz->secure_data->cnt[1] << 8 | + subghz->secure_data->cnt[2]; - seed = subghz->txrx->secure_data->seed[0] << 24 | - subghz->txrx->secure_data->seed[1] << 16 | - subghz->txrx->secure_data->seed[2] << 8 | - subghz->txrx->secure_data->seed[3]; + seed = subghz->secure_data->seed[0] << 24 | subghz->secure_data->seed[1] << 16 | + subghz->secure_data->seed[2] << 8 | subghz->secure_data->seed[3]; if(state == SubmenuIndexFaacSLH_433) { generated_protocol = subghz_scene_set_type_submenu_gen_data_faac_slh( - subghz, + subghz->txrx, "AM650", 433920000, fix_part >> 4, @@ -92,7 +84,7 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { "FAAC_SLH"); } else if(state == SubmenuIndexFaacSLH_868) { generated_protocol = subghz_scene_set_type_submenu_gen_data_faac_slh( - subghz, + subghz->txrx, "AM650", 868350000, fix_part >> 4, diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index 2ce806067..4bbf1c769 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -292,7 +292,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { bool generated_protocol = false; if(event.type == SceneManagerEventTypeCustom) { - uint32_t key = subghz_random_serial(); + uint32_t key = (uint32_t)rand(); switch(event.event) { case SubmenuIndexFaacSLH_868: scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFix); @@ -306,68 +306,68 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { case SubmenuIndexPricenton433: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 generated_protocol = subghz_gen_data_protocol_and_te( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); break; case SubmenuIndexPricenton315: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 generated_protocol = subghz_gen_data_protocol_and_te( - subghz, "AM650", 315000000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); + subghz->txrx, "AM650", 315000000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); break; case SubmenuIndexNiceFlo12bit: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 12); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 12); break; case SubmenuIndexNiceFlo24bit: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 24); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 24); break; case SubmenuIndexCAME12bit: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); break; case SubmenuIndexCAME24bit: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); break; case SubmenuIndexCAME12bit868: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); + subghz->txrx, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); break; case SubmenuIndexCAME24bit868: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); + subghz->txrx, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); break; case SubmenuIndexLinear_300_00: key = (key & 0x3FF); generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 300000000, SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10); + subghz->txrx, "AM650", 300000000, SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10); break; case SubmenuIndexBETT_433: key = (key & 0x0000FFF0); generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_BETT_NAME, key, 18); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_BETT_NAME, key, 18); break; case SubmenuIndexCAMETwee: key = (key & 0x0FFFFFF0); key = 0x003FFF7200000000 | (key ^ 0xE0E0E0EE); generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_TWEE_NAME, key, 54); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_TWEE_NAME, key, 54); break; case SubmenuIndexGateTX: key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?) uint64_t rev_key = subghz_protocol_blocks_reverse_key(key, 24); generated_protocol = subghz_gen_data_protocol( - subghz, "AM650", 433920000, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24); + subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24); break; case SubmenuIndexBeninca433: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, + subghz->txrx, "AM650", 433920000, (key & 0x000FFF00) | 0x00800080, @@ -382,7 +382,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexBeninca868: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, + subghz->txrx, "AM650", 868350000, (key & 0x000FFF00) | 0x00800080, @@ -397,7 +397,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexAllmatic433: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, + subghz->txrx, "AM650", 433920000, (key & 0x00FFFF00) | 0x01000011, @@ -412,7 +412,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexAllmatic868: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, + subghz->txrx, "AM650", 868350000, (key & 0x00FFFF00) | 0x01000011, @@ -427,7 +427,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexElmesElectronic: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, + subghz->txrx, "AM650", 433920000, (key & 0x00FFFFFF) | 0x02000000, @@ -442,7 +442,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexANMotorsAT4: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, + subghz->txrx, "AM650", 433920000, (key & 0x000FFFFF) | 0x04700000, @@ -457,7 +457,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexAprimatic: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, + subghz->txrx, "AM650", 433920000, (key & 0x000FFFFF) | 0x00600000, @@ -472,7 +472,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexGibidi433: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Gibidi"); + subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Gibidi"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -481,7 +481,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexGSN: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "GSN"); + subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "GSN"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -490,7 +490,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexIronLogic: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFF0, 0x4, 0x0005, "IronLogic"); + subghz->txrx, "AM650", 433920000, key & 0x00FFFFF0, 0x4, 0x0005, "IronLogic"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -499,7 +499,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexSommer_FM_434: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "FM476", 434420000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); + subghz->txrx, "FM476", 434420000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -508,7 +508,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexSommer_FM_868: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "FM476", 868800000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); + subghz->txrx, "FM476", 868800000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -517,7 +517,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexDTMNeo433: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0005, "DTM_Neo"); + subghz->txrx, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0005, "DTM_Neo"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -526,7 +526,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexCAMESpace: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Came_Space"); + subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Came_Space"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -535,7 +535,14 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexBFTMitto: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq_bft( - subghz, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0002, key & 0x000FFFFF, "BFT"); + subghz->txrx, + "AM650", + 433920000, + key & 0x000FFFFF, + 0x2, + 0x0002, + key & 0x000FFFFF, + "BFT"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -544,7 +551,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexAlutechAT4N: generated_protocol = subghz_scene_set_type_submenu_gen_data_alutech_at_4n( - subghz, "AM650", 433920000, (key & 0x000FFFFF) | 0x00100000, 0x44, 0x0003); + subghz->txrx, "AM650", 433920000, (key & 0x000FFFFF) | 0x00100000, 0x44, 0x0003); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -553,7 +560,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexSomfyTelis: generated_protocol = subghz_scene_set_type_submenu_gen_data_somfy_telis( - subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003); + subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003); if(!generated_protocol) { //TODO does not use databases furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -562,7 +569,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexDoorHan_433_92: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); + subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -571,7 +578,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexDoorHan_315_00: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 315000000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); + subghz->txrx, "AM650", 315000000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -580,7 +587,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexNiceFlorS_433_92: generated_protocol = subghz_scene_set_type_submenu_gen_data_nice_flor( - subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, false); + subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, false); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -589,7 +596,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexNiceOne_433_92: generated_protocol = subghz_scene_set_type_submenu_gen_data_nice_flor( - subghz, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, true); + subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, true); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -598,7 +605,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexNiceSmilo_433_92: generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( - subghz, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "NICE_Smilo"); + subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "NICE_Smilo"); if(!generated_protocol) { furi_string_set( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); @@ -606,29 +613,29 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexLiftMaster_315_00: - generated_protocol = subghz_gen_secplus_v1_protocol(subghz, "AM650", 315000000); + generated_protocol = subghz_gen_secplus_v1_protocol(subghz->txrx, "AM650", 315000000); break; case SubmenuIndexLiftMaster_390_00: - generated_protocol = subghz_gen_secplus_v1_protocol(subghz, "AM650", 390000000); + generated_protocol = subghz_gen_secplus_v1_protocol(subghz->txrx, "AM650", 390000000); break; case SubmenuIndexLiftMaster_433_00: - generated_protocol = subghz_gen_secplus_v1_protocol(subghz, "AM650", 433920000); + generated_protocol = subghz_gen_secplus_v1_protocol(subghz->txrx, "AM650", 433920000); break; case SubmenuIndexSecPlus_v2_310_00: - generated_protocol = - subghz_gen_secplus_v2_protocol(subghz, "AM650", 310000000, key, 0x68, 0xE500000); + generated_protocol = subghz_gen_secplus_v2_protocol( + subghz->txrx, "AM650", 310000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_315_00: - generated_protocol = - subghz_gen_secplus_v2_protocol(subghz, "AM650", 315000000, key, 0x68, 0xE500000); + generated_protocol = subghz_gen_secplus_v2_protocol( + subghz->txrx, "AM650", 315000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_390_00: - generated_protocol = - subghz_gen_secplus_v2_protocol(subghz, "AM650", 390000000, key, 0x68, 0xE500000); + generated_protocol = subghz_gen_secplus_v2_protocol( + subghz->txrx, "AM650", 390000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_433_00: - generated_protocol = - subghz_gen_secplus_v2_protocol(subghz, "AM650", 433920000, key, 0x68, 0xE500000); + generated_protocol = subghz_gen_secplus_v2_protocol( + subghz->txrx, "AM650", 433920000, key, 0x68, 0xE500000); break; default: return false; diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index ed4088ec5..375c142d1 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -23,7 +23,8 @@ bool subghz_scene_transmitter_update_data_show(void* context) { bool show_button = false; if(subghz_protocol_decoder_base_deserialize( - subghz->txrx->decoder_result, subghz->txrx->fff_data) == SubGhzProtocolStatusOk) { + subghz->txrx->decoder_result, subghz_txtx_get_fff_data(subghz->txrx)) == + SubGhzProtocolStatusOk) { subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, key_str); if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == @@ -70,8 +71,8 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_txrx_stop(subghz); - if(subghz_tx_start(subghz, subghz->txrx->fff_data)) { + subghz_txrx_stop(subghz->txrx); + if(subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { subghz->state_notifications = SubGhzNotificationStateTx; subghz_scene_transmitter_update_data_show(subghz); DOLPHIN_DEED(DolphinDeedSubGhzSend); @@ -79,19 +80,19 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { return true; } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) { subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); if(subghz_custom_btn_get() != 0) { subghz_custom_btn_set(0); uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); furi_hal_subghz_set_rolling_counter_mult(0); // Calling restore! - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); - if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { + if(!subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); } - subghz_txrx_stop(subghz); + subghz_txrx_stop(subghz->txrx); furi_hal_subghz_set_rolling_counter_mult(tmp_counter); } return true; diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 7e6cebe98..8731bbc9d 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -180,10 +180,11 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_test_static_get_view(subghz->subghz_test_static)); #endif + subghz->txrx = malloc(sizeof(SubGhzTxRx)); //init setting - subghz->setting = subghz_setting_alloc(); + subghz->txrx->setting = subghz_setting_alloc(); - subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user")); + subghz_setting_load(subghz->txrx->setting, EXT_PATH("subghz/assets/setting_user")); // Custom Presets load without using config file if(!alloc_for_tx_only) { @@ -193,7 +194,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 83 10 67 15 24 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset); - subghz_setting_load_custom_preset(subghz->setting, (const char*)"FM95", temp_fm_preset); + subghz_setting_load_custom_preset( + subghz->txrx->setting, (const char*)"FM95", temp_fm_preset); flipper_format_free(temp_fm_preset); @@ -204,7 +206,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 03 47 08 32 0B 06 15 32 14 00 13 00 12 00 11 32 10 A7 18 18 19 1D 1D 92 1C 00 1B 04 20 FB 22 17 21 B6 00 00 00 12 0E 34 60 C5 C1 C0"); flipper_format_rewind(temp_fm_preset2); - subghz_setting_load_custom_preset(subghz->setting, (const char*)"FM15k", temp_fm_preset2); + subghz_setting_load_custom_preset( + subghz->txrx->setting, (const char*)"FM15k", temp_fm_preset2); flipper_format_free(temp_fm_preset2); @@ -215,7 +218,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset3); - subghz_setting_load_custom_preset(subghz->setting, (const char*)"Pagers", temp_fm_preset3); + subghz_setting_load_custom_preset( + subghz->txrx->setting, (const char*)"Pagers", temp_fm_preset3); flipper_format_free(temp_fm_preset3); @@ -226,7 +230,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset4); - subghz_setting_load_custom_preset(subghz->setting, (const char*)"HND_1", temp_fm_preset4); + subghz_setting_load_custom_preset( + subghz->txrx->setting, (const char*)"HND_1", temp_fm_preset4); flipper_format_free(temp_fm_preset4); @@ -236,7 +241,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 07 11 36 10 E9 15 32 18 18 19 16 1D 92 1C 40 1B 03 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset5); - subghz_setting_load_custom_preset(subghz->setting, (const char*)"HND_2", temp_fm_preset5); + subghz_setting_load_custom_preset( + subghz->txrx->setting, (const char*)"HND_2", temp_fm_preset5); flipper_format_free(temp_fm_preset5); } @@ -253,7 +259,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { 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->txrx->setting, subghz->last_settings->frequency); } //init threshold rssi @@ -261,18 +268,22 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { //init Worker & Protocol & History & KeyBoard subghz_unlock(subghz); - subghz->txrx = malloc(sizeof(SubGhzTxRx)); + subghz->txrx->preset = malloc(sizeof(SubGhzRadioPreset)); subghz->txrx->preset->name = furi_string_alloc(); if(!alloc_for_tx_only) { - subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_preset_init(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); } else { subghz_preset_init( - subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0); + subghz->txrx, + "AM650", + subghz_setting_get_default_frequency(subghz->txrx->setting), + NULL, + 0); } subghz->txrx->txrx_state = SubGhzTxRxStateSleep; - subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); - subghz_speaker_set_state(subghz, SubGhzSpeakerStateDisable); + subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); + subghz_speaker_set_state(subghz->txrx, SubGhzSpeakerStateDisable); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); subghz->txrx->debug_pin_state = false; if(!alloc_for_tx_only) { @@ -282,7 +293,7 @@ SubGhz* subghz_alloc(bool 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)); + subghz->secure_data = malloc(sizeof(SecureData)); subghz->txrx->environment = subghz_environment_alloc(); subghz_environment_set_came_atomo_rainbow_table_file_name( @@ -303,6 +314,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); + subghz_txrx_need_save_callback_set(subghz->txrx, subghz_save_to_file, subghz); + //Init Error_str subghz->error_str = furi_string_alloc(); @@ -319,7 +332,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { subghz->rpc_ctx = NULL; } - subghz_speaker_off(subghz); + subghz_speaker_off(subghz->txrx); #if FURI_DEBUG // Packet Test @@ -390,7 +403,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { subghz->gui = NULL; // setting - subghz_setting_free(subghz->setting); + subghz_setting_free(subghz->txrx->setting); if(!alloc_for_tx_only) { subghz_last_settings_free(subghz->last_settings); } @@ -412,7 +425,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { } furi_string_free(subghz->txrx->preset->name); free(subghz->txrx->preset); - free(subghz->txrx->secure_data); + free(subghz->secure_data); free(subghz->txrx); //Error string diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 0226921ad..3b9c1c695 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -18,38 +18,6 @@ #define TAG "SubGhz" -void subghz_preset_init( - void* context, - const char* preset_name, - uint32_t frequency, - uint8_t* preset_data, - size_t preset_data_size) { - furi_assert(context); - SubGhz* subghz = context; - furi_string_set(subghz->txrx->preset->name, preset_name); - subghz->txrx->preset->frequency = frequency; - subghz->txrx->preset->data = preset_data; - subghz->txrx->preset->data_size = preset_data_size; -} - -bool subghz_set_preset(SubGhz* subghz, const char* preset) { - if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { - furi_string_set(subghz->txrx->preset->name, "AM270"); - } else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) { - furi_string_set(subghz->txrx->preset->name, "AM650"); - } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) { - furi_string_set(subghz->txrx->preset->name, "FM238"); - } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) { - furi_string_set(subghz->txrx->preset->name, "FM476"); - } else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) { - furi_string_set(subghz->txrx->preset->name, "CUSTOM"); - } else { - FURI_LOG_E(TAG, "Unknown preset"); - return false; - } - return true; -} - void subghz_get_frequency_modulation(SubGhz* subghz, FuriString* frequency, FuriString* modulation) { furi_assert(subghz); if(frequency != NULL) { @@ -64,195 +32,6 @@ void subghz_get_frequency_modulation(SubGhz* subghz, FuriString* frequency, Furi } } -void subghz_begin(SubGhz* subghz, uint8_t* preset_data) { - furi_assert(subghz); - furi_hal_subghz_reset(); - furi_hal_subghz_idle(); - furi_hal_subghz_load_custom_preset(preset_data); - furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow); - subghz->txrx->txrx_state = SubGhzTxRxStateIDLE; -} - -uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) { - furi_assert(subghz); - if(!furi_hal_subghz_is_frequency_valid(frequency)) { - furi_crash("SubGhz: Incorrect RX frequency."); - } - furi_assert( - subghz->txrx->txrx_state != SubGhzTxRxStateRx && - subghz->txrx->txrx_state != SubGhzTxRxStateSleep); - - furi_hal_subghz_idle(); - uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency); - furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow); - furi_hal_subghz_flush_rx(); - subghz_speaker_on(subghz); - furi_hal_subghz_rx(); - - furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, subghz->txrx->worker); - subghz_worker_start(subghz->txrx->worker); - subghz->txrx->txrx_state = SubGhzTxRxStateRx; - return value; -} - -static bool subghz_tx(SubGhz* subghz, uint32_t frequency) { - furi_assert(subghz); - if(!furi_hal_subghz_is_frequency_valid(frequency)) { - furi_crash("SubGhz: Incorrect TX frequency."); - } - furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep); - furi_hal_subghz_idle(); - furi_hal_subghz_set_frequency_and_path(frequency); - furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false); - furi_hal_gpio_init( - furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); - bool ret = furi_hal_subghz_tx(); - if(ret) { - subghz_speaker_on(subghz); - subghz->txrx->txrx_state = SubGhzTxRxStateTx; - } - return ret; -} - -void subghz_idle(SubGhz* subghz) { - furi_assert(subghz); - furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep); - furi_hal_subghz_idle(); - subghz_speaker_off(subghz); - subghz->txrx->txrx_state = SubGhzTxRxStateIDLE; -} - -void subghz_rx_end(SubGhz* subghz) { - furi_assert(subghz); - furi_assert(subghz->txrx->txrx_state == SubGhzTxRxStateRx); - - if(subghz_worker_is_running(subghz->txrx->worker)) { - subghz_worker_stop(subghz->txrx->worker); - furi_hal_subghz_stop_async_rx(); - } - furi_hal_subghz_idle(); - subghz_speaker_off(subghz); - subghz->txrx->txrx_state = SubGhzTxRxStateIDLE; -} - -void subghz_sleep(SubGhz* subghz) { - furi_assert(subghz); - furi_hal_subghz_sleep(); - subghz->txrx->txrx_state = SubGhzTxRxStateSleep; -} - -bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) { - furi_assert(subghz); - - bool ret = false; - FuriString* temp_str = furi_string_alloc(); - uint32_t repeat = 200; - do { - if(!flipper_format_rewind(flipper_format)) { - FURI_LOG_E(TAG, "Rewind error"); - break; - } - if(!flipper_format_read_string(flipper_format, "Protocol", temp_str)) { - FURI_LOG_E(TAG, "Missing Protocol"); - break; - } - if(!flipper_format_insert_or_update_uint32(flipper_format, "Repeat", &repeat, 1)) { - FURI_LOG_E(TAG, "Unable Repeat"); - break; - } - - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, furi_string_get_cstr(temp_str)); - - if(subghz->txrx->transmitter) { - if(subghz_transmitter_deserialize(subghz->txrx->transmitter, flipper_format) == - SubGhzProtocolStatusOk) { - if(strcmp(furi_string_get_cstr(subghz->txrx->preset->name), "") != 0) { - subghz_begin( - subghz, - subghz_setting_get_preset_data_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - } else { - FURI_LOG_E( - TAG, - "Unknown name preset \" %s \"", - furi_string_get_cstr(subghz->txrx->preset->name)); - subghz_begin( - subghz, subghz_setting_get_preset_data_by_name(subghz->setting, "AM650")); - } - if(subghz->txrx->preset->frequency) { - ret = subghz_tx(subghz, subghz->txrx->preset->frequency); - } else { - ret = subghz_tx(subghz, 433920000); - } - if(ret) { - //Start TX - furi_hal_subghz_start_async_tx( - subghz_transmitter_yield, subghz->txrx->transmitter); - } else { - subghz_dialog_message_show_only_rx(subghz); - } - } else { - dialog_message_show_storage_error( - subghz->dialogs, "Error in protocol\nparameters\ndescription"); - } - } - if(!ret) { - subghz_transmitter_free(subghz->txrx->transmitter); - if(subghz->txrx->txrx_state != SubGhzTxRxStateSleep) { - subghz_idle(subghz); - } - } - - } while(false); - furi_string_free(temp_str); - return ret; -} - -void subghz_tx_stop(SubGhz* subghz) { - furi_assert(subghz); - furi_assert(subghz->txrx->txrx_state == SubGhzTxRxStateTx); - //Stop TX - furi_hal_subghz_stop_async_tx(); - subghz_transmitter_stop(subghz->txrx->transmitter); - subghz_transmitter_free(subghz->txrx->transmitter); - - //if protocol dynamic then we save the last upload - if((subghz->txrx->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) && - (subghz_path_is_file(subghz->file_path))) { - subghz_save_protocol_to_file( - subghz, subghz->txrx->fff_data, furi_string_get_cstr(subghz->file_path)); - } - subghz_idle(subghz); - subghz_speaker_off(subghz); - notification_message(subghz->notifications, &sequence_reset_red); -} - -void subghz_txrx_stop(SubGhz* subghz) { - furi_assert(subghz); - - switch(subghz->txrx->txrx_state) { - case SubGhzTxRxStateTx: - subghz_tx_stop(subghz); - subghz_speaker_unmute(subghz); - subghz_sleep(subghz); - break; - case SubGhzTxRxStateRx: - subghz_rx_end(subghz); - subghz_speaker_mute(subghz); - subghz_sleep(subghz); - break; - - default: - break; - } -} - -SubGhzTxRxState subghz_txrx_get_state(SubGhz* subghz) { - furi_assert(subghz); - return subghz->txrx->txrx_state; -} - void subghz_dialog_message_show_only_rx(SubGhz* subghz) { DialogsApp* dialogs = subghz->dialogs; DialogMessage* message = dialog_message_alloc(); @@ -275,7 +54,8 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data); + Stream* fff_data_stream = + flipper_format_get_raw_stream(subghz_txtx_get_fff_data(subghz->txrx)); SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr; FuriString* temp_str = furi_string_alloc(); @@ -301,6 +81,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { break; } + //Load frequency if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) { FURI_LOG_E(TAG, "Missing Frequency"); break; @@ -316,14 +97,15 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { load_key_state = SubGhzLoadKeyStateOnlyRx; break; } - subghz->txrx->preset->frequency = temp_data32; + //subghz->txrx->preset->frequency = temp_data32; + //Load preset if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) { FURI_LOG_E(TAG, "Missing Preset"); break; } - if(!subghz_set_preset(subghz, furi_string_get_cstr(temp_str))) { + if(!subghz_set_preset(subghz->txrx, furi_string_get_cstr(temp_str))) { break; } @@ -331,10 +113,11 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { //Todo add Custom_preset_module //delete preset if it already exists subghz_setting_delete_custom_preset( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name)); + subghz_txrx_get_setting(subghz->txrx), + furi_string_get_cstr(subghz->txrx->preset->name)); //load custom preset from file if(!subghz_setting_load_custom_preset( - subghz->setting, + subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(subghz->txrx->preset->name), fff_data_file)) { FURI_LOG_E(TAG, "Missing Custom preset"); @@ -342,34 +125,37 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } } size_t preset_index = subghz_setting_get_inx_preset_by_name( - subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name)); + subghz_txrx_get_setting(subghz->txrx), + furi_string_get_cstr(subghz->txrx->preset->name)); subghz_preset_init( - subghz, + subghz->txrx, furi_string_get_cstr(subghz->txrx->preset->name), - subghz->txrx->preset->frequency, - subghz_setting_get_preset_data(subghz->setting, preset_index), - subghz_setting_get_preset_data_size(subghz->setting, preset_index)); + temp_data32, + subghz_setting_get_preset_data(subghz_txrx_get_setting(subghz->txrx), preset_index), + subghz_setting_get_preset_data_size( + subghz_txrx_get_setting(subghz->txrx), preset_index)); + //Load protocol if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) { FURI_LOG_E(TAG, "Missing Protocol"); break; } if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) { //if RAW - subghz->txrx->load_type_file = SubGhzLoadTypeFileRaw; - subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, file_path); + subghz->load_type_file = SubGhzLoadTypeFileRaw; + subghz_protocol_raw_gen_fff_data(subghz_txtx_get_fff_data(subghz->txrx), file_path); } else { - subghz->txrx->load_type_file = SubGhzLoadTypeFileKey; + subghz->load_type_file = SubGhzLoadTypeFileKey; stream_copy_full( flipper_format_get_raw_stream(fff_data_file), - flipper_format_get_raw_stream(subghz->txrx->fff_data)); + flipper_format_get_raw_stream(subghz_txtx_get_fff_data(subghz->txrx))); } subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name( subghz->txrx->receiver, furi_string_get_cstr(temp_str)); if(subghz->txrx->decoder_result) { SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize( - subghz->txrx->decoder_result, subghz->txrx->fff_data); + subghz->txrx->decoder_result, subghz_txtx_get_fff_data(subghz->txrx)); if(status != SubGhzProtocolStatusOk) { load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr; break; @@ -416,7 +202,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz) { furi_assert(subghz); - return subghz->txrx->load_type_file; + return subghz->load_type_file; } bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len) { @@ -460,6 +246,17 @@ bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len) { return res; } +void subghz_save_to_file(void* context) { + furi_assert(context); + SubGhz* subghz = context; + if(subghz_path_is_file(subghz->file_path)) { + subghz_save_protocol_to_file( + subghz, + subghz_txtx_get_fff_data(subghz->txrx), + furi_string_get_cstr(subghz->file_path)); + } +} + bool subghz_save_protocol_to_file( SubGhz* subghz, FlipperFormat* flipper_format, @@ -583,151 +380,6 @@ bool subghz_path_is_file(FuriString* path) { return furi_string_end_with(path, SUBGHZ_APP_EXTENSION); } -uint32_t subghz_random_serial(void) { - return (uint32_t)rand(); -} - -void subghz_hopper_update(SubGhz* subghz) { - furi_assert(subghz); - - switch(subghz->txrx->hopper_state) { - case SubGhzHopperStateOFF: - case SubGhzHopperStatePause: - return; - case SubGhzHopperStateRSSITimeOut: - if(subghz->txrx->hopper_timeout != 0) { - subghz->txrx->hopper_timeout--; - return; - } - break; - default: - break; - } - float rssi = -127.0f; - if(subghz->txrx->hopper_state != SubGhzHopperStateRSSITimeOut) { - // See RSSI Calculation timings in CC1101 17.3 RSSI - rssi = furi_hal_subghz_get_rssi(); - - // Stay if RSSI is high enough - if(rssi > -90.0f) { - subghz->txrx->hopper_timeout = 10; - subghz->txrx->hopper_state = SubGhzHopperStateRSSITimeOut; - return; - } - } else { - subghz->txrx->hopper_state = SubGhzHopperStateRunning; - } - // Select next frequency - if(subghz->txrx->hopper_idx_frequency < - subghz_setting_get_hopper_frequency_count(subghz->setting) - 1) { - subghz->txrx->hopper_idx_frequency++; - } else { - subghz->txrx->hopper_idx_frequency = 0; - } - - if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(subghz); - }; - if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) { - subghz_receiver_reset(subghz->txrx->receiver); - subghz->txrx->preset->frequency = subghz_setting_get_hopper_frequency( - subghz->setting, subghz->txrx->hopper_idx_frequency); - subghz_rx(subghz, subghz->txrx->preset->frequency); - } -} - -SubGhzHopperState subghz_hopper_get_state(SubGhz* subghz) { - furi_assert(subghz); - return subghz->txrx->hopper_state; -} - -void subghz_hopper_set_state(SubGhz* subghz, SubGhzHopperState state) { - furi_assert(subghz); - subghz->txrx->hopper_state = state; -} - -void subghz_hopper_remove_pause(SubGhz* subghz) { - furi_assert(subghz); - if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { - subghz->txrx->hopper_state = SubGhzHopperStateRunning; - } -} - -void subghz_subghz_hopper_set_pause(SubGhz* subghz) { - furi_assert(subghz); - if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) { - subghz->txrx->hopper_state = SubGhzHopperStatePause; - } -} - -void subghz_speaker_on(SubGhz* subghz) { - if(subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); - } - - if(subghz->txrx->speaker_state == SubGhzSpeakerStateEnable) { - if(furi_hal_speaker_acquire(30)) { - if(!subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(&gpio_speaker); - } - } else { - subghz->txrx->speaker_state = SubGhzSpeakerStateDisable; - } - } -} - -void subghz_speaker_off(SubGhz* subghz) { - if(subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(NULL); - } - if(subghz->txrx->speaker_state != SubGhzSpeakerStateDisable) { - if(furi_hal_speaker_is_mine()) { - if(!subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(NULL); - } - furi_hal_speaker_release(); - if(subghz->txrx->speaker_state == SubGhzSpeakerStateShutdown) - subghz->txrx->speaker_state = SubGhzSpeakerStateDisable; - } - } -} - -void subghz_speaker_mute(SubGhz* subghz) { - if(subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(NULL); - } - if(subghz->txrx->speaker_state == SubGhzSpeakerStateEnable) { - if(furi_hal_speaker_is_mine()) { - if(!subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(NULL); - } - } - } -} - -void subghz_speaker_unmute(SubGhz* subghz) { - if(subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); - } - if(subghz->txrx->speaker_state == SubGhzSpeakerStateEnable) { - if(furi_hal_speaker_is_mine()) { - if(!subghz->txrx->debug_pin_state) { - furi_hal_subghz_set_async_mirror_pin(&gpio_speaker); - } - } - } -} - -void subghz_speaker_set_state(SubGhz* subghz, SubGhzSpeakerState state) { - furi_assert(subghz); - subghz->txrx->speaker_state = state; -} - -SubGhzSpeakerState subghz_speaker_get_state(SubGhz* subghz) { - furi_assert(subghz); - return subghz->txrx->speaker_state; -} - void subghz_lock(SubGhz* subghz) { furi_assert(subghz); subghz->lock = SubGhzLockOn; @@ -752,344 +404,3 @@ SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz) { furi_assert(subghz); return subghz->rx_key_state; } - -//#############Create new Key############## -#include -#include -#include -#include -#include - -bool subghz_gen_data_protocol( - void* context, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit) { - furi_assert(context); - SubGhz* subghz = context; - - bool res = false; - - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - subghz->txrx->decoder_result = - subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, protocol_name); - - if(subghz->txrx->decoder_result == NULL) { - furi_string_set(subghz->error_str, "Protocol not\nfound!"); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); - return false; - } - - do { - Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data); - stream_clean(fff_data_stream); - if(subghz_protocol_decoder_base_serialize( - subghz->txrx->decoder_result, subghz->txrx->fff_data, subghz->txrx->preset) != - SubGhzProtocolStatusOk) { - FURI_LOG_E(TAG, "Unable to serialize"); - break; - } - if(!flipper_format_update_uint32(subghz->txrx->fff_data, "Bit", &bit, 1)) { - FURI_LOG_E(TAG, "Unable to update Bit"); - break; - } - - uint8_t key_data[sizeof(uint64_t)] = {0}; - for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; - } - if(!flipper_format_update_hex(subghz->txrx->fff_data, "Key", key_data, sizeof(uint64_t))) { - FURI_LOG_E(TAG, "Unable to update Key"); - break; - } - res = true; - } while(false); - return res; -} - -bool subghz_gen_data_protocol_and_te( - SubGhz* subghz, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit, - uint32_t te) { - furi_assert(subghz); - bool ret = false; - if(subghz_gen_data_protocol(subghz, preset_name, frequency, protocol_name, key, bit)) { - if(!flipper_format_update_uint32(subghz->txrx->fff_data, "TE", (uint32_t*)&te, 1)) { - FURI_LOG_E(TAG, "Unable to update Te"); - } else { - ret = true; - } - } - return ret; -} - -bool subghz_scene_set_type_submenu_gen_data_keeloq( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - const char* manufacture_name) { - SubGhz* subghz = context; - - bool res = false; - - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - - if(subghz->txrx->transmitter && - subghz_protocol_keeloq_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - manufacture_name, - subghz->txrx->preset)) { - flipper_format_write_string_cstr(subghz->txrx->fff_data, "Manufacture", manufacture_name); - res = true; - } - - subghz_transmitter_free(subghz->txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name) { - SubGhz* subghz = context; - - bool res = false; - - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - - if(subghz->txrx->transmitter && - subghz_protocol_keeloq_bft_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - seed, - manufacture_name, - subghz->txrx->preset)) { - res = true; - } - - if(res) { - uint8_t seed_data[sizeof(uint32_t)] = {0}; - for(size_t i = 0; i < sizeof(uint32_t); i++) { - seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; - } - - flipper_format_write_hex(subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); - - flipper_format_write_string_cstr(subghz->txrx->fff_data, "Manufacture", "BFT"); - } - - subghz_transmitter_free(subghz->txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - bool nice_one) { - SubGhz* subghz = context; - - bool res = false; - - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - - if(subghz->txrx->transmitter && - subghz_protocol_nice_flor_s_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - subghz->txrx->preset, - nice_one)) { - res = true; - } - - subghz_transmitter_free(subghz->txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name) { - SubGhz* subghz = context; - - bool res = false; - - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME); - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - - if(subghz->txrx->transmitter && - subghz_protocol_faac_slh_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - seed, - manufacture_name, - subghz->txrx->preset)) { - res = true; - } - - if(res) { - uint8_t seed_data[sizeof(uint32_t)] = {0}; - for(size_t i = 0; i < sizeof(uint32_t); i++) { - seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; - } - - flipper_format_write_hex(subghz->txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); - } - - subghz_transmitter_free(subghz->txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt) { - SubGhz* subghz = context; - - bool res = false; - - subghz->txrx->transmitter = subghz_transmitter_alloc_init( - subghz->txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - - if(subghz->txrx->transmitter && - subghz_protocol_alutech_at_4n_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - subghz->txrx->preset)) { - res = true; - } - - subghz_transmitter_free(subghz->txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt) { - SubGhz* subghz = context; - - bool res = false; - - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); - subghz_preset_init(subghz, preset_name, frequency, NULL, 0); - - if(subghz->txrx->transmitter && - subghz_protocol_somfy_telis_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - subghz->txrx->preset)) { - res = true; - } - - subghz_transmitter_free(subghz->txrx->transmitter); - - return res; -} - -bool subghz_gen_secplus_v2_protocol( - SubGhz* subghz, - const char* name_preset, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint32_t cnt) { - furi_assert(subghz); - - bool ret = false; - subghz->txrx->transmitter = - subghz_transmitter_alloc_init(subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_preset_init(subghz, name_preset, frequency, NULL, 0); - if(subghz->txrx->transmitter) { - subghz_protocol_secplus_v2_create_data( - subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter), - subghz->txrx->fff_data, - serial, - btn, - cnt, - subghz->txrx->preset); - ret = true; - } - return ret; -} - -bool subghz_gen_secplus_v1_protocol(SubGhz* subghz, const char* name_preset, uint32_t frequency) { - furi_assert(subghz); - - bool ret = false; - uint32_t serial = subghz_random_serial(); - while(!subghz_protocol_secplus_v1_check_fixed(serial)) { - serial = subghz_random_serial(); - } - if(subghz_gen_data_protocol( - subghz, - name_preset, - frequency, - SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, - (uint64_t)serial << 32 | 0xE6000000, - 42)) { - ret = true; - } - return ret; -} \ No newline at end of file diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 73b5221cb..965538d81 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -43,6 +43,8 @@ #include "helpers/subghz_threshold_rssi.h" +#include "subghz_radio.h" + #define SUBGHZ_MAX_LEN_NAME 64 #define SUBGHZ_EXT_PRESET_NAME true @@ -58,40 +60,6 @@ typedef enum { SubGhzDecodeRawStateLoaded, } SubGhzDecodeRawState; -struct SubGhzTxRx { - SubGhzWorker* worker; - - SubGhzEnvironment* environment; - SubGhzReceiver* receiver; - SubGhzTransmitter* transmitter; - SubGhzProtocolFlag filter; - SubGhzProtocolDecoderBase* decoder_result; - FlipperFormat* fff_data; - SecureData* secure_data; - - SubGhzRadioPreset* preset; - SubGhzHistory* history; - uint16_t idx_menu_chosen; - - uint8_t hopper_timeout; - uint8_t hopper_idx_frequency; - - SubGhzHopperState hopper_state; - SubGhzSpeakerState speaker_state; - - SubGhzTxRxState txrx_state; - - bool ignore_starline; - bool ignore_auto_alarms; - bool ignore_magellan; - - SubGhzLoadTypeFile load_type_file; - - bool debug_pin_state; -}; - -typedef struct SubGhzTxRx SubGhzTxRx; - struct SubGhz { Gui* gui; NotificationApp* notifications; @@ -124,7 +92,6 @@ struct SubGhz { SubGhzTestStatic* subghz_test_static; SubGhzTestPacket* subghz_test_packet; #endif - SubGhzSetting* setting; SubGhzLastSettings* last_settings; FuriString* error_str; @@ -133,33 +100,29 @@ struct SubGhz { bool in_decoder_scene; bool in_decoder_scene_skip; + bool ignore_starline; + bool ignore_auto_alarms; + bool ignore_magellan; + + SecureData* secure_data; + SubGhzDecodeRawState decode_raw_state; SubGhzFileEncoderWorker* decode_raw_file_worker_encoder; SubGhzThresholdRssi* threshold_rssi; SubGhzRxKeyState rx_key_state; + uint16_t idx_menu_chosen; + SubGhzLoadTypeFile load_type_file; + void* rpc_ctx; }; -void subghz_preset_init( - void* context, - const char* preset_name, - uint32_t frequency, - uint8_t* preset_data, - size_t preset_data_size); -bool subghz_set_preset(SubGhz* subghz, const char* preset); void subghz_get_frequency_modulation(SubGhz* subghz, FuriString* frequency, FuriString* modulation); -void subghz_begin(SubGhz* subghz, uint8_t* preset_data); -uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency); -void subghz_rx_end(SubGhz* subghz); -void subghz_sleep(SubGhz* subghz); void subghz_blink_start(SubGhz* instance); void subghz_blink_stop(SubGhz* instance); -bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format); -void subghz_tx_stop(SubGhz* subghz); void subghz_dialog_message_show_only_rx(SubGhz* subghz); bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog); bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len); @@ -167,27 +130,15 @@ bool subghz_save_protocol_to_file( SubGhz* subghz, FlipperFormat* flipper_format, const char* dev_file_name); + +void subghz_save_to_file(void* context); + bool subghz_load_protocol_from_file(SubGhz* subghz); bool subghz_rename_file(SubGhz* subghz); bool subghz_file_available(SubGhz* subghz); bool subghz_delete_file(SubGhz* subghz); void subghz_file_name_clear(SubGhz* subghz); bool subghz_path_is_file(FuriString* path); -uint32_t subghz_random_serial(void); -void subghz_hopper_update(SubGhz* subghz); -void subghz_speaker_on(SubGhz* subghz); -void subghz_speaker_off(SubGhz* subghz); -void subghz_speaker_mute(SubGhz* subghz); -void subghz_speaker_unmute(SubGhz* subghz); -void subghz_speaker_set_state(SubGhz* subghz, SubGhzSpeakerState state); -SubGhzSpeakerState subghz_speaker_get_state(SubGhz* subghz); - -void subghz_txrx_stop(SubGhz* subghz); -SubGhzTxRxState subghz_txrx_get_state(SubGhz* subghz); -SubGhzHopperState subghz_hopper_get_state(SubGhz* subghz); -void subghz_hopper_set_state(SubGhz* subghz, SubGhzHopperState state); -void subghz_hopper_remove_pause(SubGhz* subghz); -void subghz_subghz_hopper_set_pause(SubGhz* subghz); void subghz_lock(SubGhz* subghz); void subghz_unlock(SubGhz* subghz); @@ -198,87 +149,5 @@ SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state); SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz); -//#############Create new Key############## -bool subghz_gen_data_protocol( - void* context, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit); - -bool subghz_gen_data_protocol_and_te( - SubGhz* subghz, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit, - uint32_t te); - -bool subghz_scene_set_type_submenu_gen_data_keeloq( - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - const char* manufacture_name); - -bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name); - -bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - bool nice_one); - -bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name); - -bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt); - -bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt); - -bool subghz_gen_secplus_v2_protocol( - SubGhz* subghz, - const char* name_preset, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint32_t cnt); - -bool subghz_gen_secplus_v1_protocol(SubGhz* subghz, const char* name_preset, uint32_t frequency); - extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx_locked; diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c new file mode 100644 index 000000000..d132eb9c1 --- /dev/null +++ b/applications/main/subghz/subghz_radio.c @@ -0,0 +1,723 @@ +#include "subghz_radio.h" + +#define TAG "SubGhz" + +void subghz_preset_init( + SubGhzTxRx* txrx, + const char* preset_name, + uint32_t frequency, + uint8_t* preset_data, + size_t preset_data_size) { + furi_assert(txrx); + furi_string_set(txrx->preset->name, preset_name); + txrx->preset->frequency = frequency; + txrx->preset->data = preset_data; + txrx->preset->data_size = preset_data_size; +} + +bool subghz_set_preset(SubGhzTxRx* txrx, const char* preset) { + if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { + furi_string_set(txrx->preset->name, "AM270"); + } else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) { + furi_string_set(txrx->preset->name, "AM650"); + } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) { + furi_string_set(txrx->preset->name, "FM238"); + } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) { + furi_string_set(txrx->preset->name, "FM476"); + } else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) { + furi_string_set(txrx->preset->name, "CUSTOM"); + } else { + FURI_LOG_E(TAG, "Unknown preset"); + return false; + } + return true; +} + +void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) { + furi_assert(txrx); + furi_hal_subghz_reset(); + furi_hal_subghz_idle(); + furi_hal_subghz_load_custom_preset(preset_data); + furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow); + txrx->txrx_state = SubGhzTxRxStateIDLE; +} + +uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency) { + furi_assert(txrx); + if(!furi_hal_subghz_is_frequency_valid(frequency)) { + furi_crash("SubGhz: Incorrect RX frequency."); + } + furi_assert(txrx->txrx_state != SubGhzTxRxStateRx && txrx->txrx_state != SubGhzTxRxStateSleep); + + furi_hal_subghz_idle(); + uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency); + furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow); + furi_hal_subghz_flush_rx(); + subghz_speaker_on(txrx); + furi_hal_subghz_rx(); + + furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, txrx->worker); + subghz_worker_start(txrx->worker); + txrx->txrx_state = SubGhzTxRxStateRx; + return value; +} + +static void subghz_idle(SubGhzTxRx* txrx) { + furi_assert(txrx); + furi_assert(txrx->txrx_state != SubGhzTxRxStateSleep); + furi_hal_subghz_idle(); + subghz_speaker_off(txrx); + txrx->txrx_state = SubGhzTxRxStateIDLE; +} + +static void subghz_rx_end(SubGhzTxRx* txrx) { + furi_assert(txrx); + furi_assert(txrx->txrx_state == SubGhzTxRxStateRx); + + if(subghz_worker_is_running(txrx->worker)) { + subghz_worker_stop(txrx->worker); + furi_hal_subghz_stop_async_rx(); + } + furi_hal_subghz_idle(); + subghz_speaker_off(txrx); + txrx->txrx_state = SubGhzTxRxStateIDLE; +} + +// static void subghz_sleep(SubGhzTxRx* txrx) { +// furi_assert(txrx); +// furi_hal_subghz_sleep(); +// txrx->txrx_state = SubGhzTxRxStateSleep; +// } + +static bool subghz_tx(SubGhzTxRx* txrx, uint32_t frequency) { + furi_assert(txrx); + if(!furi_hal_subghz_is_frequency_valid(frequency)) { + furi_crash("SubGhz: Incorrect TX frequency."); + } + furi_assert(txrx->txrx_state != SubGhzTxRxStateSleep); + furi_hal_subghz_idle(); + furi_hal_subghz_set_frequency_and_path(frequency); + furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false); + furi_hal_gpio_init( + furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); + bool ret = furi_hal_subghz_tx(); + if(ret) { + subghz_speaker_on(txrx); + txrx->txrx_state = SubGhzTxRxStateTx; + } + return ret; +} + +bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) { + furi_assert(txrx); + + bool ret = false; + FuriString* temp_str = furi_string_alloc(); + uint32_t repeat = 200; + do { + if(!flipper_format_rewind(flipper_format)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + if(!flipper_format_read_string(flipper_format, "Protocol", temp_str)) { + FURI_LOG_E(TAG, "Missing Protocol"); + break; + } + if(!flipper_format_insert_or_update_uint32(flipper_format, "Repeat", &repeat, 1)) { + FURI_LOG_E(TAG, "Unable Repeat"); + break; + } + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, furi_string_get_cstr(temp_str)); + + if(txrx->transmitter) { + if(subghz_transmitter_deserialize(txrx->transmitter, flipper_format) == + SubGhzProtocolStatusOk) { + if(strcmp(furi_string_get_cstr(txrx->preset->name), "") != 0) { + subghz_begin( + txrx, + subghz_setting_get_preset_data_by_name( + txrx->setting, furi_string_get_cstr(txrx->preset->name))); + } else { + FURI_LOG_E( + TAG, + "Unknown name preset \" %s \"", + furi_string_get_cstr(txrx->preset->name)); + subghz_begin( + txrx, subghz_setting_get_preset_data_by_name(txrx->setting, "AM650")); + } + if(txrx->preset->frequency) { + ret = subghz_tx(txrx, txrx->preset->frequency); + } else { + ret = subghz_tx(txrx, 433920000); + } + if(ret) { + //Start TX + furi_hal_subghz_start_async_tx(subghz_transmitter_yield, txrx->transmitter); + } else { + //Todo: Show error + //subghz_dialog_message_show_only_rx(subghz); + } + } else { + //Todo: Show error + // dialog_message_show_storage_error( + // dialogs, "Error in protocol\nparameters\ndescription"); + } + } + if(!ret) { + subghz_transmitter_free(txrx->transmitter); + if(txrx->txrx_state != SubGhzTxRxStateSleep) { + subghz_idle(txrx); + } + } + + } while(false); + furi_string_free(temp_str); + return ret; +} + +void subghz_txrx_need_save_callback_set( + SubGhzTxRx* txrx, + SubGhzTxRxNeedSaveCallback callback, + void* context) { + furi_assert(txrx); + txrx->need_save_callback = callback; + txrx->need_save_context = context; +} + +static void subghz_tx_stop(SubGhzTxRx* txrx) { + furi_assert(txrx); + furi_assert(txrx->txrx_state == SubGhzTxRxStateTx); + //Stop TX + furi_hal_subghz_stop_async_tx(); + subghz_transmitter_stop(txrx->transmitter); + subghz_transmitter_free(txrx->transmitter); + + //if protocol dynamic then we save the last upload + if(txrx->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) { + if(txrx->need_save_callback) { + txrx->need_save_callback(txrx->need_save_context); + } + } + subghz_idle(txrx); + subghz_speaker_off(txrx); + //Todo: Show message + // notification_message(notifications, &sequence_reset_red); +} + +FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->fff_data; +} + +SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->setting; +} + +void subghz_txrx_stop(SubGhzTxRx* txrx) { + furi_assert(txrx); + + switch(txrx->txrx_state) { + case SubGhzTxRxStateTx: + subghz_tx_stop(txrx); + subghz_speaker_unmute(txrx); + //subghz_sleep(txrx); + break; + case SubGhzTxRxStateRx: + subghz_rx_end(txrx); + subghz_speaker_mute(txrx); + //subghz_sleep(txrx); + break; + + default: + break; + } +} + +SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->txrx_state; +} + +void subghz_hopper_update(SubGhzTxRx* txrx) { + furi_assert(txrx); + + switch(txrx->hopper_state) { + case SubGhzHopperStateOFF: + case SubGhzHopperStatePause: + return; + case SubGhzHopperStateRSSITimeOut: + if(txrx->hopper_timeout != 0) { + txrx->hopper_timeout--; + return; + } + break; + default: + break; + } + float rssi = -127.0f; + if(txrx->hopper_state != SubGhzHopperStateRSSITimeOut) { + // See RSSI Calculation timings in CC1101 17.3 RSSI + rssi = furi_hal_subghz_get_rssi(); + + // Stay if RSSI is high enough + if(rssi > -90.0f) { + txrx->hopper_timeout = 10; + txrx->hopper_state = SubGhzHopperStateRSSITimeOut; + return; + } + } else { + txrx->hopper_state = SubGhzHopperStateRunning; + } + // Select next frequency + if(txrx->hopper_idx_frequency < subghz_setting_get_hopper_frequency_count(txrx->setting) - 1) { + txrx->hopper_idx_frequency++; + } else { + txrx->hopper_idx_frequency = 0; + } + + if(txrx->txrx_state == SubGhzTxRxStateRx) { + subghz_rx_end(txrx); + }; + if(txrx->txrx_state == SubGhzTxRxStateIDLE) { + subghz_receiver_reset(txrx->receiver); + txrx->preset->frequency = + subghz_setting_get_hopper_frequency(txrx->setting, txrx->hopper_idx_frequency); + subghz_rx(txrx, txrx->preset->frequency); + } +} + +SubGhzHopperState subghz_hopper_get_state(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->hopper_state; +} + +void subghz_hopper_set_state(SubGhzTxRx* txrx, SubGhzHopperState state) { + furi_assert(txrx); + txrx->hopper_state = state; +} + +void subghz_hopper_remove_pause(SubGhzTxRx* txrx) { + furi_assert(txrx); + if(txrx->hopper_state == SubGhzHopperStatePause) { + txrx->hopper_state = SubGhzHopperStateRunning; + } +} + +void subghz_subghz_hopper_set_pause(SubGhzTxRx* txrx) { + furi_assert(txrx); + if(txrx->hopper_state == SubGhzHopperStateRunning) { + txrx->hopper_state = SubGhzHopperStatePause; + } +} + +void subghz_speaker_on(SubGhzTxRx* txrx) { + furi_assert(txrx); + if(txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); + } + + if(txrx->speaker_state == SubGhzSpeakerStateEnable) { + if(furi_hal_speaker_acquire(30)) { + if(!txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(&gpio_speaker); + } + } else { + txrx->speaker_state = SubGhzSpeakerStateDisable; + } + } +} + +void subghz_speaker_off(SubGhzTxRx* txrx) { + furi_assert(txrx); + if(txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(NULL); + } + if(txrx->speaker_state != SubGhzSpeakerStateDisable) { + if(furi_hal_speaker_is_mine()) { + if(!txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(NULL); + } + furi_hal_speaker_release(); + if(txrx->speaker_state == SubGhzSpeakerStateShutdown) + txrx->speaker_state = SubGhzSpeakerStateDisable; + } + } +} + +void subghz_speaker_mute(SubGhzTxRx* txrx) { + furi_assert(txrx); + if(txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(NULL); + } + if(txrx->speaker_state == SubGhzSpeakerStateEnable) { + if(furi_hal_speaker_is_mine()) { + if(!txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(NULL); + } + } + } +} + +void subghz_speaker_unmute(SubGhzTxRx* txrx) { + furi_assert(txrx); + if(txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); + } + if(txrx->speaker_state == SubGhzSpeakerStateEnable) { + if(furi_hal_speaker_is_mine()) { + if(!txrx->debug_pin_state) { + furi_hal_subghz_set_async_mirror_pin(&gpio_speaker); + } + } + } +} + +void subghz_speaker_set_state(SubGhzTxRx* txrx, SubGhzSpeakerState state) { + furi_assert(txrx); + txrx->speaker_state = state; +} + +SubGhzSpeakerState subghz_speaker_get_state(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->speaker_state; +} + +//#############Create new Key############## +#include +#include +#include +#include +#include + +#include +#include +#include + +bool subghz_gen_data_protocol( + void* context, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit) { + furi_assert(context); + SubGhzTxRx* txrx = context; + + bool res = false; + + subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + txrx->decoder_result = + subghz_receiver_search_decoder_base_by_name(txrx->receiver, protocol_name); + + if(txrx->decoder_result == NULL) { + //TODO: Error + // furi_string_set(error_str, "Protocol not\nfound!"); + // scene_manager_next_scene(scene_manager, SubGhzSceneShowErrorSub); + return false; + } + + do { + Stream* fff_data_stream = flipper_format_get_raw_stream(txrx->fff_data); + stream_clean(fff_data_stream); + if(subghz_protocol_decoder_base_serialize( + txrx->decoder_result, txrx->fff_data, txrx->preset) != SubGhzProtocolStatusOk) { + FURI_LOG_E(TAG, "Unable to serialize"); + break; + } + if(!flipper_format_update_uint32(txrx->fff_data, "Bit", &bit, 1)) { + FURI_LOG_E(TAG, "Unable to update Bit"); + break; + } + + uint8_t key_data[sizeof(uint64_t)] = {0}; + for(size_t i = 0; i < sizeof(uint64_t); i++) { + key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; + } + if(!flipper_format_update_hex(txrx->fff_data, "Key", key_data, sizeof(uint64_t))) { + FURI_LOG_E(TAG, "Unable to update Key"); + break; + } + res = true; + } while(false); + return res; +} + +bool subghz_gen_data_protocol_and_te( + SubGhzTxRx* txrx, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit, + uint32_t te) { + furi_assert(txrx); + bool ret = false; + if(subghz_gen_data_protocol(txrx, preset_name, frequency, protocol_name, key, bit)) { + if(!flipper_format_update_uint32(txrx->fff_data, "TE", (uint32_t*)&te, 1)) { + FURI_LOG_E(TAG, "Unable to update Te"); + } else { + ret = true; + } + } + return ret; +} + +bool subghz_scene_set_type_submenu_gen_data_keeloq( //TODO rename + SubGhzTxRx* txrx, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + const char* manufacture_name) { + furi_assert(txrx); + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); + subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_keeloq_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + manufacture_name, + txrx->preset)) { + flipper_format_write_string_cstr(txrx->fff_data, "Manufacture", manufacture_name); + res = true; + } + subghz_transmitter_free(txrx->transmitter); + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); + subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_keeloq_bft_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + seed, + manufacture_name, + txrx->preset)) { + res = true; + } + + if(res) { + uint8_t seed_data[sizeof(uint32_t)] = {0}; + for(size_t i = 0; i < sizeof(uint32_t); i++) { + seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; + } + + flipper_format_write_hex(txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); + + flipper_format_write_string_cstr(txrx->fff_data, "Manufacture", "BFT"); + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + bool nice_one) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); + subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_nice_flor_s_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + txrx->preset, + nice_one)) { + res = true; + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME); + subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_faac_slh_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + seed, + manufacture_name, + txrx->preset)) { + res = true; + } + + if(res) { + uint8_t seed_data[sizeof(uint32_t)] = {0}; + for(size_t i = 0; i < sizeof(uint32_t); i++) { + seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; + } + + flipper_format_write_hex(txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); + subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_alutech_at_4n_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + txrx->preset)) { + res = true; + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); + subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_somfy_telis_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + txrx->preset)) { + res = true; + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_gen_secplus_v2_protocol( + SubGhzTxRx* txrx, + const char* name_preset, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint32_t cnt) { + furi_assert(txrx); + + bool ret = false; + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); + subghz_preset_init(txrx, name_preset, frequency, NULL, 0); + if(txrx->transmitter) { + subghz_protocol_secplus_v2_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + txrx->preset); + ret = true; + } + return ret; +} + +bool subghz_gen_secplus_v1_protocol(SubGhzTxRx* txrx, const char* name_preset, uint32_t frequency) { + furi_assert(txrx); + + bool ret = false; + uint32_t serial = (uint32_t)rand(); + while(!subghz_protocol_secplus_v1_check_fixed(serial)) { + serial = (uint32_t)rand(); + } + if(subghz_gen_data_protocol( + txrx, + name_preset, + frequency, + SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, + (uint64_t)serial << 32 | 0xE6000000, + 42)) { + ret = true; + } + return ret; +} \ No newline at end of file diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h new file mode 100644 index 000000000..d0e9f5c87 --- /dev/null +++ b/applications/main/subghz/subghz_radio.h @@ -0,0 +1,160 @@ +#pragma once +//#include "subghz_i.h" +#include "helpers/subghz_types.h" +#include +#include +#include +#include + +#include "subghz_history.h" + +typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); + +struct SubGhzTxRx { + SubGhzWorker* worker; + + SubGhzEnvironment* environment; + SubGhzReceiver* receiver; + SubGhzTransmitter* transmitter; + SubGhzProtocolFlag filter; + SubGhzProtocolDecoderBase* decoder_result; + FlipperFormat* fff_data; + + SubGhzRadioPreset* preset; + SubGhzHistory* history; + SubGhzSetting* setting; + + uint8_t hopper_timeout; + uint8_t hopper_idx_frequency; + SubGhzHopperState hopper_state; + + SubGhzTxRxState txrx_state; + + SubGhzSpeakerState speaker_state; + + SubGhzTxRxNeedSaveCallback need_save_callback; + void* need_save_context; + + bool debug_pin_state; +}; + +typedef struct SubGhzTxRx SubGhzTxRx; + +void subghz_preset_init( + SubGhzTxRx* txrx, + const char* preset_name, + uint32_t frequency, + uint8_t* preset_data, + size_t preset_data_size); + +bool subghz_set_preset(SubGhzTxRx* txrx, const char* preset); +void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data); +uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency); +bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format); +//void subghz_rx_end(SubGhzTxRx* txrx); //depricated +//void subghz_sleep(SubGhzTxRx* txrx); + +void subghz_txrx_stop(SubGhzTxRx* txrx); +SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* txrx); + +void subghz_hopper_update(SubGhzTxRx* txrx); +SubGhzHopperState subghz_hopper_get_state(SubGhzTxRx* txrx); +void subghz_hopper_set_state(SubGhzTxRx* txrx, SubGhzHopperState state); +void subghz_hopper_remove_pause(SubGhzTxRx* txrx); +void subghz_subghz_hopper_set_pause(SubGhzTxRx* txrx); + +void subghz_speaker_on(SubGhzTxRx* txrx); +void subghz_speaker_off(SubGhzTxRx* txrx); +void subghz_speaker_mute(SubGhzTxRx* txrx); +void subghz_speaker_unmute(SubGhzTxRx* txrx); +void subghz_speaker_set_state(SubGhzTxRx* txrx, SubGhzSpeakerState state); +SubGhzSpeakerState subghz_speaker_get_state(SubGhzTxRx* txrx); + +void subghz_txrx_need_save_callback_set( + SubGhzTxRx* txrx, + SubGhzTxRxNeedSaveCallback callback, + void* context); +FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* txrx); +SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* txrx); + +//#############Create new Key############## +bool subghz_gen_data_protocol( + void* context, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit); + +bool subghz_gen_data_protocol_and_te( + SubGhzTxRx* txrx, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit, + uint32_t te); + +bool subghz_scene_set_type_submenu_gen_data_keeloq( + SubGhzTxRx* txrx, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + bool nice_one); + +bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt); + +bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt); + +bool subghz_gen_secplus_v2_protocol( + SubGhzTxRx* txrx, + const char* name_preset, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint32_t cnt); + +bool subghz_gen_secplus_v1_protocol(SubGhzTxRx* txrx, const char* name_preset, uint32_t frequency); \ No newline at end of file From f71900694b91065b63ccada55d4ac58edf82d275 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 13:34:54 +0300 Subject: [PATCH 10/36] SubGhz: refactoring --- .../subghz/scenes/subghz_scene_decode_raw.c | 2 +- .../main/subghz/scenes/subghz_scene_delete.c | 4 +- .../subghz/scenes/subghz_scene_delete_raw.c | 2 +- .../subghz/scenes/subghz_scene_read_raw.c | 23 ++++---- .../subghz/scenes/subghz_scene_receiver.c | 47 +++++++-------- .../scenes/subghz_scene_receiver_info.c | 13 ++--- .../subghz/scenes/subghz_scene_transmitter.c | 9 +-- applications/main/subghz/subghz_i.c | 38 ++++--------- applications/main/subghz/subghz_i.h | 2 - applications/main/subghz/subghz_radio.c | 57 ++++++++++++++++--- applications/main/subghz/subghz_radio.h | 9 ++- 11 files changed, 113 insertions(+), 93 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 955e0df89..6075cd655 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -29,7 +29,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); subghz_view_receiver_add_data_statusbar( subghz->subghz_receiver, diff --git a/applications/main/subghz/scenes/subghz_scene_delete.c b/applications/main/subghz/scenes/subghz_scene_delete.c index 4cad14bbf..cf0bdefb1 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete.c +++ b/applications/main/subghz/scenes/subghz_scene_delete.c @@ -15,7 +15,7 @@ void subghz_scene_delete_on_enter(void* context) { FuriString* modulation_str = furi_string_alloc(); FuriString* text = furi_string_alloc(); - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 78, @@ -33,7 +33,7 @@ void subghz_scene_delete_on_enter(void* context) { AlignTop, FontSecondary, furi_string_get_cstr(modulation_str)); - subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, text); + subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), text); widget_add_string_multiline_element( subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(text)); diff --git a/applications/main/subghz/scenes/subghz_scene_delete_raw.c b/applications/main/subghz/scenes/subghz_scene_delete_raw.c index ee7983dfd..ed960d666 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_delete_raw.c @@ -30,7 +30,7 @@ void subghz_scene_delete_raw_on_enter(void* context) { widget_add_string_element( subghz->widget, 38, 25, AlignLeft, AlignTop, FontSecondary, "RAW signal"); - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 35, diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 9abc24523..7879682a2 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -41,10 +41,10 @@ static void subghz_scene_read_raw_update_statusbar(void* context) { FuriString* modulation_str = furi_string_alloc(); #ifdef SUBGHZ_EXT_PRESET_NAME - subghz_get_frequency_modulation(subghz, frequency_str, NULL); - furi_string_printf(modulation_str, "%s", furi_string_get_cstr(subghz->txrx->preset->name)); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, true); + //furi_string_printf(modulation_str, "%s", furi_string_get_cstr(subghz->txrx->preset->name)); #else - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); #endif subghz_read_raw_add_data_statusbar( subghz->subghz_read_raw, @@ -113,9 +113,7 @@ void subghz_scene_read_raw_on_enter(void* context) { //set callback view raw subghz_read_raw_set_callback(subghz->subghz_read_raw, subghz_scene_read_raw_callback, subghz); - subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name( - subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME); - furi_assert(subghz->txrx->decoder_result); + furi_check(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, SUBGHZ_PROTOCOL_RAW_NAME)); //set filter RAW feed subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_RAW); @@ -131,7 +129,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz_txrx_stop(subghz->txrx); //Stop save file subghz_protocol_raw_save_to_file_stop( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); + (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx)); subghz->state_notifications = SubGhzNotificationStateIDLE; //needed save? if((subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) || @@ -255,10 +253,10 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWIDLE: subghz_txrx_stop(subghz->txrx); size_t spl_count = subghz_protocol_raw_get_sample_write( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); + (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx)); subghz_protocol_raw_save_to_file_stop( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); + (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx)); FuriString* temp_str = furi_string_alloc(); furi_string_printf( @@ -284,7 +282,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { if(subghz_protocol_raw_save_to_file_init( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, + (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx), RAW_FILE_NAME, subghz->txrx->preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); @@ -333,14 +331,15 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz_read_raw_update_sample_write( subghz->subghz_read_raw, subghz_protocol_raw_get_sample_write( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result)); + (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx))); SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(subghz->threshold_rssi); subghz_read_raw_add_data_rssi( subghz->subghz_read_raw, ret_rssi.rssi, ret_rssi.is_above); subghz_protocol_raw_save_to_file_pause( - (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, !ret_rssi.is_above); + (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx), + !ret_rssi.is_above); break; case SubGhzNotificationStateTx: diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 766810a04..bd0b971b4 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -46,17 +46,20 @@ static void subghz_scene_receiver_update_statusbar(void* context) { #ifdef SUBGHZ_EXT_PRESET_NAME if(subghz_history_get_last_index(subghz->txrx->history) > 0) { - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); } else { - subghz_get_frequency_modulation(subghz, frequency_str, NULL); + FuriString* temp_str = furi_string_alloc(); + + subghz_get_frequency_modulation(subghz->txrx, frequency_str, temp_str, true); furi_string_printf( modulation_str, "%s Mod: %s", furi_hal_subghz_get_radio_type() ? "Ext" : "Int", - furi_string_get_cstr(subghz->txrx->preset->name)); + furi_string_get_cstr(temp_str)); + furi_string_free(temp_str); } #else - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); #endif subghz_view_receiver_add_data_statusbar( @@ -155,37 +158,26 @@ void subghz_scene_receiver_on_enter(void* context) { // TODO: Replace with proper solution based on protocol flags, remove kostily and velosipedy from here // Needs to be done after subghz refactoring merge!!! if(subghz->ignore_starline == true) { - SubGhzProtocolDecoderBase* protocoldecoderbase = NULL; - protocoldecoderbase = - subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "Star Line"); - if(protocoldecoderbase) { + if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Star Line")) { subghz_protocol_decoder_base_set_decoder_callback( - protocoldecoderbase, NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); } } if(subghz->ignore_auto_alarms == true) { - SubGhzProtocolDecoderBase* protocoldecoderbase = NULL; - protocoldecoderbase = - subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "KIA Seed"); - if(protocoldecoderbase) { + if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "KIA Seed")) { subghz_protocol_decoder_base_set_decoder_callback( - protocoldecoderbase, NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); } - protocoldecoderbase = NULL; - protocoldecoderbase = - subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "Scher-Khan"); - if(protocoldecoderbase) { + + if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Scher-Khan")) { subghz_protocol_decoder_base_set_decoder_callback( - protocoldecoderbase, NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); } } if(subghz->ignore_magellan == true) { - SubGhzProtocolDecoderBase* protocoldecoderbase = NULL; - protocoldecoderbase = - subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "Magellan"); - if(protocoldecoderbase) { + if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Magellan")) { subghz_protocol_decoder_base_set_decoder_callback( - protocoldecoderbase, NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); } } @@ -199,9 +191,8 @@ void subghz_scene_receiver_on_enter(void* context) { subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen); //to use a universal decoder, we are looking for a link to it - subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name( - subghz->txrx->receiver, SUBGHZ_PROTOCOL_BIN_RAW_NAME); - furi_assert(subghz->txrx->decoder_result); + furi_check( + subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, SUBGHZ_PROTOCOL_BIN_RAW_NAME)); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReceiver); } @@ -277,7 +268,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { subghz_receiver_rssi(subghz->subghz_receiver, ret_rssi.rssi); subghz_protocol_decoder_bin_raw_data_input_rssi( - (SubGhzProtocolDecoderBinRAW*)subghz->txrx->decoder_result, ret_rssi.rssi); + (SubGhzProtocolDecoderBinRAW*)subghz_txrx_get_decoder(subghz->txrx), ret_rssi.rssi); switch(subghz->state_notifications) { case SubGhzNotificationStateRx: diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 3c53ac021..ed9f06770 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -23,14 +23,13 @@ void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, v static bool subghz_scene_receiver_info_update_parser(void* context) { SubGhz* subghz = context; - subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name( - subghz->txrx->receiver, - subghz_history_get_protocol_name(subghz->txrx->history, subghz->idx_menu_chosen)); - if(subghz->txrx->decoder_result) { + if(subghz_txrx_load_decoder_by_name_protocol( + subghz->txrx, + subghz_history_get_protocol_name(subghz->txrx->history, subghz->idx_menu_chosen))) { //todo we are trying to deserialize without checking for errors, since it is assumed that we just received this chignal subghz_protocol_decoder_base_deserialize( - subghz->txrx->decoder_result, + subghz_txrx_get_decoder(subghz->txrx), subghz_history_get_raw_data(subghz->txrx->history, subghz->idx_menu_chosen)); SubGhzRadioPreset* preset = @@ -53,7 +52,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { FuriString* modulation_str = furi_string_alloc(); FuriString* text = furi_string_alloc(); - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 78, @@ -71,7 +70,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { AlignTop, FontSecondary, furi_string_get_cstr(modulation_str)); - subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, text); + subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), text); widget_add_string_multiline_element( subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(text)); diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 375c142d1..c75a1b6b3 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -15,7 +15,7 @@ void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) { bool subghz_scene_transmitter_update_data_show(void* context) { SubGhz* subghz = context; bool ret = false; - if(subghz->txrx->decoder_result) { + if(subghz_txrx_get_decoder(subghz->txrx)) { FuriString* key_str = furi_string_alloc(); FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); @@ -23,16 +23,17 @@ bool subghz_scene_transmitter_update_data_show(void* context) { bool show_button = false; if(subghz_protocol_decoder_base_deserialize( - subghz->txrx->decoder_result, subghz_txtx_get_fff_data(subghz->txrx)) == + subghz_txrx_get_decoder(subghz->txrx), subghz_txtx_get_fff_data(subghz->txrx)) == SubGhzProtocolStatusOk) { - subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, key_str); + subghz_protocol_decoder_base_get_string( + subghz_txrx_get_decoder(subghz->txrx), key_str); if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) { show_button = true; } - subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); + subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); subghz_view_transmitter_add_data_to_show( subghz->subghz_transmitter, furi_string_get_cstr(key_str), diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 3b9c1c695..db8bc5cf2 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -18,20 +18,6 @@ #define TAG "SubGhz" -void subghz_get_frequency_modulation(SubGhz* subghz, FuriString* frequency, FuriString* modulation) { - furi_assert(subghz); - if(frequency != NULL) { - furi_string_printf( - frequency, - "%03ld.%02ld", - subghz->txrx->preset->frequency / 1000000 % 1000, - subghz->txrx->preset->frequency / 10000 % 100); - } - if(modulation != NULL) { - furi_string_printf(modulation, "%.2s", furi_string_get_cstr(subghz->txrx->preset->name)); - } -} - void subghz_dialog_message_show_only_rx(SubGhz* subghz) { DialogsApp* dialogs = subghz->dialogs; DialogMessage* message = dialog_message_alloc(); @@ -97,7 +83,6 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { load_key_state = SubGhzLoadKeyStateOnlyRx; break; } - //subghz->txrx->preset->frequency = temp_data32; //Load preset if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) { @@ -105,31 +90,31 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { break; } - if(!subghz_set_preset(subghz->txrx, furi_string_get_cstr(temp_str))) { + furi_string_set_str( + temp_str, subghz_set_preset(subghz->txrx, furi_string_get_cstr(temp_str))); + if(temp_str == NULL) { break; } - if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) { + if(!strcmp(furi_string_get_cstr(temp_str), "CUSTOM")) { //Todo add Custom_preset_module //delete preset if it already exists subghz_setting_delete_custom_preset( - subghz_txrx_get_setting(subghz->txrx), - furi_string_get_cstr(subghz->txrx->preset->name)); + subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(temp_str)); //load custom preset from file if(!subghz_setting_load_custom_preset( subghz_txrx_get_setting(subghz->txrx), - furi_string_get_cstr(subghz->txrx->preset->name), + furi_string_get_cstr(temp_str), fff_data_file)) { FURI_LOG_E(TAG, "Missing Custom preset"); break; } } size_t preset_index = subghz_setting_get_inx_preset_by_name( - subghz_txrx_get_setting(subghz->txrx), - furi_string_get_cstr(subghz->txrx->preset->name)); + subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(temp_str)); subghz_preset_init( subghz->txrx, - furi_string_get_cstr(subghz->txrx->preset->name), + furi_string_get_cstr(temp_str), temp_data32, subghz_setting_get_preset_data(subghz_txrx_get_setting(subghz->txrx), preset_index), subghz_setting_get_preset_data_size( @@ -151,11 +136,10 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { flipper_format_get_raw_stream(subghz_txtx_get_fff_data(subghz->txrx))); } - subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name( - subghz->txrx->receiver, furi_string_get_cstr(temp_str)); - if(subghz->txrx->decoder_result) { + if(subghz_txrx_load_decoder_by_name_protocol( + subghz->txrx, furi_string_get_cstr(temp_str))) { SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize( - subghz->txrx->decoder_result, subghz_txtx_get_fff_data(subghz->txrx)); + subghz_txrx_get_decoder(subghz->txrx), subghz_txtx_get_fff_data(subghz->txrx)); if(status != SubGhzProtocolStatusOk) { load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr; break; diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 965538d81..58d715d8b 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -118,8 +118,6 @@ struct SubGhz { void* rpc_ctx; }; -void subghz_get_frequency_modulation(SubGhz* subghz, FuriString* frequency, FuriString* modulation); - void subghz_blink_start(SubGhz* instance); void subghz_blink_stop(SubGhz* instance); diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index d132eb9c1..4a45479b6 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -15,22 +15,45 @@ void subghz_preset_init( txrx->preset->data_size = preset_data_size; } -bool subghz_set_preset(SubGhzTxRx* txrx, const char* preset) { +void subghz_get_frequency_modulation( + SubGhzTxRx* txrx, + FuriString* frequency, + FuriString* modulation, + bool long_name) { + furi_assert(txrx); + if(frequency != NULL) { + furi_string_printf( + frequency, + "%03ld.%02ld", + txrx->preset->frequency / 1000000 % 1000, + txrx->preset->frequency / 10000 % 100); + } + if(modulation != NULL) { + if(long_name) { + furi_string_printf(modulation, "%s", furi_string_get_cstr(txrx->preset->name)); + } else { + furi_string_printf(modulation, "%.2s", furi_string_get_cstr(txrx->preset->name)); + } + } +} + +const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset) { + UNUSED(txrx); + const char* preset_name = NULL; if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { - furi_string_set(txrx->preset->name, "AM270"); + preset_name = "AM270"; } else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) { - furi_string_set(txrx->preset->name, "AM650"); + preset_name = "AM650"; } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) { - furi_string_set(txrx->preset->name, "FM238"); + preset_name = "FM238"; } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) { - furi_string_set(txrx->preset->name, "FM476"); + preset_name = "FM476"; } else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) { - furi_string_set(txrx->preset->name, "CUSTOM"); + preset_name = "CUSTOM"; } else { FURI_LOG_E(TAG, "Unknown preset"); - return false; } - return true; + return preset_name; } void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) { @@ -385,6 +408,24 @@ SubGhzSpeakerState subghz_speaker_get_state(SubGhzTxRx* txrx) { return txrx->speaker_state; } +bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* txrx, const char* name_protocol) { + furi_assert(txrx); + furi_assert(name_protocol); + bool res = false; + txrx->decoder_result = NULL; + txrx->decoder_result = + subghz_receiver_search_decoder_base_by_name(txrx->receiver, name_protocol); + if(txrx->decoder_result) { + res = true; + } + return res; +} + +SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->decoder_result; +} + //#############Create new Key############## #include #include diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index d0e9f5c87..579f992a0 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -47,7 +47,12 @@ void subghz_preset_init( uint8_t* preset_data, size_t preset_data_size); -bool subghz_set_preset(SubGhzTxRx* txrx, const char* preset); +const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset); +void subghz_get_frequency_modulation( + SubGhzTxRx* txrx, + FuriString* frequency, + FuriString* modulation, + bool long_name); void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data); uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency); bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format); @@ -69,6 +74,8 @@ void subghz_speaker_mute(SubGhzTxRx* txrx); void subghz_speaker_unmute(SubGhzTxRx* txrx); void subghz_speaker_set_state(SubGhzTxRx* txrx, SubGhzSpeakerState state); SubGhzSpeakerState subghz_speaker_get_state(SubGhzTxRx* txrx); +bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* txrx, const char* name_protocol); +SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* txrx); void subghz_txrx_need_save_callback_set( SubGhzTxRx* txrx, From 07203f09893e24723d3f018bbb7bce32c54f284d Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 15:11:54 +0300 Subject: [PATCH 11/36] SubGhz: refactoring --- .../subghz_frequency_analyzer_worker.c | 2 +- .../subghz/scenes/subghz_scene_decode_raw.c | 23 ++--- .../subghz/scenes/subghz_scene_need_saving.c | 2 +- .../subghz/scenes/subghz_scene_read_raw.c | 19 ++-- .../subghz/scenes/subghz_scene_receiver.c | 37 ++++--- .../scenes/subghz_scene_receiver_config.c | 96 ++++++++++++------- .../scenes/subghz_scene_receiver_info.c | 25 ++--- .../subghz/scenes/subghz_scene_save_name.c | 2 +- .../subghz/scenes/subghz_scene_transmitter.c | 2 +- applications/main/subghz/subghz.c | 10 +- applications/main/subghz/subghz_i.c | 4 +- applications/main/subghz/subghz_i.h | 1 + applications/main/subghz/subghz_radio.c | 52 ++++++---- applications/main/subghz/subghz_radio.h | 14 +-- 14 files changed, 162 insertions(+), 127 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c index 34f7e8cff..6fec29565 100644 --- a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c +++ b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c @@ -278,7 +278,7 @@ SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* cont furi_thread_set_callback(instance->thread, subghz_frequency_analyzer_worker_thread); SubGhz* subghz = context; - instance->setting = subghz->txrx->setting; + instance->setting = subghz_txrx_get_setting(subghz->txrx); instance->trigger_level = subghz->last_settings->frequency_analyzer_trigger; //instance->trigger_level = SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD; return instance; diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 6075cd655..e75f6fda6 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -25,7 +25,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) { SubGhz* subghz = context; FuriString* history_stat_str = furi_string_alloc(); - if(!subghz_history_get_text_space_left(subghz->txrx->history, history_stat_str)) { + if(!subghz_history_get_text_space_left(subghz->history, history_stat_str)) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); @@ -60,21 +60,22 @@ static void subghz_scene_add_to_history_callback( SubGhz* subghz = context; FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); - uint16_t idx = subghz_history_get_item(subghz->txrx->history); + uint16_t idx = subghz_history_get_item(subghz->history); + SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); - if(subghz_history_add_to_history(subghz->txrx->history, decoder_base, subghz->txrx->preset)) { + if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) { furi_string_reset(item_name); furi_string_reset(item_time); subghz->state_notifications = SubGhzNotificationStateRxDone; - subghz_history_get_text_item_menu(subghz->txrx->history, item_name, idx); - subghz_history_get_time_item_menu(subghz->txrx->history, item_time, idx); + subghz_history_get_text_item_menu(subghz->history, item_name, idx); + subghz_history_get_time_item_menu(subghz->history, item_time, idx); subghz_view_receiver_add_item_to_menu( subghz->subghz_receiver, furi_string_get_cstr(item_name), furi_string_get_cstr(item_time), - subghz_history_get_type_protocol(subghz->txrx->history, idx)); + subghz_history_get_type_protocol(subghz->history, idx)); subghz_scene_receiver_update_statusbar(subghz); } @@ -173,7 +174,7 @@ void subghz_scene_decode_raw_on_enter(void* context) { if(subghz->decode_raw_state == SubGhzDecodeRawStateStart) { //Decode RAW to history - subghz_history_reset(subghz->txrx->history); + subghz_history_reset(subghz->history); if(subghz_scene_decode_raw_start(subghz)) { subghz->decode_raw_state = SubGhzDecodeRawStateLoading; subghz->state_notifications = SubGhzNotificationStateRx; @@ -181,16 +182,16 @@ void subghz_scene_decode_raw_on_enter(void* context) { } else { //Load history to receiver subghz_view_receiver_exit(subghz->subghz_receiver); - for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) { + for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) { furi_string_reset(item_name); furi_string_reset(item_time); - subghz_history_get_text_item_menu(subghz->txrx->history, item_name, i); - subghz_history_get_time_item_menu(subghz->txrx->history, item_time, i); + subghz_history_get_text_item_menu(subghz->history, item_name, i); + subghz_history_get_time_item_menu(subghz->history, item_time, i); subghz_view_receiver_add_item_to_menu( subghz->subghz_receiver, furi_string_get_cstr(item_name), furi_string_get_cstr(item_time), - subghz_history_get_type_protocol(subghz->txrx->history, i)); + subghz_history_get_type_protocol(subghz->history, i)); } furi_string_free(item_name); furi_string_free(item_time); diff --git a/applications/main/subghz/scenes/subghz_scene_need_saving.c b/applications/main/subghz/scenes/subghz_scene_need_saving.c index e64f75ef7..b0fc70b8b 100644 --- a/applications/main/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/main/subghz/scenes/subghz_scene_need_saving.c @@ -48,7 +48,7 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { } else if(event.event == SubGhzCustomEventSceneExit) { if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateExit) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz_preset_init( + subghz_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 7879682a2..4fed9424c 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -42,6 +42,7 @@ static void subghz_scene_read_raw_update_statusbar(void* context) { #ifdef SUBGHZ_EXT_PRESET_NAME subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, true); + //TODO if need subghz_get_preset //furi_string_printf(modulation_str, "%s", furi_string_get_cstr(subghz->txrx->preset->name)); #else subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); @@ -139,14 +140,15 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { } else { //Restore default setting if(subghz->raw_send_only) { - subghz_preset_init( + subghz_set_preset( subghz->txrx, "AM650", - subghz_setting_get_default_frequency(subghz->txrx->setting), + subghz_setting_get_default_frequency( + subghz_txrx_get_setting(subghz->txrx)), NULL, 0); } else { - subghz_preset_init( + subghz_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); } if(!scene_manager_search_and_switch_to_previous_scene( @@ -281,18 +283,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateIDLE) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { + SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); if(subghz_protocol_raw_save_to_file_init( (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx), RAW_FILE_NAME, - subghz->txrx->preset)) { + &preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); - subghz_txrx_stop(subghz->txrx); - subghz_begin( - subghz->txrx, - subghz_setting_get_preset_data_by_name( - subghz->txrx->setting, - furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); + subghz_rx_start(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index bd0b971b4..72083fdeb 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -40,12 +40,12 @@ const NotificationSequence subghz_sequence_rx_locked = { static void subghz_scene_receiver_update_statusbar(void* context) { SubGhz* subghz = context; FuriString* history_stat_str = furi_string_alloc(); - if(!subghz_history_get_text_space_left(subghz->txrx->history, history_stat_str)) { + if(!subghz_history_get_text_space_left(subghz->history, history_stat_str)) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); #ifdef SUBGHZ_EXT_PRESET_NAME - if(subghz_history_get_last_index(subghz->txrx->history) > 0) { + if(subghz_history_get_last_index(subghz->history) > 0) { subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); } else { FuriString* temp_str = furi_string_alloc(); @@ -94,21 +94,22 @@ static void subghz_scene_add_to_history_callback( FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); - uint16_t idx = subghz_history_get_item(subghz->txrx->history); + uint16_t idx = subghz_history_get_item(subghz->history); - if(subghz_history_add_to_history(subghz->txrx->history, decoder_base, subghz->txrx->preset)) { + SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) { furi_string_reset(item_name); furi_string_reset(item_time); subghz->state_notifications = SubGhzNotificationStateRxDone; - subghz_history_get_text_item_menu(subghz->txrx->history, item_name, idx); - subghz_history_get_time_item_menu(subghz->txrx->history, item_time, idx); + subghz_history_get_text_item_menu(subghz->history, item_name, idx); + subghz_history_get_time_item_menu(subghz->history, item_time, idx); subghz_view_receiver_add_item_to_menu( subghz->subghz_receiver, furi_string_get_cstr(item_name), furi_string_get_cstr(item_time), - subghz_history_get_type_protocol(subghz->txrx->history, idx)); + subghz_history_get_type_protocol(subghz->history, idx)); subghz_scene_receiver_update_statusbar(subghz); } @@ -125,8 +126,8 @@ void subghz_scene_receiver_on_enter(void* context) { FuriString* item_time = furi_string_alloc(); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) { - subghz_preset_init(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); - subghz_history_reset(subghz->txrx->history); + subghz_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_history_reset(subghz->history); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); } @@ -135,16 +136,16 @@ void subghz_scene_receiver_on_enter(void* context) { //Load history to receiver subghz_view_receiver_exit(subghz->subghz_receiver); - for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) { + for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) { furi_string_reset(item_name); furi_string_reset(item_time); - subghz_history_get_text_item_menu(subghz->txrx->history, item_name, i); - subghz_history_get_time_item_menu(subghz->txrx->history, item_time, i); + subghz_history_get_text_item_menu(subghz->history, item_name, i); + subghz_history_get_time_item_menu(subghz->history, item_time, i); subghz_view_receiver_add_item_to_menu( subghz->subghz_receiver, furi_string_get_cstr(item_name), furi_string_get_cstr(item_time), - subghz_history_get_type_protocol(subghz->txrx->history, i)); + subghz_history_get_type_protocol(subghz->history, i)); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); } furi_string_free(item_name); @@ -183,11 +184,7 @@ void subghz_scene_receiver_on_enter(void* context) { subghz->state_notifications = SubGhzNotificationStateRx; subghz_txrx_stop(subghz->txrx); - subghz_begin( - subghz->txrx, - subghz_setting_get_preset_data_by_name( - subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); + subghz_rx_start(subghz->txrx); subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen); //to use a universal decoder, we are looking for a link to it @@ -215,7 +212,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz_preset_init( + subghz_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); @@ -232,7 +229,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReceiverDeleteItem: subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); - subghz_history_delete_item(subghz->txrx->history, subghz->idx_menu_chosen); + subghz_history_delete_item(subghz->history, subghz->idx_menu_chosen); subghz_view_receiver_delete_element_callback(subghz->subghz_receiver); subghz_scene_receiver_update_statusbar(subghz); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index f677739fd..752b26197 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -93,12 +93,15 @@ uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* furi_assert(context); SubGhz* subghz = context; uint8_t index = 0; - for(uint8_t i = 0; i < subghz_setting_get_frequency_count(subghz->txrx->setting); i++) { - if(value == subghz_setting_get_frequency(subghz->txrx->setting, i)) { + for(uint8_t i = 0; + i < subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx)); + i++) { + if(value == subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), i)) { index = i; break; } else { - index = subghz_setting_get_frequency_default_index(subghz->txrx->setting); + index = + subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)); } } return index; @@ -108,12 +111,15 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* furi_assert(context); SubGhz* subghz = context; uint8_t index = 0; - for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz->txrx->setting); i++) { - if(!strcmp(subghz_setting_get_preset_name(subghz->txrx->setting, i), preset_name)) { + for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx)); + i++) { + if(!strcmp( + subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), i), + preset_name)) { index = i; break; } else { - // index = subghz_setting_get_frequency_default_index(subghz->txrx->setting); + // index = subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)); } } return index; @@ -149,33 +155,48 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(subghz->txrx->setting, index) / 1000000, - (subghz_setting_get_frequency(subghz->txrx->setting, index) % 1000000) / 10000); + subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) / 1000000, + (subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) % + 1000000) / + 10000); variable_item_set_current_value_text(item, text_buf); - subghz->txrx->preset->frequency = - subghz_setting_get_frequency(subghz->txrx->setting, index); - subghz->last_settings->frequency = subghz->txrx->preset->frequency; + + SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + + subghz_set_preset( + subghz->txrx, + furi_string_get_cstr(preset.name), + subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index), + preset.data, + preset.data_size); + + preset = subghz_get_preset(subghz->txrx); + + subghz->last_settings->frequency = preset.frequency; subghz_setting_set_default_frequency( - subghz->txrx->setting, subghz->txrx->preset->frequency); + subghz_txrx_get_setting(subghz->txrx), preset.frequency); } else { variable_item_set_current_value_index( - item, subghz_setting_get_frequency_default_index(subghz->txrx->setting)); + item, + subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx))); } } static void subghz_scene_receiver_config_set_preset(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - const char* preset_name = subghz_setting_get_preset_name(subghz->txrx->setting, index); + const char* preset_name = + subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), index); variable_item_set_current_value_text(item, preset_name); //subghz->last_settings->preset = index; + SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); - subghz_preset_init( + subghz_set_preset( subghz->txrx, preset_name, - subghz->txrx->preset->frequency, - subghz_setting_get_preset_data(subghz->txrx->setting, index), - subghz_setting_get_preset_data_size(subghz->txrx->setting, index)); + preset.frequency, + subghz_setting_get_preset_data(subghz_txrx_get_setting(subghz->txrx), index), + subghz_setting_get_preset_data_size(subghz_txrx_get_setting(subghz->txrx), index)); } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -189,18 +210,25 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_default_frequency(subghz->txrx->setting) / 1000000, - (subghz_setting_get_default_frequency(subghz->txrx->setting) % 1000000) / 10000); + subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) / 1000000, + (subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) % + 1000000) / + 10000); variable_item_set_current_value_text( (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), text_buf); - subghz->txrx->preset->frequency = - subghz_setting_get_default_frequency(subghz->txrx->setting); + SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + subghz_set_preset( + subghz->txrx, + furi_string_get_cstr(preset.name), + subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)), + preset.data, + preset.data_size); variable_item_set_current_value_index( (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), - subghz_setting_get_frequency_default_index(subghz->txrx->setting)); + subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx))); } else { variable_item_set_current_value_text( (VariableItem*)scene_manager_get_scene_state( @@ -209,7 +237,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) variable_item_set_current_value_index( (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), - subghz_setting_get_frequency_default_index(subghz->txrx->setting)); + subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx))); } subghz_hopper_set_state(subghz->txrx, hopping_value[index]); @@ -277,15 +305,15 @@ void subghz_scene_receiver_config_on_enter(void* context) { SubGhz* subghz = context; VariableItem* item; uint8_t value_index; + SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); item = variable_item_list_add( subghz->variable_item_list, "Frequency:", - subghz_setting_get_frequency_count(subghz->txrx->setting), + subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx)), subghz_scene_receiver_config_set_frequency, subghz); - value_index = - subghz_scene_receiver_config_next_frequency(subghz->txrx->preset->frequency, subghz); + value_index = subghz_scene_receiver_config_next_frequency(preset.frequency, subghz); scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item); variable_item_set_current_value_index(item, value_index); @@ -294,21 +322,23 @@ void subghz_scene_receiver_config_on_enter(void* context) { text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(subghz->txrx->setting, value_index) / 1000000, - (subghz_setting_get_frequency(subghz->txrx->setting, value_index) % 1000000) / 10000); + subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) / 1000000, + (subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) % + 1000000) / + 10000); variable_item_set_current_value_text(item, text_buf); item = variable_item_list_add( subghz->variable_item_list, "Modulation:", - subghz_setting_get_preset_count(subghz->txrx->setting), + subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx)), subghz_scene_receiver_config_set_preset, subghz); - value_index = subghz_scene_receiver_config_next_preset( - furi_string_get_cstr(subghz->txrx->preset->name), subghz); + value_index = + subghz_scene_receiver_config_next_preset(furi_string_get_cstr(preset.name), subghz); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text( - item, subghz_setting_get_preset_name(subghz->txrx->setting, value_index)); + item, subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), value_index)); if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerSet) { diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index ed9f06770..a026371fd 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -26,15 +26,15 @@ static bool subghz_scene_receiver_info_update_parser(void* context) { if(subghz_txrx_load_decoder_by_name_protocol( subghz->txrx, - subghz_history_get_protocol_name(subghz->txrx->history, subghz->idx_menu_chosen))) { + subghz_history_get_protocol_name(subghz->history, subghz->idx_menu_chosen))) { //todo we are trying to deserialize without checking for errors, since it is assumed that we just received this chignal subghz_protocol_decoder_base_deserialize( subghz_txrx_get_decoder(subghz->txrx), - subghz_history_get_raw_data(subghz->txrx->history, subghz->idx_menu_chosen)); + subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen)); SubGhzRadioPreset* preset = - subghz_history_get_radio_preset(subghz->txrx->history, subghz->idx_menu_chosen); - subghz_preset_init( + subghz_history_get_radio_preset(subghz->history, subghz->idx_menu_chosen); + subghz_set_preset( subghz->txrx, furi_string_get_cstr(preset->name), preset->frequency, @@ -123,21 +123,14 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) //CC1101 Stop RX -> Start TX subghz_subghz_hopper_set_pause(subghz->txrx); - subghz_txrx_stop(subghz->txrx); - if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } if(!subghz_tx_start( subghz->txrx, - subghz_history_get_raw_data(subghz->txrx->history, subghz->idx_menu_chosen))) { - subghz_txrx_stop(subghz->txrx); - subghz_begin( - subghz->txrx, - subghz_setting_get_preset_data_by_name( - subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); + subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen))) { + subghz_rx_start(subghz->txrx); subghz_hopper_remove_pause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; } else { @@ -153,11 +146,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) subghz_txrx_stop(subghz->txrx); if(!subghz->in_decoder_scene) { - subghz_begin( - subghz->txrx, - subghz_setting_get_preset_data_by_name( - subghz->txrx->setting, furi_string_get_cstr(subghz->txrx->preset->name))); - subghz_rx(subghz->txrx, subghz->txrx->preset->frequency); + subghz_rx_start(subghz->txrx); subghz_hopper_remove_pause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index f31d4be79..ca48d6b45 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -156,7 +156,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { subghz_save_protocol_to_file( subghz, subghz_history_get_raw_data( - subghz->txrx->history, subghz->idx_menu_chosen), + subghz->history, subghz->idx_menu_chosen), furi_string_get_cstr(subghz->file_path)); } } diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index c75a1b6b3..5c4d03403 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -72,7 +72,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_txrx_stop(subghz->txrx); + if(subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { subghz->state_notifications = SubGhzNotificationStateTx; subghz_scene_transmitter_update_data_show(subghz); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 8731bbc9d..be3df0551 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -272,9 +272,9 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->preset = malloc(sizeof(SubGhzRadioPreset)); subghz->txrx->preset->name = furi_string_alloc(); if(!alloc_for_tx_only) { - subghz_preset_init(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); } else { - subghz_preset_init( + subghz_set_preset( subghz->txrx, "AM650", subghz_setting_get_default_frequency(subghz->txrx->setting), @@ -287,7 +287,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); subghz->txrx->debug_pin_state = false; if(!alloc_for_tx_only) { - subghz->txrx->history = subghz_history_alloc(); + subghz->history = subghz_history_alloc(); } subghz->txrx->worker = subghz_worker_alloc(); @@ -333,6 +333,8 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { } subghz_speaker_off(subghz->txrx); + subghz_txrx_stop(subghz->txrx); + subghz_sleep(subghz->txrx); #if FURI_DEBUG // Packet Test @@ -421,7 +423,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { flipper_format_free(subghz->txrx->fff_data); if(!alloc_for_tx_only) { - subghz_history_free(subghz->txrx->history); + subghz_history_free(subghz->history); } furi_string_free(subghz->txrx->preset->name); free(subghz->txrx->preset); diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index db8bc5cf2..25e81725b 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -91,7 +91,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } furi_string_set_str( - temp_str, subghz_set_preset(subghz->txrx, furi_string_get_cstr(temp_str))); + temp_str, subghz_get_name_preset(subghz->txrx, furi_string_get_cstr(temp_str))); if(temp_str == NULL) { break; } @@ -112,7 +112,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } size_t preset_index = subghz_setting_get_inx_preset_by_name( subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(temp_str)); - subghz_preset_init( + subghz_set_preset( subghz->txrx, furi_string_get_cstr(temp_str), temp_data32, diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 58d715d8b..0914d12ed 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -111,6 +111,7 @@ struct SubGhz { SubGhzThresholdRssi* threshold_rssi; SubGhzRxKeyState rx_key_state; + SubGhzHistory* history; uint16_t idx_menu_chosen; SubGhzLoadTypeFile load_type_file; diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index 4a45479b6..ed3215ebc 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -2,7 +2,7 @@ #define TAG "SubGhz" -void subghz_preset_init( +void subghz_set_preset( SubGhzTxRx* txrx, const char* preset_name, uint32_t frequency, @@ -37,7 +37,7 @@ void subghz_get_frequency_modulation( } } -const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset) { +const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset) { UNUSED(txrx); const char* preset_name = NULL; if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { @@ -56,7 +56,12 @@ const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset) { return preset_name; } -void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) { +SubGhzRadioPreset subghz_get_preset(SubGhzTxRx* txrx) { + furi_assert(txrx); + return *txrx->preset; +} + +static void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) { furi_assert(txrx); furi_hal_subghz_reset(); furi_hal_subghz_idle(); @@ -65,7 +70,7 @@ void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) { txrx->txrx_state = SubGhzTxRxStateIDLE; } -uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency) { +static uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency) { furi_assert(txrx); if(!furi_hal_subghz_is_frequency_valid(frequency)) { furi_crash("SubGhz: Incorrect RX frequency."); @@ -106,11 +111,11 @@ static void subghz_rx_end(SubGhzTxRx* txrx) { txrx->txrx_state = SubGhzTxRxStateIDLE; } -// static void subghz_sleep(SubGhzTxRx* txrx) { -// furi_assert(txrx); -// furi_hal_subghz_sleep(); -// txrx->txrx_state = SubGhzTxRxStateSleep; -// } +void subghz_sleep(SubGhzTxRx* txrx) { + furi_assert(txrx); + furi_hal_subghz_sleep(); + txrx->txrx_state = SubGhzTxRxStateSleep; +} static bool subghz_tx(SubGhzTxRx* txrx, uint32_t frequency) { furi_assert(txrx); @@ -133,6 +138,9 @@ static bool subghz_tx(SubGhzTxRx* txrx, uint32_t frequency) { bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) { furi_assert(txrx); + furi_assert(flipper_format); + + subghz_txrx_stop(txrx); bool ret = false; FuriString* temp_str = furi_string_alloc(); @@ -200,6 +208,16 @@ bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) { return ret; } +void subghz_rx_start(SubGhzTxRx* txrx) { + furi_assert(txrx); + subghz_txrx_stop(txrx); + subghz_begin( + txrx, + subghz_setting_get_preset_data_by_name( + subghz_txrx_get_setting(txrx), furi_string_get_cstr(txrx->preset->name))); + subghz_rx(txrx, txrx->preset->frequency); +} + void subghz_txrx_need_save_callback_set( SubGhzTxRx* txrx, SubGhzTxRxNeedSaveCallback callback, @@ -449,7 +467,7 @@ bool subghz_gen_data_protocol( bool res = false; - subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + subghz_set_preset(txrx, preset_name, frequency, NULL, 0); txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(txrx->receiver, protocol_name); @@ -520,7 +538,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + subghz_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_keeloq_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -552,7 +570,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + subghz_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_keeloq_bft_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -596,7 +614,7 @@ bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); - subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + subghz_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_nice_flor_s_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -629,7 +647,7 @@ bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME); - subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + subghz_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_faac_slh_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -670,7 +688,7 @@ bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); - subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + subghz_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_alutech_at_4n_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -700,7 +718,7 @@ bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); - subghz_preset_init(txrx, preset_name, frequency, NULL, 0); + subghz_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_somfy_telis_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -729,7 +747,7 @@ bool subghz_gen_secplus_v2_protocol( bool ret = false; txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_preset_init(txrx, name_preset, frequency, NULL, 0); + subghz_set_preset(txrx, name_preset, frequency, NULL, 0); if(txrx->transmitter) { subghz_protocol_secplus_v2_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index 579f992a0..9a9f90d3d 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -21,7 +21,6 @@ struct SubGhzTxRx { FlipperFormat* fff_data; SubGhzRadioPreset* preset; - SubGhzHistory* history; SubGhzSetting* setting; uint8_t hopper_timeout; @@ -40,26 +39,27 @@ struct SubGhzTxRx { typedef struct SubGhzTxRx SubGhzTxRx; -void subghz_preset_init( +void subghz_set_preset( SubGhzTxRx* txrx, const char* preset_name, uint32_t frequency, uint8_t* preset_data, size_t preset_data_size); -const char* subghz_set_preset(SubGhzTxRx* txrx, const char* preset); +const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset); +SubGhzRadioPreset subghz_get_preset(SubGhzTxRx* txrx); + void subghz_get_frequency_modulation( SubGhzTxRx* txrx, FuriString* frequency, FuriString* modulation, bool long_name); -void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data); -uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency); bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format); //void subghz_rx_end(SubGhzTxRx* txrx); //depricated -//void subghz_sleep(SubGhzTxRx* txrx); - +void subghz_rx_start(SubGhzTxRx* txrx); void subghz_txrx_stop(SubGhzTxRx* txrx); +void subghz_sleep(SubGhzTxRx* txrx); + SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* txrx); void subghz_hopper_update(SubGhzTxRx* txrx); From 076f6785cb517d025edd75a0b321817de88780c6 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 15:22:08 +0300 Subject: [PATCH 12/36] SubGhz: refactoring --- .../scenes/subghz_scene_receiver_info.c | 10 +++------ .../subghz/scenes/subghz_scene_transmitter.c | 9 +------- applications/main/subghz/subghz_radio.c | 22 +++++++++++++++++++ applications/main/subghz/subghz_radio.h | 3 +++ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index a026371fd..f3cfd0962 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -78,8 +78,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { furi_string_free(modulation_str); furi_string_free(text); - if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == - SubGhzProtocolFlag_Save) { + if(subghz_txrx_protocol_is_preserved(subghz->txrx)) { widget_add_button_element( subghz->widget, GuiButtonTypeRight, @@ -88,9 +87,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { subghz); } // Removed static check - if(((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == - SubGhzProtocolFlag_Send) && - subghz->txrx->decoder_result->protocol->encoder->deserialize) { + if(subghz_txrx_protocol_is_send(subghz->txrx, false)) { widget_add_button_element( subghz->widget, GuiButtonTypeCenter, @@ -162,8 +159,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) return false; } - if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == - SubGhzProtocolFlag_Save) { + if(subghz_txrx_protocol_is_preserved(subghz->txrx)) { subghz_file_name_clear(subghz); if(subghz->in_decoder_scene) { diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 5c4d03403..d5bd45618 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -20,26 +20,19 @@ bool subghz_scene_transmitter_update_data_show(void* context) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); - bool show_button = false; - if(subghz_protocol_decoder_base_deserialize( subghz_txrx_get_decoder(subghz->txrx), subghz_txtx_get_fff_data(subghz->txrx)) == SubGhzProtocolStatusOk) { subghz_protocol_decoder_base_get_string( subghz_txrx_get_decoder(subghz->txrx), key_str); - if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == - SubGhzProtocolFlag_Send) { - show_button = true; - } - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); subghz_view_transmitter_add_data_to_show( subghz->subghz_transmitter, furi_string_get_cstr(key_str), furi_string_get_cstr(frequency_str), furi_string_get_cstr(modulation_str), - show_button); + subghz_txrx_protocol_is_send(subghz->txrx, false)); ret = true; } furi_string_free(frequency_str); diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index ed3215ebc..cd556efce 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -444,6 +444,28 @@ SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* txrx) { return txrx->decoder_result; } +bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* txrx) { + furi_assert(txrx); + return ( + (txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == + SubGhzProtocolFlag_Save); +} + +bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type) { + furi_assert(txrx); + if(check_type) { + return ( + ((txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == + SubGhzProtocolFlag_Send) && + txrx->decoder_result->protocol->encoder->deserialize && + txrx->decoder_result->protocol->type == SubGhzProtocolTypeStatic); + } + return ( + ((txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == + SubGhzProtocolFlag_Send) && + txrx->decoder_result->protocol->encoder->deserialize); +} + //#############Create new Key############## #include #include diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index 9a9f90d3d..0a51334cb 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -84,6 +84,9 @@ void subghz_txrx_need_save_callback_set( FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* txrx); SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* txrx); +bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* txrx); +bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type); + //#############Create new Key############## bool subghz_gen_data_protocol( void* context, From 4cbdbd9ef5b0bc6500f59ccf80095cbae7adad6a Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 15:58:56 +0300 Subject: [PATCH 13/36] SubGhz: refactoring --- applications/main/subghz/scenes/subghz_scene_decode_raw.c | 2 +- applications/main/subghz/scenes/subghz_scene_read_raw.c | 4 ++-- .../main/subghz/scenes/subghz_scene_receiver_config.c | 6 +++--- applications/main/subghz/subghz.c | 5 +++-- applications/main/subghz/subghz_i.h | 1 + applications/main/subghz/subghz_radio.c | 5 +++++ applications/main/subghz/subghz_radio.h | 3 ++- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index e75f6fda6..fa3082a3f 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -170,7 +170,7 @@ void subghz_scene_decode_raw_on_enter(void* context) { subghz_receiver_set_rx_callback( subghz->txrx->receiver, subghz_scene_add_to_history_callback, subghz); - subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); + subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_Decodable); if(subghz->decode_raw_state == SubGhzDecodeRawStateStart) { //Decode RAW to history diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 4fed9424c..778751dfe 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -117,7 +117,7 @@ void subghz_scene_read_raw_on_enter(void* context) { furi_check(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, SUBGHZ_PROTOCOL_RAW_NAME)); //set filter RAW feed - subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_RAW); + subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_RAW); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReadRAW); } @@ -359,5 +359,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, subghz->txrx->filter); + subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 752b26197..45b88b79b 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -256,8 +256,8 @@ static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, bin_raw_text[index]); - subghz->txrx->filter = bin_raw_value[index]; - subghz_receiver_set_filter(subghz->txrx->receiver, subghz->txrx->filter); + subghz->filter = bin_raw_value[index]; + subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); } static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* item) { @@ -363,7 +363,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { BIN_RAW_COUNT, subghz_scene_receiver_config_set_bin_raw, subghz); - value_index = value_index_uint32(subghz->txrx->filter, bin_raw_value, BIN_RAW_COUNT); + value_index = value_index_uint32(subghz->filter, bin_raw_value, BIN_RAW_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, bin_raw_text[value_index]); } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index be3df0551..b2fca5a9e 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -305,8 +305,9 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_environment_set_protocol_registry( subghz->txrx->environment, (void*)&subghz_protocol_registry); subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); - subghz->txrx->filter = SubGhzProtocolFlag_Decodable; - subghz_receiver_set_filter(subghz->txrx->receiver, subghz->txrx->filter); + + subghz->filter = SubGhzProtocolFlag_Decodable; + subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); subghz_worker_set_overrun_callback( subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 0914d12ed..a9594b789 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -94,6 +94,7 @@ struct SubGhz { #endif SubGhzLastSettings* last_settings; + SubGhzProtocolFlag filter; FuriString* error_str; SubGhzLock lock; diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index cd556efce..656306ed8 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -466,6 +466,11 @@ bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type) { txrx->decoder_result->protocol->encoder->deserialize); } +void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter) { + furi_assert(txrx); + subghz_receiver_set_filter(txrx->receiver, filter); +} + //#############Create new Key############## #include #include diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index 0a51334cb..59f93733c 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -16,7 +16,6 @@ struct SubGhzTxRx { SubGhzEnvironment* environment; SubGhzReceiver* receiver; SubGhzTransmitter* transmitter; - SubGhzProtocolFlag filter; SubGhzProtocolDecoderBase* decoder_result; FlipperFormat* fff_data; @@ -87,6 +86,8 @@ SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* txrx); bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* txrx); bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type); +void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter); + //#############Create new Key############## bool subghz_gen_data_protocol( void* context, From a2fbe7fab8e69598f460e6853bd0da8c51705859 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 17:30:01 +0300 Subject: [PATCH 14/36] SubGhz: refactoring --- .../scenes/subghz_scene_ext_module_settings.c | 4 +- applications/main/subghz/subghz.c | 98 +++++-------------- applications/main/subghz/subghz_radio.c | 70 +++++++++++++ applications/main/subghz/subghz_radio.h | 8 ++ 4 files changed, 102 insertions(+), 78 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c b/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c index 508ca7dcc..963483db3 100644 --- a/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_ext_module_settings.c @@ -62,7 +62,7 @@ static void subghz_scene_receiver_config_set_debug_pin(VariableItem* item) { variable_item_set_current_value_text(item, debug_pin_text[index]); - subghz->txrx->debug_pin_state = index == 1; + subghz_txrx_set_debug_pin_state(subghz->txrx, index == 1); } static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) { @@ -164,7 +164,7 @@ void subghz_scene_ext_module_settings_on_enter(void* context) { DEBUG_P_COUNT, subghz_scene_receiver_config_set_debug_pin, subghz); - value_index_dpin = subghz->txrx->debug_pin_state; + value_index_dpin = subghz_txrx_get_debug_pin_state(subghz->txrx); variable_item_set_current_value_index(item, value_index_dpin); variable_item_set_current_value_text(item, debug_pin_text[value_index_dpin]); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index b2fca5a9e..36a817117 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -180,11 +180,15 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_test_static_get_view(subghz->subghz_test_static)); #endif - subghz->txrx = malloc(sizeof(SubGhzTxRx)); - //init setting - subghz->txrx->setting = subghz_setting_alloc(); + //init threshold rssi + subghz->threshold_rssi = subghz_threshold_rssi_alloc(); - subghz_setting_load(subghz->txrx->setting, EXT_PATH("subghz/assets/setting_user")); + //init TxRx & Protocol & History & KeyBoard + subghz_unlock(subghz); + + subghz->txrx = subghz_txrx_alloc(); + + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); // Custom Presets load without using config file if(!alloc_for_tx_only) { @@ -194,8 +198,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 83 10 67 15 24 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset); - subghz_setting_load_custom_preset( - subghz->txrx->setting, (const char*)"FM95", temp_fm_preset); + subghz_setting_load_custom_preset(setting, (const char*)"FM95", temp_fm_preset); flipper_format_free(temp_fm_preset); @@ -206,8 +209,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 03 47 08 32 0B 06 15 32 14 00 13 00 12 00 11 32 10 A7 18 18 19 1D 1D 92 1C 00 1B 04 20 FB 22 17 21 B6 00 00 00 12 0E 34 60 C5 C1 C0"); flipper_format_rewind(temp_fm_preset2); - subghz_setting_load_custom_preset( - subghz->txrx->setting, (const char*)"FM15k", temp_fm_preset2); + subghz_setting_load_custom_preset(setting, (const char*)"FM15k", temp_fm_preset2); flipper_format_free(temp_fm_preset2); @@ -218,8 +220,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset3); - subghz_setting_load_custom_preset( - subghz->txrx->setting, (const char*)"Pagers", temp_fm_preset3); + subghz_setting_load_custom_preset(setting, (const char*)"Pagers", temp_fm_preset3); flipper_format_free(temp_fm_preset3); @@ -230,8 +231,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset4); - subghz_setting_load_custom_preset( - subghz->txrx->setting, (const char*)"HND_1", temp_fm_preset4); + subghz_setting_load_custom_preset(setting, (const char*)"HND_1", temp_fm_preset4); flipper_format_free(temp_fm_preset4); @@ -241,8 +241,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { (const char*)"Custom_preset_data", (const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 07 11 36 10 E9 15 32 18 18 19 16 1D 92 1C 40 1B 03 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"); flipper_format_rewind(temp_fm_preset5); - subghz_setting_load_custom_preset( - subghz->txrx->setting, (const char*)"HND_2", temp_fm_preset5); + subghz_setting_load_custom_preset(setting, (const char*)"HND_2", temp_fm_preset5); flipper_format_free(temp_fm_preset5); } @@ -259,61 +258,24 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->last_settings->frequency, subghz->last_settings->preset); #endif - subghz_setting_set_default_frequency( - subghz->txrx->setting, subghz->last_settings->frequency); + subghz_setting_set_default_frequency(setting, subghz->last_settings->frequency); } - //init threshold rssi - subghz->threshold_rssi = subghz_threshold_rssi_alloc(); - - //init Worker & Protocol & History & KeyBoard - subghz_unlock(subghz); - - subghz->txrx->preset = malloc(sizeof(SubGhzRadioPreset)); - subghz->txrx->preset->name = furi_string_alloc(); if(!alloc_for_tx_only) { subghz_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); - } else { - subghz_set_preset( - subghz->txrx, - "AM650", - subghz_setting_get_default_frequency(subghz->txrx->setting), - NULL, - 0); } - subghz->txrx->txrx_state = SubGhzTxRxStateSleep; - subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); - subghz_speaker_set_state(subghz->txrx, SubGhzSpeakerStateDisable); + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz->txrx->debug_pin_state = false; + if(!alloc_for_tx_only) { subghz->history = subghz_history_alloc(); } - subghz->txrx->worker = subghz_worker_alloc(); - - subghz->txrx->fff_data = flipper_format_string_alloc(); subghz->secure_data = malloc(sizeof(SecureData)); - subghz->txrx->environment = subghz_environment_alloc(); - subghz_environment_set_came_atomo_rainbow_table_file_name( - subghz->txrx->environment, EXT_PATH("subghz/assets/came_atomo")); - subghz_environment_set_alutech_at_4n_rainbow_table_file_name( - subghz->txrx->environment, EXT_PATH("subghz/assets/alutech_at_4n")); - subghz_environment_set_nice_flor_s_rainbow_table_file_name( - subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); - subghz_environment_set_protocol_registry( - subghz->txrx->environment, (void*)&subghz_protocol_registry); - subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); - subghz->filter = SubGhzProtocolFlag_Decodable; - subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); - 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_txrx_receiver_set_filter(subghz->txrx, subghz->filter); subghz_txrx_need_save_callback_set(subghz->txrx, subghz_save_to_file, subghz); @@ -405,8 +367,6 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { furi_record_close(RECORD_GUI); subghz->gui = NULL; - // setting - subghz_setting_free(subghz->txrx->setting); if(!alloc_for_tx_only) { subghz_last_settings_free(subghz->last_settings); } @@ -414,22 +374,14 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { // threshold rssi subghz_threshold_rssi_free(subghz->threshold_rssi); - //Worker & Protocol & History - - subghz_receiver_free(subghz->txrx->receiver); - - subghz_environment_free(subghz->txrx->environment); - - subghz_worker_free(subghz->txrx->worker); - - flipper_format_free(subghz->txrx->fff_data); if(!alloc_for_tx_only) { subghz_history_free(subghz->history); } - furi_string_free(subghz->txrx->preset->name); - free(subghz->txrx->preset); + free(subghz->secure_data); - free(subghz->txrx); + + //TxRx + subghz_txrx_free(subghz->txrx); //Error string furi_string_free(subghz->error_str); @@ -462,12 +414,6 @@ int32_t subghz_app(void* p) { subghz->raw_send_only = false; } - //Load database - bool load_database = subghz_environment_load_keystore( - subghz->txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); - subghz_environment_load_keystore( - subghz->txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); - // Call enable power for external module furi_hal_subghz_enable_ext_power(); @@ -512,7 +458,7 @@ int32_t subghz_app(void* p) { view_dispatcher_attach_to_gui( subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen); furi_string_set(subghz->file_path, SUBGHZ_APP_FOLDER); - if(load_database) { + if(subghz_txrx_is_load_database(subghz->txrx)) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart); } else { scene_manager_set_scene_state( diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index 656306ed8..6e3ae3294 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -1,7 +1,77 @@ #include "subghz_radio.h" +#include #define TAG "SubGhz" +SubGhzTxRx* subghz_txrx_alloc() { + SubGhzTxRx* txrx = malloc(sizeof(SubGhzTxRx)); + txrx->setting = subghz_setting_alloc(); + subghz_setting_load(txrx->setting, EXT_PATH("subghz/assets/setting_user")); + + txrx->preset = malloc(sizeof(SubGhzRadioPreset)); + txrx->preset->name = furi_string_alloc(); + subghz_set_preset(txrx, "AM650", subghz_setting_get_default_frequency(txrx->setting), NULL, 0); + + txrx->txrx_state = SubGhzTxRxStateSleep; + + subghz_hopper_set_state(txrx, SubGhzHopperStateOFF); + subghz_speaker_set_state(txrx, SubGhzSpeakerStateDisable); + subghz_txrx_set_debug_pin_state(txrx, false); + + txrx->worker = subghz_worker_alloc(); + txrx->fff_data = flipper_format_string_alloc(); + + txrx->environment = subghz_environment_alloc(); + txrx->load_database = subghz_environment_load_keystore( + txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); + subghz_environment_load_keystore( + txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); + subghz_environment_set_came_atomo_rainbow_table_file_name( + txrx->environment, EXT_PATH("subghz/assets/came_atomo")); + subghz_environment_set_alutech_at_4n_rainbow_table_file_name( + txrx->environment, EXT_PATH("subghz/assets/alutech_at_4n")); + subghz_environment_set_nice_flor_s_rainbow_table_file_name( + txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); + subghz_environment_set_protocol_registry(txrx->environment, (void*)&subghz_protocol_registry); + txrx->receiver = subghz_receiver_alloc_init(txrx->environment); + + subghz_worker_set_overrun_callback( + txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); + subghz_worker_set_pair_callback( + txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); + subghz_worker_set_context(txrx->worker, txrx->receiver); + + return txrx; +} + +void subghz_txrx_free(SubGhzTxRx* txrx) { + furi_assert(txrx); + + subghz_worker_free(txrx->worker); + subghz_receiver_free(txrx->receiver); + subghz_environment_free(txrx->environment); + flipper_format_free(txrx->fff_data); + furi_string_free(txrx->preset->name); + subghz_setting_free(txrx->setting); + free(txrx->preset); + free(txrx); +} + +bool subghz_txrx_is_load_database(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->load_database; +} + +void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state) { + furi_assert(txrx); + txrx->debug_pin_state = state; +} + +bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->debug_pin_state; +} + void subghz_set_preset( SubGhzTxRx* txrx, const char* preset_name, diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index 59f93733c..5e5b1a82f 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -24,6 +24,7 @@ struct SubGhzTxRx { uint8_t hopper_timeout; uint8_t hopper_idx_frequency; + bool load_database; SubGhzHopperState hopper_state; SubGhzTxRxState txrx_state; @@ -38,6 +39,13 @@ struct SubGhzTxRx { typedef struct SubGhzTxRx SubGhzTxRx; +SubGhzTxRx* subghz_txrx_alloc(); +void subghz_txrx_free(SubGhzTxRx* txrx); +bool subghz_txrx_is_load_database(SubGhzTxRx* txrx); + +void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state); +bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx); + void subghz_set_preset( SubGhzTxRx* txrx, const char* preset_name, From 8ae2cb1d32384baa98c76fb2ad8f006324aa74ed Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 18:24:25 +0300 Subject: [PATCH 15/36] SubGhz: refactoring --- .../subghz/scenes/subghz_scene_decode_raw.c | 9 ++-- .../subghz/scenes/subghz_scene_read_raw.c | 7 +-- .../subghz/scenes/subghz_scene_receiver.c | 13 +++--- .../subghz/scenes/subghz_scene_save_name.c | 12 ++--- .../subghz/scenes/subghz_scene_save_success.c | 2 +- applications/main/subghz/subghz.c | 2 +- applications/main/subghz/subghz_radio.c | 46 +++++++++++++++++++ applications/main/subghz/subghz_radio.h | 36 ++++----------- 8 files changed, 75 insertions(+), 52 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index fa3082a3f..ef431a2c6 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -125,14 +125,14 @@ bool subghz_scene_decode_raw_start(SubGhz* subghz) { bool subghz_scene_decode_raw_next(SubGhz* subghz) { LevelDuration level_duration; - + SubGhzReceiver* receiver = subghz_txrx_get_receiver(subghz->txrx); for(uint32_t read = SAMPLES_TO_READ_PER_TICK; read > 0; --read) { level_duration = subghz_file_encoder_worker_get_level_duration(subghz->decode_raw_file_worker_encoder); if(!level_duration_is_reset(level_duration)) { bool level = level_duration_get_level(level_duration); uint32_t duration = level_duration_get_duration(level_duration); - subghz_receiver_decode(subghz->txrx->receiver, level, duration); + subghz_receiver_decode(receiver, level, duration); } else { subghz->decode_raw_state = SubGhzDecodeRawStateLoaded; subghz->state_notifications = SubGhzNotificationStateIDLE; @@ -167,8 +167,7 @@ void subghz_scene_decode_raw_on_enter(void* context) { subghz_view_receiver_set_callback( subghz->subghz_receiver, subghz_scene_decode_raw_callback, subghz); - subghz_receiver_set_rx_callback( - subghz->txrx->receiver, subghz_scene_add_to_history_callback, subghz); + subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_Decodable); @@ -214,7 +213,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) { subghz->in_decoder_scene = false; subghz->in_decoder_scene_skip = false; - subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); + subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz); if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) { subghz_file_encoder_worker_stop(subghz->decode_raw_file_worker_encoder); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 778751dfe..5b20b04b1 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -228,11 +228,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { DOLPHIN_DEED(DolphinDeedSubGhzSend); } // set callback end tx - subghz_protocol_raw_file_encoder_worker_set_callback_end( - (SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance( - subghz->txrx->transmitter), - subghz_scene_read_raw_callback_end_tx, - subghz); + subghz_txrx_set_raw_file_encoder_worker_set_callback_end( + subghz->txrx, subghz_scene_read_raw_callback_end_tx, subghz); subghz->state_notifications = SubGhzNotificationStateTx; } } else { diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 72083fdeb..32e9cf6c8 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -153,32 +153,31 @@ void subghz_scene_receiver_on_enter(void* context) { subghz_scene_receiver_update_statusbar(subghz); subghz_view_receiver_set_callback( subghz->subghz_receiver, subghz_scene_receiver_callback, subghz); - subghz_receiver_set_rx_callback( - subghz->txrx->receiver, subghz_scene_add_to_history_callback, subghz); + subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); // TODO: Replace with proper solution based on protocol flags, remove kostily and velosipedy from here // Needs to be done after subghz refactoring merge!!! if(subghz->ignore_starline == true) { if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Star Line")) { subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); } } if(subghz->ignore_auto_alarms == true) { if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "KIA Seed")) { subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); } if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Scher-Khan")) { subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); } } if(subghz->ignore_magellan == true) { if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Magellan")) { subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver); + subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); } } @@ -205,7 +204,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { subghz_txrx_stop(subghz->txrx); subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); subghz->idx_menu_chosen = 0; - subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); + subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit); diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index ca48d6b45..c05230d97 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -57,15 +57,16 @@ void subghz_scene_save_name_on_enter(void* context) { if(!subghz_path_is_file(subghz->file_path)) { char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0}; if(furi_hal_subghz_get_timestamp_file_names()) { - if(subghz->txrx->decoder_result != 0x0) { - if(subghz->txrx->decoder_result != NULL) { - if(strlen(subghz->txrx->decoder_result->protocol->name) != 0) { + SubGhzProtocolDecoderBase* decoder_result = subghz_txrx_get_decoder(subghz->txrx); + if(decoder_result != 0x0) { + if(decoder_result != NULL) { + if(strlen(decoder_result->protocol->name) != 0) { if(scene_manager_has_previous_scene( subghz->scene_manager, SubGhzSceneSetType)) { subghz_scene_save_name_get_timefilename(file_name, "S", true); } else { subghz_scene_save_name_get_timefilename( - file_name, subghz->txrx->decoder_result->protocol->name, false); + file_name, decoder_result->protocol->name, false); } } else { @@ -155,8 +156,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { } else { subghz_save_protocol_to_file( subghz, - subghz_history_get_raw_data( - subghz->history, subghz->idx_menu_chosen), + subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen), furi_string_get_cstr(subghz->file_path)); } } diff --git a/applications/main/subghz/scenes/subghz_scene_save_success.c b/applications/main/subghz/scenes/subghz_scene_save_success.c index ad37da086..0d0f9059e 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_success.c +++ b/applications/main/subghz/scenes/subghz_scene_save_success.c @@ -40,7 +40,7 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) } else { subghz->decode_raw_state = SubGhzDecodeRawStateStart; subghz->idx_menu_chosen = 0; - subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); + subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz); if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) { subghz_file_encoder_worker_stop(subghz->decode_raw_file_worker_encoder); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 36a817117..f4fc1aa94 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -368,7 +368,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { subghz->gui = NULL; if(!alloc_for_tx_only) { - subghz_last_settings_free(subghz->last_settings); + subghz_last_settings_free(subghz->last_settings); //TODO always allocated } // threshold rssi diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index 6e3ae3294..c5cb7d906 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -3,6 +3,33 @@ #define TAG "SubGhz" +struct SubGhzTxRx { + SubGhzWorker* worker; + + SubGhzEnvironment* environment; + SubGhzReceiver* receiver; + SubGhzTransmitter* transmitter; + SubGhzProtocolDecoderBase* decoder_result; + FlipperFormat* fff_data; + + SubGhzRadioPreset* preset; + SubGhzSetting* setting; + + uint8_t hopper_timeout; + uint8_t hopper_idx_frequency; + bool load_database; + SubGhzHopperState hopper_state; + + SubGhzTxRxState txrx_state; + + SubGhzSpeakerState speaker_state; + + SubGhzTxRxNeedSaveCallback need_save_callback; + void* need_save_context; + + bool debug_pin_state; +}; + SubGhzTxRx* subghz_txrx_alloc() { SubGhzTxRx* txrx = malloc(sizeof(SubGhzTxRx)); txrx->setting = subghz_setting_alloc(); @@ -541,6 +568,25 @@ void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter subghz_receiver_set_filter(txrx->receiver, filter); } +void subghz_txrx_set_rx_calback(SubGhzTxRx* txrx, SubGhzReceiverCallback callback, void* context) { + subghz_receiver_set_rx_callback(txrx->receiver, callback, context); +} + +void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( + SubGhzTxRx* txrx, + SubGhzProtocolEncoderRAWCallbackEnd callback, + void* context) { + subghz_protocol_raw_file_encoder_worker_set_callback_end( + (SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(txrx->transmitter), + callback, + context); +} + +SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->receiver; +} + //#############Create new Key############## #include #include diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index 5e5b1a82f..7745aa0ef 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -5,38 +5,12 @@ #include #include #include +#include #include "subghz_history.h" typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); -struct SubGhzTxRx { - SubGhzWorker* worker; - - SubGhzEnvironment* environment; - SubGhzReceiver* receiver; - SubGhzTransmitter* transmitter; - SubGhzProtocolDecoderBase* decoder_result; - FlipperFormat* fff_data; - - SubGhzRadioPreset* preset; - SubGhzSetting* setting; - - uint8_t hopper_timeout; - uint8_t hopper_idx_frequency; - bool load_database; - SubGhzHopperState hopper_state; - - SubGhzTxRxState txrx_state; - - SubGhzSpeakerState speaker_state; - - SubGhzTxRxNeedSaveCallback need_save_callback; - void* need_save_context; - - bool debug_pin_state; -}; - typedef struct SubGhzTxRx SubGhzTxRx; SubGhzTxRx* subghz_txrx_alloc(); @@ -96,6 +70,14 @@ bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type); void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter); +void subghz_txrx_set_rx_calback(SubGhzTxRx* txrx, SubGhzReceiverCallback callback, void* context); +void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( + SubGhzTxRx* txrx, + SubGhzProtocolEncoderRAWCallbackEnd callback, + void* context); + +SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx); // TODO use only in DecodeRaw + //#############Create new Key############## bool subghz_gen_data_protocol( void* context, From 9b3654c1f0d4d8585e097759e8bf0a23ea0fb961 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 18:24:38 +0300 Subject: [PATCH 16/36] SubGhz: refactoring make subghz_radio.h look like in OFW --- applications/main/subghz/subghz_radio.c | 64 ++++++++++++------------- applications/main/subghz/subghz_radio.h | 7 ++- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index c5cb7d906..556339bc3 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -89,16 +89,6 @@ bool subghz_txrx_is_load_database(SubGhzTxRx* txrx) { return txrx->load_database; } -void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state) { - furi_assert(txrx); - txrx->debug_pin_state = state; -} - -bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->debug_pin_state; -} - void subghz_set_preset( SubGhzTxRx* txrx, const char* preset_name, @@ -112,28 +102,6 @@ void subghz_set_preset( txrx->preset->data_size = preset_data_size; } -void subghz_get_frequency_modulation( - SubGhzTxRx* txrx, - FuriString* frequency, - FuriString* modulation, - bool long_name) { - furi_assert(txrx); - if(frequency != NULL) { - furi_string_printf( - frequency, - "%03ld.%02ld", - txrx->preset->frequency / 1000000 % 1000, - txrx->preset->frequency / 10000 % 100); - } - if(modulation != NULL) { - if(long_name) { - furi_string_printf(modulation, "%s", furi_string_get_cstr(txrx->preset->name)); - } else { - furi_string_printf(modulation, "%.2s", furi_string_get_cstr(txrx->preset->name)); - } - } -} - const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset) { UNUSED(txrx); const char* preset_name = NULL; @@ -158,6 +126,28 @@ SubGhzRadioPreset subghz_get_preset(SubGhzTxRx* txrx) { return *txrx->preset; } +void subghz_get_frequency_modulation( + SubGhzTxRx* txrx, + FuriString* frequency, + FuriString* modulation, + bool long_name) { + furi_assert(txrx); + if(frequency != NULL) { + furi_string_printf( + frequency, + "%03ld.%02ld", + txrx->preset->frequency / 1000000 % 1000, + txrx->preset->frequency / 10000 % 100); + } + if(modulation != NULL) { + if(long_name) { + furi_string_printf(modulation, "%s", furi_string_get_cstr(txrx->preset->name)); + } else { + furi_string_printf(modulation, "%.2s", furi_string_get_cstr(txrx->preset->name)); + } + } +} + static void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) { furi_assert(txrx); furi_hal_subghz_reset(); @@ -582,6 +572,16 @@ void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( context); } +void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state) { + furi_assert(txrx); + txrx->debug_pin_state = state; +} + +bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx) { + furi_assert(txrx); + return txrx->debug_pin_state; +} + SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx) { furi_assert(txrx); return txrx->receiver; diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index 7745aa0ef..dc6834ac1 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -17,9 +17,6 @@ SubGhzTxRx* subghz_txrx_alloc(); void subghz_txrx_free(SubGhzTxRx* txrx); bool subghz_txrx_is_load_database(SubGhzTxRx* txrx); -void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state); -bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx); - void subghz_set_preset( SubGhzTxRx* txrx, const char* preset_name, @@ -36,7 +33,6 @@ void subghz_get_frequency_modulation( FuriString* modulation, bool long_name); bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format); -//void subghz_rx_end(SubGhzTxRx* txrx); //depricated void subghz_rx_start(SubGhzTxRx* txrx); void subghz_txrx_stop(SubGhzTxRx* txrx); void subghz_sleep(SubGhzTxRx* txrx); @@ -76,6 +72,9 @@ void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( SubGhzProtocolEncoderRAWCallbackEnd callback, void* context); +void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state); +bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx); + SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx); // TODO use only in DecodeRaw //#############Create new Key############## From d7f3b8a4254777da7e4506424f8f89abef236871 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 19:10:56 +0300 Subject: [PATCH 17/36] SubGhz: refactoring move txrx --- .../{subghz_radio.c => helpers/subghz_txrx.c} | 554 +++++++++--------- .../{subghz_radio.h => helpers/subghz_txrx.h} | 95 +-- .../subghz/scenes/subghz_scene_decode_raw.c | 4 +- .../main/subghz/scenes/subghz_scene_delete.c | 2 +- .../subghz/scenes/subghz_scene_delete_raw.c | 2 +- .../subghz/scenes/subghz_scene_need_saving.c | 2 +- .../subghz/scenes/subghz_scene_read_raw.c | 14 +- .../subghz/scenes/subghz_scene_receiver.c | 21 +- .../scenes/subghz_scene_receiver_config.c | 26 +- .../scenes/subghz_scene_receiver_info.c | 22 +- .../main/subghz/scenes/subghz_scene_rpc.c | 2 +- .../subghz/scenes/subghz_scene_set_type.c | 38 +- .../subghz/scenes/subghz_scene_transmitter.c | 6 +- applications/main/subghz/subghz.c | 18 +- applications/main/subghz/subghz_i.c | 4 +- applications/main/subghz/subghz_i.h | 6 +- 16 files changed, 416 insertions(+), 400 deletions(-) rename applications/main/subghz/{subghz_radio.c => helpers/subghz_txrx.c} (53%) rename applications/main/subghz/{subghz_radio.h => helpers/subghz_txrx.h} (50%) diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/helpers/subghz_txrx.c similarity index 53% rename from applications/main/subghz/subghz_radio.c rename to applications/main/subghz/helpers/subghz_txrx.c index 556339bc3..c99b95e09 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -1,4 +1,4 @@ -#include "subghz_radio.h" +#include "subghz_txrx.h" #include #define TAG "SubGhz" @@ -21,7 +21,6 @@ struct SubGhzTxRx { SubGhzHopperState hopper_state; SubGhzTxRxState txrx_state; - SubGhzSpeakerState speaker_state; SubGhzTxRxNeedSaveCallback need_save_callback; @@ -31,79 +30,81 @@ struct SubGhzTxRx { }; SubGhzTxRx* subghz_txrx_alloc() { - SubGhzTxRx* txrx = malloc(sizeof(SubGhzTxRx)); - txrx->setting = subghz_setting_alloc(); - subghz_setting_load(txrx->setting, EXT_PATH("subghz/assets/setting_user")); + SubGhzTxRx* instance = malloc(sizeof(SubGhzTxRx)); + instance->setting = subghz_setting_alloc(); + subghz_setting_load(instance->setting, EXT_PATH("subghz/assets/setting_user")); - txrx->preset = malloc(sizeof(SubGhzRadioPreset)); - txrx->preset->name = furi_string_alloc(); - subghz_set_preset(txrx, "AM650", subghz_setting_get_default_frequency(txrx->setting), NULL, 0); + instance->preset = malloc(sizeof(SubGhzRadioPreset)); + instance->preset->name = furi_string_alloc(); + subghz_txrx_set_preset( + instance, "AM650", subghz_setting_get_default_frequency(instance->setting), NULL, 0); - txrx->txrx_state = SubGhzTxRxStateSleep; + instance->txrx_state = SubGhzTxRxStateSleep; - subghz_hopper_set_state(txrx, SubGhzHopperStateOFF); - subghz_speaker_set_state(txrx, SubGhzSpeakerStateDisable); - subghz_txrx_set_debug_pin_state(txrx, false); + subghz_txrx_hopper_set_state(instance, SubGhzHopperStateOFF); + subghz_txrx_speaker_set_state(instance, SubGhzSpeakerStateDisable); + subghz_txrx_set_debug_pin_state(instance, false); - txrx->worker = subghz_worker_alloc(); - txrx->fff_data = flipper_format_string_alloc(); + instance->worker = subghz_worker_alloc(); + instance->fff_data = flipper_format_string_alloc(); - txrx->environment = subghz_environment_alloc(); - txrx->load_database = subghz_environment_load_keystore( - txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); + instance->environment = subghz_environment_alloc(); + instance->load_database = subghz_environment_load_keystore( + instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); subghz_environment_load_keystore( - txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); + instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); subghz_environment_set_came_atomo_rainbow_table_file_name( - txrx->environment, EXT_PATH("subghz/assets/came_atomo")); + instance->environment, EXT_PATH("subghz/assets/came_atomo")); subghz_environment_set_alutech_at_4n_rainbow_table_file_name( - txrx->environment, EXT_PATH("subghz/assets/alutech_at_4n")); + instance->environment, EXT_PATH("subghz/assets/alutech_at_4n")); subghz_environment_set_nice_flor_s_rainbow_table_file_name( - txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); - subghz_environment_set_protocol_registry(txrx->environment, (void*)&subghz_protocol_registry); - txrx->receiver = subghz_receiver_alloc_init(txrx->environment); + instance->environment, EXT_PATH("subghz/assets/nice_flor_s")); + subghz_environment_set_protocol_registry( + instance->environment, (void*)&subghz_protocol_registry); + instance->receiver = subghz_receiver_alloc_init(instance->environment); subghz_worker_set_overrun_callback( - txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); + instance->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); subghz_worker_set_pair_callback( - txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); - subghz_worker_set_context(txrx->worker, txrx->receiver); + instance->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); + subghz_worker_set_context(instance->worker, instance->receiver); - return txrx; + return instance; } -void subghz_txrx_free(SubGhzTxRx* txrx) { - furi_assert(txrx); +void subghz_txrx_free(SubGhzTxRx* instance) { + furi_assert(instance); - subghz_worker_free(txrx->worker); - subghz_receiver_free(txrx->receiver); - subghz_environment_free(txrx->environment); - flipper_format_free(txrx->fff_data); - furi_string_free(txrx->preset->name); - subghz_setting_free(txrx->setting); - free(txrx->preset); - free(txrx); + subghz_worker_free(instance->worker); + subghz_receiver_free(instance->receiver); + subghz_environment_free(instance->environment); + flipper_format_free(instance->fff_data); + furi_string_free(instance->preset->name); + subghz_setting_free(instance->setting); + free(instance->preset); + free(instance); } -bool subghz_txrx_is_load_database(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->load_database; +bool subghz_txrx_is_load_database(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->load_database; } -void subghz_set_preset( - SubGhzTxRx* txrx, +void subghz_txrx_set_preset( + SubGhzTxRx* instance, const char* preset_name, uint32_t frequency, uint8_t* preset_data, size_t preset_data_size) { - furi_assert(txrx); - furi_string_set(txrx->preset->name, preset_name); - txrx->preset->frequency = frequency; - txrx->preset->data = preset_data; - txrx->preset->data_size = preset_data_size; + furi_assert(instance); + furi_string_set(instance->preset->name, preset_name); + instance->preset->frequency = frequency; + instance->preset->data = preset_data; + instance->preset->data_size = preset_data_size; } -const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset) { - UNUSED(txrx); +const char* subghz_txrx_get_name_preset(SubGhzTxRx* instance, const char* preset) { + UNUSED(instance); const char* preset_name = NULL; if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { preset_name = "AM270"; @@ -121,95 +122,96 @@ const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset) { return preset_name; } -SubGhzRadioPreset subghz_get_preset(SubGhzTxRx* txrx) { - furi_assert(txrx); - return *txrx->preset; +SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance) { + furi_assert(instance); + return *instance->preset; } -void subghz_get_frequency_modulation( - SubGhzTxRx* txrx, +void subghz_txrx_get_frequency_modulation( + SubGhzTxRx* instance, FuriString* frequency, FuriString* modulation, bool long_name) { - furi_assert(txrx); + furi_assert(instance); if(frequency != NULL) { furi_string_printf( frequency, "%03ld.%02ld", - txrx->preset->frequency / 1000000 % 1000, - txrx->preset->frequency / 10000 % 100); + instance->preset->frequency / 1000000 % 1000, + instance->preset->frequency / 10000 % 100); } if(modulation != NULL) { if(long_name) { - furi_string_printf(modulation, "%s", furi_string_get_cstr(txrx->preset->name)); + furi_string_printf(modulation, "%s", furi_string_get_cstr(instance->preset->name)); } else { - furi_string_printf(modulation, "%.2s", furi_string_get_cstr(txrx->preset->name)); + furi_string_printf(modulation, "%.2s", furi_string_get_cstr(instance->preset->name)); } } } -static void subghz_begin(SubGhzTxRx* txrx, uint8_t* preset_data) { - furi_assert(txrx); +static void subghz_txrx_begin(SubGhzTxRx* instance, uint8_t* preset_data) { + furi_assert(instance); furi_hal_subghz_reset(); furi_hal_subghz_idle(); furi_hal_subghz_load_custom_preset(preset_data); furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow); - txrx->txrx_state = SubGhzTxRxStateIDLE; + instance->txrx_state = SubGhzTxRxStateIDLE; } -static uint32_t subghz_rx(SubGhzTxRx* txrx, uint32_t frequency) { - furi_assert(txrx); +static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) { + furi_assert(instance); if(!furi_hal_subghz_is_frequency_valid(frequency)) { furi_crash("SubGhz: Incorrect RX frequency."); } - furi_assert(txrx->txrx_state != SubGhzTxRxStateRx && txrx->txrx_state != SubGhzTxRxStateSleep); + furi_assert( + instance->txrx_state != SubGhzTxRxStateRx && instance->txrx_state != SubGhzTxRxStateSleep); furi_hal_subghz_idle(); uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency); furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow); furi_hal_subghz_flush_rx(); - subghz_speaker_on(txrx); + subghz_txrx_speaker_on(instance); furi_hal_subghz_rx(); - furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, txrx->worker); - subghz_worker_start(txrx->worker); - txrx->txrx_state = SubGhzTxRxStateRx; + furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, instance->worker); + subghz_worker_start(instance->worker); + instance->txrx_state = SubGhzTxRxStateRx; return value; } -static void subghz_idle(SubGhzTxRx* txrx) { - furi_assert(txrx); - furi_assert(txrx->txrx_state != SubGhzTxRxStateSleep); +static void subghz_txrx_idle(SubGhzTxRx* instance) { + furi_assert(instance); + furi_assert(instance->txrx_state != SubGhzTxRxStateSleep); furi_hal_subghz_idle(); - subghz_speaker_off(txrx); - txrx->txrx_state = SubGhzTxRxStateIDLE; + subghz_txrx_speaker_off(instance); + instance->txrx_state = SubGhzTxRxStateIDLE; } -static void subghz_rx_end(SubGhzTxRx* txrx) { - furi_assert(txrx); - furi_assert(txrx->txrx_state == SubGhzTxRxStateRx); +static void subghz_txrx_rx_end(SubGhzTxRx* instance) { + furi_assert(instance); + furi_assert(instance->txrx_state == SubGhzTxRxStateRx); - if(subghz_worker_is_running(txrx->worker)) { - subghz_worker_stop(txrx->worker); + if(subghz_worker_is_running(instance->worker)) { + subghz_worker_stop(instance->worker); furi_hal_subghz_stop_async_rx(); } furi_hal_subghz_idle(); - subghz_speaker_off(txrx); - txrx->txrx_state = SubGhzTxRxStateIDLE; + subghz_txrx_speaker_off(instance); + instance->txrx_state = SubGhzTxRxStateIDLE; } -void subghz_sleep(SubGhzTxRx* txrx) { - furi_assert(txrx); +void subghz_txrx_sleep(SubGhzTxRx* instance) { + furi_assert(instance); furi_hal_subghz_sleep(); - txrx->txrx_state = SubGhzTxRxStateSleep; + instance->txrx_state = SubGhzTxRxStateSleep; } -static bool subghz_tx(SubGhzTxRx* txrx, uint32_t frequency) { - furi_assert(txrx); +static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) { + furi_assert(instance); if(!furi_hal_subghz_is_frequency_valid(frequency)) { furi_crash("SubGhz: Incorrect TX frequency."); } - furi_assert(txrx->txrx_state != SubGhzTxRxStateSleep); + furi_assert(instance->txrx_state != SubGhzTxRxStateSleep); furi_hal_subghz_idle(); furi_hal_subghz_set_frequency_and_path(frequency); furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false); @@ -217,17 +219,17 @@ static bool subghz_tx(SubGhzTxRx* txrx, uint32_t frequency) { furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); bool ret = furi_hal_subghz_tx(); if(ret) { - subghz_speaker_on(txrx); - txrx->txrx_state = SubGhzTxRxStateTx; + subghz_txrx_speaker_on(instance); + instance->txrx_state = SubGhzTxRxStateTx; } return ret; } -bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) { - furi_assert(txrx); +bool subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format) { + furi_assert(instance); furi_assert(flipper_format); - subghz_txrx_stop(txrx); + subghz_txrx_stop(instance); bool ret = false; FuriString* temp_str = furi_string_alloc(); @@ -246,33 +248,35 @@ bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) { break; } - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, furi_string_get_cstr(temp_str)); + instance->transmitter = + subghz_transmitter_alloc_init(instance->environment, furi_string_get_cstr(temp_str)); - if(txrx->transmitter) { - if(subghz_transmitter_deserialize(txrx->transmitter, flipper_format) == + if(instance->transmitter) { + if(subghz_transmitter_deserialize(instance->transmitter, flipper_format) == SubGhzProtocolStatusOk) { - if(strcmp(furi_string_get_cstr(txrx->preset->name), "") != 0) { - subghz_begin( - txrx, + if(strcmp(furi_string_get_cstr(instance->preset->name), "") != 0) { + subghz_txrx_begin( + instance, subghz_setting_get_preset_data_by_name( - txrx->setting, furi_string_get_cstr(txrx->preset->name))); + instance->setting, furi_string_get_cstr(instance->preset->name))); } else { FURI_LOG_E( TAG, "Unknown name preset \" %s \"", - furi_string_get_cstr(txrx->preset->name)); - subghz_begin( - txrx, subghz_setting_get_preset_data_by_name(txrx->setting, "AM650")); + furi_string_get_cstr(instance->preset->name)); + subghz_txrx_begin( + instance, + subghz_setting_get_preset_data_by_name(instance->setting, "AM650")); } - if(txrx->preset->frequency) { - ret = subghz_tx(txrx, txrx->preset->frequency); + if(instance->preset->frequency) { + ret = subghz_txrx_tx(instance, instance->preset->frequency); } else { - ret = subghz_tx(txrx, 433920000); + ret = subghz_txrx_tx(instance, 433920000); } if(ret) { //Start TX - furi_hal_subghz_start_async_tx(subghz_transmitter_yield, txrx->transmitter); + furi_hal_subghz_start_async_tx( + subghz_transmitter_yield, instance->transmitter); } else { //Todo: Show error //subghz_dialog_message_show_only_rx(subghz); @@ -284,9 +288,9 @@ bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) { } } if(!ret) { - subghz_transmitter_free(txrx->transmitter); - if(txrx->txrx_state != SubGhzTxRxStateSleep) { - subghz_idle(txrx); + subghz_transmitter_free(instance->transmitter); + if(instance->txrx_state != SubGhzTxRxStateIDLE) { + subghz_txrx_idle(instance); } } @@ -295,68 +299,68 @@ bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format) { return ret; } -void subghz_rx_start(SubGhzTxRx* txrx) { - furi_assert(txrx); - subghz_txrx_stop(txrx); - subghz_begin( - txrx, +void subghz_txrx_rx_start(SubGhzTxRx* instance) { + furi_assert(instance); + subghz_txrx_stop(instance); + subghz_txrx_begin( + instance, subghz_setting_get_preset_data_by_name( - subghz_txrx_get_setting(txrx), furi_string_get_cstr(txrx->preset->name))); - subghz_rx(txrx, txrx->preset->frequency); + subghz_txrx_get_setting(instance), furi_string_get_cstr(instance->preset->name))); + subghz_txrx_rx(instance, instance->preset->frequency); } void subghz_txrx_need_save_callback_set( - SubGhzTxRx* txrx, + SubGhzTxRx* instance, SubGhzTxRxNeedSaveCallback callback, void* context) { - furi_assert(txrx); - txrx->need_save_callback = callback; - txrx->need_save_context = context; + furi_assert(instance); + instance->need_save_callback = callback; + instance->need_save_context = context; } -static void subghz_tx_stop(SubGhzTxRx* txrx) { - furi_assert(txrx); - furi_assert(txrx->txrx_state == SubGhzTxRxStateTx); +static void subghz_txrx_tx_stop(SubGhzTxRx* instance) { + furi_assert(instance); + furi_assert(instance->txrx_state == SubGhzTxRxStateTx); //Stop TX furi_hal_subghz_stop_async_tx(); - subghz_transmitter_stop(txrx->transmitter); - subghz_transmitter_free(txrx->transmitter); + subghz_transmitter_stop(instance->transmitter); + subghz_transmitter_free(instance->transmitter); //if protocol dynamic then we save the last upload - if(txrx->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) { - if(txrx->need_save_callback) { - txrx->need_save_callback(txrx->need_save_context); + if(instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) { + if(instance->need_save_callback) { + instance->need_save_callback(instance->need_save_context); } } - subghz_idle(txrx); - subghz_speaker_off(txrx); + subghz_txrx_idle(instance); + subghz_txrx_speaker_off(instance); //Todo: Show message // notification_message(notifications, &sequence_reset_red); } -FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->fff_data; +FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->fff_data; } -SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->setting; +SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->setting; } -void subghz_txrx_stop(SubGhzTxRx* txrx) { - furi_assert(txrx); +void subghz_txrx_stop(SubGhzTxRx* instance) { + furi_assert(instance); - switch(txrx->txrx_state) { + switch(instance->txrx_state) { case SubGhzTxRxStateTx: - subghz_tx_stop(txrx); - subghz_speaker_unmute(txrx); - //subghz_sleep(txrx); + subghz_txrx_tx_stop(instance); + subghz_txrx_speaker_unmute(instance); + //subghz_txrx_sleep(txrx); break; case SubGhzTxRxStateRx: - subghz_rx_end(txrx); - subghz_speaker_mute(txrx); - //subghz_sleep(txrx); + subghz_txrx_rx_end(instance); + subghz_txrx_speaker_mute(instance); + //subghz_txrx_sleep(txrx); break; default: @@ -364,21 +368,21 @@ void subghz_txrx_stop(SubGhzTxRx* txrx) { } } -SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->txrx_state; +SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->txrx_state; } -void subghz_hopper_update(SubGhzTxRx* txrx) { - furi_assert(txrx); +void subghz_txrx_hopper_update(SubGhzTxRx* instance) { + furi_assert(instance); - switch(txrx->hopper_state) { + switch(instance->hopper_state) { case SubGhzHopperStateOFF: case SubGhzHopperStatePause: return; case SubGhzHopperStateRSSITimeOut: - if(txrx->hopper_timeout != 0) { - txrx->hopper_timeout--; + if(instance->hopper_timeout != 0) { + instance->hopper_timeout--; return; } break; @@ -386,205 +390,209 @@ void subghz_hopper_update(SubGhzTxRx* txrx) { break; } float rssi = -127.0f; - if(txrx->hopper_state != SubGhzHopperStateRSSITimeOut) { + if(instance->hopper_state != SubGhzHopperStateRSSITimeOut) { // See RSSI Calculation timings in CC1101 17.3 RSSI rssi = furi_hal_subghz_get_rssi(); // Stay if RSSI is high enough if(rssi > -90.0f) { - txrx->hopper_timeout = 10; - txrx->hopper_state = SubGhzHopperStateRSSITimeOut; + instance->hopper_timeout = 10; + instance->hopper_state = SubGhzHopperStateRSSITimeOut; return; } } else { - txrx->hopper_state = SubGhzHopperStateRunning; + instance->hopper_state = SubGhzHopperStateRunning; } // Select next frequency - if(txrx->hopper_idx_frequency < subghz_setting_get_hopper_frequency_count(txrx->setting) - 1) { - txrx->hopper_idx_frequency++; + if(instance->hopper_idx_frequency < + subghz_setting_get_hopper_frequency_count(instance->setting) - 1) { + instance->hopper_idx_frequency++; } else { - txrx->hopper_idx_frequency = 0; + instance->hopper_idx_frequency = 0; } - if(txrx->txrx_state == SubGhzTxRxStateRx) { - subghz_rx_end(txrx); + if(instance->txrx_state == SubGhzTxRxStateRx) { + subghz_txrx_rx_end(instance); }; - if(txrx->txrx_state == SubGhzTxRxStateIDLE) { - subghz_receiver_reset(txrx->receiver); - txrx->preset->frequency = - subghz_setting_get_hopper_frequency(txrx->setting, txrx->hopper_idx_frequency); - subghz_rx(txrx, txrx->preset->frequency); + if(instance->txrx_state == SubGhzTxRxStateIDLE) { + subghz_receiver_reset(instance->receiver); + instance->preset->frequency = + subghz_setting_get_hopper_frequency(instance->setting, instance->hopper_idx_frequency); + subghz_txrx_rx(instance, instance->preset->frequency); } } -SubGhzHopperState subghz_hopper_get_state(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->hopper_state; +SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->hopper_state; } -void subghz_hopper_set_state(SubGhzTxRx* txrx, SubGhzHopperState state) { - furi_assert(txrx); - txrx->hopper_state = state; +void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state) { + furi_assert(instance); + instance->hopper_state = state; } -void subghz_hopper_remove_pause(SubGhzTxRx* txrx) { - furi_assert(txrx); - if(txrx->hopper_state == SubGhzHopperStatePause) { - txrx->hopper_state = SubGhzHopperStateRunning; +void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance) { + furi_assert(instance); + if(instance->hopper_state == SubGhzHopperStatePause) { + instance->hopper_state = SubGhzHopperStateRunning; } } -void subghz_subghz_hopper_set_pause(SubGhzTxRx* txrx) { - furi_assert(txrx); - if(txrx->hopper_state == SubGhzHopperStateRunning) { - txrx->hopper_state = SubGhzHopperStatePause; +void subghz_txrx_hopper_set_pause(SubGhzTxRx* instance) { + furi_assert(instance); + if(instance->hopper_state == SubGhzHopperStateRunning) { + instance->hopper_state = SubGhzHopperStatePause; } } -void subghz_speaker_on(SubGhzTxRx* txrx) { - furi_assert(txrx); - if(txrx->debug_pin_state) { +void subghz_txrx_speaker_on(SubGhzTxRx* instance) { + furi_assert(instance); + if(instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); } - if(txrx->speaker_state == SubGhzSpeakerStateEnable) { + if(instance->speaker_state == SubGhzSpeakerStateEnable) { if(furi_hal_speaker_acquire(30)) { - if(!txrx->debug_pin_state) { + if(!instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(&gpio_speaker); } } else { - txrx->speaker_state = SubGhzSpeakerStateDisable; + instance->speaker_state = SubGhzSpeakerStateDisable; } } } -void subghz_speaker_off(SubGhzTxRx* txrx) { - furi_assert(txrx); - if(txrx->debug_pin_state) { +void subghz_txrx_speaker_off(SubGhzTxRx* instance) { + furi_assert(instance); + if(instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(NULL); } - if(txrx->speaker_state != SubGhzSpeakerStateDisable) { + if(instance->speaker_state != SubGhzSpeakerStateDisable) { if(furi_hal_speaker_is_mine()) { - if(!txrx->debug_pin_state) { + if(!instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(NULL); } furi_hal_speaker_release(); - if(txrx->speaker_state == SubGhzSpeakerStateShutdown) - txrx->speaker_state = SubGhzSpeakerStateDisable; + if(instance->speaker_state == SubGhzSpeakerStateShutdown) + instance->speaker_state = SubGhzSpeakerStateDisable; } } } -void subghz_speaker_mute(SubGhzTxRx* txrx) { - furi_assert(txrx); - if(txrx->debug_pin_state) { +void subghz_txrx_speaker_mute(SubGhzTxRx* instance) { + furi_assert(instance); + if(instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(NULL); } - if(txrx->speaker_state == SubGhzSpeakerStateEnable) { + if(instance->speaker_state == SubGhzSpeakerStateEnable) { if(furi_hal_speaker_is_mine()) { - if(!txrx->debug_pin_state) { + if(!instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(NULL); } } } } -void subghz_speaker_unmute(SubGhzTxRx* txrx) { - furi_assert(txrx); - if(txrx->debug_pin_state) { +void subghz_txrx_speaker_unmute(SubGhzTxRx* instance) { + furi_assert(instance); + if(instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); } - if(txrx->speaker_state == SubGhzSpeakerStateEnable) { + if(instance->speaker_state == SubGhzSpeakerStateEnable) { if(furi_hal_speaker_is_mine()) { - if(!txrx->debug_pin_state) { + if(!instance->debug_pin_state) { furi_hal_subghz_set_async_mirror_pin(&gpio_speaker); } } } } -void subghz_speaker_set_state(SubGhzTxRx* txrx, SubGhzSpeakerState state) { - furi_assert(txrx); - txrx->speaker_state = state; +void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState state) { + furi_assert(instance); + instance->speaker_state = state; } -SubGhzSpeakerState subghz_speaker_get_state(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->speaker_state; +SubGhzSpeakerState subghz_txrx_speaker_get_state(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->speaker_state; } -bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* txrx, const char* name_protocol) { - furi_assert(txrx); +bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol) { + furi_assert(instance); furi_assert(name_protocol); bool res = false; - txrx->decoder_result = NULL; - txrx->decoder_result = - subghz_receiver_search_decoder_base_by_name(txrx->receiver, name_protocol); - if(txrx->decoder_result) { + instance->decoder_result = NULL; + instance->decoder_result = + subghz_receiver_search_decoder_base_by_name(instance->receiver, name_protocol); + if(instance->decoder_result) { res = true; } return res; } -SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->decoder_result; +SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->decoder_result; } -bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* txrx) { - furi_assert(txrx); +bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* instance) { + furi_assert(instance); return ( - (txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == + (instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == SubGhzProtocolFlag_Save); } -bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type) { - furi_assert(txrx); +bool subghz_txrx_protocol_is_send(SubGhzTxRx* instance, bool check_type) { + furi_assert(instance); if(check_type) { return ( - ((txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == + ((instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && - txrx->decoder_result->protocol->encoder->deserialize && - txrx->decoder_result->protocol->type == SubGhzProtocolTypeStatic); + instance->decoder_result->protocol->encoder->deserialize && + instance->decoder_result->protocol->type == SubGhzProtocolTypeStatic); } return ( - ((txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == + ((instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && - txrx->decoder_result->protocol->encoder->deserialize); + instance->decoder_result->protocol->encoder->deserialize); } -void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter) { - furi_assert(txrx); - subghz_receiver_set_filter(txrx->receiver, filter); +void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter) { + furi_assert(instance); + subghz_receiver_set_filter(instance->receiver, filter); } -void subghz_txrx_set_rx_calback(SubGhzTxRx* txrx, SubGhzReceiverCallback callback, void* context) { - subghz_receiver_set_rx_callback(txrx->receiver, callback, context); +void subghz_txrx_set_rx_calback( + SubGhzTxRx* instance, + SubGhzReceiverCallback callback, + void* context) { + subghz_receiver_set_rx_callback(instance->receiver, callback, context); } void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( - SubGhzTxRx* txrx, + SubGhzTxRx* instance, SubGhzProtocolEncoderRAWCallbackEnd callback, void* context) { subghz_protocol_raw_file_encoder_worker_set_callback_end( - (SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(txrx->transmitter), + (SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(instance->transmitter), callback, context); } -void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state) { - furi_assert(txrx); - txrx->debug_pin_state = state; +void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state) { + furi_assert(instance); + instance->debug_pin_state = state; } -bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->debug_pin_state; +bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->debug_pin_state; } -SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx) { - furi_assert(txrx); - return txrx->receiver; +SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) { + furi_assert(instance); + return instance->receiver; } //#############Create new Key############## @@ -598,7 +606,7 @@ SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx) { #include #include -bool subghz_gen_data_protocol( +bool subghz_txrx_gen_data_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -606,15 +614,15 @@ bool subghz_gen_data_protocol( uint64_t key, uint32_t bit) { furi_assert(context); - SubGhzTxRx* txrx = context; + SubGhzTxRx* instance = context; bool res = false; - subghz_set_preset(txrx, preset_name, frequency, NULL, 0); - txrx->decoder_result = - subghz_receiver_search_decoder_base_by_name(txrx->receiver, protocol_name); + subghz_txrx_set_preset(instance, preset_name, frequency, NULL, 0); + instance->decoder_result = + subghz_receiver_search_decoder_base_by_name(instance->receiver, protocol_name); - if(txrx->decoder_result == NULL) { + if(instance->decoder_result == NULL) { //TODO: Error // furi_string_set(error_str, "Protocol not\nfound!"); // scene_manager_next_scene(scene_manager, SubGhzSceneShowErrorSub); @@ -622,14 +630,15 @@ bool subghz_gen_data_protocol( } do { - Stream* fff_data_stream = flipper_format_get_raw_stream(txrx->fff_data); + Stream* fff_data_stream = flipper_format_get_raw_stream(instance->fff_data); stream_clean(fff_data_stream); if(subghz_protocol_decoder_base_serialize( - txrx->decoder_result, txrx->fff_data, txrx->preset) != SubGhzProtocolStatusOk) { + instance->decoder_result, instance->fff_data, instance->preset) != + SubGhzProtocolStatusOk) { FURI_LOG_E(TAG, "Unable to serialize"); break; } - if(!flipper_format_update_uint32(txrx->fff_data, "Bit", &bit, 1)) { + if(!flipper_format_update_uint32(instance->fff_data, "Bit", &bit, 1)) { FURI_LOG_E(TAG, "Unable to update Bit"); break; } @@ -638,7 +647,7 @@ bool subghz_gen_data_protocol( for(size_t i = 0; i < sizeof(uint64_t); i++) { key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; } - if(!flipper_format_update_hex(txrx->fff_data, "Key", key_data, sizeof(uint64_t))) { + if(!flipper_format_update_hex(instance->fff_data, "Key", key_data, sizeof(uint64_t))) { FURI_LOG_E(TAG, "Unable to update Key"); break; } @@ -647,18 +656,18 @@ bool subghz_gen_data_protocol( return res; } -bool subghz_gen_data_protocol_and_te( - SubGhzTxRx* txrx, +bool subghz_txrx_gen_data_protocol_and_te( + SubGhzTxRx* instance, const char* preset_name, uint32_t frequency, const char* protocol_name, uint64_t key, uint32_t bit, uint32_t te) { - furi_assert(txrx); + furi_assert(instance); bool ret = false; - if(subghz_gen_data_protocol(txrx, preset_name, frequency, protocol_name, key, bit)) { - if(!flipper_format_update_uint32(txrx->fff_data, "TE", (uint32_t*)&te, 1)) { + if(subghz_txrx_gen_data_protocol(instance, preset_name, frequency, protocol_name, key, bit)) { + if(!flipper_format_update_uint32(instance->fff_data, "TE", (uint32_t*)&te, 1)) { FURI_LOG_E(TAG, "Unable to update Te"); } else { ret = true; @@ -681,7 +690,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_set_preset(txrx, preset_name, frequency, NULL, 0); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_keeloq_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -713,7 +722,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_set_preset(txrx, preset_name, frequency, NULL, 0); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_keeloq_bft_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -757,7 +766,7 @@ bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); - subghz_set_preset(txrx, preset_name, frequency, NULL, 0); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_nice_flor_s_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -790,7 +799,7 @@ bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME); - subghz_set_preset(txrx, preset_name, frequency, NULL, 0); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_faac_slh_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -831,7 +840,7 @@ bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); - subghz_set_preset(txrx, preset_name, frequency, NULL, 0); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_alutech_at_4n_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -861,7 +870,7 @@ bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); - subghz_set_preset(txrx, preset_name, frequency, NULL, 0); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); if(txrx->transmitter && subghz_protocol_somfy_telis_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -878,7 +887,7 @@ bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename return res; } -bool subghz_gen_secplus_v2_protocol( +bool subghz_txrx_gen_secplus_v2_protocol( SubGhzTxRx* txrx, const char* name_preset, uint32_t frequency, @@ -890,7 +899,7 @@ bool subghz_gen_secplus_v2_protocol( bool ret = false; txrx->transmitter = subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_set_preset(txrx, name_preset, frequency, NULL, 0); + subghz_txrx_set_preset(txrx, name_preset, frequency, NULL, 0); if(txrx->transmitter) { subghz_protocol_secplus_v2_create_data( subghz_transmitter_get_protocol_instance(txrx->transmitter), @@ -904,7 +913,10 @@ bool subghz_gen_secplus_v2_protocol( return ret; } -bool subghz_gen_secplus_v1_protocol(SubGhzTxRx* txrx, const char* name_preset, uint32_t frequency) { +bool subghz_txrx_gen_secplus_v1_protocol( + SubGhzTxRx* txrx, + const char* name_preset, + uint32_t frequency) { furi_assert(txrx); bool ret = false; @@ -912,7 +924,7 @@ bool subghz_gen_secplus_v1_protocol(SubGhzTxRx* txrx, const char* name_preset, u while(!subghz_protocol_secplus_v1_check_fixed(serial)) { serial = (uint32_t)rand(); } - if(subghz_gen_data_protocol( + if(subghz_txrx_gen_data_protocol( txrx, name_preset, frequency, diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/helpers/subghz_txrx.h similarity index 50% rename from applications/main/subghz/subghz_radio.h rename to applications/main/subghz/helpers/subghz_txrx.h index dc6834ac1..cb50e8334 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -1,84 +1,84 @@ #pragma once -//#include "subghz_i.h" -#include "helpers/subghz_types.h" +#include "subghz_types.h" #include #include #include #include #include -#include "subghz_history.h" - typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); typedef struct SubGhzTxRx SubGhzTxRx; SubGhzTxRx* subghz_txrx_alloc(); -void subghz_txrx_free(SubGhzTxRx* txrx); -bool subghz_txrx_is_load_database(SubGhzTxRx* txrx); +void subghz_txrx_free(SubGhzTxRx* instance); +bool subghz_txrx_is_load_database(SubGhzTxRx* instance); -void subghz_set_preset( - SubGhzTxRx* txrx, +void subghz_txrx_set_preset( + SubGhzTxRx* instance, const char* preset_name, uint32_t frequency, uint8_t* preset_data, size_t preset_data_size); -const char* subghz_get_name_preset(SubGhzTxRx* txrx, const char* preset); -SubGhzRadioPreset subghz_get_preset(SubGhzTxRx* txrx); +const char* subghz_txrx_get_name_preset(SubGhzTxRx* instance, const char* preset); +SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance); -void subghz_get_frequency_modulation( - SubGhzTxRx* txrx, +void subghz_txrx_get_frequency_modulation( + SubGhzTxRx* instance, FuriString* frequency, FuriString* modulation, bool long_name); -bool subghz_tx_start(SubGhzTxRx* txrx, FlipperFormat* flipper_format); -void subghz_rx_start(SubGhzTxRx* txrx); -void subghz_txrx_stop(SubGhzTxRx* txrx); -void subghz_sleep(SubGhzTxRx* txrx); +bool subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format); +void subghz_txrx_rx_start(SubGhzTxRx* instance); +void subghz_txrx_stop(SubGhzTxRx* instance); +void subghz_txrx_sleep(SubGhzTxRx* instance); -SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* txrx); +SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* instance); -void subghz_hopper_update(SubGhzTxRx* txrx); -SubGhzHopperState subghz_hopper_get_state(SubGhzTxRx* txrx); -void subghz_hopper_set_state(SubGhzTxRx* txrx, SubGhzHopperState state); -void subghz_hopper_remove_pause(SubGhzTxRx* txrx); -void subghz_subghz_hopper_set_pause(SubGhzTxRx* txrx); +void subghz_txrx_hopper_update(SubGhzTxRx* instance); +SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance); +void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state); +void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance); +void subghz_txrx_hopper_set_pause(SubGhzTxRx* instance); -void subghz_speaker_on(SubGhzTxRx* txrx); -void subghz_speaker_off(SubGhzTxRx* txrx); -void subghz_speaker_mute(SubGhzTxRx* txrx); -void subghz_speaker_unmute(SubGhzTxRx* txrx); -void subghz_speaker_set_state(SubGhzTxRx* txrx, SubGhzSpeakerState state); -SubGhzSpeakerState subghz_speaker_get_state(SubGhzTxRx* txrx); -bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* txrx, const char* name_protocol); -SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* txrx); +void subghz_txrx_speaker_on(SubGhzTxRx* instance); +void subghz_txrx_speaker_off(SubGhzTxRx* instance); +void subghz_txrx_speaker_mute(SubGhzTxRx* instance); +void subghz_txrx_speaker_unmute(SubGhzTxRx* instance); +void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState state); +SubGhzSpeakerState subghz_txrx_speaker_get_state(SubGhzTxRx* instance); +bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol); +SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance); void subghz_txrx_need_save_callback_set( - SubGhzTxRx* txrx, + SubGhzTxRx* instance, SubGhzTxRxNeedSaveCallback callback, void* context); -FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* txrx); -SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* txrx); +FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* instance); +SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance); -bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* txrx); -bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type); +bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* instance); +bool subghz_txrx_protocol_is_send(SubGhzTxRx* instance, bool check_type); -void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter); +void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter); -void subghz_txrx_set_rx_calback(SubGhzTxRx* txrx, SubGhzReceiverCallback callback, void* context); +void subghz_txrx_set_rx_calback( + SubGhzTxRx* instance, + SubGhzReceiverCallback callback, + void* context); void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( - SubGhzTxRx* txrx, + SubGhzTxRx* instance, SubGhzProtocolEncoderRAWCallbackEnd callback, void* context); -void subghz_txrx_set_debug_pin_state(SubGhzTxRx* txrx, bool state); -bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* txrx); +void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state); +bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance); -SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx); // TODO use only in DecodeRaw +SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw //#############Create new Key############## -bool subghz_gen_data_protocol( +bool subghz_txrx_gen_data_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -86,8 +86,8 @@ bool subghz_gen_data_protocol( uint64_t key, uint32_t bit); -bool subghz_gen_data_protocol_and_te( - SubGhzTxRx* txrx, +bool subghz_txrx_gen_data_protocol_and_te( + SubGhzTxRx* instance, const char* preset_name, uint32_t frequency, const char* protocol_name, @@ -149,7 +149,7 @@ bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename uint8_t btn, uint16_t cnt); -bool subghz_gen_secplus_v2_protocol( +bool subghz_txrx_gen_secplus_v2_protocol( SubGhzTxRx* txrx, const char* name_preset, uint32_t frequency, @@ -157,4 +157,7 @@ bool subghz_gen_secplus_v2_protocol( uint8_t btn, uint32_t cnt); -bool subghz_gen_secplus_v1_protocol(SubGhzTxRx* txrx, const char* name_preset, uint32_t frequency); \ No newline at end of file +bool subghz_txrx_gen_secplus_v1_protocol( + SubGhzTxRx* txrx, + const char* name_preset, + uint32_t frequency); \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index ef431a2c6..f008db380 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -29,7 +29,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); subghz_view_receiver_add_data_statusbar( subghz->subghz_receiver, @@ -61,7 +61,7 @@ static void subghz_scene_add_to_history_callback( FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); uint16_t idx = subghz_history_get_item(subghz->history); - SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) { furi_string_reset(item_name); diff --git a/applications/main/subghz/scenes/subghz_scene_delete.c b/applications/main/subghz/scenes/subghz_scene_delete.c index cf0bdefb1..095cdf899 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete.c +++ b/applications/main/subghz/scenes/subghz_scene_delete.c @@ -15,7 +15,7 @@ void subghz_scene_delete_on_enter(void* context) { FuriString* modulation_str = furi_string_alloc(); FuriString* text = furi_string_alloc(); - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 78, diff --git a/applications/main/subghz/scenes/subghz_scene_delete_raw.c b/applications/main/subghz/scenes/subghz_scene_delete_raw.c index ed960d666..bc8a4d6ef 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_delete_raw.c @@ -30,7 +30,7 @@ void subghz_scene_delete_raw_on_enter(void* context) { widget_add_string_element( subghz->widget, 38, 25, AlignLeft, AlignTop, FontSecondary, "RAW signal"); - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 35, diff --git a/applications/main/subghz/scenes/subghz_scene_need_saving.c b/applications/main/subghz/scenes/subghz_scene_need_saving.c index b0fc70b8b..c249ff282 100644 --- a/applications/main/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/main/subghz/scenes/subghz_scene_need_saving.c @@ -48,7 +48,7 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { } else if(event.event == SubGhzCustomEventSceneExit) { if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateExit) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 5b20b04b1..298ffda06 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -41,8 +41,8 @@ static void subghz_scene_read_raw_update_statusbar(void* context) { FuriString* modulation_str = furi_string_alloc(); #ifdef SUBGHZ_EXT_PRESET_NAME - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, true); - //TODO if need subghz_get_preset + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, true); + //TODO if need subghz_txrx_get_preset //furi_string_printf(modulation_str, "%s", furi_string_get_cstr(subghz->txrx->preset->name)); #else subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); @@ -140,7 +140,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { } else { //Restore default setting if(subghz->raw_send_only) { - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, "AM650", subghz_setting_get_default_frequency( @@ -148,7 +148,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { NULL, 0); } else { - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); } if(!scene_manager_search_and_switch_to_previous_scene( @@ -215,7 +215,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); - if(!subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { + if(!subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); subghz_read_raw_set_status( subghz->subghz_read_raw, @@ -280,13 +280,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateIDLE) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { - SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); if(subghz_protocol_raw_save_to_file_init( (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx), RAW_FILE_NAME, &preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); - subghz_rx_start(subghz->txrx); + subghz_txrx_rx_start(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 32e9cf6c8..7570d822d 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -46,11 +46,12 @@ static void subghz_scene_receiver_update_statusbar(void* context) { #ifdef SUBGHZ_EXT_PRESET_NAME if(subghz_history_get_last_index(subghz->history) > 0) { - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation( + subghz->txrx, frequency_str, modulation_str, false); } else { FuriString* temp_str = furi_string_alloc(); - subghz_get_frequency_modulation(subghz->txrx, frequency_str, temp_str, true); + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, temp_str, true); furi_string_printf( modulation_str, "%s Mod: %s", @@ -59,7 +60,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_free(temp_str); } #else - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); #endif subghz_view_receiver_add_data_statusbar( @@ -96,7 +97,7 @@ static void subghz_scene_add_to_history_callback( FuriString* item_time = furi_string_alloc(); uint16_t idx = subghz_history_get_item(subghz->history); - SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) { furi_string_reset(item_name); furi_string_reset(item_time); @@ -126,7 +127,7 @@ void subghz_scene_receiver_on_enter(void* context) { FuriString* item_time = furi_string_alloc(); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) { - subghz_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); subghz_history_reset(subghz->history); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); } @@ -183,7 +184,7 @@ void subghz_scene_receiver_on_enter(void* context) { subghz->state_notifications = SubGhzNotificationStateRx; subghz_txrx_stop(subghz->txrx); - subghz_rx_start(subghz->txrx); + subghz_txrx_rx_start(subghz->txrx); subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen); //to use a universal decoder, we are looking for a link to it @@ -202,7 +203,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { // Stop CC1101 Rx subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); - subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); + subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); subghz->idx_menu_chosen = 0; subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz); @@ -211,7 +212,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); @@ -254,8 +255,8 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { break; } } else if(event.type == SceneManagerEventTypeTick) { - if(subghz_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { - subghz_hopper_update(subghz->txrx); + if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { + subghz_txrx_hopper_update(subghz->txrx); subghz_scene_receiver_update_statusbar(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 45b88b79b..d65778b01 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -149,7 +149,7 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - if(subghz_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { + if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { char text_buf[10] = {0}; snprintf( text_buf, @@ -161,16 +161,16 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { 10000); variable_item_set_current_value_text(item, text_buf); - SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset.name), subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index), preset.data, preset.data_size); - preset = subghz_get_preset(subghz->txrx); + preset = subghz_txrx_get_preset(subghz->txrx); subghz->last_settings->frequency = preset.frequency; subghz_setting_set_default_frequency( @@ -189,9 +189,9 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), index); variable_item_set_current_value_text(item, preset_name); //subghz->last_settings->preset = index; - SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, preset_name, preset.frequency, @@ -218,8 +218,8 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), text_buf); - SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); - subghz_set_preset( + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); + subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset.name), subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)), @@ -240,7 +240,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx))); } - subghz_hopper_set_state(subghz->txrx, hopping_value[index]); + subghz_txrx_hopper_set_state(subghz->txrx, hopping_value[index]); } static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { @@ -248,7 +248,7 @@ static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, speaker_text[index]); - subghz_speaker_set_state(subghz->txrx, speaker_value[index]); + subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[index]); } static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) { @@ -305,7 +305,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { SubGhz* subghz = context; VariableItem* item; uint8_t value_index; - SubGhzRadioPreset preset = subghz_get_preset(subghz->txrx); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); item = variable_item_list_add( subghz->variable_item_list, @@ -350,7 +350,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_hopping_running, subghz); value_index = subghz_scene_receiver_config_hopper_value_index( - subghz_hopper_get_state(subghz->txrx), hopping_value, HOPPING_COUNT, subghz); + subghz_txrx_hopper_get_state(subghz->txrx), hopping_value, HOPPING_COUNT, subghz); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, hopping_text[value_index]); } @@ -412,7 +412,7 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz_scene_receiver_config_set_speaker, subghz); value_index = - value_index_uint32(subghz_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT); + value_index_uint32(subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, speaker_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 f3cfd0962..019898025 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -34,7 +34,7 @@ static bool subghz_scene_receiver_info_update_parser(void* context) { SubGhzRadioPreset* preset = subghz_history_get_radio_preset(subghz->history, subghz->idx_menu_chosen); - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset->name), preset->frequency, @@ -52,7 +52,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { FuriString* modulation_str = furi_string_alloc(); FuriString* text = furi_string_alloc(); - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 78, @@ -118,17 +118,17 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) { //CC1101 Stop RX -> Start TX - subghz_subghz_hopper_set_pause(subghz->txrx); + subghz_txrx_hopper_set_pause(subghz->txrx); if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } - if(!subghz_tx_start( + if(!subghz_txrx_tx_start( subghz->txrx, subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen))) { - subghz_rx_start(subghz->txrx); - subghz_hopper_remove_pause(subghz->txrx); + subghz_txrx_rx_start(subghz->txrx); + subghz_txrx_hopper_remove_pause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; } else { subghz->state_notifications = SubGhzNotificationStateTx; @@ -143,16 +143,16 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) subghz_txrx_stop(subghz->txrx); if(!subghz->in_decoder_scene) { - subghz_rx_start(subghz->txrx); + subghz_txrx_rx_start(subghz->txrx); - subghz_hopper_remove_pause(subghz->txrx); + subghz_txrx_hopper_remove_pause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; } return true; } else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) { //CC1101 Stop RX -> Save subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); + subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); subghz_txrx_stop(subghz->txrx); if(!subghz_scene_receiver_info_update_parser(subghz)) { @@ -170,8 +170,8 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) return true; } } else if(event.type == SceneManagerEventTypeTick) { - if(subghz_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { - subghz_hopper_update(subghz->txrx); + if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { + subghz_txrx_hopper_update(subghz->txrx); } switch(subghz->state_notifications) { case SubGhzNotificationStateTx: diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 2af4112cf..680eae7bc 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -44,7 +44,7 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { bool result = false; if((subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateSleep) && (state == SubGhzRpcStateLoaded)) { - result = subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx)); + result = subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx)); if(result) subghz_blink_start(subghz); } if(!result) { diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index 4bbf1c769..87ef6b0af 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -305,64 +305,64 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { break; case SubmenuIndexPricenton433: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - generated_protocol = subghz_gen_data_protocol_and_te( + generated_protocol = subghz_txrx_gen_data_protocol_and_te( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); break; case SubmenuIndexPricenton315: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - generated_protocol = subghz_gen_data_protocol_and_te( + generated_protocol = subghz_txrx_gen_data_protocol_and_te( subghz->txrx, "AM650", 315000000, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 400); break; case SubmenuIndexNiceFlo12bit: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 12); break; case SubmenuIndexNiceFlo24bit: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 24); break; case SubmenuIndexCAME12bit: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); break; case SubmenuIndexCAME24bit: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); break; case SubmenuIndexCAME12bit868: key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4 - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 12); break; case SubmenuIndexCAME24bit868: key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8 - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 868350000, SUBGHZ_PROTOCOL_CAME_NAME, key, 24); break; case SubmenuIndexLinear_300_00: key = (key & 0x3FF); - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 300000000, SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10); break; case SubmenuIndexBETT_433: key = (key & 0x0000FFF0); - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_BETT_NAME, key, 18); break; case SubmenuIndexCAMETwee: key = (key & 0x0FFFFFF0); key = 0x003FFF7200000000 | (key ^ 0xE0E0E0EE); - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_CAME_TWEE_NAME, key, 54); break; case SubmenuIndexGateTX: key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?) uint64_t rev_key = subghz_protocol_blocks_reverse_key(key, 24); - generated_protocol = subghz_gen_data_protocol( + generated_protocol = subghz_txrx_gen_data_protocol( subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24); break; case SubmenuIndexBeninca433: @@ -613,28 +613,28 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexLiftMaster_315_00: - generated_protocol = subghz_gen_secplus_v1_protocol(subghz->txrx, "AM650", 315000000); + generated_protocol = subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 315000000); break; case SubmenuIndexLiftMaster_390_00: - generated_protocol = subghz_gen_secplus_v1_protocol(subghz->txrx, "AM650", 390000000); + generated_protocol = subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 390000000); break; case SubmenuIndexLiftMaster_433_00: - generated_protocol = subghz_gen_secplus_v1_protocol(subghz->txrx, "AM650", 433920000); + generated_protocol = subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 433920000); break; case SubmenuIndexSecPlus_v2_310_00: - generated_protocol = subghz_gen_secplus_v2_protocol( + generated_protocol = subghz_txrx_gen_secplus_v2_protocol( subghz->txrx, "AM650", 310000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_315_00: - generated_protocol = subghz_gen_secplus_v2_protocol( + generated_protocol = subghz_txrx_gen_secplus_v2_protocol( subghz->txrx, "AM650", 315000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_390_00: - generated_protocol = subghz_gen_secplus_v2_protocol( + generated_protocol = subghz_txrx_gen_secplus_v2_protocol( subghz->txrx, "AM650", 390000000, key, 0x68, 0xE500000); break; case SubmenuIndexSecPlus_v2_433_00: - generated_protocol = subghz_gen_secplus_v2_protocol( + generated_protocol = subghz_txrx_gen_secplus_v2_protocol( subghz->txrx, "AM650", 433920000, key, 0x68, 0xE500000); break; default: diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index d5bd45618..305217f7d 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -26,7 +26,7 @@ bool subghz_scene_transmitter_update_data_show(void* context) { subghz_protocol_decoder_base_get_string( subghz_txrx_get_decoder(subghz->txrx), key_str); - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); subghz_view_transmitter_add_data_to_show( subghz->subghz_transmitter, furi_string_get_cstr(key_str), @@ -66,7 +66,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { + if(subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { subghz->state_notifications = SubGhzNotificationStateTx; subghz_scene_transmitter_update_data_show(subghz); DOLPHIN_DEED(DolphinDeedSubGhzSend); @@ -82,7 +82,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { // Calling restore! subghz_txrx_stop(subghz->txrx); - if(!subghz_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { + if(!subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index f4fc1aa94..ac6297d9e 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -51,14 +51,14 @@ static void subghz_rpc_command_callback(RpcAppSystemEvent event, void* context) } } -void subghz_blink_start(SubGhz* instance) { - furi_assert(instance); - notification_message(instance->notifications, &sequence_blink_start_magenta); +void subghz_blink_start(SubGhz* subghz) { + furi_assert(subghz); + notification_message(subghz->notifications, &sequence_blink_start_magenta); } -void subghz_blink_stop(SubGhz* instance) { - furi_assert(instance); - notification_message(instance->notifications, &sequence_blink_stop); +void subghz_blink_stop(SubGhz* subghz) { + furi_assert(subghz); + notification_message(subghz->notifications, &sequence_blink_stop); } SubGhz* subghz_alloc(bool alloc_for_tx_only) { @@ -262,7 +262,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { } if(!alloc_for_tx_only) { - subghz_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); } subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); @@ -295,9 +295,9 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { subghz->rpc_ctx = NULL; } - subghz_speaker_off(subghz->txrx); + subghz_txrx_speaker_off(subghz->txrx); subghz_txrx_stop(subghz->txrx); - subghz_sleep(subghz->txrx); + subghz_txrx_sleep(subghz->txrx); #if FURI_DEBUG // Packet Test diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 25e81725b..03aaa6da6 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -91,7 +91,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } furi_string_set_str( - temp_str, subghz_get_name_preset(subghz->txrx, furi_string_get_cstr(temp_str))); + temp_str, subghz_txrx_get_name_preset(subghz->txrx, furi_string_get_cstr(temp_str))); if(temp_str == NULL) { break; } @@ -112,7 +112,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } size_t preset_index = subghz_setting_get_inx_preset_by_name( subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(temp_str)); - subghz_set_preset( + subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(temp_str), temp_data32, diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index a9594b789..82cc71752 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -43,7 +43,7 @@ #include "helpers/subghz_threshold_rssi.h" -#include "subghz_radio.h" +#include "helpers/subghz_txrx.h" #define SUBGHZ_MAX_LEN_NAME 64 #define SUBGHZ_EXT_PRESET_NAME true @@ -120,8 +120,8 @@ struct SubGhz { void* rpc_ctx; }; -void subghz_blink_start(SubGhz* instance); -void subghz_blink_stop(SubGhz* instance); +void subghz_blink_start(SubGhz* subghz); +void subghz_blink_stop(SubGhz* subghz); void subghz_dialog_message_show_only_rx(SubGhz* subghz); bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog); From c69b2086b0942c3c1ccd3a233b26a8a13079178d Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 19:33:45 +0300 Subject: [PATCH 18/36] SubGhz: refactoring --- .../main/subghz/helpers/subghz_txrx.c | 5 +---- .../main/subghz/helpers/subghz_txrx.h | 2 +- .../subghz/scenes/subghz_scene_read_raw.c | 8 +------ .../scenes/subghz_scene_receiver_info.c | 5 ++--- applications/main/subghz/subghz.c | 12 ----------- applications/main/subghz/subghz_i.c | 21 +++++++++++++++++++ applications/main/subghz/subghz_i.h | 7 +++---- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index c99b95e09..f400a1a52 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -355,12 +355,10 @@ void subghz_txrx_stop(SubGhzTxRx* instance) { case SubGhzTxRxStateTx: subghz_txrx_tx_stop(instance); subghz_txrx_speaker_unmute(instance); - //subghz_txrx_sleep(txrx); break; case SubGhzTxRxStateRx: subghz_txrx_rx_end(instance); subghz_txrx_speaker_mute(instance); - //subghz_txrx_sleep(txrx); break; default: @@ -439,7 +437,7 @@ void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance) { } } -void subghz_txrx_hopper_set_pause(SubGhzTxRx* instance) { +void subghz_txrx_hopper_pause(SubGhzTxRx* instance) { furi_assert(instance); if(instance->hopper_state == SubGhzHopperStateRunning) { instance->hopper_state = SubGhzHopperStatePause; @@ -522,7 +520,6 @@ bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* furi_assert(instance); furi_assert(name_protocol); bool res = false; - instance->decoder_result = NULL; instance->decoder_result = subghz_receiver_search_decoder_base_by_name(instance->receiver, name_protocol); if(instance->decoder_result) { diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index cb50e8334..c1ef132a4 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -40,7 +40,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance); SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance); void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state); void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance); -void subghz_txrx_hopper_set_pause(SubGhzTxRx* instance); +void subghz_txrx_hopper_pause(SubGhzTxRx* instance); void subghz_txrx_speaker_on(SubGhzTxRx* instance); void subghz_txrx_speaker_off(SubGhzTxRx* instance); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 298ffda06..b7131e66e 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -140,13 +140,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { } else { //Restore default setting if(subghz->raw_send_only) { - subghz_txrx_set_preset( - subghz->txrx, - "AM650", - subghz_setting_get_default_frequency( - subghz_txrx_get_setting(subghz->txrx)), - NULL, - 0); + subghz_set_defalut_preset(subghz); } else { subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 019898025..4e0e9e26f 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -117,13 +117,12 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) SubGhz* subghz = context; if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) { - //CC1101 Stop RX -> Start TX - subghz_txrx_hopper_set_pause(subghz->txrx); - if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } + //CC1101 Stop RX -> Start TX + subghz_txrx_hopper_pause(subghz->txrx); if(!subghz_txrx_tx_start( subghz->txrx, subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen))) { diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index ac6297d9e..4bf6e7aaf 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -51,16 +51,6 @@ static void subghz_rpc_command_callback(RpcAppSystemEvent event, void* context) } } -void subghz_blink_start(SubGhz* subghz) { - furi_assert(subghz); - notification_message(subghz->notifications, &sequence_blink_start_magenta); -} - -void subghz_blink_stop(SubGhz* subghz) { - furi_assert(subghz); - notification_message(subghz->notifications, &sequence_blink_stop); -} - SubGhz* subghz_alloc(bool alloc_for_tx_only) { SubGhz* subghz = malloc(sizeof(SubGhz)); @@ -274,9 +264,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->secure_data = malloc(sizeof(SecureData)); subghz->filter = SubGhzProtocolFlag_Decodable; - subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); - subghz_txrx_need_save_callback_set(subghz->txrx, subghz_save_to_file, subghz); //Init Error_str diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 03aaa6da6..101ffdfdf 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -18,6 +18,27 @@ #define TAG "SubGhz" +void subghz_set_defalut_preset(SubGhz* subghz) { + furi_assert(subghz); + subghz_txrx_set_preset( + subghz->txrx, + "AM650", + subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)), + NULL, + 0); +} + +void subghz_blink_start(SubGhz* subghz) { + furi_assert(subghz); + notification_message(subghz->notifications, &sequence_blink_stop); + notification_message(subghz->notifications, &sequence_blink_start_magenta); +} + +void subghz_blink_stop(SubGhz* subghz) { + furi_assert(subghz); + notification_message(subghz->notifications, &sequence_blink_stop); +} + void subghz_dialog_message_show_only_rx(SubGhz* subghz) { DialogsApp* dialogs = subghz->dialogs; DialogMessage* message = dialog_message_alloc(); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 82cc71752..e955d8360 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -120,32 +120,31 @@ struct SubGhz { void* rpc_ctx; }; +void subghz_set_defalut_preset(SubGhz* subghz); void subghz_blink_start(SubGhz* subghz); void subghz_blink_stop(SubGhz* subghz); void subghz_dialog_message_show_only_rx(SubGhz* subghz); + bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog); bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len); bool subghz_save_protocol_to_file( SubGhz* subghz, FlipperFormat* flipper_format, const char* dev_file_name); - void subghz_save_to_file(void* context); - bool subghz_load_protocol_from_file(SubGhz* subghz); bool subghz_rename_file(SubGhz* subghz); bool subghz_file_available(SubGhz* subghz); bool subghz_delete_file(SubGhz* subghz); void subghz_file_name_clear(SubGhz* subghz); bool subghz_path_is_file(FuriString* path); +SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); void subghz_lock(SubGhz* subghz); void subghz_unlock(SubGhz* subghz); bool subghz_is_locked(SubGhz* subghz); -SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); - void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state); SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz); From 21cd94cc7953fefde53bf39058c5a0398e7c3849 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 19:50:01 +0300 Subject: [PATCH 19/36] SubGhz: show error tx start --- .../main/subghz/helpers/subghz_txrx.c | 32 ++++++++----------- .../main/subghz/helpers/subghz_txrx.h | 8 ++++- .../subghz/scenes/subghz_scene_read_raw.c | 2 +- .../scenes/subghz_scene_receiver_info.c | 4 +-- .../main/subghz/scenes/subghz_scene_rpc.c | 2 +- .../subghz/scenes/subghz_scene_transmitter.c | 7 ++-- applications/main/subghz/subghz_i.c | 17 ++++++++++ applications/main/subghz/subghz_i.h | 1 + 8 files changed, 47 insertions(+), 26 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index f400a1a52..c5118e67d 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -225,13 +225,13 @@ static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) { return ret; } -bool subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format) { +SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format) { furi_assert(instance); furi_assert(flipper_format); subghz_txrx_stop(instance); - bool ret = false; + SubGhzTxRxStartTxState ret = SubGhzTxRxStartTxStateErrorParserOthers; FuriString* temp_str = furi_string_alloc(); uint32_t repeat = 200; do { @@ -259,35 +259,31 @@ bool subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format) { instance, subghz_setting_get_preset_data_by_name( instance->setting, furi_string_get_cstr(instance->preset->name))); + if(instance->preset->frequency) { + if(!subghz_txrx_tx(instance, instance->preset->frequency)) { + FURI_LOG_E(TAG, "Only Rx"); + ret = SubGhzTxRxStartTxStateErrorOnlyRx; + } + } else { + ret = SubGhzTxRxStartTxStateErrorParserOthers; + } } else { FURI_LOG_E( TAG, "Unknown name preset \" %s \"", furi_string_get_cstr(instance->preset->name)); - subghz_txrx_begin( - instance, - subghz_setting_get_preset_data_by_name(instance->setting, "AM650")); + ret = SubGhzTxRxStartTxStateErrorParserOthers; } - if(instance->preset->frequency) { - ret = subghz_txrx_tx(instance, instance->preset->frequency); - } else { - ret = subghz_txrx_tx(instance, 433920000); - } - if(ret) { + if(ret == SubGhzTxRxStartTxStateOk) { //Start TX furi_hal_subghz_start_async_tx( subghz_transmitter_yield, instance->transmitter); - } else { - //Todo: Show error - //subghz_dialog_message_show_only_rx(subghz); } } else { - //Todo: Show error - // dialog_message_show_storage_error( - // dialogs, "Error in protocol\nparameters\ndescription"); + ret = SubGhzTxRxStartTxStateErrorParserOthers; } } - if(!ret) { + if(ret != SubGhzTxRxStartTxStateOk) { subghz_transmitter_free(instance->transmitter); if(instance->txrx_state != SubGhzTxRxStateIDLE) { subghz_txrx_idle(instance); diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index c1ef132a4..4b7c28f3c 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -10,6 +10,12 @@ typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); typedef struct SubGhzTxRx SubGhzTxRx; +typedef enum { + SubGhzTxRxStartTxStateOk, + SubGhzTxRxStartTxStateErrorOnlyRx, + SubGhzTxRxStartTxStateErrorParserOthers, +} SubGhzTxRxStartTxState; + SubGhzTxRx* subghz_txrx_alloc(); void subghz_txrx_free(SubGhzTxRx* instance); bool subghz_txrx_is_load_database(SubGhzTxRx* instance); @@ -29,7 +35,7 @@ void subghz_txrx_get_frequency_modulation( FuriString* frequency, FuriString* modulation, bool long_name); -bool subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format); +SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format); void subghz_txrx_rx_start(SubGhzTxRx* instance); void subghz_txrx_stop(SubGhzTxRx* instance); void subghz_txrx_sleep(SubGhzTxRx* instance); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index b7131e66e..f4749df65 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -209,7 +209,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); - if(!subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { + if(!subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx))) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); subghz_read_raw_set_status( subghz->subghz_read_raw, diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 4e0e9e26f..c92573e85 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -123,8 +123,8 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) //CC1101 Stop RX -> Start TX subghz_txrx_hopper_pause(subghz->txrx); - if(!subghz_txrx_tx_start( - subghz->txrx, + if(!subghz_tx_start( + subghz, subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen))) { subghz_txrx_rx_start(subghz->txrx); subghz_txrx_hopper_remove_pause(subghz->txrx); diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 680eae7bc..70c909756 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -44,7 +44,7 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { bool result = false; if((subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateSleep) && (state == SubGhzRpcStateLoaded)) { - result = subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx)); + result = subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx)); if(result) subghz_blink_start(subghz); } if(!result) { diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 305217f7d..72ba4ffc0 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -26,7 +26,8 @@ bool subghz_scene_transmitter_update_data_show(void* context) { subghz_protocol_decoder_base_get_string( subghz_txrx_get_decoder(subghz->txrx), key_str); - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_modulation( + subghz->txrx, frequency_str, modulation_str, false); subghz_view_transmitter_add_data_to_show( subghz->subghz_transmitter, furi_string_get_cstr(key_str), @@ -66,7 +67,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { + if(subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx))) { subghz->state_notifications = SubGhzNotificationStateTx; subghz_scene_transmitter_update_data_show(subghz); DOLPHIN_DEED(DolphinDeedSubGhzSend); @@ -82,7 +83,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { // Calling restore! subghz_txrx_stop(subghz->txrx); - if(!subghz_txrx_tx_start(subghz->txrx, subghz_txtx_get_fff_data(subghz->txrx))) { + if(!subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx))) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); } diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 101ffdfdf..96b75e5b7 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -39,6 +39,23 @@ void subghz_blink_stop(SubGhz* subghz) { notification_message(subghz->notifications, &sequence_blink_stop); } +bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) { + switch(subghz_txrx_tx_start(subghz->txrx, flipper_format)) { + case SubGhzTxRxStartTxStateErrorParserOthers: + dialog_message_show_storage_error( + subghz->dialogs, "Error in protocol\nparameters\ndescription"); + break; + case SubGhzTxRxStartTxStateErrorOnlyRx: + subghz_dialog_message_show_only_rx(subghz); + break; + + default: + return true; + break; + } + return false; +} + void subghz_dialog_message_show_only_rx(SubGhz* subghz) { DialogsApp* dialogs = subghz->dialogs; DialogMessage* message = dialog_message_alloc(); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index e955d8360..b0157b672 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -124,6 +124,7 @@ void subghz_set_defalut_preset(SubGhz* subghz); void subghz_blink_start(SubGhz* subghz); void subghz_blink_stop(SubGhz* subghz); +bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format); void subghz_dialog_message_show_only_rx(SubGhz* subghz); bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog); From 752a11ba2644ead98ab4b420bafc3f3e1b9341b3 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 20:06:22 +0300 Subject: [PATCH 20/36] SubGhz: refactoring RPC --- applications/main/subghz/helpers/subghz_txrx.c | 5 ----- applications/main/subghz/helpers/subghz_txrx.h | 2 -- applications/main/subghz/scenes/subghz_scene_rpc.c | 11 +++++++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index c5118e67d..f106df4f4 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -362,11 +362,6 @@ void subghz_txrx_stop(SubGhzTxRx* instance) { } } -SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* instance) { - furi_assert(instance); - return instance->txrx_state; -} - void subghz_txrx_hopper_update(SubGhzTxRx* instance) { furi_assert(instance); diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index 4b7c28f3c..667033d14 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -40,8 +40,6 @@ void subghz_txrx_rx_start(SubGhzTxRx* instance); void subghz_txrx_stop(SubGhzTxRx* instance); void subghz_txrx_sleep(SubGhzTxRx* instance); -SubGhzTxRxState subghz_txrx_get_state(SubGhzTxRx* instance); - void subghz_txrx_hopper_update(SubGhzTxRx* instance); SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance); void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state); diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 70c909756..59497c493 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -7,6 +7,7 @@ typedef enum { SubGhzRpcStateIdle, SubGhzRpcStateLoaded, + SubGhzRpcStateTx, } SubGhzRpcState; void subghz_scene_rpc_on_enter(void* context) { @@ -42,9 +43,9 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { view_dispatcher_stop(subghz->view_dispatcher); } else if(event.event == SubGhzCustomEventSceneRpcButtonPress) { bool result = false; - if((subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateSleep) && - (state == SubGhzRpcStateLoaded)) { + if((state == SubGhzRpcStateLoaded)) { result = subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx)); + state = SubGhzRpcStateTx; if(result) subghz_blink_start(subghz); } if(!result) { @@ -56,9 +57,10 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result); } else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) { bool result = false; - if(subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateTx) { + if(state == SubGhzRpcStateTx) { subghz_txrx_stop(subghz->txrx); subghz_blink_stop(subghz); + state = SubGhzRpcStateIdle; result = true; } rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonRelease, result); @@ -96,7 +98,8 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { void subghz_scene_rpc_on_exit(void* context) { SubGhz* subghz = context; - if(subghz_txrx_get_state(subghz->txrx) == SubGhzTxRxStateTx) { + SubGhzRpcState state = scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneRpc); + if(state != SubGhzRpcStateIdle) { subghz_txrx_stop(subghz->txrx); subghz_blink_stop(subghz); } From 42a415e4490b02b006539ee565bd6a1cfc8240b1 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 20:19:01 +0300 Subject: [PATCH 21/36] SubGhz: value get optimizations --- .../subghz/scenes/subghz_scene_read_raw.c | 2 +- .../scenes/subghz_scene_receiver_config.c | 71 ++++++++----------- .../subghz/scenes/subghz_scene_transmitter.c | 10 +-- applications/main/subghz/subghz_i.c | 2 +- applications/main/subghz/subghz_i.h | 2 +- 5 files changed, 37 insertions(+), 50 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index f4749df65..e7e93ad24 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -140,7 +140,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { } else { //Restore default setting if(subghz->raw_send_only) { - subghz_set_defalut_preset(subghz); + subghz_set_default_preset(subghz); } else { subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index d65778b01..3edde712e 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -93,15 +93,14 @@ uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* furi_assert(context); SubGhz* subghz = context; uint8_t index = 0; - for(uint8_t i = 0; - i < subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx)); - i++) { - if(value == subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), i)) { + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); + + for(uint8_t i = 0; i < subghz_setting_get_frequency_count(setting); i++) { + if(value == subghz_setting_get_frequency(setting, i)) { index = i; break; } else { - index = - subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)); + index = subghz_setting_get_frequency_default_index(setting); } } return index; @@ -111,15 +110,14 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* furi_assert(context); SubGhz* subghz = context; uint8_t index = 0; - for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx)); - i++) { - if(!strcmp( - subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), i), - preset_name)) { + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); + + for(uint8_t i = 0; i < subghz_setting_get_preset_count(setting); i++) { + if(!strcmp(subghz_setting_get_preset_name(setting, i), preset_name)) { index = i; break; } else { - // index = subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx)); + // index = subghz_setting_get_frequency_default_index(setting); } } return index; @@ -148,6 +146,7 @@ uint8_t subghz_scene_receiver_config_hopper_value_index( static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { char text_buf[10] = {0}; @@ -155,10 +154,8 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) / 1000000, - (subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index) % - 1000000) / - 10000); + subghz_setting_get_frequency(setting, index) / 1000000, + (subghz_setting_get_frequency(setting, index) % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); @@ -166,19 +163,17 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset.name), - subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), index), + subghz_setting_get_frequency(setting, index), preset.data, preset.data_size); preset = subghz_txrx_get_preset(subghz->txrx); subghz->last_settings->frequency = preset.frequency; - subghz_setting_set_default_frequency( - subghz_txrx_get_setting(subghz->txrx), preset.frequency); + subghz_setting_set_default_frequency(setting, preset.frequency); } else { variable_item_set_current_value_index( - item, - subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx))); + item, subghz_setting_get_frequency_default_index(setting)); } } @@ -202,42 +197,34 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); + VariableItem* frequency_item = (VariableItem*)scene_manager_get_scene_state( + subghz->scene_manager, SubGhzSceneReceiverConfig); variable_item_set_current_value_text(item, hopping_text[index]); if(hopping_value[index] == SubGhzHopperStateOFF) { char text_buf[10] = {0}; + uint32_t frequency = subghz_setting_get_default_frequency(setting); snprintf( text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) / 1000000, - (subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)) % - 1000000) / - 10000); - variable_item_set_current_value_text( - (VariableItem*)scene_manager_get_scene_state( - subghz->scene_manager, SubGhzSceneReceiverConfig), - text_buf); + frequency / 1000000, + (frequency % 1000000) / 10000); + variable_item_set_current_value_text(frequency_item, text_buf); SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset.name), - subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)), + frequency, preset.data, preset.data_size); variable_item_set_current_value_index( - (VariableItem*)scene_manager_get_scene_state( - subghz->scene_manager, SubGhzSceneReceiverConfig), - subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx))); + frequency_item, subghz_setting_get_frequency_default_index(setting)); } else { - variable_item_set_current_value_text( - (VariableItem*)scene_manager_get_scene_state( - subghz->scene_manager, SubGhzSceneReceiverConfig), - " -----"); + variable_item_set_current_value_text(frequency_item, " -----"); variable_item_set_current_value_index( - (VariableItem*)scene_manager_get_scene_state( - subghz->scene_manager, SubGhzSceneReceiverConfig), - subghz_setting_get_frequency_default_index(subghz_txrx_get_setting(subghz->txrx))); + frequency_item, subghz_setting_get_frequency_default_index(setting)); } subghz_txrx_hopper_set_state(subghz->txrx, hopping_value[index]); @@ -411,8 +398,8 @@ void subghz_scene_receiver_config_on_enter(void* context) { SPEAKER_COUNT, subghz_scene_receiver_config_set_speaker, subghz); - value_index = - value_index_uint32(subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT); + value_index = value_index_uint32( + subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, speaker_text[value_index]); diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 72ba4ffc0..c1bbd2343 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -15,16 +15,16 @@ void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) { bool subghz_scene_transmitter_update_data_show(void* context) { SubGhz* subghz = context; bool ret = false; - if(subghz_txrx_get_decoder(subghz->txrx)) { + SubGhzProtocolDecoderBase* decoder = subghz_txrx_get_decoder(subghz->txrx); + + if(decoder) { FuriString* key_str = furi_string_alloc(); FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); if(subghz_protocol_decoder_base_deserialize( - subghz_txrx_get_decoder(subghz->txrx), subghz_txtx_get_fff_data(subghz->txrx)) == - SubGhzProtocolStatusOk) { - subghz_protocol_decoder_base_get_string( - subghz_txrx_get_decoder(subghz->txrx), key_str); + decoder, subghz_txtx_get_fff_data(subghz->txrx)) == SubGhzProtocolStatusOk) { + subghz_protocol_decoder_base_get_string(decoder, key_str); subghz_txrx_get_frequency_modulation( subghz->txrx, frequency_str, modulation_str, false); diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 96b75e5b7..d17c6858f 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -18,7 +18,7 @@ #define TAG "SubGhz" -void subghz_set_defalut_preset(SubGhz* subghz) { +void subghz_set_default_preset(SubGhz* subghz) { furi_assert(subghz); subghz_txrx_set_preset( subghz->txrx, diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index b0157b672..785a6708f 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -120,7 +120,7 @@ struct SubGhz { void* rpc_ctx; }; -void subghz_set_defalut_preset(SubGhz* subghz); +void subghz_set_default_preset(SubGhz* subghz); void subghz_blink_start(SubGhz* subghz); void subghz_blink_stop(SubGhz* subghz); From def4ae395ea64e8e5bee31740344d2a0a14b89d8 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 21:20:35 +0300 Subject: [PATCH 22/36] SubGhz: refactoring --- .../main/subghz/helpers/subghz_txrx.c | 410 +----------------- .../main/subghz/helpers/subghz_txrx.h | 86 +--- .../subghz/helpers/subghz_txrx_callbacks.h | 2 + .../helpers/subghz_txrx_create_potocol_key.c | 346 +++++++++++++++ .../helpers/subghz_txrx_create_potocol_key.h | 87 ++++ .../main/subghz/helpers/subghz_txrx_i.h | 34 ++ .../subghz/scenes/subghz_scene_need_saving.c | 7 +- .../subghz/scenes/subghz_scene_read_raw.c | 52 +-- .../subghz/scenes/subghz_scene_receiver.c | 24 +- .../scenes/subghz_scene_receiver_config.c | 38 +- .../subghz/scenes/subghz_scene_set_seed.c | 1 + .../subghz/scenes/subghz_scene_set_type.c | 44 +- 12 files changed, 573 insertions(+), 558 deletions(-) create mode 100644 applications/main/subghz/helpers/subghz_txrx_callbacks.h create mode 100644 applications/main/subghz/helpers/subghz_txrx_create_potocol_key.c create mode 100644 applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h create mode 100644 applications/main/subghz/helpers/subghz_txrx_i.h diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index f106df4f4..38cf549de 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -1,34 +1,9 @@ +#include "subghz_txrx_i.h" #include "subghz_txrx.h" #include #define TAG "SubGhz" -struct SubGhzTxRx { - SubGhzWorker* worker; - - SubGhzEnvironment* environment; - SubGhzReceiver* receiver; - SubGhzTransmitter* transmitter; - SubGhzProtocolDecoderBase* decoder_result; - FlipperFormat* fff_data; - - SubGhzRadioPreset* preset; - SubGhzSetting* setting; - - uint8_t hopper_timeout; - uint8_t hopper_idx_frequency; - bool load_database; - SubGhzHopperState hopper_state; - - SubGhzTxRxState txrx_state; - SubGhzSpeakerState speaker_state; - - SubGhzTxRxNeedSaveCallback need_save_callback; - void* need_save_context; - - bool debug_pin_state; -}; - SubGhzTxRx* subghz_txrx_alloc() { SubGhzTxRx* instance = malloc(sizeof(SubGhzTxRx)); instance->setting = subghz_setting_alloc(); @@ -98,9 +73,10 @@ void subghz_txrx_set_preset( size_t preset_data_size) { furi_assert(instance); furi_string_set(instance->preset->name, preset_name); - instance->preset->frequency = frequency; - instance->preset->data = preset_data; - instance->preset->data_size = preset_data_size; + SubGhzRadioPreset* preset = instance->preset; + preset->frequency = frequency; + preset->data = preset_data; + preset->data_size = preset_data_size; } const char* subghz_txrx_get_name_preset(SubGhzTxRx* instance, const char* preset) { @@ -133,18 +109,19 @@ void subghz_txrx_get_frequency_modulation( FuriString* modulation, bool long_name) { furi_assert(instance); + SubGhzRadioPreset* preset = instance->preset; if(frequency != NULL) { furi_string_printf( frequency, "%03ld.%02ld", - instance->preset->frequency / 1000000 % 1000, - instance->preset->frequency / 10000 % 100); + preset->frequency / 1000000 % 1000, + preset->frequency / 10000 % 100); } if(modulation != NULL) { if(long_name) { - furi_string_printf(modulation, "%s", furi_string_get_cstr(instance->preset->name)); + furi_string_printf(modulation, "%s", furi_string_get_cstr(preset->name)); } else { - furi_string_printf(modulation, "%.2s", furi_string_get_cstr(instance->preset->name)); + furi_string_printf(modulation, "%.2s", furi_string_get_cstr(preset->name)); } } } @@ -247,20 +224,22 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* FURI_LOG_E(TAG, "Unable Repeat"); break; } + ret = SubGhzTxRxStartTxStateOk; + SubGhzRadioPreset* preset = instance->preset; instance->transmitter = subghz_transmitter_alloc_init(instance->environment, furi_string_get_cstr(temp_str)); if(instance->transmitter) { if(subghz_transmitter_deserialize(instance->transmitter, flipper_format) == SubGhzProtocolStatusOk) { - if(strcmp(furi_string_get_cstr(instance->preset->name), "") != 0) { + if(strcmp(furi_string_get_cstr(preset->name), "") != 0) { subghz_txrx_begin( instance, subghz_setting_get_preset_data_by_name( - instance->setting, furi_string_get_cstr(instance->preset->name))); - if(instance->preset->frequency) { - if(!subghz_txrx_tx(instance, instance->preset->frequency)) { + instance->setting, furi_string_get_cstr(preset->name))); + if(preset->frequency) { + if(!subghz_txrx_tx(instance, preset->frequency)) { FURI_LOG_E(TAG, "Only Rx"); ret = SubGhzTxRxStartTxStateErrorOnlyRx; } @@ -269,9 +248,7 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* } } else { FURI_LOG_E( - TAG, - "Unknown name preset \" %s \"", - furi_string_get_cstr(instance->preset->name)); + TAG, "Unknown name preset \" %s \"", furi_string_get_cstr(preset->name)); ret = SubGhzTxRxStartTxStateErrorParserOthers; } if(ret == SubGhzTxRxStartTxStateOk) { @@ -533,17 +510,15 @@ bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* instance) { bool subghz_txrx_protocol_is_send(SubGhzTxRx* instance, bool check_type) { furi_assert(instance); + const SubGhzProtocol* protocol = instance->decoder_result->protocol; if(check_type) { return ( - ((instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == - SubGhzProtocolFlag_Send) && - instance->decoder_result->protocol->encoder->deserialize && - instance->decoder_result->protocol->type == SubGhzProtocolTypeStatic); + ((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && + protocol->encoder->deserialize && protocol->type == SubGhzProtocolTypeStatic); } return ( - ((instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == - SubGhzProtocolFlag_Send) && - instance->decoder_result->protocol->encoder->deserialize); + ((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && + protocol->encoder->deserialize); } void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter) { @@ -581,345 +556,4 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) { SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) { furi_assert(instance); return instance->receiver; -} - -//#############Create new Key############## -#include -#include -#include -#include -#include - -#include -#include -#include - -bool subghz_txrx_gen_data_protocol( - void* context, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit) { - furi_assert(context); - SubGhzTxRx* instance = context; - - bool res = false; - - subghz_txrx_set_preset(instance, preset_name, frequency, NULL, 0); - instance->decoder_result = - subghz_receiver_search_decoder_base_by_name(instance->receiver, protocol_name); - - if(instance->decoder_result == NULL) { - //TODO: Error - // furi_string_set(error_str, "Protocol not\nfound!"); - // scene_manager_next_scene(scene_manager, SubGhzSceneShowErrorSub); - return false; - } - - do { - Stream* fff_data_stream = flipper_format_get_raw_stream(instance->fff_data); - stream_clean(fff_data_stream); - if(subghz_protocol_decoder_base_serialize( - instance->decoder_result, instance->fff_data, instance->preset) != - SubGhzProtocolStatusOk) { - FURI_LOG_E(TAG, "Unable to serialize"); - break; - } - if(!flipper_format_update_uint32(instance->fff_data, "Bit", &bit, 1)) { - FURI_LOG_E(TAG, "Unable to update Bit"); - break; - } - - uint8_t key_data[sizeof(uint64_t)] = {0}; - for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; - } - if(!flipper_format_update_hex(instance->fff_data, "Key", key_data, sizeof(uint64_t))) { - FURI_LOG_E(TAG, "Unable to update Key"); - break; - } - res = true; - } while(false); - return res; -} - -bool subghz_txrx_gen_data_protocol_and_te( - SubGhzTxRx* instance, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit, - uint32_t te) { - furi_assert(instance); - bool ret = false; - if(subghz_txrx_gen_data_protocol(instance, preset_name, frequency, protocol_name, key, bit)) { - if(!flipper_format_update_uint32(instance->fff_data, "TE", (uint32_t*)&te, 1)) { - FURI_LOG_E(TAG, "Unable to update Te"); - } else { - ret = true; - } - } - return ret; -} - -bool subghz_scene_set_type_submenu_gen_data_keeloq( //TODO rename - SubGhzTxRx* txrx, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - const char* manufacture_name) { - furi_assert(txrx); - - bool res = false; - - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); - - if(txrx->transmitter && subghz_protocol_keeloq_create_data( - subghz_transmitter_get_protocol_instance(txrx->transmitter), - txrx->fff_data, - serial, - btn, - cnt, - manufacture_name, - txrx->preset)) { - flipper_format_write_string_cstr(txrx->fff_data, "Manufacture", manufacture_name); - res = true; - } - subghz_transmitter_free(txrx->transmitter); - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name) { - SubGhzTxRx* txrx = context; - - bool res = false; - - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); - subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); - - if(txrx->transmitter && subghz_protocol_keeloq_bft_create_data( - subghz_transmitter_get_protocol_instance(txrx->transmitter), - txrx->fff_data, - serial, - btn, - cnt, - seed, - manufacture_name, - txrx->preset)) { - res = true; - } - - if(res) { - uint8_t seed_data[sizeof(uint32_t)] = {0}; - for(size_t i = 0; i < sizeof(uint32_t); i++) { - seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; - } - - flipper_format_write_hex(txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); - - flipper_format_write_string_cstr(txrx->fff_data, "Manufacture", "BFT"); - } - - subghz_transmitter_free(txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - bool nice_one) { - SubGhzTxRx* txrx = context; - - bool res = false; - - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); - subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); - - if(txrx->transmitter && subghz_protocol_nice_flor_s_create_data( - subghz_transmitter_get_protocol_instance(txrx->transmitter), - txrx->fff_data, - serial, - btn, - cnt, - txrx->preset, - nice_one)) { - res = true; - } - - subghz_transmitter_free(txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name) { - SubGhzTxRx* txrx = context; - - bool res = false; - - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME); - subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); - - if(txrx->transmitter && subghz_protocol_faac_slh_create_data( - subghz_transmitter_get_protocol_instance(txrx->transmitter), - txrx->fff_data, - serial, - btn, - cnt, - seed, - manufacture_name, - txrx->preset)) { - res = true; - } - - if(res) { - uint8_t seed_data[sizeof(uint32_t)] = {0}; - for(size_t i = 0; i < sizeof(uint32_t); i++) { - seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; - } - - flipper_format_write_hex(txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); - } - - subghz_transmitter_free(txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt) { - SubGhzTxRx* txrx = context; - - bool res = false; - - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); - subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); - - if(txrx->transmitter && subghz_protocol_alutech_at_4n_create_data( - subghz_transmitter_get_protocol_instance(txrx->transmitter), - txrx->fff_data, - serial, - btn, - cnt, - txrx->preset)) { - res = true; - } - - subghz_transmitter_free(txrx->transmitter); - - return res; -} - -bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt) { - SubGhzTxRx* txrx = context; - - bool res = false; - - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); - subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); - - if(txrx->transmitter && subghz_protocol_somfy_telis_create_data( - subghz_transmitter_get_protocol_instance(txrx->transmitter), - txrx->fff_data, - serial, - btn, - cnt, - txrx->preset)) { - res = true; - } - - subghz_transmitter_free(txrx->transmitter); - - return res; -} - -bool subghz_txrx_gen_secplus_v2_protocol( - SubGhzTxRx* txrx, - const char* name_preset, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint32_t cnt) { - furi_assert(txrx); - - bool ret = false; - txrx->transmitter = - subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); - subghz_txrx_set_preset(txrx, name_preset, frequency, NULL, 0); - if(txrx->transmitter) { - subghz_protocol_secplus_v2_create_data( - subghz_transmitter_get_protocol_instance(txrx->transmitter), - txrx->fff_data, - serial, - btn, - cnt, - txrx->preset); - ret = true; - } - return ret; -} - -bool subghz_txrx_gen_secplus_v1_protocol( - SubGhzTxRx* txrx, - const char* name_preset, - uint32_t frequency) { - furi_assert(txrx); - - bool ret = false; - uint32_t serial = (uint32_t)rand(); - while(!subghz_protocol_secplus_v1_check_fixed(serial)) { - serial = (uint32_t)rand(); - } - if(subghz_txrx_gen_data_protocol( - txrx, - name_preset, - frequency, - SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, - (uint64_t)serial << 32 | 0xE6000000, - 42)) { - ret = true; - } - return ret; } \ No newline at end of file diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index 667033d14..590fcd4f4 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -1,5 +1,6 @@ #pragma once #include "subghz_types.h" +#include "subghz_txrx_callbacks.h" #include #include #include @@ -80,88 +81,3 @@ void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state); bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance); SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw - -//#############Create new Key############## -bool subghz_txrx_gen_data_protocol( - void* context, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit); - -bool subghz_txrx_gen_data_protocol_and_te( - SubGhzTxRx* instance, - const char* preset_name, - uint32_t frequency, - const char* protocol_name, - uint64_t key, - uint32_t bit, - uint32_t te); - -bool subghz_scene_set_type_submenu_gen_data_keeloq( - SubGhzTxRx* txrx, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - const char* manufacture_name); - -bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name); - -bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - bool nice_one); - -bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt, - uint32_t seed, - const char* manufacture_name); - -bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt); - -bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename - void* context, - const char* preset_name, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint16_t cnt); - -bool subghz_txrx_gen_secplus_v2_protocol( - SubGhzTxRx* txrx, - const char* name_preset, - uint32_t frequency, - uint32_t serial, - uint8_t btn, - uint32_t cnt); - -bool subghz_txrx_gen_secplus_v1_protocol( - SubGhzTxRx* txrx, - const char* name_preset, - uint32_t frequency); \ No newline at end of file diff --git a/applications/main/subghz/helpers/subghz_txrx_callbacks.h b/applications/main/subghz/helpers/subghz_txrx_callbacks.h new file mode 100644 index 000000000..5bee720e9 --- /dev/null +++ b/applications/main/subghz/helpers/subghz_txrx_callbacks.h @@ -0,0 +1,2 @@ +#pragma once +typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); \ No newline at end of file diff --git a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.c b/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.c new file mode 100644 index 000000000..7c3b1c7ff --- /dev/null +++ b/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.c @@ -0,0 +1,346 @@ +#include "subghz_txrx_i.h" +#include "subghz_txrx_create_potocol_key.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define TAG "SubGhzCreateProtocolKey" + +bool subghz_txrx_gen_data_protocol( + void* context, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit) { + furi_assert(context); + SubGhzTxRx* instance = context; + + bool res = false; + + subghz_txrx_set_preset(instance, preset_name, frequency, NULL, 0); + instance->decoder_result = + subghz_receiver_search_decoder_base_by_name(instance->receiver, protocol_name); + + if(instance->decoder_result == NULL) { + //TODO: Error + // furi_string_set(error_str, "Protocol not\nfound!"); + // scene_manager_next_scene(scene_manager, SubGhzSceneShowErrorSub); + FURI_LOG_E(TAG, "Protocol not found!"); + return false; + } + + do { + Stream* fff_data_stream = flipper_format_get_raw_stream(instance->fff_data); + stream_clean(fff_data_stream); + if(subghz_protocol_decoder_base_serialize( + instance->decoder_result, instance->fff_data, instance->preset) != + SubGhzProtocolStatusOk) { + FURI_LOG_E(TAG, "Unable to serialize"); + break; + } + if(!flipper_format_update_uint32(instance->fff_data, "Bit", &bit, 1)) { + FURI_LOG_E(TAG, "Unable to update Bit"); + break; + } + + uint8_t key_data[sizeof(uint64_t)] = {0}; + for(size_t i = 0; i < sizeof(uint64_t); i++) { + key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; + } + if(!flipper_format_update_hex(instance->fff_data, "Key", key_data, sizeof(uint64_t))) { + FURI_LOG_E(TAG, "Unable to update Key"); + break; + } + res = true; + } while(false); + return res; +} + +bool subghz_txrx_gen_data_protocol_and_te( + SubGhzTxRx* instance, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit, + uint32_t te) { + furi_assert(instance); + bool ret = false; + if(subghz_txrx_gen_data_protocol(instance, preset_name, frequency, protocol_name, key, bit)) { + if(!flipper_format_update_uint32(instance->fff_data, "TE", (uint32_t*)&te, 1)) { + FURI_LOG_E(TAG, "Unable to update Te"); + } else { + ret = true; + } + } + return ret; +} + +bool subghz_txrx_gen_keelog_protocol( //TODO lead to a general appearance + SubGhzTxRx* instance, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + const char* manufacture_name) { + furi_assert(instance); + + bool res = false; + + instance->transmitter = + subghz_transmitter_alloc_init(instance->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); + subghz_txrx_set_preset(instance, preset_name, frequency, NULL, 0); + + if(instance->transmitter && + subghz_protocol_keeloq_create_data( + subghz_transmitter_get_protocol_instance(instance->transmitter), + instance->fff_data, + serial, + btn, + cnt, + manufacture_name, + instance->preset)) { + flipper_format_write_string_cstr(instance->fff_data, "Manufacture", manufacture_name); + res = true; + } + subghz_transmitter_free(instance->transmitter); + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename & lead to a general appearance + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_keeloq_bft_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + seed, + manufacture_name, + txrx->preset)) { + res = true; + } + + if(res) { + uint8_t seed_data[sizeof(uint32_t)] = {0}; + for(size_t i = 0; i < sizeof(uint32_t); i++) { + seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; + } + + flipper_format_write_hex(txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); + + flipper_format_write_string_cstr(txrx->fff_data, "Manufacture", "BFT"); + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename & lead to a general appearance + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + bool nice_one) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_NICE_FLOR_S_NAME); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_nice_flor_s_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + txrx->preset, + nice_one)) { + res = true; + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename & lead to a general appearance + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_FAAC_SLH_NAME); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_faac_slh_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + seed, + manufacture_name, + txrx->preset)) { + res = true; + } + + if(res) { + uint8_t seed_data[sizeof(uint32_t)] = {0}; + for(size_t i = 0; i < sizeof(uint32_t); i++) { + seed_data[sizeof(uint32_t) - i - 1] = (seed >> i * 8) & 0xFF; + } + + flipper_format_write_hex(txrx->fff_data, "Seed", seed_data, sizeof(uint32_t)); + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename & lead to a general appearance + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_alutech_at_4n_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + txrx->preset)) { + res = true; + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename & lead to a general appearance + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt) { + SubGhzTxRx* txrx = context; + + bool res = false; + + txrx->transmitter = + subghz_transmitter_alloc_init(txrx->environment, SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME); + subghz_txrx_set_preset(txrx, preset_name, frequency, NULL, 0); + + if(txrx->transmitter && subghz_protocol_somfy_telis_create_data( + subghz_transmitter_get_protocol_instance(txrx->transmitter), + txrx->fff_data, + serial, + btn, + cnt, + txrx->preset)) { + res = true; + } + + subghz_transmitter_free(txrx->transmitter); + + return res; +} + +bool subghz_txrx_gen_secplus_v2_protocol( + SubGhzTxRx* instance, + const char* name_preset, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint32_t cnt) { + furi_assert(instance); + + bool ret = false; + instance->transmitter = + subghz_transmitter_alloc_init(instance->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME); + subghz_txrx_set_preset(instance, name_preset, frequency, NULL, 0); + if(instance->transmitter) { + subghz_protocol_secplus_v2_create_data( + subghz_transmitter_get_protocol_instance(instance->transmitter), + instance->fff_data, + serial, + btn, + cnt, + instance->preset); + ret = true; + } + return ret; +} + +bool subghz_txrx_gen_secplus_v1_protocol( + SubGhzTxRx* instance, + const char* name_preset, + uint32_t frequency) { + furi_assert(instance); + + bool ret = false; + uint32_t serial = (uint32_t)rand(); + while(!subghz_protocol_secplus_v1_check_fixed(serial)) { + serial = (uint32_t)rand(); + } + if(subghz_txrx_gen_data_protocol( + instance, + name_preset, + frequency, + SUBGHZ_PROTOCOL_SECPLUS_V1_NAME, + (uint64_t)serial << 32 | 0xE6000000, + 42)) { + ret = true; + } + return ret; +} \ No newline at end of file diff --git a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h b/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h new file mode 100644 index 000000000..99c83a060 --- /dev/null +++ b/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h @@ -0,0 +1,87 @@ +#pragma once +#include "subghz_types.h" +#include "subghz_txrx.h" + +bool subghz_txrx_gen_data_protocol( + void* context, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit); + +bool subghz_txrx_gen_data_protocol_and_te( + SubGhzTxRx* instance, + const char* preset_name, + uint32_t frequency, + const char* protocol_name, + uint64_t key, + uint32_t bit, + uint32_t te); + +bool subghz_txrx_gen_keelog_protocol( + SubGhzTxRx* instance, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + bool nice_one); + +bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt, + uint32_t seed, + const char* manufacture_name); + +bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt); + +bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename + void* context, + const char* preset_name, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint16_t cnt); + +bool subghz_txrx_gen_secplus_v2_protocol( + SubGhzTxRx* instance, + const char* name_preset, + uint32_t frequency, + uint32_t serial, + uint8_t btn, + uint32_t cnt); + +bool subghz_txrx_gen_secplus_v1_protocol( + SubGhzTxRx* instance, + const char* name_preset, + uint32_t frequency); \ No newline at end of file diff --git a/applications/main/subghz/helpers/subghz_txrx_i.h b/applications/main/subghz/helpers/subghz_txrx_i.h new file mode 100644 index 000000000..2d3025554 --- /dev/null +++ b/applications/main/subghz/helpers/subghz_txrx_i.h @@ -0,0 +1,34 @@ + +#pragma once +#include "subghz_types.h" +#include "subghz_txrx_callbacks.h" +#include +#include +#include +#include + +struct SubGhzTxRx { + SubGhzWorker* worker; + + SubGhzEnvironment* environment; + SubGhzReceiver* receiver; + SubGhzTransmitter* transmitter; + SubGhzProtocolDecoderBase* decoder_result; + FlipperFormat* fff_data; + + SubGhzRadioPreset* preset; + SubGhzSetting* setting; + + uint8_t hopper_timeout; + uint8_t hopper_idx_frequency; + bool load_database; + SubGhzHopperState hopper_state; + + SubGhzTxRxState txrx_state; + SubGhzSpeakerState speaker_state; + + SubGhzTxRxNeedSaveCallback need_save_callback; + void* need_save_context; + + bool debug_pin_state; +}; \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_need_saving.c b/applications/main/subghz/scenes/subghz_scene_need_saving.c index c249ff282..8bbaae2ce 100644 --- a/applications/main/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/main/subghz/scenes/subghz_scene_need_saving.c @@ -46,14 +46,15 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { scene_manager_previous_scene(subghz->scene_manager); return true; } else if(event.event == SubGhzCustomEventSceneExit) { - if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateExit) { - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + SubGhzRxKeyState state = subghz_rx_key_state_get(subghz); + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + + if(state) { subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } else { - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); scene_manager_previous_scene(subghz->scene_manager); } diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index e7e93ad24..4d9553854 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -13,13 +13,13 @@ bool subghz_scene_read_raw_update_filename(SubGhz* subghz) { //set the path to read the file FuriString* temp_str = furi_string_alloc(); do { - if(!flipper_format_rewind(subghz_txtx_get_fff_data(subghz->txrx))) { + FlipperFormat* fff_data = subghz_txtx_get_fff_data(subghz->txrx); + if(!flipper_format_rewind(fff_data)) { FURI_LOG_E(TAG, "Rewind error"); break; } - if(!flipper_format_read_string( - subghz_txtx_get_fff_data(subghz->txrx), "File_name", temp_str)) { + if(!flipper_format_read_string(fff_data, "File_name", temp_str)) { FURI_LOG_E(TAG, "Missing File_name"); break; } @@ -73,13 +73,11 @@ void subghz_scene_read_raw_on_enter(void* context) { SubGhz* subghz = context; FuriString* file_name = furi_string_alloc(); + float threshold_rssi = subghz_threshold_rssi_get(subghz->threshold_rssi); switch(subghz_rx_key_state_get(subghz)) { case SubGhzRxKeyStateBack: subghz_read_raw_set_status( - subghz->subghz_read_raw, - SubGhzReadRAWStatusIDLE, - "", - subghz_threshold_rssi_get(subghz->threshold_rssi)); + subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, "", threshold_rssi); break; case SubGhzRxKeyStateRAWLoad: path_extract_filename(subghz->file_path, file_name, true); @@ -87,8 +85,7 @@ void subghz_scene_read_raw_on_enter(void* context) { subghz->subghz_read_raw, SubGhzReadRAWStatusLoadKeyTX, furi_string_get_cstr(file_name), - subghz_threshold_rssi_get(subghz->threshold_rssi)); - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + threshold_rssi); break; case SubGhzRxKeyStateRAWSave: path_extract_filename(subghz->file_path, file_name, true); @@ -96,18 +93,17 @@ void subghz_scene_read_raw_on_enter(void* context) { subghz->subghz_read_raw, SubGhzReadRAWStatusSaveKey, furi_string_get_cstr(file_name), - subghz_threshold_rssi_get(subghz->threshold_rssi)); - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + threshold_rssi); break; default: subghz_read_raw_set_status( - subghz->subghz_read_raw, - SubGhzReadRAWStatusStart, - "", - subghz_threshold_rssi_get(subghz->threshold_rssi)); - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + subghz->subghz_read_raw, SubGhzReadRAWStatusStart, "", threshold_rssi); break; } + + if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateBack) { + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + } furi_string_free(file_name); subghz_scene_read_raw_update_statusbar(subghz); @@ -124,13 +120,14 @@ void subghz_scene_read_raw_on_enter(void* context) { bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; bool consumed = false; + SubGhzProtocolDecoderRAW* decoder_raw = + (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx); if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case SubGhzCustomEventViewReadRAWBack: subghz_txrx_stop(subghz->txrx); //Stop save file - subghz_protocol_raw_save_to_file_stop( - (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx)); + subghz_protocol_raw_save_to_file_stop(decoder_raw); subghz->state_notifications = SubGhzNotificationStateIDLE; //needed save? if((subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) || @@ -245,11 +242,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWIDLE: subghz_txrx_stop(subghz->txrx); - size_t spl_count = subghz_protocol_raw_get_sample_write( - (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx)); + size_t spl_count = subghz_protocol_raw_get_sample_write(decoder_raw); - subghz_protocol_raw_save_to_file_stop( - (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx)); + subghz_protocol_raw_save_to_file_stop(decoder_raw); FuriString* temp_str = furi_string_alloc(); furi_string_printf( @@ -275,10 +270,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); - if(subghz_protocol_raw_save_to_file_init( - (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx), - RAW_FILE_NAME, - &preset)) { + if(subghz_protocol_raw_save_to_file_init(decoder_raw, RAW_FILE_NAME, &preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); subghz_txrx_rx_start(subghz->txrx); @@ -317,17 +309,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { notification_message(subghz->notifications, &sequence_blink_cyan_10); subghz_read_raw_update_sample_write( - subghz->subghz_read_raw, - subghz_protocol_raw_get_sample_write( - (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx))); + subghz->subghz_read_raw, subghz_protocol_raw_get_sample_write(decoder_raw)); SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data(subghz->threshold_rssi); subghz_read_raw_add_data_rssi( subghz->subghz_read_raw, ret_rssi.rssi, ret_rssi.is_above); - subghz_protocol_raw_save_to_file_pause( - (SubGhzProtocolDecoderRAW*)subghz_txrx_get_decoder(subghz->txrx), - !ret_rssi.is_above); + subghz_protocol_raw_save_to_file_pause(decoder_raw, !ret_rssi.is_above); break; case SubGhzNotificationStateTx: diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 7570d822d..304797eff 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -90,27 +90,26 @@ static void subghz_scene_add_to_history_callback( SubGhzProtocolDecoderBase* decoder_base, void* context) { furi_assert(context); - SubGhz* subghz = context; - + SubGhzHistory* history = subghz->history; FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); - uint16_t idx = subghz_history_get_item(subghz->history); + uint16_t idx = subghz_history_get_item(history); SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); - if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) { + if(subghz_history_add_to_history(history, decoder_base, &preset)) { furi_string_reset(item_name); furi_string_reset(item_time); subghz->state_notifications = SubGhzNotificationStateRxDone; - subghz_history_get_text_item_menu(subghz->history, item_name, idx); - subghz_history_get_time_item_menu(subghz->history, item_time, idx); + subghz_history_get_text_item_menu(history, item_name, idx); + subghz_history_get_time_item_menu(history, item_time, idx); subghz_view_receiver_add_item_to_menu( subghz->subghz_receiver, furi_string_get_cstr(item_name), furi_string_get_cstr(item_time), - subghz_history_get_type_protocol(subghz->history, idx)); + subghz_history_get_type_protocol(history, idx)); subghz_scene_receiver_update_statusbar(subghz); } @@ -122,13 +121,14 @@ static void subghz_scene_add_to_history_callback( void subghz_scene_receiver_on_enter(void* context) { SubGhz* subghz = context; + SubGhzHistory* history = subghz->history; FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) { subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); - subghz_history_reset(subghz->history); + subghz_history_reset(history); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); } @@ -137,16 +137,16 @@ void subghz_scene_receiver_on_enter(void* context) { //Load history to receiver subghz_view_receiver_exit(subghz->subghz_receiver); - for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) { + for(uint8_t i = 0; i < subghz_history_get_item(history); i++) { furi_string_reset(item_name); furi_string_reset(item_time); - subghz_history_get_text_item_menu(subghz->history, item_name, i); - subghz_history_get_time_item_menu(subghz->history, item_time, i); + subghz_history_get_text_item_menu(history, item_name, i); + subghz_history_get_time_item_menu(history, item_time, i); subghz_view_receiver_add_item_to_menu( subghz->subghz_receiver, furi_string_get_cstr(item_name), furi_string_get_cstr(item_time), - subghz_history_get_type_protocol(subghz->history, i)); + subghz_history_get_type_protocol(history, i)); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); } furi_string_free(item_name); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 3edde712e..e9f84ed0e 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -150,20 +150,20 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { char text_buf[10] = {0}; + uint32_t frequency = subghz_setting_get_frequency(setting, index); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); + snprintf( text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(setting, index) / 1000000, - (subghz_setting_get_frequency(setting, index) % 1000000) / 10000); + frequency / 1000000, + (frequency % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); - - SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); - subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset.name), - subghz_setting_get_frequency(setting, index), + frequency, preset.data, preset.data_size); @@ -180,8 +180,9 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { static void subghz_scene_receiver_config_set_preset(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - const char* preset_name = - subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), index); + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); + + const char* preset_name = subghz_setting_get_preset_name(setting, index); variable_item_set_current_value_text(item, preset_name); //subghz->last_settings->preset = index; SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); @@ -190,8 +191,8 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { subghz->txrx, preset_name, preset.frequency, - subghz_setting_get_preset_data(subghz_txrx_get_setting(subghz->txrx), index), - subghz_setting_get_preset_data_size(subghz_txrx_get_setting(subghz->txrx), index)); + subghz_setting_get_preset_data(setting, index), + subghz_setting_get_preset_data_size(setting, index)); } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -205,6 +206,8 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) if(hopping_value[index] == SubGhzHopperStateOFF) { char text_buf[10] = {0}; uint32_t frequency = subghz_setting_get_default_frequency(setting); + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); + snprintf( text_buf, sizeof(text_buf), @@ -212,7 +215,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) frequency / 1000000, (frequency % 1000000) / 10000); variable_item_set_current_value_text(frequency_item, text_buf); - SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); + subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset.name), @@ -292,12 +295,13 @@ void subghz_scene_receiver_config_on_enter(void* context) { SubGhz* subghz = context; VariableItem* item; uint8_t value_index; + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); item = variable_item_list_add( subghz->variable_item_list, "Frequency:", - subghz_setting_get_frequency_count(subghz_txrx_get_setting(subghz->txrx)), + subghz_setting_get_frequency_count(setting), subghz_scene_receiver_config_set_frequency, subghz); value_index = subghz_scene_receiver_config_next_frequency(preset.frequency, subghz); @@ -309,23 +313,21 @@ void subghz_scene_receiver_config_on_enter(void* context) { text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) / 1000000, - (subghz_setting_get_frequency(subghz_txrx_get_setting(subghz->txrx), value_index) % - 1000000) / - 10000); + subghz_setting_get_frequency(setting, value_index) / 1000000, + (subghz_setting_get_frequency(setting, value_index) % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); item = variable_item_list_add( subghz->variable_item_list, "Modulation:", - subghz_setting_get_preset_count(subghz_txrx_get_setting(subghz->txrx)), + subghz_setting_get_preset_count(setting), subghz_scene_receiver_config_set_preset, subghz); value_index = subghz_scene_receiver_config_next_preset(furi_string_get_cstr(preset.name), subghz); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text( - item, subghz_setting_get_preset_name(subghz_txrx_get_setting(subghz->txrx), value_index)); + item, subghz_setting_get_preset_name(setting, value_index)); if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerSet) { diff --git a/applications/main/subghz/scenes/subghz_scene_set_seed.c b/applications/main/subghz/scenes/subghz_scene_set_seed.c index e416d8c2d..d3537689d 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_seed.c +++ b/applications/main/subghz/scenes/subghz_scene_set_seed.c @@ -1,4 +1,5 @@ #include "../subghz_i.h" +#include "../helpers/subghz_txrx_create_potocol_key.h" #define TAG "SubGhzSetSeed" diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index 87ef6b0af..076241767 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -1,4 +1,5 @@ #include "../subghz_i.h" +#include "../helpers/subghz_txrx_create_potocol_key.h" #include #include @@ -366,7 +367,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24); break; case SubmenuIndexBeninca433: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, @@ -381,7 +382,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexBeninca868: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 868350000, @@ -396,7 +397,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAllmatic433: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, @@ -411,7 +412,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAllmatic868: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 868350000, @@ -426,7 +427,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexElmesElectronic: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, @@ -441,7 +442,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexANMotorsAT4: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, @@ -456,7 +457,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAprimatic: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, @@ -471,7 +472,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexGibidi433: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Gibidi"); if(!generated_protocol) { furi_string_set( @@ -480,7 +481,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexGSN: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "GSN"); if(!generated_protocol) { furi_string_set( @@ -489,7 +490,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexIronLogic: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFF0, 0x4, 0x0005, "IronLogic"); if(!generated_protocol) { furi_string_set( @@ -498,7 +499,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexSommer_FM_434: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "FM476", 434420000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); if(!generated_protocol) { furi_string_set( @@ -507,7 +508,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexSommer_FM_868: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "FM476", 868800000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); if(!generated_protocol) { furi_string_set( @@ -516,7 +517,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexDTMNeo433: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0005, "DTM_Neo"); if(!generated_protocol) { furi_string_set( @@ -525,7 +526,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexCAMESpace: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Came_Space"); if(!generated_protocol) { furi_string_set( @@ -568,7 +569,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexDoorHan_433_92: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); if(!generated_protocol) { furi_string_set( @@ -577,7 +578,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexDoorHan_315_00: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 315000000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); if(!generated_protocol) { furi_string_set( @@ -604,7 +605,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexNiceSmilo_433_92: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq( + generated_protocol = subghz_txrx_gen_keelog_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "NICE_Smilo"); if(!generated_protocol) { furi_string_set( @@ -613,13 +614,16 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexLiftMaster_315_00: - generated_protocol = subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 315000000); + generated_protocol = + subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 315000000); break; case SubmenuIndexLiftMaster_390_00: - generated_protocol = subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 390000000); + generated_protocol = + subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 390000000); break; case SubmenuIndexLiftMaster_433_00: - generated_protocol = subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 433920000); + generated_protocol = + subghz_txrx_gen_secplus_v1_protocol(subghz->txrx, "AM650", 433920000); break; case SubmenuIndexSecPlus_v2_310_00: generated_protocol = subghz_txrx_gen_secplus_v2_protocol( From e817a4cdba4e9ae278d733941a95a59f9e465f20 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 21:38:25 +0300 Subject: [PATCH 23/36] SubGhz: add function description --- .../main/subghz/helpers/subghz_txrx.h | 216 +++++++++++++++++- .../helpers/subghz_txrx_create_potocol_key.h | 54 +++++ applications/main/subghz/subghz_i.c | 8 +- 3 files changed, 273 insertions(+), 5 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index 590fcd4f4..e44b57a13 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -7,20 +7,47 @@ #include #include -typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); - typedef struct SubGhzTxRx SubGhzTxRx; +typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); + typedef enum { SubGhzTxRxStartTxStateOk, SubGhzTxRxStartTxStateErrorOnlyRx, SubGhzTxRxStartTxStateErrorParserOthers, } SubGhzTxRxStartTxState; +/** + * Allocate SubGhzTxRx + * + * @return SubGhzTxRx* pointer to SubGhzTxRx + */ SubGhzTxRx* subghz_txrx_alloc(); + +/** + * Free SubGhzTxRx + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_free(SubGhzTxRx* instance); + +/** + * Check if the database is loaded + * + * @param instance Pointer to a SubGhzTxRx + * @return bool True if the database is loaded + */ bool subghz_txrx_is_load_database(SubGhzTxRx* instance); +/** + * Set preset + * + * @param instance Pointer to a SubGhzTxRx + * @param preset_name Name of preset + * @param frequency Frequency in Hz + * @param preset_data Data of preset + * @param preset_data_size Size of preset data + */ void subghz_txrx_set_preset( SubGhzTxRx* instance, const char* preset_name, @@ -28,50 +55,235 @@ void subghz_txrx_set_preset( uint8_t* preset_data, size_t preset_data_size); +/** + * Get name of preset + * + * @param instance Pointer to a SubGhzTxRx + * @param preset String of preset + * @return const char* Name of preset + */ const char* subghz_txrx_get_name_preset(SubGhzTxRx* instance, const char* preset); + +/** + * Get of preset + * + * @param instance Pointer to a SubGhzTxRx + * @return SubGhzRadioPreset Preset + */ SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance); +/** + * Get string frequency and modulation + * + * @param instance Pointer to a SubGhzTxRx + * @param frequency Pointer to a string frequency + * @param modulation Pointer to a string modulation + */ void subghz_txrx_get_frequency_modulation( SubGhzTxRx* instance, FuriString* frequency, FuriString* modulation, bool long_name); + +/** + * Start TX CC1101 + * + * @param instance Pointer to a SubGhzTxRx + * @param flipper_format Pointer to a FlipperFormat + * @return SubGhzTxRxStartTxState + */ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format); + +/** + * Start RX CC1101 + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_rx_start(SubGhzTxRx* instance); + +/** + * Stop TX/RX CC1101 + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_stop(SubGhzTxRx* instance); + +/** + * Set sleep mode CC1101 + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_sleep(SubGhzTxRx* instance); +/** + * Update frequency CC1101 in automatic mode (hopper) + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_hopper_update(SubGhzTxRx* instance); + +/** + * Get state hopper + * + * @param instance Pointer to a SubGhzTxRx + * @return SubGhzHopperState + */ SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance); + +/** + * Set state hopper + * + * @param instance Pointer to a SubGhzTxRx + * @param state State hopper + */ void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state); + +/** + * Unpause hopper + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance); + +/** + * Set pause hopper + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_hopper_pause(SubGhzTxRx* instance); +/** + * Speaker on + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_speaker_on(SubGhzTxRx* instance); + +/** + * Speaker off + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_speaker_off(SubGhzTxRx* instance); + +/** + * Speaker mute + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_speaker_mute(SubGhzTxRx* instance); + +/** + * Speaker unmute + * + * @param instance Pointer to a SubGhzTxRx + */ void subghz_txrx_speaker_unmute(SubGhzTxRx* instance); + +/** + * Set state speaker + * + * @param instance Pointer to a SubGhzTxRx + * @param state State speaker + */ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState state); + +/** + * Get state speaker + * + * @param instance Pointer to a SubGhzTxRx + * @return SubGhzSpeakerState + */ SubGhzSpeakerState subghz_txrx_speaker_get_state(SubGhzTxRx* instance); + +/** + * load decoder by name protocol + * + * @param instance Pointer to a SubGhzTxRx + * @param name_protocol Name protocol + * @return bool True if the decoder is loaded + */ bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol); + +/** + * Get decoder + * + * @param instance Pointer to a SubGhzTxRx + * @return SubGhzProtocolDecoderBase* Pointer to a SubGhzProtocolDecoderBase + */ SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance); +/** + * Set callback for save data + * + * @param instance Pointer to a SubGhzTxRx + * @param callback Callback for save data + * @param context Context for callback + */ void subghz_txrx_need_save_callback_set( SubGhzTxRx* instance, SubGhzTxRxNeedSaveCallback callback, void* context); + +/** + * Get pointer to a load data key + * + * @param instance Pointer to a SubGhzTxRx + * @return FlipperFormat* + */ FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* instance); + +/** + * Get pointer to a SugGhzSetting + * + * @param instance Pointer to a SubGhzTxRx + * @return SubGhzSetting* + */ SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance); +/** + * Is it possible to save this protocol + * + * @param instance Pointer to a SubGhzTxRx + * @return bool True if it is possible to save this protocol + */ bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* instance); + +/** + * Is it possible to send this protocol + * + * @param instance Pointer to a SubGhzTxRx + * @return bool True if it is possible to send this protocol + */ bool subghz_txrx_protocol_is_send(SubGhzTxRx* instance, bool check_type); +/** + * Set filter, what types of decoder to use + * + * @param instance Pointer to a SubGhzTxRx + * @param filter Filter + */ void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter); +/** + * Set callback for receive data + * + * @param instance Pointer to a SubGhzTxRx + * @param callback Callback for receive data + * @param context Context for callback + */ void subghz_txrx_set_rx_calback( SubGhzTxRx* instance, SubGhzReceiverCallback callback, void* context); + +/** + * Set callback for Raw decoder, end of data transfer + * + * @param instance Pointer to a SubGhzTxRx + * @param callback Callback for Raw decoder, end of data transfer + * @param context Context for callback + */ void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( SubGhzTxRx* instance, SubGhzProtocolEncoderRAWCallbackEnd callback, diff --git a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h b/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h index 99c83a060..5aa8a31ac 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h +++ b/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h @@ -2,6 +2,17 @@ #include "subghz_types.h" #include "subghz_txrx.h" +/** + * Generate data for protocol + * + * @param instance Pointer to a SubGhzTxRx + * @param preset_name Name of preset + * @param frequency Frequency in Hz + * @param protocol_name Name of protocol + * @param key Key + * @param bit Bit + * @return bool True if success + */ bool subghz_txrx_gen_data_protocol( void* context, const char* preset_name, @@ -10,6 +21,18 @@ bool subghz_txrx_gen_data_protocol( uint64_t key, uint32_t bit); +/** + * Generate data for protocol and te + * + * @param instance Pointer to a SubGhzTxRx + * @param preset_name Name of preset + * @param frequency Frequency in Hz + * @param protocol_name Name of protocol + * @param key Key + * @param bit Bit + * @param te Te + * @return bool True if success + */ bool subghz_txrx_gen_data_protocol_and_te( SubGhzTxRx* instance, const char* preset_name, @@ -19,6 +42,18 @@ bool subghz_txrx_gen_data_protocol_and_te( uint32_t bit, uint32_t te); +/** + * Generate data Keeloq protocol + * + * @param instance Pointer to a SubGhzTxRx + * @param preset_name Name of preset + * @param frequency Frequency in Hz + * @param serial Serial number + * @param btn Button + * @param cnt Counter + * @param manufacture_name Name of Keeloq sysmem + * @return bool True if success + */ bool subghz_txrx_gen_keelog_protocol( SubGhzTxRx* instance, const char* preset_name, @@ -73,6 +108,17 @@ bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename uint8_t btn, uint16_t cnt); +/** + * Generate data SecPlus v2 protocol + * + * @param instance Pointer to a SubGhzTxRx + * @param name_preset Name of preset + * @param frequency Frequency in Hz + * @param serial Serial number + * @param btn Button + * @param cnt Counter + * @return bool True if success + */ bool subghz_txrx_gen_secplus_v2_protocol( SubGhzTxRx* instance, const char* name_preset, @@ -81,6 +127,14 @@ bool subghz_txrx_gen_secplus_v2_protocol( uint8_t btn, uint32_t cnt); +/** + * Generate data SecPlus v1 protocol + * + * @param instance Pointer to a SubGhzTxRx + * @param name_preset Name of preset + * @param frequency Frequency in Hz + * @return bool True if success + */ bool subghz_txrx_gen_secplus_v1_protocol( SubGhzTxRx* instance, const char* name_preset, diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index d17c6858f..50a5919ba 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -163,21 +163,23 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { FURI_LOG_E(TAG, "Missing Protocol"); break; } + + FlipperFormat* fff_data = subghz_txtx_get_fff_data(subghz->txrx); if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) { //if RAW subghz->load_type_file = SubGhzLoadTypeFileRaw; - subghz_protocol_raw_gen_fff_data(subghz_txtx_get_fff_data(subghz->txrx), file_path); + subghz_protocol_raw_gen_fff_data(fff_data, file_path); } else { subghz->load_type_file = SubGhzLoadTypeFileKey; stream_copy_full( flipper_format_get_raw_stream(fff_data_file), - flipper_format_get_raw_stream(subghz_txtx_get_fff_data(subghz->txrx))); + flipper_format_get_raw_stream(fff_data)); } if(subghz_txrx_load_decoder_by_name_protocol( subghz->txrx, furi_string_get_cstr(temp_str))) { SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize( - subghz_txrx_get_decoder(subghz->txrx), subghz_txtx_get_fff_data(subghz->txrx)); + subghz_txrx_get_decoder(subghz->txrx), fff_data); if(status != SubGhzProtocolStatusOk) { load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr; break; From 5b447d0a56c95d10a8902228e445ff7bfc3c4122 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 21:44:53 +0300 Subject: [PATCH 24/36] SubGhz: refactoring --- applications/main/subghz/scenes/subghz_scene_transmitter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index c1bbd2343..8ef61bd53 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -84,7 +84,8 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { subghz_txrx_stop(subghz->txrx); if(!subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx))) { - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); + scene_manager_next_scene( + subghz->scene_manager, SubGhzSceneShowOnlyRx); //TODO Is this necessary? } subghz_txrx_stop(subghz->txrx); From 85d44c5f6c2cd1e253ba879e19589d3cd1da05a6 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 21:54:56 +0300 Subject: [PATCH 25/36] SubGhz: fix naming part 2 and 3 --- .../main/subghz/helpers/subghz_txrx.c | 22 +++++++++---------- .../main/subghz/helpers/subghz_txrx.h | 18 +++++++-------- .../main/subghz/helpers/subghz_txrx_i.h | 2 +- .../subghz/scenes/subghz_scene_decode_raw.c | 6 ++--- .../main/subghz/scenes/subghz_scene_delete.c | 2 +- .../subghz/scenes/subghz_scene_delete_raw.c | 2 +- .../subghz/scenes/subghz_scene_read_raw.c | 10 ++++----- .../subghz/scenes/subghz_scene_receiver.c | 7 +++--- .../scenes/subghz_scene_receiver_info.c | 12 +++++----- .../main/subghz/scenes/subghz_scene_rpc.c | 2 +- .../subghz/scenes/subghz_scene_save_name.c | 4 ++-- .../subghz/scenes/subghz_scene_transmitter.c | 10 ++++----- applications/main/subghz/subghz.c | 4 ++-- applications/main/subghz/subghz_i.c | 8 +++---- 14 files changed, 55 insertions(+), 54 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 38cf549de..fcbebba8f 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -24,7 +24,7 @@ SubGhzTxRx* subghz_txrx_alloc() { instance->fff_data = flipper_format_string_alloc(); instance->environment = subghz_environment_alloc(); - instance->load_database = subghz_environment_load_keystore( + instance->is_database_loaded = subghz_environment_load_keystore( instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes")); subghz_environment_load_keystore( instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user")); @@ -60,9 +60,9 @@ void subghz_txrx_free(SubGhzTxRx* instance) { free(instance); } -bool subghz_txrx_is_load_database(SubGhzTxRx* instance) { +bool subghz_txrx_is_database_loaded(SubGhzTxRx* instance) { furi_assert(instance); - return instance->load_database; + return instance->is_database_loaded; } void subghz_txrx_set_preset( @@ -79,7 +79,7 @@ void subghz_txrx_set_preset( preset->data_size = preset_data_size; } -const char* subghz_txrx_get_name_preset(SubGhzTxRx* instance, const char* preset) { +const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset) { UNUSED(instance); const char* preset_name = NULL; if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { @@ -103,7 +103,7 @@ SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance) { return *instance->preset; } -void subghz_txrx_get_frequency_modulation( +void subghz_txrx_get_frequency_and_modulation( SubGhzTxRx* instance, FuriString* frequency, FuriString* modulation, @@ -282,7 +282,7 @@ void subghz_txrx_rx_start(SubGhzTxRx* instance) { subghz_txrx_rx(instance, instance->preset->frequency); } -void subghz_txrx_need_save_callback_set( +void subghz_txrx_set_need_save_callback( SubGhzTxRx* instance, SubGhzTxRxNeedSaveCallback callback, void* context) { @@ -311,7 +311,7 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) { // notification_message(notifications, &sequence_reset_red); } -FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* instance) { +FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) { furi_assert(instance); return instance->fff_data; } @@ -398,7 +398,7 @@ void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state) instance->hopper_state = state; } -void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance) { +void subghz_txrx_hopper_unpause(SubGhzTxRx* instance) { furi_assert(instance); if(instance->hopper_state == SubGhzHopperStatePause) { instance->hopper_state = SubGhzHopperStateRunning; @@ -501,14 +501,14 @@ SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) { return instance->decoder_result; } -bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* instance) { +bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance) { furi_assert(instance); return ( (instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == SubGhzProtocolFlag_Save); } -bool subghz_txrx_protocol_is_send(SubGhzTxRx* instance, bool check_type) { +bool subghz_txrx_protocol_is_transmittable(SubGhzTxRx* instance, bool check_type) { furi_assert(instance); const SubGhzProtocol* protocol = instance->decoder_result->protocol; if(check_type) { @@ -533,7 +533,7 @@ void subghz_txrx_set_rx_calback( subghz_receiver_set_rx_callback(instance->receiver, callback, context); } -void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( +void subghz_txrx_set_raw_file_encoder_worker_callback_end( SubGhzTxRx* instance, SubGhzProtocolEncoderRAWCallbackEnd callback, void* context) { diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index e44b57a13..f2bf6d9a1 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -37,7 +37,7 @@ void subghz_txrx_free(SubGhzTxRx* instance); * @param instance Pointer to a SubGhzTxRx * @return bool True if the database is loaded */ -bool subghz_txrx_is_load_database(SubGhzTxRx* instance); +bool subghz_txrx_is_database_loaded(SubGhzTxRx* instance); /** * Set preset @@ -62,7 +62,7 @@ void subghz_txrx_set_preset( * @param preset String of preset * @return const char* Name of preset */ -const char* subghz_txrx_get_name_preset(SubGhzTxRx* instance, const char* preset); +const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset); /** * Get of preset @@ -79,7 +79,7 @@ SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance); * @param frequency Pointer to a string frequency * @param modulation Pointer to a string modulation */ -void subghz_txrx_get_frequency_modulation( +void subghz_txrx_get_frequency_and_modulation( SubGhzTxRx* instance, FuriString* frequency, FuriString* modulation, @@ -143,7 +143,7 @@ void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state) * * @param instance Pointer to a SubGhzTxRx */ -void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance); +void subghz_txrx_hopper_unpause(SubGhzTxRx* instance); /** * Set pause hopper @@ -220,7 +220,7 @@ SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance); * @param callback Callback for save data * @param context Context for callback */ -void subghz_txrx_need_save_callback_set( +void subghz_txrx_set_need_save_callback( SubGhzTxRx* instance, SubGhzTxRxNeedSaveCallback callback, void* context); @@ -231,7 +231,7 @@ void subghz_txrx_need_save_callback_set( * @param instance Pointer to a SubGhzTxRx * @return FlipperFormat* */ -FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* instance); +FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance); /** * Get pointer to a SugGhzSetting @@ -247,7 +247,7 @@ SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance); * @param instance Pointer to a SubGhzTxRx * @return bool True if it is possible to save this protocol */ -bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* instance); +bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance); /** * Is it possible to send this protocol @@ -255,7 +255,7 @@ bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* instance); * @param instance Pointer to a SubGhzTxRx * @return bool True if it is possible to send this protocol */ -bool subghz_txrx_protocol_is_send(SubGhzTxRx* instance, bool check_type); +bool subghz_txrx_protocol_is_transmittable(SubGhzTxRx* instance, bool check_type); /** * Set filter, what types of decoder to use @@ -284,7 +284,7 @@ void subghz_txrx_set_rx_calback( * @param callback Callback for Raw decoder, end of data transfer * @param context Context for callback */ -void subghz_txrx_set_raw_file_encoder_worker_set_callback_end( +void subghz_txrx_set_raw_file_encoder_worker_callback_end( SubGhzTxRx* instance, SubGhzProtocolEncoderRAWCallbackEnd callback, void* context); diff --git a/applications/main/subghz/helpers/subghz_txrx_i.h b/applications/main/subghz/helpers/subghz_txrx_i.h index 2d3025554..e5c1445ea 100644 --- a/applications/main/subghz/helpers/subghz_txrx_i.h +++ b/applications/main/subghz/helpers/subghz_txrx_i.h @@ -21,7 +21,7 @@ struct SubGhzTxRx { uint8_t hopper_timeout; uint8_t hopper_idx_frequency; - bool load_database; + bool is_database_loaded; SubGhzHopperState hopper_state; SubGhzTxRxState txrx_state; diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index f008db380..5ad12b509 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -29,7 +29,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, false); subghz_view_receiver_add_data_statusbar( subghz->subghz_receiver, @@ -88,13 +88,13 @@ bool subghz_scene_decode_raw_start(SubGhz* subghz) { FuriString* file_name = furi_string_alloc(); bool success = false; do { - if(!flipper_format_rewind(subghz_txtx_get_fff_data(subghz->txrx))) { + if(!flipper_format_rewind(subghz_txrx_get_fff_data(subghz->txrx))) { FURI_LOG_E(TAG, "Rewind error"); break; } if(!flipper_format_read_string( - subghz_txtx_get_fff_data(subghz->txrx), "File_name", file_name)) { + subghz_txrx_get_fff_data(subghz->txrx), "File_name", file_name)) { FURI_LOG_E(TAG, "Missing File_name"); break; } diff --git a/applications/main/subghz/scenes/subghz_scene_delete.c b/applications/main/subghz/scenes/subghz_scene_delete.c index 095cdf899..3fc4be069 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete.c +++ b/applications/main/subghz/scenes/subghz_scene_delete.c @@ -15,7 +15,7 @@ void subghz_scene_delete_on_enter(void* context) { FuriString* modulation_str = furi_string_alloc(); FuriString* text = furi_string_alloc(); - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 78, diff --git a/applications/main/subghz/scenes/subghz_scene_delete_raw.c b/applications/main/subghz/scenes/subghz_scene_delete_raw.c index bc8a4d6ef..ada0f4c5c 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_delete_raw.c @@ -30,7 +30,7 @@ void subghz_scene_delete_raw_on_enter(void* context) { widget_add_string_element( subghz->widget, 38, 25, AlignLeft, AlignTop, FontSecondary, "RAW signal"); - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 35, diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 4d9553854..a858ca355 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -13,7 +13,7 @@ bool subghz_scene_read_raw_update_filename(SubGhz* subghz) { //set the path to read the file FuriString* temp_str = furi_string_alloc(); do { - FlipperFormat* fff_data = subghz_txtx_get_fff_data(subghz->txrx); + FlipperFormat* fff_data = subghz_txrx_get_fff_data(subghz->txrx); if(!flipper_format_rewind(fff_data)) { FURI_LOG_E(TAG, "Rewind error"); break; @@ -41,7 +41,7 @@ static void subghz_scene_read_raw_update_statusbar(void* context) { FuriString* modulation_str = furi_string_alloc(); #ifdef SUBGHZ_EXT_PRESET_NAME - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, true); + subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, true); //TODO if need subghz_txrx_get_preset //furi_string_printf(modulation_str, "%s", furi_string_get_cstr(subghz->txrx->preset->name)); #else @@ -206,7 +206,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); - if(!subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx))) { + if(!subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); subghz_read_raw_set_status( subghz->subghz_read_raw, @@ -219,7 +219,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { DOLPHIN_DEED(DolphinDeedSubGhzSend); } // set callback end tx - subghz_txrx_set_raw_file_encoder_worker_set_callback_end( + subghz_txrx_set_raw_file_encoder_worker_callback_end( subghz->txrx, subghz_scene_read_raw_callback_end_tx, subghz); subghz->state_notifications = SubGhzNotificationStateTx; } @@ -250,7 +250,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { furi_string_printf( temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, RAW_FILE_NAME, SUBGHZ_APP_EXTENSION); subghz_protocol_raw_gen_fff_data( - subghz_txtx_get_fff_data(subghz->txrx), furi_string_get_cstr(temp_str)); + subghz_txrx_get_fff_data(subghz->txrx), furi_string_get_cstr(temp_str)); furi_string_free(temp_str); if(spl_count > 0) { diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 304797eff..8abb6aff3 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -46,12 +46,12 @@ static void subghz_scene_receiver_update_statusbar(void* context) { #ifdef SUBGHZ_EXT_PRESET_NAME if(subghz_history_get_last_index(subghz->history) > 0) { - subghz_txrx_get_frequency_modulation( + subghz_txrx_get_frequency_and_modulation( subghz->txrx, frequency_str, modulation_str, false); } else { FuriString* temp_str = furi_string_alloc(); - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, temp_str, true); + subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, temp_str, true); furi_string_printf( modulation_str, "%s Mod: %s", @@ -60,7 +60,8 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_free(temp_str); } #else - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation( + subghz->txrx, frequency_str, modulation_str, false); #endif subghz_view_receiver_add_data_statusbar( diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index c92573e85..5a4dbf5d4 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -52,7 +52,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { FuriString* modulation_str = furi_string_alloc(); FuriString* text = furi_string_alloc(); - subghz_txrx_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 78, @@ -78,7 +78,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { furi_string_free(modulation_str); furi_string_free(text); - if(subghz_txrx_protocol_is_preserved(subghz->txrx)) { + if(subghz_txrx_protocol_is_serializable(subghz->txrx)) { widget_add_button_element( subghz->widget, GuiButtonTypeRight, @@ -87,7 +87,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { subghz); } // Removed static check - if(subghz_txrx_protocol_is_send(subghz->txrx, false)) { + if(subghz_txrx_protocol_is_transmittable(subghz->txrx, false)) { widget_add_button_element( subghz->widget, GuiButtonTypeCenter, @@ -127,7 +127,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) subghz, subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen))) { subghz_txrx_rx_start(subghz->txrx); - subghz_txrx_hopper_remove_pause(subghz->txrx); + subghz_txrx_hopper_unpause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; } else { subghz->state_notifications = SubGhzNotificationStateTx; @@ -144,7 +144,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) if(!subghz->in_decoder_scene) { subghz_txrx_rx_start(subghz->txrx); - subghz_txrx_hopper_remove_pause(subghz->txrx); + subghz_txrx_hopper_unpause(subghz->txrx); subghz->state_notifications = SubGhzNotificationStateRx; } return true; @@ -158,7 +158,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) return false; } - if(subghz_txrx_protocol_is_preserved(subghz->txrx)) { + if(subghz_txrx_protocol_is_serializable(subghz->txrx)) { subghz_file_name_clear(subghz); if(subghz->in_decoder_scene) { diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 59497c493..ef718c4e1 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -44,7 +44,7 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) { } else if(event.event == SubGhzCustomEventSceneRpcButtonPress) { bool result = false; if((state == SubGhzRpcStateLoaded)) { - result = subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx)); + result = subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx)); state = SubGhzRpcStateTx; if(result) subghz_blink_start(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index c05230d97..b0c3a1b12 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -147,7 +147,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { SubGhzCustomEventManagerNoSet) { subghz_save_protocol_to_file( subghz, - subghz_txtx_get_fff_data(subghz->txrx), + subghz_txrx_get_fff_data(subghz->txrx), furi_string_get_cstr(subghz->file_path)); scene_manager_set_scene_state( subghz->scene_manager, @@ -164,7 +164,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerNoSet) { subghz_protocol_raw_gen_fff_data( - subghz_txtx_get_fff_data(subghz->txrx), + subghz_txrx_get_fff_data(subghz->txrx), furi_string_get_cstr(subghz->file_path)); scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet); diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 8ef61bd53..5ac1b0a27 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -23,17 +23,17 @@ bool subghz_scene_transmitter_update_data_show(void* context) { FuriString* modulation_str = furi_string_alloc(); if(subghz_protocol_decoder_base_deserialize( - decoder, subghz_txtx_get_fff_data(subghz->txrx)) == SubGhzProtocolStatusOk) { + decoder, subghz_txrx_get_fff_data(subghz->txrx)) == SubGhzProtocolStatusOk) { subghz_protocol_decoder_base_get_string(decoder, key_str); - subghz_txrx_get_frequency_modulation( + subghz_txrx_get_frequency_and_modulation( subghz->txrx, frequency_str, modulation_str, false); subghz_view_transmitter_add_data_to_show( subghz->subghz_transmitter, furi_string_get_cstr(key_str), furi_string_get_cstr(frequency_str), furi_string_get_cstr(modulation_str), - subghz_txrx_protocol_is_send(subghz->txrx, false)); + subghz_txrx_protocol_is_transmittable(subghz->txrx, false)); ret = true; } furi_string_free(frequency_str); @@ -67,7 +67,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(event.event == SubGhzCustomEventViewTransmitterSendStart) { subghz->state_notifications = SubGhzNotificationStateIDLE; - if(subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx))) { + if(subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { subghz->state_notifications = SubGhzNotificationStateTx; subghz_scene_transmitter_update_data_show(subghz); DOLPHIN_DEED(DolphinDeedSubGhzSend); @@ -83,7 +83,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { // Calling restore! subghz_txrx_stop(subghz->txrx); - if(!subghz_tx_start(subghz, subghz_txtx_get_fff_data(subghz->txrx))) { + if(!subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { scene_manager_next_scene( subghz->scene_manager, SubGhzSceneShowOnlyRx); //TODO Is this necessary? } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 4bf6e7aaf..f9413bbfb 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -265,7 +265,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->filter = SubGhzProtocolFlag_Decodable; subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); - subghz_txrx_need_save_callback_set(subghz->txrx, subghz_save_to_file, subghz); + subghz_txrx_set_need_save_callback(subghz->txrx, subghz_save_to_file, subghz); //Init Error_str subghz->error_str = furi_string_alloc(); @@ -446,7 +446,7 @@ int32_t subghz_app(void* p) { view_dispatcher_attach_to_gui( subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen); furi_string_set(subghz->file_path, SUBGHZ_APP_FOLDER); - if(subghz_txrx_is_load_database(subghz->txrx)) { + if(subghz_txrx_is_database_loaded(subghz->txrx)) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart); } else { scene_manager_set_scene_state( diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 50a5919ba..243a1a123 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -79,7 +79,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); Stream* fff_data_stream = - flipper_format_get_raw_stream(subghz_txtx_get_fff_data(subghz->txrx)); + flipper_format_get_raw_stream(subghz_txrx_get_fff_data(subghz->txrx)); SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr; FuriString* temp_str = furi_string_alloc(); @@ -129,7 +129,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } furi_string_set_str( - temp_str, subghz_txrx_get_name_preset(subghz->txrx, furi_string_get_cstr(temp_str))); + temp_str, subghz_txrx_get_preset_name(subghz->txrx, furi_string_get_cstr(temp_str))); if(temp_str == NULL) { break; } @@ -164,7 +164,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { break; } - FlipperFormat* fff_data = subghz_txtx_get_fff_data(subghz->txrx); + FlipperFormat* fff_data = subghz_txrx_get_fff_data(subghz->txrx); if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) { //if RAW subghz->load_type_file = SubGhzLoadTypeFileRaw; @@ -276,7 +276,7 @@ void subghz_save_to_file(void* context) { if(subghz_path_is_file(subghz->file_path)) { subghz_save_protocol_to_file( subghz, - subghz_txtx_get_fff_data(subghz->txrx), + subghz_txrx_get_fff_data(subghz->txrx), furi_string_get_cstr(subghz->file_path)); } } From 0019baaa00993f1e1da6bdc102915557416ab7ff Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 21:58:36 +0300 Subject: [PATCH 26/36] SubGhz: simplify includes --- applications/main/subghz/helpers/subghz_txrx.c | 1 - applications/main/subghz/helpers/subghz_txrx.h | 1 - applications/main/subghz/helpers/subghz_txrx_callbacks.h | 2 -- applications/main/subghz/helpers/subghz_txrx_i.h | 7 +------ 4 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 applications/main/subghz/helpers/subghz_txrx_callbacks.h diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index fcbebba8f..a96004046 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -1,5 +1,4 @@ #include "subghz_txrx_i.h" -#include "subghz_txrx.h" #include #define TAG "SubGhz" diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index f2bf6d9a1..edd7fa81d 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -1,6 +1,5 @@ #pragma once #include "subghz_types.h" -#include "subghz_txrx_callbacks.h" #include #include #include diff --git a/applications/main/subghz/helpers/subghz_txrx_callbacks.h b/applications/main/subghz/helpers/subghz_txrx_callbacks.h deleted file mode 100644 index 5bee720e9..000000000 --- a/applications/main/subghz/helpers/subghz_txrx_callbacks.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -typedef void (*SubGhzTxRxNeedSaveCallback)(void* context); \ No newline at end of file diff --git a/applications/main/subghz/helpers/subghz_txrx_i.h b/applications/main/subghz/helpers/subghz_txrx_i.h index e5c1445ea..680d27158 100644 --- a/applications/main/subghz/helpers/subghz_txrx_i.h +++ b/applications/main/subghz/helpers/subghz_txrx_i.h @@ -1,11 +1,6 @@ #pragma once -#include "subghz_types.h" -#include "subghz_txrx_callbacks.h" -#include -#include -#include -#include +#include "subghz_txrx.h" struct SubGhzTxRx { SubGhzWorker* worker; From a3cf592f298c93ffb3af71a10fd1f62466223b33 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 22:16:52 +0300 Subject: [PATCH 27/36] Minor fixes --- .../main/subghz/helpers/subghz_txrx.c | 7 +++++- .../main/subghz/helpers/subghz_txrx.h | 2 ++ applications/main/subghz/subghz_i.c | 24 +++++++++---------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index a96004046..c1f519ba0 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -80,7 +80,7 @@ void subghz_txrx_set_preset( const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset) { UNUSED(instance); - const char* preset_name = NULL; + const char* preset_name = ""; if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { preset_name = "AM270"; } else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) { @@ -198,6 +198,7 @@ static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) { subghz_txrx_speaker_on(instance); instance->txrx_state = SubGhzTxRxStateTx; } + return ret; } @@ -245,11 +246,13 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* } else { ret = SubGhzTxRxStartTxStateErrorParserOthers; } + } else { FURI_LOG_E( TAG, "Unknown name preset \" %s \"", furi_string_get_cstr(preset->name)); ret = SubGhzTxRxStartTxStateErrorParserOthers; } + if(ret == SubGhzTxRxStartTxStateOk) { //Start TX furi_hal_subghz_start_async_tx( @@ -258,6 +261,8 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* } else { ret = SubGhzTxRxStartTxStateErrorParserOthers; } + } else { + ret = SubGhzTxRxStartTxStateErrorParserOthers; } if(ret != SubGhzTxRxStartTxStateOk) { subghz_transmitter_free(instance->transmitter); diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index edd7fa81d..fd7c024b8 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -1,5 +1,7 @@ #pragma once + #include "subghz_types.h" + #include #include #include diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 243a1a123..205c7ca02 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -130,7 +130,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { furi_string_set_str( temp_str, subghz_txrx_get_preset_name(subghz->txrx, furi_string_get_cstr(temp_str))); - if(temp_str == NULL) { + if(!strcmp(furi_string_get_cstr(temp_str), "")) { break; } @@ -270,17 +270,6 @@ bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len) { return res; } -void subghz_save_to_file(void* context) { - furi_assert(context); - SubGhz* subghz = context; - if(subghz_path_is_file(subghz->file_path)) { - subghz_save_protocol_to_file( - subghz, - subghz_txrx_get_fff_data(subghz->txrx), - furi_string_get_cstr(subghz->file_path)); - } -} - bool subghz_save_protocol_to_file( SubGhz* subghz, FlipperFormat* flipper_format, @@ -321,6 +310,17 @@ bool subghz_save_protocol_to_file( return saved; } +void subghz_save_to_file(void* context) { + furi_assert(context); + SubGhz* subghz = context; + if(subghz_path_is_file(subghz->file_path)) { + subghz_save_protocol_to_file( + subghz, + subghz_txrx_get_fff_data(subghz->txrx), + furi_string_get_cstr(subghz->file_path)); + } +} + bool subghz_load_protocol_from_file(SubGhz* subghz) { furi_assert(subghz); From 6f109903867ee0f208e1113febdfa96fab227cea Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Wed, 10 May 2023 13:21:42 +0300 Subject: [PATCH 28/36] SubGhz: fix syntax & minor fixes --- .../subghz/scenes/subghz_scene_need_saving.c | 2 +- .../main/subghz/scenes/subghz_scene_read_raw.c | 5 +---- .../main/subghz/scenes/subghz_scene_receiver.c | 1 - .../scenes/subghz_scene_receiver_config.c | 8 ++++---- .../subghz/scenes/subghz_scene_receiver_info.c | 6 +++--- .../main/subghz/scenes/subghz_scene_saved.c | 2 +- .../subghz/scenes/subghz_scene_transmitter.c | 2 +- applications/main/subghz/subghz.c | 2 +- applications/main/subghz/subghz_i.c | 17 +++++++---------- 9 files changed, 19 insertions(+), 26 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_need_saving.c b/applications/main/subghz/scenes/subghz_scene_need_saving.c index 8bbaae2ce..8259b6e82 100644 --- a/applications/main/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/main/subghz/scenes/subghz_scene_need_saving.c @@ -49,7 +49,7 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { SubGhzRxKeyState state = subghz_rx_key_state_get(subghz); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - if(state) { + if(state == SubGhzRxKeyStateExit) { subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index a858ca355..4b8303ddd 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -125,6 +125,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case SubGhzCustomEventViewReadRAWBack: + subghz_txrx_stop(subghz->txrx); //Stop save file subghz_protocol_raw_save_to_file_stop(decoder_raw); @@ -204,8 +205,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_file_available(subghz) && subghz_scene_read_raw_update_filename(subghz)) { //start send subghz->state_notifications = SubGhzNotificationStateIDLE; - - subghz_txrx_stop(subghz->txrx); if(!subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack); subghz_read_raw_set_status( @@ -273,7 +272,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_protocol_raw_save_to_file_init(decoder_raw, RAW_FILE_NAME, &preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); subghz_txrx_rx_start(subghz->txrx); - subghz->state_notifications = SubGhzNotificationStateRx; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); } else { @@ -316,7 +314,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz_read_raw_add_data_rssi( subghz->subghz_read_raw, ret_rssi.rssi, ret_rssi.is_above); subghz_protocol_raw_save_to_file_pause(decoder_raw, !ret_rssi.is_above); - break; case SubGhzNotificationStateTx: notification_message(subghz->notifications, &sequence_blink_magenta_10); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 8abb6aff3..9987449cd 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -184,7 +184,6 @@ void subghz_scene_receiver_on_enter(void* context) { } subghz->state_notifications = SubGhzNotificationStateRx; - subghz_txrx_stop(subghz->txrx); subghz_txrx_rx_start(subghz->txrx); subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index e9f84ed0e..29d55c03a 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -92,9 +92,9 @@ const char* const magellan_text[MAGELLAN_COUNT] = { uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) { furi_assert(context); SubGhz* subghz = context; - uint8_t index = 0; SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); + uint8_t index = 0; for(uint8_t i = 0; i < subghz_setting_get_frequency_count(setting); i++) { if(value == subghz_setting_get_frequency(setting, i)) { index = i; @@ -186,7 +186,6 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { variable_item_set_current_value_text(item, preset_name); //subghz->last_settings->preset = index; SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); - subghz_txrx_set_preset( subghz->txrx, preset_name, @@ -309,12 +308,13 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item); variable_item_set_current_value_index(item, value_index); char text_buf[10] = {0}; + uint32_t frequency = subghz_setting_get_frequency(setting, value_index); snprintf( text_buf, sizeof(text_buf), "%lu.%02lu", - subghz_setting_get_frequency(setting, value_index) / 1000000, - (subghz_setting_get_frequency(setting, value_index) % 1000000) / 10000); + frequency / 1000000, + (frequency % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); item = variable_item_list_add( diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 5a4dbf5d4..c04f39cb8 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -52,7 +52,8 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { FuriString* modulation_str = furi_string_alloc(); FuriString* text = furi_string_alloc(); - subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation( + subghz->txrx, frequency_str, modulation_str, false); widget_add_string_element( subghz->widget, 78, @@ -120,7 +121,6 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } - //CC1101 Stop RX -> Start TX subghz_txrx_hopper_pause(subghz->txrx); if(!subghz_tx_start( @@ -140,7 +140,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) widget_reset(subghz->widget); subghz_scene_receiver_info_draw_widget(subghz); - subghz_txrx_stop(subghz->txrx); + subghz_txrx_stop(subghz->txrx); //TODO this is probably a redundant call if(!subghz->in_decoder_scene) { subghz_txrx_rx_start(subghz->txrx); diff --git a/applications/main/subghz/scenes/subghz_scene_saved.c b/applications/main/subghz/scenes/subghz_scene_saved.c index eca5ab801..8b198e339 100644 --- a/applications/main/subghz/scenes/subghz_scene_saved.c +++ b/applications/main/subghz/scenes/subghz_scene_saved.c @@ -4,7 +4,7 @@ void subghz_scene_saved_on_enter(void* context) { SubGhz* subghz = context; if(subghz_load_protocol_from_file(subghz)) { - if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { + if(subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); } else { diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 5ac1b0a27..c3ae04a8f 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -81,7 +81,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); furi_hal_subghz_set_rolling_counter_mult(0); // Calling restore! - subghz_txrx_stop(subghz->txrx); + subghz_txrx_stop(subghz->txrx); //TODO this is probably a redundant call if(!subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { scene_manager_next_scene( diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index f9413bbfb..975ec540a 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -428,7 +428,7 @@ int32_t subghz_app(void* p) { if(subghz_key_load(subghz, p, true)) { furi_string_set(subghz->file_path, (const char*)p); - if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { + if(subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw) { //Load Raw TX subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 205c7ca02..70812ed11 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -133,30 +133,27 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { if(!strcmp(furi_string_get_cstr(temp_str), "")) { break; } + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); if(!strcmp(furi_string_get_cstr(temp_str), "CUSTOM")) { //Todo add Custom_preset_module //delete preset if it already exists - subghz_setting_delete_custom_preset( - subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(temp_str)); + subghz_setting_delete_custom_preset(setting, furi_string_get_cstr(temp_str)); //load custom preset from file if(!subghz_setting_load_custom_preset( - subghz_txrx_get_setting(subghz->txrx), - furi_string_get_cstr(temp_str), - fff_data_file)) { + setting, furi_string_get_cstr(temp_str), fff_data_file)) { FURI_LOG_E(TAG, "Missing Custom preset"); break; } } - size_t preset_index = subghz_setting_get_inx_preset_by_name( - subghz_txrx_get_setting(subghz->txrx), furi_string_get_cstr(temp_str)); + size_t preset_index = + subghz_setting_get_inx_preset_by_name(setting, furi_string_get_cstr(temp_str)); subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(temp_str), temp_data32, - subghz_setting_get_preset_data(subghz_txrx_get_setting(subghz->txrx), preset_index), - subghz_setting_get_preset_data_size( - subghz_txrx_get_setting(subghz->txrx), preset_index)); + subghz_setting_get_preset_data(setting, preset_index), + subghz_setting_get_preset_data_size(setting, preset_index)); //Load protocol if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) { From cca6606c7819fd4c3249172bb895a51a7030bcfd Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 10 May 2023 21:48:48 +0300 Subject: [PATCH 29/36] fix typos from ofw --- .../debug/unit_tests/subghz/subghz_test.c | 8 ++--- ...ey.c => subghz_txrx_create_protocol_key.c} | 4 +-- ...ey.h => subghz_txrx_create_protocol_key.h} | 2 +- .../subghz/scenes/subghz_scene_set_seed.c | 2 +- .../subghz/scenes/subghz_scene_set_type.c | 36 +++++++++---------- lib/subghz/protocols/keeloq_common.c | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) rename applications/main/subghz/helpers/{subghz_txrx_create_potocol_key.c => subghz_txrx_create_protocol_key.c} (98%) rename applications/main/subghz/helpers/{subghz_txrx_create_potocol_key.h => subghz_txrx_create_protocol_key.h} (98%) diff --git a/applications/debug/unit_tests/subghz/subghz_test.c b/applications/debug/unit_tests/subghz/subghz_test.c index c7e9c96f1..f1ab92653 100644 --- a/applications/debug/unit_tests/subghz/subghz_test.c +++ b/applications/debug/unit_tests/subghz/subghz_test.c @@ -407,7 +407,7 @@ MU_TEST(subghz_decoder_ido_test) { "Test decoder " SUBGHZ_PROTOCOL_IDO_NAME " error\r\n"); } -MU_TEST(subghz_decoder_keelog_test) { +MU_TEST(subghz_decoder_keeloq_test) { mu_assert( subghz_decoder_test( EXT_PATH("unit_tests/subghz/doorhan_raw.sub"), SUBGHZ_PROTOCOL_KEELOQ_NAME), @@ -676,7 +676,7 @@ MU_TEST(subghz_encoder_nice_flo_test) { "Test encoder " SUBGHZ_PROTOCOL_NICE_FLO_NAME " error\r\n"); } -MU_TEST(subghz_encoder_keelog_test) { +MU_TEST(subghz_encoder_keeloq_test) { mu_assert( subghz_encoder_test(EXT_PATH("unit_tests/subghz/doorhan.sub")), "Test encoder " SUBGHZ_PROTOCOL_KEELOQ_NAME " error\r\n"); @@ -813,7 +813,7 @@ MU_TEST_SUITE(subghz) { MU_RUN_TEST(subghz_decoder_gate_tx_test); MU_RUN_TEST(subghz_decoder_hormann_hsm_test); MU_RUN_TEST(subghz_decoder_ido_test); - MU_RUN_TEST(subghz_decoder_keelog_test); + MU_RUN_TEST(subghz_decoder_keeloq_test); MU_RUN_TEST(subghz_decoder_kia_seed_test); MU_RUN_TEST(subghz_decoder_nero_radio_test); MU_RUN_TEST(subghz_decoder_nero_sketch_test); @@ -852,7 +852,7 @@ MU_TEST_SUITE(subghz) { MU_RUN_TEST(subghz_encoder_came_twee_test); MU_RUN_TEST(subghz_encoder_gate_tx_test); MU_RUN_TEST(subghz_encoder_nice_flo_test); - MU_RUN_TEST(subghz_encoder_keelog_test); + MU_RUN_TEST(subghz_encoder_keeloq_test); MU_RUN_TEST(subghz_encoder_linear_test); MU_RUN_TEST(subghz_encoder_linear_delta3_test); MU_RUN_TEST(subghz_encoder_megacode_test); diff --git a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.c b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c similarity index 98% rename from applications/main/subghz/helpers/subghz_txrx_create_potocol_key.c rename to applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c index 7c3b1c7ff..7a0060f16 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.c +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c @@ -1,5 +1,5 @@ #include "subghz_txrx_i.h" -#include "subghz_txrx_create_potocol_key.h" +#include "subghz_txrx_create_protocol_key.h" #include #include #include @@ -84,7 +84,7 @@ bool subghz_txrx_gen_data_protocol_and_te( return ret; } -bool subghz_txrx_gen_keelog_protocol( //TODO lead to a general appearance +bool subghz_txrx_gen_keeloq_protocol( //TODO lead to a general appearance SubGhzTxRx* instance, const char* preset_name, uint32_t frequency, diff --git a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h similarity index 98% rename from applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h rename to applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h index 5aa8a31ac..96e592936 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_potocol_key.h +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h @@ -54,7 +54,7 @@ bool subghz_txrx_gen_data_protocol_and_te( * @param manufacture_name Name of Keeloq sysmem * @return bool True if success */ -bool subghz_txrx_gen_keelog_protocol( +bool subghz_txrx_gen_keeloq_protocol( SubGhzTxRx* instance, const char* preset_name, uint32_t frequency, diff --git a/applications/main/subghz/scenes/subghz_scene_set_seed.c b/applications/main/subghz/scenes/subghz_scene_set_seed.c index d3537689d..18bc787bb 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_seed.c +++ b/applications/main/subghz/scenes/subghz_scene_set_seed.c @@ -1,5 +1,5 @@ #include "../subghz_i.h" -#include "../helpers/subghz_txrx_create_potocol_key.h" +#include "../helpers/subghz_txrx_create_protocol_key.h" #define TAG "SubGhzSetSeed" diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index 076241767..342f01536 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -1,5 +1,5 @@ #include "../subghz_i.h" -#include "../helpers/subghz_txrx_create_potocol_key.h" +#include "../helpers/subghz_txrx_create_protocol_key.h" #include #include @@ -367,7 +367,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { subghz->txrx, "AM650", 433920000, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24); break; case SubmenuIndexBeninca433: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, @@ -382,7 +382,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexBeninca868: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 868350000, @@ -397,7 +397,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAllmatic433: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, @@ -412,7 +412,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAllmatic868: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 868350000, @@ -427,7 +427,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexElmesElectronic: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, @@ -442,7 +442,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexANMotorsAT4: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, @@ -457,7 +457,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAprimatic: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, @@ -472,7 +472,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexGibidi433: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Gibidi"); if(!generated_protocol) { furi_string_set( @@ -481,7 +481,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexGSN: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "GSN"); if(!generated_protocol) { furi_string_set( @@ -490,7 +490,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexIronLogic: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFF0, 0x4, 0x0005, "IronLogic"); if(!generated_protocol) { furi_string_set( @@ -499,7 +499,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexSommer_FM_434: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "FM476", 434420000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); if(!generated_protocol) { furi_string_set( @@ -508,7 +508,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexSommer_FM_868: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "FM476", 868800000, key & 0x0FFFFFFF, 0x4, 0x0003, "Sommer(fsk476)"); if(!generated_protocol) { furi_string_set( @@ -517,7 +517,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexDTMNeo433: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, key & 0x000FFFFF, 0x2, 0x0005, "DTM_Neo"); if(!generated_protocol) { furi_string_set( @@ -526,7 +526,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexCAMESpace: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "Came_Space"); if(!generated_protocol) { furi_string_set( @@ -569,7 +569,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexDoorHan_433_92: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); if(!generated_protocol) { furi_string_set( @@ -578,7 +578,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexDoorHan_315_00: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 315000000, key & 0x0FFFFFFF, 0x2, 0x0003, "DoorHan"); if(!generated_protocol) { furi_string_set( @@ -605,7 +605,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexNiceSmilo_433_92: - generated_protocol = subghz_txrx_gen_keelog_protocol( + generated_protocol = subghz_txrx_gen_keeloq_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "NICE_Smilo"); if(!generated_protocol) { furi_string_set( diff --git a/lib/subghz/protocols/keeloq_common.c b/lib/subghz/protocols/keeloq_common.c index 1d2d04457..a9a2238dd 100644 --- a/lib/subghz/protocols/keeloq_common.c +++ b/lib/subghz/protocols/keeloq_common.c @@ -23,7 +23,7 @@ inline uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const } /** Simple Learning Decrypt - * @param data - keelog encrypt data + * @param data - keeloq encrypt data * @param key - manufacture (64bit) * @return 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter */ From 735fe31f3bc7e5f05dafb345250674f3c37fe48e Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 10 May 2023 22:56:56 +0300 Subject: [PATCH 30/36] Fmt and cleanup some "if"s in protocols --- applications/main/subghz/scenes/subghz_scene_decode_raw.c | 3 ++- lib/subghz/protocols/alutech_at_4n.c | 6 ++---- lib/subghz/protocols/kinggates_stylo_4k.c | 4 +--- lib/subghz/protocols/somfy_keytis.c | 6 ++---- lib/subghz/protocols/somfy_telis.c | 6 ++---- lib/subghz/protocols/star_line.c | 6 ++---- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 5ad12b509..7dead8d4e 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -29,7 +29,8 @@ static void subghz_scene_receiver_update_statusbar(void* context) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); - subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation( + subghz->txrx, frequency_str, modulation_str, false); subghz_view_receiver_add_data_statusbar( subghz->subghz_receiver, diff --git a/lib/subghz/protocols/alutech_at_4n.c b/lib/subghz/protocols/alutech_at_4n.c index 20dae49c1..47cf37d6b 100644 --- a/lib/subghz/protocols/alutech_at_4n.c +++ b/lib/subghz/protocols/alutech_at_4n.c @@ -429,10 +429,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( if((custom_btn_id == 0) && (original_btn_num != 0)) { btn = original_btn_num; } - //gen new key - if(subghz_protocol_alutech_at_4n_gen_data(instance, btn)) { - //ToDo if you need to add a callback to automatically update the data on the display - } else { + // Gen new key + if(!subghz_protocol_alutech_at_4n_gen_data(instance, btn)) { return false; } diff --git a/lib/subghz/protocols/kinggates_stylo_4k.c b/lib/subghz/protocols/kinggates_stylo_4k.c index a9127d2b1..c5d21bcb0 100644 --- a/lib/subghz/protocols/kinggates_stylo_4k.c +++ b/lib/subghz/protocols/kinggates_stylo_4k.c @@ -197,9 +197,7 @@ static bool subghz_protocol_encoder_kinggates_stylo_4k_get_upload( furi_assert(instance); // Gen new key - if(subghz_protocol_kinggates_stylo_4k_gen_data(instance, btn)) { - //ToDo if you need to add a callback to automatically update the data on the display - } else { + if(!subghz_protocol_kinggates_stylo_4k_gen_data(instance, btn)) { return false; } diff --git a/lib/subghz/protocols/somfy_keytis.c b/lib/subghz/protocols/somfy_keytis.c index dd860a61d..4074d757b 100644 --- a/lib/subghz/protocols/somfy_keytis.c +++ b/lib/subghz/protocols/somfy_keytis.c @@ -208,10 +208,8 @@ static bool subghz_protocol_encoder_somfy_keytis_get_upload( uint8_t btn) { furi_assert(instance); - //gen new key - if(subghz_protocol_somfy_keytis_gen_data(instance, btn)) { - //ToDo if you need to add a callback to automatically update the data on the display - } else { + // Gen new key + if(!subghz_protocol_somfy_keytis_gen_data(instance, btn)) { return false; } diff --git a/lib/subghz/protocols/somfy_telis.c b/lib/subghz/protocols/somfy_telis.c index 047efb688..57c6c510b 100644 --- a/lib/subghz/protocols/somfy_telis.c +++ b/lib/subghz/protocols/somfy_telis.c @@ -254,10 +254,8 @@ static bool subghz_protocol_encoder_somfy_telis_get_upload( uint8_t btn) { furi_assert(instance); - //gen new key - if(subghz_protocol_somfy_telis_gen_data(instance, btn, false)) { - //ToDo if you need to add a callback to automatically update the data on the display - } else { + // Gen new key + if(!subghz_protocol_somfy_telis_gen_data(instance, btn, false)) { return false; } diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 181dee643..cb9b26760 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -237,10 +237,8 @@ static bool subghz_protocol_encoder_star_line_get_upload( uint8_t btn) { furi_assert(instance); - //gen new key - if(subghz_protocol_star_line_gen_data(instance, btn)) { - //ToDo if you need to add a callback to automatically update the data on the display - } else { + // Gen new key + if(!subghz_protocol_star_line_gen_data(instance, btn)) { return false; } From 3e3538b9bc52bbf9337e5adc3f640cb602807b26 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 10 May 2023 23:07:06 +0300 Subject: [PATCH 31/36] Always free --- applications/main/subghz/subghz.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 975ec540a..4f4393efb 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -355,9 +355,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { furi_record_close(RECORD_GUI); subghz->gui = NULL; - if(!alloc_for_tx_only) { - subghz_last_settings_free(subghz->last_settings); //TODO always allocated - } + subghz_last_settings_free(subghz->last_settings); // threshold rssi subghz_threshold_rssi_free(subghz->threshold_rssi); From a941ed8c2aba434d3af852fc2e7178dd70f1e9f5 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 10 May 2023 23:12:50 +0300 Subject: [PATCH 32/36] Rename funcs --- .../subghz/helpers/subghz_txrx_create_protocol_key.c | 10 +++++----- .../subghz/helpers/subghz_txrx_create_protocol_key.h | 10 +++++----- .../main/subghz/scenes/subghz_scene_set_seed.c | 6 +++--- .../main/subghz/scenes/subghz_scene_set_type.c | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c index 7a0060f16..053f472aa 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c @@ -116,7 +116,7 @@ bool subghz_txrx_gen_keeloq_protocol( //TODO lead to a general appearance return res; } -bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_keeloq_bft_protocol( //TODO rename & lead to a general appearance void* context, const char* preset_name, uint32_t frequency, @@ -161,7 +161,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename & lead to return res; } -bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_nice_flor_s_protocol( //TODO rename & lead to a general appearance void* context, const char* preset_name, uint32_t frequency, @@ -193,7 +193,7 @@ bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename & lead to a return res; } -bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_faac_slh_protocol( //TODO rename & lead to a general appearance void* context, const char* preset_name, uint32_t frequency, @@ -236,7 +236,7 @@ bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename & lead to a return res; } -bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_alutech_at_4n_protocol( //TODO rename & lead to a general appearance void* context, const char* preset_name, uint32_t frequency, @@ -266,7 +266,7 @@ bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename & lead return res; } -bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_somfy_telis_protocol( //TODO rename & lead to a general appearance void* context, const char* preset_name, uint32_t frequency, diff --git a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h index 96e592936..61dbf9e56 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h @@ -63,7 +63,7 @@ bool subghz_txrx_gen_keeloq_protocol( uint16_t cnt, const char* manufacture_name); -bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename +bool subghz_txrx_gen_keeloq_bft_protocol( //TODO rename void* context, const char* preset_name, uint32_t frequency, @@ -73,7 +73,7 @@ bool subghz_scene_set_type_submenu_gen_data_keeloq_bft( //TODO rename uint32_t seed, const char* manufacture_name); -bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename +bool subghz_txrx_gen_nice_flor_s_protocol( //TODO rename void* context, const char* preset_name, uint32_t frequency, @@ -82,7 +82,7 @@ bool subghz_scene_set_type_submenu_gen_data_nice_flor( //TODO rename uint16_t cnt, bool nice_one); -bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename +bool subghz_txrx_gen_faac_slh_protocol( //TODO rename void* context, const char* preset_name, uint32_t frequency, @@ -92,7 +92,7 @@ bool subghz_scene_set_type_submenu_gen_data_faac_slh( //TODO rename uint32_t seed, const char* manufacture_name); -bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename +bool subghz_txrx_gen_alutech_at_4n_protocol( //TODO rename void* context, const char* preset_name, uint32_t frequency, @@ -100,7 +100,7 @@ bool subghz_scene_set_type_submenu_gen_data_alutech_at_4n( //TODO rename uint8_t btn, uint16_t cnt); -bool subghz_scene_set_type_submenu_gen_data_somfy_telis( //TODO rename +bool subghz_txrx_gen_somfy_telis_protocol( //TODO rename void* context, const char* preset_name, uint32_t frequency, diff --git a/applications/main/subghz/scenes/subghz_scene_set_seed.c b/applications/main/subghz/scenes/subghz_scene_set_seed.c index 18bc787bb..e6850d1e3 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_seed.c +++ b/applications/main/subghz/scenes/subghz_scene_set_seed.c @@ -45,7 +45,7 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { seed = subghz->secure_data->seed[0] << 24 | subghz->secure_data->seed[1] << 16 | subghz->secure_data->seed[2] << 8 | subghz->secure_data->seed[3]; - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq_bft( + generated_protocol = subghz_txrx_gen_keeloq_bft_protocol( subghz->txrx, "AM650", 433920000, @@ -74,7 +74,7 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { subghz->secure_data->seed[2] << 8 | subghz->secure_data->seed[3]; if(state == SubmenuIndexFaacSLH_433) { - generated_protocol = subghz_scene_set_type_submenu_gen_data_faac_slh( + generated_protocol = subghz_txrx_gen_faac_slh_protocol( subghz->txrx, "AM650", 433920000, @@ -84,7 +84,7 @@ bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) { seed, "FAAC_SLH"); } else if(state == SubmenuIndexFaacSLH_868) { - generated_protocol = subghz_scene_set_type_submenu_gen_data_faac_slh( + generated_protocol = subghz_txrx_gen_faac_slh_protocol( subghz->txrx, "AM650", 868350000, diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index 342f01536..23ecbb539 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -535,7 +535,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexBFTMitto: - generated_protocol = subghz_scene_set_type_submenu_gen_data_keeloq_bft( + generated_protocol = subghz_txrx_gen_keeloq_bft_protocol( subghz->txrx, "AM650", 433920000, @@ -551,7 +551,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexAlutechAT4N: - generated_protocol = subghz_scene_set_type_submenu_gen_data_alutech_at_4n( + generated_protocol = subghz_txrx_gen_alutech_at_4n_protocol( subghz->txrx, "AM650", 433920000, (key & 0x000FFFFF) | 0x00100000, 0x44, 0x0003); if(!generated_protocol) { furi_string_set( @@ -560,7 +560,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexSomfyTelis: - generated_protocol = subghz_scene_set_type_submenu_gen_data_somfy_telis( + generated_protocol = subghz_txrx_gen_somfy_telis_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003); if(!generated_protocol) { //TODO does not use databases furi_string_set( @@ -587,7 +587,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexNiceFlorS_433_92: - generated_protocol = subghz_scene_set_type_submenu_gen_data_nice_flor( + generated_protocol = subghz_txrx_gen_nice_flor_s_protocol( subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, false); if(!generated_protocol) { furi_string_set( @@ -596,7 +596,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } break; case SubmenuIndexNiceOne_433_92: - generated_protocol = subghz_scene_set_type_submenu_gen_data_nice_flor( + generated_protocol = subghz_txrx_gen_nice_flor_s_protocol( subghz->txrx, "AM650", 433920000, key & 0x0FFFFFFF, 0x1, 0x0003, true); if(!generated_protocol) { furi_string_set( From e7707b31f0a503ada1ae6f92d5a8c6735405da50 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 10 May 2023 23:28:09 +0300 Subject: [PATCH 33/36] Do some TODOs --- .../subghz/scenes/subghz_scene_decode_raw.c | 21 +------------------ .../subghz/scenes/subghz_scene_read_raw.c | 4 +--- .../scenes/subghz_scene_receiver_info.c | 4 ++-- .../subghz/scenes/subghz_scene_set_type.c | 5 ----- .../subghz/scenes/subghz_scene_transmitter.c | 2 -- 5 files changed, 4 insertions(+), 32 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 7dead8d4e..4412676f3 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -7,21 +7,6 @@ #define TAG "SubGhzDecodeRaw" #define SAMPLES_TO_READ_PER_TICK 400 -// TODO: -// [X] Remember RAW file after decoding -// [X] Decode in tick events instead of on_enter -// [X] Make "Config" label optional in subghz_view_receiver_draw (../views/receiver.c) -// [X] Make "Scanning..." label optional in subghz_view_receiver_draw (../views/receiver.c) -// [X] Add Decoding logo -// [ ] Design nicer Decoding logo -// [X] Check progress in stream_buffer, instead of raw stream -// [X] Blink led while decoding -// [X] Stop rx blink (blue, fast) on history item view -// [X] Don't reparse file on back -// [X] Fix: RX animation+LED returning from decoded detail view -// [X] Find good value for SAMPLES_TO_READ_PER_TICK -// [X] Fix: read errors (slow flash) after aborting decode read - static void subghz_scene_receiver_update_statusbar(void* context) { SubGhz* subghz = context; FuriString* history_stat_str = furi_string_alloc(); @@ -163,7 +148,7 @@ void subghz_scene_decode_raw_on_enter(void* context) { FuriString* item_time = furi_string_alloc(); subghz_view_receiver_set_lock( - subghz->subghz_receiver, subghz_is_locked(subghz)); //TODO Doesn't matter in DecodeRAW + subghz->subghz_receiver, false); //TODO Doesn't matter in DecodeRAW subghz_view_receiver_set_mode(subghz->subghz_receiver, SubGhzViewReceiverModeFile); subghz_view_receiver_set_callback( subghz->subghz_receiver, subghz_scene_decode_raw_callback, subghz); @@ -243,10 +228,6 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) { notification_message(subghz->notifications, &sequence_display_backlight_off); consumed = true; break; - case SubGhzCustomEventViewReceiverUnlock: - subghz_unlock(subghz); //TODO There is no such event in DecodeRAW - consumed = true; - break; default: break; } diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 4b8303ddd..a1b25cbd1 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -42,10 +42,8 @@ static void subghz_scene_read_raw_update_statusbar(void* context) { #ifdef SUBGHZ_EXT_PRESET_NAME subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, true); - //TODO if need subghz_txrx_get_preset - //furi_string_printf(modulation_str, "%s", furi_string_get_cstr(subghz->txrx->preset->name)); #else - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); + subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str, false); #endif subghz_read_raw_add_data_statusbar( subghz->subghz_read_raw, diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index c04f39cb8..370638931 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -27,7 +27,7 @@ static bool subghz_scene_receiver_info_update_parser(void* context) { if(subghz_txrx_load_decoder_by_name_protocol( subghz->txrx, subghz_history_get_protocol_name(subghz->history, subghz->idx_menu_chosen))) { - //todo we are trying to deserialize without checking for errors, since it is assumed that we just received this chignal + //todo we are trying to deserialize without checking for errors, since it is assumed that we just received this signal subghz_protocol_decoder_base_deserialize( subghz_txrx_get_decoder(subghz->txrx), subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen)); @@ -140,7 +140,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) widget_reset(subghz->widget); subghz_scene_receiver_info_draw_widget(subghz); - subghz_txrx_stop(subghz->txrx); //TODO this is probably a redundant call + subghz_txrx_stop(subghz->txrx); if(!subghz->in_decoder_scene) { subghz_txrx_rx_start(subghz->txrx); diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index 23ecbb539..ef53006da 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -562,11 +562,6 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { case SubmenuIndexSomfyTelis: generated_protocol = subghz_txrx_gen_somfy_telis_protocol( subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003); - if(!generated_protocol) { //TODO does not use databases - furi_string_set( - subghz->error_str, "Function requires\nan SD card with\nfresh databases."); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); - } break; case SubmenuIndexDoorHan_433_92: generated_protocol = subghz_txrx_gen_keeloq_protocol( diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index c3ae04a8f..dc8c51b7a 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -81,8 +81,6 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); furi_hal_subghz_set_rolling_counter_mult(0); // Calling restore! - subghz_txrx_stop(subghz->txrx); //TODO this is probably a redundant call - if(!subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { scene_manager_next_scene( subghz->scene_manager, SubGhzSceneShowOnlyRx); //TODO Is this necessary? From b38a593c4fcc2dd4bc4234111c404eb1c4a5bcfe Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 10 May 2023 23:36:52 +0300 Subject: [PATCH 34/36] Remove this --- applications/main/subghz/scenes/subghz_scene_decode_raw.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 4412676f3..54c729cc3 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -147,8 +147,6 @@ void subghz_scene_decode_raw_on_enter(void* context) { FuriString* item_name = furi_string_alloc(); FuriString* item_time = furi_string_alloc(); - subghz_view_receiver_set_lock( - subghz->subghz_receiver, false); //TODO Doesn't matter in DecodeRAW subghz_view_receiver_set_mode(subghz->subghz_receiver, SubGhzViewReceiverModeFile); subghz_view_receiver_set_callback( subghz->subghz_receiver, subghz_scene_decode_raw_callback, subghz); From 3531caaa0b80844cbb541afce821af62d783b3d2 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 10 May 2023 23:48:47 +0300 Subject: [PATCH 35/36] Clean up some comments, rename is done --- .../subghz/helpers/subghz_txrx_create_protocol_key.c | 10 +++++----- .../subghz/helpers/subghz_txrx_create_protocol_key.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c index 053f472aa..0631c7c15 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c @@ -116,7 +116,7 @@ bool subghz_txrx_gen_keeloq_protocol( //TODO lead to a general appearance return res; } -bool subghz_txrx_gen_keeloq_bft_protocol( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_keeloq_bft_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -161,7 +161,7 @@ bool subghz_txrx_gen_keeloq_bft_protocol( //TODO rename & lead to a general appe return res; } -bool subghz_txrx_gen_nice_flor_s_protocol( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_nice_flor_s_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -193,7 +193,7 @@ bool subghz_txrx_gen_nice_flor_s_protocol( //TODO rename & lead to a general app return res; } -bool subghz_txrx_gen_faac_slh_protocol( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_faac_slh_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -236,7 +236,7 @@ bool subghz_txrx_gen_faac_slh_protocol( //TODO rename & lead to a general appear return res; } -bool subghz_txrx_gen_alutech_at_4n_protocol( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_alutech_at_4n_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -266,7 +266,7 @@ bool subghz_txrx_gen_alutech_at_4n_protocol( //TODO rename & lead to a general a return res; } -bool subghz_txrx_gen_somfy_telis_protocol( //TODO rename & lead to a general appearance +bool subghz_txrx_gen_somfy_telis_protocol( void* context, const char* preset_name, uint32_t frequency, diff --git a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h index 61dbf9e56..a5fa2a802 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h @@ -63,7 +63,7 @@ bool subghz_txrx_gen_keeloq_protocol( uint16_t cnt, const char* manufacture_name); -bool subghz_txrx_gen_keeloq_bft_protocol( //TODO rename +bool subghz_txrx_gen_keeloq_bft_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -73,7 +73,7 @@ bool subghz_txrx_gen_keeloq_bft_protocol( //TODO rename uint32_t seed, const char* manufacture_name); -bool subghz_txrx_gen_nice_flor_s_protocol( //TODO rename +bool subghz_txrx_gen_nice_flor_s_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -82,7 +82,7 @@ bool subghz_txrx_gen_nice_flor_s_protocol( //TODO rename uint16_t cnt, bool nice_one); -bool subghz_txrx_gen_faac_slh_protocol( //TODO rename +bool subghz_txrx_gen_faac_slh_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -92,7 +92,7 @@ bool subghz_txrx_gen_faac_slh_protocol( //TODO rename uint32_t seed, const char* manufacture_name); -bool subghz_txrx_gen_alutech_at_4n_protocol( //TODO rename +bool subghz_txrx_gen_alutech_at_4n_protocol( void* context, const char* preset_name, uint32_t frequency, @@ -100,7 +100,7 @@ bool subghz_txrx_gen_alutech_at_4n_protocol( //TODO rename uint8_t btn, uint16_t cnt); -bool subghz_txrx_gen_somfy_telis_protocol( //TODO rename +bool subghz_txrx_gen_somfy_telis_protocol( void* context, const char* preset_name, uint32_t frequency, From bc93de0f03856e6950834ba47157bba9e161cc62 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 11 May 2023 00:01:28 +0300 Subject: [PATCH 36/36] remove unnecessary scene switch --- applications/main/subghz/scenes/subghz_scene_transmitter.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index dc8c51b7a..b07785c06 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -81,11 +81,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); furi_hal_subghz_set_rolling_counter_mult(0); // Calling restore! - if(!subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) { - scene_manager_next_scene( - subghz->scene_manager, SubGhzSceneShowOnlyRx); //TODO Is this necessary? - } - + subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx)); subghz_txrx_stop(subghz->txrx); furi_hal_subghz_set_rolling_counter_mult(tmp_counter); }