]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/uart.py
srd: Remove decode() docstrings.
[libsigrokdecode.git] / decoders / uart.py
index efc1756149e568f5d0c57048396b355c1939af27..66deb5e2be7044edda76013ac2f6e9960ea94363 100644 (file)
@@ -131,7 +131,7 @@ class Sample():
     def __init__(self, data):
         self.data = data
     def probe(self, probe):
-        s = ord(self.data[probe / 8]) & (1 << (probe % 8))
+        s = self.data[probe / 8] & (1 << (probe % 8))
         return True if s else False
 
 def sampleiter(data, unitsize):
@@ -194,6 +194,8 @@ class Decoder(sigrok.Decoder):
 
     def __init__(self, **kwargs):
         self.probes = Decoder.probes.copy()
+        self.output_protocol = None
+        self.output_annotation = None
 
         # Set defaults, can be overridden in 'start'.
         self.baudrate = 115200
@@ -227,6 +229,8 @@ class Decoder(sigrok.Decoder):
     def start(self, metadata):
         self.unitsize = metadata['unitsize']
         self.samplerate = metadata['samplerate']
+        # self.output_protocol = self.output_new(2)
+        self.output_annotation = self.output_new(1)
 
         # TODO
         ### self.baudrate = metadata['baudrate']
@@ -370,9 +374,7 @@ class Decoder(sigrok.Decoder):
     # TODO: Currently only supports 1 stop bit.
     def get_stop_bits(self, signal):
         # Skip samples until we're in the middle of the stop bit(s).
-        skip_parity = 0
-        if self.parity != PARITY_NONE:
-            skip_parity = 1
+        skip_parity = 0 if self.parity == PARITY_NONE else 1
         if not self.reached_bit(self.num_data_bits + 1 + skip_parity):
             return []
 
@@ -392,12 +394,10 @@ class Decoder(sigrok.Decoder):
              'data': None, 'ann': 'Stop bit'}]
         return o
 
-    def decode(self, data):
-        """UART protocol decoder"""
-
+    def decode(self, timeoffset, duration, data):
         out = []
 
-        for sample in sampleiter(data["data"], self.unitsize):
+        for sample in sampleiter(data, self.unitsize):
 
             # TODO: Eliminate the need for ord().
             s = ord(sample.data)
@@ -435,5 +435,6 @@ class Decoder(sigrok.Decoder):
             # self.oldtx = tx
 
         if out != []:
-            self.put(out)
+            # self.put(self.output_protocol, 0, 0, out_proto)
+            self.put(self.output_annotation, 0, 0, out)