Firmware
Classes | Macros | Typedefs | Enumerations | Functions
dsm.h File Reference

RC protocol definition for Spektrum RC. More...

#include <stdint.h>
#include <px4_config.h>
#include <px4_defines.h>

Go to the source code of this file.

Classes

struct  dsm_decode_t
 

Macros

#define DSM_FRAME_SIZE   16
 DSM frame size in bytes.
 
#define DSM_FRAME_CHANNELS   7
 Max supported DSM channels per frame.
 
#define DSM_MAX_CHANNEL_COUNT   18
 Max channel count of any DSM RC.
 
#define DSM_BUFFER_SIZE   (DSM_FRAME_SIZE + DSM_FRAME_SIZE / 2)
 
#define DSM2_BIND_PULSES   3 /* DSM_BIND_START parameter, pulses required to start dsm2 pairing */
 
#define DSMX_BIND_PULSES   7 /* DSM_BIND_START parameter, pulses required to start dsmx pairing */
 
#define DSMX8_BIND_PULSES   9 /* DSM_BIND_START parameter, pulses required to start 8 or more channel dsmx pairing */
 

Typedefs

typedef uint8_t dsm_frame_t[DSM_BUFFER_SIZE]
 DSM dsm frame receive buffer.
 
typedef uint8_t dsm_buf_t[DSM_FRAME_SIZE *2]
 
typedef struct dsm_decode_t dsm_decode_t
 

Enumerations

enum  DSM_CMD {
  DSM_CMD_BIND_POWER_DOWN = 0, DSM_CMD_BIND_POWER_UP, DSM_CMD_BIND_SET_RX_OUT, DSM_CMD_BIND_SEND_PULSES,
  DSM_CMD_BIND_REINIT_UART
}
 

Functions

__EXPORT int dsm_init (const char *device)
 Initialize the DSM receive functionality. More...
 
__EXPORT void dsm_deinit (void)
 
__EXPORT void dsm_proto_init (void)
 
__EXPORT int dsm_config (int dsm_fd)
 
__EXPORT bool dsm_input (int dsm_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...
 
__EXPORT 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)
 

Detailed Description

RC protocol definition for Spektrum RC.

Author
Lorenz Meier loren.nosp@m.z@px.nosp@m.4.io

Function Documentation

§ dsm_init()

__EXPORT int dsm_init ( const char *  device)

Initialize the DSM receive functionality.

Open the UART for receiving DSM frames and configure it appropriately

Parameters
[in]deviceDevice name of DSM UART

§ dsm_input()

__EXPORT 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.

Parameters
[out]valuespointer to per channel array of decoded values
[out]num_valuespointer to number of raw channel values returned, high order bit 0:10 bit data, 1:11 bit data
[out]n_butesnumber of bytes read
[out]bytespointer to the buffer of read bytes
[out]rssivalue in percent, if supported, or 127
Returns
true=decoded raw channel values updated, false=no update