def main(): for info, value in TestValues: scaling = getScalingInfo(info) print scaling if value > 0xff: print convertForward16(value, info.zero, info.range, scaling.factor) else: print convertForward8(value, info.zero, info.range, scaling.factor)
def rawInterpreteResponse(response, datapoints, valueInterpretation): result = MyList() for apdu in response.APDUs: if valueInterpretation == defs.OS_GET: dataItemsByName = dict([(a, (b, c)) for a, b ,c in DATA_POOL[apdu.klass]]) for name, value in zip(datapoints, apdu.data): _, (head, unit, zero, range) = dataItemsByName[name] if head == 0x82: unitInfo = units.UnitTable[unit] result.append(ValueType(name, unitInfo.unit, conversion.convertForward8(value, zero, range, unitInfo.factor))) elif valueInterpretation == defs.OS_INFO: idx = 0 values = [] for datapoint in datapoints: data = apdu.data[idx] sif = data & 0b11 if sif in (0, 1): result.append(Info(data, None, None, None)) idx += 1 # No scaling information. else: result.append(Info(data, apdu.data[idx + 1], apdu.data[idx + 2], apdu.data[idx + 3])) idx += 4 elif valueInterpretation == defs.OS_SET: result.append(AckType(apdu.klass, apdu.ack >> 6)) result.type = valueInterpretation return result
def updateMeasurements(self, measurements): items = measurements.items() for key, value in items: if key in NullModel.SPECIAL_DATAPOINTS: # Special handling of bit fields. msg = "PUMP_STATUS.%s" datapoints = dissectPumpStatus(key, value) for key, value in datapoints: self.sendMessage(msg % key, str(value)) elif key.endswith('_lo'): continue elif key.endswith('_hi'): key = key[ : key.index('_hi')] #print "16Bit", key, value_hi = value value_lo = measurements[key + '_lo'] value = makeWord(value_hi, value_lo) scaledValue = "%.2f" % self.roundValue(conversion.convertForward16(value, info.zero, info.range, scalingInfo.factor)) msg = "MEASURERED_DATA.%s" self.sendMessage(msg % key + '_hi', scaledValue) else: info = self.getInfo(defs.ADPUClass.MEASURERED_DATA, key) scalingInfo = getScalingInfo(info) if value == 0xff: scaledValue = 'n/a' else: if (info.head & 0x02) == 2: scaledValue = "%.2f" % self.roundValue(conversion.convertForward8(value, info.zero, info.range, scalingInfo.factor)) else: scaledValue = str(value) # Unscaled. msg = "MEASURERED_DATA.%s" self.sendMessage(msg % key, scaledValue)
def main(): for info, value in TestValues: scaling = getScalingInfo(info) print(scaling) if value > 0xff: print( convertForward16(value, info.zero, info.range, scaling.factor)) else: print(convertForward8(value, info.zero, info.range, scaling.factor))
def updateMeasurements(self, measurements): items = measurements.items() for key, value in items: if key in NullModel.SPECIAL_DATAPOINTS: # Special handling of bit fields. msg = "PUMP_STATUS.%s" datapoints = dissectPumpStatus(key, value) for key, value in datapoints: self.sendMessage(msg % key, str(value)) elif key.endswith('_lo'): continue elif key.endswith('_hi'): info = self.getInfo(defs.APDUClass.MEASURED_DATA, key) scalingInfo = getScalingInfo(info) key = key[ : key.index('_hi')] value_hi = value value_lo = measurements[key + '_lo'] value = makeWord(value_hi, value_lo) if key == 'speed': # 0x83 Extended Precision 16bit scaledValue = "%.2f" % self.roundValue(conversion.convertExtended16(value, info.zero, info.range, scalingInfo.factor)) else: scaledValue = "%.2f" % self.roundValue(conversion.convertForward16(value, info.zero, info.range, scalingInfo.factor)) msg = "MEASURED_DATA.%s" self.sendMessage(msg % key + '_hi', scaledValue) elif key.endswith('_16'): # 0x83 Extended Precision 16bit info = self.getInfo(defs.APDUClass.SIXTEENBIT_MEASURED_DATA, key) scalingInfo = getScalingInfo(info) if key == 't_w_16': scaledValue = "%.2f" % self.roundValue(conversion.convertExtended16(value, info.zero, info.range, scalingInfo.factor)) scaledValue = str(float(scaledValue) - 273.15) # Kelvin -> Celsius else: scaledValue = "%.2f" % self.roundValue(conversion.convertExtended16(value, info.zero, info.range, scalingInfo.factor)) msg = "SIXTEENBIT_MEASURED_DATA.%s" self.sendMessage(msg % key, scaledValue) else: info = self.getInfo(defs.APDUClass.MEASURED_DATA, key) scalingInfo = getScalingInfo(info) if value == 0xff: scaledValue = 'n/a' else: if (info.head & 0x02) == 2: scaledValue = "%.2f" % self.roundValue(conversion.convertForward8(value, info.zero, info.range, scalingInfo.factor)) else: scaledValue = str(value) # Unscaled. msg = "MEASURED_DATA.%s" self.sendMessage(msg % key, scaledValue)
def rawInterpreteResponse(response, datapoints, valueInterpretation): result = MyList() for apdu in response.APDUs: if valueInterpretation == defs.OS_GET: dataItemsByName = dict([(a, (b, c)) for a, b, c in DATA_POOL[apdu.klass]]) for name, value in zip(datapoints, apdu.data): _, (head, unit, zero, range) = dataItemsByName[name] unitInfo = units.UnitTable[unit] if head == 0x82: result.append( ValueType( name, unitInfo.unit, conversion.convertForward8(value, zero, range, unitInfo.factor))) elif head == 0x83: result.append( ValueType( name, unitInfo.unit, conversion.Extended16(value, zero, range, unitInfo.factor))) elif valueInterpretation == defs.OS_INFO: idx = 0 values = [] for datapoint in datapoints: data = apdu.data[idx] sif = data & 0b11 if sif in (0, 1): result.append(Info(data, None, None, None)) idx += 1 # No scaling information. else: result.append( Info(data, apdu.data[idx + 1], apdu.data[idx + 2], apdu.data[idx + 3])) idx += 4 elif valueInterpretation == defs.OS_SET: result.append(AckType(apdu.klass, apdu.ack >> 6)) result.type = valueInterpretation return result
value is a regular measurement value. e.g.: python ValueCalculator.py """ % os.path.split(sys.argv[0])[1] print USAGE # UNIT RANGE ZERO # 21 90 10 # 44 120 0 u21 = UnitTable[21] u44 = UnitTable[44] print convertForward8(163, 10, 90, 1) print convertForward16(0x10d6, 0, 120, 1) def argumentsToLower(): return map(lambda x: string.lower(x), sys.argv[1 :]) def main(): for info, value in TestValues: scaling = getScalingInfo(info) print scaling if value > 0xff: print convertForward16(value, info.zero, info.range, scaling.factor) else: print convertForward8(value, info.zero, info.range, scaling.factor)