From 409a79ddee69acdc4dca47f75df575a3f69a4133 Mon Sep 17 00:00:00 2001 From: VerstreuteSeele Date: Sat, 11 Feb 2023 23:27:21 +0100 Subject: [PATCH] Fix chat & subghz settings --- applications/main/subghz/subghz_cli.c | 8 ++- .../targets/f7/furi_hal/furi_hal_subghz.c | 64 ++++++++++++++++--- .../f7/furi_hal/furi_hal_subghz_configs.h | 10 +++ 3 files changed, 70 insertions(+), 12 deletions(-) diff --git a/applications/main/subghz/subghz_cli.c b/applications/main/subghz/subghz_cli.c index c047a32b3..be7143643 100644 --- a/applications/main/subghz/subghz_cli.c +++ b/applications/main/subghz/subghz_cli.c @@ -602,7 +602,8 @@ static void subghz_cli_command_encrypt_raw(Cli* cli, FuriString* args) { furi_string_free(source); } -static void subghz_cli_command_chat(Cli* cli, FuriString* args) { +static void subghz_cli_command_chat(Cli* cli, FuriString* args, void* context) { + UNUSED(context); uint32_t frequency = 433920000; if(furi_string_size(args)) { @@ -795,7 +796,7 @@ static void subghz_cli_command(Cli* cli, FuriString* args, void* context) { } if(furi_string_cmp_str(cmd, "chat") == 0) { - subghz_cli_command_chat(cli, args); + subghz_cli_command_chat(cli, args, NULL); break; } @@ -853,6 +854,9 @@ void subghz_on_system_start() { cli_add_command(cli, "subghz", CliCommandFlagDefault, subghz_cli_command, NULL); + // psst RM... i know you dont care much about errors, but if you ever see this... incompatible pointer type :3 + cli_add_command(cli, "chat", CliCommandFlagDefault, subghz_cli_command_chat, NULL); + furi_record_close(RECORD_CLI); #else UNUSED(subghz_cli_command); diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index c2c238a13..0fe5d1878 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -1,6 +1,6 @@ #include #include - +#include #include #include #include @@ -390,7 +390,8 @@ uint8_t furi_hal_subghz_get_lqi() { /* Modified by @tkerby & MX to the full YARD Stick One extended range of 281-361 MHz, 378-481 MHz, and 749-962 MHz. - These changes are at your own risk. The PLL may not lock and FZ devs have warned of possible damage! + These changes are at your own risk. The PLL may not lock and FZ devs have warned of possible damage + Set flag use_ext_range_at_own_risk in extend_range.txt to use */ bool furi_hal_subghz_is_frequency_valid(uint32_t value) { @@ -420,29 +421,69 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) { bool furi_hal_subghz_is_tx_allowed(uint32_t value) { bool is_extended = false; + bool is_allowed = false; // TODO: !!! Move file check to another place Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - if(flipper_format_file_open_existing(fff_data_file, "/ext/subghz/assets/dangerous_settings")) { - flipper_format_read_bool( - fff_data_file, "yes_i_want_to_destroy_my_flipper", &is_extended, 1); + if(flipper_format_file_open_existing(fff_data_file, "/ext/subghz/assets/extend_range.txt")) { + flipper_format_read_bool(fff_data_file, "use_ext_range_at_own_risk", &is_extended, 1); + flipper_format_read_bool(fff_data_file, "ignore_default_tx_region", &is_allowed, 1); } flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); - if(!(value >= 299999755 && value <= 350000335) && + switch(furi_hal_version_get_hw_region()) { + case FuriHalVersionRegionEuRu: + //433,05..434,79; 868,15..868,55 + if(!(value >= 433050000 && value <= 434790000) && + !(value >= 868150000 && value <= 868550000)) { + } else { + is_allowed = true; + } + break; + case FuriHalVersionRegionUsCaAu: + //304,10..321,95; 433,05..434,79; 915,00..928,00 + if(!(value >= 304100000 && value <= 321950000) && + !(value >= 433050000 && value <= 434790000) && + !(value >= 915000000 && value <= 928000000)) { + } else { + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { + if(value <= 321950000 && + ((furi_hal_subghz.preset == FuriHalSubGhzPresetOok270Async) || + (furi_hal_subghz.preset == FuriHalSubGhzPresetOok650Async))) { + furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable_au); + } + } + is_allowed = true; + } + break; + case FuriHalVersionRegionJp: + //312,00..315,25; 920,50..923,50 + if(!(value >= 312000000 && value <= 315250000) && + !(value >= 920500000 && value <= 923500000)) { + } else { + is_allowed = true; + } + break; + + default: + is_allowed = true; + break; + } + // No flag - test original range, flag set, test extended range + if(!(value >= 299999755 && value <= 348000335) && !(value >= 386999938 && value <= 464000000) && !(value >= 778999847 && value <= 928000000) && !(is_extended)) { - FURI_LOG_I(TAG, "Frequency blocked - outside default range"); + FURI_LOG_I(TAG, "Frequency blocked - outside regional range"); return false; } else if( !(value >= 281000000 && value <= 361000000) && !(value >= 378000000 && value <= 481000000) && !(value >= 749000000 && value <= 962000000) && is_extended) { - FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range"); + FURI_LOG_I(TAG, "Frequency blocked - outside extended range"); return false; } @@ -450,8 +491,11 @@ bool furi_hal_subghz_is_tx_allowed(uint32_t value) { } uint32_t furi_hal_subghz_set_frequency(uint32_t value) { - furi_hal_subghz.regulation = SubGhzRegulationTxRx; - + if(furi_hal_region_is_frequency_allowed(value)) { + furi_hal_subghz.regulation = SubGhzRegulationTxRx; + } else { + furi_hal_subghz.regulation = SubGhzRegulationTxRx; + } furi_hal_spi_acquire(furi_hal_subghz.spi_bus_handle); uint32_t real_frequency = cc1101_set_frequency(furi_hal_subghz.spi_bus_handle, value); cc1101_calibrate(furi_hal_subghz.spi_bus_handle); diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz_configs.h b/firmware/targets/f7/furi_hal/furi_hal_subghz_configs.h index b2b5760fd..5ea17b6dd 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz_configs.h +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz_configs.h @@ -273,6 +273,16 @@ static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = { 0x00, 0x00}; +static const uint8_t furi_hal_subghz_preset_ook_async_patable_au[8] = { + 0x00, + 0x37, // 12dBm 0xC0, 10dBm 0xC5, 7dBm 0xCD, 5dBm 0x86, 0dBm 0x50, -6dBm 0x37, -10dBm 0x26, -15dBm 0x1D, -20dBm 0x17, -30dBm 0x03 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}; + static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = { 0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12 0x00,