mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-30 08:44:34 +03:00
4418e73b26
* ToolBox: add manchester-decoder and manchester-encoder * SubGhz: add new FM config cc1101 * Subghz: add protocol Kia * SubGhz: fix receiving the last packet Nero Radio * SubGhz: app protocol CAME Twin (TW2EE/TW4EE) * SubGhz: add protocol CAME Atomo (AT03EV/ AT04EV) * F7: sync with F6 * SubGhz: add frequency analyzer * SubGhz: remove space from file name * SubGhz: frequency analyzer add filter and fix view * [FL-1939] GubGhz: Frequency analyzer redesign * SubGhz: fix incorrect subghz api call sequence in frequency analyzer worker Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
54 lines
1.4 KiB
C
54 lines
1.4 KiB
C
#include "manchester-encoder.h"
|
|
#include <stdio.h>
|
|
|
|
void manchester_encoder_reset(ManchesterEncoderState* state) {
|
|
state->step = 0;
|
|
}
|
|
|
|
bool manchester_encoder_advance(
|
|
ManchesterEncoderState* state,
|
|
const bool curr_bit,
|
|
ManchesterEncoderResult* result) {
|
|
bool advance = false;
|
|
switch(state->step) {
|
|
case 0:
|
|
state->prev_bit = curr_bit;
|
|
if(state->prev_bit) {
|
|
*result = ManchesterEncoderResultShortLow;
|
|
} else {
|
|
*result = ManchesterEncoderResultShortHigh;
|
|
}
|
|
state->step = 1;
|
|
advance = true;
|
|
break;
|
|
case 1:
|
|
*result = (state->prev_bit << 1) + curr_bit;
|
|
if(curr_bit == state->prev_bit) {
|
|
state->step = 2;
|
|
} else {
|
|
state->prev_bit = curr_bit;
|
|
advance = true;
|
|
}
|
|
break;
|
|
case 2:
|
|
if(curr_bit) {
|
|
*result = ManchesterEncoderResultShortLow;
|
|
} else {
|
|
*result = ManchesterEncoderResultShortHigh;
|
|
}
|
|
state->prev_bit = curr_bit;
|
|
state->step = 1;
|
|
advance = true;
|
|
break;
|
|
default:
|
|
printf("DO CRASH HERE\r\n");
|
|
// furi_crash
|
|
break;
|
|
}
|
|
return advance;
|
|
}
|
|
|
|
ManchesterEncoderResult manchester_encoder_finish(ManchesterEncoderState* state) {
|
|
state->step = 0;
|
|
return (state->prev_bit << 1) + state->prev_bit;
|
|
} |