From 151402748e037012947f0f233f30ca320e2f9560 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 29 Nov 2015 14:55:03 +0100 Subject: [PATCH] S.BUS input: Be less sensitive on timing --- src/lib/rc/sbus.c | 5 ++--- src/lib/rc/sbus.h | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib/rc/sbus.c b/src/lib/rc/sbus.c index 1ba1ff298e..f5330b720d 100644 --- a/src/lib/rc/sbus.c +++ b/src/lib/rc/sbus.c @@ -174,8 +174,7 @@ sbus_input(int sbus_fd, uint16_t *values, uint16_t *num_values, bool *sbus_fails * The minimum frame spacing is 7ms; with 25 bytes at 100000bps * frame transmission time is ~2ms. * - * We expect to only be called when bytes arrive for processing, - * and if an interval of more than 3ms passes between calls, + * If an interval of more than 4ms passes between calls, * the first byte we read will be the first byte of a frame. * * In the case where byte(s) are dropped from a frame, this also @@ -184,7 +183,7 @@ sbus_input(int sbus_fd, uint16_t *values, uint16_t *num_values, bool *sbus_fails */ now = hrt_absolute_time(); - if ((now - last_rx_time) > 3000) { + if ((now - last_rx_time) > 4000) { if (partial_frame_count > 0) { sbus_frame_drops++; partial_frame_count = 0; diff --git a/src/lib/rc/sbus.h b/src/lib/rc/sbus.h index 1404a9eabd..04b91dc126 100644 --- a/src/lib/rc/sbus.h +++ b/src/lib/rc/sbus.h @@ -47,6 +47,24 @@ __BEGIN_DECLS __EXPORT int sbus_init(const char *device, bool singlewire); + +/** + * Parse serial bytes on the S.BUS bus + * + * The S.bus protocol doesn't provide reliable framing, + * so we detect frame boundaries by the inter-frame delay. + * + * The minimum frame spacing is 7ms; with 25 bytes at 100000bps + * frame transmission time is ~2ms. + * + * If an interval of more than 4ms (7 ms frame spacing plus margin) + * passes between calls, the first byte we read will be the first + * byte of a frame. + * + * In the case where byte(s) are dropped from a frame, this also + * provides a degree of protection. Of course, it would be better + * if we didn't drop bytes... + */ __EXPORT bool sbus_input(int sbus_fd, uint16_t *values, uint16_t *num_values, bool *sbus_failsafe, bool *sbus_frame_drop, uint16_t max_channels);