diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2022-12-30 09:55:30 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2023-01-09 20:13:35 +0100 |
commit | e50276324056e37149b5456070a097170d49725b (patch) | |
tree | 30c9db0e9f554a4a91643607a8d205cbbaf61fc3 /decoders | |
parent | 912f4e8a245f014b312bfc90e4ec6dba256379d4 (diff) | |
download | libsigrokdecode-e50276324056e37149b5456070a097170d49725b.tar.gz libsigrokdecode-e50276324056e37149b5456070a097170d49725b.zip |
adf435x: rework emission of annotations
Separate data processing from text formatting in the code paths which
emit annotations. Introduce a local .putg() helper. This unobfuscates
the decoder's operation, and also happens to shorten text lines. Raises
awareness for zoom levels and alternative text during maintenance.
This commit incompatibly rephrases the "Wrong number of bits" message.
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/adf435x/pd.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/decoders/adf435x/pd.py b/decoders/adf435x/pd.py index 7810190..d234a81 100644 --- a/decoders/adf435x/pd.py +++ b/decoders/adf435x/pd.py @@ -118,6 +118,9 @@ class Decoder(srd.Decoder): def start(self): self.out_ann = self.register(srd.OUTPUT_ANN) + def putg(self, ss, es, cls, data): + self.put(ss, es, self.out_ann, [ cls, data, ]) + def decode_bits(self, offset, width): bits = self.bits[offset:][:width] ss, es = bits[-1][1], bits[0][2] @@ -125,9 +128,10 @@ class Decoder(srd.Decoder): return ( value, ( ss, es, )) def decode_field(self, name, offset, width, parser): - val, pos = self.decode_bits(offset, width) - self.put(pos[0], pos[1], self.out_ann, [ANN_REG, - ['%s: %s' % (name, parser(val) if parser else str(val))]]) + val, ( ss, es, ) = self.decode_bits(offset, width) + val = parser(val) if parser else str(val) + text = ['%s: %s' % (name, val)] + self.putg(ss, es, ANN_REG, text) return val def decode(self, ss, es, data): @@ -136,17 +140,24 @@ class Decoder(srd.Decoder): if ptype == 'TRANSFER': if len(self.bits) == 32: self.bits.reverse() - reg_value, reg_pos = self.decode_bits(0, 3) - self.put(reg_pos[0], reg_pos[1], self.out_ann, [ANN_REG, - ['Register: %d' % reg_value, 'Reg: %d' % reg_value, - '[%d]' % reg_value]]) + reg_value, ( reg_ss, reg_es, ) = self.decode_bits(0, 3) + text = [ + 'Register: %d' % reg_value, + 'Reg: %d' % reg_value, + '[%d]' % reg_value, + ] + self.putg(reg_ss, reg_es, ANN_REG, text) if reg_value < len(regs): field_descs = regs[reg_value] for field_desc in field_descs: field = self.decode_field(*field_desc) else: - error = "Frame error: Wrong number of bits: got %d expected 32" % len(self.bits) - self.put(ss, es, self.out_ann, [ANN_WARN, [error, 'Frame error']]) + text = [ + 'Frame error: Bit count: want 32, got %d' % len(self.bits), + 'Frame error: Bit count', + 'Frame error', + ] + self.putg(ss, es, ANN_WARN, text) self.bits.clear() if ptype == 'BITS': |