[FL-1956] Fix long packets bug, fix Manchester overrun (#766)

Also fix RC6 test to detect this manchester bug
This commit is contained in:
Albert Kharisov
2021-10-16 16:00:21 +04:00
committed by GitHub
parent 2255060d52
commit 98830a8a41
12 changed files with 174 additions and 38 deletions

View File

@@ -84,16 +84,22 @@ static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) {
bool level = (decoder->level + decoder->timings_cnt + 1) % 2;
uint32_t timing = decoder->timings[0];
/* check if short protocol version can be decoded */
if (timings->min_split_time && !level && (timing > timings->min_split_time)) {
for (int i = 1; decoder->protocol->databit_len[i] && (i < COUNT_OF(decoder->protocol->databit_len)); ++i) {
if (decoder->protocol->databit_len[i] == decoder->databit_cnt) {
return IrdaStatusReady;
if (timings->min_split_time && !level) {
if (timing > timings->min_split_time) {
/* long low timing - check if we're ready for any of protocol modification */
for (int i = 0; decoder->protocol->databit_len[i] && (i < COUNT_OF(decoder->protocol->databit_len)); ++i) {
if (decoder->protocol->databit_len[i] == decoder->databit_cnt) {
return IrdaStatusReady;
}
}
} else if (decoder->protocol->databit_len[0] == decoder->databit_cnt) {
/* short low timing for longest protocol - this is signal is longer than we expected */
return IrdaStatusError;
}
}
status = decoder->protocol->decode(decoder, level, timing);
furi_check(decoder->databit_cnt <= decoder->protocol->databit_len[0]);
furi_assert(status == IrdaStatusError || status == IrdaStatusOk);
if (status == IrdaStatusError) {
break;
@@ -101,7 +107,7 @@ static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) {
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
/* check if largest protocol version can be decoded */
if (level && (decoder->protocol->databit_len[0] == decoder->databit_cnt)) {
if (level && (decoder->protocol->databit_len[0] == decoder->databit_cnt) && !timings->min_split_time) {
status = IrdaStatusReady;
break;
}
@@ -177,6 +183,9 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level,
}
if (*switch_detect) {
if (decoder->protocol->databit_len[0] == decoder->databit_cnt) {
return IrdaStatusError;
}
accumulate_lsb(decoder, level);
}
@@ -185,8 +194,16 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level,
IrdaMessage* irda_common_decoder_check_ready(IrdaCommonDecoder* decoder) {
IrdaMessage* message = NULL;
bool found_length = false;
if (decoder->protocol->interpret(decoder)) {
for (int i = 0; decoder->protocol->databit_len[i] && (i < COUNT_OF(decoder->protocol->databit_len)); ++i) {
if (decoder->protocol->databit_len[i] == decoder->databit_cnt) {
found_length = true;
break;
}
}
if (found_length && decoder->protocol->interpret(decoder)) {
decoder->databit_cnt = 0;
message = &decoder->message;
if (decoder->protocol->decode_repeat) {
@@ -268,7 +285,6 @@ void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec* protocol) {
+ protocol->databit_len[0] / 8
+ !!(protocol->databit_len[0] % 8);
IrdaCommonDecoder* decoder = furi_alloc(alloc_size);
memset(decoder, 0, alloc_size);
decoder->protocol = protocol;
decoder->level = true;
return decoder;

View File

@@ -35,6 +35,7 @@ const IrdaCommonProtocolSpec protocol_samsung32 = {
.preamble_tolerance = IRDA_SAMSUNG_PREAMBLE_TOLERANCE,
.bit_tolerance = IRDA_SAMSUNG_BIT_TOLERANCE,
.silence_time = IRDA_SAMSUNG_SILENCE,
.min_split_time = IRDA_SAMSUNG_MIN_SPLIT_TIME,
},
.databit_len[0] = 32,
.no_stop_bit = false,
@@ -53,6 +54,7 @@ const IrdaCommonProtocolSpec protocol_rc6 = {
.preamble_tolerance = IRDA_RC6_PREAMBLE_TOLERANCE,
.bit_tolerance = IRDA_RC6_BIT_TOLERANCE,
.silence_time = IRDA_RC6_SILENCE,
.min_split_time = IRDA_RC6_MIN_SPLIT_TIME,
},
.databit_len[0] = 1 + 3 + 1 + 8 + 8, // start_bit + 3 mode bits, + 1 toggle bit (x2 timing) + 8 address + 8 command
.manchester_start_from_space = false,
@@ -71,6 +73,7 @@ const IrdaCommonProtocolSpec protocol_rc5 = {
.preamble_tolerance = 0,
.bit_tolerance = IRDA_RC5_BIT_TOLERANCE,
.silence_time = IRDA_RC5_SILENCE,
.min_split_time = IRDA_RC5_MIN_SPLIT_TIME,
},
.databit_len[0] = 1 + 1 + 1 + 5 + 6, // start_bit + start_bit/command_bit + toggle_bit + 5 address + 6 command
.manchester_start_from_space = true,