diff options
author | px4dev <px4@purgatory.org> | 2012-11-05 00:55:22 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-11-05 00:55:45 -0800 |
commit | 39659e57f817c4f49be595d6cecf05e67e2d89db (patch) | |
tree | e7e4e1e06c3e075a33f5788ed38d257cfde1bd45 /apps/px4io/comms.c | |
parent | 87fd9fcc067d8115624170ee0f934c1f75e19633 (diff) | |
download | px4-firmware-39659e57f817c4f49be595d6cecf05e67e2d89db.tar.gz px4-firmware-39659e57f817c4f49be595d6cecf05e67e2d89db.tar.bz2 px4-firmware-39659e57f817c4f49be595d6cecf05e67e2d89db.zip |
Add prototypical support for Spektrum satellite remotes to PX4IO.
Diffstat (limited to 'apps/px4io/comms.c')
-rw-r--r-- | apps/px4io/comms.c | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/apps/px4io/comms.c b/apps/px4io/comms.c index 8fdf7d1c8..1edff25b1 100644 --- a/apps/px4io/comms.c +++ b/apps/px4io/comms.c @@ -116,18 +116,32 @@ int frame_rx; int frame_bad; static void -comms_handle_frame(void *arg, const void *buffer, size_t length) +comms_handle_config(const void *buffer, size_t length) { - struct px4io_command *cmd = (struct px4io_command *)buffer; + const struct px4io_config *cfg = (struct px4io_config *)buffer; - /* make sure it's what we are expecting */ - if ((length != sizeof(struct px4io_command)) || - (cmd->f2i_magic != F2I_MAGIC)) { - frame_bad++; + if (length != sizeof(*cfg)) { + frame_bad++; return; } + frame_rx++; + mixer_set_serial_mode(cfg->serial_rx_mode); + +} + +static void +comms_handle_command(const void *buffer, size_t length) +{ + const struct px4io_command *cmd = (struct px4io_command *)buffer; + + if (length != sizeof(*cmd)) { + frame_bad++; + return; + } + + frame_rx++; irqstate_t flags = irqsave(); /* fetch new PWM output values */ @@ -146,6 +160,29 @@ comms_handle_frame(void *arg, const void *buffer, size_t length) for (unsigned i = 0; i < PX4IO_RELAY_CHANNELS; i++) system_state.relays[i] = cmd->relay_state[i]; -out: irqrestore(flags); } + + +static void +comms_handle_frame(void *arg, const void *buffer, size_t length) +{ + const uint16_t *type = (const uint16_t *)buffer; + + + /* make sure it's what we are expecting */ + if (length > 2) { + switch (*type) { + case F2I_MAGIC: + comms_handle_command(buffer, length); + break; + case F2I_CONFIG_MAGIC: + comms_handle_config(buffer, length); + break; + default: + break; + } + } + frame_bad++; +} + |