diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c23a274..45a086b6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Added: - Sub-GHz: - New Legrand doorbell protocol (#120 by @user890104) + - Integrate EmosE601x and Acurite 5in1 protocols from WS app (#170 by @htotoo) - Choose RSSI threshold for Hopping mode (by @Willy-JL) - UL: Novoferm remotes full support (by @xMasterX) - UL: Add manually Hormann EcoStar, also Sommer FM238 option when default won't work (by @xMasterX) diff --git a/lib/subghz/protocols/acurite_5n1.c b/lib/subghz/protocols/acurite_5n1.c new file mode 100644 index 000000000..55bb02b34 --- /dev/null +++ b/lib/subghz/protocols/acurite_5n1.c @@ -0,0 +1,294 @@ +#include "acurite_5n1.h" + +#define TAG "WSProtocolAcurite_5n1" + +/* + * Help + * https://github.com/merbanan/rtl_433/blob/master/src/devices/acurite.c + * + * Acurite 5n1 Wind Speed Temperature Humidity sensor decoder + * Message Type 0x38, 8 bytes + * | Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 | Byte 7 | + * | --------- | --------- | --------- | --------- | --------- | --------- | --------- | --------- | + * | CCII IIII | IIII IIII | pB11 1000 | p??W WWWW | pWWW TTTT | pTTT TTTT | pHHH HHHH | KKKK KKKK | + * - C: Channel 00: C, 10: B, 11: A, (01 is invalid) + * - I: Device ID (14 bits) + * - B: Battery, 1 is battery OK, 0 is battery low + * - M: Message type (6 bits), 0x38 + * - W: Wind Speed (8 bits) + * - T: Temperature Fahrenheit (11 bits), + 400 * 10 + * - H: Relative Humidity (%) (7 bits) + * - K: Checksum (8 bits) + * - p: Parity bit + * Notes: + * - Temperature + * - Encoded as Fahrenheit + 400 * 10 + * - only 11 bits needed for specified range -40 F - 158 F (-40 C to 70 C) + * + */ + +static const SubGhzBlockConst ws_protocol_acurite_5n1_const = { + .te_short = 200, + .te_long = 400, + .te_delta = 90, + .min_count_bit_for_found = 64, +}; + +struct WSProtocolDecoderAcurite_5n1 { + SubGhzProtocolDecoderBase base; + + SubGhzBlockDecoder decoder; + WSBlockGeneric generic; + + uint16_t header_count; +}; + +struct WSProtocolEncoderAcurite_5n1 { + SubGhzProtocolEncoderBase base; + + SubGhzProtocolBlockEncoder encoder; + WSBlockGeneric generic; +}; + +typedef enum { + Acurite_5n1DecoderStepReset = 0, + Acurite_5n1DecoderStepCheckPreambule, + Acurite_5n1DecoderStepSaveDuration, + Acurite_5n1DecoderStepCheckDuration, +} Acurite_5n1DecoderStep; + +const SubGhzProtocolDecoder ws_protocol_acurite_5n1_decoder = { + .alloc = ws_protocol_decoder_acurite_5n1_alloc, + .free = ws_protocol_decoder_acurite_5n1_free, + + .feed = ws_protocol_decoder_acurite_5n1_feed, + .reset = ws_protocol_decoder_acurite_5n1_reset, + + .get_hash_data = NULL, + .get_hash_data_long = ws_protocol_decoder_acurite_5n1_get_hash_data, + .serialize = ws_protocol_decoder_acurite_5n1_serialize, + .deserialize = ws_protocol_decoder_acurite_5n1_deserialize, + .get_string = ws_protocol_decoder_acurite_5n1_get_string, + .get_string_brief = NULL, +}; + +const SubGhzProtocolEncoder ws_protocol_acurite_5n1_encoder = { + .alloc = NULL, + .free = NULL, + + .deserialize = NULL, + .stop = NULL, + .yield = NULL, +}; + +const SubGhzProtocol ws_protocol_acurite_5n1 = { + .name = WS_PROTOCOL_ACURITE_5N1_NAME, + .type = SubGhzProtocolTypeStatic, + .flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 | + SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load | + SubGhzProtocolFlag_Save, + + .decoder = &ws_protocol_acurite_5n1_decoder, + .encoder = &ws_protocol_acurite_5n1_encoder, + + .filter = SubGhzProtocolFilter_Weather, +}; + +void* ws_protocol_decoder_acurite_5n1_alloc(SubGhzEnvironment* environment) { + UNUSED(environment); + WSProtocolDecoderAcurite_5n1* instance = malloc(sizeof(WSProtocolDecoderAcurite_5n1)); + instance->base.protocol = &ws_protocol_acurite_5n1; + instance->generic.protocol_name = instance->base.protocol->name; + return instance; +} + +void ws_protocol_decoder_acurite_5n1_free(void* context) { + furi_assert(context); + WSProtocolDecoderAcurite_5n1* instance = context; + free(instance); +} + +void ws_protocol_decoder_acurite_5n1_reset(void* context) { + furi_assert(context); + WSProtocolDecoderAcurite_5n1* instance = context; + instance->decoder.parser_step = Acurite_5n1DecoderStepReset; +} + +static bool ws_protocol_acurite_5n1_check_crc(WSProtocolDecoderAcurite_5n1* instance) { + uint8_t msg[] = { + instance->decoder.decode_data >> 56, + instance->decoder.decode_data >> 48, + instance->decoder.decode_data >> 40, + instance->decoder.decode_data >> 32, + instance->decoder.decode_data >> 24, + instance->decoder.decode_data >> 16, + instance->decoder.decode_data >> 8}; + + if((subghz_protocol_blocks_add_bytes(msg, 7) == + (uint8_t)(instance->decoder.decode_data & 0xFF)) && + (!subghz_protocol_blocks_parity_bytes(&msg[2], 5))) { + return true; + } else { + return false; + } +} + +static bool ws_protocol_acurite_5n1_check_message_type(WSProtocolDecoderAcurite_5n1* instance) { + if(((instance->decoder.decode_data >> 40) & 0x3F) == 0x38) { + return true; + } else { + return false; + } +} + +/** + * Analysis of received data + * @param instance Pointer to a WSBlockGeneric* instance + */ +static void ws_protocol_acurite_5n1_remote_controller(WSBlockGeneric* instance) { + uint8_t channel[] = {3, 0, 2, 1}; + uint8_t channel_raw = ((instance->data >> 62) & 0x03); + instance->channel = channel[channel_raw]; + instance->id = (instance->data >> 48) & 0x3FFF; + instance->battery_low = !((instance->data >> 46) & 1); + instance->humidity = (instance->data >> 8) & 0x7F; + + uint16_t temp_raw = ((instance->data >> (24 - 7)) & 0x780) | ((instance->data >> 16) & 0x7F); + instance->temp = locale_fahrenheit_to_celsius(((float)(temp_raw)-400) / 10.0f); + + instance->btn = WS_NO_BTN; +} + +void ws_protocol_decoder_acurite_5n1_feed(void* context, bool level, uint32_t duration) { + furi_assert(context); + WSProtocolDecoderAcurite_5n1* instance = context; + + switch(instance->decoder.parser_step) { + case Acurite_5n1DecoderStepReset: + if((level) && (DURATION_DIFF(duration, ws_protocol_acurite_5n1_const.te_short * 3) < + ws_protocol_acurite_5n1_const.te_delta * 2)) { + instance->decoder.parser_step = Acurite_5n1DecoderStepCheckPreambule; + instance->decoder.te_last = duration; + instance->header_count = 0; + } + break; + + case Acurite_5n1DecoderStepCheckPreambule: + if(level) { + instance->decoder.te_last = duration; + } else { + if((DURATION_DIFF( + instance->decoder.te_last, ws_protocol_acurite_5n1_const.te_short * 3) < + ws_protocol_acurite_5n1_const.te_delta * 2) && + (DURATION_DIFF(duration, ws_protocol_acurite_5n1_const.te_short * 3) < + ws_protocol_acurite_5n1_const.te_delta * 2)) { + //Found preambule + instance->header_count++; + } else if((instance->header_count > 2) && (instance->header_count < 5)) { + if((DURATION_DIFF( + instance->decoder.te_last, ws_protocol_acurite_5n1_const.te_short) < + ws_protocol_acurite_5n1_const.te_delta) && + (DURATION_DIFF(duration, ws_protocol_acurite_5n1_const.te_long) < + ws_protocol_acurite_5n1_const.te_delta)) { + instance->decoder.decode_data = 0; + instance->decoder.decode_count_bit = 0; + subghz_protocol_blocks_add_bit(&instance->decoder, 0); + instance->decoder.parser_step = Acurite_5n1DecoderStepSaveDuration; + } else if( + (DURATION_DIFF( + instance->decoder.te_last, ws_protocol_acurite_5n1_const.te_long) < + ws_protocol_acurite_5n1_const.te_delta) && + (DURATION_DIFF(duration, ws_protocol_acurite_5n1_const.te_short) < + ws_protocol_acurite_5n1_const.te_delta)) { + instance->decoder.decode_data = 0; + instance->decoder.decode_count_bit = 0; + subghz_protocol_blocks_add_bit(&instance->decoder, 1); + instance->decoder.parser_step = Acurite_5n1DecoderStepSaveDuration; + } else { + instance->decoder.parser_step = Acurite_5n1DecoderStepReset; + } + } else { + instance->decoder.parser_step = Acurite_5n1DecoderStepReset; + } + } + break; + + case Acurite_5n1DecoderStepSaveDuration: + if(level) { + instance->decoder.te_last = duration; + instance->decoder.parser_step = Acurite_5n1DecoderStepCheckDuration; + } else { + instance->decoder.parser_step = Acurite_5n1DecoderStepReset; + } + break; + + case Acurite_5n1DecoderStepCheckDuration: + if(!level) { + if(duration >= ((uint32_t)ws_protocol_acurite_5n1_const.te_short * 5)) { + if((instance->decoder.decode_count_bit == + ws_protocol_acurite_5n1_const.min_count_bit_for_found) && + ws_protocol_acurite_5n1_check_crc(instance) && + ws_protocol_acurite_5n1_check_message_type(instance)) { + instance->generic.data = instance->decoder.decode_data; + instance->generic.data_count_bit = instance->decoder.decode_count_bit; + ws_protocol_acurite_5n1_remote_controller(&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 = Acurite_5n1DecoderStepReset; + break; + } else if( + (DURATION_DIFF(instance->decoder.te_last, ws_protocol_acurite_5n1_const.te_short) < + ws_protocol_acurite_5n1_const.te_delta) && + (DURATION_DIFF(duration, ws_protocol_acurite_5n1_const.te_long) < + ws_protocol_acurite_5n1_const.te_delta)) { + subghz_protocol_blocks_add_bit(&instance->decoder, 0); + instance->decoder.parser_step = Acurite_5n1DecoderStepSaveDuration; + } else if( + (DURATION_DIFF(instance->decoder.te_last, ws_protocol_acurite_5n1_const.te_long) < + ws_protocol_acurite_5n1_const.te_delta) && + (DURATION_DIFF(duration, ws_protocol_acurite_5n1_const.te_short) < + ws_protocol_acurite_5n1_const.te_delta)) { + subghz_protocol_blocks_add_bit(&instance->decoder, 1); + instance->decoder.parser_step = Acurite_5n1DecoderStepSaveDuration; + } else { + instance->decoder.parser_step = Acurite_5n1DecoderStepReset; + } + } else { + instance->decoder.parser_step = Acurite_5n1DecoderStepReset; + } + break; + } +} + +uint32_t ws_protocol_decoder_acurite_5n1_get_hash_data(void* context) { + furi_assert(context); + WSProtocolDecoderAcurite_5n1* instance = context; + return subghz_protocol_blocks_get_hash_data_long( + &instance->decoder, (instance->decoder.decode_count_bit / 8) + 1); +} + +SubGhzProtocolStatus ws_protocol_decoder_acurite_5n1_serialize( + void* context, + FlipperFormat* flipper_format, + SubGhzRadioPreset* preset) { + furi_assert(context); + WSProtocolDecoderAcurite_5n1* instance = context; + return ws_block_generic_serialize(&instance->generic, flipper_format, preset); +} + +SubGhzProtocolStatus + ws_protocol_decoder_acurite_5n1_deserialize(void* context, FlipperFormat* flipper_format) { + furi_assert(context); + WSProtocolDecoderAcurite_5n1* instance = context; + return ws_block_generic_deserialize_check_count_bit( + &instance->generic, flipper_format, ws_protocol_acurite_5n1_const.min_count_bit_for_found); +} + +void ws_protocol_decoder_acurite_5n1_get_string(void* context, FuriString* output) { + furi_assert(context); + WSProtocolDecoderAcurite_5n1* instance = context; + ws_block_generic_get_string(&instance->generic, output); +} diff --git a/lib/subghz/protocols/acurite_5n1.h b/lib/subghz/protocols/acurite_5n1.h new file mode 100644 index 000000000..eabc500be --- /dev/null +++ b/lib/subghz/protocols/acurite_5n1.h @@ -0,0 +1,80 @@ +#pragma once + +#include + +#include +#include +#include +#include "ws_generic.h" +#include + +#define WS_PROTOCOL_ACURITE_5N1_NAME "Acurite 5n1" + +typedef struct WSProtocolDecoderAcurite_5n1 WSProtocolDecoderAcurite_5n1; +typedef struct WSProtocolEncoderAcurite_5n1 WSProtocolEncoderAcurite_5n1; + +extern const SubGhzProtocolDecoder ws_protocol_acurite_5n1_decoder; +extern const SubGhzProtocolEncoder ws_protocol_acurite_5n1_encoder; +extern const SubGhzProtocol ws_protocol_acurite_5n1; + +/** + * Allocate WSProtocolDecoderAcurite_5n1. + * @param environment Pointer to a SubGhzEnvironment instance + * @return WSProtocolDecoderAcurite_5n1* pointer to a WSProtocolDecoderAcurite_5n1 instance + */ +void* ws_protocol_decoder_acurite_5n1_alloc(SubGhzEnvironment* environment); + +/** + * Free WSProtocolDecoderAcurite_5n1. + * @param context Pointer to a WSProtocolDecoderAcurite_5n1 instance + */ +void ws_protocol_decoder_acurite_5n1_free(void* context); + +/** + * Reset decoder WSProtocolDecoderAcurite_5n1. + * @param context Pointer to a WSProtocolDecoderAcurite_5n1 instance + */ +void ws_protocol_decoder_acurite_5n1_reset(void* context); + +/** + * Parse a raw sequence of levels and durations received from the air. + * @param context Pointer to a WSProtocolDecoderAcurite_5n1 instance + * @param level Signal level true-high false-low + * @param duration Duration of this level in, us + */ +void ws_protocol_decoder_acurite_5n1_feed(void* context, bool level, uint32_t duration); + +/** + * Getting the hash sum of the last randomly received parcel. + * @param context Pointer to a WSProtocolDecoderAcurite_5n1 instance + * @return hash Hash sum + */ +uint32_t ws_protocol_decoder_acurite_5n1_get_hash_data(void* context); + +/** + * Serialize data WSProtocolDecoderAcurite_5n1. + * @param context Pointer to a WSProtocolDecoderAcurite_5n1 instance + * @param flipper_format Pointer to a FlipperFormat instance + * @param preset The modulation on which the signal was received, SubGhzRadioPreset + * @return status + */ +SubGhzProtocolStatus ws_protocol_decoder_acurite_5n1_serialize( + void* context, + FlipperFormat* flipper_format, + SubGhzRadioPreset* preset); + +/** + * Deserialize data WSProtocolDecoderAcurite_5n1. + * @param context Pointer to a WSProtocolDecoderAcurite_5n1 instance + * @param flipper_format Pointer to a FlipperFormat instance + * @return status + */ +SubGhzProtocolStatus + ws_protocol_decoder_acurite_5n1_deserialize(void* context, FlipperFormat* flipper_format); + +/** + * Getting a textual representation of the received data. + * @param context Pointer to a WSProtocolDecoderAcurite_5n1 instance + * @param output Resulting text + */ +void ws_protocol_decoder_acurite_5n1_get_string(void* context, FuriString* output); diff --git a/lib/subghz/protocols/emos_e601x.c b/lib/subghz/protocols/emos_e601x.c new file mode 100644 index 000000000..bb69b5206 --- /dev/null +++ b/lib/subghz/protocols/emos_e601x.c @@ -0,0 +1,269 @@ +#include "emos_e601x.h" + +#define TAG "WSProtocolEmosE601x" + +/* + * Help + * https://github.com/merbanan/rtl_433/blob/master/src/devices/emos_e6016.c + * + * Data Layout: + * + * PP PP PP II ?K KK KK KK CT TT HH SS DF XX RR + * + * - P: (24 bit) preamble + * - I: (8 bit) ID + * - ?: (2 bit) unknown + * - K: (32 bit) datetime, fields are 6d-4d-5d 5d:6d:6d + * - C: (2 bit) channel + * - T: (12 bit) temperature, signed, scale 10 + * - H: (8 bit) humidity + * - S: (8 bit) wind speed + * - D: (4 bit) wind direction + * - F: (4 bit) flags of (?B??), B is battery good indication + * - X: (8 bit) checksum + * - R: (8 bit) repeat counter + */ + +static const SubGhzBlockConst ws_protocol_emose601x_const = { + .te_short = 260, + .te_long = 800, + .te_delta = 100, + .min_count_bit_for_found = 24, +}; + +#define MAGIC_HEADER 0xaaa583 + +struct WSProtocolDecoderEmosE601x { + SubGhzProtocolDecoderBase base; + + SubGhzBlockDecoder decoder; + WSBlockGeneric generic; + uint64_t upper_decode_data; +}; + +struct WSProtocolEncoderEmosE601x { + SubGhzProtocolEncoderBase base; + + SubGhzProtocolBlockEncoder encoder; + WSBlockGeneric generic; +}; + +typedef enum { + EmosE601xDecoderStepReset = 0, + EmosE601xDecoderStepCheckPreamble, + EmosE601xDecoderStepSaveDuration, + EmosE601xDecoderStepCheckDuration, +} EmosE601xDecoderStep; + +const SubGhzProtocolDecoder ws_protocol_emose601x_decoder = { + .alloc = ws_protocol_decoder_emose601x_alloc, + .free = ws_protocol_decoder_emose601x_free, + + .feed = ws_protocol_decoder_emose601x_feed, + .reset = ws_protocol_decoder_emose601x_reset, + + .get_hash_data = NULL, + .get_hash_data_long = ws_protocol_decoder_emose601x_get_hash_data, + .serialize = ws_protocol_decoder_emose601x_serialize, + .deserialize = ws_protocol_decoder_emose601x_deserialize, + .get_string = ws_protocol_decoder_emose601x_get_string, + .get_string_brief = NULL, +}; + +const SubGhzProtocolEncoder ws_protocol_emose601x_encoder = { + .alloc = NULL, + .free = NULL, + + .deserialize = NULL, + .stop = NULL, + .yield = NULL, +}; + +const SubGhzProtocol ws_protocol_emose601x = { + .name = WS_PROTOCOL_EMOSE601X_NAME, + .type = SubGhzProtocolTypeStatic, + .flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 | + SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load | + SubGhzProtocolFlag_Save, + + .decoder = &ws_protocol_emose601x_decoder, + .encoder = &ws_protocol_emose601x_encoder, + + .filter = SubGhzProtocolFilter_Weather, +}; + +void* ws_protocol_decoder_emose601x_alloc(SubGhzEnvironment* environment) { + UNUSED(environment); + WSProtocolDecoderEmosE601x* instance = malloc(sizeof(WSProtocolDecoderEmosE601x)); + instance->base.protocol = &ws_protocol_emose601x; + instance->generic.protocol_name = instance->base.protocol->name; + return instance; +} + +void ws_protocol_decoder_emose601x_free(void* context) { + furi_assert(context); + WSProtocolDecoderEmosE601x* instance = context; + free(instance); +} + +void ws_protocol_decoder_emose601x_reset(void* context) { + furi_assert(context); + WSProtocolDecoderEmosE601x* instance = context; + instance->decoder.parser_step = EmosE601xDecoderStepReset; +} + +static bool ws_protocol_emose601x_check(WSProtocolDecoderEmosE601x* instance) { + uint8_t msg[] = { + instance->upper_decode_data >> 48, + instance->upper_decode_data >> 40, + instance->upper_decode_data >> 32, + instance->upper_decode_data >> 24, + instance->upper_decode_data >> 16, + instance->upper_decode_data >> 8, + instance->upper_decode_data, + instance->decoder.decode_data >> 56, + instance->decoder.decode_data >> 48, + instance->decoder.decode_data >> 40, + instance->decoder.decode_data >> 32, + instance->decoder.decode_data >> 24, + instance->decoder.decode_data >> 16}; + + uint8_t sum = subghz_protocol_blocks_add_bytes(msg, 13); + return (sum == ((instance->decoder.decode_data >> 8) & 0xff)); +} + +/** + * Analysis of received data + * @param instance Pointer to a WSBlockGeneric* instance + */ +static void ws_protocol_emose601x_extract_data(WSProtocolDecoderEmosE601x* instance) { + instance->generic.id = (instance->upper_decode_data >> 24) & 0xff; + instance->generic.battery_low = (instance->decoder.decode_data >> 10) & 1; + instance->generic.btn = WS_NO_BTN; + int16_t temp = (instance->decoder.decode_data >> 40) & 0xfff; + /* Handle signed data */ + if(temp & 0x800) { + temp |= 0xf000; + } + instance->generic.temp = (float)temp / 10.0; + instance->generic.humidity = (instance->decoder.decode_data >> 32) & 0xff; + instance->generic.channel = (instance->decoder.decode_data >> 52) & 0x03; + instance->generic.data = (instance->decoder.decode_data >> 16); +} + +void ws_protocol_decoder_emose601x_feed(void* context, bool level, uint32_t duration) { + furi_assert(context); + WSProtocolDecoderEmosE601x* instance = context; + + switch(instance->decoder.parser_step) { + case EmosE601xDecoderStepReset: + if((level) && (DURATION_DIFF(duration, ws_protocol_emose601x_const.te_short * 7) < + ws_protocol_emose601x_const.te_delta * 2)) { + instance->decoder.parser_step = EmosE601xDecoderStepCheckPreamble; + instance->decoder.te_last = duration; + } + break; + + case EmosE601xDecoderStepCheckPreamble: + if(level) { + instance->decoder.te_last = duration; + } else { + if((DURATION_DIFF(instance->decoder.te_last, ws_protocol_emose601x_const.te_short * 7) < + ws_protocol_emose601x_const.te_delta * 2) && + (DURATION_DIFF(duration, ws_protocol_emose601x_const.te_short) < + ws_protocol_emose601x_const.te_delta)) { + //Found preamble + instance->decoder.parser_step = EmosE601xDecoderStepSaveDuration; + instance->decoder.decode_data = 0; + instance->decoder.decode_count_bit = 0; + } else { + instance->decoder.parser_step = EmosE601xDecoderStepReset; + } + } + break; + + case EmosE601xDecoderStepSaveDuration: + if(level) { + instance->decoder.te_last = duration; + instance->decoder.parser_step = EmosE601xDecoderStepCheckDuration; + } else { + instance->decoder.parser_step = EmosE601xDecoderStepReset; + } + break; + + case EmosE601xDecoderStepCheckDuration: + if(!level) { + if((DURATION_DIFF(instance->decoder.te_last, ws_protocol_emose601x_const.te_short) < + ws_protocol_emose601x_const.te_delta) && + (DURATION_DIFF(duration, ws_protocol_emose601x_const.te_long) < + ws_protocol_emose601x_const.te_delta)) { + subghz_protocol_blocks_add_to_128_bit( + &instance->decoder, 0, &instance->upper_decode_data); + instance->decoder.parser_step = EmosE601xDecoderStepSaveDuration; + } else if( + (DURATION_DIFF(instance->decoder.te_last, ws_protocol_emose601x_const.te_long) < + ws_protocol_emose601x_const.te_delta) && + (DURATION_DIFF(duration, ws_protocol_emose601x_const.te_short) < + ws_protocol_emose601x_const.te_delta)) { + subghz_protocol_blocks_add_to_128_bit( + &instance->decoder, 1, &instance->upper_decode_data); + instance->decoder.parser_step = EmosE601xDecoderStepSaveDuration; + } else { + instance->decoder.parser_step = EmosE601xDecoderStepReset; + break; + } + + /* Bail out if the header doesn't match */ + if(instance->decoder.decode_count_bit == + ws_protocol_emose601x_const.min_count_bit_for_found) { + if(instance->decoder.decode_data != MAGIC_HEADER) { + instance->decoder.parser_step = EmosE601xDecoderStepReset; + break; + } + } + + if(instance->decoder.decode_count_bit == 120) { + instance->generic.data_count_bit = instance->decoder.decode_count_bit; + if(ws_protocol_emose601x_check(instance)) { + ws_protocol_emose601x_extract_data(instance); + if(instance->base.callback) + instance->base.callback(&instance->base, instance->base.context); + } + break; + } + } else { + instance->decoder.parser_step = EmosE601xDecoderStepReset; + } + break; + } +} + +uint32_t ws_protocol_decoder_emose601x_get_hash_data(void* context) { + furi_assert(context); + WSProtocolDecoderEmosE601x* instance = context; + return subghz_protocol_blocks_get_hash_data_long( + &instance->decoder, (instance->decoder.decode_count_bit / 8) + 1); +} + +SubGhzProtocolStatus ws_protocol_decoder_emose601x_serialize( + void* context, + FlipperFormat* flipper_format, + SubGhzRadioPreset* preset) { + furi_assert(context); + WSProtocolDecoderEmosE601x* instance = context; + return ws_block_generic_serialize(&instance->generic, flipper_format, preset); +} + +SubGhzProtocolStatus + ws_protocol_decoder_emose601x_deserialize(void* context, FlipperFormat* flipper_format) { + furi_assert(context); + WSProtocolDecoderEmosE601x* instance = context; + return ws_block_generic_deserialize_check_count_bit( + &instance->generic, flipper_format, ws_protocol_emose601x_const.min_count_bit_for_found); +} + +void ws_protocol_decoder_emose601x_get_string(void* context, FuriString* output) { + furi_assert(context); + WSProtocolDecoderEmosE601x* instance = context; + ws_block_generic_get_string(&instance->generic, output); +} diff --git a/lib/subghz/protocols/emos_e601x.h b/lib/subghz/protocols/emos_e601x.h new file mode 100644 index 000000000..b260cfacf --- /dev/null +++ b/lib/subghz/protocols/emos_e601x.h @@ -0,0 +1,80 @@ +#pragma once + +#include + +#include +#include +#include +#include "ws_generic.h" +#include + +#define WS_PROTOCOL_EMOSE601X_NAME "EMOS E601x" + +typedef struct WSProtocolDecoderEmosE601x WSProtocolDecoderEmosE601x; +typedef struct WSProtocolEncoderEmosE601x WSProtocolEncoderEmosE601x; + +extern const SubGhzProtocolDecoder ws_protocol_emose601x_decoder; +extern const SubGhzProtocolEncoder ws_protocol_emose601x_encoder; +extern const SubGhzProtocol ws_protocol_emose601x; + +/** + * Allocate WSProtocolDecoderEmosE601x. + * @param environment Pointer to a SubGhzEnvironment instance + * @return WSProtocolDecoderEmosE601x* pointer to a WSProtocolDecoderEmosE601x instance + */ +void* ws_protocol_decoder_emose601x_alloc(SubGhzEnvironment* environment); + +/** + * Free WSProtocolDecoderEmosE601x. + * @param context Pointer to a WSProtocolDecoderEmosE601x instance + */ +void ws_protocol_decoder_emose601x_free(void* context); + +/** + * Reset decoder WSProtocolDecoderEmosE601x. + * @param context Pointer to a WSProtocolDecoderEmosE601x instance + */ +void ws_protocol_decoder_emose601x_reset(void* context); + +/** + * Parse a raw sequence of levels and durations received from the air. + * @param context Pointer to a WSProtocolDecoderEmosE601x instance + * @param level Signal level true-high false-low + * @param duration Duration of this level in, us + */ +void ws_protocol_decoder_emose601x_feed(void* context, bool level, uint32_t duration); + +/** + * Getting the hash sum of the last randomly received parcel. + * @param context Pointer to a WSProtocolDecoderEmosE601x instance + * @return hash Hash sum + */ +uint32_t ws_protocol_decoder_emose601x_get_hash_data(void* context); + +/** + * Serialize data WSProtocolDecoderEmosE601x. + * @param context Pointer to a WSProtocolDecoderEmosE601x instance + * @param flipper_format Pointer to a FlipperFormat instance + * @param preset The modulation on which the signal was received, SubGhzRadioPreset + * @return status + */ +SubGhzProtocolStatus ws_protocol_decoder_emose601x_serialize( + void* context, + FlipperFormat* flipper_format, + SubGhzRadioPreset* preset); + +/** + * Deserialize data WSProtocolDecoderEmosE601x. + * @param context Pointer to a WSProtocolDecoderEmosE601x instance + * @param flipper_format Pointer to a FlipperFormat instance + * @return status + */ +SubGhzProtocolStatus + ws_protocol_decoder_emose601x_deserialize(void* context, FlipperFormat* flipper_format); + +/** + * Getting a textual representation of the received data. + * @param context Pointer to a WSProtocolDecoderEmosE601x instance + * @param output Resulting text + */ +void ws_protocol_decoder_emose601x_get_string(void* context, FuriString* output); diff --git a/lib/subghz/protocols/protocol_items.c b/lib/subghz/protocols/protocol_items.c index f7976aaef..8275071eb 100644 --- a/lib/subghz/protocols/protocol_items.c +++ b/lib/subghz/protocols/protocol_items.c @@ -63,6 +63,8 @@ const SubGhzProtocol* subghz_protocol_registry_items[] = { &ws_protocol_wendox_w6726, &ws_protocol_auriol_ahfl, &ws_protocol_kedsum_th, + &ws_protocol_emose601x, + &ws_protocol_acurite_5n1, &subghz_protocol_pocsag, &tpms_protocol_schrader_gg4, &subghz_protocol_bin_raw, diff --git a/lib/subghz/protocols/protocol_items.h b/lib/subghz/protocols/protocol_items.h index 403cdda1a..367025951 100644 --- a/lib/subghz/protocols/protocol_items.h +++ b/lib/subghz/protocols/protocol_items.h @@ -64,6 +64,8 @@ #include "wendox_w6726.h" #include "auriol_ahfl.h" #include "kedsum_th.h" +#include "emos_e601x.h" +#include "acurite_5n1.h" #include "pocsag.h" #include "schrader_gg4.h" #include "bin_raw.h"