def _read(self): dallas = self.parent dallas.reset() dallas.matchrom(self.address) dallas.readscratch() result = dallas.readbytes(9) if crc_of(result) == 0: t = unpack('<h', result[:2])[0] self.result = t if self.bad_crc_count > 10: #was logged as bad msglog.log('DallasBus', 'information', 'Resumed: %s' % \ as_node_url(self)) self.bad_crc_count = 0 t = uptime_secs() self.scan_period = t - self._last_read_time self._last_read_time = t if self.debug: print "TEMPERATURE SENSOR: _read value", self.result else: if self.bad_crc_count < 11: self.bad_crc_count += 1 if self.bad_crc_count == 10: self.result = None #return ETimeout to gets raise EInvalidResponse('Failed read ten times: %s' % \ as_node_url(self)) if self.debug: print "TEMPERATURE SENSOR: BAD CRC", result return
def asciihex_to_address(value): # There may be a much easier way to do this. nibble_map = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'a':10, 'b':11, 'c':12, 'd':13, 'e':14, 'f':15, 'A':10, 'B':11, 'C':12, 'D':13, 'E':14, 'F':15} addr = '' for i in range(0,len(value),2): addr += chr((nibble_map[value[i]] << 4) + nibble_map[value[i+1]]) if crc_of(addr) != 0: # CRC does not pass, try the reverse byte order instead addr = '' for i in range(len(value),0,-2): addr += chr((nibble_map[value[i-2]] << 4) + nibble_map[value[i-1]]) return addr
def asciihex_to_address(value): # There may be a much easier way to do this. nibble_map = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15 } addr = '' for i in range(0, len(value), 2): addr += chr((nibble_map[value[i]] << 4) + nibble_map[value[i + 1]]) if crc_of(addr) != 0: # CRC does not pass, try the reverse byte order instead addr = '' for i in range(len(value), 0, -2): addr += chr((nibble_map[value[i - 2]] << 4) + nibble_map[value[i - 1]]) return addr