42 #define SBUS_FRAME_SIZE 25 43 #define SBUS_INPUT_CHANNELS 16 44 #define SBUS_FLAGS_BYTE 23 45 #define SBUS_FAILSAFE_BIT 3 46 #define SBUS_FRAMELOST_BIT 2 49 #define SBUS_RANGE_MIN 200.0f 50 #define SBUS_RANGE_MAX 1800.0f 52 #define SBUS_TARGET_MIN 1000.0f 53 #define SBUS_TARGET_MAX 2000.0f 56 #define SBUS_SCALE_FACTOR ((SBUS_TARGET_MAX - SBUS_TARGET_MIN) / (SBUS_RANGE_MAX - SBUS_RANGE_MIN)) 57 #define SBUS_SCALE_OFFSET (int)(SBUS_TARGET_MIN - (SBUS_SCALE_FACTOR * SBUS_RANGE_MIN + 0.5f)) 77 { { 0, 0, 0xff, 0}, { 1, 0, 0x07, 8}, { 0, 0, 0x00, 0} },
78 { { 1, 3, 0x1f, 0}, { 2, 0, 0x3f, 5}, { 0, 0, 0x00, 0} },
79 { { 2, 6, 0x03, 0}, { 3, 0, 0xff, 2}, { 4, 0, 0x01, 10} },
80 { { 4, 1, 0x7f, 0}, { 5, 0, 0x0f, 7}, { 0, 0, 0x00, 0} },
81 { { 5, 4, 0x0f, 0}, { 6, 0, 0x7f, 4}, { 0, 0, 0x00, 0} },
82 { { 6, 7, 0x01, 0}, { 7, 0, 0xff, 1}, { 8, 0, 0x03, 9} },
83 { { 8, 2, 0x3f, 0}, { 9, 0, 0x1f, 6}, { 0, 0, 0x00, 0} },
84 { { 9, 5, 0x07, 0}, {10, 0, 0xff, 3}, { 0, 0, 0x00, 0} },
85 { {11, 0, 0xff, 0}, {12, 0, 0x07, 8}, { 0, 0, 0x00, 0} },
86 { {12, 3, 0x1f, 0}, {13, 0, 0x3f, 5}, { 0, 0, 0x00, 0} },
87 { {13, 6, 0x03, 0}, {14, 0, 0xff, 2}, {15, 0, 0x01, 10} },
88 { {15, 1, 0x7f, 0}, {16, 0, 0x0f, 7}, { 0, 0, 0x00, 0} },
89 { {16, 4, 0x0f, 0}, {17, 0, 0x7f, 4}, { 0, 0, 0x00, 0} },
90 { {17, 7, 0x01, 0}, {18, 0, 0xff, 1}, {19, 0, 0x03, 9} },
91 { {19, 2, 0x3f, 0}, {20, 0, 0x1f, 6}, { 0, 0, 0x00, 0} },
92 { {20, 5, 0x07, 0}, {21, 0, 0xff, 3}, { 0, 0, 0x00, 0} }
97 sbus_decode(
const uint8_t frame[25], uint16_t *values, uint16_t *num_values,
98 bool *sbus_failsafe,
bool *sbus_frame_drop, uint16_t max_values)
101 if ((frame[0] != 0x0f)) {
131 for (
unsigned channel = 0; channel < chancount; channel++) {
134 for (
unsigned pick = 0; pick < 3; pick++) {
135 const struct sbus_bit_pick *decode = &sbus_decoder[channel][pick];
137 if (decode->
mask != 0) {
138 unsigned piece = frame[1 + decode->
byte];
140 piece &= decode->
mask;
153 if (max_values > 17 && chancount > 15) {
163 *num_values = chancount;
168 *sbus_failsafe =
true;
169 *sbus_frame_drop =
true;
178 *sbus_failsafe =
false;
179 *sbus_frame_drop =
true;
181 *sbus_failsafe =
false;
182 *sbus_frame_drop =
false;
#define SBUS_FRAMELOST_BIT
static const struct sbus_bit_pick sbus_decoder[SBUS_INPUT_CHANNELS][3]
#define SBUS_FAILSAFE_BIT
bool sbus_decode(const uint8_t frame[25], uint16_t *values, uint16_t *num_values, bool *sbus_failsafe, bool *sbus_frame_drop, uint16_t max_values)
#define SBUS_SCALE_FACTOR
#define SBUS_SCALE_OFFSET
#define SBUS_INPUT_CHANNELS