From 7554b325382628eac47972e232397e461c7fe362 Mon Sep 17 00:00:00 2001 From: MMX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 24 Sep 2025 13:45:03 +0300 Subject: [PATCH] SubGHz: Linear and Dickert MAHS protocols fixes & improvements (#4267) * Linear and dickert mahs fixes * fix dip pattern * proper fix by WillyJL * Fix unit tests Linear Decoder now decodes more linear signals --------- Co-authored-by: hedger --- .../unit_tests/tests/subghz/subghz_test.c | 2 +- lib/subghz/protocols/dickert_mahs.c | 5 ++-- lib/subghz/protocols/linear.c | 29 ++++++++++--------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/applications/debug/unit_tests/tests/subghz/subghz_test.c b/applications/debug/unit_tests/tests/subghz/subghz_test.c index ac14bce6a..a58875fe8 100644 --- a/applications/debug/unit_tests/tests/subghz/subghz_test.c +++ b/applications/debug/unit_tests/tests/subghz/subghz_test.c @@ -17,7 +17,7 @@ #define NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s") #define ALUTECH_AT_4N_DIR_NAME EXT_PATH("subghz/assets/alutech_at_4n") #define TEST_RANDOM_DIR_NAME EXT_PATH("unit_tests/subghz/test_random_raw.sub") -#define TEST_RANDOM_COUNT_PARSE 329 +#define TEST_RANDOM_COUNT_PARSE 331 #define TEST_TIMEOUT 10000 static SubGhzEnvironment* environment_handler; diff --git a/lib/subghz/protocols/dickert_mahs.c b/lib/subghz/protocols/dickert_mahs.c index 4691e3423..3f614412b 100644 --- a/lib/subghz/protocols/dickert_mahs.c +++ b/lib/subghz/protocols/dickert_mahs.c @@ -288,8 +288,9 @@ void subghz_protocol_decoder_dickert_mahs_feed(void* context, bool level, uint32 instance->decoder.decode_count_bit = 0; } - if((!level) && (duration > 10 * subghz_protocol_dickert_mahs_const.te_short)) { - //Found header DICKERT_MAHS + if((!level) && (DURATION_DIFF(duration, subghz_protocol_dickert_mahs_const.te_long * 50) < + subghz_protocol_dickert_mahs_const.te_delta * 70)) { + //Found header DICKERT_MAHS 44k us instance->decoder.parser_step = DickertMAHSDecoderStepInitial; } break; diff --git a/lib/subghz/protocols/linear.c b/lib/subghz/protocols/linear.c index f9d7aaca8..7671dc428 100644 --- a/lib/subghz/protocols/linear.c +++ b/lib/subghz/protocols/linear.c @@ -18,7 +18,7 @@ static const SubGhzBlockConst subghz_protocol_linear_const = { .te_short = 500, .te_long = 1500, - .te_delta = 150, + .te_delta = 350, .min_count_bit_for_found = 10, }; @@ -116,7 +116,7 @@ static bool subghz_protocol_encoder_linear_get_upload(SubGhzProtocolEncoderLinea if(bit_read(instance->generic.data, i - 1)) { //send bit 1 instance->encoder.upload[index++] = - level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short * 3); + level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_long); instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short); } else { @@ -124,22 +124,22 @@ static bool subghz_protocol_encoder_linear_get_upload(SubGhzProtocolEncoderLinea instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short); instance->encoder.upload[index++] = - level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 3); + level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_long); } } //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_linear_const.te_short * 3); - //Send PT_GUARD + level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_long); + //Send gap instance->encoder.upload[index++] = 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_linear_const.te_short); - //Send PT_GUARD + //Send gap instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 44); } @@ -223,7 +223,7 @@ void subghz_protocol_decoder_linear_feed(void* context, bool level, uint32_t dur switch(instance->decoder.parser_step) { case LinearDecoderStepReset: if((!level) && (DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) < - subghz_protocol_linear_const.te_delta * 20)) { + subghz_protocol_linear_const.te_delta * 15)) { //Found header Linear instance->decoder.decode_data = 0; instance->decoder.decode_count_bit = 0; @@ -244,7 +244,7 @@ void subghz_protocol_decoder_linear_feed(void* context, bool level, uint32_t dur instance->decoder.parser_step = LinearDecoderStepReset; //checking that the duration matches the guardtime if(DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) > - subghz_protocol_linear_const.te_delta * 20) { + subghz_protocol_linear_const.te_delta * 15) { break; } if(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_linear_const.te_short) < @@ -321,18 +321,21 @@ void subghz_protocol_decoder_linear_get_string(void* context, FuriString* output furi_assert(context); SubGhzProtocolDecoderLinear* instance = context; - uint32_t code_found_lo = instance->generic.data & 0x00000000ffffffff; + // Protocol is actually implemented wrong way around, bits are inverted. + // Instead of fixing it and breaking old saved remotes, + // only the display here is inverted (~) to show correct values. + uint32_t code_found_lo = ~instance->generic.data & 0x00000000000003ff; uint64_t code_found_reverse = subghz_protocol_blocks_reverse_key( - instance->generic.data, instance->generic.data_count_bit); + ~instance->generic.data, instance->generic.data_count_bit); - uint32_t code_found_reverse_lo = code_found_reverse & 0x00000000ffffffff; + uint32_t code_found_reverse_lo = code_found_reverse & 0x00000000000003ff; furi_string_cat_printf( output, "%s %dbit\r\n" - "Key:0x%08lX\r\n" - "Yek:0x%08lX\r\n" + "Key:0x%03lX\r\n" + "Yek:0x%03lX\r\n" "DIP:" DIP_PATTERN "\r\n", instance->generic.protocol_name, instance->generic.data_count_bit,