Firmware
|
Serial protocol decoder for the Spektrum DSM* family of protocols. More...
#include <px4_config.h>
#include <board_config.h>
#include <px4_defines.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <string.h>
#include "dsm.h"
#include "spektrum_rssi.h"
#include "common_rc.h"
#include <drivers/drv_hrt.h>
Macros | |
#define | dsm_udelay(arg) px4_usleep(arg) |
Enumerations | |
enum | DSM_DECODE_STATE { DSM_DECODE_STATE_DESYNC = 0, DSM_DECODE_STATE_SYNC } |
Functions | |
int | dsm_config (int fd) |
void | dsm_proto_init () |
int | dsm_init (const char *device) |
Initialize the DSM receive functionality. More... | |
void | dsm_deinit () |
bool | dsm_input (int fd, uint16_t *values, uint16_t *num_values, bool *dsm_11_bit, uint8_t *n_bytes, uint8_t **bytes, int8_t *rssi, unsigned max_values) |
Called periodically to check for input data from the DSM UART. More... | |
bool | dsm_parse (const uint64_t now, const uint8_t *frame, const unsigned len, uint16_t *values, uint16_t *num_values, bool *dsm_11_bit, unsigned *frame_drops, int8_t *rssi_percent, uint16_t max_channels) |
Serial protocol decoder for the Spektrum DSM* family of protocols.
Decodes into the global PPM buffer and updates accordingly.
int dsm_init | ( | const char * | device | ) |
Initialize the DSM receive functionality.
Open the UART for receiving DSM frames and configure it appropriately
[in] | device | Device name of DSM UART |
bool dsm_input | ( | int | fd, |
uint16_t * | values, | ||
uint16_t * | num_values, | ||
bool * | dsm_11_bit, | ||
uint8_t * | n_bytes, | ||
uint8_t ** | bytes, | ||
int8_t * | rssi, | ||
unsigned | max_values | ||
) |
Called periodically to check for input data from the DSM UART.
The DSM* protocol doesn't provide any explicit framing, so we detect dsm frame boundaries by the inter-dsm frame delay. The minimum dsm frame spacing is 11ms; with 16 bytes at 115200bps dsm 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, the first byte we read will be the first byte of a dsm frame. In the case where byte(s) are dropped from a dsm frame, this also provides a degree of protection. Of course, it would be better if we didn't drop bytes... Upon receiving a full dsm frame we attempt to decode it.
[out] | values | pointer to per channel array of decoded values |
[out] | num_values | pointer to number of raw channel values returned, high order bit 0:10 bit data, 1:11 bit data |
[out] | n_butes | number of bytes read |
[out] | bytes | pointer to the buffer of read bytes |
[out] | rssi | value in percent, if supported, or 127 |