def decode_tx29(binaryMsg): """ Decoding a LaCrosse/TFA sensor message. """ # lengths counts 4 bits (nibbles) excluding 1st one givenLength = take(binaryMsg, 0, 4) actualLength = len(binaryMsg) / 4 - 1 print( "Length: actual={:02X}, received={:02X}, valid={}".format( actualLength, givenLength, "yes" if (givenLength == actualLength) else "no" ) ) givenCRC = take(binaryMsg, binaryMsg.size - 8, 8) computedCRC = crc.crc(0x31, 8, 0, 0, binaryMsg[:-8]) print( "CRC: computed={:02X}, received={:02X}, valid={}".format( computedCRC, givenCRC, "yes" if (givenCRC == computedCRC) else "no" ) ) devID = take(binaryMsg, 4, 6) print("Device: id={:02X}".format(devID)) newBattery = take(binaryMsg, 10, 1) weakBattery = take(binaryMsg, 24, 1) print("Battery: new={}, weak={}".format("yes" if newBattery else "no", "yes" if weakBattery else "no")) temperature = (take(binaryMsg, 12, 4) * 10 + take(binaryMsg, 16, 4) + take(binaryMsg, 20, 4) * 0.1) - 40 reserved = take(binaryMsg, 11, 1) print("Reserved 0 bit: received={:01X}, valid={}".format(reserved, "yes" if (reserved == 0) else "no")) humidity = take(binaryMsg, 25, 7) if humidity == 106: humidity = "N/A" print("Temperature: {:+0.1f} C -- Humidity: {} %".format(temperature, humidity)) if givenCRC == computedCRC: return Report(temperature, humidity, "TX29", devID)
def decode_tx29(binaryMsg): ''' Decoding a LaCrosse/TFA sensor message. ''' # lengths counts 4 bits (nibbles) excluding 1st one givenLength = take(binaryMsg, 0, 4) actualLength = len(binaryMsg) / 4 - 1 print("Length: actual={:02X}, received={:02X}, valid={}".format( actualLength, givenLength, "yes" if (givenLength == actualLength) else "no")) givenCRC = take(binaryMsg, binaryMsg.size - 8, 8) computedCRC = crc.crc(0x31, 8, 0, 0, binaryMsg[:-8]) print("CRC: computed={:02X}, received={:02X}, valid={}".format( computedCRC, givenCRC, "yes" if (givenCRC == computedCRC) else "no")) devID = take(binaryMsg, 4, 6) print("Device: id={:02X}".format(devID)) newBattery = take(binaryMsg, 10, 1) weakBattery = take(binaryMsg, 24, 1) print("Battery: new={}, weak={}".format("yes" if newBattery else "no", "yes" if weakBattery else "no")) temperature = (take(binaryMsg, 12, 4) * 10 + take(binaryMsg, 16, 4) + take(binaryMsg, 20, 4) * .1) - 40 reserved = take(binaryMsg, 11, 1) print("Reserved 0 bit: received={:01X}, valid={}".format( reserved, "yes" if (reserved == 0) else "no")) humidity = take(binaryMsg, 25, 7) if humidity == 106: humidity = "N/A" print("Temperature: {:+0.1f} C -- Humidity: {} %".format( temperature, humidity)) if givenCRC == computedCRC: return Report(temperature, humidity, "TX29", devID)
def decode_tx29(binaryMsg): givenCRC = take(binaryMsg, binaryMsg.size-8, 8) print "CRC: calculated={0:02X}, received={1:02X}".format(crc.crc(0x31, 8, 0, 0, binaryMsg[:-8]), givenCRC) temperature = (take(binaryMsg, 12, 4) * 10 + take(binaryMsg, 16, 4) + take(binaryMsg, 20, 4) * .1) - 40 humidity = take(binaryMsg, 24, 8) if humidity == 106: humidity = "N/A" print "Temperature: {0:0.1f} C -- Humidity: {1} %".format(temperature, humidity)
def decode_tx29(binaryMsg): givenCRC = take(binaryMsg, binaryMsg.size - 8, 8) print "CRC: calculated={0:02X}, received={1:02X}".format( crc.crc(0x31, 8, 0, 0, binaryMsg[:-8]), givenCRC) temperature = (take(binaryMsg, 12, 4) * 10 + take(binaryMsg, 16, 4) + take(binaryMsg, 20, 4) * .1) - 40 humidity = take(binaryMsg, 24, 8) if humidity == 106: humidity = "N/A" print "Temperature: {0:0.1f} C -- Humidity: {1} %".format( temperature, humidity)
def process_sdc_group(self, data): print("************************************************************") print("SDC ENTRY GROUP: total {0} bits ({1} bytes)".format(data.size, data.size/8)) given_crc = self.take(data, data.size-16, 16) data = data[:data.size-16] print "\tCRC: calc={0:04X}, given={1:04X}".format(crc.crc(0b0001000000100001, 16, 0xFFFF, 0xFFFF, data), given_crc) print("************************************************************") cont = True while cont: pos = self.process_sdc_entry(data) if pos < data.size: data = data[pos:] else: cont = 0