mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-14 17:35:34 -04:00
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f5
.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
This commit is contained in:
parent
02810bf527
commit
2ccda5aebd
71 changed files with 4952 additions and 248 deletions
139
firmware/baseband/fprotos/s-magellan.hpp
Normal file
139
firmware/baseband/fprotos/s-magellan.hpp
Normal file
|
@ -0,0 +1,139 @@
|
|||
|
||||
#ifndef __FPROTO_MAGELLAN_H__
|
||||
#define __FPROTO_MAGELLAN_H__
|
||||
|
||||
#include "subghzdbase.hpp"
|
||||
|
||||
typedef enum : uint8_t {
|
||||
MagellanDecoderStepReset = 0,
|
||||
MagellanDecoderStepCheckPreambula,
|
||||
MagellanDecoderStepFoundPreambula,
|
||||
MagellanDecoderStepSaveDuration,
|
||||
MagellanDecoderStepCheckDuration,
|
||||
} MagellanDecoderStep;
|
||||
|
||||
class FProtoSubGhzDMagellan : public FProtoSubGhzDBase {
|
||||
public:
|
||||
FProtoSubGhzDMagellan() {
|
||||
sensorType = FPS_MAGELLAN;
|
||||
te_short = 200;
|
||||
te_long = 400;
|
||||
te_delta = 100;
|
||||
min_count_bit_for_found = 32;
|
||||
}
|
||||
|
||||
void feed(bool level, uint32_t duration) {
|
||||
switch (parser_step) {
|
||||
case MagellanDecoderStepReset:
|
||||
if ((level) && (DURATION_DIFF(duration, te_short) < te_delta)) {
|
||||
parser_step = MagellanDecoderStepCheckPreambula;
|
||||
te_last = duration;
|
||||
header_count = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case MagellanDecoderStepCheckPreambula:
|
||||
if (level) {
|
||||
te_last = duration;
|
||||
} else {
|
||||
if ((DURATION_DIFF(te_last, te_short) < te_delta) &&
|
||||
(DURATION_DIFF(duration, te_short) < te_delta)) {
|
||||
// Found header
|
||||
header_count++;
|
||||
} else if (
|
||||
(DURATION_DIFF(te_last, te_short) < te_delta) &&
|
||||
(DURATION_DIFF(duration, te_long) < te_delta * 2) &&
|
||||
(header_count > 10)) {
|
||||
parser_step = MagellanDecoderStepFoundPreambula;
|
||||
} else {
|
||||
parser_step = MagellanDecoderStepReset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MagellanDecoderStepFoundPreambula:
|
||||
if (level) {
|
||||
te_last = duration;
|
||||
} else {
|
||||
if ((DURATION_DIFF(te_last, te_short * 6) < te_delta * 3) &&
|
||||
(DURATION_DIFF(duration, te_long) < te_delta * 2)) {
|
||||
parser_step = MagellanDecoderStepSaveDuration;
|
||||
decode_data = 0;
|
||||
decode_count_bit = 0;
|
||||
} else {
|
||||
parser_step = MagellanDecoderStepReset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MagellanDecoderStepSaveDuration:
|
||||
if (level) {
|
||||
te_last = duration;
|
||||
parser_step = MagellanDecoderStepCheckDuration;
|
||||
} else {
|
||||
parser_step = MagellanDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case MagellanDecoderStepCheckDuration:
|
||||
if (!level) {
|
||||
if ((DURATION_DIFF(te_last, te_short) < te_delta) &&
|
||||
(DURATION_DIFF(duration, te_long) < te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(1);
|
||||
parser_step = MagellanDecoderStepSaveDuration;
|
||||
} else if (
|
||||
(DURATION_DIFF(te_last, te_long) < te_delta) &&
|
||||
(DURATION_DIFF(duration, te_short) < te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(0);
|
||||
parser_step = MagellanDecoderStepSaveDuration;
|
||||
} else if (duration >= (te_long * 3)) {
|
||||
// Found stop bit
|
||||
if ((decode_count_bit == min_count_bit_for_found) &&
|
||||
subghz_protocol_magellan_check_crc()) {
|
||||
data = decode_data;
|
||||
data_count_bit = decode_count_bit;
|
||||
|
||||
// controller
|
||||
uint64_t data_rev = FProtoGeneral::subghz_protocol_blocks_reverse_key(data >> 8, 24);
|
||||
serial = data_rev & 0xFFFF;
|
||||
btn = (data_rev >> 16) & 0xFF;
|
||||
if (callback) callback(this);
|
||||
}
|
||||
decode_data = 0;
|
||||
decode_count_bit = 0;
|
||||
parser_step = MagellanDecoderStepReset;
|
||||
} else {
|
||||
parser_step = MagellanDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
parser_step = MagellanDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool subghz_protocol_magellan_check_crc() {
|
||||
uint8_t data[3] = {
|
||||
(uint8_t)(decode_data >> 24),
|
||||
(uint8_t)(decode_data >> 16),
|
||||
(uint8_t)(decode_data >> 8)};
|
||||
return (decode_data & 0xFF) == subghz_protocol_magellan_crc8(data, sizeof(data));
|
||||
}
|
||||
uint8_t subghz_protocol_magellan_crc8(uint8_t* data, size_t len) {
|
||||
uint8_t crc = 0x00;
|
||||
uint8_t i, j;
|
||||
for (i = 0; i < len; i++) {
|
||||
crc ^= data[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
if ((crc & 0x80) != 0)
|
||||
crc = (uint8_t)((crc << 1) ^ 0x31);
|
||||
else
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue