X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fonewire_network%2Fpd.py;h=bddc4a8434246d12cbef28623c19ab191be57350;hb=9576e005e18b2d0131e0fce5279a401cbe71c0f8;hp=642cc0e68c869b42bb60ad1a92c8e8091b205781;hpb=ef36224880135a05d2fbde8f048ea3fe3f425df9;p=libsigrokdecode.git diff --git a/decoders/onewire_network/pd.py b/decoders/onewire_network/pd.py index 642cc0e..bddc4a8 100644 --- a/decoders/onewire_network/pd.py +++ b/decoders/onewire_network/pd.py @@ -33,7 +33,7 @@ command = { } class Decoder(srd.Decoder): - api_version = 1 + api_version = 2 id = 'onewire_network' name = '1-Wire network layer' longname = '1-Wire serial communication bus (network layer)' @@ -41,16 +41,13 @@ class Decoder(srd.Decoder): license = 'gplv2+' inputs = ['onewire_link'] outputs = ['onewire_network'] - probes = [] - optional_probes = [] - options = {} - annotations = [ - ['Text', 'Human-readable text'], - ] + annotations = ( + ('text', 'Human-readable text'), + ) def __init__(self, **kwargs): - self.beg = 0 - self.end = 0 + self.ss_block = 0 + self.es_block = 0 self.state = 'COMMAND' self.bit_cnt = 0 self.search = 'P' @@ -60,16 +57,16 @@ class Decoder(srd.Decoder): self.rom = 0x0000000000000000 def start(self): - self.out_proto = self.register(srd.OUTPUT_PYTHON) + self.out_python = self.register(srd.OUTPUT_PYTHON) self.out_ann = self.register(srd.OUTPUT_ANN) def putx(self, data): # Helper function for most annotations. - self.put(self.beg, self.end, self.out_ann, data) + self.put(self.ss_block, self.es_block, self.out_ann, data) def puty(self, data): # Helper function for most protocol packets. - self.put(self.beg, self.end, self.out_proto, data) + self.put(self.ss_block, self.es_block, self.out_python, data) def decode(self, ss, es, data): code, val = data @@ -80,7 +77,7 @@ class Decoder(srd.Decoder): self.bit_cnt = 0 self.put(ss, es, self.out_ann, [0, ['Reset/presence: %s' % ('true' if val else 'false')]]) - self.put(ss, es, self.out_proto, ['RESET/PRESENCE', val]) + self.put(ss, es, self.out_python, ['RESET/PRESENCE', val]) self.state = 'COMMAND' return @@ -129,20 +126,18 @@ class Decoder(srd.Decoder): if self.onewire_collect(8, val, ss, es) == 0: return self.putx([0, ['ROM error data: 0x%02x' % self.data]]) - else: - raise Exception('Invalid state: %s' % self.state) # Data collector. def onewire_collect(self, length, val, ss, es): # Storing the sample this sequence begins with. if self.bit_cnt == 1: - self.beg = ss + self.ss_block = ss self.data = self.data & ~(1 << self.bit_cnt) | (val << self.bit_cnt) self.bit_cnt += 1 # Storing the sample this sequence ends with. # In case the full length of the sequence is received, return 1. if self.bit_cnt == length: - self.end = es + self.es_block = es self.data = self.data & ((1 << length) - 1) self.bit_cnt = 0 return 1 @@ -153,7 +148,7 @@ class Decoder(srd.Decoder): def onewire_search(self, length, val, ss, es): # Storing the sample this sequence begins with. if (self.bit_cnt == 0) and (self.search == 'P'): - self.beg = ss + self.ss_block = ss if self.search == 'P': # Master receives an original address bit. @@ -174,7 +169,7 @@ class Decoder(srd.Decoder): # Storing the sample this sequence ends with. # In case the full length of the sequence is received, return 1. if self.bit_cnt == length: - self.end = es + self.es_block = es self.data_p = self.data_p & ((1 << length) - 1) self.data_n = self.data_n & ((1 << length) - 1) self.data = self.data & ((1 << length) - 1)