[FL-1912, FL-1939] Sub-GHz frequency analyzer and add new protocol (#746)
* 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>
This commit is contained in:
34
lib/toolbox/manchester-decoder.c
Normal file
34
lib/toolbox/manchester-decoder.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "manchester-decoder.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t transitions[] = {0b00000001, 0b10010001, 0b10011011, 0b11111011};
|
||||
static const ManchesterState manchester_reset_state = ManchesterStateMid1;
|
||||
|
||||
bool manchester_advance(
|
||||
ManchesterState state,
|
||||
ManchesterEvent event,
|
||||
ManchesterState* next_state,
|
||||
bool* data) {
|
||||
bool result = false;
|
||||
ManchesterState new_state;
|
||||
|
||||
if(event == ManchesterEventReset) {
|
||||
new_state = manchester_reset_state;
|
||||
} else {
|
||||
new_state = transitions[state] >> event & 0x3;
|
||||
if(new_state == state) {
|
||||
new_state = manchester_reset_state;
|
||||
} else {
|
||||
if(new_state == ManchesterStateMid0) {
|
||||
*data = false;
|
||||
result = true;
|
||||
} else if(new_state == ManchesterStateMid1) {
|
||||
*data = true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*next_state = new_state;
|
||||
return result;
|
||||
}
|
33
lib/toolbox/manchester-decoder.h
Normal file
33
lib/toolbox/manchester-decoder.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ManchesterEventShortLow = 0,
|
||||
ManchesterEventShortHigh = 2,
|
||||
ManchesterEventLongLow = 4,
|
||||
ManchesterEventLongHigh = 6,
|
||||
ManchesterEventReset = 8
|
||||
} ManchesterEvent;
|
||||
|
||||
typedef enum {
|
||||
ManchesterStateStart1 = 0,
|
||||
ManchesterStateMid1 = 1,
|
||||
ManchesterStateMid0 = 2,
|
||||
ManchesterStateStart0 = 3
|
||||
} ManchesterState;
|
||||
|
||||
|
||||
|
||||
bool manchester_advance(
|
||||
ManchesterState state,
|
||||
ManchesterEvent event,
|
||||
ManchesterState* next_state,
|
||||
bool* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
54
lib/toolbox/manchester-encoder.c
Normal file
54
lib/toolbox/manchester-encoder.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#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;
|
||||
}
|
32
lib/toolbox/manchester-encoder.h
Normal file
32
lib/toolbox/manchester-encoder.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
bool prev_bit;
|
||||
uint8_t step;
|
||||
} ManchesterEncoderState;
|
||||
|
||||
typedef enum {
|
||||
ManchesterEncoderResultShortLow = 0b00,
|
||||
ManchesterEncoderResultLongLow = 0b01,
|
||||
ManchesterEncoderResultLongHigh = 0b10,
|
||||
ManchesterEncoderResultShortHigh = 0b11,
|
||||
} ManchesterEncoderResult;
|
||||
|
||||
void manchester_encoder_reset(ManchesterEncoderState* state);
|
||||
|
||||
bool manchester_encoder_advance(
|
||||
ManchesterEncoderState* state,
|
||||
const bool curr_bit,
|
||||
ManchesterEncoderResult* result);
|
||||
|
||||
ManchesterEncoderResult manchester_encoder_finish(ManchesterEncoderState* state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user