From db4083f684303dba5d21434f2c2748ce3e97f701 Mon Sep 17 00:00:00 2001 From: HTotoo Date: Sat, 9 Dec 2023 19:34:00 +0100 Subject: [PATCH] Proto: bett --- firmware/application/apps/ui_subghzd.cpp | 7 +- firmware/application/apps/ui_subghzd.hpp | 9 ++- firmware/baseband/fprotos/s-bett.hpp | 85 +++++++++++++++++++++ firmware/baseband/fprotos/subghzdbase.hpp | 9 ++- firmware/baseband/fprotos/subghzdprotos.hpp | 4 +- firmware/baseband/fprotos/subghztypes.hpp | 2 +- firmware/common/message.hpp | 8 +- 7 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 firmware/baseband/fprotos/s-bett.hpp diff --git a/firmware/application/apps/ui_subghzd.cpp b/firmware/application/apps/ui_subghzd.cpp index 138b8ce0c..6a61db84d 100644 --- a/firmware/application/apps/ui_subghzd.cpp +++ b/firmware/application/apps/ui_subghzd.cpp @@ -37,6 +37,9 @@ void SubGhzDRecentEntryDetailView::update_data() { text_id.set("0x" + to_string_hex(entry_.serial)); if (entry_.bits > 0) console.writeln("Bits: " + to_string_dec_uint(entry_.bits)); if (entry_.btn != SD_NO_BTN) console.writeln("Btn: " + to_string_dec_uint(entry_.btn)); + + if (entry_.data != 0) console.writeln("Data: " + to_string_dec_uint(entry_.data)); + if (entry_.data_2 != 0) console.writeln("Data2: " + to_string_dec_uint(entry_.data_2)); } SubGhzDRecentEntryDetailView::SubGhzDRecentEntryDetailView(NavigationView& nav, const SubGhzDRecentEntry& entry) @@ -101,7 +104,7 @@ void SubGhzDView::on_tick_second() { } void SubGhzDView::on_data(const SubGhzDDataMessage* data) { - SubGhzDRecentEntry key{data->sensorType, data->serial, data->bits, data->btn}; + SubGhzDRecentEntry key{data->sensorType, data->serial, data->bits, data->data, data->data_2, data->btn}; auto matching_recent = find(recent, key.key()); if (matching_recent != std::end(recent)) { // Found within. Move to front of list, increment counter. @@ -127,6 +130,8 @@ const char* SubGhzDView::getSensorTypeName(FPROTO_SUBGHZD_SENSOR type) { return "Ansonic"; case FPS_PRINCETON: return "Princeton"; + case FPS_BETT: + return "Bett"; case FPS_Invalid: default: return "Unknown"; diff --git a/firmware/application/apps/ui_subghzd.hpp b/firmware/application/apps/ui_subghzd.hpp index 15363fd6b..4ff73b1e3 100644 --- a/firmware/application/apps/ui_subghzd.hpp +++ b/firmware/application/apps/ui_subghzd.hpp @@ -46,17 +46,22 @@ struct SubGhzDRecentEntry { uint16_t bits = 0; uint8_t btn = SD_NO_BTN; uint16_t age = 0; // updated on each seconds, show how long the signal was last seen - + uint32_t data = 0; + uint32_t data_2 = 0; SubGhzDRecentEntry() {} SubGhzDRecentEntry( uint8_t sensorType, uint32_t serial, uint16_t bits = 0, + uint32_t data = 0, + uint32_t data_2 = 0, uint8_t btn = SD_NO_BTN) : sensorType{sensorType}, serial{serial}, bits{bits}, - btn{btn} { + btn{btn}, + data{data}, + data_2{data_2} { } Key key() const { return (static_cast(serial) << 32) | diff --git a/firmware/baseband/fprotos/s-bett.hpp b/firmware/baseband/fprotos/s-bett.hpp new file mode 100644 index 000000000..f0fea86fe --- /dev/null +++ b/firmware/baseband/fprotos/s-bett.hpp @@ -0,0 +1,85 @@ + +#ifndef __FPROTO_BETT_H__ +#define __FPROTO_BETT_H__ + +#include "subghzdbase.hpp" + +typedef enum { + BETTDecoderStepReset = 0, + BETTDecoderStepSaveDuration, + BETTDecoderStepCheckDuration, +} BETTDecoderStep; + +class FProtoSubGhzDBett : public FProtoSubGhzDBase { + public: + FProtoSubGhzDBett() { + sensorType = FPS_BETT; + } + + void feed(bool level, uint32_t duration) { + switch (parser_step) { + case BETTDecoderStepReset: + if ((!level) && (DURATION_DIFF(duration, te_short * 44) < + (te_delta * 15))) { + decode_data = 0; + decode_count_bit = 0; + parser_step = BETTDecoderStepCheckDuration; + } + break; + case BETTDecoderStepSaveDuration: + if (!level) { + if (DURATION_DIFF(duration, te_short * 44) < + (te_delta * 15)) { + if (decode_count_bit == + min_count_bit_for_found) { + data = decode_data; + data_count_bit = decode_count_bit; + // dip decoder needed + if (callback) callback(this); + } else { + parser_step = BETTDecoderStepReset; + } + decode_data = 0; + decode_count_bit = 0; + break; + } else { + if ((DURATION_DIFF(duration, te_short) < + te_delta) || + (DURATION_DIFF(duration, te_long) < + te_delta * 3)) { + parser_step = BETTDecoderStepCheckDuration; + } else { + parser_step = BETTDecoderStepReset; + } + } + } + break; + case BETTDecoderStepCheckDuration: + if (level) { + if (DURATION_DIFF(duration, te_long) < + te_delta * 3) { + subghz_protocol_blocks_add_bit(1); + parser_step = BETTDecoderStepSaveDuration; + } else if ( + DURATION_DIFF(duration, te_short) < + te_delta) { + subghz_protocol_blocks_add_bit(0); + parser_step = BETTDecoderStepSaveDuration; + } else { + parser_step = BETTDecoderStepReset; + } + } else { + parser_step = BETTDecoderStepReset; + } + break; + } + } + + protected: + uint32_t te_short = 340; + uint32_t te_long = 2000; + uint32_t te_delta = 150; + uint32_t min_count_bit_for_found = 18; +}; + +#endif diff --git a/firmware/baseband/fprotos/subghzdbase.hpp b/firmware/baseband/fprotos/subghzdbase.hpp index 38565282c..54c79aa90 100644 --- a/firmware/baseband/fprotos/subghzdbase.hpp +++ b/firmware/baseband/fprotos/subghzdbase.hpp @@ -26,6 +26,8 @@ class FProtoSubGhzDBase { uint32_t getSensorSerial() { return serial; } uint16_t getBits() { return data_count_bit; } uint8_t getBtn() { return btn; } + uint32_t getData() { return data; } + uint32_t getData2() { return data_2; } uint8_t modulation = FPM_AM; // override this, if FM protected: // Helper functions to keep it as compatible with flipper as we can, so adding new protos will be easy. @@ -42,15 +44,16 @@ class FProtoSubGhzDBase { uint32_t serial = SD_NO_SERIAL; uint16_t data_count_bit = 0; uint32_t seed = SD_NO_SEED; - // princeton TE + uint64_t data = 0; + uint64_t data_2 = 0; + // princeton TE?! //todo // inner logic stuff, also for flipper compatibility. SubGhzDProtocolDecoderBaseRxCallback callback = NULL; uint16_t header_count = 0; uint8_t parser_step = 0; uint32_t te_last = 0; - uint64_t data = 0; - uint64_t data_2 = 0; + uint64_t decode_data = 0; uint32_t decode_count_bit = 0; uint8_t cnt_2 = 0; diff --git a/firmware/baseband/fprotos/subghzdprotos.hpp b/firmware/baseband/fprotos/subghzdprotos.hpp index 3796d651e..15893fc6d 100644 --- a/firmware/baseband/fprotos/subghzdprotos.hpp +++ b/firmware/baseband/fprotos/subghzdprotos.hpp @@ -12,6 +12,7 @@ So include here the .hpp, and add a new element to the protos vector in the cons #include "subghzdbase.hpp" #include "s-ansonic.hpp" #include "s-princeton.hpp" +#include "s-bett.hpp" #ifndef __FPROTO_PROTOLISTSGZ_H__ #define __FPROTO_PROTOLISTSGZ_H__ @@ -22,6 +23,7 @@ class SubGhzDProtos : public FProtoListGeneral { // add protos protos.push_back(std::make_unique()); // 1 protos.push_back(std::make_unique()); // 2 + protos.push_back(std::make_unique()); // 3 // set callback for them for (const auto& obj : protos) { @@ -30,7 +32,7 @@ class SubGhzDProtos : public FProtoListGeneral { } static void callbackTarget(FProtoSubGhzDBase* instance) { - SubGhzDDataMessage packet_message{instance->getSensorType(), instance->getSensorSerial(), instance->getBits(), instance->getBtn()}; + SubGhzDDataMessage packet_message{instance->getSensorType(), instance->getSensorSerial(), instance->getBits(), instance->getData(), instance->getData2(), instance->getBtn()}; shared_memory.application_queue.push(packet_message); } diff --git a/firmware/baseband/fprotos/subghztypes.hpp b/firmware/baseband/fprotos/subghztypes.hpp index 59b145e12..c4dea4dc9 100644 --- a/firmware/baseband/fprotos/subghztypes.hpp +++ b/firmware/baseband/fprotos/subghztypes.hpp @@ -21,7 +21,7 @@ enum FPROTO_SUBGHZD_SENSOR { FPS_Invalid = 0, FPS_ANSONIC = 1, FPS_PRINCETON = 2, - + FPS_BETT = 3, }; #endif \ No newline at end of file diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index ffe8e816b..590169b0c 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -1283,17 +1283,23 @@ class SubGhzDDataMessage : public Message { uint8_t sensorType = 0, uint32_t serial = 0xFFFFFFFF, uint16_t bits = 0, + uint32_t data = 0, + uint32_t data_2 = 0, uint8_t btn = 0xFF) : Message{ID::SubGhzDData}, sensorType{sensorType}, serial{serial}, bits{bits}, - btn{btn} { + btn{btn}, + data{data}, + data_2{data_2} { } uint8_t sensorType = 0; uint32_t serial = 0xFFFFFFFF; uint16_t bits; uint8_t btn = 0xFF; + uint32_t data = 0; + uint32_t data_2 = 0; }; #endif /*__MESSAGE_H__*/