X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Ft55xx%2Fpd.py;h=fb1bcb94d6646f2e202304933bec7f2f189aa42e;hp=87ebeba7adb865ea49124fd05f792957c88867a3;hb=d6d8a8a440ea2a81e6ddde33d16bc84d01cdb432;hpb=e2bc7a1e2f4e40250d117c587ad02343257d0f2a diff --git a/decoders/t55xx/pd.py b/decoders/t55xx/pd.py index 87ebeba..fb1bcb9 100644 --- a/decoders/t55xx/pd.py +++ b/decoders/t55xx/pd.py @@ -5,8 +5,8 @@ ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either data 2 of the License, or -## (at your option) any later data. +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,8 +14,7 @@ ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## along with this program; if not, see . ## import sigrokdecode as srd @@ -24,7 +23,7 @@ class SamplerateError(Exception): pass class Decoder(srd.Decoder): - api_version = 2 + api_version = 3 id = 't55xx' name = 'T55xx' longname = 'RFID T55xx' @@ -32,6 +31,7 @@ class Decoder(srd.Decoder): license = 'gplv2+' inputs = ['logic'] outputs = ['t55xx'] + tags = ['IC', 'RFID'] channels = ( {'id': 'data', 'name': 'Data', 'desc': 'Data line'}, ) @@ -66,9 +66,11 @@ class Decoder(srd.Decoder): ('decode', 'Decode', (10,)), ) - def __init__(self, **kwargs): + def __init__(self): + self.reset() + + def reset(self): self.samplerate = None - self.oldpin = None self.last_samplenum = None self.lastlast_samplenum = None self.state = 'START_GAP' @@ -255,77 +257,70 @@ class Decoder(srd.Decoder): self.bits_pos[self.bit_nr][2] = bit_end self.bit_nr += 1 - def decode(self, ss, es, data): + def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') - for (self.samplenum, (pin,)) in data: - # Ignore identical samples early on (for performance reasons). - if self.oldpin == pin: - continue - if self.oldpin is None: - self.oldpin = pin - self.last_samplenum = self.samplenum - self.lastlast_samplenum = self.samplenum - self.last_edge = self.samplenum - self.oldpl = 0 - self.oldpp = 0 - self.oldsamplenum = 0 - self.last_bit_pos = 0 + self.last_samplenum = 0 + self.lastlast_samplenum = 0 + self.last_edge = 0 + self.oldpl = 0 + self.oldpp = 0 + self.oldsamplenum = 0 + self.last_bit_pos = 0 + self.old_gap_start = 0 + self.old_gap_end = 0 + self.gap_detected = 0 + self.bit_nr = 0 - self.old_gap_start = 0 - self.old_gap_end = 0 - self.gap_detected = 0 - self.bit_nr = 0 - continue + while True: + (pin,) = self.wait({0: 'e'}) - if self.oldpin != pin: - pl = self.samplenum - self.oldsamplenum - pp = pin - samples = self.samplenum - self.last_samplenum + pl = self.samplenum - self.oldsamplenum + pp = pin + samples = self.samplenum - self.last_samplenum - if self.state == 'WRITE_GAP': - if pl > self.writegap: - self.gap_detected = 1 - self.put(self.last_samplenum, self.samplenum, - self.out_ann, [2, ['Write gap']]) - if (self.last_samplenum-self.old_gap_end) > self.nogap: - self.gap_detected = 0 - self.state = 'START_GAP' - self.put(self.old_gap_end, self.last_samplenum, - self.out_ann, [3, ['Write mode exit']]) - self.put_fields() + if self.state == 'WRITE_GAP': + if pl > self.writegap: + self.gap_detected = 1 + self.put(self.last_samplenum, self.samplenum, + self.out_ann, [2, ['Write gap']]) + if (self.last_samplenum-self.old_gap_end) > self.nogap: + self.gap_detected = 0 + self.state = 'START_GAP' + self.put(self.old_gap_end, self.last_samplenum, + self.out_ann, [3, ['Write mode exit']]) + self.put_fields() - if self.state == 'START_GAP': - if pl > self.startgap: - self.gap_detected = 1 - self.put(self.last_samplenum, self.samplenum, - self.out_ann, [1, ['Start gap']]) - self.state = 'WRITE_GAP' + if self.state == 'START_GAP': + if pl > self.startgap: + self.gap_detected = 1 + self.put(self.last_samplenum, self.samplenum, + self.out_ann, [1, ['Start gap']]) + self.state = 'WRITE_GAP' - if self.gap_detected == 1: - self.gap_detected = 0 - if (self.last_samplenum - self.old_gap_end) > self.wzmin \ - and (self.last_samplenum - self.old_gap_end) < self.wzmax: - self.put(self.old_gap_end, self.last_samplenum, - self.out_ann, [0, ['0']]) - self.put(self.old_gap_end, self.last_samplenum, - self.out_ann, [4, ['Bit']]) - self.add_bits_pos(0, self.old_gap_end, - self.last_samplenum) - if (self.last_samplenum - self.old_gap_end) > self.womin \ - and (self.last_samplenum - self.old_gap_end) < self.womax: - self.put(self.old_gap_end, self.last_samplenum, - self.out_ann, [0, ['1']]) - self.put(self.old_gap_end, self.last_samplenum, - self.out_ann, [4, ['Bit']]) - self.add_bits_pos(1, self.old_gap_end, self.last_samplenum) + if self.gap_detected == 1: + self.gap_detected = 0 + if (self.last_samplenum - self.old_gap_end) > self.wzmin \ + and (self.last_samplenum - self.old_gap_end) < self.wzmax: + self.put(self.old_gap_end, self.last_samplenum, + self.out_ann, [0, ['0']]) + self.put(self.old_gap_end, self.last_samplenum, + self.out_ann, [4, ['Bit']]) + self.add_bits_pos(0, self.old_gap_end, + self.last_samplenum) + if (self.last_samplenum - self.old_gap_end) > self.womin \ + and (self.last_samplenum - self.old_gap_end) < self.womax: + self.put(self.old_gap_end, self.last_samplenum, + self.out_ann, [0, ['1']]) + self.put(self.old_gap_end, self.last_samplenum, + self.out_ann, [4, ['Bit']]) + self.add_bits_pos(1, self.old_gap_end, self.last_samplenum) - self.old_gap_start = self.last_samplenum - self.old_gap_end = self.samplenum + self.old_gap_start = self.last_samplenum + self.old_gap_end = self.samplenum - self.oldpl = pl - self.oldpp = pp - self.oldsamplenum = self.samplenum - self.last_samplenum = self.samplenum - self.oldpin = pin + self.oldpl = pl + self.oldpp = pp + self.oldsamplenum = self.samplenum + self.last_samplenum = self.samplenum