Debugging a new Sigrok Pulseview Protocol Decoder -- where is the error log?  - Page 1
Forum section: electronics / projects

author: AndySymons
author_rank: Newbie
timestamp: September 24, 2024, 06:07:15 pm
content: I am a noob to Sigrok and to Python programming, but have 40 years experience in programming and engineering in general. I can follow a guide! Sadly Sigrok's guides that I have found so far are rather skimpy...https://sigrok.org/wiki/Protocol_decoder_HOWTO#Fileshttps://sigrok.org/wiki/Protocol_decoder_APIhttps://sigrok.org/wiki/Protocol_decoder_API/QueriesI have created a new protocol decoder (PD) for PulseView. I initially copied an existing one (I2C) and installed it using the procedure I describe is a previous topic (https://www.eevblog.com/forum/projects/how-to-install-custom-sigrok-pulseview-protocol-decoder/msg5650791/#msg5650791).It runs OK initially. I can invoke it from within PulseView and it produces results (which are incorrect because I am still developing it). Now I am modifying it iteratively as I reverse-engineer the protocol in question -- for details of the project see my GitHub repository:https://github.com/AndySymons/KELLY-Scantronic-994x-Keypad/wikiIf I make an error in my PD coding, PulseView says 'decoder reported an error'.So where is the error reported?Is there a log flle somewhere? Clearly I need a line number and error description to track it down and correct it. I would get this in the IDE if I were to run a stand-alone Python program, but in this case it is running within the Sigroklibsigrokdecodeenvironment, which is written in C and runs within the PulseView app.I can fix small errors by taking baby steps, keeping previous versions and code inspection but that is not sufficient when making major changes.Can anyone from Sigrok or with experience of writing a libsigrokdecode Protocol Decoder tell me how you debug a new PD or point me to a guide that is not in the list above?

author: bson
author_rank: Unknown
timestamp: September 24, 2024, 07:56:16 pm
content: Clone the repos and search for the string, see where it logs to, see what file that is.Unfortunately, with dynamically typed languages, only an iota of static analysis and poorly documented software (the only design doc amounting to an automatically generated API reference broken into a gazillion separate files, leaving it to the reader to figure out how this actually works), going through the source is the only option. It looks reasonably well factored and straightforward.I couldn't find the string 'decoder reported' anywhere in pulseview or libsigrok, but there are more libraries or maybe it was slightly different (I hate when software displays errors but won't allow copying it for purely aesthetic reasons - that's beyond bad UI design).

author: bson
author_rank: Unknown
timestamp: September 24, 2024, 11:03:21 pm
content: I just tested on Fedora by throwing an exception in a clone of the i2c decoder, and if I run pulseview from a terminal the exception and any other errors are output to the terminal.I was always a fan of MacOS, as a BSD flavor Unix with a well-done UI and plenty of software. But over the years they've deviated so far from that I finally gave up on it and will be sticking to Linux unless there's something I specifically need in which case I can pull out the M1 Max MBP. But most of my use is dev related, and Linux is a vastly better platform for that these days. Just such a thing as no support for Mach-O executables in binutils, and no gdb port for it is kind of crippling, ties you into xcode - which is a bloated, useless pig IMO, whose only meaningful purpose is to build Apple ecosystem apps. And that's fine, but I haven't written an Apple app in... probably 15 years, at least.

author: sharow
author_rank: Contributor
timestamp: September 25, 2024, 07:10:53 am
content: I recommend using sigrok-cli instead of PulseView.https://sigrok.org/wiki/Sigrok-cliWhile PulseView is user-friendly, it acts as a smoke screen for developers working on decoders.The wiki mentions, "It is recommended to capture the data first and process them later." This is worth reiterating here: your focus should be on developing the decoder, not on integration testing. PulseView forces integration test-like actions.You can set own decoder path using SIGROKDECODE_DIR.Error-log issue you mentioning is not issue with sigrok-cli.Code:$ sigrok-cli --versionsigrok-cli 0.7.2~~ snip ~~$$ find ./mydecodersmydecodersmydecoders/foomydecoders/foo/pd.pymydecoders/foo/__init__.py$$ SIGROKDECODE_DIR=./mydecoders sigrok-cli -L | grep foofoo foo$Even you can call breakpoint() in your decoder, it's like gdb-like debugger pdb.This is not easily done in PulseView.https://docs.python.org/3/library/functions.html#breakpointhttps://docs.python.org/3/library/pdb.htmlCode:$ SIGROKDECODE_DIR=./mydecoders sigrok-cli -P foo -I binary -i ./test.sr> <~~snip~~>/mydecoders/foo/pd.py(166)decode()-> print('foooooooooooooo!')(Pdb) list161 zero = 0162163 while True:164 if self.debug:165 breakpoint()166 -> print('foooooooooooooo!')167 x = [1,2,3]168 print('foo!')169 prevtime = curtime170171(Pdb) p self<foo.pd.Decoder object at 0x7508ee7b5580>(Pdb) p self.__dict__{'num_channels': 8, 'samplerate': None, 'increment': <foo.pd.Value object at 0x7508eed358b0>, 'count': <foo.pd.Value object at 0x7508eed35550>, ~~ snip ~~ }

