]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/ieee488/pd.py
ieee488: support optional parity for ATN commands (for HP gear)
[libsigrokdecode.git] / decoders / ieee488 / pd.py
index e39ecc549b207fcd4a390f7c3abbdb7d4d6a8444..0451c14f4f0edb494e66a258278dd060cbd76b42 100644 (file)
@@ -288,6 +288,8 @@ class Decoder(srd.Decoder):
             'default': 'no', 'values': ('no', 'yes')},
         {'id': 'delim', 'desc': 'Payload data delimiter',
             'default': 'eol', 'values': ('none', 'eol')},
+        {'id': 'atn_parity', 'desc': 'ATN commands use parity',
+            'default': 'no', 'values': ('no', 'yes')},
     )
     annotations = (
         ('bit', 'IEC bit'),
@@ -300,7 +302,7 @@ class Decoder(srd.Decoder):
         ('eoi', 'EOI'),
         ('text', 'Talker text'),
         ('periph', 'IEC bus peripherals'),
-        ('warn', 'Warning'),
+        ('warning', 'Warning'),
     )
     annotation_rows = (
         ('bits', 'IEC bits', (ANN_RAW_BIT,)),
@@ -309,7 +311,7 @@ class Decoder(srd.Decoder):
         ('eois', 'EOI', (ANN_EOI,)),
         ('texts', 'Talker texts', (ANN_TEXT,)),
         ('periphs', 'IEC peripherals', (ANN_IEC_PERIPH,)),
-        ('warns', 'Warnings', (ANN_WARN,)),
+        ('warnings', 'Warnings', (ANN_WARN,)),
     )
     binary = (
         ('raw', 'Raw bytes'),
@@ -486,6 +488,13 @@ class Decoder(srd.Decoder):
             upd_iec = False,
             py_type = None
             py_peers = False
+            if self.options['atn_parity'] == 'yes':
+                par = 1 if b & 0x80 else 0
+                b &= ~0x80
+                ones = bin(b).count('1') + par
+                if ones % 2:
+                    warn_texts = ['Command parity error', 'parity', 'PAR']
+                    self.emit_warn_ann(self.ss_raw, self.es_raw, warn_texts)
             is_cmd, is_unl, is_unt = _is_command(b)
             laddr = _is_listen_addr(b)
             taddr = _is_talk_addr(b)