Proto: bett

This commit is contained in:
HTotoo
2023-12-09 19:34:00 +01:00
parent 39fabab022
commit db4083f684
7 changed files with 115 additions and 9 deletions
+6 -1
View File
@@ -37,6 +37,9 @@ void SubGhzDRecentEntryDetailView::update_data() {
text_id.set("0x" + to_string_hex(entry_.serial)); text_id.set("0x" + to_string_hex(entry_.serial));
if (entry_.bits > 0) console.writeln("Bits: " + to_string_dec_uint(entry_.bits)); 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_.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) SubGhzDRecentEntryDetailView::SubGhzDRecentEntryDetailView(NavigationView& nav, const SubGhzDRecentEntry& entry)
@@ -101,7 +104,7 @@ void SubGhzDView::on_tick_second() {
} }
void SubGhzDView::on_data(const SubGhzDDataMessage* data) { 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()); auto matching_recent = find(recent, key.key());
if (matching_recent != std::end(recent)) { if (matching_recent != std::end(recent)) {
// Found within. Move to front of list, increment counter. // Found within. Move to front of list, increment counter.
@@ -127,6 +130,8 @@ const char* SubGhzDView::getSensorTypeName(FPROTO_SUBGHZD_SENSOR type) {
return "Ansonic"; return "Ansonic";
case FPS_PRINCETON: case FPS_PRINCETON:
return "Princeton"; return "Princeton";
case FPS_BETT:
return "Bett";
case FPS_Invalid: case FPS_Invalid:
default: default:
return "Unknown"; return "Unknown";
+7 -2
View File
@@ -46,17 +46,22 @@ struct SubGhzDRecentEntry {
uint16_t bits = 0; uint16_t bits = 0;
uint8_t btn = SD_NO_BTN; uint8_t btn = SD_NO_BTN;
uint16_t age = 0; // updated on each seconds, show how long the signal was last seen 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() {}
SubGhzDRecentEntry( SubGhzDRecentEntry(
uint8_t sensorType, uint8_t sensorType,
uint32_t serial, uint32_t serial,
uint16_t bits = 0, uint16_t bits = 0,
uint32_t data = 0,
uint32_t data_2 = 0,
uint8_t btn = SD_NO_BTN) uint8_t btn = SD_NO_BTN)
: sensorType{sensorType}, : sensorType{sensorType},
serial{serial}, serial{serial},
bits{bits}, bits{bits},
btn{btn} { btn{btn},
data{data},
data_2{data_2} {
} }
Key key() const { Key key() const {
return (static_cast<uint64_t>(serial) << 32) | return (static_cast<uint64_t>(serial) << 32) |
+85
View File
@@ -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
+6 -3
View File
@@ -26,6 +26,8 @@ class FProtoSubGhzDBase {
uint32_t getSensorSerial() { return serial; } uint32_t getSensorSerial() { return serial; }
uint16_t getBits() { return data_count_bit; } uint16_t getBits() { return data_count_bit; }
uint8_t getBtn() { return btn; } 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 uint8_t modulation = FPM_AM; // override this, if FM
protected: protected:
// Helper functions to keep it as compatible with flipper as we can, so adding new protos will be easy. // 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; uint32_t serial = SD_NO_SERIAL;
uint16_t data_count_bit = 0; uint16_t data_count_bit = 0;
uint32_t seed = SD_NO_SEED; 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. // inner logic stuff, also for flipper compatibility.
SubGhzDProtocolDecoderBaseRxCallback callback = NULL; SubGhzDProtocolDecoderBaseRxCallback callback = NULL;
uint16_t header_count = 0; uint16_t header_count = 0;
uint8_t parser_step = 0; uint8_t parser_step = 0;
uint32_t te_last = 0; uint32_t te_last = 0;
uint64_t data = 0;
uint64_t data_2 = 0;
uint64_t decode_data = 0; uint64_t decode_data = 0;
uint32_t decode_count_bit = 0; uint32_t decode_count_bit = 0;
uint8_t cnt_2 = 0; uint8_t cnt_2 = 0;
+3 -1
View File
@@ -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 "subghzdbase.hpp"
#include "s-ansonic.hpp" #include "s-ansonic.hpp"
#include "s-princeton.hpp" #include "s-princeton.hpp"
#include "s-bett.hpp"
#ifndef __FPROTO_PROTOLISTSGZ_H__ #ifndef __FPROTO_PROTOLISTSGZ_H__
#define __FPROTO_PROTOLISTSGZ_H__ #define __FPROTO_PROTOLISTSGZ_H__
@@ -22,6 +23,7 @@ class SubGhzDProtos : public FProtoListGeneral {
// add protos // add protos
protos.push_back(std::make_unique<FProtoSubGhzDAnsonic>()); // 1 protos.push_back(std::make_unique<FProtoSubGhzDAnsonic>()); // 1
protos.push_back(std::make_unique<FProtoSubGhzDPrinceton>()); // 2 protos.push_back(std::make_unique<FProtoSubGhzDPrinceton>()); // 2
protos.push_back(std::make_unique<FProtoSubGhzDBett>()); // 3
// set callback for them // set callback for them
for (const auto& obj : protos) { for (const auto& obj : protos) {
@@ -30,7 +32,7 @@ class SubGhzDProtos : public FProtoListGeneral {
} }
static void callbackTarget(FProtoSubGhzDBase* instance) { 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); shared_memory.application_queue.push(packet_message);
} }
+1 -1
View File
@@ -21,7 +21,7 @@ enum FPROTO_SUBGHZD_SENSOR {
FPS_Invalid = 0, FPS_Invalid = 0,
FPS_ANSONIC = 1, FPS_ANSONIC = 1,
FPS_PRINCETON = 2, FPS_PRINCETON = 2,
FPS_BETT = 3,
}; };
#endif #endif
+7 -1
View File
@@ -1283,17 +1283,23 @@ class SubGhzDDataMessage : public Message {
uint8_t sensorType = 0, uint8_t sensorType = 0,
uint32_t serial = 0xFFFFFFFF, uint32_t serial = 0xFFFFFFFF,
uint16_t bits = 0, uint16_t bits = 0,
uint32_t data = 0,
uint32_t data_2 = 0,
uint8_t btn = 0xFF) uint8_t btn = 0xFF)
: Message{ID::SubGhzDData}, : Message{ID::SubGhzDData},
sensorType{sensorType}, sensorType{sensorType},
serial{serial}, serial{serial},
bits{bits}, bits{bits},
btn{btn} { btn{btn},
data{data},
data_2{data_2} {
} }
uint8_t sensorType = 0; uint8_t sensorType = 0;
uint32_t serial = 0xFFFFFFFF; uint32_t serial = 0xFFFFFFFF;
uint16_t bits; uint16_t bits;
uint8_t btn = 0xFF; uint8_t btn = 0xFF;
uint32_t data = 0;
uint32_t data_2 = 0;
}; };
#endif /*__MESSAGE_H__*/ #endif /*__MESSAGE_H__*/