56 #define SBUS_FRAME_SIZE 25 57 #define SBUS_INPUT_CHANNELS 16 58 #define SBUS_FLAGS_BYTE 23 59 #define SBUS_FAILSAFE_BIT 3 60 #define SBUS_FRAMELOST_BIT 2 63 #define SBUS_RANGE_MIN 200.0f 64 #define SBUS_RANGE_MAX 1800.0f 66 #define SBUS_TARGET_MIN 1000.0f 67 #define SBUS_TARGET_MAX 2000.0f 70 #define SBUS_SCALE_FACTOR ((SBUS_TARGET_MAX - SBUS_TARGET_MIN) / (SBUS_RANGE_MAX - SBUS_RANGE_MIN)) 71 #define SBUS_SCALE_OFFSET (int)(SBUS_TARGET_MIN - (SBUS_SCALE_FACTOR * SBUS_RANGE_MIN + 0.5f)) 91 { { 0, 0, 0xff, 0}, { 1, 0, 0x07, 8}, { 0, 0, 0x00, 0} },
92 { { 1, 3, 0x1f, 0}, { 2, 0, 0x3f, 5}, { 0, 0, 0x00, 0} },
93 { { 2, 6, 0x03, 0}, { 3, 0, 0xff, 2}, { 4, 0, 0x01, 10} },
94 { { 4, 1, 0x7f, 0}, { 5, 0, 0x0f, 7}, { 0, 0, 0x00, 0} },
95 { { 5, 4, 0x0f, 0}, { 6, 0, 0x7f, 4}, { 0, 0, 0x00, 0} },
96 { { 6, 7, 0x01, 0}, { 7, 0, 0xff, 1}, { 8, 0, 0x03, 9} },
97 { { 8, 2, 0x3f, 0}, { 9, 0, 0x1f, 6}, { 0, 0, 0x00, 0} },
98 { { 9, 5, 0x07, 0}, {10, 0, 0xff, 3}, { 0, 0, 0x00, 0} },
99 { {11, 0, 0xff, 0}, {12, 0, 0x07, 8}, { 0, 0, 0x00, 0} },
100 { {12, 3, 0x1f, 0}, {13, 0, 0x3f, 5}, { 0, 0, 0x00, 0} },
101 { {13, 6, 0x03, 0}, {14, 0, 0xff, 2}, {15, 0, 0x01, 10} },
102 { {15, 1, 0x7f, 0}, {16, 0, 0x0f, 7}, { 0, 0, 0x00, 0} },
103 { {16, 4, 0x0f, 0}, {17, 0, 0x7f, 4}, { 0, 0, 0x00, 0} },
104 { {17, 7, 0x01, 0}, {18, 0, 0xff, 1}, {19, 0, 0x03, 9} },
105 { {19, 2, 0x3f, 0}, {20, 0, 0x1f, 6}, { 0, 0, 0x00, 0} },
106 { {20, 5, 0x07, 0}, {21, 0, 0xff, 3}, { 0, 0, 0x00, 0} }
111 bool *sbus_failsafe,
bool *sbus_frame_drop, uint16_t max_values)
114 if ((frame[0] != 0x0f)) {
144 for (
unsigned channel = 0; channel < chancount; channel++) {
147 for (
unsigned pick = 0; pick < 3; pick++) {
148 const struct sbus_bit_pick *decode = &sbus_decoder[channel][pick];
150 if (decode->
mask != 0) {
151 unsigned piece = frame[1 + decode->
byte];
153 piece &= decode->
mask;
166 if (max_values > 17 && chancount > 15) {
176 *num_values = chancount;
181 *sbus_failsafe =
true;
182 *sbus_frame_drop =
true;
191 *sbus_failsafe =
false;
192 *sbus_frame_drop =
true;
194 *sbus_failsafe =
false;
195 *sbus_frame_drop =
false;
208 uint16_t bits_s0 = (width_s0+1) / 10;
209 uint16_t bits_s1 = (width_s1+1) / 10;
212 uint8_t byte_ofs = sbus_state.bit_ofs/12;
213 uint8_t bit_ofs = sbus_state.bit_ofs%12;
215 if (bits_s0 == 0 || bits_s1 == 0) {
220 if (bits_s0+bit_ofs > 10) {
226 sbus_state.bytes[byte_ofs] |= ((1U<<bits_s0)-1) << bit_ofs;
227 sbus_state.bit_ofs += bits_s0;
232 if (nlow + bit_ofs > 12) {
236 sbus_state.bit_ofs += nlow;
238 if (sbus_state.bit_ofs == 25*12 && bits_s1 > 12) {
242 for (i=0; i<25; i++) {
244 uint16_t
v = ~sbus_state.bytes[i];
250 if ((v & 0xC00) != 0xC00) {
254 uint8_t parity = 0, j;
255 for (j=1; j<=8; j++) {
256 parity ^= (v & (1U<<j))?1:0;
258 if (parity != (v&0x200)>>9) {
261 bytes[i] = ((v>>1) & 0xFF);
264 uint16_t num_values=0;
265 bool sbus_failsafe=
false, sbus_frame_drop=
false;
267 &sbus_failsafe, &sbus_frame_drop,
270 add_input(num_values, values, sbus_failsafe);
273 }
else if (bits_s1 > 12) {
279 memset(&sbus_state, 0,
sizeof(sbus_state));
#define SBUS_SCALE_OFFSET
#define MAX_RCIN_CHANNELS
#define SBUS_INPUT_CHANNELS
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 MIN_RCIN_CHANNELS
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_FAILSAFE_BIT
static const struct sbus_bit_pick sbus_decoder[SBUS_INPUT_CHANNELS][3]
#define SBUS_FRAMELOST_BIT
#define SBUS_SCALE_FACTOR
void process_pulse(uint32_t width_s0, uint32_t width_s1) override