import sigrokdecode as srd
+class SamplerateError(Exception):
+ pass
+
class Decoder(srd.Decoder):
- api_version = 1
+ api_version = 2
id = 'onewire_link'
name = '1-Wire link layer'
longname = '1-Wire serial communication bus (link layer)'
license = 'gplv2+'
inputs = ['logic']
outputs = ['onewire_link']
- probes = (
+ channels = (
{'id': 'owr', 'name': 'OWR', 'desc': '1-Wire signal line'},
)
- optional_probes = (
+ optional_channels = (
{'id': 'pwr', 'name': 'PWR', 'desc': '1-Wire power supply pin'},
)
options = (
if (time_min < 0.0000073) or (time_max > 0.000010):
self.putm([1, ['The overdrive mode presence sample time interval ' +
'(%2.1fus-%2.1fus) should be inside (7.3us, 10.0us).'
- % (time_min*1000000, time_max*1000000)]])
+ % (time_min * 1000000, time_max * 1000000)]])
def decode(self, ss, es, data):
- if self.samplerate is None:
- raise Exception("Cannot decode without samplerate.")
+ if not self.samplerate:
+ raise SamplerateError('Cannot decode without samplerate.')
for (self.samplenum, (owr, pwr)) in data:
# State machine.
if self.state == 'WAIT FOR FALLING EDGE':
# Save the sample number for the rising edge.
self.rise = self.samplenum
self.putfr([2, ['Reset', 'Rst', 'R']])
- self.state = "WAIT FOR PRESENCE DETECT"
+ self.state = 'WAIT FOR PRESENCE DETECT'
# Otherwise this is assumed to be a data bit.
else:
- self.state = "WAIT FOR FALLING EDGE"
+ self.state = 'WAIT FOR FALLING EDGE'
elif self.state == 'WAIT FOR PRESENCE DETECT':
# Sample presence status.
t = self.samplenum - self.rise
# Wait for next slot.
self.state = 'WAIT FOR FALLING EDGE'
- else:
- raise Exception('Invalid state: %s' % self.state)