src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
11 / 11
100.0%
Branches:
-
-%
Functions:
1 / 1
100.0%

PulseDecoder.h
Line Branch Exec Source
1 #ifndef PULSE_DECODER_H
2 #define PULSE_DECODER_H
3 #include <stdint.h>
4 #include <string.h>
5
6 // Turns the time between edges of a received RTS transmission into frame
7 // bits. Runs in the receive interrupt, so it stays in IRAM on the ESP32, and
8 // is kept free of the radio so it can be unit tested on the PC
9 // (pio test -e native).
10
11 // Half an RTS bit in us. A bit is two symbols with an edge in the middle.
12 #define SYMBOL 640
13
14 #define MAX_TIMINGS 300
15
16 typedef enum {
17 waiting_synchro = 0,
18 receiving_data = 1,
19 complete = 2
20 } t_status;
21
22 struct somfy_rx_t {
23 8 void clear() {
24 8 this->status = t_status::waiting_synchro;
25 8 this->bit_length = 56;
26 8 this->cpt_synchro_hw = 0;
27 8 this->cpt_bits = 0;
28 8 this->previous_bit = 0;
29 8 this->waiting_half_symbol = false;
30 8 memset(this->payload, 0, sizeof(this->payload));
31 8 memset(this->pulses, 0, sizeof(this->pulses));
32 8 this->pulseCount = 0;
33 8 }
34 t_status status;
35 uint8_t bit_length = 56;
36 uint8_t cpt_synchro_hw = 0;
37 uint8_t cpt_bits = 0;
38 uint8_t previous_bit = 0;
39 bool waiting_half_symbol;
40 uint8_t payload[10];
41 unsigned int pulses[MAX_TIMINGS];
42 uint16_t pulseCount = 0;
43 };
44
45 enum class PulseResult : uint8_t {
46 glitch, // Too short to be a symbol. The caller times the next edge from the last one.
47 more, // Taken, the frame isn't complete yet.
48 frame // rx holds a complete frame.
49 };
50 // Feeds the time since the previous edge to rx.
51 PulseResult decodePulse(somfy_rx_t &rx, uint32_t durationUs);
52 #endif
53
54