mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2025-10-10 15:12:41 +02:00
Bresser 3CH protocol: added V0 message format (#245)
* feat(subghz): added V0 message format to Bresser 3CH protocol Improved the Bresser 3CH recognition, as some sensors send multiple message types at the same time. * Update changelog --------- Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
- Games: Umpire Indicator (by @RocketGod-git)
|
- Games: Umpire Indicator (by @RocketGod-git)
|
||||||
- Sub-GHz:
|
- Sub-GHz:
|
||||||
- Show satellites count with an icon (#215 by @m7i-org)
|
- Show satellites count with an icon (#215 by @m7i-org)
|
||||||
- Add Bresser 3CH weather station protocol (#217 by @m7i-org)
|
- Add Bresser 3CH weather station protocol (#217 #245 by @m7i-org)
|
||||||
- UL: Add Marantec24 protocol (static 24 bit) with add manually (by @xMasterX)
|
- UL: Add Marantec24 protocol (static 24 bit) with add manually (by @xMasterX)
|
||||||
- UL: Add GangQi protocol (static 34 bit) with button parsing and add manually (by @xMasterX & @Skorpionm)
|
- UL: Add GangQi protocol (static 34 bit) with button parsing and add manually (by @xMasterX & @Skorpionm)
|
||||||
- UL: Add Hollarm protocol (static 42 bit) with button parsing and add manually (by @xMasterX & @Skorpionm)
|
- UL: Add Hollarm protocol (static 42 bit) with button parsing and add manually (by @xMasterX & @Skorpionm)
|
||||||
|
@@ -0,0 +1,16 @@
|
|||||||
|
Filetype: Flipper SubGhz Key File
|
||||||
|
Version: 1
|
||||||
|
Frequency: 433920000
|
||||||
|
Preset: FuriHalSubGhzPresetOok270Async
|
||||||
|
Latitute: nan
|
||||||
|
Longitude: nan
|
||||||
|
Protocol: Bresser-3CH
|
||||||
|
Id: 117
|
||||||
|
Bit: 36
|
||||||
|
Data: 00 00 00 07 58 05 9F 46
|
||||||
|
Batt: 0
|
||||||
|
Hum: 70
|
||||||
|
Ts: 1728202096
|
||||||
|
Ch: 1
|
||||||
|
Btn: 0
|
||||||
|
Temp: 8.900000
|
@@ -0,0 +1,6 @@
|
|||||||
|
Filetype: Flipper SubGhz RAW File
|
||||||
|
Version: 1
|
||||||
|
Frequency: 433920000
|
||||||
|
Preset: FuriHalSubGhzPresetOok270Async
|
||||||
|
Protocol: RAW
|
||||||
|
RAW_Data: 520 -1000 470 -998 502 -1020 516 -992 482 -2002 482 -992 514 -1962 482 -1990 504 -984 488 -1020 478 -1988 536 -1982 478 -1968 488 -1982 500 -1976 478 -1014 488 -2010 448 -1018 484 -1022 512 -1004 476 -2002 482 -1980 488 -1014 530 -1008 480 -1014 464 -1000 512 -1012 476 -998 502 -1000 502 -986 504 -1012 512 -1002 470 -1030 472 -1020 478 -1014 478 -1000 504 -1016 482 -988 480 -1042 480 -4016 476 -1010 488 -1984 478 -1976 512 -1976 472 -1010 496 -1994 470 -1008 508 -1968 534 -1952 510 -1012 474 -1000 506 -984 518 -992 480 -1010 488 -1020 480 -1016 514 -1006 482 -1982 472 -1012 512 -1970 482 -1978 488 -1018 490 -1010 478 -1980 544 -1950 500 -1974 512 -1970 482 -1978 524 -982 490 -1966 516 -1004 490 -1008 510 -1012 490 -1968 480 -1998 482 -1030 486 -1012 480 -1016 472 -1030 482 -996 484 -1008 484 -1022 482 -1020 482 -1006 506 -984 480 -1016 474 -1004 504 -986 518 -986 476 -1000 480 -1026 480 -1026 482 -3986 530 -1018 476 -1994 480 -1982 456 -2008 478 -1002 500 -1988 476 -1010 476 -1998 514 -1964 484 -1002 482 -1014 474 -998 502 -996 500 -986 510 -982 510 -1006 504 -1016 468 -1972 510 -1010 458 -2006 476 -1966 484 -1020 476 -1006 482 -1990 502 -1976 494 -1996 476 -1964 518 -1948 520 -984 488 -1996 476 -1006 488 -1002 502 -1002 480 -1986 494 -1998 488 -1010 486 -1010 478 -1012 500 -1008 462 -1010 476 -1010 500 -1002 478 -1014 476 -1030 506 -1008 458 -1006 508 -976 508 -1002 468 -1014 482 -1020 478 -1004 500 -1028 470 -3998 554 -984 496 -1966 470 -2002 480 -1982 472 -1006 506 -1958 518 -986 476 -2000 514 -1970 484 -994 502 -1008 470 -1004 508 -1006 468 -996 502 -1014 470 -1002 478 -1012 502 -1974 476 -1004 504 -1976 486 -1964 486 -1002 514 -974 482 -2008 522 -1964 502 -1954 528 -2002 460 -1978 508 -1010 458 -2010 476 -1008 456 -1048 510 -984 476 -1990 482 -1984 468 -1028 500 -1026 468 -1018 466 -1008 504 -998 468 -1020 482 -1018 476 -1010 488 -1020 510 -986 476 -1002 480 -1026 468 -1014 502 -1006 472 -998 504 -982 484 -1016 512 -3980 492 -1008 474 -1994 482 -1982 502 -1970 478 -1016 488 -1966 480 -1028 482 -1986 486 -1988 490 -1004 474 -1012 520 -986 488 -1000 472 -1014 502 -982 508 -1012 506 -1006 480 -1980 504 -978 508 -1966 484 -1972 500 -994 512 -970 512 -1962 508 -2002 480 -1972 508 -1966 500 -1976 470 -998 502 -1960 508 -1010 472 -996 504 -1010 502 -1982 500 -1964 470 -1040 498 -984 510 -1010 486 -984 492 -1004 478 -1014 498 -984 504 -976 506 -998 512 -996 496 -1006 502 -974 506 -996 470 -1028 472 -1008 490 -1006 478 -2372 752 -720 734 -710 742 -752 710 -742 236 -470
|
@@ -677,11 +677,18 @@ MU_TEST(subghz_decoder_solight_te44_test) {
|
|||||||
"Test decoder " WS_PROTOCOL_SOLIGHT_TE44_NAME " error\r\n");
|
"Test decoder " WS_PROTOCOL_SOLIGHT_TE44_NAME " error\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
MU_TEST(subghz_decoder_bresser_3ch_test) {
|
MU_TEST(subghz_decoder_bresser_3ch_v1_test) {
|
||||||
mu_assert(
|
mu_assert(
|
||||||
subghz_decoder_test(
|
subghz_decoder_test(
|
||||||
EXT_PATH("unit_tests/subghz/bresser_3ch_raw.sub"), WS_PROTOCOL_BRESSER_3CH_NAME),
|
EXT_PATH("unit_tests/subghz/bresser_3ch_raw.sub"), WS_PROTOCOL_BRESSER_3CH_NAME),
|
||||||
"Test decoder " WS_PROTOCOL_BRESSER_3CH_NAME " error\r\n");
|
"Test decoder " WS_PROTOCOL_BRESSER_3CH_NAME " v1 error\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
MU_TEST(subghz_decoder_bresser_3ch_v0_test) {
|
||||||
|
mu_assert(
|
||||||
|
subghz_decoder_test(
|
||||||
|
EXT_PATH("unit_tests/subghz/bresser_3ch_v0_raw.sub"), WS_PROTOCOL_BRESSER_3CH_NAME),
|
||||||
|
"Test decoder " WS_PROTOCOL_BRESSER_3CH_NAME " v0 error\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//test encoders
|
//test encoders
|
||||||
@@ -907,6 +914,8 @@ MU_TEST_SUITE(subghz) {
|
|||||||
MU_RUN_TEST(subghz_decoder_mastercode_test);
|
MU_RUN_TEST(subghz_decoder_mastercode_test);
|
||||||
MU_RUN_TEST(subghz_decoder_dickert_test);
|
MU_RUN_TEST(subghz_decoder_dickert_test);
|
||||||
MU_RUN_TEST(subghz_decoder_solight_te44_test);
|
MU_RUN_TEST(subghz_decoder_solight_te44_test);
|
||||||
|
MU_RUN_TEST(subghz_decoder_bresser_3ch_v1_test);
|
||||||
|
MU_RUN_TEST(subghz_decoder_bresser_3ch_v0_test);
|
||||||
|
|
||||||
MU_RUN_TEST(subghz_encoder_princeton_test);
|
MU_RUN_TEST(subghz_encoder_princeton_test);
|
||||||
MU_RUN_TEST(subghz_encoder_came_test);
|
MU_RUN_TEST(subghz_encoder_came_test);
|
||||||
|
@@ -3,11 +3,15 @@
|
|||||||
#define TAG "WSProtocolBresser3ch"
|
#define TAG "WSProtocolBresser3ch"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Bresser sensor protocol in versions V1 and V0
|
||||||
|
*
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* Bresser-3CH V1 format
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*
|
||||||
* Help:
|
* Help:
|
||||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/bresser_3ch.c
|
* https://github.com/merbanan/rtl_433/blob/master/src/devices/bresser_3ch.c
|
||||||
*
|
*
|
||||||
* Bresser sensor protocol.
|
|
||||||
*
|
|
||||||
* The protocol is for the wireless Temperature/Humidity sensor
|
* The protocol is for the wireless Temperature/Humidity sensor
|
||||||
* - Bresser Thermo-/Hygro-Sensor 3CH
|
* - Bresser Thermo-/Hygro-Sensor 3CH
|
||||||
* - also works for Renkforce DM-7511
|
* - also works for Renkforce DM-7511
|
||||||
@@ -30,15 +34,49 @@
|
|||||||
* - humi is 8 bit relative humidity percentage
|
* - humi is 8 bit relative humidity percentage
|
||||||
* - chk is the sum of the four data bytes
|
* - chk is the sum of the four data bytes
|
||||||
*
|
*
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* Bresser-3CH V0 format
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Typically gets sent before V1: same weather station parameters, but in another format.
|
||||||
|
* Probably for older weather stations, as it seems simpler and without a CRC check. No rtl_433 driver yet.
|
||||||
|
*
|
||||||
|
* Encoding, PPM modulated with 0 and 1 swapped:
|
||||||
|
* - Data sync begins with 475 -3975
|
||||||
|
* - A zero is encoded 475 -990
|
||||||
|
* - A one is encoded 475 -1980
|
||||||
|
*
|
||||||
|
* Very much deduced data structure:
|
||||||
|
*
|
||||||
|
* - 8 repetitions of the same 52 bit payload, a sync between each repetition
|
||||||
|
* - 52 bit payload format: IIII IIII CCBB TTTT TTTT TTTT 1111 HHHH HHHH 0000 0000 0000 0000
|
||||||
|
* ^ ^ ^ ^ ^ ^
|
||||||
|
* | | | | | |
|
||||||
|
* 8 bit sensor ID -/ | | | | |
|
||||||
|
* 2 bit channel, bat and btn / | | | |
|
||||||
|
* 12 bit signed int temp(C/10) ---/ / | |
|
||||||
|
* separator ------------------------------------/ / /
|
||||||
|
* 8 bit relative humidity, percentage ---------------/ /
|
||||||
|
* 16 bit zero tail to end (omitted in the saved data) --------/
|
||||||
|
*
|
||||||
* @m7i-org - because there's more stuff screaming in the ether than you might think
|
* @m7i-org - because there's more stuff screaming in the ether than you might think
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const SubGhzBlockConst ws_protocol_bresser_3ch_const = {
|
#define BRESSER_V0_DATA 36
|
||||||
|
#define BRESSER_V0_DATA_AND_TAIL 52
|
||||||
|
#define BRESSER_V1_DATA 40
|
||||||
|
|
||||||
|
static const SubGhzBlockConst ws_protocol_bresser_3ch_v0_const = {
|
||||||
|
.te_short = 475,
|
||||||
|
.te_long = 3900,
|
||||||
|
.te_delta = 150,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const SubGhzBlockConst ws_protocol_bresser_3ch_v1_const = {
|
||||||
.te_short = 250,
|
.te_short = 250,
|
||||||
.te_long = 500,
|
.te_long = 500,
|
||||||
.te_delta = 150,
|
.te_delta = 150,
|
||||||
.min_count_bit_for_found = 40,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WSProtocolDecoderBresser3ch {
|
struct WSProtocolDecoderBresser3ch {
|
||||||
@@ -92,11 +130,14 @@ const SubGhzProtocol ws_protocol_bresser_3ch = {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
Bresser3chDecoderStepReset = 0,
|
Bresser3chDecoderStepReset = 0,
|
||||||
Bresser3chDecoderStepPreambleDn,
|
Bresser3chDecoderStepV0SaveDuration,
|
||||||
Bresser3chDecoderStepPreambleUp,
|
Bresser3chDecoderStepV0CheckDuration,
|
||||||
Bresser3chDecoderStepSaveDuration,
|
Bresser3chDecoderStepV0TailCheckDuration,
|
||||||
Bresser3chDecoderStepCheckDuration,
|
Bresser3chDecoderStepV1PreambleDn,
|
||||||
} Bresser3chDecoderStep;
|
Bresser3chDecoderStepV1PreambleUp,
|
||||||
|
Bresser3chDecoderStepV1SaveDuration,
|
||||||
|
Bresser3chDecoderStepV1CheckDuration,
|
||||||
|
} Bresser3chDecoderStepV1;
|
||||||
|
|
||||||
void* ws_protocol_decoder_bresser_3ch_alloc(SubGhzEnvironment* environment) {
|
void* ws_protocol_decoder_bresser_3ch_alloc(SubGhzEnvironment* environment) {
|
||||||
UNUSED(environment);
|
UNUSED(environment);
|
||||||
@@ -118,7 +159,27 @@ void ws_protocol_decoder_bresser_3ch_reset(void* context) {
|
|||||||
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ws_protocol_bresser_3ch_check(WSProtocolDecoderBresser3ch* instance) {
|
static bool ws_protocol_bresser_3ch_check_v0(WSProtocolDecoderBresser3ch* instance) {
|
||||||
|
if(!instance->decoder.decode_data) return false;
|
||||||
|
|
||||||
|
// No CRC, so better sanity checks here
|
||||||
|
|
||||||
|
if(((instance->decoder.decode_data >> 8) & 0x0f) != 0x0f) return false; // separator not 0xf
|
||||||
|
if(((instance->decoder.decode_data >> 28) & 0xff) == 0xff) return false; // ID only ones?
|
||||||
|
if(((instance->decoder.decode_data >> 28) & 0xff) == 0x00) return false; // ID only zeroes?
|
||||||
|
if(((instance->decoder.decode_data >> 25) & 0x0f) == 0x0f) return false; // flags only ones?
|
||||||
|
if(((instance->decoder.decode_data >> 25) & 0x0f) == 0x00) return false; // flags only zeroes?
|
||||||
|
if(((instance->decoder.decode_data >> 12) & 0x0fff) == 0x0fff)
|
||||||
|
return false; // temperature maxed out?
|
||||||
|
if((instance->decoder.decode_data & 0xff) < 20)
|
||||||
|
return false; // humidity percentage less than 20?
|
||||||
|
if((instance->decoder.decode_data & 0xff) > 95)
|
||||||
|
return false; // humidity percentage more than 95?
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ws_protocol_bresser_3ch_check_v1(WSProtocolDecoderBresser3ch* instance) {
|
||||||
if(!instance->decoder.decode_data) return false;
|
if(!instance->decoder.decode_data) return false;
|
||||||
|
|
||||||
uint8_t sum = (((instance->decoder.decode_data >> 32) & 0xff) +
|
uint8_t sum = (((instance->decoder.decode_data >> 32) & 0xff) +
|
||||||
@@ -131,10 +192,30 @@ static bool ws_protocol_bresser_3ch_check(WSProtocolDecoderBresser3ch* instance)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Analysis of received data
|
* Analysis of received data for V0
|
||||||
* @param instance Pointer to a WSBlockGeneric* instance
|
* @param instance Pointer to a WSBlockGeneric* instance
|
||||||
*/
|
*/
|
||||||
static void ws_protocol_bresser_3ch_extract_data(WSBlockGeneric* instance) {
|
static void ws_protocol_bresser_3ch_extract_data_v0(WSBlockGeneric* instance) {
|
||||||
|
instance->id = (instance->data >> 28) & 0xff;
|
||||||
|
instance->channel = ((instance->data >> 27) & 0x01) | (((instance->data >> 26) & 0x01) << 1);
|
||||||
|
instance->btn = ((instance->data >> 25) & 0x1);
|
||||||
|
instance->battery_low = ((instance->data >> 24) & 0x1);
|
||||||
|
|
||||||
|
int16_t temp = (instance->data >> 12) & 0x0fff;
|
||||||
|
/* Handle signed data */
|
||||||
|
if(temp & 0x0800) {
|
||||||
|
temp |= 0xf000;
|
||||||
|
}
|
||||||
|
instance->temp = (float)temp / 10.0;
|
||||||
|
|
||||||
|
instance->humidity = instance->data & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analysis of received data for V1
|
||||||
|
* @param instance Pointer to a WSBlockGeneric* instance
|
||||||
|
*/
|
||||||
|
static void ws_protocol_bresser_3ch_extract_data_v1(WSBlockGeneric* instance) {
|
||||||
instance->id = (instance->data >> 32) & 0xff;
|
instance->id = (instance->data >> 32) & 0xff;
|
||||||
instance->battery_low = ((instance->data >> 31) & 0x1);
|
instance->battery_low = ((instance->data >> 31) & 0x1);
|
||||||
instance->btn = (instance->data >> 30) & 0x1;
|
instance->btn = (instance->data >> 30) & 0x1;
|
||||||
@@ -152,48 +233,117 @@ void ws_protocol_decoder_bresser_3ch_feed(void* context, bool level, uint32_t du
|
|||||||
|
|
||||||
switch(instance->decoder.parser_step) {
|
switch(instance->decoder.parser_step) {
|
||||||
case Bresser3chDecoderStepReset:
|
case Bresser3chDecoderStepReset:
|
||||||
if(level && DURATION_DIFF(duration, ws_protocol_bresser_3ch_const.te_short * 3) <
|
if(level && DURATION_DIFF(duration, ws_protocol_bresser_3ch_v1_const.te_short * 3) <
|
||||||
ws_protocol_bresser_3ch_const.te_delta) {
|
ws_protocol_bresser_3ch_v1_const.te_delta) {
|
||||||
instance->decoder.te_last = duration;
|
instance->decoder.te_last = duration;
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepPreambleDn;
|
instance->decoder.parser_step = Bresser3chDecoderStepV1PreambleDn;
|
||||||
|
instance->decoder.decode_data = 0;
|
||||||
|
instance->decoder.decode_count_bit = 0;
|
||||||
|
} else if((!level) && duration >= ws_protocol_bresser_3ch_v0_const.te_long) {
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepV0SaveDuration;
|
||||||
instance->decoder.decode_data = 0;
|
instance->decoder.decode_data = 0;
|
||||||
instance->decoder.decode_count_bit = 0;
|
instance->decoder.decode_count_bit = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Bresser3chDecoderStepPreambleDn:
|
case Bresser3chDecoderStepV0SaveDuration:
|
||||||
if((!level) && DURATION_DIFF(duration, ws_protocol_bresser_3ch_const.te_short * 3) <
|
if(level) {
|
||||||
ws_protocol_bresser_3ch_const.te_delta) {
|
instance->decoder.te_last = duration;
|
||||||
if(DURATION_DIFF(
|
if(instance->decoder.decode_count_bit < BRESSER_V0_DATA) {
|
||||||
instance->decoder.te_last, ws_protocol_bresser_3ch_const.te_short * 12) <
|
instance->decoder.parser_step = Bresser3chDecoderStepV0CheckDuration;
|
||||||
ws_protocol_bresser_3ch_const.te_delta * 2) {
|
|
||||||
// End of sync after 4*750 (12*250) high values, start reading the message
|
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepSaveDuration;
|
|
||||||
} else {
|
} else {
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepPreambleUp;
|
instance->decoder.parser_step = Bresser3chDecoderStepV0TailCheckDuration;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Bresser3chDecoderStepPreambleUp:
|
case Bresser3chDecoderStepV0CheckDuration:
|
||||||
if(level && DURATION_DIFF(duration, ws_protocol_bresser_3ch_const.te_short * 3) <
|
if(!level) {
|
||||||
ws_protocol_bresser_3ch_const.te_delta) {
|
if(DURATION_DIFF(instance->decoder.te_last, ws_protocol_bresser_3ch_v0_const.te_short) <
|
||||||
instance->decoder.te_last = instance->decoder.te_last + duration;
|
ws_protocol_bresser_3ch_v0_const.te_delta) {
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepPreambleDn;
|
if(DURATION_DIFF(duration, ws_protocol_bresser_3ch_v0_const.te_short * 2) <
|
||||||
|
ws_protocol_bresser_3ch_v0_const.te_delta) {
|
||||||
|
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepV0SaveDuration;
|
||||||
|
} else if(
|
||||||
|
DURATION_DIFF(duration, ws_protocol_bresser_3ch_v0_const.te_short * 4) <
|
||||||
|
ws_protocol_bresser_3ch_v0_const.te_delta) {
|
||||||
|
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepV0SaveDuration;
|
||||||
|
} else
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
|
} else
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
|
} else
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Bresser3chDecoderStepV0TailCheckDuration:
|
||||||
|
if(!level) {
|
||||||
|
if(duration >= ws_protocol_bresser_3ch_v0_const.te_long) {
|
||||||
|
if(instance->decoder.decode_count_bit == BRESSER_V0_DATA_AND_TAIL &&
|
||||||
|
ws_protocol_bresser_3ch_check_v0(instance)) {
|
||||||
|
instance->generic.data = instance->decoder.decode_data;
|
||||||
|
instance->decoder.decode_count_bit = BRESSER_V0_DATA;
|
||||||
|
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||||
|
ws_protocol_bresser_3ch_extract_data_v0(&instance->generic);
|
||||||
|
|
||||||
|
if(instance->base.callback) {
|
||||||
|
instance->base.callback(&instance->base, instance->base.context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
instance->decoder.decode_data = 0;
|
||||||
|
instance->decoder.decode_count_bit = 0;
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
|
} else if(
|
||||||
|
instance->decoder.decode_count_bit < BRESSER_V0_DATA_AND_TAIL &&
|
||||||
|
DURATION_DIFF(
|
||||||
|
instance->decoder.te_last, ws_protocol_bresser_3ch_v0_const.te_short) <
|
||||||
|
ws_protocol_bresser_3ch_v0_const.te_delta &&
|
||||||
|
DURATION_DIFF(duration, ws_protocol_bresser_3ch_v0_const.te_short * 2) <
|
||||||
|
ws_protocol_bresser_3ch_v0_const.te_delta) {
|
||||||
|
instance->decoder.decode_count_bit++;
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepV0SaveDuration;
|
||||||
|
} else
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
|
} else
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Bresser3chDecoderStepV1PreambleDn:
|
||||||
|
if((!level) && DURATION_DIFF(duration, ws_protocol_bresser_3ch_v1_const.te_short * 3) <
|
||||||
|
ws_protocol_bresser_3ch_v1_const.te_delta) {
|
||||||
|
if(DURATION_DIFF(
|
||||||
|
instance->decoder.te_last, ws_protocol_bresser_3ch_v1_const.te_short * 12) <
|
||||||
|
ws_protocol_bresser_3ch_v1_const.te_delta * 2) {
|
||||||
|
// End of sync after 4*750 (12*250) high values, start reading the message
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepV1SaveDuration;
|
||||||
|
} else {
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepV1PreambleUp;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Bresser3chDecoderStepSaveDuration:
|
case Bresser3chDecoderStepV1PreambleUp:
|
||||||
if(instance->decoder.decode_count_bit ==
|
if(level && DURATION_DIFF(duration, ws_protocol_bresser_3ch_v1_const.te_short * 3) <
|
||||||
ws_protocol_bresser_3ch_const.min_count_bit_for_found) {
|
ws_protocol_bresser_3ch_v1_const.te_delta) {
|
||||||
if(ws_protocol_bresser_3ch_check(instance)) {
|
instance->decoder.te_last = instance->decoder.te_last + duration;
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepV1PreambleDn;
|
||||||
|
} else {
|
||||||
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Bresser3chDecoderStepV1SaveDuration:
|
||||||
|
if(instance->decoder.decode_count_bit == BRESSER_V1_DATA) {
|
||||||
|
if(ws_protocol_bresser_3ch_check_v1(instance)) {
|
||||||
instance->generic.data = instance->decoder.decode_data;
|
instance->generic.data = instance->decoder.decode_data;
|
||||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||||
ws_protocol_bresser_3ch_extract_data(&instance->generic);
|
ws_protocol_bresser_3ch_extract_data_v1(&instance->generic);
|
||||||
|
|
||||||
if(instance->base.callback) {
|
if(instance->base.callback) {
|
||||||
instance->base.callback(&instance->base, instance->base.context);
|
instance->base.callback(&instance->base, instance->base.context);
|
||||||
@@ -204,27 +354,27 @@ void ws_protocol_decoder_bresser_3ch_feed(void* context, bool level, uint32_t du
|
|||||||
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
} else if(level) {
|
} else if(level) {
|
||||||
instance->decoder.te_last = duration;
|
instance->decoder.te_last = duration;
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepCheckDuration;
|
instance->decoder.parser_step = Bresser3chDecoderStepV1CheckDuration;
|
||||||
} else {
|
} else {
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Bresser3chDecoderStepCheckDuration:
|
case Bresser3chDecoderStepV1CheckDuration:
|
||||||
if(!level) {
|
if(!level) {
|
||||||
if(DURATION_DIFF(instance->decoder.te_last, ws_protocol_bresser_3ch_const.te_short) <
|
if(DURATION_DIFF(instance->decoder.te_last, ws_protocol_bresser_3ch_v1_const.te_short) <
|
||||||
ws_protocol_bresser_3ch_const.te_delta &&
|
ws_protocol_bresser_3ch_v1_const.te_delta &&
|
||||||
DURATION_DIFF(duration, ws_protocol_bresser_3ch_const.te_long) <
|
DURATION_DIFF(duration, ws_protocol_bresser_3ch_v1_const.te_long) <
|
||||||
ws_protocol_bresser_3ch_const.te_delta) {
|
ws_protocol_bresser_3ch_v1_const.te_delta) {
|
||||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepSaveDuration;
|
instance->decoder.parser_step = Bresser3chDecoderStepV1SaveDuration;
|
||||||
} else if(
|
} else if(
|
||||||
DURATION_DIFF(instance->decoder.te_last, ws_protocol_bresser_3ch_const.te_long) <
|
DURATION_DIFF(instance->decoder.te_last, ws_protocol_bresser_3ch_v1_const.te_long) <
|
||||||
ws_protocol_bresser_3ch_const.te_delta &&
|
ws_protocol_bresser_3ch_v1_const.te_delta &&
|
||||||
DURATION_DIFF(duration, ws_protocol_bresser_3ch_const.te_short) <
|
DURATION_DIFF(duration, ws_protocol_bresser_3ch_v1_const.te_short) <
|
||||||
ws_protocol_bresser_3ch_const.te_delta) {
|
ws_protocol_bresser_3ch_v1_const.te_delta) {
|
||||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepSaveDuration;
|
instance->decoder.parser_step = Bresser3chDecoderStepV1SaveDuration;
|
||||||
} else
|
} else
|
||||||
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
instance->decoder.parser_step = Bresser3chDecoderStepReset;
|
||||||
} else
|
} else
|
||||||
@@ -253,8 +403,18 @@ SubGhzProtocolStatus
|
|||||||
ws_protocol_decoder_bresser_3ch_deserialize(void* context, FlipperFormat* flipper_format) {
|
ws_protocol_decoder_bresser_3ch_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
WSProtocolDecoderBresser3ch* instance = context;
|
WSProtocolDecoderBresser3ch* instance = context;
|
||||||
return ws_block_generic_deserialize_check_count_bit(
|
|
||||||
&instance->generic, flipper_format, ws_protocol_bresser_3ch_const.min_count_bit_for_found);
|
SubGhzProtocolStatus ret = ws_block_generic_deserialize(&instance->generic, flipper_format);
|
||||||
|
|
||||||
|
if(ret == SubGhzProtocolStatusOk) {
|
||||||
|
if(instance->generic.data_count_bit != BRESSER_V0_DATA &&
|
||||||
|
instance->generic.data_count_bit != BRESSER_V1_DATA) {
|
||||||
|
FURI_LOG_D(TAG, "Wrong number of bits in key for Bresser-3CH V0 or V1 packet format");
|
||||||
|
ret = SubGhzProtocolStatusErrorValueBitCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws_protocol_decoder_bresser_3ch_get_string(void* context, FuriString* output) {
|
void ws_protocol_decoder_bresser_3ch_get_string(void* context, FuriString* output) {
|
||||||
|
Reference in New Issue
Block a user