Open RTS
Full implementation of the Somfy RTS protocol
Loading...
Searching...
No Matches
rts_frame_builder.h
Go to the documentation of this file.
1#ifndef RTS_FRAME_BUILDER_H
2#define RTS_FRAME_BUILDER_H
3
4#include <stdint.h>
5
6#include "rts_frame.h"
7#include "rts_timings.h"
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
37 // Timings to use for generating pulses
38 struct rts_timings *timings;
39
40 // The timing tolerance to use when processing pulses. Defaults to
41 // `timings->symbol / 2` when calling rts_frame_builder_init
42 uint16_t tolerance;
43
44 // User provided frame callback
45 void (*callback)(struct rts_frame *frame, uint8_t count, uint32_t duration,
46 void *user_data);
47
48 // Additional user data to supply whenever callback is called
49 void *callback_user_data;
50
51 //
52 // Internal frame assembly state
53 //
54
55 // Frame builder state
56 uint8_t mode;
57
58 // The frame currently being assembled
59 uint8_t bytes[RTS_FRAME_BYTES];
60
61 // The number of bits we've assembled so far
62 uint8_t bits;
63
64 // Are we half way through receiving a bit
65 bool mid_bit : 1;
66
67 // Keep track of previous manchester symbol
68 bool prev_symbol : 1;
69
70 // Check if this is the first data pulse
71 uint8_t first_data_pulse;
72
73 // The number of preamble pulses received while assembling this frame
74 uint8_t preambles;
75
76 // The last complete frame we assembled, used to detect repeat frames
77 uint8_t last_bytes[RTS_FRAME_BYTES];
78
79 // How many times have we seen this frame repeated
80 uint8_t frame_repeat_count;
81
82 // When did we first see this frame
83 uint32_t frame_first_seen;
84};
85
94void rts_frame_builder_init(struct rts_frame_builder *builder,
95 struct rts_timings *timings);
96
108void rts_frame_builder_handle_pulse(struct rts_frame_builder *builder,
109 bool state, uint32_t micros);
110
121void rts_frame_builder_set_callback(struct rts_frame_builder *builder,
122 void (*callback)(struct rts_frame *frame,
123 uint8_t count,
124 uint32_t duration,
125 void *user_data),
126 void *user_data);
127
132#ifdef __cplusplus
133} // extern "C"
134#endif
135
136#endif // RTS_FRAME_BUILDER_H
Assembles pulses received via rts_frame_builder_handle_pulse, into a complete rts_frame,...
Definition rts_frame_builder.h:36
Represents the message "payload" sent by RTS remote controls.
Definition rts_frame.h:32
Timing definitions for encoding and decoding frames to pulses.
Definition rts_timings.h:31