diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 581c6db5c..c9bebeacf 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -216,11 +216,8 @@ void subghz_txrx_sleep(SubGhzTxRx* instance) { static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) { furi_assert(instance); - // TODO - if(!furi_hal_subghz_is_frequency_valid(frequency)) { - furi_crash("SubGhz: Incorrect TX frequency."); - } furi_assert(instance->txrx_state != SubGhzTxRxStateSleep); + subghz_devices_idle(instance->radio_device); subghz_devices_set_frequency(instance->radio_device, frequency); @@ -637,6 +634,19 @@ bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t f return subghz_devices_is_frequency_valid(instance->radio_device, frequency); } +bool subghz_txrx_radio_device_is_tx_alowed(SubGhzTxRx* instance, uint32_t frequency) { + furi_assert(instance); + furi_assert(instance->txrx_state != SubGhzTxRxStateSleep); + + subghz_devices_idle(instance->radio_device); + subghz_devices_set_frequency(instance->radio_device, frequency); + + bool ret = subghz_devices_set_tx(instance->radio_device); + subghz_devices_idle(instance->radio_device); + + return ret; +} + void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state) { furi_assert(instance); instance->debug_pin_state = state; diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index d03c618c4..fc09ab8ea 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -336,6 +336,8 @@ const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance); */ bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency); +bool subghz_txrx_radio_device_is_tx_alowed(SubGhzTxRx* instance, uint32_t frequency); + void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state); bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance); diff --git a/applications/main/subghz/helpers/subghz_types.h b/applications/main/subghz/helpers/subghz_types.h index 5e5b4e5de..3c928c3b5 100644 --- a/applications/main/subghz/helpers/subghz_types.h +++ b/applications/main/subghz/helpers/subghz_types.h @@ -61,6 +61,7 @@ typedef enum { SubGhzLoadKeyStateOK, SubGhzLoadKeyStateParseErr, SubGhzLoadKeyStateOnlyRx, + SubGhzLoadKeyStateUnsuportedFreq, SubGhzLoadKeyStateProtocolDescriptionErr, } SubGhzLoadKeyState; diff --git a/applications/main/subghz/subghz_cli.c b/applications/main/subghz/subghz_cli.c index fb7453f06..810729dab 100644 --- a/applications/main/subghz/subghz_cli.c +++ b/applications/main/subghz/subghz_cli.c @@ -227,8 +227,7 @@ void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) { subghz_devices_stop_async_tx(device); } else { - printf("Transmission on this frequency is restricted in your region\r\n"); - // TODO region? + printf("Frequency is outside of default range. Check docs.\r\n"); } subghz_devices_sleep(device); diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 4e44302f7..f91f128cf 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -46,7 +46,7 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) { subghz->dialogs, "Error in protocol\nparameters\ndescription"); break; case SubGhzTxRxStartTxStateErrorOnlyRx: - subghz_dialog_message_show_only_rx(subghz); + subghz_dialog_message_freq_error(subghz, true); break; default: @@ -56,12 +56,16 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) { return false; } -void subghz_dialog_message_show_only_rx(SubGhz* subghz) { +void subghz_dialog_message_freq_error(SubGhz* subghz, bool only_rx) { DialogsApp* dialogs = subghz->dialogs; DialogMessage* message = dialog_message_alloc(); + const char* header_text = "Frequency not supported"; + const char* message_text = "Frequency\nis outside of\nsuported range."; - const char* header_text = "Transmission is blocked"; - const char* message_text = "Frequency\nis outside of\ndefault range.\nCheck docs."; + if(only_rx) { + header_text = "Transmission is blocked"; + message_text = "Frequency\nis outside of\ndefault range.\nCheck docs."; + } dialog_message_set_header(message, header_text, 63, 3, AlignCenter, AlignTop); dialog_message_set_text(message, message_text, 0, 17, AlignLeft, AlignTop); @@ -112,12 +116,13 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } if(!subghz_txrx_radio_device_is_frequecy_valid(subghz->txrx, temp_data32)) { - FURI_LOG_E(TAG, "Frequency not supported"); + FURI_LOG_E(TAG, "Frequency not supported on chosen radio module"); + load_key_state = SubGhzLoadKeyStateUnsuportedFreq; break; } - if(!furi_hal_subghz_is_tx_allowed(temp_data32)) { - FURI_LOG_E(TAG, "This frequency can only be used for RX"); + if(!subghz_txrx_radio_device_is_tx_alowed(subghz->txrx, temp_data32)) { + FURI_LOG_E(TAG, "This frequency can only be used for RX on chosen radio module"); load_key_state = SubGhzLoadKeyStateOnlyRx; break; } @@ -207,9 +212,15 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } return false; + case SubGhzLoadKeyStateUnsuportedFreq: + if(show_dialog) { + subghz_dialog_message_freq_error(subghz, false); + } + return false; + case SubGhzLoadKeyStateOnlyRx: if(show_dialog) { - subghz_dialog_message_show_only_rx(subghz); + subghz_dialog_message_freq_error(subghz, true); } return false; diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 3d1c2db9c..329c6e35f 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -115,7 +115,7 @@ 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); +void subghz_dialog_message_freq_error(SubGhz* subghz, bool only_rx); 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);