diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-27 21:15:20 +0200 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-08-30 07:23:58 +0200 |
commit | c328c18123c83e0f1e54181b9634bec76a2e3c43 (patch) | |
tree | b6f05e1aea941c21e8dc394119e31312172daa6d /decoders | |
parent | 52f08e6d879d8f82e01eb581646a5c929f21d6b8 (diff) | |
download | libsigrokdecode-c328c18123c83e0f1e54181b9634bec76a2e3c43.tar.gz libsigrokdecode-c328c18123c83e0f1e54181b9634bec76a2e3c43.zip |
sle44xx: rephrase annotation text construction
Concentrate all text variants for zoom levels in a single spot. Remove
duplicates, and on the other hand add more verbose phrases to support
users which are not intimately familiar with the protocol. Prefer the
Python strings .format() method over the % operator for its versatility
and readability.
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/sle44xx/pd.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/decoders/sle44xx/pd.py b/decoders/sle44xx/pd.py index 25b1cc2..02bea42 100644 --- a/decoders/sle44xx/pd.py +++ b/decoders/sle44xx/pd.py @@ -28,14 +28,23 @@ class Ann: class Bin: SEND_DATA, = range(1) -# CMD: [annotation class index, long annotation, short annotation] +# CMD: [annotation class index, annotation texts for zoom levels] proto = { - 'ATR': [Ann.ATR, 'ATR', 'ATR'], - 'CMD': [Ann.CMD, 'Command', 'C'], - 'DATA': [Ann.DATA, 'Data', 'D'], - 'RESET': [Ann.RESET, 'Reset', 'R'], + 'BIT': [Ann.BIT, '{bit}',], + 'ATR': [Ann.ATR, 'Answer To Reset: {data:02x}', 'ATR: {data:02x}', '{data:02x}',], + 'CMD': [Ann.CMD, 'Command: {data:02x}', 'Cmd: {data:02x}', '{data:02x}',], + 'DATA': [Ann.DATA, 'Data: {data:02x}', '{data:02x}',], + 'RESET': [Ann.RESET, 'Reset', 'R',], } +def lookup_proto_ann_txt(cmd, variables): + ann = proto.get(cmd, None) + if ann is None: + return None, [] + cls, texts = ann[0], ann[1:] + texts = [t.format(**variables) for t in texts] + return cls, texts + class Decoder(srd.Decoder): api_version = 3 id = 'sle44xx' @@ -93,8 +102,9 @@ class Decoder(srd.Decoder): def handle_reset(self, pins): self.ss, self.es = self.samplenum, self.samplenum - cmd = 'RESET' # No need to set the global self.cmd as this command is atomic - self.putx([proto[cmd][0], proto[cmd][1:]]) + self.cmd = 'RESET' + cls, texts = lookup_proto_ann_txt(self.cmd, {}) + self.putx([cls, texts]) self.bitcount = self.databyte = 0 self.bits = [] self.cmd = 'ATR' # Next data bytes will be ATR @@ -137,11 +147,12 @@ class Decoder(srd.Decoder): self.putb([Bin.SEND_DATA, bytes([self.databyte])]) - for bit in self.bits: - self.put(bit[1], bit[2], self.out_ann, [Ann.BIT, ['%d' % bit[0]]]) + for bit_val, bit_ss, bit_es in self.bits: + cls, texts = lookup_proto_ann_txt('BIT', {'bit': bit_val}) + self.put(bit_ss, bit_es, self.out_ann, [cls, texts]) - self.putx([proto[self.cmd][0], ['%s: %02X' % (proto[self.cmd][1], self.databyte), - '%s: %02X' % (proto[self.cmd][2], self.databyte), '%02X' % self.databyte]]) + cls, texts = lookup_proto_ann_txt(self.cmd, {'data': self.databyte}) + self.putx([cls, texts]) # Done with this packet. self.bitcount = self.databyte = 0 |