APM:Libraries
Macros | Functions | Variables
dsm.cpp File Reference
#include <stdint.h>
#include <stdio.h>
#include "dsm.h"
Include dependency graph for dsm.cpp:

Go to the source code of this file.

Macros

#define DSM_FRAME_SIZE   16
 
#define DSM_FRAME_CHANNELS   7
 
#define debug(fmt, args...)   do {} while(0)
 

Functions

static bool dsm_decode_channel (uint16_t raw, unsigned shift, unsigned *channel, unsigned *value)
 
static void dsm_guess_format (bool reset, const uint8_t dsm_frame[16])
 
bool dsm_decode (uint64_t frame_time, const uint8_t dsm_frame[16], uint16_t *values, uint16_t *num_values, uint16_t max_values)
 

Variables

static uint64_t dsm_last_frame_time
 
static unsigned dsm_channel_shift
 

Macro Definition Documentation

◆ debug

#define debug (   fmt,
  args... 
)    do {} while(0)

Definition at line 54 of file dsm.cpp.

Referenced by dsm_guess_format().

◆ DSM_FRAME_CHANNELS

#define DSM_FRAME_CHANNELS   7

Max supported DSM channels

Definition at line 44 of file dsm.cpp.

Referenced by dsm_decode(), and dsm_guess_format().

◆ DSM_FRAME_SIZE

#define DSM_FRAME_SIZE   16

DSM frame size in bytes

Definition at line 43 of file dsm.cpp.

Referenced by dsm_decode().

Function Documentation

◆ dsm_decode()

bool dsm_decode ( uint64_t  frame_time,
const uint8_t  dsm_frame[16],
uint16_t *  values,
uint16_t *  num_values,
uint16_t  max_values 
)

Decode the entire dsm frame (all contained channels)

Definition at line 195 of file dsm.cpp.

Referenced by F4Light::PPM_parser::_process_dsm_pulse(), Linux::RCInput::_process_dsm_pulse(), Linux::RCInput::add_dsm_input(), dsm_decode(), F4Light::DSM_parser::init(), and AP_RCProtocol_DSM::process_pulse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dsm_decode_channel()

static bool dsm_decode_channel ( uint16_t  raw,
unsigned  shift,
unsigned *  channel,
unsigned *  value 
)
static

Attempt to decode a single channel raw channel datum

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
[in]raw16 bit raw channel value from dsm frame
[in]shiftposition of channel number in raw data
[out]channelpointer to returned channel number
[out]valuepointer to returned channel value
Returns
true=raw value successfully decoded

Definition at line 83 of file dsm.cpp.

Referenced by dsm_decode(), and dsm_guess_format().

Here is the caller graph for this function:

◆ dsm_guess_format()

static void dsm_guess_format ( bool  reset,
const uint8_t  dsm_frame[16] 
)
static

Attempt to guess if receiving 10 or 11 bit channel values

Parameters
[in]resettrue=reset the 10/11 bit state to unknown

Definition at line 105 of file dsm.cpp.

Referenced by dsm_decode().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ dsm_channel_shift

unsigned dsm_channel_shift
static

Channel resolution, 0=unknown, 10=10 bit, 11=11 bit

Definition at line 47 of file dsm.cpp.

Referenced by dsm_decode(), and dsm_guess_format().

◆ dsm_last_frame_time

uint64_t dsm_last_frame_time
static

Timestamp for start of last dsm frame

Definition at line 46 of file dsm.cpp.

Referenced by dsm_decode().