Talk:Protocol Decoder API
Protocol Decoder Framework
- Protocol decoders are written in Python.
- All Python modules in $PREFIX/share/sigrok/decoders are loaded by libsigrokdecode and are assumed to contain protocol decoders.
- Sigrok provides a module sigrok which provides the PDs an interface back to the sigrok core.
- This sigrok module defines an abstract object sigrok.Decoder from which all PDs will inherit.
- Currently PD modules must provide a subclass of sigrok.Decoder called Decoder described below.
The Decoder class
The Decoder object provided by all PD modules must provide these methods, which will be called by sigrok:
start(metadata)
This method is called by the front end when the DF_HEADER packet is received by the core datafeed. It is used to initialise the protocol decoder state machine. The single metadata parameter is a dictionary containing information about the stream. Currently contains these fields: driver, unitsize, starttime, and samplerate.
decode(data)
This method is called by the front end when the DF_LOGIC packet is received by the core datafeed. It is used to pass sample data to the PD instance. The format of the data parameter is likely to change, but is currently a dictionary with these fields time, duration, and data. data is currently a string of raw binary sample data which must be interpreted according to the unitsize field of the metadata passed to the start method. This is the number of bytes per sample.
The sigrok.Decoder superclass provided by the sigrok module defines a put method which the subclass must call to pass decoded data back to sigrok for passing on to the front end or the next decoder up the stack.