From: Gerhard Sittig Date: Sun, 18 Jun 2017 10:24:32 +0000 (+0200) Subject: lpc: Improve robustness when decoding unexpected input data X-Git-Url: http://sigrok.org/gitweb/?p=libsigrokdecode.git;a=commitdiff_plain;h=a912e8cbb6ab4a56bee71a9c0fd0045d5fdee55c lpc: Improve robustness when decoding unexpected input data The 'fields' table of state and descriptions is not fully populated, some slots are missing. Cope with lookup misses when unexpected input data is not found in the table. Use different error text in annotations for described but invalid states (the previous implementation used "reserved / invalid"), and for states that are not described in the table (introduce the "reserved / unknown" text for conditions that are not covered by the decoder implementation). The previous implementation missed the emission of some warnings. When a "reserved / invalid" description was found, the subsequent exact match for "reserved" failed and the warning was not emitted. Weaken the test to emit warnings for either description that has "reserved" in it, regardless of whether the text was found in the table or is not part of the table at all. --- diff --git a/decoders/lpc/pd.py b/decoders/lpc/pd.py index 08d0437..c737544 100644 --- a/decoders/lpc/pd.py +++ b/decoders/lpc/pd.py @@ -182,10 +182,10 @@ class Decoder(srd.Decoder): def handle_get_ct_dr(self, lad, lad_bits): # LAD[3:0]: Cycle type / direction field (1 clock cycle). - self.cycle_type = fields['CT_DR'][lad] + self.cycle_type = fields['CT_DR'].get(lad, 'Reserved / unknown') # TODO: Warning/error on invalid cycle types. - if self.cycle_type == 'Reserved': + if 'Reserved' in self.cycle_type: self.putb([0, ['Invalid cycle type (%s)' % lad_bits]]) self.es_block = self.samplenum @@ -251,10 +251,10 @@ class Decoder(srd.Decoder): # LAD[3:0]: SYNC field (1-n clock cycles). self.sync_val = lad_bits - self.cycle_type = fields['SYNC'][lad] + self.cycle_type = fields['SYNC'].get(lad, 'Reserved / unknown') # TODO: Warnings if reserved value are seen? - if self.cycle_type == 'Reserved': + if 'Reserved' in self.cycle_type: self.putb([0, ['SYNC, cycle %d: %s (reserved value)' % \ (self.synccount, self.sync_val)]])