rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
sbus.h
Go to the documentation of this file.
1
31
32#ifndef RCBENCH_SBUS_H
33#define RCBENCH_SBUS_H
34
35#include <stdbool.h>
36#include <stdint.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
43#define SBUS_FRAME_BYTES 25u
44#define SBUS_HEADER 0x0Fu
45#define SBUS_CHANNELS 16u
46
48#define SBUS_RAW_MIN 0u
49#define SBUS_RAW_MAX 2047u
50
58#define SBUS_RAW_1000US 172u
59#define SBUS_RAW_2000US 1811u
60
68#define SBUS_GAP_US 2000u
69
71#define SBUS_FLAG_CH17 0x01u
72#define SBUS_FLAG_CH18 0x02u
73#define SBUS_FLAG_FRAME_LOST 0x04u
74#define SBUS_FLAG_FAILSAFE 0x08u
75
77typedef struct {
79 bool ch17;
80 bool ch18;
89
91typedef struct {
93 uint8_t len;
94 uint32_t last_byte_us;
95 bool have_time;
96
97 /* Diagnostics, for the analyser view. */
98 uint32_t frames;
99 uint32_t resyncs;
100 uint32_t bad_footer;
102
109
124bool sbus_decode_byte(sbus_decoder_t *d, uint8_t byte, uint32_t now_us,
125 sbus_frame_t *out);
126
133uint16_t sbus_to_us(uint16_t raw);
134
135#ifdef __cplusplus
136}
137#endif
138
139#endif /* RCBENCH_SBUS_H */
#define SBUS_FRAME_BYTES
Frame layout: byte count, header byte and channel count.
Definition sbus.h:43
uint16_t sbus_to_us(uint16_t raw)
Microseconds for a raw channel value, clamped to a sane pulse.
Definition sbus.c:113
#define SBUS_CHANNELS
Definition sbus.h:45
bool sbus_decode_byte(sbus_decoder_t *d, uint8_t byte, uint32_t now_us, sbus_frame_t *out)
Feed one byte with the time it arrived; true when out holds a frame.
Definition sbus.c:57
void sbus_decoder_reset(sbus_decoder_t *d)
Clear a decoder, including its diagnostic counters.
Definition sbus.c:26
Decoder state for one S.BUS byte stream.
Definition sbus.h:91
uint32_t resyncs
Definition sbus.h:99
uint32_t last_byte_us
Definition sbus.h:94
bool have_time
Definition sbus.h:95
uint8_t buf[SBUS_FRAME_BYTES]
Definition sbus.h:92
uint32_t bad_footer
Definition sbus.h:100
uint8_t len
Definition sbus.h:93
One decoded S.BUS frame.
Definition sbus.h:77
bool ch17
Definition sbus.h:79
uint16_t channel[SBUS_CHANNELS]
Definition sbus.h:78
bool ch18
Definition sbus.h:80
bool failsafe
The receiver has lost the transmitter and is generating these values.
Definition sbus.h:87
bool frame_lost
This frame did not arrive intact at the receiver.
Definition sbus.h:82