Typically, in a Python protocol decoder plugin for sigrok, we can find where a signal transition happened, by using self.wait, e.g:
``` # let's say our signal 0 is in "HIGH" level/state now, and self.samplenum is 0 # we want to find transition to low, so we use self.wait: (mysig,) = self.wait({0: 'l'}) # after self.wait returns, self.samplenum is (say) at 1000, first sample location away from 0 which has a "LOW" level/state ``` However, as the example notes, self.wait also manipulates self.samplenum; and it is noted: https://sigrok.org/wiki/Protocol_decoder_API/Queries
self.samplenum is a special attribute that is read-only for the protocol decoder and should only be set by the libsigrokdecode backend.
So, this is the problem I have: Let's say, I'm at the (first) low bit, right after a transition from HIGH to LOW; let's say samplenum here ("now") is 1000. If the next transition LOW to HIGH happens in less than 1000 samples duration, then I should decode (serial) bits - meaning I have to read sample-by-sample into an accumulator, find the average to determine final bit value (let's say a "bit" takes 10 samples in my signal data), and emit (PulseView) annotation for each bit, starting from "now" (samplenum=1000). However, if the next transition LOW to HIGH happens in more than 1000 samples, then I should *not* decode bits - instead I should have a single annotation from "now" (samplenum 1000) to wherever the "next" transition is, and I should proceed in a different state (other than "decode bits") after the "next" transition happens. Easiest for me, was to have a "CHECK NEXT STATE" state, as in: ``` if self.state == 'CHECK NEXT STATE': # we should be in low state here, - so we wait for a high transition (mysig,) = self.wait({0: 'h'}) # we have a new samplenum here, for the transition; calc the duration runlen = (self.samplenum - self.run_start) # if runlen is >= 1000, declare SOMETHING ELSE state if runlen >= 1000: self.state = 'SOMETHING ELSE' else: self.state = 'DECODE BITS' # "rewind", so the state detection works: self.samplenum = self.run_start - 1 self.run_start = self.samplenum ``` ... which sorta makes sense in general; except, its impossible to "rewind" self.samplenum - as it is read only! Right now, when I hit a situation where 'SOMETHING ELSE' should be declared, I just get a bunch of wrongly decoded bits in PulseView instead, because I do the 'DECODE BITS' explicitly each time - which I do not want. I guess, I could still do the 'DECODE BITS' with the faulty bits, and once enough time (1000 samples) have passed, checked whether the state changes from last 'CHECK NEXT STATE' - and if it didn't, then erase all annotations added by the last 'DECODE BITS' ... but I cannot tell how to erase *only* those annotations !? So, how is something like this - that is, "peeking"/finding signal transitions into the "future" from "now" (that is, current samplenum), without changing samplenum - meant to be handled in a Python protocol decoder for sigrok/pulseview? _______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel