X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fcan%2Fpd.py;h=c92877b556db18a0de9c05ccce71fded631549af;hb=eb6360c9b161e77c6a04479a08c581306ffb9818;hp=af8168ce5eb3f48da403e1b9b4153bc35b75c9ed;hpb=b0918d40e285e7782f4e86356c41648dc748e477;p=libsigrokdecode.git diff --git a/decoders/can/pd.py b/decoders/can/pd.py index af8168c..c92877b 100644 --- a/decoders/can/pd.py +++ b/decoders/can/pd.py @@ -20,8 +20,11 @@ import sigrokdecode as srd +class SamplerateError(Exception): + pass + class Decoder(srd.Decoder): - api_version = 1 + api_version = 2 id = 'can' name = 'CAN' longname = 'Controller Area Network' @@ -29,7 +32,7 @@ class Decoder(srd.Decoder): license = 'gplv2+' inputs = ['logic'] outputs = ['can'] - probes = ( + channels = ( {'id': 'can_rx', 'name': 'CAN RX', 'desc': 'CAN bus line'}, ) options = ( @@ -54,14 +57,18 @@ class Decoder(srd.Decoder): ('ack-delimiter', 'ACK delimiter'), ('stuff-bit', 'Stuff bit'), ('warnings', 'Human-readable warnings'), + ('bit', 'Bit'), + ) + annotation_rows = ( + ('bits', 'Bits', (15, 17)), + ('fields', 'Fields', tuple(range(15)) + (16,)), ) - def __init__(self, **kwargs): + def __init__(self): self.samplerate = None self.reset_variables() def start(self): - # self.out_python = self.register(srd.OUTPUT_PYTHON) self.out_ann = self.register(srd.OUTPUT_ANN) def metadata(self, key, value): @@ -113,8 +120,6 @@ class Decoder(srd.Decoder): return False # Stuff bit. Keep it in self.rawbits, but drop it from self.bits. - self.putx([15, ['Stuff bit: %d' % self.rawbits[-1], - 'SB: %d' % self.rawbits[-1], 'SB']]) self.bits.pop() # Drop last bit. return True @@ -303,14 +308,13 @@ class Decoder(srd.Decoder): # Get the index of the current CAN frame bit (without stuff bits). bitnum = len(self.bits) - 1 - # For debugging. - # self.putx([0, ['Bit %d (CAN bit %d): %d' % \ - # (self.curbit, bitnum, can_rx)]]) - # If this is a stuff bit, remove it from self.bits and ignore it. if self.is_stuff_bit(): + self.putx([15, [str(can_rx)]]) self.curbit += 1 # Increase self.curbit (bitnum is not affected). return + else: + self.putx([17, [str(can_rx)]]) # Bit 0: Start of frame (SOF) bit if bitnum == 0: @@ -359,8 +363,8 @@ class Decoder(srd.Decoder): self.curbit += 1 def decode(self, ss, es, data): - if self.samplerate is None: - raise Exception("Cannot decode without samplerate.") + if not self.samplerate: + raise SamplerateError('Cannot decode without samplerate.') for (self.samplenum, pins) in data: (can_rx,) = pins @@ -377,6 +381,3 @@ class Decoder(srd.Decoder): if not self.reached_bit(self.curbit): continue self.handle_bit(can_rx) - else: - raise Exception("Invalid state: %s" % self.state) -