Esempio n. 1
0
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)
Esempio n. 2
0
 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)
Esempio n. 3
0
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))
Esempio n. 4
0
 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)
Esempio n. 5
0
    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)