From: Gerhard Sittig Date: Thu, 12 Dec 2019 09:39:57 +0000 (+0100) Subject: signature: increase compatibility across Python versions X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=commitdiff_plain;h=6d718968df2909655c84bbe4938b72b5b7178ead;hp=1d7e79da75afbdfd5d1863de6482bf4cd21e5c7e signature: increase compatibility across Python versions Underscores in number literals are a recent Python feature which only was introduced in version 3.6. The sigrok project claims compatibility with previous Python versions, but the signature decoder fails to load with this error: $ pulseview srd: SyntaxError: Failed to load decoder signature: import by name failed: invalid syntax (pd.py, line 138) srd: Traceback (most recent call last): File "/home/user/share/libsigrokdecode/decoders/signature/__init__.py", line 25, in from .pd import Decoder File "/home/user/share/libsigrokdecode/decoders/signature/pd.py", line 138 incoming = (bin(shiftreg & 0b0000_0010_1001_0001).count('1') + data) & 1 ^ SyntaxError: invalid syntax Use the more compact hex presentation for a magic binary pattern. This obsoletes the necessity to separate groups of bits for readability. --- diff --git a/decoders/signature/pd.py b/decoders/signature/pd.py index 65b86a2..aebd5b4 100644 --- a/decoders/signature/pd.py +++ b/decoders/signature/pd.py @@ -135,7 +135,7 @@ class Decoder(srd.Decoder): started = False else: self.putb(last_samplenum, [data, [str(data)]]) - incoming = (bin(shiftreg & 0b0000_0010_1001_0001).count('1') + data) & 1 + incoming = (bin(shiftreg & 0x0291).count('1') + data) & 1 shiftreg = (incoming << 15) | (shiftreg >> 1) prev_start = start prev_stop = stop