From 841e18dfec820cc7197957f30af1a613c7021efd Mon Sep 17 00:00:00 2001 From: Skorpionm <85568270+Skorpionm@users.noreply.github.com> Date: Mon, 11 Oct 2021 23:48:54 +0400 Subject: [PATCH] [FL-1940] SubGuz: fix te pricenton protocol #755 --- lib/subghz/protocols/subghz_protocol_princeton.c | 13 ++++++------- lib/subghz/protocols/subghz_protocol_princeton.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/subghz/protocols/subghz_protocol_princeton.c b/lib/subghz/protocols/subghz_protocol_princeton.c index 7819d0dd..6e8b2ac6 100644 --- a/lib/subghz/protocols/subghz_protocol_princeton.c +++ b/lib/subghz/protocols/subghz_protocol_princeton.c @@ -209,6 +209,7 @@ void subghz_decoder_princeton_parse( instance->common.parser_step = PrincetonDecoderStepSaveDuration; instance->common.code_found = 0; instance->common.code_count_bit = 0; + instance->te = 0; } else { instance->common.parser_step = PrincetonDecoderStepReset; } @@ -217,6 +218,7 @@ void subghz_decoder_princeton_parse( //save duration if(level) { instance->common.te_last = duration; + instance->te += duration; instance->common.parser_step = PrincetonDecoderStepCheckDuration; } break; @@ -226,13 +228,7 @@ void subghz_decoder_princeton_parse( instance->common.parser_step = PrincetonDecoderStepSaveDuration; if(instance->common.code_count_bit == instance->common.code_min_count_bit_for_found) { - if(instance->common.code_last_found == instance->common.code_found) { - //instance->te = (instance->te+instance->common.te_last)/2; //Option 1 TE averaging - if(instance->te > instance->common.te_last) - instance->te = instance->common.te_last; //Option 2 TE averaging - } else { - instance->te = instance->common.te_last; - } + instance->te /= (instance->common.code_count_bit * 4 + 1); instance->common.code_last_found = instance->common.code_found; instance->common.code_last_count_bit = instance->common.code_count_bit; @@ -245,9 +241,12 @@ void subghz_decoder_princeton_parse( } instance->common.code_found = 0; instance->common.code_count_bit = 0; + instance->te = 0; break; } + instance->te += duration; + if((DURATION_DIFF(instance->common.te_last, instance->common.te_short) < instance->common.te_delta) && (DURATION_DIFF(duration, instance->common.te_long) < diff --git a/lib/subghz/protocols/subghz_protocol_princeton.h b/lib/subghz/protocols/subghz_protocol_princeton.h index 09a9f482..d7c54e6b 100644 --- a/lib/subghz/protocols/subghz_protocol_princeton.h +++ b/lib/subghz/protocols/subghz_protocol_princeton.h @@ -4,7 +4,7 @@ struct SubGhzDecoderPrinceton { SubGhzProtocolCommon common; - uint16_t te; + uint32_t te; }; /** SubGhzEncoderPrinceton anonymous type */