diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-01-15 10:44:19 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-01-15 13:55:42 +0100 |
commit | afb0d2339c0218627d6802a9138d78de57bab0a7 (patch) | |
tree | 1a781412e7e15638335ef104707321e2ae6f7ac1 /decoders | |
parent | 4539e9ca58966ce3c9cad4801b16c315e86ace01 (diff) | |
download | libsigrokdecode-afb0d2339c0218627d6802a9138d78de57bab0a7.tar.gz libsigrokdecode-afb0d2339c0218627d6802a9138d78de57bab0a7.zip |
em4100: Convert to PD API version 3
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/em4100/pd.py | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/decoders/em4100/pd.py b/decoders/em4100/pd.py index faba51b..8c8a72b 100644 --- a/decoders/em4100/pd.py +++ b/decoders/em4100/pd.py @@ -23,7 +23,7 @@ class SamplerateError(Exception): pass class Decoder(srd.Decoder): - api_version = 2 + api_version = 3 id = 'em4100' name = 'EM4100' longname = 'RFID EM4100' @@ -185,52 +185,50 @@ class Decoder(srd.Decoder): self.col_parity_pos = [] self.all_row_parity_ok = True - def manchester_decode(self, samplenum, pl, pp, pin): + def manchester_decode(self, pl, pp, pin): bit = self.oldpin ^ self.polarity if pl > self.halfbit_limit: - es = int(samplenum - pl/2) + es = int(self.samplenum - pl/2) if self.oldpl > self.halfbit_limit: ss = int(self.oldsamplenum - self.oldpl/2) else: ss = int(self.oldsamplenum - self.oldpl) self.putbit(bit, ss, es) - self.last_bit_pos = int(samplenum - pl/2) + self.last_bit_pos = int(self.samplenum - pl/2) else: - es = int(samplenum) + es = int(self.samplenum) if self.oldpl > self.halfbit_limit: ss = int(self.oldsamplenum - self.oldpl/2) self.putbit(bit, ss, es) - self.last_bit_pos = int(samplenum) + self.last_bit_pos = int(self.samplenum) else: if self.last_bit_pos <= self.oldsamplenum - self.oldpl: ss = int(self.oldsamplenum - self.oldpl) self.putbit(bit, ss, es) - self.last_bit_pos = int(samplenum) + self.last_bit_pos = int(self.samplenum) - def decode(self, ss, es, data): + def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') - for (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 = samplenum - self.lastlast_samplenum = samplenum - self.last_edge = samplenum - self.oldpl = 0 - self.oldpp = 0 - self.oldsamplenum = 0 - self.last_bit_pos = 0 - continue - - if self.oldpin != pin: - pl = samplenum - self.oldsamplenum - pp = pin - self.manchester_decode(samplenum, pl, pp, pin) - self.oldpl = pl - self.oldpp = pp - self.oldsamplenum = samplenum - self.oldpin = pin + + # Initialize internal state from the very first sample. + (pin,) = self.wait({'skip': 1}) + 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 + + while True: + # Ignore identical samples, only process edges. + (pin,) = self.wait({0: 'e'}) + pl = self.samplenum - self.oldsamplenum + pp = pin + self.manchester_decode(pl, pp, pin) + self.oldpl = pl + self.oldpp = pp + self.oldsamplenum = self.samplenum + self.oldpin = pin |