aboutsummaryrefslogtreecommitdiff
path: root/apps/px4io/dsm.c
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-12-29 16:01:24 -0800
committerpx4dev <px4@purgatory.org>2012-12-29 16:01:24 -0800
commitd81edb09cf29dd36d50ce7a7bcf55631fecc470f (patch)
tree63cb30938794a69981782ff666b9e181c2b286da /apps/px4io/dsm.c
parentf9520ee39d0e14bc67cce809375fb69de9a7f977 (diff)
downloadpx4-firmware-d81edb09cf29dd36d50ce7a7bcf55631fecc470f.tar.gz
px4-firmware-d81edb09cf29dd36d50ce7a7bcf55631fecc470f.tar.bz2
px4-firmware-d81edb09cf29dd36d50ce7a7bcf55631fecc470f.zip
whitespace/formatting
Diffstat (limited to 'apps/px4io/dsm.c')
-rw-r--r--apps/px4io/dsm.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/apps/px4io/dsm.c b/apps/px4io/dsm.c
index 2611f3a03..560ef47d9 100644
--- a/apps/px4io/dsm.c
+++ b/apps/px4io/dsm.c
@@ -47,7 +47,7 @@
#include <termios.h>
#include <systemlib/ppm_decode.h>
-
+
#include <drivers/drv_hrt.h>
#define DEBUG
@@ -97,6 +97,7 @@ dsm_init(const char *device)
dsm_guess_format(true);
debug("DSM: ready");
+
} else {
debug("DSM: open failed");
}
@@ -118,7 +119,7 @@ dsm_input(void)
* frame transmission time is ~1.4ms.
*
* We expect to only be called when bytes arrive for processing,
- * and if an interval of more than 5ms passes between calls,
+ * and if an interval of more than 5ms 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
@@ -126,6 +127,7 @@ dsm_input(void)
* if we didn't drop bytes...
*/
now = hrt_absolute_time();
+
if ((now - last_rx_time) > 5000) {
if (partial_frame_count > 0) {
dsm_frame_drops++;
@@ -142,6 +144,7 @@ dsm_input(void)
/* if the read failed for any reason, just give up here */
if (ret < 1)
goto out;
+
last_rx_time = now;
/*
@@ -153,7 +156,7 @@ dsm_input(void)
* If we don't have a full frame, return
*/
if (partial_frame_count < DSM_FRAME_SIZE)
- goto out;
+ goto out;
/*
* Great, it looks like we might have a frame. Go ahead and
@@ -164,7 +167,7 @@ dsm_input(void)
out:
/*
- * If we have seen a frame in the last 200ms, we consider ourselves 'locked'
+ * If we have seen a frame in the last 200ms, we consider ourselves 'locked'
*/
return (now - last_frame_time) < 200000;
}
@@ -212,6 +215,7 @@ dsm_guess_format(bool reset)
/* if the channel decodes, remember the assigned number */
if (dsm_decode_channel(raw, 10, &channel, &value) && (channel < 31))
cs10 |= (1 << channel);
+
if (dsm_decode_channel(raw, 11, &channel, &value) && (channel < 31))
cs11 |= (1 << channel);
@@ -222,7 +226,7 @@ dsm_guess_format(bool reset)
if (samples++ < 5)
return;
- /*
+ /*
* Iterate the set of sensible sniffed channel sets and see whether
* decoding in 10 or 11-bit mode has yielded anything we recognise.
*
@@ -233,7 +237,7 @@ dsm_guess_format(bool reset)
* See e.g. http://git.openpilot.org/cru/OPReview-116 for a discussion
* of this issue.
*/
- static uint32_t masks[] = {
+ static uint32_t masks[] = {
0x3f, /* 6 channels (DX6) */
0x7f, /* 7 channels (DX7) */
0xff, /* 8 channels (DX8) */
@@ -247,14 +251,17 @@ dsm_guess_format(bool reset)
if (cs10 == masks[i])
votes10++;
+
if (cs11 == masks[i])
votes11++;
}
+
if ((votes11 == 1) && (votes10 == 0)) {
channel_shift = 11;
debug("DSM: detected 11-bit format");
return;
}
+
if ((votes10 == 1) && (votes11 == 0)) {
channel_shift = 10;
debug("DSM: detected 10-bit format");
@@ -270,13 +277,13 @@ static void
dsm_decode(hrt_abstime frame_time)
{
-/*
- debug("DSM frame %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x",
- frame[0], frame[1], frame[2], frame[3], frame[4], frame[5], frame[6], frame[7],
- frame[8], frame[9], frame[10], frame[11], frame[12], frame[13], frame[14], frame[15]);
-*/
/*
- * If we have lost signal for at least a second, reset the
+ debug("DSM frame %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x",
+ frame[0], frame[1], frame[2], frame[3], frame[4], frame[5], frame[6], frame[7],
+ frame[8], frame[9], frame[10], frame[11], frame[12], frame[13], frame[14], frame[15]);
+ */
+ /*
+ * If we have lost signal for at least a second, reset the
* format guessing heuristic.
*/
if (((frame_time - last_frame_time) > 1000000) && (channel_shift != 0))
@@ -292,7 +299,7 @@ dsm_decode(hrt_abstime frame_time)
}
/*
- * The encoding of the first two bytes is uncertain, so we're
+ * The encoding of the first two bytes is uncertain, so we're
* going to ignore them for now.
*
* Each channel is a 16-bit unsigned value containing either a 10-
@@ -322,9 +329,10 @@ dsm_decode(hrt_abstime frame_time)
/* convert 0-1024 / 0-2048 values to 1000-2000 ppm encoding in a very sloppy fashion */
if (channel_shift == 11)
value /= 2;
+
value += 998;
- /*
+ /*
* Store the decoded channel into the R/C input buffer, taking into
* account the different ideas about channel assignement that we have.
*
@@ -335,14 +343,18 @@ dsm_decode(hrt_abstime frame_time)
case 0:
channel = 2;
break;
+
case 1:
channel = 0;
break;
+
case 2:
channel = 1;
+
default:
break;
}
+
system_state.rc_channel_data[channel] = value;
}