mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-04 20:21:01 -05:00
111 lines
4.0 KiB
C++
111 lines
4.0 KiB
C++
|
|
#ifndef __FPROTO_PRINCETON_H__
|
|
#define __FPROTO_PRINCETON_H__
|
|
|
|
#include "subghzdbase.hpp"
|
|
|
|
typedef enum {
|
|
PrincetonDecoderStepReset = 0,
|
|
PrincetonDecoderStepSaveDuration,
|
|
PrincetonDecoderStepCheckDuration,
|
|
} PrincetonDecoderStep;
|
|
|
|
class FProtoSubGhzDPrinceton : public FProtoSubGhzDBase {
|
|
public:
|
|
FProtoSubGhzDPrinceton() {
|
|
sensorType = FPS_PRINCETON;
|
|
}
|
|
|
|
void feed(bool level, uint32_t duration) {
|
|
switch (parser_step) {
|
|
case PrincetonDecoderStepReset:
|
|
if ((!level) && (DURATION_DIFF(duration, te_short * 36) < te_delta * 36)) {
|
|
// Found Preambula
|
|
parser_step = PrincetonDecoderStepSaveDuration;
|
|
decode_data = 0;
|
|
decode_count_bit = 0;
|
|
te = 0;
|
|
}
|
|
break;
|
|
case PrincetonDecoderStepSaveDuration:
|
|
// save duration
|
|
if (level) {
|
|
te_last = duration;
|
|
te += duration;
|
|
parser_step = PrincetonDecoderStepCheckDuration;
|
|
}
|
|
break;
|
|
case PrincetonDecoderStepCheckDuration:
|
|
if (!level) {
|
|
if (duration >= ((uint32_t)te_long * 2)) {
|
|
parser_step = PrincetonDecoderStepSaveDuration;
|
|
if (decode_count_bit ==
|
|
min_count_bit_for_found) {
|
|
if ((last_data == decode_data) &&
|
|
last_data) {
|
|
te /= (decode_count_bit * 4 + 1);
|
|
|
|
data = decode_data;
|
|
data_count_bit = decode_count_bit;
|
|
if (callback) callback(this);
|
|
}
|
|
last_data = decode_data;
|
|
}
|
|
decode_data = 0;
|
|
decode_count_bit = 0;
|
|
te = 0;
|
|
break;
|
|
}
|
|
|
|
te += duration;
|
|
|
|
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 = PrincetonDecoderStepSaveDuration;
|
|
} 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 = PrincetonDecoderStepSaveDuration;
|
|
} else {
|
|
parser_step = PrincetonDecoderStepReset;
|
|
}
|
|
} else {
|
|
parser_step = PrincetonDecoderStepReset;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
void subghz_protocol_princeton_check_remote_controller() {
|
|
serial = data >> 4;
|
|
btn = data & 0xF;
|
|
}
|
|
void get_string(std::string& output) {
|
|
subghz_protocol_princeton_check_remote_controller();
|
|
uint32_t data_rev = FProtoGeneral::subghz_protocol_blocks_reverse_key(data, data_count_bit);
|
|
|
|
/* output = to_string_dec_uint(data_count_bit) + " bit\r\n";
|
|
output += "Key: " + to_string_hex((uint32_t)(data & 0xFFFFFF)) + "\r\n";
|
|
output += "Yek: " + to_string_hex(data_rev) + "\r\n";
|
|
output += "SN: " + to_string_dec_uint(serial) + "\r\n";
|
|
output += "BTN: " + to_string_dec_uint(btn) + "\r\n";
|
|
output += "TE: " + to_string_dec_uint(te) + "\r\n"; */
|
|
}
|
|
|
|
protected:
|
|
uint32_t te_short = 390;
|
|
uint32_t te_long = 1170;
|
|
uint32_t te_delta = 300;
|
|
uint32_t min_count_bit_for_found = 24;
|
|
|
|
uint32_t te = 0;
|
|
uint32_t last_data = 0;
|
|
};
|
|
|
|
#endif
|