Hi

I have added support for extended addresses to the ir_nec decoder.

I found that the error detection code in the decoder did not detect all
error conditions. 
The check should be that the address byte is followed by its
complement, and similary for the data byte.
The first patch ir_nec_errordetect.patch fixes this bug.

The second patch ir_nec_extended.patch adds support for extended
addresses where the second byte is used as part of the error check
instead of for error detection.

The data file is from a NAD remote and contains one command with
extended addressing followed by 3 repeat codes.


Søren Wedel Nielsen

diff --git a/decoders/ir_nec/pd.py b/decoders/ir_nec/pd.py
index bb52420..2d5f781 100644
--- a/decoders/ir_nec/pd.py
+++ b/decoders/ir_nec/pd.py
@@ -140,7 +140,8 @@ def handle_bit(self, tick):
         self.ss_bit = self.samplenum
 
     def data_ok(self):
-        ret, name = (self.data >> 8) & (self.data & 0xff), self.state.title()
+        ret = (self.data >> 8) ^ (self.data & 0xff) == 0xff
+        name = self.state.title()
         if self.count == 8:
             if self.state == 'ADDRESS':
                 self.addr = self.data
@@ -149,13 +150,13 @@ def data_ok(self):
             self.putd(self.data)
             self.ss_start = self.samplenum
             return True
-        if ret == 0:
+        if ret:
             self.putd(self.data >> 8)
         else:
             self.putx([12, ['%s error: 0x%04X' % (name, self.data)]])
         self.data = self.count = 0
         self.ss_bit = self.ss_start = self.samplenum
-        return ret == 0
+        return ret
 
     def decode(self):
         if not self.samplerate:
diff --git a/decoders/ir_nec/pd.py b/decoders/ir_nec/pd.py
index 2d5f781..5212c4e 100644
--- a/decoders/ir_nec/pd.py
+++ b/decoders/ir_nec/pd.py
@@ -19,6 +19,7 @@
 
 import sigrokdecode as srd
 from .lists import *
+import struct
 
 class SamplerateError(Exception):
     pass
@@ -40,6 +41,8 @@ class Decoder(srd.Decoder):
         {'id': 'polarity', 'desc': 'Polarity', 'default': 'active-low',
             'values': ('active-low', 'active-high')},
         {'id': 'cd_freq', 'desc': 'Carrier Frequency', 'default': 0},
+        {'id': 'protocol', 'desc': 'Protocol type', 'default': 'standard',
+            'values': ('standard', 'extended')},
     )
     annotations = (
         ('bit', 'Bit'),
@@ -140,8 +143,14 @@ def handle_bit(self, tick):
         self.ss_bit = self.samplenum
 
     def data_ok(self):
-        ret = (self.data >> 8) ^ (self.data & 0xff) == 0xff
-        name = self.state.title()
+        if self.options['protocol'] == 'extended' and self.state == 'ADDRESS':
+            ret, name = True, self.state.title
+            # Little endian to native byte order
+            data, = struct.unpack('<H',struct.pack('H',self.data))
+        else:
+            data = self.data >> 8
+            ret = data ^ (self.data & 0xff) == 0xff
+            name = self.state.title()
         if self.count == 8:
             if self.state == 'ADDRESS':
                 self.addr = self.data
@@ -151,7 +160,7 @@ def data_ok(self):
             self.ss_start = self.samplenum
             return True
         if ret:
-            self.putd(self.data >> 8)
+            self.putd(data)
         else:
             self.putx([12, ['%s error: 0x%04X' % (name, self.data)]])
         self.data = self.count = 0
@@ -216,8 +225,10 @@ def decode(self):
                 self.ss_bit = self.ss_start = self.samplenum
             elif self.state == 'ADDRESS':
                 self.handle_bit(b)
-                if self.count == 8:
+                if self.options['protocol'] == 'standard' and self.count == 8:
                     self.state = 'ADDRESS#' if self.data_ok() else 'IDLE'
+                if self.options['protocol'] == 'extended' and self.count == 16:
+                    self.state = 'COMMAND' if self.data_ok() else 'IDLE'
             elif self.state == 'ADDRESS#':
                 self.handle_bit(b)
                 if self.count == 16:

Attachment: nec_ext_cmd_3repeat.sr
Description: Zip archive

_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to