summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
inline | side by side (from parent 1:
499bf26)
Eliminate redundancy in time to snum conversions and vice versa. Don't
locally overload .wait() with unexpected semantics and neither change
its parameters nor return values. Give reviewers and maintainers a
chance to see what's happening when they inspect call sites. The
'signals' identifier is unusual for pin states, use the more common
'pins' instead for consistency with other decoders. Reflect when return
values are not used, so that readers need to juggle fewer details in
their head.
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
+ self.snum_per_us = self.samplerate / 1e6
def putg(self, ss, es, cls, texts):
self.put(ss, es, self.out_ann, [cls, texts])
def tolerance(self, ss, es, expected):
def putg(self, ss, es, cls, texts):
self.put(ss, es, self.out_ann, [cls, texts])
def tolerance(self, ss, es, expected):
- microseconds = 1000000 * (es - ss) / self.samplerate
+ microseconds = (es - ss) / self.snum_per_us
tolerance = expected * 0.30
return (expected - tolerance) < microseconds < (expected + tolerance)
tolerance = expected * 0.30
return (expected - tolerance) < microseconds < (expected + tolerance)
- def wait(self, *conds, timeout=None):
+ def wait_wrap(self, conds, timeout=None):
conds = list(conds)
if timeout is not None:
conds = list(conds)
if timeout is not None:
- to = int(self.samplerate * timeout / 1000000)
+ to = int(timeout * self.snum_per_us)
conds.append({'skip': to})
ss = self.samplenum
conds.append({'skip': to})
ss = self.samplenum
- signals = super(Decoder, self).wait(conds)
+ pins = self.wait(conds)
- return signals, ss, es, self.matched
+ return pins, ss, es, self.matched
def read_pulse(self, high, time):
e = 'f' if high else 'r'
max_time = int(time * 1.30)
def read_pulse(self, high, time):
e = 'f' if high else 'r'
max_time = int(time * 1.30)
- signals, ss, es, (edge, timeout) = self.wait({0: e}, timeout=max_time)
+ pins, ss, es, (edge, timeout) = self.wait_wrap([{0: e}], max_time)
if timeout or not self.tolerance(ss, es, time):
raise SIRCError('Timeout')
if timeout or not self.tolerance(ss, es, time):
raise SIRCError('Timeout')
- return signals, ss, es, (edge, timeout)
+ return pins, ss, es, (edge, timeout)
def read_bit(self):
e = 'f' if self.active else 'r'
def read_bit(self):
e = 'f' if self.active else 'r'
- signals, high_ss, high_es, (edge, timeout) = self.wait({0: e}, timeout=2000)
+ _, high_ss, high_es, (edge, timeout) = self.wait_wrap([{0: e}], 2000)
if timeout:
raise SIRCError('Bit High Timeout')
if self.tolerance(high_ss, high_es, 1200):
if timeout:
raise SIRCError('Bit High Timeout')
if self.tolerance(high_ss, high_es, 1200):
else:
raise SIRCError('Bit Low Timeout')
try:
else:
raise SIRCError('Bit Low Timeout')
try:
- signals, low_ss, low_es, matched = self.read_pulse(not self.active, 600)
+ _, low_ss, low_es, matched = self.read_pulse(not self.active, 600)
good = True
except SIRCError:
good = True
except SIRCError:
- low_es = high_es + int(600 * self.samplerate / 1000000)
+ low_es = high_es + int(600 * self.snum_per_us)
good = False
self.putg(high_ss, low_es, 0, ['{}'.format(bit)])
return bit, high_ss, low_es, good
good = False
self.putg(high_ss, low_es, 0, ['{}'.format(bit)])
return bit, high_ss, low_es, good
def read_signal(self):
# Start code
try:
def read_signal(self):
# Start code
try:
- signals, agc_ss, agc_es, matched = self.read_pulse(self.active, 2400)
- signals, pause_ss, pause_es, matched = self.read_pulse(not self.active, 600)
+ _, agc_ss, agc_es, matched = self.read_pulse(self.active, 2400)
+ _, pause_ss, pause_es, matched = self.read_pulse(not self.active, 600)
except SIRCError:
raise SIRCErrorSilent('not an SIRC message')
self.putg(agc_ss, agc_es, 1, ['AGC', 'A'])
except SIRCError:
raise SIRCErrorSilent('not an SIRC message')
self.putg(agc_ss, agc_es, 1, ['AGC', 'A'])
while True:
e = 'h' if self.active else 'l'
while True:
e = 'h' if self.active else 'l'
- signal, ss, es, matched = self.wait({0: e})
+ signal, ss, es, matched = self.wait_wrap([{0: e}], None)
try:
address, command, extended, payload_ss, payload_es = self.read_signal()
names, commands = ADDRESSES.get((address, extended), (['Unknown Device: ', 'UNK: '], {}))
try:
address, command, extended, payload_ss, payload_es = self.read_signal()
names, commands = ADDRESSES.get((address, extended), (['Unknown Device: ', 'UNK: '], {}))