From: Uwe Hermann Date: Tue, 8 Jul 2014 19:21:03 +0000 (+0200) Subject: All PDs: Drop unneeded exceptions. X-Git-Tag: libsigrokdecode-0.4.0~208 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e28f7aee3b96afeb543e0c3c29e3950ddd61a490;p=libsigrokdecode.git All PDs: Drop unneeded exceptions. In all current PDs it is not necessary to raise an exception upon invalid states (of the PD's state machine), since we can guarantee that no such invalid state can ever be reached in these PDs. --- diff --git a/decoders/can/pd.py b/decoders/can/pd.py index bf38b7f..e425575 100644 --- a/decoders/can/pd.py +++ b/decoders/can/pd.py @@ -376,6 +376,4 @@ class Decoder(srd.Decoder): if not self.reached_bit(self.curbit): continue self.handle_bit(can_rx) - else: - raise Exception("Invalid state: %s" % self.state) diff --git a/decoders/dcf77/pd.py b/decoders/dcf77/pd.py index fc97a1d..3f0ff50 100644 --- a/decoders/dcf77/pd.py +++ b/decoders/dcf77/pd.py @@ -310,8 +310,5 @@ class Decoder(srd.Decoder): self.state = 'WAIT FOR RISING EDGE' - else: - raise Exception('Invalid state: %s' % self.state) - self.oldval = val diff --git a/decoders/ds1307/pd.py b/decoders/ds1307/pd.py index 68943d4..1a49f9a 100644 --- a/decoders/ds1307/pd.py +++ b/decoders/ds1307/pd.py @@ -164,6 +164,4 @@ class Decoder(srd.Decoder): self.state = 'IDLE' else: pass # TODO? - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/i2cfilter/pd.py b/decoders/i2cfilter/pd.py index f1ac6a4..895cc17 100644 --- a/decoders/i2cfilter/pd.py +++ b/decoders/i2cfilter/pd.py @@ -39,7 +39,6 @@ class Decoder(srd.Decoder): ) def __init__(self, **kwargs): - self.state = None self.curslave = -1 self.curdirection = None self.packets = [] # Local cache of I²C packets diff --git a/decoders/ir_nec/pd.py b/decoders/ir_nec/pd.py index 94e232f..d9091be 100644 --- a/decoders/ir_nec/pd.py +++ b/decoders/ir_nec/pd.py @@ -199,8 +199,6 @@ class Decoder(srd.Decoder): self.putremote() self.ss_bit = self.ss_start = self.samplenum self.state = 'IDLE' - else: - raise Exception('Invalid state: %s' % self.state) self.old_ir = self.ir diff --git a/decoders/ir_rc5/pd.py b/decoders/ir_rc5/pd.py index 38b4793..885b29d 100644 --- a/decoders/ir_rc5/pd.py +++ b/decoders/ir_rc5/pd.py @@ -168,8 +168,6 @@ class Decoder(srd.Decoder): if edge == 's': self.state = 'MID0' bit = 0 if edge == 's' else None - else: - raise Exception('Invalid state: %s' % self.state) self.edges.append(self.samplenum) if bit != None: diff --git a/decoders/jtag/pd.py b/decoders/jtag/pd.py index 25f2634..d7b35aa 100644 --- a/decoders/jtag/pd.py +++ b/decoders/jtag/pd.py @@ -139,9 +139,6 @@ class Decoder(srd.Decoder): elif self.state == 'UPDATE-IR': self.state = 'SELECT-DR-SCAN' if (tms) else 'RUN-TEST/IDLE' - else: - raise Exception('Invalid state: %s' % self.state) - def handle_rising_tck_edge(self, tdi, tdo, tck, tms): # Rising TCK edges always advance the state machine. self.advance_state_machine(tms) diff --git a/decoders/jtag_stm32/pd.py b/decoders/jtag_stm32/pd.py index 5aac07f..9113b4c 100644 --- a/decoders/jtag_stm32/pd.py +++ b/decoders/jtag_stm32/pd.py @@ -218,6 +218,4 @@ class Decoder(srd.Decoder): handle_reg(cmd, val) if cmd == 'DR TDO': # TODO: Assumes 'DR TDI' comes before 'DR TDO' self.state = 'IDLE' - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/lm75/pd.py b/decoders/lm75/pd.py index 89d6c61..6655ef0 100644 --- a/decoders/lm75/pd.py +++ b/decoders/lm75/pd.py @@ -181,6 +181,4 @@ class Decoder(srd.Decoder): else: # self.putx([0, ['Ignoring: %s (data=%s)' % (cmd, databyte)]]) pass - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/lpc/pd.py b/decoders/lpc/pd.py index 6e03966..b626e0d 100644 --- a/decoders/lpc/pd.py +++ b/decoders/lpc/pd.py @@ -365,6 +365,4 @@ class Decoder(srd.Decoder): self.handle_get_data(lad, lad_bits) elif self.state == 'GET TAR2': self.handle_get_tar2(lad, lad_bits) - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/maxim_ds28ea00/pd.py b/decoders/maxim_ds28ea00/pd.py index 4693cd9..1e2c36a 100644 --- a/decoders/maxim_ds28ea00/pd.py +++ b/decoders/maxim_ds28ea00/pd.py @@ -88,6 +88,4 @@ class Decoder(srd.Decoder): self.putx([0, ['Temperature conversion status: 0x%02x' % val]]) elif self.state in [s.upper() for s in command.values()]: self.putx([0, ['TODO \'%s\': 0x%02x' % (self.state, val)]]) - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/midi/pd.py b/decoders/midi/pd.py index b1f0053..0717dbc 100644 --- a/decoders/midi/pd.py +++ b/decoders/midi/pd.py @@ -206,6 +206,4 @@ class Decoder(srd.Decoder): self.handle_syscommon_msg(pdata) elif self.state == 'HANDLE SYSREALTIME MSG': self.handle_sysrealtime_msg(pdata) - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/mlx90614/pd.py b/decoders/mlx90614/pd.py index edc770d..eeb2743 100644 --- a/decoders/mlx90614/pd.py +++ b/decoders/mlx90614/pd.py @@ -73,6 +73,4 @@ class Decoder(srd.Decoder): self.putx([1, ['Temperature: %3.2f K' % kelvin]]) self.state = 'IGNORE START REPEAT' self.data = [] - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/mxc6225xu/pd.py b/decoders/mxc6225xu/pd.py index e0c857f..c506fb6 100644 --- a/decoders/mxc6225xu/pd.py +++ b/decoders/mxc6225xu/pd.py @@ -213,6 +213,4 @@ class Decoder(srd.Decoder): self.state = 'IDLE' else: pass # TODO? - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/nunchuk/pd.py b/decoders/nunchuk/pd.py index 95d7bdb..8ed98e6 100644 --- a/decoders/nunchuk/pd.py +++ b/decoders/nunchuk/pd.py @@ -202,6 +202,4 @@ class Decoder(srd.Decoder): else: # self.putx([14, ['Ignoring: %s (data=%s)' % (cmd, databyte)]]) pass - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/onewire_link/pd.py b/decoders/onewire_link/pd.py index 3641b98..9503d15 100644 --- a/decoders/onewire_link/pd.py +++ b/decoders/onewire_link/pd.py @@ -278,5 +278,3 @@ class Decoder(srd.Decoder): # Wait for next slot. self.state = 'WAIT FOR FALLING EDGE' - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/onewire_network/pd.py b/decoders/onewire_network/pd.py index 23402a6..5c836c2 100644 --- a/decoders/onewire_network/pd.py +++ b/decoders/onewire_network/pd.py @@ -126,8 +126,6 @@ class Decoder(srd.Decoder): if self.onewire_collect(8, val, ss, es) == 0: return self.putx([0, ['ROM error data: 0x%02x' % self.data]]) - else: - raise Exception('Invalid state: %s' % self.state) # Data collector. def onewire_collect(self, length, val, ss, es): diff --git a/decoders/pan1321/pd.py b/decoders/pan1321/pd.py index d173e1c..7edd1c8 100644 --- a/decoders/pan1321/pd.py +++ b/decoders/pan1321/pd.py @@ -154,8 +154,6 @@ class Decoder(srd.Decoder): self.handle_device_reply(rxtx, self.cmd[rxtx][:-2]) elif rxtx == TX: self.handle_host_command(rxtx, self.cmd[rxtx][:-2]) - else: - raise Exception('Invalid rxtx value: %d' % rxtx) self.cmd[rxtx] = '' diff --git a/decoders/parallel/pd.py b/decoders/parallel/pd.py index 03b5e2f..0b512c8 100644 --- a/decoders/parallel/pd.py +++ b/decoders/parallel/pd.py @@ -92,7 +92,6 @@ class Decoder(srd.Decoder): self.oldpins = None self.ss_item = self.es_item = None self.first = True - self.state = 'IDLE' def start(self): self.out_python = self.register(srd.OUTPUT_PYTHON) @@ -181,12 +180,8 @@ class Decoder(srd.Decoder): continue self.oldpins = pins - # State machine. - if self.state == 'IDLE': - if pins[0] not in (0, 1): - self.handle_bits(pins[1:]) - else: - self.find_clk_edge(pins[0], pins[1:]) + if pins[0] not in (0, 1): + self.handle_bits(pins[1:]) else: - raise Exception('Invalid state: %s' % self.state) + self.find_clk_edge(pins[0], pins[1:]) diff --git a/decoders/rtc8564/pd.py b/decoders/rtc8564/pd.py index f13af36..5f031e2 100644 --- a/decoders/rtc8564/pd.py +++ b/decoders/rtc8564/pd.py @@ -252,6 +252,4 @@ class Decoder(srd.Decoder): self.state = 'IDLE' else: pass # TODO? - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/sdcard_spi/pd.py b/decoders/sdcard_spi/pd.py index be20ee3..6bd0be7 100644 --- a/decoders/sdcard_spi/pd.py +++ b/decoders/sdcard_spi/pd.py @@ -439,6 +439,4 @@ class Decoder(srd.Decoder): handle_response(miso) self.state = 'IDLE' - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index ae99874..ff8a516 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -360,8 +360,6 @@ class Decoder(srd.Decoder): self.get_parity_bit(rxtx, signal) elif self.state[rxtx] == 'GET STOP BITS': self.get_stop_bits(rxtx, signal) - else: - raise Exception('Invalid state: %s' % self.state[rxtx]) # Save current RX/TX values for the next round. self.oldbit[rxtx] = signal diff --git a/decoders/usb_packet/pd.py b/decoders/usb_packet/pd.py index 8f86cc7..4716dd7 100644 --- a/decoders/usb_packet/pd.py +++ b/decoders/usb_packet/pd.py @@ -338,6 +338,4 @@ class Decoder(srd.Decoder): self.bits, self.state = [], 'WAIT FOR SOP' else: pass # TODO: Error - else: - raise Exception('Invalid state: %s' % self.state) diff --git a/decoders/usb_signalling/pd.py b/decoders/usb_signalling/pd.py index 8c6a9c3..a21fe8d 100644 --- a/decoders/usb_signalling/pd.py +++ b/decoders/usb_signalling/pd.py @@ -237,6 +237,4 @@ class Decoder(srd.Decoder): self.get_bit(sym) elif self.state == 'GET EOP': self.get_eop(sym) - else: - raise Exception('Invalid state: %s' % self.state)