Protocol decoder scripting methodology

In this chapter, we’ll present a methodology that we recommend when writing a script that decodes a specific protocol.

Please note that this is just a recommendation, and we believe this to be an effective way of quickly developing protocol decoder scripts. That being said, depending on the specific protocol you’re attempting to write, or the tasks carried by the script, this may not be the best approach.

Obviously, it’s mandatory to fully understand how the protocol works and obtain all necessary documentation that describes all timings, waveform, packetization, CRC calculations or whatever specificity for that protocol.

First, we start by including the mandatory entry point function on_decode_signals and on_draw_gui_decoder so that ScanaStudio can detect this script as a valid signal decoder script. It’s okay if those functions are empty at that moment.

According to this methodology, we start by writing the decoder GUI function (on_draw_gui_decoder). This is usually a simple straight forward task. One can easily test how the GUI looks like by adding the script to a ScanaStudio workspace.

The next step is to write the signal builder object for that protocol (the ScanaStudio.BuilderObject object). The builder object should be a fully independent piece of code, so that it can be included in any other script.

Once the ScanaStudio.BuilderObject is written, we can start testing it by writing the demo signal generation function: on_build_demo_signals.

As soon as this function is implemented, we can add this script to a demo ScanaStudio workspace (no any device connected) and hit the start button: ScanaStudio will launch the on_build_demo_signals function and generate the demo signals.

At this point, the design loop described in the image below can start:

script writing methodology

This design loop will help you to quickly converge your script into a fully functional and tested protocol decoder script. You start by writing/testing/debugging the BuilderObject for a particular configuration (that was set in the script GUI), then, the on_decode_signals can be written and tested. Sometimes, one may find bugs in the BuilderObject while testing the signal decoder and vice versa.

In other words, the BuilderObject helps you to debug the signal decoder, and the signal decoder helps you to debug the BuilderObject.