示例#1
0
class NullModel(ModelIf.IModel):
    logger = logging.getLogger("genicontrol")

    def initialize(self, quitEvent):
        for idx, item in enumerate(DataitemConfiguration['MeasurementValues']):
            key, displayName, unit, controlIdValue, controlIdUnit = item
            ditem =  dataitems.MEASUREMENT_VALUES[key]
            self.sendMessage('Measurements.%s' % key, ModelIf.DATA_NOT_AVAILABLE)
        self.sendMessage('References', ModelIf.DATA_NOT_AVAILABLE)
        self.dataAvailable = False
        self._quitEvent = quitEvent
        self._modelThread = RequestorThread(quitEvent)
        self._modelThread.start()
        return self._modelThread

    def quit(self):
        self._quitEvent.set()
        self._modelThread.join()

    def connect(self, *parameters):
        pass

    def disconnect(self):
        pass

    def requestMeasurementValues(self):
        pass

    def requestParameters(self):
        pass

    def requestReferences(self):
        pass

    def requestInfo(self):
        pass

    def setReferenceValue(self, item, value):
        pass

    def setParameterValue(self, item, value):
        pass

    def sendCommand(self, command):
        pass
示例#2
0
 def initialize(self, quitEvent):
     for idx, item in enumerate(DataitemConfiguration['MeasurementValues']):
         key, displayName, unit, controlIdValue, controlIdUnit = item
         ditem = dataitems.MEASUREMENT_VALUES[key]
         self.sendMessage('Measurements.%s' % key, ModelIf.DATA_NOT_AVAILABLE)
     self.sendMessage('References', ModelIf.DATA_NOT_AVAILABLE)
     self.dataAvailable = False
     self._quitEvent = quitEvent
     self._setValueLock = threading.RLock()
     self._concurrentAccess = threading.Lock()
     self._commandRequested = False
     self._valueDict = createDataDictionary()
     self._infoDict = createDataDictionary()
     self._values = dict()
     self.connected = False
     self._modelThread = RequestorThread(self)
     self._requestQueue = self._modelThread.requestQueue
     self._modelThread.start()
     return self._modelThread
示例#3
0
 def initialize(self, quitEvent):
     for idx, item in enumerate(DataitemConfiguration['MeasurementValues']):
         key, displayName, unit, controlIdValue, controlIdUnit = item
         ditem =  dataitems.MEASUREMENT_VALUES[key]
         self.sendMessage('Measurements.%s' % key, ModelIf.DATA_NOT_AVAILABLE)
     self.sendMessage('References', ModelIf.DATA_NOT_AVAILABLE)
     self.dataAvailable = False
     self._quitEvent = quitEvent
     self._modelThread = RequestorThread(quitEvent)
     self._modelThread.start()
     return self._modelThread
示例#4
0
 def initialize(self, quitEvent):
     for idx, item in enumerate(DataitemConfiguration['MeasurementValues']):
         key, displayName, unit, controlIdValue, controlIdUnit = item
         ditem =  dataitems.MEASUREMENT_VALUES[key]
         self.sendMessage('Measurements.%s' % key, ModelIf.DATA_NOT_AVAILABLE)
     self.sendMessage('References', ModelIf.DATA_NOT_AVAILABLE)
     self.dataAvailable = False
     self._quitEvent = quitEvent
     self._setValueLock = threading.RLock()
     self._concurrentAccess = threading.Lock()
     self._commandRequested = False
     self._valueDict = createDataDictionary()
     self._infoDict = createDataDictionary()
     self._values = dict()
     self.connected = False
     self._modelThread = RequestorThread(self)
     self._requestQueue = self._modelThread.requestQueue
     self._modelThread.start()
     return self._modelThread
示例#5
0
class NullModel(ModelIf.IModel):
    logger = logging.getLogger("GeniControl")
    TYPE = "Simulator"
    SPECIAL_DATAPOINTS = ('act_mode1', 'act_mode2', 'act_mode3', 'contr_source')

    def initialize(self, quitEvent):
        for idx, item in enumerate(DataitemConfiguration['MeasurementValues']):
            key, displayName, unit, controlIdValue, controlIdUnit = item
            ditem =  dataitems.MEASUREMENT_VALUES[key]
            self.sendMessage('Measurements.%s' % key, ModelIf.DATA_NOT_AVAILABLE)
        self.sendMessage('References', ModelIf.DATA_NOT_AVAILABLE)
        self.dataAvailable = False
        self._quitEvent = quitEvent
        self._setValueLock = threading.RLock()
        self._concurrentAccess = threading.Lock()
        self._commandRequested = False
        self._valueDict = createDataDictionary()
        self._infoDict = createDataDictionary()
        self._values = dict()
        self.connected = False
        self._modelThread = RequestorThread(self)
        self._requestQueue = self._modelThread.requestQueue
        self._modelThread.start()
        return self._modelThread

    def quit(self):
        self._quitEvent.set()
        self._modelThread.join()

    def writeToServer(self, req):
        self._connection.write(req)
        self._controller.trace(False, req)

    def readFromServer(self):
        resp = self._connection.read(0x100)
        self._controller.trace(True, resp)
        return resp

    def connect(self, toDriver = True):
        if toDriver:
             res = self._connection.connect()
             self.connected = res
             if not res:
                  self._connection.close()
        else:
             pdu = apdu.createConnectRequestPDU(0x01)
             self._modelThread.request(pdu)

    def disconnect(self):
        pass

    def request(self, requ):
        self._requestQueue.put(requ)

    def requestMeasurementValues(self):
        pass

    def requestParameters(self):
        pass

    def requestReferences(self, req):
        pass

    def requestInfo(self, req):
        self._modelThread.request(req)

    def setReferenceValue(self, item, value):
        pass

    def setParameterValue(self, item, value):
        pass

    def sendCommand(self, command):
        self._concurrentAccess.acquire()
        print "Command requested:", command
        self._commandRequested = True
        req = apdu.createSetCommandsPDU(
            apdu.Header(defs.SD_DATA_REQUEST, self.getUnitAddress(), 0x04),
            [command]
        )
        self.writeToServer(req)
        self._concurrentAccess.release()

    def roundValue(self, value):
        return int(math.ceil(value * 100))/100.00

    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 updateReferences(self, references):
        msg = "REFERENCE_VALUES.%s"
        for key, value in references.items():
            self.sendMessage(msg % key, value)

    def updateParameter(self, parameter):
        msg = "CONFIGURATION_PARAMETERS.%s"
        for key, value in parameter.items():
            self.sendMessage(msg % key, value)

    def setValue(self, group, datapoint, value):
        self._setValueLock.acquire()
        #print "SetValue - Group: %s DP: % s Value: %s" % (defs.ADPUClass.toString(group), datapoint, value)
        self._valueDict.setdefault(group, dict())[datapoint] = value
        self.sendMessage("%s.%s" % (defs.ADPUClass.toString(group), datapoint), value)
        self._setValueLock.release()

    def getValue(self, group, datapoint):
        group = self._valueDict.get(group, None)
        if not group:
            return None
        return group.get(datapoint, None)

    def getUnitAddress(self):
        return self.getValue(defs.ADPUClass.CONFIGURATION_PARAMETERS, 'unit_addr')

    def updateInfoDict(self, di):
        for key, value in di.items():
            self._infoDict[key].update(value)
        self.sendMessage('INFO', di)

    def getInfo(self, klass, dp):
        return self._infoDict[klass][dp]
