Skip to content

Adding a Protocol Decoder

Val edited this page Nov 17, 2026 · 2 revisions

Protocol decoders live in src/decode/ and include/openosc/decode/. This page shows where a new protocol plugs in. Open an issue first to agree on the scope.

How decoding runs

  1. The scope publishes a finished record (both channels).
  2. A job (decode/job.hpp) converts the samples of the source channels into logic transitions, using the per-channel threshold, hysteresis and minimum pulse (decode/threshold.hpp).
  3. The job feeds the transitions to the protocol's state machine in record order, block by block.
  4. The machine writes events into a fixed-size ResultSet (decode/result.hpp). A full set counts further events as lost.
  5. The UI (table, strip, detail) and the CSV export (decode/csv_export.hpp) read the published result.

All work is done in slices from the main loop; memory is fixed and lives in the decoder workspace in ITCM.

The interface

class ProtocolDecoder {
public:
    virtual void start(ResultSet &result, int initialLevel) = 0;                         // new record
    virtual void feed(const Transition *transitions, unsigned count, ResultSet &result) = 0; // a block
    virtual void finish(uint32_t samples, ResultSet &result) = 0;                         // record end
};

State is kept between feed() calls. An event never spans two records.

Steps

  1. State machine: add include/openosc/decode/protocols/<name>.hpp and src/decode/protocols/<name>.cpp, implementing ProtocolDecoder. It must be trivially destructible and fit the shared storage.
  2. Machine registry: add it to the Storage union and to ProtocolMachine::configure() in decode/machine.hpp / machine.cpp.
  3. Settings: add the protocol to enum class Protocol and its options to decoding::Settings (decode/settings.hpp), with validation, hash(), the source channels and JSON load/save.
  4. Panel: add its rows to DecoderProperties::layout() (ui/editors/decoder_properties.cpp).
  5. Table and CSV: event text in decode/table_text.* and the CSV columns in decode/export/.
  6. SCPI: DECode:PROTocol? returns the protocol's name.

Rules

  • Mark doubtful events honestly (?, CUT, error flags) instead of guessing.
  • Reject timing the record cannot resolve (too few samples per bit) instead of producing garbage.
  • No heap, no large stack frames.
  • Test with recorded and generated signals, and say in the pull request what you tested on hardware.

Clone this wiki locally