From 3a68afe5116140dc6c872feabc4584163fac7ae4 Mon Sep 17 00:00:00 2001 From: HTotoo Date: Sun, 10 Dec 2023 15:02:15 +0100 Subject: [PATCH] More protos --- firmware/application/apps/ui_subghzd.cpp | 4 + firmware/baseband/fprotos/s-faac.hpp | 87 ++++++++++++++++ firmware/baseband/fprotos/s-gate_tx.hpp | 90 ++++++++++++++++ firmware/baseband/fprotos/s-holtek.hpp | 109 ++++++++++++++++++++ firmware/baseband/fprotos/subghzdprotos.hpp | 8 +- firmware/baseband/fprotos/subghztypes.hpp | 3 + 6 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 firmware/baseband/fprotos/s-faac.hpp create mode 100644 firmware/baseband/fprotos/s-gate_tx.hpp create mode 100644 firmware/baseband/fprotos/s-holtek.hpp diff --git a/firmware/application/apps/ui_subghzd.cpp b/firmware/application/apps/ui_subghzd.cpp index 9211bfdc1..598d092a7 100644 --- a/firmware/application/apps/ui_subghzd.cpp +++ b/firmware/application/apps/ui_subghzd.cpp @@ -150,6 +150,10 @@ const char* SubGhzDView::getSensorTypeName(FPROTO_SUBGHZD_SENSOR type) { return "Doitrand"; case FPS_DOOYA: return "Dooya"; + case FPS_FAAC: + return "Faac"; + case FPS_GATETX: + return "Gate TX"; case FPS_Invalid: default: return "Unknown"; diff --git a/firmware/baseband/fprotos/s-faac.hpp b/firmware/baseband/fprotos/s-faac.hpp new file mode 100644 index 000000000..e834c8786 --- /dev/null +++ b/firmware/baseband/fprotos/s-faac.hpp @@ -0,0 +1,87 @@ + +#ifndef __FPROTO_FAAC_H__ +#define __FPROTO_FAAC_H__ + +#include "subghzdbase.hpp" + +typedef enum { + FaacSLHDecoderStepReset = 0, + FaacSLHDecoderStepFoundPreambula, + FaacSLHDecoderStepSaveDuration, + FaacSLHDecoderStepCheckDuration, +} FaacSLHDecoderStep; + +class FProtoSubGhzDCFaac : public FProtoSubGhzDBase { + public: + FProtoSubGhzDCFaac() { + sensorType = FPS_FAAC; + } + + void feed(bool level, uint32_t duration) { + switch (parser_step) { + case FaacSLHDecoderStepReset: + if ((level) && (DURATION_DIFF(duration, te_long * 2) < te_delta * 3)) { + parser_step = FaacSLHDecoderStepFoundPreambula; + } + break; + case FaacSLHDecoderStepFoundPreambula: + if ((!level) && (DURATION_DIFF(duration, te_long * 2) < te_delta * 3)) { + // Found Preambula + parser_step = FaacSLHDecoderStepSaveDuration; + decode_data = 0; + decode_count_bit = 0; + } else { + parser_step = FaacSLHDecoderStepReset; + } + break; + case FaacSLHDecoderStepSaveDuration: + if (level) { + if (duration >= ((uint32_t)te_short * 3 + te_delta)) { + parser_step = FaacSLHDecoderStepFoundPreambula; + if (decode_count_bit == min_count_bit_for_found) { + data = decode_data; + data_count_bit = decode_count_bit; + // remark controller skipped + if (callback) callback(this); + } + decode_data = 0; + decode_count_bit = 0; + break; + } else { + te_last = duration; + parser_step = FaacSLHDecoderStepCheckDuration; + } + + } else { + parser_step = FaacSLHDecoderStepReset; + } + break; + case FaacSLHDecoderStepCheckDuration: + if (!level) { + if ((DURATION_DIFF(te_last, te_short) < te_delta) && + (DURATION_DIFF(duration, te_long) < te_delta)) { + subghz_protocol_blocks_add_bit(0); + parser_step = FaacSLHDecoderStepSaveDuration; + } else if ( + (DURATION_DIFF(te_last, te_long) < te_delta) && + (DURATION_DIFF(duration, te_short) < te_delta)) { + subghz_protocol_blocks_add_bit(1); + parser_step = FaacSLHDecoderStepSaveDuration; + } else { + parser_step = FaacSLHDecoderStepReset; + } + } else { + parser_step = FaacSLHDecoderStepReset; + } + break; + } + } + + protected: + uint32_t te_short = 255; + uint32_t te_long = 595; + uint32_t te_delta = 100; + uint32_t min_count_bit_for_found = 64; +}; + +#endif diff --git a/firmware/baseband/fprotos/s-gate_tx.hpp b/firmware/baseband/fprotos/s-gate_tx.hpp new file mode 100644 index 000000000..2d5f89938 --- /dev/null +++ b/firmware/baseband/fprotos/s-gate_tx.hpp @@ -0,0 +1,90 @@ + +#ifndef __FPROTO_GATETX_H__ +#define __FPROTO_GATETX_H__ + +#include "subghzdbase.hpp" + +typedef enum { + GateTXDecoderStepReset = 0, + GateTXDecoderStepFoundStartBit, + GateTXDecoderStepSaveDuration, + GateTXDecoderStepCheckDuration, +} GateTXDecoderStep; + +class FProtoSubGhzDCGateTx : public FProtoSubGhzDBase { + public: + FProtoSubGhzDCGateTx() { + sensorType = FPS_GATETX; + } + + void feed(bool level, uint32_t duration) { + switch (parser_step) { + case GateTXDecoderStepReset: + if ((!level) && (DURATION_DIFF(duration, te_short * 47) < te_delta * 47)) { + // Found Preambula + parser_step = GateTXDecoderStepFoundStartBit; + } + break; + case GateTXDecoderStepFoundStartBit: + if (level && ((DURATION_DIFF(duration, te_long) < te_delta * 3))) { + // Found start bit + parser_step = GateTXDecoderStepSaveDuration; + decode_data = 0; + decode_count_bit = 0; + } else { + parser_step = GateTXDecoderStepReset; + } + break; + case GateTXDecoderStepSaveDuration: + if (!level) { + if (duration >= ((uint32_t)te_short * 10 + te_delta)) { + parser_step = GateTXDecoderStepFoundStartBit; + if (decode_count_bit == min_count_bit_for_found) { + data = decode_data; + data_count_bit = decode_count_bit; + + // controller + uint32_t code_found_reverse = FProtoGeneral::subghz_protocol_blocks_reverse_key(data, data_count_bit); + serial = (code_found_reverse & 0xFF) << 12 | ((code_found_reverse >> 8) & 0xFF) << 4 | ((code_found_reverse >> 20) & 0x0F); + btn = ((code_found_reverse >> 16) & 0x0F); + + if (callback) callback(this); + } + decode_data = 0; + decode_count_bit = 0; + break; + } else { + te_last = duration; + parser_step = GateTXDecoderStepCheckDuration; + } + } + break; + case GateTXDecoderStepCheckDuration: + if (level) { + if ((DURATION_DIFF(te_last, te_short) < te_delta) && + (DURATION_DIFF(duration, te_long) < te_delta * 3)) { + subghz_protocol_blocks_add_bit(0); + parser_step = GateTXDecoderStepSaveDuration; + } else if ( + (DURATION_DIFF(te_last, te_long) < te_delta * 3) && + (DURATION_DIFF(duration, te_short) < te_delta)) { + subghz_protocol_blocks_add_bit(1); + parser_step = GateTXDecoderStepSaveDuration; + } else { + parser_step = GateTXDecoderStepReset; + } + } else { + parser_step = GateTXDecoderStepReset; + } + break; + } + } + + protected: + uint32_t te_short = 350; + uint32_t te_long = 700; + uint32_t te_delta = 100; + uint32_t min_count_bit_for_found = 24; +}; + +#endif diff --git a/firmware/baseband/fprotos/s-holtek.hpp b/firmware/baseband/fprotos/s-holtek.hpp new file mode 100644 index 000000000..e6b9f2b6e --- /dev/null +++ b/firmware/baseband/fprotos/s-holtek.hpp @@ -0,0 +1,109 @@ + +#ifndef __FPROTO_HOLTEK_H__ +#define __FPROTO_HOLTEK_H__ + +#include "subghzdbase.hpp" + +#define HOLTEK_HEADER_MASK 0xF000000000 +#define HOLTEK_HEADER 0x5000000000 + +typedef enum { + HoltekDecoderStepReset = 0, + HoltekDecoderStepFoundStartBit, + HoltekDecoderStepSaveDuration, + HoltekDecoderStepCheckDuration, +} HoltekDecoderStep; + +class FProtoSubGhzDCHoltek : public FProtoSubGhzDBase { + public: + FProtoSubGhzDCHoltek() { + sensorType = FPS_HOLTEK; + } + + void feed(bool level, uint32_t duration) { + switch (parser_step) { + case HoltekDecoderStepReset: + if ((!level) && (DURATION_DIFF(duration, te_short * 36) < te_delta * 36)) { + // Found Preambula + parser_step = HoltekDecoderStepFoundStartBit; + } + break; + case HoltekDecoderStepFoundStartBit: + if ((level) && (DURATION_DIFF(duration, te_short) < te_delta)) { + // Found StartBit + parser_step = HoltekDecoderStepSaveDuration; + decode_data = 0; + decode_count_bit = 0; + } else { + parser_step = HoltekDecoderStepReset; + } + break; + case HoltekDecoderStepSaveDuration: + // save duration + if (!level) { + if (duration >= ((uint32_t)te_short * 10 + te_delta)) { + if (decode_count_bit == + min_count_bit_for_found) { + if ((decode_data & HOLTEK_HEADER_MASK) == HOLTEK_HEADER) { + data = decode_data; + data_count_bit = decode_count_bit; + + // controller + serial = FProtoGeneral::subghz_protocol_blocks_reverse_key((data >> 16) & 0xFFFFF, 20); + uint16_t btn = data & 0xFFFF; + if ((btn & 0xf) != 0xA) { + btn = 0x1 << 4 | (btn & 0xF); + } else if (((btn >> 4) & 0xF) != 0xA) { + btn = 0x2 << 4 | ((btn >> 4) & 0xF); + } else if (((btn >> 8) & 0xF) != 0xA) { + btn = 0x3 << 4 | ((btn >> 8) & 0xF); + } else if (((btn >> 12) & 0xF) != 0xA) { + btn = 0x4 << 4 | ((btn >> 12) & 0xF); + } else { + btn = 0; + } + + if (callback) callback(this); + } + } + decode_data = 0; + decode_count_bit = 0; + parser_step = HoltekDecoderStepFoundStartBit; + break; + } else { + te_last = duration; + parser_step = HoltekDecoderStepCheckDuration; + } + } else { + parser_step = HoltekDecoderStepReset; + } + break; + case HoltekDecoderStepCheckDuration: + if (level) { + if ((DURATION_DIFF(te_last, te_short) < te_delta) && + (DURATION_DIFF(duration, te_long) < te_delta * 2)) { + subghz_protocol_blocks_add_bit(0); + parser_step = HoltekDecoderStepSaveDuration; + } else if ( + (DURATION_DIFF(te_last, te_long) < te_delta * 2) && + (DURATION_DIFF(duration, te_short) < te_delta)) { + subghz_protocol_blocks_add_bit(1); + parser_step = HoltekDecoderStepSaveDuration; + } else { + parser_step = HoltekDecoderStepReset; + } + } else { + parser_step = HoltekDecoderStepReset; + } + break; + } + } + + protected: + uint32_t te_short = 430; + uint32_t te_long = 870; + uint32_t te_delta = 100; + uint32_t min_count_bit_for_found = 40; +}; + +#endif diff --git a/firmware/baseband/fprotos/subghzdprotos.hpp b/firmware/baseband/fprotos/subghzdprotos.hpp index 8ca621cad..9b2505ae8 100644 --- a/firmware/baseband/fprotos/subghzdprotos.hpp +++ b/firmware/baseband/fprotos/subghzdprotos.hpp @@ -20,6 +20,9 @@ So include here the .hpp, and add a new element to the protos vector in the cons #include "s-clemsa.hpp" #include "s-doitrand.hpp" #include "s-dooya.hpp" +#include "s-faac.hpp" +#include "s-gate_tx.hpp" +#include "s-holtek.hpp" #ifndef __FPROTO_PROTOLISTSGZ_H__ #define __FPROTO_PROTOLISTSGZ_H__ @@ -37,7 +40,10 @@ class SubGhzDProtos : public FProtoListGeneral { protos.push_back(std::make_unique()); // 9 protos.push_back(std::make_unique()); // 10 protos.push_back(std::make_unique()); // 11 - protos.push_back(std::make_unique()); // 11 + protos.push_back(std::make_unique()); // 12 + protos.push_back(std::make_unique()); // 13 + protos.push_back(std::make_unique()); // 14 + protos.push_back(std::make_unique()); // 15 // set callback for them for (const auto& obj : protos) { diff --git a/firmware/baseband/fprotos/subghztypes.hpp b/firmware/baseband/fprotos/subghztypes.hpp index 96a28557e..180b459b1 100644 --- a/firmware/baseband/fprotos/subghztypes.hpp +++ b/firmware/baseband/fprotos/subghztypes.hpp @@ -31,6 +31,9 @@ enum FPROTO_SUBGHZD_SENSOR { FPS_CLEMSA = 10, FPS_DOITRAND = 11, FPS_DOOYA = 12, + FPS_FAAC = 13, + FPS_GATETX = 14, + FPS_HOLTEK = 15, }; #endif