diff options
author | px4dev <px4@purgatory.org> | 2012-12-30 01:17:19 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-12-30 01:17:19 -0800 |
commit | fd016abd46954311f85dd4a9345fce6aef680c44 (patch) | |
tree | 3de0f91a2abdb7e10d13f1f921a93b958a6f7707 /apps/px4io/mixer.cpp | |
parent | c740e9c6160b72fa11d252e5ef4efe6ae741abba (diff) | |
download | px4-firmware-fd016abd46954311f85dd4a9345fce6aef680c44.tar.gz px4-firmware-fd016abd46954311f85dd4a9345fce6aef680c44.tar.bz2 px4-firmware-fd016abd46954311f85dd4a9345fce6aef680c44.zip |
Implement the remaining pieces of mixer upload to PX4IO.
Diffstat (limited to 'apps/px4io/mixer.cpp')
-rw-r--r-- | apps/px4io/mixer.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/apps/px4io/mixer.cpp b/apps/px4io/mixer.cpp index 52666ae39..d21b3a898 100644 --- a/apps/px4io/mixer.cpp +++ b/apps/px4io/mixer.cpp @@ -52,6 +52,7 @@ #include <systemlib/mixer/mixer.h> extern "C" { +//#define DEBUG #include "px4io.h" } @@ -175,14 +176,17 @@ mixer_callback(uintptr_t handle, return 0; } +static char mixer_text[256]; +static unsigned mixer_text_length = 0; + void mixer_handle_text(const void *buffer, size_t length) { - static char mixer_text[256]; - static unsigned mixer_text_length = 0; px4io_mixdata *msg = (px4io_mixdata *)buffer; + debug("mixer text %u", length); + if (length < sizeof(px4io_mixdata)) return; @@ -190,11 +194,13 @@ mixer_handle_text(const void *buffer, size_t length) switch (msg->action) { case F2I_MIXER_ACTION_RESET: + debug("reset"); mixer_group.reset(); mixer_text_length = 0; /* FALLTHROUGH */ case F2I_MIXER_ACTION_APPEND: + debug("append %d", length); /* check for overflow - this is really fatal */ if ((mixer_text_length + text_length + 1) > sizeof(mixer_text)) @@ -204,14 +210,22 @@ mixer_handle_text(const void *buffer, size_t length) memcpy(&mixer_text[mixer_text_length], msg->text, text_length); mixer_text_length += text_length; mixer_text[mixer_text_length] = '\0'; + debug("buflen %u", mixer_text_length); /* process the text buffer, adding new mixers as their descriptions can be parsed */ - char *end = &mixer_text[mixer_text_length]; - mixer_group.load_from_buf(&mixer_text[0], mixer_text_length); + unsigned resid = mixer_text_length; + mixer_group.load_from_buf(&mixer_text[0], resid); + + /* if anything was parsed */ + if (resid != mixer_text_length) { + debug("used %u", mixer_text_length - resid); - /* copy any leftover text to the base of the buffer for re-use */ - if (mixer_text_length > 0) - memcpy(&mixer_text[0], end - mixer_text_length, mixer_text_length); + /* copy any leftover text to the base of the buffer for re-use */ + if (resid > 0) + memcpy(&mixer_text[0], &mixer_text[mixer_text_length - resid], resid); + + mixer_text_length = resid; + } break; } |