aboutsummaryrefslogtreecommitdiff
path: root/apps/px4io/sbus.c
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-12-04 09:52:16 -0800
committerpx4dev <px4@purgatory.org>2012-12-04 09:52:16 -0800
commit7c3b28d503123121403b4ad68c934bb91b05d878 (patch)
tree44f090d7f31fc26fc91f04c60827ec6d68abb93c /apps/px4io/sbus.c
parent1485a4ec1aa8328cc50d99a1195b20df2b11045e (diff)
downloadpx4-firmware-7c3b28d503123121403b4ad68c934bb91b05d878.tar.gz
px4-firmware-7c3b28d503123121403b4ad68c934bb91b05d878.tar.bz2
px4-firmware-7c3b28d503123121403b4ad68c934bb91b05d878.zip
Lock out the PPM decoder if the DSM or S.bus decoders have seen a frame recently.
Diffstat (limited to 'apps/px4io/sbus.c')
-rw-r--r--apps/px4io/sbus.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/apps/px4io/sbus.c b/apps/px4io/sbus.c
index 25fe0cf38..a8f628a84 100644
--- a/apps/px4io/sbus.c
+++ b/apps/px4io/sbus.c
@@ -58,6 +58,7 @@
static int sbus_fd = -1;
static hrt_abstime last_rx_time;
+static hrt_abstime last_frame_time;
static uint8_t frame[SBUS_FRAME_SIZE];
@@ -94,7 +95,7 @@ sbus_init(const char *device)
return sbus_fd;
}
-void
+bool
sbus_input(void)
{
ssize_t ret;
@@ -131,7 +132,7 @@ sbus_input(void)
/* if the read failed for any reason, just give up here */
if (ret < 1)
- return;
+ goto out;
last_rx_time = now;
/*
@@ -143,7 +144,7 @@ sbus_input(void)
* If we don't have a full frame, return
*/
if (partial_frame_count < SBUS_FRAME_SIZE)
- return;
+ goto out;
/*
* Great, it looks like we might have a frame. Go ahead and
@@ -151,6 +152,12 @@ sbus_input(void)
*/
sbus_decode(now);
partial_frame_count = 0;
+
+out:
+ /*
+ * If we have seen a frame in the last 200ms, we consider ourselves 'locked'
+ */
+ return (now - last_frame_time) < 200000;
}
/*
@@ -203,6 +210,9 @@ sbus_decode(hrt_abstime frame_time)
return;
}
+ /* we have received something we think is a frame */
+ last_frame_time = frame_time;
+
unsigned chancount = (PX4IO_INPUT_CHANNELS > SBUS_INPUT_CHANNELS) ?
SBUS_INPUT_CHANNELS : PX4IO_INPUT_CHANNELS;