PX4 Firmware
PX4 Autopilot Software http://px4.io
sbus.h File Reference

RC protocol definition for S.BUS. More...

#include <stdint.h>
#include <stdbool.h>
Include dependency graph for sbus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SBUS_FRAME_SIZE   25
 
#define SBUS_BUFFER_SIZE   (SBUS_FRAME_SIZE + SBUS_FRAME_SIZE / 2)
 

Typedefs

typedef uint8_t sbus_frame_t[SBUS_FRAME_SIZE+(SBUS_FRAME_SIZE/2)]
 

Functions

__EXPORT int sbus_init (const char *device, bool singlewire)
 
__EXPORT int sbus_config (int sbus_fd, bool singlewire)
 Parse serial bytes on the S.BUS bus. More...
 
__EXPORT bool sbus_input (int sbus_fd, uint16_t *values, uint16_t *num_values, bool *sbus_failsafe, bool *sbus_frame_drop, uint16_t max_channels)
 
__EXPORT bool sbus_parse (uint64_t now, uint8_t *frame, unsigned len, uint16_t *values, uint16_t *num_values, bool *sbus_failsafe, bool *sbus_frame_drop, unsigned *frame_drops, uint16_t max_channels)
 
__EXPORT void sbus1_output (int sbus_fd, uint16_t *values, uint16_t num_values)
 
__EXPORT void sbus2_output (int sbus_fd, uint16_t *values, uint16_t num_values)
 
__EXPORT void sbus1_set_output_rate_hz (uint16_t rate_hz)
 
__EXPORT unsigned sbus_dropped_frames (void)
 The number of incomplete frames we encountered. More...
 

Detailed Description

RC protocol definition for S.BUS.

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

Definition in file sbus.h.

Macro Definition Documentation

◆ SBUS_BUFFER_SIZE

#define SBUS_BUFFER_SIZE   (SBUS_FRAME_SIZE + SBUS_FRAME_SIZE / 2)

Definition at line 50 of file sbus.h.

Referenced by RCInput::cycle(), and RCTest::sbus2Test().

◆ SBUS_FRAME_SIZE

#define SBUS_FRAME_SIZE   25

Definition at line 49 of file sbus.h.

Referenced by sbus1_output(), sbus_decode(), sbus_input(), and sbus_parse().

Typedef Documentation

◆ sbus_frame_t

typedef uint8_t sbus_frame_t[SBUS_FRAME_SIZE+(SBUS_FRAME_SIZE/2)]

Definition at line 52 of file sbus.h.

Function Documentation

◆ sbus1_output()

__EXPORT void sbus1_output ( int  sbus_fd,
uint16_t *  values,
uint16_t  num_values 
)

Definition at line 237 of file sbus.cpp.

References f(), hrt_absolute_time(), hrt_abstime, last_txframe_time, sbus1_frame_delay, SBUS_FRAME_SIZE, SBUS_SCALE_FACTOR, SBUS_SCALE_OFFSET, and write().

Referenced by mixer_tick(), and sbus2_output().

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

◆ sbus1_set_output_rate_hz()

__EXPORT void sbus1_set_output_rate_hz ( uint16_t  rate_hz)

Definition at line 705 of file sbus.cpp.

References sbus1_frame_delay, SBUS1_MAX_RATE_HZ, and SBUS1_MIN_RATE_HZ.

Referenced by registers_set_one().

Here is the caller graph for this function:

◆ sbus2_output()

__EXPORT void sbus2_output ( int  sbus_fd,
uint16_t *  values,
uint16_t  num_values 
)

Definition at line 276 of file sbus.cpp.

References sbus1_output().

Referenced by mixer_tick().

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

◆ sbus_config()

__EXPORT int sbus_config ( int  sbus_fd,
bool  singlewire 
)

Parse serial bytes on the S.BUS bus.

The S.bus protocol doesn't provide reliable framing, so we detect frame boundaries by the inter-frame delay.

The minimum frame spacing is 7ms; with 25 bytes at 100000bps frame transmission time is ~2ms.

If an interval of more than 4ms (7 ms frame spacing plus margin) passes between calls, the first byte we read will be the first byte of a frame.

In the case where byte(s) are dropped from a frame, this also provides a degree of protection. Of course, it would be better if we didn't drop bytes...

Definition at line 153 of file sbus.cpp.

References hrt_absolute_time(), last_rx_time, partial_frame_count, and sbus_frame_drops.

Referenced by RCInput::cycle(), RCInput::init(), and sbus_init().

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

◆ sbus_dropped_frames()

__EXPORT unsigned sbus_dropped_frames ( void  )

The number of incomplete frames we encountered.

Definition at line 128 of file sbus.cpp.

References sbus_decode(), and sbus_frame_drops.

Referenced by RCInput::print_status().

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

◆ sbus_init()

__EXPORT int sbus_init ( const char *  device,
bool  singlewire 
)

Definition at line 138 of file sbus.cpp.

References sbus_config().

Referenced by controls_init().

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

◆ sbus_input()

__EXPORT bool sbus_input ( int  sbus_fd,
uint16_t *  values,
uint16_t *  num_values,
bool *  sbus_failsafe,
bool *  sbus_frame_drop,
uint16_t  max_channels 
)

Definition at line 282 of file sbus.cpp.

References hrt_absolute_time(), hrt_abstime, last_rx_time, partial_frame_count, read(), SBUS2_DECODE_STATE_DESYNC, sbus_decode_state, sbus_frame_drops, SBUS_FRAME_SIZE, sbus_parse(), and SBUS_START_SYMBOL.

Referenced by controls_tick().

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

◆ sbus_parse()

__EXPORT bool sbus_parse ( uint64_t  now,
uint8_t *  frame,
unsigned  len,
uint16_t *  values,
uint16_t *  num_values,
bool *  sbus_failsafe,
bool *  sbus_frame_drop,
unsigned *  frame_drops,
uint16_t  max_channels 
)

Definition at line 343 of file sbus.cpp.

References last_rx_time, partial_frame_count, SBUS2_DECODE_STATE_DESYNC, SBUS2_DECODE_STATE_SBUS1_SYNC, SBUS2_DECODE_STATE_SBUS2_GPS, SBUS2_DECODE_STATE_SBUS2_RX_VOLTAGE, SBUS2_DECODE_STATE_SBUS2_SYNC, SBUS2_DECODE_STATE_SBUS_START, SBUS2_FRAME_SIZE_RX_VOLTAGE, sbus_decode(), sbus_decode_state, sbus_frame, sbus_frame_drops, SBUS_FRAME_SIZE, and SBUS_START_SYMBOL.

Referenced by RCInput::cycle(), RCTest::sbus2Test(), and sbus_input().

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