author: AndySymons
author_rank: Newbie
timestamp: September 25, 2024, 08:36:37 am
content: Thanks everyone.It looks like the CLI approach is the way to go. I have both MacOS and Linux systems available, so can try both...

author: AndySymons
author_rank: Newbie
timestamp: September 25, 2024, 07:12:58 pm
content: Update: I spent all day on this because Sigrok documentation is rather unclear for a noob (it's all detail without context).I first tried installingsigrok-clion MacOS but failed because I cannot meet its strange prerequisites:One prerequisite is that it wantsqt@5.5, which does not seem to exist. I tried installing qt@5 from the qt website but it said it could not be installed on my rather old Mac running OSX Catalina 10.15.7.The second is that is wants python@2even though the documentation says it uses Python 3. I installed python@2 anyway, but even after I had, thesigrok-cliinstaller still said it needed it!I therefore switched to my Debian 11 Linux system, where I had more success.I first tried the packaged versions of sigrok-cli and pulseview. Pulseview worked fine but sigrok-cli does not do anything if you run the deb file as an executable, so I don't know what use this is?I therefore went to the build procedures pagehttps://sigrok.org/wiki/Building.Sigrok-cliturns out to need other components, which in turn seem to have their interdependencies. The Sigrok documentation sends you in circles with the prerequisites, so I ended up downloading them all, one at a time for all of the components in the suitelibserialport, libsigrok, libsigrokdecode, pulseview, sigrok-cli,andsigrok-util. I then did all the builds, as detailed onhttps://sigrok.org/wiki/Building. A good couple of hours work!The Sigrok instructions do not say where to put all the files. I therefore made up my own directory structure; I created aSigrokdirectory in my user home directory/home/andrewsymons/and put each of the components in subfolders created by the build procedures:libserialport, libsigrok, libsigrokdecode, pulseview, sigrok-cli,andsigrok-util.Note that they forget to tell you that after entering each component directory to complete the install, you need to go back to your base directory before doing the next one, otherwise they all get nested!Both the packaged and built versions ofpulseviewwork OK.Pulseview opens the grahic window as on the Mac.My first test ofsigrok-cliwas to runCode:$ sigrok-cli -hand get the help page. That proves the app is installed.The Sigrok instructions do not suggest any structure for the test environment. After several runs at it, I ended up with a test environment directory,SAKIP-testenv, in my user home directory (next toSigrok), which contains amongst other things asample-datadirectory and adecodersdirectory.Unfortunately, I have been unable to connect my Logic Analyzer to Pulseview on the Linux system, even though the USB port is recognised fine, so I have to capture the data on my iMac with Pulseview there, save the data, and then transfer the file to the Linux system using a USB stick with FAT format! That is a bit tedious, but I have now successfully connected to the input file with this command issued from mySAKIP-testenvdirectory:Code:$ sigrok-cli -i "sample-data/240925-1038-system-startup" -I binaryIt produces a long binary listing.Thedecoderssubdirectorysakipcontains the__init__.pyandpd.pyfiles that I am developing. This is the same structure and files that worked with the MaxOS Pulseview app.The Sigrok instructions inhttps://sigrok.org/wiki/Protocol_decoder_HOWTOfor the SIGROKDECODE_DIR environment variable look completely wrong.Sigrok-clireported that it could not find the decoder. I think the command should be (in my case)Code:$ export SIGROKDECODE_DIR=/home/andrewsymons/SAKIP-testenv/decoders/If I do this, then the commandCode:$ sigrok-cli -i "sample-data/240925-1038-system-startup" -I binary -P sakipreturns an error "Failed to load decoder sakip: annotation class/row IDs contain duplicates" -- which at least suggests it is finding the decoder. I have yet to find out why it has this error.Development continues, but it looks like I am on the right track ...

author: bson
author_rank: Unknown
timestamp: September 25, 2024, 08:31:09 pm
content: Quote from: AndySymons on September 25, 2024, 07:12:58 pmThis is exactly why I switched to Linux; it's the path of least resistance. Once it works on Linux any remaining platform problems on MacOS and Windoze can be ironed out. At least that point they're clearly platform issues so narrows down the problem.