Skip to content

sbus_futaba: Add SBUS2 telemetry decoding and optimize performance - #135

Open
edwin-oetelaar wants to merge 7 commits into
sigrokproject:masterfrom
edwin-oetelaar:master
Open

sbus_futaba: Add SBUS2 telemetry decoding and optimize performance#135
edwin-oetelaar wants to merge 7 commits into
sigrokproject:masterfrom
edwin-oetelaar:master

Conversation

@edwin-oetelaar

Copy link
Copy Markdown

This commit adds full support for Futaba SBUS2 telemetry frames while significantly improving the decoder's execution performance and memory footprint.

Background:
Standard Futaba SBUS frames end with a 0x00 footer byte. SBUS2 receivers use non-zero footers (e.g. 0x04, 0x14, 0x24, 0x34) to request telemetry slot data (slots 0-7, 8-15, 16-23, 24-31). Following an inter-frame gap (~1960 µs), sensors and receivers respond with 3-byte telemetry slots. Previously, non-zero footers produced warnings and subsequent telemetry bytes triggered "excess data" warnings, causing frame decoding to fail.

Key Changes:

  • SBUS2 Telemetry Support:

    • Recognize valid SBUS2 telemetry footers and indicate requested telemetry slot groups in UI annotations.
    • Added a state machine transition to decode 3-byte telemetry packets (1-byte Slot ID + 2-byte 16-bit payload value) after inter-frame gaps.
    • Handled UART IDLE gaps between main servo frames and telemetry bursts seamlessly.
  • High-Performance Byte-Buffer Architecture:

    • Replaced bit-by-bit accumulator tuple parsing with byte-level buffering, eliminating thousands of micro-allocations per capture.
    • Implemented fast 11-bit channel extraction directly from the 22-byte payload using bitwise shifts.
  • Precise Sample Alignment & Visual Usability:

    • Added bit-level UART sample interpolation for Byte 23 (Digital Ch 17, 18, Frame Lost, Failsafe) and Channels 1-16. This prevents annotation overlapping in PulseView and ensures clean, distinct visual rendering.
  • Code Quality & Documentation:

    • Restructured state machine representation to use integer constants.
    • Added standardized docstrings (Brief, Params, Invariants, Output) to all methods.

Tested against live Futaba SBUS2 receiver captures containing receiver battery voltage telemetry slots in PulseView.

This commit adds full support for Futaba SBUS2 telemetry frames while
significantly improving the decoder's execution performance and memory footprint.

Background:
Standard Futaba SBUS frames end with a 0x00 footer byte. SBUS2 receivers
use non-zero footers (e.g. 0x04, 0x14, 0x24, 0x34) to request telemetry
slot data (slots 0-7, 8-15, 16-23, 24-31). Following an inter-frame gap
(~1960 µs), sensors and receivers respond with 3-byte telemetry slots.
Previously, non-zero footers produced warnings and subsequent telemetry
bytes triggered "excess data" warnings, causing frame decoding to fail.

Key Changes:
- SBUS2 Telemetry Support:
  * Recognize valid SBUS2 telemetry footers and indicate requested telemetry
    slot groups in UI annotations.
  * Added a state machine transition to decode 3-byte telemetry packets
    (1-byte Slot ID + 2-byte 16-bit payload value) after inter-frame gaps.
  * Handled UART IDLE gaps between main servo frames and telemetry bursts seamlessly.

- High-Performance Byte-Buffer Architecture:
  * Replaced bit-by-bit accumulator tuple parsing with byte-level buffering,
    eliminating thousands of micro-allocations per capture.
  * Implemented fast 11-bit channel extraction directly from the 22-byte payload
    using bitwise shifts.

- Precise Sample Alignment & Visual Usability:
  * Added bit-level UART sample interpolation for Byte 23 (Digital Ch 17, 18,
    Frame Lost, Failsafe) and Channels 1-16. This prevents annotation overlapping
    in PulseView and ensures clean, distinct visual rendering.

- Code Quality & Documentation:
  * Restructured state machine representation to use integer constants.
  * Added standardized docstrings (Brief, Params, Invariants, Output) to all methods.

Tested against live Futaba SBUS2 receiver captures containing receiver battery
voltage telemetry slots in PulseView.

@edwin-oetelaar edwin-oetelaar left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi everyone,

I noticed that the current sbus_futaba decoder has trouble decoding frames from Futaba SBUS2 receivers when telemetry is enabled, as non-zero footers and telemetry response bytes trigger unexpected warnings.

I have updated the decoder to support SBUS2 telemetry decoding while also refactoring the internal bit-accumulator logic into a high-performance byte-buffer architecture for significantly faster decoding in PulseView.

Summary of Changes

  • SBUS2 Telemetry: Added support for non-zero footers (0x04, 0x14, etc.) and decoding of 3-byte telemetry slots (Slot ID + 16-bit payload).
  • Performance: Replaced bit-by-bit tuple slicing with direct byte-buffer bitwise unpacking.
  • UI & Alignment: Added bit-accurate sample timing interpolation for Digital channels (Ch 17, 18), flags (Frame Lost, Failsafe), and Proportional channels so annotations render cleanly without overlapping in PulseView.
  • Code Quality: Added docstrings (Brief, Params, Invariants, Output) to all methods and converted state flags to integer constants.

Tested on a physical SBUS2 receiver trace with receiver battery voltage telemetry.

Feedback and suggestions are very welcome!

Best regards,
Edwin van den Oetelaar

@edwin-oetelaar

Copy link
Copy Markdown
Author

added some more decoding of telemetry :

SBUS2 telemetry decoding now recognizes sensor type flags:
0xC0: voltage, decoded in 0.1 V steps
0xC4: current, decoded in mA
Other flags: retained as raw 16-bit telemetry values
Decoded values are available as graphical annotations and Python output packets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants