Skip to content

Commit 7554b32

Browse files
xMasterXhedger
andauthored
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 <hedger@users.noreply.github.com>
1 parent 6a49131 commit 7554b32

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

applications/debug/unit_tests/tests/subghz/subghz_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s")
1818
#define ALUTECH_AT_4N_DIR_NAME EXT_PATH("subghz/assets/alutech_at_4n")
1919
#define TEST_RANDOM_DIR_NAME EXT_PATH("unit_tests/subghz/test_random_raw.sub")
20-
#define TEST_RANDOM_COUNT_PARSE 329
20+
#define TEST_RANDOM_COUNT_PARSE 331
2121
#define TEST_TIMEOUT 10000
2222

2323
static SubGhzEnvironment* environment_handler;

lib/subghz/protocols/dickert_mahs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ void subghz_protocol_decoder_dickert_mahs_feed(void* context, bool level, uint32
288288
instance->decoder.decode_count_bit = 0;
289289
}
290290

291-
if((!level) && (duration > 10 * subghz_protocol_dickert_mahs_const.te_short)) {
292-
//Found header DICKERT_MAHS
291+
if((!level) && (DURATION_DIFF(duration, subghz_protocol_dickert_mahs_const.te_long * 50) <
292+
subghz_protocol_dickert_mahs_const.te_delta * 70)) {
293+
//Found header DICKERT_MAHS 44k us
293294
instance->decoder.parser_step = DickertMAHSDecoderStepInitial;
294295
}
295296
break;

lib/subghz/protocols/linear.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
static const SubGhzBlockConst subghz_protocol_linear_const = {
1919
.te_short = 500,
2020
.te_long = 1500,
21-
.te_delta = 150,
21+
.te_delta = 350,
2222
.min_count_bit_for_found = 10,
2323
};
2424

@@ -116,30 +116,30 @@ static bool subghz_protocol_encoder_linear_get_upload(SubGhzProtocolEncoderLinea
116116
if(bit_read(instance->generic.data, i - 1)) {
117117
//send bit 1
118118
instance->encoder.upload[index++] =
119-
level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short * 3);
119+
level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_long);
120120
instance->encoder.upload[index++] =
121121
level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short);
122122
} else {
123123
//send bit 0
124124
instance->encoder.upload[index++] =
125125
level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short);
126126
instance->encoder.upload[index++] =
127-
level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 3);
127+
level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_long);
128128
}
129129
}
130130
//Send end bit
131131
if(bit_read(instance->generic.data, 0)) {
132132
//send bit 1
133133
instance->encoder.upload[index++] =
134-
level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short * 3);
135-
//Send PT_GUARD
134+
level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_long);
135+
//Send gap
136136
instance->encoder.upload[index++] =
137137
level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 42);
138138
} else {
139139
//send bit 0
140140
instance->encoder.upload[index++] =
141141
level_duration_make(true, (uint32_t)subghz_protocol_linear_const.te_short);
142-
//Send PT_GUARD
142+
//Send gap
143143
instance->encoder.upload[index++] =
144144
level_duration_make(false, (uint32_t)subghz_protocol_linear_const.te_short * 44);
145145
}
@@ -223,7 +223,7 @@ void subghz_protocol_decoder_linear_feed(void* context, bool level, uint32_t dur
223223
switch(instance->decoder.parser_step) {
224224
case LinearDecoderStepReset:
225225
if((!level) && (DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) <
226-
subghz_protocol_linear_const.te_delta * 20)) {
226+
subghz_protocol_linear_const.te_delta * 15)) {
227227
//Found header Linear
228228
instance->decoder.decode_data = 0;
229229
instance->decoder.decode_count_bit = 0;
@@ -244,7 +244,7 @@ void subghz_protocol_decoder_linear_feed(void* context, bool level, uint32_t dur
244244
instance->decoder.parser_step = LinearDecoderStepReset;
245245
//checking that the duration matches the guardtime
246246
if(DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) >
247-
subghz_protocol_linear_const.te_delta * 20) {
247+
subghz_protocol_linear_const.te_delta * 15) {
248248
break;
249249
}
250250
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
321321
furi_assert(context);
322322
SubGhzProtocolDecoderLinear* instance = context;
323323

324-
uint32_t code_found_lo = instance->generic.data & 0x00000000ffffffff;
324+
// Protocol is actually implemented wrong way around, bits are inverted.
325+
// Instead of fixing it and breaking old saved remotes,
326+
// only the display here is inverted (~) to show correct values.
327+
uint32_t code_found_lo = ~instance->generic.data & 0x00000000000003ff;
325328

326329
uint64_t code_found_reverse = subghz_protocol_blocks_reverse_key(
327-
instance->generic.data, instance->generic.data_count_bit);
330+
~instance->generic.data, instance->generic.data_count_bit);
328331

329-
uint32_t code_found_reverse_lo = code_found_reverse & 0x00000000ffffffff;
332+
uint32_t code_found_reverse_lo = code_found_reverse & 0x00000000000003ff;
330333

331334
furi_string_cat_printf(
332335
output,
333336
"%s %dbit\r\n"
334-
"Key:0x%08lX\r\n"
335-
"Yek:0x%08lX\r\n"
337+
"Key:0x%03lX\r\n"
338+
"Yek:0x%03lX\r\n"
336339
"DIP:" DIP_PATTERN "\r\n",
337340
instance->generic.protocol_name,
338341
instance->generic.data_count_bit,

0 commit comments

Comments
 (0)