SubGhz app: fix is_tx_allowed and freq check

This commit is contained in:
gid9798 2023-06-20 14:28:03 +03:00
parent e2e9e53b6a
commit 6e26de3763
6 changed files with 38 additions and 15 deletions

View File

@ -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;

View File

@ -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);

View File

@ -61,6 +61,7 @@ typedef enum {
SubGhzLoadKeyStateOK,
SubGhzLoadKeyStateParseErr,
SubGhzLoadKeyStateOnlyRx,
SubGhzLoadKeyStateUnsuportedFreq,
SubGhzLoadKeyStateProtocolDescriptionErr,
} SubGhzLoadKeyState;

View File

@ -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);

View File

@ -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;

View File

@ -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);