mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 13:03:13 +00:00
[FL-1590] SubGhz: fix incorrect limits on frequency that were causing crashes #607
This commit is contained in:
parent
2313b948c6
commit
4c1ac2a13d
3 changed files with 27 additions and 22 deletions
|
@ -5,17 +5,8 @@
|
|||
#include <stream_buffer.h>
|
||||
#include <lib/subghz/protocols/subghz_protocol.h>
|
||||
|
||||
#define CC1101_FREQUENCY_RANGE_STR \
|
||||
"300000000...348000000 or 387000000...464000000 or 779000000...928000000"
|
||||
|
||||
bool subghz_check_frequency_range(uint32_t frequency) {
|
||||
if(!(frequency >= 300000000 && frequency <= 348000000) &&
|
||||
!(frequency >= 387000000 && frequency <= 464000000) &&
|
||||
!(frequency >= 779000000 && frequency <= 928000000)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
||||
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
||||
|
||||
void subghz_cli_init() {
|
||||
Cli* cli = furi_record_open("cli");
|
||||
|
@ -40,9 +31,9 @@ void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
|||
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!subghz_check_frequency_range(frequency)) {
|
||||
if(!api_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
|
@ -77,9 +68,9 @@ void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
|
|||
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!subghz_check_frequency_range(frequency)) {
|
||||
if(!api_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
|
@ -127,9 +118,9 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
|
|||
string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!subghz_check_frequency_range(frequency)) {
|
||||
if(!api_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
|
@ -209,9 +200,9 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
|||
cli_print_usage("subghz_rx", "<Frequency in HZ>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!subghz_check_frequency_range(frequency)) {
|
||||
if(!api_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " CC1101_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -104,6 +104,11 @@ void api_hal_subghz_tx();
|
|||
/** Get RSSI value in dBm */
|
||||
float api_hal_subghz_get_rssi();
|
||||
|
||||
/** Check if frequency is in valid range
|
||||
* @return true if frequncy is valid, otherwise false
|
||||
*/
|
||||
bool api_hal_subghz_is_frequency_valid(uint32_t value);
|
||||
|
||||
/** Set frequency and path
|
||||
* This function automatically selects antenna matching network
|
||||
* @param frequency in herz
|
||||
|
|
|
@ -242,13 +242,22 @@ float api_hal_subghz_get_rssi() {
|
|||
return rssi;
|
||||
}
|
||||
|
||||
bool api_hal_subghz_is_frequency_valid(uint32_t value) {
|
||||
if(!(value >= 299999755 && value <= 348000335) &&
|
||||
!(value >= 386999938 && value <= 464000000) &&
|
||||
!(value >= 778999847 && value <= 928000000)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t api_hal_subghz_set_frequency_and_path(uint32_t value) {
|
||||
value = api_hal_subghz_set_frequency(value);
|
||||
if(value >= 300000000 && value <= 348000335) {
|
||||
if(value >= 299999755 && value <= 348000335) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath315);
|
||||
} else if(value >= 387000000 && value <= 464000000) {
|
||||
} else if(value >= 386999938 && value <= 464000000) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath433);
|
||||
} else if(value >= 779000000 && value <= 928000000) {
|
||||
} else if(value >= 778999847 && value <= 928000000) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath868);
|
||||
} else {
|
||||
furi_check(0);
|
||||
|
|
Loading…
Reference in a new issue