]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/sae_j1850_vpw/pd.py
irmp: silence "illegal character encoding" compiler warning
[libsigrokdecode.git] / decoders / sae_j1850_vpw / pd.py
index 8faba64c2a274480e2d2f7b02ece53748e1fe5fb..fd2389ec55e38534a616f9ceed6b03aac10cf82d 100644 (file)
@@ -25,17 +25,9 @@ class SamplerateError(Exception):
 def timeuf(t):
     return int (t * 1000.0 * 1000.0)
 
-def normalize_time(t):
-    if t >= 1.0:
-        return '%d s' % t
-    elif t >= 0.001:
-        return '%d ms' % (t * 1000.0)
-    elif t >= 0.000001:
-        return '%d μs' % (t * 1000.0 * 1000.0)
-    elif t >= 0.000000001:
-        return '%d ns' % (t * 1000.0 * 1000.0 * 1000.0)
-    else:
-        return '%f' % t
+class Ann:
+    ANN_RAW, ANN_SOF, ANN_IFS, ANN_DATA, \
+    ANN_PACKET = range(5)
 
 class Decoder(srd.Decoder):
     api_version = 3
@@ -51,7 +43,6 @@ class Decoder(srd.Decoder):
         {'id': 'data', 'name': 'Data', 'desc': 'Data line'},
     )
     annotations = (
-        ('time', 'Time'),
         ('raw', 'Raw'),
         ('sof', 'SOF'),
         ('ifs', 'EOF/IFS'),
@@ -59,10 +50,9 @@ class Decoder(srd.Decoder):
         ('packet', 'Packet'),
     )
     annotation_rows = (
-        ('packets', 'Packets', (5,)),
-        ('bytes', 'Bytes', (4,)),
-        ('raws', 'Raws', (1,2,3,)),
-        ('times', 'Times', (0,)),
+        ('raws', 'Raws', (Ann.ANN_RAW, Ann.ANN_SOF, Ann.ANN_IFS,)),
+        ('bytes', 'Bytes', (Ann.ANN_DATA,)),
+        ('packets', 'Packets', (Ann.ANN_PACKET,)),
     )
 
     def __init__(self):
@@ -97,25 +87,25 @@ class Decoder(srd.Decoder):
 
     def handle_bit(self, ss, es, b):
         self.data |= (b << 7-self.count) # MSB-first
-        self.put(ss, es, self.out_ann, [1, ["%d" % b]])
+        self.put(ss, es, self.out_ann, [Ann.ANN_RAW, ["%d" % b]])
         if self.count == 0:
             self.datastart = ss
         if self.count == 7:
             self.csa = self.datastart # for CS
             self.csb = self.samplenum # for CS
-            self.put(self.datastart, self.samplenum, self.out_ann, [4, ["%02X" % self.data]])
+            self.put(self.datastart, self.samplenum, self.out_ann, [Ann.ANN_DATA, ["%02X" % self.data]])
             # add protocol parsing here
             if self.byte == 0:
-                self.put(self.datastart, self.samplenum, self.out_ann, [5, ['Priority','Prio','P']])
+                self.put(self.datastart, self.samplenum, self.out_ann, [Ann.ANN_PACKET, ['Priority','Prio','P']])
             elif self.byte == 1:
-                self.put(self.datastart, self.samplenum, self.out_ann, [5, ['Destination','Dest','D']])
+                self.put(self.datastart, self.samplenum, self.out_ann, [Ann.ANN_PACKET, ['Destination','Dest','D']])
             elif self.byte == 2:
-                self.put(self.datastart, self.samplenum, self.out_ann, [5, ['Source','Src','S']])
+                self.put(self.datastart, self.samplenum, self.out_ann, [Ann.ANN_PACKET, ['Source','Src','S']])
             elif self.byte == 3:
-                self.put(self.datastart, self.samplenum, self.out_ann, [5, ['Mode','M']])
+                self.put(self.datastart, self.samplenum, self.out_ann, [Ann.ANN_PACKET, ['Mode','M']])
                 self.mode = self.data
             elif self.mode == 1 and self.byte == 4: # mode 1 payload
-                self.put(self.datastart, self.samplenum, self.out_ann, [5, ['Pid','P']])
+                self.put(self.datastart, self.samplenum, self.out_ann, [Ann.ANN_PACKET, ['Pid','P']])
 
             # prepare for next byte
             self.count = -1
@@ -142,18 +132,16 @@ class Decoder(srd.Decoder):
             es = self.samplenum
 
             samples = es - ss
-            txt = normalize_time(samples / self.samplerate)
-            self.put(ss, es, self.out_ann, [0, [txt]])
             t = timeuf(samples / self.samplerate)
             if self.state == 'IDLE': # detect and set speed from the size of sof
                 if pin == self.active and t in range(self.sofl , self.sofh):
-                    self.put(ss, es, self.out_ann, [1, ['1X SOF', 'S1', 'S']])
+                    self.put(ss, es, self.out_ann, [Ann.ANN_RAW, ['1X SOF', 'S1', 'S']])
                     self.spd = 1
                     self.data = 0
                     self.count = 0
                     self.state = 'DATA'
                 elif pin == self.active and t in range(int(self.sofl / 4) , int(self.sofh / 4)):
-                    self.put(ss, es, self.out_ann, [1, ['4X SOF', 'S4', '4']])
+                    self.put(ss, es, self.out_ann, [Ann.ANN_RAW, ['4X SOF', 'S4', '4']])
                     self.spd = 4
                     self.data = 0
                     self.count = 0
@@ -162,8 +150,8 @@ class Decoder(srd.Decoder):
             elif self.state == 'DATA':
                 if t >= int(self.ifs / self.spd):
                     self.state = 'IDLE'
-                    self.put(ss, es, self.out_ann, [1, ["EOF/IFS", "E"]]) # EOF=239-280 IFS=281+
-                    self.put(self.csa, self.csb, self.out_ann, [5, ['Checksum','CS','C']]) # retrospective print of CS
+                    self.put(ss, es, self.out_ann, [Ann.ANN_RAW, ["EOF/IFS", "E"]]) # EOF=239-280 IFS=281+
+                    self.put(self.csa, self.csb, self.out_ann, [Ann.ANN_PACKET, ['Checksum','CS','C']]) # retrospective print of CS
                     self.byte = 0 # reset packet offset
                 elif t in range(int(self.shortl / self.spd), int(self.shorth / self.spd)):
                     if pin == self.active: