- elif code == 'BIT':
- if self.state == 'COMMAND':
- # Receiving and decoding a ROM command.
- if self.onewire_collect(8, val, ss, es):
- if self.data in command:
- self.putx([0, ['ROM COMMAND: 0x%02x \'%s\''
- % (self.data, command[self.data][0])]])
- self.state = command[self.data][1]
- else:
- self.putx([0, ['ROM COMMAND: 0x%02x \'%s\''
- % (self.data, 'UNRECOGNIZED')]])
- self.state = 'COMMAND ERROR'
- elif self.state == 'GET ROM':
- # A 64 bit device address is selected.
- # Family code (1B) + serial number (6B) + CRC (1B)
- if self.onewire_collect(64, val, ss, es):
- self.net_rom = self.data & 0xffffffffffffffff
- self.putx([0, ['ROM: 0x%016x' % self.net_rom]])
- self.puty(['ROM', self.net_rom])
- self.state = 'TRANSPORT'
- elif self.state == 'SEARCH ROM':
- # A 64 bit device address is searched for.
- # Family code (1B) + serial number (6B) + CRC (1B)
- if self.onewire_search(64, val, ss, es):
- self.net_rom = self.data & 0xffffffffffffffff
- self.putx([0, ['ROM: 0x%016x' % self.net_rom]])
- self.puty(['ROM', self.net_rom])
- self.state = 'TRANSPORT'
- elif self.state == 'TRANSPORT':
- # The transport layer is handled in byte sized units.
- if self.onewire_collect(8, val, ss, es):
- self.putx([0, ['DATA: 0x%02x' % self.data]])
- self.puty(['DATA', self.data])
- elif self.state == 'COMMAND ERROR':
- # Since the command is not recognized, print raw data.
- if self.onewire_collect(8, val, ss, es):
- self.putx([0, ['ROM ERROR DATA: 0x%02x' % self.data]])
+ return
+
+ # For now we're only interested in 'RESET/PRESENCE' and 'BIT' packets.
+ if code != 'BIT':
+ return
+
+ if self.state == 'COMMAND':
+ # Receiving and decoding a ROM command.
+ if self.onewire_collect(8, val, ss, es) == 0:
+ return
+ if self.data in command:
+ self.putx([0, ['ROM COMMAND: 0x%02x \'%s\''
+ % (self.data, command[self.data][0])]])
+ self.state = command[self.data][1]