summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Pelissier <sylvain.pelissier@gmail.com>2019-07-19 14:32:01 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2019-08-30 01:19:05 +0200
commit9b61fbd1b54df4a4e4b0e42dd89a5891c71f6fb2 (patch)
treea766611bd0070f337beda15e51cd42a66ac95fd3
parent5e82e3c666ac2180d6b9a1e67eed25693de0c6ef (diff)
downloadlibsigrokdecode-9b61fbd1b54df4a4e4b0e42dd89a5891c71f6fb2.tar.gz
libsigrokdecode-9b61fbd1b54df4a4e4b0e42dd89a5891c71f6fb2.zip
eeprom93xx: Add ascii format support
-rw-r--r--decoders/eeprom93xx/pd.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/decoders/eeprom93xx/pd.py b/decoders/eeprom93xx/pd.py
index 7b64e59..68649b5 100644
--- a/decoders/eeprom93xx/pd.py
+++ b/decoders/eeprom93xx/pd.py
@@ -32,6 +32,8 @@ class Decoder(srd.Decoder):
options = (
{'id': 'addresssize', 'desc': 'Address size', 'default': 8},
{'id': 'wordsize', 'desc': 'Word size', 'default': 16},
+ {'id': 'format', 'desc': 'Data format', 'default': 'hex',
+ 'values': ('ascii', 'hex')},
)
annotations = (
('si-data', 'SI data'),
@@ -69,8 +71,20 @@ class Decoder(srd.Decoder):
d = data[b].si if si else data[b].so
word += (d << (len(data) - b - 1))
idx = 0 if si else 1
- self.put(data[0].ss, data[-1].es,
- self.out_ann, [idx, ['Data: 0x%x' % word, '0x%x' % word]])
+
+ if self.options['format'] == 'ascii':
+ word_str = ''
+ for s in range(0, len(data), 8):
+ c = 0xff & (word >> s)
+ if c in range(32, 126 + 1):
+ word_str = chr(c) + word_str
+ else:
+ word_str = '[{:02X}]'.format(c) + word_str
+ self.put(data[0].ss, data[-1].es,
+ self.out_ann, [idx, ['Data: %s' % word_str, '%s' % word_str]])
+ else:
+ self.put(data[0].ss, data[-1].es,
+ self.out_ann, [idx, ['Data: 0x%x' % word, '0x%x' % word]])
def decode(self, ss, es, data):
if len(data) < (2 + self.addresssize):