示例#6
0
class NullModel(ModelIf.IModel):
    logger = logging.getLogger("GeniControl")
    TYPE = "Simulator"
    SPECIAL_DATAPOINTS = ('act_mode1', 'act_mode2', 'act_mode3', 'contr_source')

    def initialize(self, quitEvent):
        for idx, item in enumerate(DataitemConfiguration['MeasurementValues']):
            key, displayName, unit, controlIdValue, controlIdUnit = item
            ditem = dataitems.MEASUREMENT_VALUES[key]
            self.sendMessage('Measurements.%s' % key, ModelIf.DATA_NOT_AVAILABLE)
        self.sendMessage('References', ModelIf.DATA_NOT_AVAILABLE)
        self.dataAvailable = False
        self._quitEvent = quitEvent
        self._setValueLock = threading.RLock()
        self._concurrentAccess = threading.Lock()
        self._commandRequested = False
        self._valueDict = createDataDictionary()
        self._infoDict = createDataDictionary()
        self._values = dict()
        self.connected = False
        self._modelThread = RequestorThread(self)
        self._requestQueue = self._modelThread.requestQueue
        self._modelThread.start()
        return self._modelThread

    def quit(self):
        self._quitEvent.set()
        self._modelThread.join()

    def writeToServer(self, req):
        self._connection.write(req)
        self._controller.trace(False, req)

    def readFromServer(self):
        resp = self._connection.read(0x100)
        self._controller.trace(True, resp)
        return resp

    def connect(self, toDriver = True):
        if toDriver:
            res = self._connection.connect()
            self.connected = res
            if not res:
                self._connection.close()
        else:
            #pdu = apdu.createSetRemotePDU(0x01)
            #self._modelThread.request(pdu)
            pdu = apdu.createConnectRequestPDU(0x01)
            self._modelThread.request(pdu)

    def disconnect(self):
        pass

    def request(self, requ):
        self._requestQueue.put(requ)

    def requestMeasurementValues(self):
        pass

    def requestParameters(self):
        pass

    def requestReferences(self, req):
        pass

    def requestInfo(self, req):
        self._modelThread.request(req)

    def setReferenceValue(self, item, value):
        pass

    def setParameterValue(self, item, value):
        pass

    def sendCommand(self, command):
        self._concurrentAccess.acquire()
        print("Command requested:", command)
        self._commandRequested = True
        req = apdu.createSetCommandsPDU(
            apdu.Header(defs.SD_DATA_REQUEST, self.getUnitAddress(), 0x01),
            [command]
        )
        self.writeToServer(req)
        self._concurrentAccess.release()

    def roundValue(self, value):
        return int(math.ceil(value * 100))/100.00

    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 updateReferences(self, references):
        msg = "REFERENCE_VALUES.%s"
        for key, value in references.items():
            self.sendMessage(msg % key, value)

    def updateParameter(self, parameter):
        items = parameter.items()
        msg = "CONFIGURATION_PARAMETERS.%s"
        for key, value in items:
            self.sendMessage(msg % key, value)

    def setValue(self, group, datapoint, value):
        self._setValueLock.acquire()
        self._valueDict.setdefault(group, dict())[datapoint] = value
        self.sendMessage("%s.%s" % (defs.APDUClass.toString(group), datapoint), value)
        self._setValueLock.release()

    def getValue(self, group, datapoint):
        group = self._valueDict.get(group, None)
        if not group:
            return None
        return group.get(datapoint, None)

    def getUnitAddress(self):
        return self.getValue(defs.APDUClass.CONFIGURATION_PARAMETERS, 'unit_addr')

    def updateInfoDict(self, di):
        for key, value in di.items():
            self._infoDict[key].update(value)
        self.sendMessage('INFO', di)

    def getInfo(self, klass, dp):
        return self._infoDict[klass][dp]