From 69d90d5b005b02b21c751dce7f3bf93760552cf7 Mon Sep 17 00:00:00 2001 From: gornekich Date: Mon, 30 May 2022 18:39:43 +0300 Subject: [PATCH 1/4] nfc device: fix nfc cards save (#1277) --- applications/nfc/nfc_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/applications/nfc/nfc_device.c b/applications/nfc/nfc_device.c index ca3fc45aa..51e14a6c1 100644 --- a/applications/nfc/nfc_device.c +++ b/applications/nfc/nfc_device.c @@ -906,8 +906,11 @@ bool nfc_file_select(NfcDevice* dev) { furi_assert(dev); // Input events and views are managed by file_browser + string_t nfc_app_folder; + string_init_set_str(nfc_app_folder, NFC_APP_FOLDER); bool res = dialog_file_browser_show( - dev->dialogs, dev->load_path, dev->load_path, NFC_APP_EXTENSION, true, &I_Nfc_10px, true); + dev->dialogs, dev->load_path, nfc_app_folder, NFC_APP_EXTENSION, true, &I_Nfc_10px, true); + string_clear(nfc_app_folder); if(res) { string_t filename; string_init(filename); @@ -935,7 +938,7 @@ void nfc_device_clear(NfcDevice* dev) { nfc_device_data_clear(&dev->dev_data); memset(&dev->dev_data, 0, sizeof(dev->dev_data)); dev->format = NfcDeviceSaveFormatUid; - string_set_str(dev->load_path, NFC_APP_FOLDER); + string_reset(dev->load_path); } bool nfc_device_delete(NfcDevice* dev, bool use_load_path) { From 66dbb689477516ee7067e46941225d09e3635bcf Mon Sep 17 00:00:00 2001 From: Skorpionm <85568270+Skorpionm@users.noreply.github.com> Date: Tue, 31 May 2022 19:50:50 +0400 Subject: [PATCH 2/4] SubGhz: support 310 MHz and fix (#1262) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SubGhz: add frequency support 310 MHz * SubGhz: deleting a TMP file using the "Erase" button in Read RAW * SubGhz: fix frequency analyzer scan speed * SubGhz: fix start duration came_atomo protocol * SubGhz: refactoring subghz_setting * SubGhz: refactoring load setting frequency analyzer * SubGhz: fix load setting, default frequency * SubGhz: patch raw temp file remove code to work with string_t * Storage: parallel safe cli * SubGhz: new frequency settings loading system * Assets: recompile to include latest subghz custom frequency control changes Co-authored-by: あく --- applications/storage/storage_cli.c | 2 +- .../subghz_frequency_analyzer_worker.c | 19 +- .../subghz_frequency_analyzer_worker.h | 4 +- applications/subghz/helpers/subghz_testing.c | 3 +- .../subghz/scenes/subghz_scene_read_raw.c | 4 + applications/subghz/subghz_setting.c | 254 +++++++++--------- .../subghz/views/subghz_frequency_analyzer.c | 2 +- assets/resources/Manifest | 5 +- .../assets/setting_frequency_analyzer_user | 19 -- assets/resources/subghz/assets/setting_user | 38 ++- lib/subghz/protocols/came_atomo.c | 4 +- 11 files changed, 172 insertions(+), 182 deletions(-) delete mode 100644 assets/resources/subghz/assets/setting_frequency_analyzer_user diff --git a/applications/storage/storage_cli.c b/applications/storage/storage_cli.c index b35e37a89..4ce91770a 100644 --- a/applications/storage/storage_cli.c +++ b/applications/storage/storage_cli.c @@ -593,7 +593,7 @@ static void storage_cli_factory_reset(Cli* cli, string_t args, void* context) { void storage_on_system_start() { #ifdef SRV_CLI Cli* cli = furi_record_open("cli"); - cli_add_command(cli, "storage", CliCommandFlagDefault, storage_cli, NULL); + cli_add_command(cli, "storage", CliCommandFlagParallelSafe, storage_cli, NULL); cli_add_command( cli, "factory_reset", CliCommandFlagParallelSafe, storage_cli_factory_reset, NULL); furi_record_close("cli"); diff --git a/applications/subghz/helpers/subghz_frequency_analyzer_worker.c b/applications/subghz/helpers/subghz_frequency_analyzer_worker.c index 88e2a621c..69e597595 100644 --- a/applications/subghz/helpers/subghz_frequency_analyzer_worker.c +++ b/applications/subghz/helpers/subghz_frequency_analyzer_worker.c @@ -3,8 +3,6 @@ #include -#include "../subghz_i.h" - #define TAG "SubghzFrequencyAnalyzerWorker" #define SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD -95.0f @@ -82,7 +80,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { cc1101_flush_tx(&furi_hal_spi_bus_handle_subghz); cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW); cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_MDMCFG3, - 0b11111111); // symbol rate + 0b01111111); // symbol rate cc1101_write_reg( &furi_hal_spi_bus_handle_subghz, CC1101_AGCCTRL2, @@ -130,7 +128,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz); // delay will be in range between 1 and 2ms - osDelay(2); + osDelay(3); rssi = furi_hal_subghz_get_rssi(); @@ -179,9 +177,12 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz); // delay will be in range between 1 and 2ms - osDelay(2); + osDelay(3); rssi = furi_hal_subghz_get_rssi(); + + FURI_LOG_T(TAG, "#:%u:%f", frequency, (double)rssi); + if(frequency_rssi.rssi < rssi) { frequency_rssi.rssi = rssi; frequency_rssi.frequency = frequency; @@ -222,7 +223,8 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { return 0; } -SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc() { +SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* context) { + furi_assert(context); SubGhzFrequencyAnalyzerWorker* instance = malloc(sizeof(SubGhzFrequencyAnalyzerWorker)); instance->thread = furi_thread_alloc(); @@ -231,8 +233,8 @@ SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc() { furi_thread_set_context(instance->thread, instance); furi_thread_set_callback(instance->thread, subghz_frequency_analyzer_worker_thread); - instance->setting = subghz_setting_alloc(); - subghz_setting_load(instance->setting, "/ext/subghz/assets/setting_frequency_analyzer_user"); + SubGhz* subghz = context; + instance->setting = subghz->setting; return instance; } @@ -240,7 +242,6 @@ void subghz_frequency_analyzer_worker_free(SubGhzFrequencyAnalyzerWorker* instan furi_assert(instance); furi_thread_free(instance->thread); - subghz_setting_free(instance->setting); free(instance); } diff --git a/applications/subghz/helpers/subghz_frequency_analyzer_worker.h b/applications/subghz/helpers/subghz_frequency_analyzer_worker.h index 93f7caf01..424270a03 100644 --- a/applications/subghz/helpers/subghz_frequency_analyzer_worker.h +++ b/applications/subghz/helpers/subghz_frequency_analyzer_worker.h @@ -1,6 +1,7 @@ #pragma once #include +#include "../subghz_i.h" typedef struct SubGhzFrequencyAnalyzerWorker SubGhzFrequencyAnalyzerWorker; @@ -14,9 +15,10 @@ typedef struct { /** Allocate SubGhzFrequencyAnalyzerWorker * + * @param context SubGhz* context * @return SubGhzFrequencyAnalyzerWorker* */ -SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(); +SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* context); /** Free SubGhzFrequencyAnalyzerWorker * diff --git a/applications/subghz/helpers/subghz_testing.c b/applications/subghz/helpers/subghz_testing.c index f4cbe4a47..8afa868e0 100644 --- a/applications/subghz/helpers/subghz_testing.c +++ b/applications/subghz/helpers/subghz_testing.c @@ -4,6 +4,7 @@ const uint32_t subghz_frequencies_testing[] = { /* 300 - 348 */ 300000000, 304500000, + 310000000, 312025000, 313250000, 313625000, @@ -34,4 +35,4 @@ const uint32_t subghz_frequencies_testing[] = { const uint32_t subghz_frequencies_count_testing = sizeof(subghz_frequencies_testing) / sizeof(uint32_t); -const uint32_t subghz_frequencies_433_92_testing = 12; +const uint32_t subghz_frequencies_433_92_testing = 13; diff --git a/applications/subghz/scenes/subghz_scene_read_raw.c b/applications/subghz/scenes/subghz_scene_read_raw.c index 191a7285c..38a9067c6 100644 --- a/applications/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/subghz/scenes/subghz_scene_read_raw.c @@ -168,6 +168,10 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWErase: subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + if(subghz_scene_read_raw_update_filename(subghz)) { + string_set(subghz->file_path_tmp, subghz->file_path); + subghz_delete_file(subghz); + } notification_message(subghz->notifications, &sequence_reset_rgb); return true; break; diff --git a/applications/subghz/subghz_setting.c b/applications/subghz/subghz_setting.c index 4d40d49ee..9dcfb291c 100644 --- a/applications/subghz/subghz_setting.c +++ b/applications/subghz/subghz_setting.c @@ -7,20 +7,19 @@ #define TAG "SubGhzSetting" -#define SUBGHZ_SETTING_FILE_VERSION 1 #define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File" +#define SUBGHZ_SETTING_FILE_VERSION 1 -typedef enum { - SubGhzSettingStateNoLoad = 0, - SubGhzSettingStateLoadFrequencyDefault, - SubGhzSettingStateOkLoad, -} SubGhzSettingState; +#define FREQUENCY_FLAG_DEFAULT (1 << 31) +#define FREQUENCY_MASK (0xFFFFFFFF ^ FREQUENCY_FLAG_DEFAULT) -static const uint32_t subghz_frequencies[] = { +/* Default */ +static const uint32_t subghz_frequency_list[] = { /* 300 - 348 */ 300000000, 303875000, 304250000, + 310000000, 315000000, 318000000, @@ -29,7 +28,7 @@ static const uint32_t subghz_frequencies[] = { 418000000, 433075000, /* LPD433 first */ 433420000, - 433920000, /* LPD433 mid */ + 433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */ 434420000, 434775000, /* LPD433 last channels */ 438900000, @@ -40,7 +39,9 @@ static const uint32_t subghz_frequencies[] = { 925000000, 0, }; -static const uint32_t subghz_hopper_frequencies[] = { + +static const uint32_t subghz_hopper_frequency_list[] = { + 310000000, 315000000, 318000000, 390000000, @@ -48,13 +49,14 @@ static const uint32_t subghz_hopper_frequencies[] = { 868350000, 0, }; -static const uint32_t subghz_frequency_default_index = 9; -static const uint32_t subghz_frequencies_region_eu_ru[] = { +/* Europe and Russia */ +static const uint32_t subghz_frequency_list_region_eu_ru[] = { /* 300 - 348 */ 300000000, 303875000, 304250000, + 310000000, 315000000, 318000000, @@ -63,7 +65,7 @@ static const uint32_t subghz_frequencies_region_eu_ru[] = { 418000000, 433075000, /* LPD433 first */ 433420000, - 433920000, /* LPD433 mid */ + 433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */ 434420000, 434775000, /* LPD433 last channels */ 438900000, @@ -74,7 +76,8 @@ static const uint32_t subghz_frequencies_region_eu_ru[] = { 925000000, 0, }; -static const uint32_t subghz_hopper_frequencies_region_eu_ru[] = { +static const uint32_t subghz_hopper_frequency_list_region_eu_ru[] = { + 310000000, 315000000, 318000000, 390000000, @@ -82,13 +85,14 @@ static const uint32_t subghz_hopper_frequencies_region_eu_ru[] = { 868350000, 0, }; -static const uint32_t subghz_frequency_default_index_region_eu_ru = 9; -static const uint32_t subghz_frequencies_region_us_ca_au[] = { +/* Region 0 */ +static const uint32_t subghz_frequency_list_region_us_ca_au[] = { /* 300 - 348 */ 300000000, 303875000, 304250000, + 310000000, 315000000, 318000000, @@ -97,7 +101,7 @@ static const uint32_t subghz_frequencies_region_us_ca_au[] = { 418000000, 433075000, /* LPD433 first */ 433420000, - 433920000, /* LPD433 mid */ + 433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */ 434420000, 434775000, /* LPD433 last channels */ 438900000, @@ -108,7 +112,8 @@ static const uint32_t subghz_frequencies_region_us_ca_au[] = { 925000000, 0, }; -static const uint32_t subghz_hopper_frequencies_region_us_ca_au[] = { +static const uint32_t subghz_hopper_frequency_list_region_us_ca_au[] = { + 310000000, 315000000, 318000000, 390000000, @@ -116,13 +121,13 @@ static const uint32_t subghz_hopper_frequencies_region_us_ca_au[] = { 868350000, 0, }; -static const uint32_t subghz_frequency_default_index_region_us_ca_au = 9; -static const uint32_t subghz_frequencies_region_jp[] = { +static const uint32_t subghz_frequency_list_region_jp[] = { /* 300 - 348 */ 300000000, 303875000, 304250000, + 310000000, 315000000, 318000000, @@ -131,7 +136,7 @@ static const uint32_t subghz_frequencies_region_jp[] = { 418000000, 433075000, /* LPD433 first */ 433420000, - 433920000, /* LPD433 mid */ + 433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */ 434420000, 434775000, /* LPD433 last channels */ 438900000, @@ -142,7 +147,8 @@ static const uint32_t subghz_frequencies_region_jp[] = { 925000000, 0, }; -static const uint32_t subghz_hopper_frequencies_region_jp[] = { +static const uint32_t subghz_hopper_frequency_list_region_jp[] = { + 310000000, 315000000, 318000000, 390000000, @@ -150,72 +156,88 @@ static const uint32_t subghz_hopper_frequencies_region_jp[] = { 868350000, 0, }; -static const uint32_t subghz_frequency_default_index_region_jp = 9; -LIST_DEF(FrequenciesList, uint32_t) +LIST_DEF(FrequencyList, uint32_t) + +#define M_OPL_FrequencyList_t() LIST_OPLIST(FrequencyList) struct SubGhzSetting { - FrequenciesList_t frequencies; - FrequenciesList_t hopper_frequencies; - size_t frequencies_count; - size_t hopper_frequencies_count; - uint32_t frequency_default_index; + FrequencyList_t frequencies; + FrequencyList_t hopper_frequencies; }; SubGhzSetting* subghz_setting_alloc(void) { SubGhzSetting* instance = malloc(sizeof(SubGhzSetting)); - FrequenciesList_init(instance->frequencies); - FrequenciesList_init(instance->hopper_frequencies); + FrequencyList_init(instance->frequencies); + FrequencyList_init(instance->hopper_frequencies); return instance; } void subghz_setting_free(SubGhzSetting* instance) { furi_assert(instance); - FrequenciesList_clear(instance->frequencies); - FrequenciesList_clear(instance->hopper_frequencies); + FrequencyList_clear(instance->frequencies); + FrequencyList_clear(instance->hopper_frequencies); free(instance); } -void subghz_setting_load_default( +static void subghz_setting_load_default_region( SubGhzSetting* instance, const uint32_t frequencies[], - const uint32_t hopper_frequencies[], - const uint32_t frequency_default_index) { + const uint32_t hopper_frequencies[]) { furi_assert(instance); - size_t i = 0; - FrequenciesList_clear(instance->frequencies); - FrequenciesList_clear(instance->hopper_frequencies); - i = 0; - while(frequencies[i]) { - FrequenciesList_push_back(instance->frequencies, frequencies[i]); - i++; - } - instance->frequencies_count = i; - i = 0; - while(hopper_frequencies[i]) { - FrequenciesList_push_back(instance->hopper_frequencies, hopper_frequencies[i]); - i++; - } - instance->hopper_frequencies_count = i; + FrequencyList_reset(instance->frequencies); + FrequencyList_reset(instance->hopper_frequencies); - instance->frequency_default_index = frequency_default_index; + while(*frequencies) { + FrequencyList_push_back(instance->frequencies, *frequencies); + frequencies++; + } + + while(*hopper_frequencies) { + FrequencyList_push_back(instance->hopper_frequencies, *hopper_frequencies); + hopper_frequencies++; + } +} + +void subghz_setting_load_default(SubGhzSetting* instance) { + switch(furi_hal_version_get_hw_region()) { + case FuriHalVersionRegionEuRu: + subghz_setting_load_default_region( + instance, + subghz_frequency_list_region_eu_ru, + subghz_hopper_frequency_list_region_eu_ru); + break; + case FuriHalVersionRegionUsCaAu: + subghz_setting_load_default_region( + instance, + subghz_frequency_list_region_us_ca_au, + subghz_hopper_frequency_list_region_us_ca_au); + break; + case FuriHalVersionRegionJp: + subghz_setting_load_default_region( + instance, subghz_frequency_list_region_jp, subghz_hopper_frequency_list_region_jp); + break; + + default: + subghz_setting_load_default_region( + instance, subghz_frequency_list, subghz_hopper_frequency_list); + break; + } } void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { furi_assert(instance); - FrequenciesList_clear(instance->frequencies); - FrequenciesList_clear(instance->hopper_frequencies); - Storage* storage = furi_record_open("storage"); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); string_t temp_str; string_init(temp_str); uint32_t temp_data32; - SubGhzSettingState loading = SubGhzSettingStateNoLoad; - uint16_t i = 0; + bool temp_bool; + + subghz_setting_load_default(instance); if(file_path) { do { @@ -236,63 +258,60 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { break; } + // Standard frequencies (optional) + temp_bool = true; + flipper_format_read_bool(fff_data_file, "add_standard_frequencies", &temp_bool, 1); + if(!temp_bool) { + FURI_LOG_I(TAG, "Removing standard frequencies"); + FrequencyList_reset(instance->frequencies); + FrequencyList_reset(instance->hopper_frequencies); + } else { + FURI_LOG_I(TAG, "Keeping standard frequencies"); + } + + // Load frequencies if(!flipper_format_rewind(fff_data_file)) { FURI_LOG_E(TAG, "Rewind error"); break; } - i = 0; while(flipper_format_read_uint32( - fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) { + fff_data_file, "frequency", (uint32_t*)&temp_data32, 1)) { if(furi_hal_subghz_is_frequency_valid(temp_data32)) { FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32); - FrequenciesList_push_back(instance->frequencies, temp_data32); - i++; + FrequencyList_push_back(instance->frequencies, temp_data32); } else { FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32); } } - instance->frequencies_count = i; + // Load hopper frequencies if(!flipper_format_rewind(fff_data_file)) { FURI_LOG_E(TAG, "Rewind error"); break; } - i = 0; while(flipper_format_read_uint32( - fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) { + fff_data_file, "hopper_frequency", (uint32_t*)&temp_data32, 1)) { if(furi_hal_subghz_is_frequency_valid(temp_data32)) { FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32); - FrequenciesList_push_back(instance->hopper_frequencies, temp_data32); - i++; + FrequencyList_push_back(instance->hopper_frequencies, temp_data32); } else { FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32); } } - instance->hopper_frequencies_count = i; + // Default frequency (optional) if(!flipper_format_rewind(fff_data_file)) { FURI_LOG_E(TAG, "Rewind error"); break; } - if(!flipper_format_read_uint32( - fff_data_file, "Frequency_default", (uint32_t*)&temp_data32, 1)) { - FURI_LOG_E(TAG, "Frequency default missing"); - break; - } - - for(i = 0; i < instance->frequencies_count; i++) { - if(subghz_setting_get_frequency(instance, i) == temp_data32) { - instance->frequency_default_index = i; - FURI_LOG_I(TAG, "Frequency default index %lu", i); - loading = SubGhzSettingStateLoadFrequencyDefault; - break; - } - } - - if(loading == SubGhzSettingStateLoadFrequencyDefault) { - loading = SubGhzSettingStateOkLoad; - } else { - FURI_LOG_E(TAG, "Frequency default index missing"); + if(flipper_format_read_uint32(fff_data_file, "default_frequency", &temp_data32, 1)) { + for + M_EACH(frequency, instance->frequencies, FrequencyList_t) { + *frequency &= FREQUENCY_MASK; + if(*frequency == temp_data32) { + *frequency |= FREQUENCY_FLAG_DEFAULT; + } + } } } while(false); } @@ -301,67 +320,56 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { flipper_format_free(fff_data_file); furi_record_close("storage"); - if(loading != SubGhzSettingStateOkLoad) { - switch(furi_hal_version_get_hw_region()) { - case FuriHalVersionRegionEuRu: - subghz_setting_load_default( - instance, - subghz_frequencies_region_eu_ru, - subghz_hopper_frequencies_region_eu_ru, - subghz_frequency_default_index_region_eu_ru); - break; - case FuriHalVersionRegionUsCaAu: - subghz_setting_load_default( - instance, - subghz_frequencies_region_us_ca_au, - subghz_hopper_frequencies_region_us_ca_au, - subghz_frequency_default_index_region_us_ca_au); - break; - case FuriHalVersionRegionJp: - subghz_setting_load_default( - instance, - subghz_frequencies_region_jp, - subghz_hopper_frequencies_region_jp, - subghz_frequency_default_index_region_jp); - break; - - default: - subghz_setting_load_default( - instance, - subghz_frequencies, - subghz_hopper_frequencies, - subghz_frequency_default_index); - break; - } + if(!FrequencyList_size(instance->frequencies) || + !FrequencyList_size(instance->hopper_frequencies)) { + FURI_LOG_E(TAG, "Error loading user settings, loading default settings"); + subghz_setting_load_default(instance); } } size_t subghz_setting_get_frequency_count(SubGhzSetting* instance) { furi_assert(instance); - return instance->frequencies_count; + return FrequencyList_size(instance->frequencies); } size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance) { furi_assert(instance); - return instance->hopper_frequencies_count; + return FrequencyList_size(instance->hopper_frequencies); } uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) { furi_assert(instance); - return *FrequenciesList_get(instance->frequencies, idx); + uint32_t* ret = FrequencyList_get(instance->frequencies, idx); + if(ret) { + return (*ret) & FREQUENCY_MASK; + } else { + return 0; + } } uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx) { furi_assert(instance); - return *FrequenciesList_get(instance->hopper_frequencies, idx); + uint32_t* ret = FrequencyList_get(instance->hopper_frequencies, idx); + if(ret) { + return *ret; + } else { + return 0; + } } uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance) { furi_assert(instance); - return instance->frequency_default_index; + for(size_t i = 0; i < FrequencyList_size(instance->frequencies); i++) { + uint32_t frequency = *FrequencyList_get(instance->frequencies, i); + if(frequency & FREQUENCY_FLAG_DEFAULT) { + return i; + } + } + return 0; } uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance) { furi_assert(instance); - return *FrequenciesList_get(instance->frequencies, instance->frequency_default_index); + return subghz_setting_get_frequency( + instance, subghz_setting_get_frequency_default_index(instance)); } diff --git a/applications/subghz/views/subghz_frequency_analyzer.c b/applications/subghz/views/subghz_frequency_analyzer.c index ec3c5ee9a..d3f773159 100644 --- a/applications/subghz/views/subghz_frequency_analyzer.c +++ b/applications/subghz/views/subghz_frequency_analyzer.c @@ -111,7 +111,7 @@ void subghz_frequency_analyzer_enter(void* context) { SubGhzFrequencyAnalyzer* instance = context; //Start worker - instance->worker = subghz_frequency_analyzer_worker_alloc(); + instance->worker = subghz_frequency_analyzer_worker_alloc(instance->context); subghz_frequency_analyzer_worker_set_pair_callback( instance->worker, diff --git a/assets/resources/Manifest b/assets/resources/Manifest index 76b902329..9d854b13c 100644 --- a/assets/resources/Manifest +++ b/assets/resources/Manifest @@ -1,5 +1,5 @@ V:0 -T:1653334495 +T:1654009290 D:badusb D:dolphin D:infrared @@ -235,8 +235,7 @@ F:dda1ef895b8a25fde57c874feaaef997:650:subghz/assets/came_atomo F:610a0ffa2479a874f2060eb2348104c5:2712:subghz/assets/keeloq_mfcodes F:9214f9c10463b746a27e82ce0b96e040:465:subghz/assets/keeloq_mfcodes_user F:653bd8d349055a41e1152e557d4a52d3:202:subghz/assets/nice_flor_s -F:00e967e5c558e44a0651bb821d5cf1d0:414:subghz/assets/setting_frequency_analyzer_user -F:16e8c7cb4a13f26ea55b2b0a59f9cc7a:554:subghz/assets/setting_user +F:c6ec4374275cd20f482ecd46de9f53e3:528:subghz/assets/setting_user D:u2f/assets F:7e11e688e39034bbb9d88410044795e1:365:u2f/assets/cert.der F:f60b88c20ed479ed9684e249f7134618:264:u2f/assets/cert_key.u2f diff --git a/assets/resources/subghz/assets/setting_frequency_analyzer_user b/assets/resources/subghz/assets/setting_frequency_analyzer_user deleted file mode 100644 index 2c03a4022..000000000 --- a/assets/resources/subghz/assets/setting_frequency_analyzer_user +++ /dev/null @@ -1,19 +0,0 @@ -Filetype: Flipper SubGhz Setting File -Version: 1 -Frequency_default: 433920000 -Frequency: 300000000 -Frequency: 303875000 -Frequency: 304250000 -Frequency: 315000000 -Frequency: 318000000 -Frequency: 390000000 -Frequency: 418000000 -Frequency: 433075000 -Frequency: 433420000 -Frequency: 433920000 -Frequency: 434420000 -Frequency: 434775000 -Frequency: 438900000 -Frequency: 868350000 -Frequency: 915000000 -Frequency: 925000000 diff --git a/assets/resources/subghz/assets/setting_user b/assets/resources/subghz/assets/setting_user index 11bd984dc..413dbf31f 100644 --- a/assets/resources/subghz/assets/setting_user +++ b/assets/resources/subghz/assets/setting_user @@ -1,24 +1,18 @@ Filetype: Flipper SubGhz Setting File Version: 1 -Frequency_default: 433920000 -Frequency: 300000000 -Frequency: 303875000 -Frequency: 304250000 -Frequency: 315000000 -Frequency: 318000000 -Frequency: 390000000 -Frequency: 418000000 -Frequency: 433075000 -Frequency: 433420000 -Frequency: 433920000 -Frequency: 434420000 -Frequency: 434775000 -Frequency: 438900000 -Frequency: 868350000 -Frequency: 915000000 -Frequency: 925000000 -Hopper_frequency: 315000000 -Hopper_frequency: 318000000 -Hopper_frequency: 390000000 -Hopper_frequency: 433920000 -Hopper_frequency: 868350000 + +# Add Standard frequencies for your region +#add_standard_frequencies: true + +# Default Frequency: used as default for "Read" and "Read Raw" +#default_frequency: 433920000 + +# Frequencies used for "Read", "Read Raw" and "Frequency Analyzer" +#frequency: 300000000 +#frequency: 310000000 +#frequency: 320000000 + +# Frequencies used for hopping mode (keep this list small or flipper will miss signal) +#hopper_frequency: 300000000 +#hopper_frequency: 310000000 +#hopper_frequency: 310000000 diff --git a/lib/subghz/protocols/came_atomo.c b/lib/subghz/protocols/came_atomo.c index 51e7fe0b3..ad98f83f1 100644 --- a/lib/subghz/protocols/came_atomo.c +++ b/lib/subghz/protocols/came_atomo.c @@ -108,8 +108,8 @@ void subghz_protocol_decoder_came_atomo_feed(void* context, bool level, uint32_t ManchesterEvent event = ManchesterEventReset; switch(instance->decoder.parser_step) { case CameAtomoDecoderStepReset: - if((!level) && (DURATION_DIFF(duration, subghz_protocol_came_atomo_const.te_long * 65) < - subghz_protocol_came_atomo_const.te_delta * 20)) { + if((!level) && (DURATION_DIFF(duration, subghz_protocol_came_atomo_const.te_long * 60) < + subghz_protocol_came_atomo_const.te_delta * 40)) { //Found header CAME instance->decoder.parser_step = CameAtomoDecoderStepDecoderData; instance->decoder.decode_data = 0; From 2c4b2b87753899f988ab4cbca11480061c966956 Mon Sep 17 00:00:00 2001 From: UberGuidoZ <57457139+UberGuidoZ@users.noreply.github.com> Date: Tue, 31 May 2022 15:35:31 -0700 Subject: [PATCH 3/4] Fixing typo across many files (#1287) * Update furi_hal_subghz.c * Update subghz_scene_read_raw.c * Update subghz_i.c * Update came_twee.c * Update secplus_v2.c --- applications/subghz/scenes/subghz_scene_read_raw.c | 2 +- applications/subghz/subghz_i.c | 6 +++--- firmware/targets/f7/furi_hal/furi_hal_subghz.c | 4 ++-- lib/subghz/protocols/came_twee.c | 2 +- lib/subghz/protocols/secplus_v2.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/applications/subghz/scenes/subghz_scene_read_raw.c b/applications/subghz/scenes/subghz_scene_read_raw.c index 38a9067c6..ae3abd6ac 100644 --- a/applications/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/subghz/scenes/subghz_scene_read_raw.c @@ -184,7 +184,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW); return true; } else { - furi_crash("SugGhz: RAW file name update error."); + furi_crash("SubGhz: RAW file name update error."); } break; diff --git a/applications/subghz/subghz_i.c b/applications/subghz/subghz_i.c index 5439fd2a9..33ceb9bbb 100644 --- a/applications/subghz/subghz_i.c +++ b/applications/subghz/subghz_i.c @@ -54,7 +54,7 @@ void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_ subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) { string_set_str(modulation, "FM"); } else { - furi_crash("SugGhz: Modulation is incorrect."); + furi_crash("SubGhz: Modulation is incorrect."); } } } @@ -71,7 +71,7 @@ void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset) { uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) { furi_assert(subghz); if(!furi_hal_subghz_is_frequency_valid(frequency)) { - furi_crash("SugGhz: Incorrect RX frequency."); + furi_crash("SubGhz: Incorrect RX frequency."); } furi_assert( subghz->txrx->txrx_state != SubGhzTxRxStateRx && @@ -92,7 +92,7 @@ uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) { static bool subghz_tx(SubGhz* subghz, uint32_t frequency) { furi_assert(subghz); if(!furi_hal_subghz_is_frequency_valid(frequency)) { - furi_crash("SugGhz: Incorrect TX frequency."); + furi_crash("SubGhz: Incorrect TX frequency."); } furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep); furi_hal_subghz_idle(); diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index 7f40a1528..79262ef52 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -412,7 +412,7 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) { furi_hal_subghz_load_registers(furi_hal_subghz_preset_gfsk_9_99kb_async_regs); furi_hal_subghz_load_patable(furi_hal_subghz_preset_gfsk_async_patable); } else { - furi_crash("SugGhz: Missing config."); + furi_crash("SubGhz: Missing config."); } furi_hal_subghz_preset = preset; } @@ -564,7 +564,7 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) { } else if(value >= 778999847 && value <= 928000000) { furi_hal_subghz_set_path(FuriHalSubGhzPath868); } else { - furi_crash("SugGhz: Incorrect frequency during set."); + furi_crash("SubGhz: Incorrect frequency during set."); } return value; } diff --git a/lib/subghz/protocols/came_twee.c b/lib/subghz/protocols/came_twee.c index e5fb12d1e..1b60e1119 100644 --- a/lib/subghz/protocols/came_twee.c +++ b/lib/subghz/protocols/came_twee.c @@ -145,7 +145,7 @@ static LevelDuration break; default: - furi_crash("SugGhz: ManchesterEncoderResult is incorrect."); + furi_crash("SubGhz: ManchesterEncoderResult is incorrect."); break; } return level_duration_make(data.level, data.duration); diff --git a/lib/subghz/protocols/secplus_v2.c b/lib/subghz/protocols/secplus_v2.c index af4de9342..70ff19e48 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -442,7 +442,7 @@ static LevelDuration break; default: - furi_crash("SugGhz: ManchesterEncoderResult is incorrect."); + furi_crash("SubGhz: ManchesterEncoderResult is incorrect."); break; } return level_duration_make(data.level, data.duration); From b625e84424f2058b0d507d2959600d0ff8b7ddad Mon Sep 17 00:00:00 2001 From: Skorpionm <85568270+Skorpionm@users.noreply.github.com> Date: Wed, 1 Jun 2022 16:17:21 +0400 Subject: [PATCH 4/4] SubGhz: Add Chamberlain 7-Code, Chamberlain 8-Code, Chamberlain 9-Code (#1288) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SubGhz: fix protocol MegaCode start duration * SubGhz: add reception Chamberlain Code 7, 8, 9 protocols * SubGhz: Generating an upload from HEX data and a duration of 1 bit * SubGhz: add transmit Chamberlain Code 7, 8, 9 protocol * SubGhz: Rename Firefly -> Linear Co-authored-by: あく --- .../subghz/scenes/subghz_scene_set_type.c | 10 +- applications/unit_tests/subghz/subghz_test.c | 16 +- .../subghz/{firely.sub => linear.sub} | 2 +- .../{firefly_raw.sub => linear_raw.sub} | 0 lib/subghz/blocks/encoder.c | 42 ++ lib/subghz/blocks/encoder.h | 36 ++ lib/subghz/protocols/chamberlain_code.c | 483 ++++++++++++++++++ lib/subghz/protocols/chamberlain_code.h | 109 ++++ lib/subghz/protocols/firefly.h | 109 ---- lib/subghz/protocols/{firefly.c => linear.c} | 198 ++++--- lib/subghz/protocols/linear.h | 109 ++++ lib/subghz/protocols/megacode.c | 2 +- lib/subghz/protocols/registry.c | 3 +- lib/subghz/protocols/registry.h | 3 +- 14 files changed, 896 insertions(+), 226 deletions(-) rename assets/unit_tests/subghz/{firely.sub => linear.sub} (88%) rename assets/unit_tests/subghz/{firefly_raw.sub => linear_raw.sub} (100%) create mode 100644 lib/subghz/protocols/chamberlain_code.c create mode 100644 lib/subghz/protocols/chamberlain_code.h delete mode 100644 lib/subghz/protocols/firefly.h rename lib/subghz/protocols/{firefly.c => linear.c} (55%) create mode 100644 lib/subghz/protocols/linear.h diff --git a/applications/subghz/scenes/subghz_scene_set_type.c b/applications/subghz/scenes/subghz_scene_set_type.c index b64d0023b..a6f0c3eaa 100644 --- a/applications/subghz/scenes/subghz_scene_set_type.c +++ b/applications/subghz/scenes/subghz_scene_set_type.c @@ -22,7 +22,7 @@ enum SubmenuIndex { SubmenuIndexGateTX, SubmenuIndexDoorHan_315_00, SubmenuIndexDoorHan_433_92, - SubmenuIndexFirefly_300_00, + SubmenuIndexLinear_300_00, SubmenuIndexLiftMaster_315_00, SubmenuIndexLiftMaster_390_00, SubmenuIndexSecPlus_v2_310_00, @@ -117,8 +117,8 @@ void subghz_scene_set_type_on_enter(void* context) { subghz); submenu_add_item( subghz->submenu, - "Firefly_300", - SubmenuIndexFirefly_300_00, + "Linear_300", + SubmenuIndexLinear_300_00, subghz_scene_set_type_submenu_callback, subghz); submenu_add_item( @@ -256,11 +256,11 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { generated_protocol = true; } break; - case SubmenuIndexFirefly_300_00: + case SubmenuIndexLinear_300_00: key = (key & 0x3FF); if(subghz_scene_set_type_submenu_gen_data_protocol( subghz, - SUBGHZ_PROTOCOL_FIREFLY_NAME, + SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10, 300000000, diff --git a/applications/unit_tests/subghz/subghz_test.c b/applications/unit_tests/subghz/subghz_test.c index 9e5b65990..c8f23780a 100644 --- a/applications/unit_tests/subghz/subghz_test.c +++ b/applications/unit_tests/subghz/subghz_test.c @@ -328,10 +328,10 @@ MU_TEST(subghz_decoder_star_line_test) { "Test decoder " SUBGHZ_PROTOCOL_STAR_LINE_NAME " error\r\n"); } -MU_TEST(subghz_decoder_firefly_test) { +MU_TEST(subghz_decoder_linear_test) { mu_assert( - subghz_decoder_test("/ext/unit_tests/subghz/firefly_raw.sub", SUBGHZ_PROTOCOL_FIREFLY_NAME), - "Test decoder " SUBGHZ_PROTOCOL_FIREFLY_NAME " error\r\n"); + subghz_decoder_test("/ext/unit_tests/subghz/linear_raw.sub", SUBGHZ_PROTOCOL_LINEAR_NAME), + "Test decoder " SUBGHZ_PROTOCOL_LINEAR_NAME " error\r\n"); } MU_TEST(subghz_decoder_megacode_test) { @@ -398,10 +398,10 @@ MU_TEST(subghz_encoder_keelog_test) { "Test encoder " SUBGHZ_PROTOCOL_KEELOQ_NAME " error\r\n"); } -MU_TEST(subghz_encoder_firefly_test) { +MU_TEST(subghz_encoder_linear_test) { mu_assert( - subghz_encoder_test("/ext/unit_tests/subghz/firely.sub"), - "Test encoder " SUBGHZ_PROTOCOL_FIREFLY_NAME " error\r\n"); + subghz_encoder_test("/ext/unit_tests/subghz/linear.sub"), + "Test encoder " SUBGHZ_PROTOCOL_LINEAR_NAME " error\r\n"); } MU_TEST(subghz_encoder_megacode_test) { @@ -454,7 +454,7 @@ MU_TEST_SUITE(subghz) { MU_RUN_TEST(subghz_decoder_somfy_keytis_test); MU_RUN_TEST(subghz_decoder_somfy_telis_test); MU_RUN_TEST(subghz_decoder_star_line_test); - MU_RUN_TEST(subghz_decoder_firefly_test); + MU_RUN_TEST(subghz_decoder_linear_test); MU_RUN_TEST(subghz_decoder_megacode_test); MU_RUN_TEST(subghz_decoder_secplus_v1_test); MU_RUN_TEST(subghz_decoder_secplus_v2_test); @@ -466,7 +466,7 @@ MU_TEST_SUITE(subghz) { 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_firefly_test); + MU_RUN_TEST(subghz_encoder_linear_test); MU_RUN_TEST(subghz_encoder_megacode_test); MU_RUN_TEST(subghz_encoder_holtek_test); MU_RUN_TEST(subghz_encoder_secplus_v1_test); diff --git a/assets/unit_tests/subghz/firely.sub b/assets/unit_tests/subghz/linear.sub similarity index 88% rename from assets/unit_tests/subghz/firely.sub rename to assets/unit_tests/subghz/linear.sub index a38c21df0..19ab5d722 100644 --- a/assets/unit_tests/subghz/firely.sub +++ b/assets/unit_tests/subghz/linear.sub @@ -2,6 +2,6 @@ Filetype: Flipper SubGhz Key File Version: 1 Frequency: 300000000 Preset: FuriHalSubGhzPresetOok650Async -Protocol: Firefly +Protocol: Linear Bit: 10 Key: 00 00 00 00 00 00 01 E4 diff --git a/assets/unit_tests/subghz/firefly_raw.sub b/assets/unit_tests/subghz/linear_raw.sub similarity index 100% rename from assets/unit_tests/subghz/firefly_raw.sub rename to assets/unit_tests/subghz/linear_raw.sub diff --git a/lib/subghz/blocks/encoder.c b/lib/subghz/blocks/encoder.c index e4b1ddba8..3cefc2c15 100644 --- a/lib/subghz/blocks/encoder.c +++ b/lib/subghz/blocks/encoder.c @@ -1,3 +1,45 @@ #include "encoder.h" +#include "math.h" +#include #define TAG "SubGhzBlockEncoder" + +void subghz_protocol_blocks_set_bit_array( + bool bit_value, + uint8_t data_array[], + size_t set_index_bit, + size_t max_size_array) { + furi_assert(set_index_bit < max_size_array * 8); + bit_write(data_array[set_index_bit >> 3], 7 - (set_index_bit & 0x7), bit_value); +} + +bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_index_bit) { + return bit_read(data_array[read_index_bit >> 3], 7 - (read_index_bit & 0x7)); +} + +size_t subghz_protocol_blocks_get_upload( + uint8_t data_array[], + size_t count_bit_data_array, + LevelDuration* upload, + size_t max_size_upload, + uint32_t duration_bit) { + size_t index_bit = 0; + size_t size_upload = 0; + uint32_t duration = duration_bit; + bool last_bit = subghz_protocol_blocks_get_bit_array(data_array, index_bit++); + for(size_t i = 1; i < count_bit_data_array; i++) { + if(last_bit == subghz_protocol_blocks_get_bit_array(data_array, index_bit)) { + duration += duration_bit; + } else { + furi_assert(max_size_upload > size_upload); + upload[size_upload++] = level_duration_make( + subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration); + last_bit = !last_bit; + duration = duration_bit; + } + index_bit++; + } + upload[size_upload++] = level_duration_make( + subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration); + return size_upload; +} \ No newline at end of file diff --git a/lib/subghz/blocks/encoder.h b/lib/subghz/blocks/encoder.h index 5c84fcd19..80ffe4900 100644 --- a/lib/subghz/blocks/encoder.h +++ b/lib/subghz/blocks/encoder.h @@ -14,3 +14,39 @@ typedef struct { LevelDuration* upload; } SubGhzProtocolBlockEncoder; + +/** + * Set data bit when encoding HEX array. + * @param bit_value The value of the bit to be set + * @param data_array Pointer to a HEX array + * @param set_index_bit Number set a bit in the array starting from the left + * @param max_size_array array size, check not to overflow + */ +void subghz_protocol_blocks_set_bit_array( + bool bit_value, + uint8_t data_array[], + size_t set_index_bit, + size_t max_size_array); + +/** + * Get data bit when encoding HEX array. + * @param data_array Pointer to a HEX array + * @param read_index_bit Number get a bit in the array starting from the left + * @return bool value bit + */ +bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_index_bit); + +/** + * Generating an upload from data. + * @param data_array Pointer to a HEX array + * @param count_bit_data_array How many bits in the array are processed + * @param upload Pointer to a LevelDuration + * @param max_size_upload upload size, check not to overflow + * @param duration_bit duration 1 bit + */ +size_t subghz_protocol_blocks_get_upload( + uint8_t data_array[], + size_t count_bit_data_array, + LevelDuration* upload, + size_t max_size_upload, + uint32_t duration_bit); diff --git a/lib/subghz/protocols/chamberlain_code.c b/lib/subghz/protocols/chamberlain_code.c new file mode 100644 index 000000000..23ac8cc89 --- /dev/null +++ b/lib/subghz/protocols/chamberlain_code.c @@ -0,0 +1,483 @@ +#include "chamberlain_code.h" + +#include "../blocks/const.h" +#include "../blocks/decoder.h" +#include "../blocks/encoder.h" +#include "../blocks/generic.h" +#include "../blocks/math.h" + +#define TAG "SubGhzProtocolChamb_Code" + +#define CHAMBERLAIN_CODE_BIT_STOP 0b0001 +#define CHAMBERLAIN_CODE_BIT_1 0b0011 +#define CHAMBERLAIN_CODE_BIT_0 0b0111 + +#define CHAMBERLAIN_7_CODE_MASK 0xF000000FF0F +#define CHAMBERLAIN_8_CODE_MASK 0xF00000F00F +#define CHAMBERLAIN_9_CODE_MASK 0xF000000000F + +#define CHAMBERLAIN_7_CODE_MASK_CHECK 0x10000001101 +#define CHAMBERLAIN_8_CODE_MASK_CHECK 0x1000001001 +#define CHAMBERLAIN_9_CODE_MASK_CHECK 0x10000000001 + +#define CHAMBERLAIN_7_CODE_DIP_PATTERN "%c%c%c%c%c%c%c" +#define CHAMBERLAIN_7_CODE_DATA_TO_DIP(dip) \ + (dip & 0x0040 ? '1' : '0'), (dip & 0x0020 ? '1' : '0'), (dip & 0x0010 ? '1' : '0'), \ + (dip & 0x0008 ? '1' : '0'), (dip & 0x0004 ? '1' : '0'), (dip & 0x0002 ? '1' : '0'), \ + (dip & 0x0001 ? '1' : '0') + +#define CHAMBERLAIN_8_CODE_DIP_PATTERN "%c%c%c%c%cx%c%c" +#define CHAMBERLAIN_8_CODE_DATA_TO_DIP(dip) \ + (dip & 0x0080 ? '1' : '0'), (dip & 0x0040 ? '1' : '0'), (dip & 0x0020 ? '1' : '0'), \ + (dip & 0x0010 ? '1' : '0'), (dip & 0x0008 ? '1' : '0'), (dip & 0x0001 ? '1' : '0'), \ + (dip & 0x0002 ? '1' : '0') + +#define CHAMBERLAIN_9_CODE_DIP_PATTERN "%c%c%c%c%c%c%c%c%c" +#define CHAMBERLAIN_9_CODE_DATA_TO_DIP(dip) \ + (dip & 0x0100 ? '1' : '0'), (dip & 0x0080 ? '1' : '0'), (dip & 0x0040 ? '1' : '0'), \ + (dip & 0x0020 ? '1' : '0'), (dip & 0x0010 ? '1' : '0'), (dip & 0x0008 ? '1' : '0'), \ + (dip & 0x0001 ? '1' : '0'), (dip & 0x0002 ? '1' : '0'), (dip & 0x0004 ? '1' : '0') + +static const SubGhzBlockConst subghz_protocol_chamb_code_const = { + .te_short = 1000, + .te_long = 3000, + .te_delta = 200, + .min_count_bit_for_found = 10, +}; + +struct SubGhzProtocolDecoderChamb_Code { + SubGhzProtocolDecoderBase base; + + SubGhzBlockDecoder decoder; + SubGhzBlockGeneric generic; +}; + +struct SubGhzProtocolEncoderChamb_Code { + SubGhzProtocolEncoderBase base; + + SubGhzProtocolBlockEncoder encoder; + SubGhzBlockGeneric generic; +}; + +typedef enum { + Chamb_CodeDecoderStepReset = 0, + Chamb_CodeDecoderStepFoundStartBit, + Chamb_CodeDecoderStepSaveDuration, + Chamb_CodeDecoderStepCheckDuration, +} Chamb_CodeDecoderStep; + +const SubGhzProtocolDecoder subghz_protocol_chamb_code_decoder = { + .alloc = subghz_protocol_decoder_chamb_code_alloc, + .free = subghz_protocol_decoder_chamb_code_free, + + .feed = subghz_protocol_decoder_chamb_code_feed, + .reset = subghz_protocol_decoder_chamb_code_reset, + + .get_hash_data = subghz_protocol_decoder_chamb_code_get_hash_data, + .serialize = subghz_protocol_decoder_chamb_code_serialize, + .deserialize = subghz_protocol_decoder_chamb_code_deserialize, + .get_string = subghz_protocol_decoder_chamb_code_get_string, +}; + +const SubGhzProtocolEncoder subghz_protocol_chamb_code_encoder = { + .alloc = subghz_protocol_encoder_chamb_code_alloc, + .free = subghz_protocol_encoder_chamb_code_free, + + .deserialize = subghz_protocol_encoder_chamb_code_deserialize, + .stop = subghz_protocol_encoder_chamb_code_stop, + .yield = subghz_protocol_encoder_chamb_code_yield, +}; + +const SubGhzProtocol subghz_protocol_chamb_code = { + .name = SUBGHZ_PROTOCOL_CHAMB_CODE_NAME, + .type = SubGhzProtocolTypeStatic, + .flag = SubGhzProtocolFlag_315 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | + SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send, + + .decoder = &subghz_protocol_chamb_code_decoder, + .encoder = &subghz_protocol_chamb_code_encoder, +}; + +void* subghz_protocol_encoder_chamb_code_alloc(SubGhzEnvironment* environment) { + UNUSED(environment); + SubGhzProtocolEncoderChamb_Code* instance = malloc(sizeof(SubGhzProtocolEncoderChamb_Code)); + + instance->base.protocol = &subghz_protocol_chamb_code; + instance->generic.protocol_name = instance->base.protocol->name; + + instance->encoder.repeat = 10; + instance->encoder.size_upload = 24; + instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration)); + instance->encoder.is_runing = false; + return instance; +} + +void subghz_protocol_encoder_chamb_code_free(void* context) { + furi_assert(context); + SubGhzProtocolEncoderChamb_Code* instance = context; + free(instance->encoder.upload); + free(instance); +} + +static uint64_t subghz_protocol_chamb_bit_to_code(uint64_t data, uint8_t size) { + uint64_t data_res = 0; + for(uint8_t i = 0; i < size; i++) { + if(!(bit_read(data, size - i - 1))) { + data_res = data_res << 4 | CHAMBERLAIN_CODE_BIT_0; + } else { + data_res = data_res << 4 | CHAMBERLAIN_CODE_BIT_1; + } + } + return data_res; +} + +/** + * Generating an upload from data. + * @param instance Pointer to a SubGhzProtocolEncoderChamb_Code instance + * @return true On success + */ +static bool + subghz_protocol_encoder_chamb_code_get_upload(SubGhzProtocolEncoderChamb_Code* instance) { + furi_assert(instance); + + uint64_t data = subghz_protocol_chamb_bit_to_code( + instance->generic.data, instance->generic.data_count_bit); + + switch(instance->generic.data_count_bit) { + case 7: + data = ((data >> 4) << 16) | (data & 0xF) << 4 | CHAMBERLAIN_7_CODE_MASK_CHECK; + break; + case 8: + data = ((data >> 12) << 16) | (data & 0xFF) << 4 | CHAMBERLAIN_8_CODE_MASK_CHECK; + break; + case 9: + data = (data << 4) | CHAMBERLAIN_9_CODE_MASK_CHECK; + break; + + default: + furi_crash(TAG " unknown protocol."); + return false; + break; + } +#define UPLOAD_HEX_DATA_SIZE 10 + uint8_t upload_hex_data[UPLOAD_HEX_DATA_SIZE] = {0}; + size_t upload_hex_count_bit = 0; + + //insert guard time + for(uint8_t i = 0; i < 36; i++) { + subghz_protocol_blocks_set_bit_array( + 0, upload_hex_data, upload_hex_count_bit++, UPLOAD_HEX_DATA_SIZE); + } + + //insert data + switch(instance->generic.data_count_bit) { + case 7: + case 9: + for(uint8_t i = 44; i > 0; i--) { + if(!bit_read(data, i - 1)) { + subghz_protocol_blocks_set_bit_array( + 0, upload_hex_data, upload_hex_count_bit++, UPLOAD_HEX_DATA_SIZE); + } else { + subghz_protocol_blocks_set_bit_array( + 1, upload_hex_data, upload_hex_count_bit++, UPLOAD_HEX_DATA_SIZE); + } + } + break; + case 8: + for(uint8_t i = 40; i > 0; i--) { + if(!bit_read(data, i - 1)) { + subghz_protocol_blocks_set_bit_array( + 0, upload_hex_data, upload_hex_count_bit++, UPLOAD_HEX_DATA_SIZE); + } else { + subghz_protocol_blocks_set_bit_array( + 1, upload_hex_data, upload_hex_count_bit++, UPLOAD_HEX_DATA_SIZE); + } + } + break; + } + + instance->encoder.size_upload = subghz_protocol_blocks_get_upload( + upload_hex_data, + upload_hex_count_bit, + instance->encoder.upload, + instance->encoder.size_upload, + subghz_protocol_chamb_code_const.te_short); + + return true; +} + +bool subghz_protocol_encoder_chamb_code_deserialize(void* context, FlipperFormat* flipper_format) { + furi_assert(context); + SubGhzProtocolEncoderChamb_Code* instance = context; + bool res = false; + do { + if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) { + FURI_LOG_E(TAG, "Deserialize error"); + break; + } + + //optional parameter parameter + flipper_format_read_uint32( + flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1); + + subghz_protocol_encoder_chamb_code_get_upload(instance); + instance->encoder.is_runing = true; + + res = true; + } while(false); + + return res; +} + +void subghz_protocol_encoder_chamb_code_stop(void* context) { + SubGhzProtocolEncoderChamb_Code* instance = context; + instance->encoder.is_runing = false; +} + +LevelDuration subghz_protocol_encoder_chamb_code_yield(void* context) { + SubGhzProtocolEncoderChamb_Code* instance = context; + + if(instance->encoder.repeat == 0 || !instance->encoder.is_runing) { + instance->encoder.is_runing = false; + return level_duration_reset(); + } + + LevelDuration ret = instance->encoder.upload[instance->encoder.front]; + + if(++instance->encoder.front == instance->encoder.size_upload) { + instance->encoder.repeat--; + instance->encoder.front = 0; + } + + return ret; +} + +void* subghz_protocol_decoder_chamb_code_alloc(SubGhzEnvironment* environment) { + UNUSED(environment); + SubGhzProtocolDecoderChamb_Code* instance = malloc(sizeof(SubGhzProtocolDecoderChamb_Code)); + instance->base.protocol = &subghz_protocol_chamb_code; + instance->generic.protocol_name = instance->base.protocol->name; + return instance; +} + +void subghz_protocol_decoder_chamb_code_free(void* context) { + furi_assert(context); + SubGhzProtocolDecoderChamb_Code* instance = context; + free(instance); +} + +void subghz_protocol_decoder_chamb_code_reset(void* context) { + furi_assert(context); + SubGhzProtocolDecoderChamb_Code* instance = context; + instance->decoder.parser_step = Chamb_CodeDecoderStepReset; +} + +static bool subghz_protocol_chamb_code_to_bit(uint64_t* data, uint8_t size) { + uint64_t data_tmp = data[0]; + uint64_t data_res = 0; + for(uint8_t i = 0; i < size; i++) { + if((data_tmp & 0xF) == CHAMBERLAIN_CODE_BIT_0) { + bit_write(data_res, i, 0); + } else if((data_tmp & 0xF) == CHAMBERLAIN_CODE_BIT_1) { + bit_write(data_res, i, 1); + } else { + return false; + } + data_tmp >>= 4; + } + data[0] = data_res; + return true; +} + +static bool subghz_protocol_decoder_chamb_code_check_mask_and_parse( + SubGhzProtocolDecoderChamb_Code* instance) { + furi_assert(instance); + if(instance->decoder.decode_count_bit > + subghz_protocol_chamb_code_const.min_count_bit_for_found + 1) + return false; + + if((instance->decoder.decode_data & CHAMBERLAIN_7_CODE_MASK) == + CHAMBERLAIN_7_CODE_MASK_CHECK) { + instance->decoder.decode_count_bit = 7; + instance->decoder.decode_data &= ~CHAMBERLAIN_7_CODE_MASK; + instance->decoder.decode_data = (instance->decoder.decode_data >> 12) | + ((instance->decoder.decode_data >> 4) & 0xF); + } else if( + (instance->decoder.decode_data & CHAMBERLAIN_8_CODE_MASK) == + CHAMBERLAIN_8_CODE_MASK_CHECK) { + instance->decoder.decode_count_bit = 8; + instance->decoder.decode_data &= ~CHAMBERLAIN_8_CODE_MASK; + instance->decoder.decode_data = instance->decoder.decode_data >> 4 | + CHAMBERLAIN_CODE_BIT_0 << 8; //DIP 6 no use + } else if( + (instance->decoder.decode_data & CHAMBERLAIN_9_CODE_MASK) == + CHAMBERLAIN_9_CODE_MASK_CHECK) { + instance->decoder.decode_count_bit = 9; + instance->decoder.decode_data &= ~CHAMBERLAIN_9_CODE_MASK; + instance->decoder.decode_data >>= 4; + } else { + return false; + } + return subghz_protocol_chamb_code_to_bit( + &instance->decoder.decode_data, instance->decoder.decode_count_bit); +} + +void subghz_protocol_decoder_chamb_code_feed(void* context, bool level, uint32_t duration) { + furi_assert(context); + SubGhzProtocolDecoderChamb_Code* instance = context; + switch(instance->decoder.parser_step) { + case Chamb_CodeDecoderStepReset: + if((!level) && (DURATION_DIFF(duration, subghz_protocol_chamb_code_const.te_short * 39) < + subghz_protocol_chamb_code_const.te_delta * 20)) { + //Found header Chamb_Code + instance->decoder.parser_step = Chamb_CodeDecoderStepFoundStartBit; + } + break; + case Chamb_CodeDecoderStepFoundStartBit: + if((level) && (DURATION_DIFF(duration, subghz_protocol_chamb_code_const.te_short) < + subghz_protocol_chamb_code_const.te_delta)) { + //Found start bit Chamb_Code + instance->decoder.decode_data = 0; + instance->decoder.decode_count_bit = 0; + instance->decoder.decode_data = instance->decoder.decode_data << 4 | + CHAMBERLAIN_CODE_BIT_STOP; + instance->decoder.decode_count_bit++; + instance->decoder.parser_step = Chamb_CodeDecoderStepSaveDuration; + } else { + instance->decoder.parser_step = Chamb_CodeDecoderStepReset; + } + break; + case Chamb_CodeDecoderStepSaveDuration: + if(!level) { //save interval + if(duration > subghz_protocol_chamb_code_const.te_short * 5) { + if(instance->decoder.decode_count_bit >= + subghz_protocol_chamb_code_const.min_count_bit_for_found) { + instance->generic.serial = 0x0; + instance->generic.btn = 0x0; + if(subghz_protocol_decoder_chamb_code_check_mask_and_parse(instance)) { + instance->generic.data = instance->decoder.decode_data; + instance->generic.data_count_bit = instance->decoder.decode_count_bit; + if(instance->base.callback) + instance->base.callback(&instance->base, instance->base.context); + } + } + instance->decoder.parser_step = Chamb_CodeDecoderStepReset; + } else { + instance->decoder.te_last = duration; + instance->decoder.parser_step = Chamb_CodeDecoderStepCheckDuration; + } + } else { + instance->decoder.parser_step = Chamb_CodeDecoderStepReset; + } + break; + case Chamb_CodeDecoderStepCheckDuration: + if(level) { + if((DURATION_DIFF( //Found stop bit Chamb_Code + instance->decoder.te_last, + subghz_protocol_chamb_code_const.te_short * 3) < + subghz_protocol_chamb_code_const.te_delta) && + (DURATION_DIFF(duration, subghz_protocol_chamb_code_const.te_short) < + subghz_protocol_chamb_code_const.te_delta)) { + instance->decoder.decode_data = instance->decoder.decode_data << 4 | + CHAMBERLAIN_CODE_BIT_STOP; + instance->decoder.decode_count_bit++; + instance->decoder.parser_step = Chamb_CodeDecoderStepSaveDuration; + } else if( + (DURATION_DIFF( + instance->decoder.te_last, subghz_protocol_chamb_code_const.te_short * 2) < + subghz_protocol_chamb_code_const.te_delta) && + (DURATION_DIFF(duration, subghz_protocol_chamb_code_const.te_short * 2) < + subghz_protocol_chamb_code_const.te_delta)) { + instance->decoder.decode_data = instance->decoder.decode_data << 4 | + CHAMBERLAIN_CODE_BIT_1; + instance->decoder.decode_count_bit++; + instance->decoder.parser_step = Chamb_CodeDecoderStepSaveDuration; + } else if( + (DURATION_DIFF( + instance->decoder.te_last, subghz_protocol_chamb_code_const.te_short) < + subghz_protocol_chamb_code_const.te_delta) && + (DURATION_DIFF(duration, subghz_protocol_chamb_code_const.te_short * 3) < + subghz_protocol_chamb_code_const.te_delta)) { + instance->decoder.decode_data = instance->decoder.decode_data << 4 | + CHAMBERLAIN_CODE_BIT_0; + instance->decoder.decode_count_bit++; + instance->decoder.parser_step = Chamb_CodeDecoderStepSaveDuration; + } else { + instance->decoder.parser_step = Chamb_CodeDecoderStepReset; + } + + } else { + instance->decoder.parser_step = Chamb_CodeDecoderStepReset; + } + break; + } +} + +uint8_t subghz_protocol_decoder_chamb_code_get_hash_data(void* context) { + furi_assert(context); + SubGhzProtocolDecoderChamb_Code* instance = context; + return subghz_protocol_blocks_get_hash_data( + &instance->decoder, (instance->decoder.decode_count_bit / 8) + 1); +} + +bool subghz_protocol_decoder_chamb_code_serialize( + void* context, + FlipperFormat* flipper_format, + uint32_t frequency, + FuriHalSubGhzPreset preset) { + furi_assert(context); + SubGhzProtocolDecoderChamb_Code* instance = context; + return subghz_block_generic_serialize(&instance->generic, flipper_format, frequency, preset); +} + +bool subghz_protocol_decoder_chamb_code_deserialize(void* context, FlipperFormat* flipper_format) { + furi_assert(context); + SubGhzProtocolDecoderChamb_Code* instance = context; + return subghz_block_generic_deserialize(&instance->generic, flipper_format); +} + +void subghz_protocol_decoder_chamb_code_get_string(void* context, string_t output) { + furi_assert(context); + SubGhzProtocolDecoderChamb_Code* instance = context; + + uint32_t code_found_lo = instance->generic.data & 0x00000000ffffffff; + + uint64_t code_found_reverse = subghz_protocol_blocks_reverse_key( + instance->generic.data, instance->generic.data_count_bit); + + uint32_t code_found_reverse_lo = code_found_reverse & 0x00000000ffffffff; + + string_cat_printf( + output, + "%s %db\r\n" + "Key:0x%03lX\r\n" + "Yek:0x%03lX\r\n", + instance->generic.protocol_name, + instance->generic.data_count_bit, + code_found_lo, + code_found_reverse_lo); + + switch(instance->generic.data_count_bit) { + case 7: + string_cat_printf( + output, + "DIP:" CHAMBERLAIN_7_CODE_DIP_PATTERN "\r\n", + CHAMBERLAIN_7_CODE_DATA_TO_DIP(code_found_lo)); + break; + case 8: + string_cat_printf( + output, + "DIP:" CHAMBERLAIN_8_CODE_DIP_PATTERN "\r\n", + CHAMBERLAIN_8_CODE_DATA_TO_DIP(code_found_lo)); + break; + case 9: + string_cat_printf( + output, + "DIP:" CHAMBERLAIN_9_CODE_DIP_PATTERN "\r\n", + CHAMBERLAIN_9_CODE_DATA_TO_DIP(code_found_lo)); + break; + + default: + break; + } +} diff --git a/lib/subghz/protocols/chamberlain_code.h b/lib/subghz/protocols/chamberlain_code.h new file mode 100644 index 000000000..f6ef48fdb --- /dev/null +++ b/lib/subghz/protocols/chamberlain_code.h @@ -0,0 +1,109 @@ +#pragma once + +#include "base.h" + +#define SUBGHZ_PROTOCOL_CHAMB_CODE_NAME "Cham_Code" + +typedef struct SubGhzProtocolDecoderChamb_Code SubGhzProtocolDecoderChamb_Code; +typedef struct SubGhzProtocolEncoderChamb_Code SubGhzProtocolEncoderChamb_Code; + +extern const SubGhzProtocolDecoder subghz_protocol_chamb_code_decoder; +extern const SubGhzProtocolEncoder subghz_protocol_chamb_code_encoder; +extern const SubGhzProtocol subghz_protocol_chamb_code; + +/** + * Allocate SubGhzProtocolEncoderChamb_Code. + * @param environment Pointer to a SubGhzEnvironment instance + * @return SubGhzProtocolEncoderChamb_Code* pointer to a SubGhzProtocolEncoderChamb_Code instance + */ +void* subghz_protocol_encoder_chamb_code_alloc(SubGhzEnvironment* environment); + +/** + * Free SubGhzProtocolEncoderChamb_Code. + * @param context Pointer to a SubGhzProtocolEncoderChamb_Code instance + */ +void subghz_protocol_encoder_chamb_code_free(void* context); + +/** + * Deserialize and generating an upload to send. + * @param context Pointer to a SubGhzProtocolEncoderChamb_Code instance + * @param flipper_format Pointer to a FlipperFormat instance + * @return true On success + */ +bool subghz_protocol_encoder_chamb_code_deserialize(void* context, FlipperFormat* flipper_format); + +/** + * Forced transmission stop. + * @param context Pointer to a SubGhzProtocolEncoderChamb_Code instance + */ +void subghz_protocol_encoder_chamb_code_stop(void* context); + +/** + * Getting the level and duration of the upload to be loaded into DMA. + * @param context Pointer to a SubGhzProtocolEncoderChamb_Code instance + * @return LevelDuration + */ +LevelDuration subghz_protocol_encoder_chamb_code_yield(void* context); + +/** + * Allocate SubGhzProtocolDecoderChamb_Code. + * @param environment Pointer to a SubGhzEnvironment instance + * @return SubGhzProtocolDecoderChamb_Code* pointer to a SubGhzProtocolDecoderChamb_Code instance + */ +void* subghz_protocol_decoder_chamb_code_alloc(SubGhzEnvironment* environment); + +/** + * Free SubGhzProtocolDecoderChamb_Code. + * @param context Pointer to a SubGhzProtocolDecoderChamb_Code instance + */ +void subghz_protocol_decoder_chamb_code_free(void* context); + +/** + * Reset decoder SubGhzProtocolDecoderChamb_Code. + * @param context Pointer to a SubGhzProtocolDecoderChamb_Code instance + */ +void subghz_protocol_decoder_chamb_code_reset(void* context); + +/** + * Parse a raw sequence of levels and durations received from the air. + * @param context Pointer to a SubGhzProtocolDecoderChamb_Code instance + * @param level Signal level true-high false-low + * @param duration Duration of this level in, us + */ +void subghz_protocol_decoder_chamb_code_feed(void* context, bool level, uint32_t duration); + +/** + * Getting the hash sum of the last randomly received parcel. + * @param context Pointer to a SubGhzProtocolDecoderChamb_Code instance + * @return hash Hash sum + */ +uint8_t subghz_protocol_decoder_chamb_code_get_hash_data(void* context); + +/** + * Serialize data SubGhzProtocolDecoderChamb_Code. + * @param context Pointer to a SubGhzProtocolDecoderChamb_Code instance + * @param flipper_format Pointer to a FlipperFormat instance + * @param frequency The frequency at which the signal was received, Hz + * @param preset The modulation on which the signal was received, FuriHalSubGhzPreset + * @return true On success + */ +bool subghz_protocol_decoder_chamb_code_serialize( + void* context, + FlipperFormat* flipper_format, + uint32_t frequency, + FuriHalSubGhzPreset preset); + +/** + * Deserialize data SubGhzProtocolDecoderChamb_Code. + * @param context Pointer to a SubGhzProtocolDecoderChamb_Code instance + * @param flipper_format Pointer to a FlipperFormat instance + * @return true On success + */ +bool subghz_protocol_decoder_chamb_code_deserialize(void* context, FlipperFormat* flipper_format); + +/** + * Getting a textual representation of the received data. + * @param context Pointer to a SubGhzProtocolDecoderChamb_Code instance + * @param output Resulting text + */ +void subghz_protocol_decoder_chamb_code_get_string(void* context, string_t output); diff --git a/lib/subghz/protocols/firefly.h b/lib/subghz/protocols/firefly.h deleted file mode 100644 index abb4537c8..000000000 --- a/lib/subghz/protocols/firefly.h +++ /dev/null @@ -1,109 +0,0 @@ -#pragma once - -#include "base.h" - -#define SUBGHZ_PROTOCOL_FIREFLY_NAME "Firefly" - -typedef struct SubGhzProtocolDecoderFirefly SubGhzProtocolDecoderFirefly; -typedef struct SubGhzProtocolEncoderFirefly SubGhzProtocolEncoderFirefly; - -extern const SubGhzProtocolDecoder subghz_protocol_firefly_decoder; -extern const SubGhzProtocolEncoder subghz_protocol_firefly_encoder; -extern const SubGhzProtocol subghz_protocol_firefly; - -/** - * Allocate SubGhzProtocolEncoderFirefly. - * @param environment Pointer to a SubGhzEnvironment instance - * @return SubGhzProtocolEncoderFirefly* pointer to a SubGhzProtocolEncoderFirefly instance - */ -void* subghz_protocol_encoder_firefly_alloc(SubGhzEnvironment* environment); - -/** - * Free SubGhzProtocolEncoderFirefly. - * @param context Pointer to a SubGhzProtocolEncoderFirefly instance - */ -void subghz_protocol_encoder_firefly_free(void* context); - -/** - * Deserialize and generating an upload to send. - * @param context Pointer to a SubGhzProtocolEncoderFirefly instance - * @param flipper_format Pointer to a FlipperFormat instance - * @return true On success - */ -bool subghz_protocol_encoder_firefly_deserialize(void* context, FlipperFormat* flipper_format); - -/** - * Forced transmission stop. - * @param context Pointer to a SubGhzProtocolEncoderFirefly instance - */ -void subghz_protocol_encoder_firefly_stop(void* context); - -/** - * Getting the level and duration of the upload to be loaded into DMA. - * @param context Pointer to a SubGhzProtocolEncoderFirefly instance - * @return LevelDuration - */ -LevelDuration subghz_protocol_encoder_firefly_yield(void* context); - -/** - * Allocate SubGhzProtocolDecoderFirefly. - * @param environment Pointer to a SubGhzEnvironment instance - * @return SubGhzProtocolDecoderFirefly* pointer to a SubGhzProtocolDecoderFirefly instance - */ -void* subghz_protocol_decoder_firefly_alloc(SubGhzEnvironment* environment); - -/** - * Free SubGhzProtocolDecoderFirefly. - * @param context Pointer to a SubGhzProtocolDecoderFirefly instance - */ -void subghz_protocol_decoder_firefly_free(void* context); - -/** - * Reset decoder SubGhzProtocolDecoderFirefly. - * @param context Pointer to a SubGhzProtocolDecoderFirefly instance - */ -void subghz_protocol_decoder_firefly_reset(void* context); - -/** - * Parse a raw sequence of levels and durations received from the air. - * @param context Pointer to a SubGhzProtocolDecoderFirefly instance - * @param level Signal level true-high false-low - * @param duration Duration of this level in, us - */ -void subghz_protocol_decoder_firefly_feed(void* context, bool level, uint32_t duration); - -/** - * Getting the hash sum of the last randomly received parcel. - * @param context Pointer to a SubGhzProtocolDecoderFirefly instance - * @return hash Hash sum - */ -uint8_t subghz_protocol_decoder_firefly_get_hash_data(void* context); - -/** - * Serialize data SubGhzProtocolDecoderFirefly. - * @param context Pointer to a SubGhzProtocolDecoderFirefly instance - * @param flipper_format Pointer to a FlipperFormat instance - * @param frequency The frequency at which the signal was received, Hz - * @param preset The modulation on which the signal was received, FuriHalSubGhzPreset - * @return true On success - */ -bool subghz_protocol_decoder_firefly_serialize( - void* context, - FlipperFormat* flipper_format, - uint32_t frequency, - FuriHalSubGhzPreset preset); - -/** - * Deserialize data SubGhzProtocolDecoderFirefly. - * @param context Pointer to a SubGhzProtocolDecoderFirefly instance - * @param flipper_format Pointer to a FlipperFormat instance - * @return true On success - */ -bool subghz_protocol_decoder_firefly_deserialize(void* context, FlipperFormat* flipper_format); - -/** - * Getting a textual representation of the received data. - * @param context Pointer to a SubGhzProtocolDecoderFirefly instance - * @param output Resulting text - */ -void subghz_protocol_decoder_firefly_get_string(void* context, string_t output); diff --git a/lib/subghz/protocols/firefly.c b/lib/subghz/protocols/linear.c similarity index 55% rename from lib/subghz/protocols/firefly.c rename to lib/subghz/protocols/linear.c index 21047a304..6b0132788 100644 --- a/lib/subghz/protocols/firefly.c +++ b/lib/subghz/protocols/linear.c @@ -1,4 +1,4 @@ -#include "firefly.h" +#include "linear.h" #include "../blocks/const.h" #include "../blocks/decoder.h" @@ -6,7 +6,7 @@ #include "../blocks/generic.h" #include "../blocks/math.h" -#define TAG "SubGhzProtocolFirefly" +#define TAG "SubGhzProtocolLinear" #define DIP_PATTERN "%c%c%c%c%c%c%c%c%c%c" #define DATA_TO_DIP(dip) \ @@ -15,21 +15,21 @@ (dip & 0x0008 ? '1' : '0'), (dip & 0x0004 ? '1' : '0'), (dip & 0x0002 ? '1' : '0'), \ (dip & 0x0001 ? '1' : '0') -static const SubGhzBlockConst subghz_protocol_firefly_const = { +static const SubGhzBlockConst subghz_protocol_linear_const = { .te_short = 500, .te_long = 1500, .te_delta = 150, .min_count_bit_for_found = 10, }; -struct SubGhzProtocolDecoderFirefly { +struct SubGhzProtocolDecoderLinear { SubGhzProtocolDecoderBase base; SubGhzBlockDecoder decoder; SubGhzBlockGeneric generic; }; -struct SubGhzProtocolEncoderFirefly { +struct SubGhzProtocolEncoderLinear { SubGhzProtocolEncoderBase base; SubGhzProtocolBlockEncoder encoder; @@ -37,48 +37,48 @@ struct SubGhzProtocolEncoderFirefly { }; typedef enum { - FireflyDecoderStepReset = 0, - FireflyDecoderStepSaveDuration, - FireflyDecoderStepCheckDuration, -} FireflyDecoderStep; + LinearDecoderStepReset = 0, + LinearDecoderStepSaveDuration, + LinearDecoderStepCheckDuration, +} LinearDecoderStep; -const SubGhzProtocolDecoder subghz_protocol_firefly_decoder = { - .alloc = subghz_protocol_decoder_firefly_alloc, - .free = subghz_protocol_decoder_firefly_free, +const SubGhzProtocolDecoder subghz_protocol_linear_decoder = { + .alloc = subghz_protocol_decoder_linear_alloc, + .free = subghz_protocol_decoder_linear_free, - .feed = subghz_protocol_decoder_firefly_feed, - .reset = subghz_protocol_decoder_firefly_reset, + .feed = subghz_protocol_decoder_linear_feed, + .reset = subghz_protocol_decoder_linear_reset, - .get_hash_data = subghz_protocol_decoder_firefly_get_hash_data, - .serialize = subghz_protocol_decoder_firefly_serialize, - .deserialize = subghz_protocol_decoder_firefly_deserialize, - .get_string = subghz_protocol_decoder_firefly_get_string, + .get_hash_data = subghz_protocol_decoder_linear_get_hash_data, + .serialize = subghz_protocol_decoder_linear_serialize, + .deserialize = subghz_protocol_decoder_linear_deserialize, + .get_string = subghz_protocol_decoder_linear_get_string, }; -const SubGhzProtocolEncoder subghz_protocol_firefly_encoder = { - .alloc = subghz_protocol_encoder_firefly_alloc, - .free = subghz_protocol_encoder_firefly_free, +const SubGhzProtocolEncoder subghz_protocol_linear_encoder = { + .alloc = subghz_protocol_encoder_linear_alloc, + .free = subghz_protocol_encoder_linear_free, - .deserialize = subghz_protocol_encoder_firefly_deserialize, - .stop = subghz_protocol_encoder_firefly_stop, - .yield = subghz_protocol_encoder_firefly_yield, + .deserialize = subghz_protocol_encoder_linear_deserialize, + .stop = subghz_protocol_encoder_linear_stop, + .yield = subghz_protocol_encoder_linear_yield, }; -const SubGhzProtocol subghz_protocol_firefly = { - .name = SUBGHZ_PROTOCOL_FIREFLY_NAME, +const SubGhzProtocol subghz_protocol_linear = { + .name = SUBGHZ_PROTOCOL_LINEAR_NAME, .type = SubGhzProtocolTypeStatic, .flag = SubGhzProtocolFlag_315 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send, - .decoder = &subghz_protocol_firefly_decoder, - .encoder = &subghz_protocol_firefly_encoder, + .decoder = &subghz_protocol_linear_decoder, + .encoder = &subghz_protocol_linear_encoder, }; -void* subghz_protocol_encoder_firefly_alloc(SubGhzEnvironment* environment) { +void* subghz_protocol_encoder_linear_alloc(SubGhzEnvironment* environment) { UNUSED(environment); - SubGhzProtocolEncoderFirefly* instance = malloc(sizeof(SubGhzProtocolEncoderFirefly)); + SubGhzProtocolEncoderLinear* instance = malloc(sizeof(SubGhzProtocolEncoderLinear)); - instance->base.protocol = &subghz_protocol_firefly; + instance->base.protocol = &subghz_protocol_linear; instance->generic.protocol_name = instance->base.protocol->name; instance->encoder.repeat = 10; @@ -88,19 +88,19 @@ void* subghz_protocol_encoder_firefly_alloc(SubGhzEnvironment* environment) { return instance; } -void subghz_protocol_encoder_firefly_free(void* context) { +void subghz_protocol_encoder_linear_free(void* context) { furi_assert(context); - SubGhzProtocolEncoderFirefly* instance = context; + SubGhzProtocolEncoderLinear* instance = context; free(instance->encoder.upload); free(instance); } /** * Generating an upload from data. - * @param instance Pointer to a SubGhzProtocolEncoderFirefly instance + * @param instance Pointer to a SubGhzProtocolEncoderLinear instance * @return true On success */ -static bool subghz_protocol_encoder_firefly_get_upload(SubGhzProtocolEncoderFirefly* instance) { +static bool subghz_protocol_encoder_linear_get_upload(SubGhzProtocolEncoderLinear* instance) { furi_assert(instance); size_t index = 0; size_t size_upload = (instance->generic.data_count_bit * 2); @@ -116,40 +116,40 @@ static bool subghz_protocol_encoder_firefly_get_upload(SubGhzProtocolEncoderFire if(bit_read(instance->generic.data, i - 1)) { //send bit 1 instance->encoder.upload[index++] = - level_duration_make(true, (uint32_t)subghz_protocol_firefly_const.te_short * 3); + level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short * 3); instance->encoder.upload[index++] = - level_duration_make(false, (uint32_t)subghz_protocol_firefly_const.te_short); + level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short); } else { //send bit 0 instance->encoder.upload[index++] = - level_duration_make(true, (uint32_t)subghz_protocol_firefly_const.te_short); + level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short); instance->encoder.upload[index++] = - level_duration_make(false, (uint32_t)subghz_protocol_firefly_const.te_short * 3); + level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 3); } } //Send end bit if(bit_read(instance->generic.data, 0)) { //send bit 1 instance->encoder.upload[index++] = - level_duration_make(true, (uint32_t)subghz_protocol_firefly_const.te_short * 3); + level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short * 3); //Send PT_GUARD instance->encoder.upload[index++] = - level_duration_make(false, (uint32_t)subghz_protocol_firefly_const.te_short * 42); + level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 42); } else { //send bit 0 instance->encoder.upload[index++] = - level_duration_make(true, (uint32_t)subghz_protocol_firefly_const.te_short); + level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short); //Send PT_GUARD instance->encoder.upload[index++] = - level_duration_make(false, (uint32_t)subghz_protocol_firefly_const.te_short * 44); + level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 44); } return true; } -bool subghz_protocol_encoder_firefly_deserialize(void* context, FlipperFormat* flipper_format) { +bool subghz_protocol_encoder_linear_deserialize(void* context, FlipperFormat* flipper_format) { furi_assert(context); - SubGhzProtocolEncoderFirefly* instance = context; + SubGhzProtocolEncoderLinear* instance = context; bool res = false; do { if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) { @@ -161,7 +161,7 @@ bool subghz_protocol_encoder_firefly_deserialize(void* context, FlipperFormat* f flipper_format_read_uint32( flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1); - subghz_protocol_encoder_firefly_get_upload(instance); + subghz_protocol_encoder_linear_get_upload(instance); instance->encoder.is_runing = true; res = true; @@ -170,13 +170,13 @@ bool subghz_protocol_encoder_firefly_deserialize(void* context, FlipperFormat* f return res; } -void subghz_protocol_encoder_firefly_stop(void* context) { - SubGhzProtocolEncoderFirefly* instance = context; +void subghz_protocol_encoder_linear_stop(void* context) { + SubGhzProtocolEncoderLinear* instance = context; instance->encoder.is_runing = false; } -LevelDuration subghz_protocol_encoder_firefly_yield(void* context) { - SubGhzProtocolEncoderFirefly* instance = context; +LevelDuration subghz_protocol_encoder_linear_yield(void* context) { + SubGhzProtocolEncoderLinear* instance = context; if(instance->encoder.repeat == 0 || !instance->encoder.is_runing) { instance->encoder.is_runing = false; @@ -193,68 +193,66 @@ LevelDuration subghz_protocol_encoder_firefly_yield(void* context) { return ret; } -void* subghz_protocol_decoder_firefly_alloc(SubGhzEnvironment* environment) { +void* subghz_protocol_decoder_linear_alloc(SubGhzEnvironment* environment) { UNUSED(environment); - SubGhzProtocolDecoderFirefly* instance = malloc(sizeof(SubGhzProtocolDecoderFirefly)); - instance->base.protocol = &subghz_protocol_firefly; + SubGhzProtocolDecoderLinear* instance = malloc(sizeof(SubGhzProtocolDecoderLinear)); + instance->base.protocol = &subghz_protocol_linear; instance->generic.protocol_name = instance->base.protocol->name; return instance; } -void subghz_protocol_decoder_firefly_free(void* context) { +void subghz_protocol_decoder_linear_free(void* context) { furi_assert(context); - SubGhzProtocolDecoderFirefly* instance = context; + SubGhzProtocolDecoderLinear* instance = context; free(instance); } -void subghz_protocol_decoder_firefly_reset(void* context) { +void subghz_protocol_decoder_linear_reset(void* context) { furi_assert(context); - SubGhzProtocolDecoderFirefly* instance = context; - instance->decoder.parser_step = FireflyDecoderStepReset; + SubGhzProtocolDecoderLinear* instance = context; + instance->decoder.parser_step = LinearDecoderStepReset; } -void subghz_protocol_decoder_firefly_feed(void* context, bool level, uint32_t duration) { +void subghz_protocol_decoder_linear_feed(void* context, bool level, uint32_t duration) { furi_assert(context); - SubGhzProtocolDecoderFirefly* instance = context; + SubGhzProtocolDecoderLinear* instance = context; switch(instance->decoder.parser_step) { - case FireflyDecoderStepReset: - if((!level) && (DURATION_DIFF(duration, subghz_protocol_firefly_const.te_short * 42) < - subghz_protocol_firefly_const.te_delta * 20)) { - //Found header Firefly + case LinearDecoderStepReset: + if((!level) && (DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) < + subghz_protocol_linear_const.te_delta * 20)) { + //Found header Linear instance->decoder.decode_data = 0; instance->decoder.decode_count_bit = 0; - instance->decoder.parser_step = FireflyDecoderStepSaveDuration; + instance->decoder.parser_step = LinearDecoderStepSaveDuration; } break; - case FireflyDecoderStepSaveDuration: + case LinearDecoderStepSaveDuration: if(level) { instance->decoder.te_last = duration; - instance->decoder.parser_step = FireflyDecoderStepCheckDuration; + instance->decoder.parser_step = LinearDecoderStepCheckDuration; } else { - instance->decoder.parser_step = FireflyDecoderStepReset; + instance->decoder.parser_step = LinearDecoderStepReset; } break; - case FireflyDecoderStepCheckDuration: + case LinearDecoderStepCheckDuration: if(!level) { //save interval - if(duration >= (subghz_protocol_firefly_const.te_short * 5)) { - instance->decoder.parser_step = FireflyDecoderStepReset; + if(duration >= (subghz_protocol_linear_const.te_short * 5)) { + instance->decoder.parser_step = LinearDecoderStepReset; //checking that the duration matches the guardtime - if((DURATION_DIFF(duration, subghz_protocol_firefly_const.te_short * 42) > - subghz_protocol_firefly_const.te_delta * 20)) { + if((DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) > + subghz_protocol_linear_const.te_delta * 20)) { break; } - if(DURATION_DIFF( - instance->decoder.te_last, subghz_protocol_firefly_const.te_short) < - subghz_protocol_firefly_const.te_delta) { + if(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_linear_const.te_short) < + subghz_protocol_linear_const.te_delta) { subghz_protocol_blocks_add_bit(&instance->decoder, 0); } else if( - DURATION_DIFF( - instance->decoder.te_last, subghz_protocol_firefly_const.te_long) < - subghz_protocol_firefly_const.te_delta) { + DURATION_DIFF(instance->decoder.te_last, subghz_protocol_linear_const.te_long) < + subghz_protocol_linear_const.te_delta) { subghz_protocol_blocks_add_bit(&instance->decoder, 1); } if(instance->decoder.decode_count_bit == - subghz_protocol_firefly_const.min_count_bit_for_found) { + subghz_protocol_linear_const.min_count_bit_for_found) { instance->generic.serial = 0x0; instance->generic.btn = 0x0; @@ -267,56 +265,56 @@ void subghz_protocol_decoder_firefly_feed(void* context, bool level, uint32_t du break; } - if((DURATION_DIFF(instance->decoder.te_last, subghz_protocol_firefly_const.te_short) < - subghz_protocol_firefly_const.te_delta) && - (DURATION_DIFF(duration, subghz_protocol_firefly_const.te_long) < - subghz_protocol_firefly_const.te_delta)) { + if((DURATION_DIFF(instance->decoder.te_last, subghz_protocol_linear_const.te_short) < + subghz_protocol_linear_const.te_delta) && + (DURATION_DIFF(duration, subghz_protocol_linear_const.te_long) < + subghz_protocol_linear_const.te_delta)) { subghz_protocol_blocks_add_bit(&instance->decoder, 0); - instance->decoder.parser_step = FireflyDecoderStepSaveDuration; + instance->decoder.parser_step = LinearDecoderStepSaveDuration; } else if( - (DURATION_DIFF(instance->decoder.te_last, subghz_protocol_firefly_const.te_long) < - subghz_protocol_firefly_const.te_delta) && - (DURATION_DIFF(duration, subghz_protocol_firefly_const.te_short) < - subghz_protocol_firefly_const.te_delta)) { + (DURATION_DIFF(instance->decoder.te_last, subghz_protocol_linear_const.te_long) < + subghz_protocol_linear_const.te_delta) && + (DURATION_DIFF(duration, subghz_protocol_linear_const.te_short) < + subghz_protocol_linear_const.te_delta)) { subghz_protocol_blocks_add_bit(&instance->decoder, 1); - instance->decoder.parser_step = FireflyDecoderStepSaveDuration; + instance->decoder.parser_step = LinearDecoderStepSaveDuration; } else { - instance->decoder.parser_step = FireflyDecoderStepReset; + instance->decoder.parser_step = LinearDecoderStepReset; } } else { - instance->decoder.parser_step = FireflyDecoderStepReset; + instance->decoder.parser_step = LinearDecoderStepReset; } break; } } -uint8_t subghz_protocol_decoder_firefly_get_hash_data(void* context) { +uint8_t subghz_protocol_decoder_linear_get_hash_data(void* context) { furi_assert(context); - SubGhzProtocolDecoderFirefly* instance = context; + SubGhzProtocolDecoderLinear* instance = context; return subghz_protocol_blocks_get_hash_data( &instance->decoder, (instance->decoder.decode_count_bit / 8) + 1); } -bool subghz_protocol_decoder_firefly_serialize( +bool subghz_protocol_decoder_linear_serialize( void* context, FlipperFormat* flipper_format, uint32_t frequency, FuriHalSubGhzPreset preset) { furi_assert(context); - SubGhzProtocolDecoderFirefly* instance = context; + SubGhzProtocolDecoderLinear* instance = context; return subghz_block_generic_serialize(&instance->generic, flipper_format, frequency, preset); } -bool subghz_protocol_decoder_firefly_deserialize(void* context, FlipperFormat* flipper_format) { +bool subghz_protocol_decoder_linear_deserialize(void* context, FlipperFormat* flipper_format) { furi_assert(context); - SubGhzProtocolDecoderFirefly* instance = context; + SubGhzProtocolDecoderLinear* instance = context; return subghz_block_generic_deserialize(&instance->generic, flipper_format); } -void subghz_protocol_decoder_firefly_get_string(void* context, string_t output) { +void subghz_protocol_decoder_linear_get_string(void* context, string_t output) { furi_assert(context); - SubGhzProtocolDecoderFirefly* instance = context; + SubGhzProtocolDecoderLinear* instance = context; uint32_t code_found_lo = instance->generic.data & 0x00000000ffffffff; diff --git a/lib/subghz/protocols/linear.h b/lib/subghz/protocols/linear.h new file mode 100644 index 000000000..44f4e7ddc --- /dev/null +++ b/lib/subghz/protocols/linear.h @@ -0,0 +1,109 @@ +#pragma once + +#include "base.h" + +#define SUBGHZ_PROTOCOL_LINEAR_NAME "Linear" + +typedef struct SubGhzProtocolDecoderLinear SubGhzProtocolDecoderLinear; +typedef struct SubGhzProtocolEncoderLinear SubGhzProtocolEncoderLinear; + +extern const SubGhzProtocolDecoder subghz_protocol_linear_decoder; +extern const SubGhzProtocolEncoder subghz_protocol_linear_encoder; +extern const SubGhzProtocol subghz_protocol_linear; + +/** + * Allocate SubGhzProtocolEncoderLinear. + * @param environment Pointer to a SubGhzEnvironment instance + * @return SubGhzProtocolEncoderLinear* pointer to a SubGhzProtocolEncoderLinear instance + */ +void* subghz_protocol_encoder_linear_alloc(SubGhzEnvironment* environment); + +/** + * Free SubGhzProtocolEncoderLinear. + * @param context Pointer to a SubGhzProtocolEncoderLinear instance + */ +void subghz_protocol_encoder_linear_free(void* context); + +/** + * Deserialize and generating an upload to send. + * @param context Pointer to a SubGhzProtocolEncoderLinear instance + * @param flipper_format Pointer to a FlipperFormat instance + * @return true On success + */ +bool subghz_protocol_encoder_linear_deserialize(void* context, FlipperFormat* flipper_format); + +/** + * Forced transmission stop. + * @param context Pointer to a SubGhzProtocolEncoderLinear instance + */ +void subghz_protocol_encoder_linear_stop(void* context); + +/** + * Getting the level and duration of the upload to be loaded into DMA. + * @param context Pointer to a SubGhzProtocolEncoderLinear instance + * @return LevelDuration + */ +LevelDuration subghz_protocol_encoder_linear_yield(void* context); + +/** + * Allocate SubGhzProtocolDecoderLinear. + * @param environment Pointer to a SubGhzEnvironment instance + * @return SubGhzProtocolDecoderLinear* pointer to a SubGhzProtocolDecoderLinear instance + */ +void* subghz_protocol_decoder_linear_alloc(SubGhzEnvironment* environment); + +/** + * Free SubGhzProtocolDecoderLinear. + * @param context Pointer to a SubGhzProtocolDecoderLinear instance + */ +void subghz_protocol_decoder_linear_free(void* context); + +/** + * Reset decoder SubGhzProtocolDecoderLinear. + * @param context Pointer to a SubGhzProtocolDecoderLinear instance + */ +void subghz_protocol_decoder_linear_reset(void* context); + +/** + * Parse a raw sequence of levels and durations received from the air. + * @param context Pointer to a SubGhzProtocolDecoderLinear instance + * @param level Signal level true-high false-low + * @param duration Duration of this level in, us + */ +void subghz_protocol_decoder_linear_feed(void* context, bool level, uint32_t duration); + +/** + * Getting the hash sum of the last randomly received parcel. + * @param context Pointer to a SubGhzProtocolDecoderLinear instance + * @return hash Hash sum + */ +uint8_t subghz_protocol_decoder_linear_get_hash_data(void* context); + +/** + * Serialize data SubGhzProtocolDecoderLinear. + * @param context Pointer to a SubGhzProtocolDecoderLinear instance + * @param flipper_format Pointer to a FlipperFormat instance + * @param frequency The frequency at which the signal was received, Hz + * @param preset The modulation on which the signal was received, FuriHalSubGhzPreset + * @return true On success + */ +bool subghz_protocol_decoder_linear_serialize( + void* context, + FlipperFormat* flipper_format, + uint32_t frequency, + FuriHalSubGhzPreset preset); + +/** + * Deserialize data SubGhzProtocolDecoderLinear. + * @param context Pointer to a SubGhzProtocolDecoderLinear instance + * @param flipper_format Pointer to a FlipperFormat instance + * @return true On success + */ +bool subghz_protocol_decoder_linear_deserialize(void* context, FlipperFormat* flipper_format); + +/** + * Getting a textual representation of the received data. + * @param context Pointer to a SubGhzProtocolDecoderLinear instance + * @param output Resulting text + */ +void subghz_protocol_decoder_linear_get_string(void* context, string_t output); diff --git a/lib/subghz/protocols/megacode.c b/lib/subghz/protocols/megacode.c index 6f6240a62..f8d42b29e 100644 --- a/lib/subghz/protocols/megacode.c +++ b/lib/subghz/protocols/megacode.c @@ -247,7 +247,7 @@ void subghz_protocol_decoder_megacode_feed(void* context, bool level, uint32_t d switch(instance->decoder.parser_step) { case MegaCodeDecoderStepReset: if((!level) && (DURATION_DIFF(duration, subghz_protocol_megacode_const.te_short * 13) < - subghz_protocol_megacode_const.te_delta * 15)) { //10..16ms + subghz_protocol_megacode_const.te_delta * 17)) { //10..16ms //Found header MegaCode instance->decoder.parser_step = MegaCodeDecoderStepFoundStartBit; } diff --git a/lib/subghz/protocols/registry.c b/lib/subghz/protocols/registry.c index b90e535c3..668e6ad50 100644 --- a/lib/subghz/protocols/registry.c +++ b/lib/subghz/protocols/registry.c @@ -7,8 +7,9 @@ const SubGhzProtocol* subghz_protocol_registry[] = { &subghz_protocol_nero_sketch, &subghz_protocol_ido, &subghz_protocol_kia, &subghz_protocol_hormann, &subghz_protocol_nero_radio, &subghz_protocol_somfy_telis, &subghz_protocol_somfy_keytis, &subghz_protocol_scher_khan, &subghz_protocol_princeton, - &subghz_protocol_raw, &subghz_protocol_firefly, &subghz_protocol_secplus_v2, + &subghz_protocol_raw, &subghz_protocol_linear, &subghz_protocol_secplus_v2, &subghz_protocol_secplus_v1, &subghz_protocol_megacode, &subghz_protocol_holtek, + &subghz_protocol_chamb_code, }; diff --git a/lib/subghz/protocols/registry.h b/lib/subghz/protocols/registry.h index a8bc9af45..393223802 100644 --- a/lib/subghz/protocols/registry.h +++ b/lib/subghz/protocols/registry.h @@ -21,11 +21,12 @@ #include "scher_khan.h" #include "gate_tx.h" #include "raw.h" -#include "firefly.h" +#include "linear.h" #include "secplus_v2.h" #include "secplus_v1.h" #include "megacode.h" #include "holtek.h" +#include "chamberlain_code.h" /** * Registration by name SubGhzProtocol.