From 56cc44ff1106e8e28d9242b6232552c501090ed4 Mon Sep 17 00:00:00 2001
From: Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
Date: Fri, 13 Nov 2015 04:05:24 +0100
Subject: usb_signalling: consolidate symbol output

No need to replicate the symbol formatting in several places
---
 decoders/usb_signalling/pd.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

(limited to 'decoders/usb_signalling')

diff --git a/decoders/usb_signalling/pd.py b/decoders/usb_signalling/pd.py
index 768a3b7..4af2eff 100644
--- a/decoders/usb_signalling/pd.py
+++ b/decoders/usb_signalling/pd.py
@@ -66,11 +66,11 @@ bitrates = {
     'full-speed': 12000000, # 12Mb/s (+/- 0.25%)
 }
 
-sym_idx = {
-    'J': 0,
-    'K': 1,
-    'SE0': 2,
-    'SE1': 3,
+sym_annotation = {
+    'J': [0, ['J']],
+    'K': [1, ['K']],
+    'SE0': [2, ['SE0', '0']],
+    'SE1': [3, ['SE1', '1']],
 }
 
 class SamplerateError(Exception):
@@ -180,13 +180,11 @@ class Decoder(srd.Decoder):
             # Stuff bit.
             self.putpb(['STUFF BIT', None])
             self.putb([7, ['Stuff bit: %s' % b, 'SB: %s' % b, '%s' % b]])
-            self.putb([sym_idx[sym], ['%s' % sym]])
             self.consecutive_ones = 0
         else:
             # Normal bit (not a stuff bit).
             self.putpb(['BIT', b])
             self.putb([6, ['%s' % b]])
-            self.putb([sym_idx[sym], ['%s' % sym]])
             if b == '1':
                 self.consecutive_ones += 1
             else:
@@ -196,7 +194,7 @@ class Decoder(srd.Decoder):
         # EOP: SE0 for >= 1 bittime (usually 2 bittimes), then J.
         self.syms.append(sym)
         self.putpb(['SYM', sym])
-        self.putb([sym_idx[sym], ['%s' % sym, '%s' % sym[0]]])
+        self.putb(sym_annotation[sym])
         self.set_new_target_samplenum()
         self.oldsym = sym
         if self.syms[-2:] == ['SE0', 'J']:
@@ -217,6 +215,7 @@ class Decoder(srd.Decoder):
         self.syms.append(sym)
         self.putpb(['SYM', sym])
         b = '0' if self.oldsym != sym else '1'
+        self.putb(sym_annotation[sym])
         if self.oldsym != sym:
             edgesym = symbols[self.options['signalling']][tuple(self.edgepins)]
             if edgesym not in ('SE0', 'SE1'):
-- 
cgit v1.2.3-70-g09d2