|
|
|
@ -88,6 +88,7 @@ sbus_init(const char *device)
@@ -88,6 +88,7 @@ sbus_init(const char *device)
|
|
|
|
|
last_rx_time = hrt_absolute_time(); |
|
|
|
|
|
|
|
|
|
debug("S.Bus: ready"); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
debug("S.Bus: open failed"); |
|
|
|
|
} |
|
|
|
@ -117,6 +118,7 @@ sbus_input(void)
@@ -117,6 +118,7 @@ sbus_input(void)
|
|
|
|
|
* if we didn't drop bytes... |
|
|
|
|
*/ |
|
|
|
|
now = hrt_absolute_time(); |
|
|
|
|
|
|
|
|
|
if ((now - last_rx_time) > 3000) { |
|
|
|
|
if (partial_frame_count > 0) { |
|
|
|
|
sbus_frame_drops++; |
|
|
|
@ -133,6 +135,7 @@ sbus_input(void)
@@ -133,6 +135,7 @@ sbus_input(void)
|
|
|
|
|
/* if the read failed for any reason, just give up here */ |
|
|
|
|
if (ret < 1) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
last_rx_time = now; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -144,7 +147,7 @@ sbus_input(void)
@@ -144,7 +147,7 @@ sbus_input(void)
|
|
|
|
|
* If we don't have a full frame, return |
|
|
|
|
*/ |
|
|
|
|
if (partial_frame_count < SBUS_FRAME_SIZE) |
|
|
|
|
goto out; |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Great, it looks like we might have a frame. Go ahead and |
|
|
|
@ -178,22 +181,22 @@ struct sbus_bit_pick {
@@ -178,22 +181,22 @@ struct sbus_bit_pick {
|
|
|
|
|
uint8_t lshift; |
|
|
|
|
}; |
|
|
|
|
static const struct sbus_bit_pick sbus_decoder[SBUS_INPUT_CHANNELS][3] = { |
|
|
|
|
/* 0 */ { { 0, 0, 0xff, 0},{ 1, 0, 0x07, 8},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 1 */ { { 1, 3, 0x1f, 0},{ 2, 0, 0x3f, 5},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 2 */ { { 2, 6, 0x03, 0},{ 3, 0, 0xff, 2},{ 4, 0, 0x01, 10} }, |
|
|
|
|
/* 3 */ { { 4, 1, 0x7f, 0},{ 5, 0, 0x0f, 7},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 4 */ { { 5, 4, 0x0f, 0},{ 6, 0, 0x7f, 4},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 5 */ { { 6, 7, 0x01, 0},{ 7, 0, 0xff, 1},{ 8, 0, 0x03, 9} }, |
|
|
|
|
/* 6 */ { { 8, 2, 0x3f, 0},{ 9, 0, 0x1f, 6},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 7 */ { { 9, 5, 0x07, 0},{10, 0, 0xff, 3},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 8 */ { {11, 0, 0xff, 0},{12, 0, 0x07, 8},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 9 */ { {12, 3, 0x1f, 0},{13, 0, 0x3f, 5},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 10 */ { {13, 6, 0x03, 0},{14, 0, 0xff, 2},{15, 0, 0x01, 10} }, |
|
|
|
|
/* 11 */ { {15, 1, 0x7f, 0},{16, 0, 0x0f, 7},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 12 */ { {16, 4, 0x0f, 0},{17, 0, 0x7f, 4},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 13 */ { {17, 7, 0x01, 0},{18, 0, 0xff, 1},{19, 0, 0x03, 9} }, |
|
|
|
|
/* 14 */ { {19, 2, 0x3f, 0},{20, 0, 0x1f, 6},{ 0, 0, 0x00, 0} }, |
|
|
|
|
/* 15 */ { {20, 5, 0x07, 0},{21, 0, 0xff, 3},{ 0, 0, 0x00, 0} } |
|
|
|
|
/* 0 */ { { 0, 0, 0xff, 0}, { 1, 0, 0x07, 8}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 1 */ { { 1, 3, 0x1f, 0}, { 2, 0, 0x3f, 5}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 2 */ { { 2, 6, 0x03, 0}, { 3, 0, 0xff, 2}, { 4, 0, 0x01, 10} }, |
|
|
|
|
/* 3 */ { { 4, 1, 0x7f, 0}, { 5, 0, 0x0f, 7}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 4 */ { { 5, 4, 0x0f, 0}, { 6, 0, 0x7f, 4}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 5 */ { { 6, 7, 0x01, 0}, { 7, 0, 0xff, 1}, { 8, 0, 0x03, 9} }, |
|
|
|
|
/* 6 */ { { 8, 2, 0x3f, 0}, { 9, 0, 0x1f, 6}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 7 */ { { 9, 5, 0x07, 0}, {10, 0, 0xff, 3}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 8 */ { {11, 0, 0xff, 0}, {12, 0, 0x07, 8}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 9 */ { {12, 3, 0x1f, 0}, {13, 0, 0x3f, 5}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 10 */ { {13, 6, 0x03, 0}, {14, 0, 0xff, 2}, {15, 0, 0x01, 10} }, |
|
|
|
|
/* 11 */ { {15, 1, 0x7f, 0}, {16, 0, 0x0f, 7}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 12 */ { {16, 4, 0x0f, 0}, {17, 0, 0x7f, 4}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 13 */ { {17, 7, 0x01, 0}, {18, 0, 0xff, 1}, {19, 0, 0x03, 9} }, |
|
|
|
|
/* 14 */ { {19, 2, 0x3f, 0}, {20, 0, 0x1f, 6}, { 0, 0, 0x00, 0} }, |
|
|
|
|
/* 15 */ { {20, 5, 0x07, 0}, {21, 0, 0xff, 3}, { 0, 0, 0x00, 0} } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
@ -207,7 +210,7 @@ sbus_decode(hrt_abstime frame_time)
@@ -207,7 +210,7 @@ sbus_decode(hrt_abstime frame_time)
|
|
|
|
|
|
|
|
|
|
/* if the failsafe or connection lost bit is set, we consider the frame invalid */ |
|
|
|
|
if ((frame[23] & (1 << 2)) && /* signal lost */ |
|
|
|
|
(frame[23] & (1 << 3))) { /* failsafe */ |
|
|
|
|
(frame[23] & (1 << 3))) { /* failsafe */ |
|
|
|
|
|
|
|
|
|
/* actively announce signal loss */ |
|
|
|
|
system_state.rc_channels = 0; |
|
|
|
@ -218,7 +221,7 @@ sbus_decode(hrt_abstime frame_time)
@@ -218,7 +221,7 @@ sbus_decode(hrt_abstime frame_time)
|
|
|
|
|
last_frame_time = frame_time; |
|
|
|
|
|
|
|
|
|
unsigned chancount = (PX4IO_INPUT_CHANNELS > SBUS_INPUT_CHANNELS) ? |
|
|
|
|
SBUS_INPUT_CHANNELS : PX4IO_INPUT_CHANNELS; |
|
|
|
|
SBUS_INPUT_CHANNELS : PX4IO_INPUT_CHANNELS; |
|
|
|
|
|
|
|
|
|
/* use the decoder matrix to extract channel data */ |
|
|
|
|
for (unsigned channel = 0; channel < chancount; channel++) { |
|
|
|
@ -236,6 +239,7 @@ sbus_decode(hrt_abstime frame_time)
@@ -236,6 +239,7 @@ sbus_decode(hrt_abstime frame_time)
|
|
|
|
|
value |= piece; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* convert 0-2048 values to 1000-2000 ppm encoding in a very sloppy fashion */ |
|
|
|
|
system_state.rc_channel_data[channel] = (value / 2) + 998; |
|
|
|
|
} |
|
|
|
|