C++ SBUS library working on the Raspberry Pi and possibly any linux system with a serial port. To use the built-in UART on the RPi 3 make sure to use the PL011 (ttyAMA0) as the mini UART does not support parity. It is also possible to use a simple USB-Serial converter (expect latency with FTDI adapters, fix coming soon).
- Non-blocking and blocking modes
- Send & Receive
- All channels from 1 - 16
- Channels 17 and 18 (whatever they are for)
- Failsafe and frame lost bits
- Automatic recovery from hardware failures like broken wiring
SBUS protocol specification and original decoding function: https://github.com/bolderflight/SBUS
- Create a CMake project
- Clone this repo somewhere into your project
- Add
add_subdirectory(path/to/raspberry-sbus)
to your CMakeLists.txt - Link the library to your targets with
target_link_libraries(your_target PUBLIC sbuslib)
.
Example CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(my-sbus-project)
add_subdirectory(raspberry-sbus) # relative path to the cloned repo
add_executable(main main.cpp)
target_link_libraries(main PUBLIC sbuslib)
In blocking mode the read
function waits for at least one packet to be available (not using CPU time).
This mode is best used when your code contains a main loop that does not need to process anything when there are no packets.
You can also create a seperate thread for reading.
In non-blocking mode read
processes only available bytes and returns immediately.
This works like polling. You have to call read
as often as possible.
The most common use case is when your main loop does other things and only processes SBUS packets when one arrives.
#include <SBUS.h>
- Create
SBUS sbus
object sbus.install("/path/to/tty", blocking_mode)
to init the serial port
- Define packet callback
void packetCallback(sbus_packet_t packet) {/* handle packet */}
- Set packet callback with
sbus.onPacket(packetCallback)
- Call
sbus.read()
as often as possible to poll the serial port (non-blocking) or at least once per packet (blocking mode). In blocking moderead
will block and wait for a packet to arrive while non-blocking works by polling and returns immediately.
- Create
sbus_packet_t myPacket
object and populate its fields sbus.write(myPacket)
to send an SBUS packet
Look at examples folder for more.