Exemplo n.º 1
0
class SampleReadableLocation(Object):

    objectType = 'sampleReadableLocation'
    properties = [
        ReadableProperty('location', CharacterString),
    ]

    def __init__(self, **kwargs):
        if _debug: SampleReadableLocation._debug("__init__ %r", kwargs)
        Object.__init__(self, **kwargs)
Exemplo n.º 2
0
class ModbusLocalDevice(LocalDeviceObject):
    properties = [
        ReadableProperty('deviceIp', CharacterString),
        ReadableProperty('modbusId', Integer),
        ReadableProperty('modbusMapName', CharacterString),
        ReadableProperty('modbusMapRev', CharacterString),
        ReadableProperty('deviceModelName', CharacterString),
        ReadableProperty('modbusPort', Integer),
        # ReadableProperty('wordOrder', CharacterString)
        ReadableProperty('meterRespWordOrder', CharacterString),
    ]
Exemplo n.º 3
0
    class _Commando(object):

        properties = [
            WritableProperty(presentValue, datatype),
            ReadableProperty(priorityArray, PriorityArray),
            ReadableProperty(relinquishDefault, datatype),
        ]

        _pv_choice = None

        def __init__(self, **kwargs):
            super(_Commando, self).__init__(**kwargs)

            # build a default value in case one is needed
            default_value = datatype().value
            if issubclass(datatype, Enumerated):
                default_value = datatype._xlate_table[default_value]
            if _debug:
                Commandable._debug("    - default_value: %r", default_value)

            # see if a present value was provided
            if (presentValue not in kwargs):
                setattr(self, presentValue, default_value)

            # see if a priority array was provided
            if (priorityArray not in kwargs):
                setattr(self, priorityArray, PriorityArray())

            # see if a present value was provided
            if (relinquishDefault not in kwargs):
                setattr(self, relinquishDefault, default_value)

        def _highest_priority_value(self):
            if _debug: Commandable._debug("_highest_priority_value")

            priority_array = getattr(self, priorityArray)
            for i in range(1, 17):
                priority_value = priority_array[i]
                if priority_value.null is None:
                    if _debug:
                        Commandable._debug("    - found at index: %r", i)

                    value = getattr(priority_value, _Commando._pv_choice)
                    value_source = "###"

                    if issubclass(datatype, Enumerated):
                        value = datatype._xlate_table[value]
                        if _debug:
                            Commandable._debug(
                                "    - remapped enumeration: %r", value)

                    break
            else:
                value = getattr(self, relinquishDefault)
                value_source = None

            if _debug:
                Commandable._debug("    - value, value_source: %r, %r", value,
                                   value_source)

            # return what you found
            return value, value_source

        def WriteProperty(self,
                          property,
                          value,
                          arrayIndex=None,
                          priority=None,
                          direct=False):
            if _debug:
                Commandable._debug(
                    "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r",
                    property, value, arrayIndex, priority, direct)

            # when writing to the presentValue with a priority
            if (property == presentValue):
                if _debug:
                    Commandable._debug("    - writing to %s, priority %r",
                                       presentValue, priority)

                # default (lowest) priority
                if priority is None:
                    priority = 16
                if _debug:
                    Commandable._debug(
                        "    - translate to priority array, index %d",
                        priority)

                # translate to updating the priority array
                property = priorityArray
                arrayIndex = priority
                priority = None

            # update the priority array entry
            if (property == priorityArray):
                if (arrayIndex is None):
                    if _debug:
                        Commandable._debug("    - writing entire %s",
                                           priorityArray)

                    # pass along the request
                    super(_Commando, self).WriteProperty(
                        property,
                        value,
                        arrayIndex=arrayIndex,
                        priority=priority,
                        direct=direct,
                    )
                else:
                    if _debug:
                        Commandable._debug(
                            "    - writing to %s, array index %d",
                            priorityArray, arrayIndex)

                    # check the bounds
                    if arrayIndex == 0:
                        raise ExecutionError(errorClass='property',
                                             errorCode='writeAccessDenied')
                    if (arrayIndex < 1) or (arrayIndex > 16):
                        raise ExecutionError(errorClass='property',
                                             errorCode='invalidArrayIndex')

                    # update the specific priorty value element
                    priority_value = getattr(self, priorityArray)[arrayIndex]
                    if _debug:
                        Commandable._debug("    - priority_value: %r",
                                           priority_value)

                    # the null or the choice has to be set, the other clear
                    if value is ():
                        if _debug: Commandable._debug("    - write a null")
                        priority_value.null = value
                        setattr(priority_value, _Commando._pv_choice, None)
                    else:
                        if _debug: Commandable._debug("    - write a value")

                        if issubclass(datatype, Enumerated):
                            value = datatype._xlate_table[value]
                            if _debug:
                                Commandable._debug(
                                    "    - remapped enumeration: %r", value)

                        priority_value.null = None
                        setattr(priority_value, _Commando._pv_choice, value)

                # look for the highest priority value
                value, value_source = self._highest_priority_value()

                # compare with the current value
                current_value = getattr(self, presentValue)
                if value == current_value:
                    if _debug:
                        Commandable._debug("    - no present value change")
                    return

                # turn this into a present value change
                property = presentValue
                arrayIndex = priority = None

            # allow the request to pass through
            if _debug:
                Commandable._debug(
                    "    - super: %r %r arrayIndex=%r priority=%r", property,
                    value, arrayIndex, priority)

            super(_Commando, self).WriteProperty(
                property,
                value,
                arrayIndex=arrayIndex,
                priority=priority,
                direct=direct,
            )
Exemplo n.º 4
0
class ModbusAnalogInputObject(Object):
    objectType = 'analogInput'
    properties = \
        [ReadableProperty('presentValue', Real),
         OptionalProperty('deviceType', CharacterString),
         OptionalProperty('profileLocation', CharacterString),
         ReadableProperty('statusFlags', StatusFlags),
         ReadableProperty('eventState', EventState),
         OptionalProperty('reliability', Reliability),
         ReadableProperty('outOfService', Boolean),
         OptionalProperty('updateInterval', Unsigned),
         ReadableProperty('units', EngineeringUnits),
         OptionalProperty('minPresValue', Real, mutable=True),
         OptionalProperty('maxPresValue', Real, mutable=True),
         OptionalProperty('resolution', Real),
         OptionalProperty('covIncrement', Real),
         # OptionalProperty('timeDelay', Unsigned),
         # OptionalProperty('notificationClass', Unsigned),
         # OptionalProperty('highLimit', Real),
         # OptionalProperty('lowLimit', Real),
         # OptionalProperty('deadband', Real),
         # OptionalProperty('limitEnable', LimitEnable),
         # OptionalProperty('eventEnable', EventTransitionBits),
         OptionalProperty('ackedTransitions', EventTransitionBits),
         # OptionalProperty('notifyType', NotifyType),
         # OptionalProperty('eventTimeStamps', ArrayOf(TimeStamp)),
         # OptionalProperty('eventMessageTexts', ArrayOf(CharacterString)),
         # OptionalProperty('eventMessageTextsConfig', ArrayOf(CharacterString)),
         # OptionalProperty('eventDetectionEnable', Boolean),
         # OptionalProperty('eventAlgorithmInhibitRef', ObjectPropertyReference),
         # OptionalProperty('eventAlgorithmInhibit', Boolean),
         # OptionalProperty('timeDelayNormal', Unsigned),
         # OptionalProperty('reliabilityEvaluationInhibit', Boolean)
         ReadableProperty('modbusFunction', ModbusFunctions),
         ReadableProperty('registerStart', Unsigned),
         ReadableProperty('numberOfRegisters', Unsigned),
         ReadableProperty('registerFormat', CharacterString),
         ReadableProperty('wordOrder', CharacterString),
         ReadableProperty('modbusScaling', ArrayOf(Real)),
         ReadableProperty('modbusCommErr', ModbusErrors)
         ]

    def __init__(self, **kwargs):
        if _debug: ModbusAnalogInputObject._debug("__init__ %r", kwargs)
        Object.__init__(self, **kwargs)

        # set unassigned properties to default values
        for propid, prop in self._properties.items():
            if prop.ReadProperty(
                    self) is None and propid in modbus_ai_obj_def_vals:
                if _debug:
                    ModbusAnalogInputObject._debug(
                        '%s %s was not set, default is %s', self.objectName,
                        propid, modbus_ai_obj_def_vals[propid])

                prop.WriteProperty(self,
                                   modbus_ai_obj_def_vals[propid],
                                   direct=True)

    def ReadProperty(self, propid, arrayIndex=None):
        # if _debug: ModbusAnalogInputObject._debug('BACnet REQUEST for (%s, %s)  at %s: %s %s',_strftime(decimal_places=3), propid,
        #                                           getattr(self, propid))  # might need self._values[propid]

        # if _debug: ModbusAnalogInputObject._debug('BACnet REQUEST for (%s, %s), (%s, %s): %s at %s',
        #                                           self._app._values['objectName'],
        #                                           self._app._values['objectIdentifier'], self._values['objectName'],
        #                                           self._values['objectIdentifier'], propid, _strftime(decimal_places=3))
        value = Object.ReadProperty(self, propid, arrayIndex=arrayIndex)
        # if _debug: ModbusAnalogInputObject._debug('BACnet REQUEST for (%s, %s), (%s, %s), %s= %s at %s',
        #                                           self._app.localDevice._values['objectName'],
        #                                           self._app.localDevice._values['objectIdentifier'][1],
        #                                           self._values['objectName'], self._values['objectIdentifier'][1],
        #                                           propid, value, _strftime(decimal_places=3))
        if _debug:
            ModbusAnalogInputObject._debug(
                'BACnet REQUEST for (%s, %s), (%s, %s), %s= %s at %s',
                self._app.localDevice.objectName,
                self._app.localDevice.objectIdentifier[1], self.objectName,
                self.objectIdentifier[1], propid, value,
                _strftime(decimal_places=3))
        return value
Exemplo n.º 5
0
class NetworkPortObject(Object):
    objectType = 'NetworkPort'  #56
    properties = \
        [ ReadableProperty('statusFlags', StatusFlags)  #111
        , ReadableProperty('reliability', Reliability)  #103
        , ReadableProperty('outOfService', Boolean) #81
        , ReadableProperty('networkType', NetworkType)  #427
        , ReadableProperty('protocolLevel', ProtocolLevel)  #482
        , OptionalProperty('referencePort', Unsigned)   #483
        , ReadableProperty('networkNumber', Unsigned16) #425
        , ReadableProperty('networkNumberQuality', NetworkNumberQuality)    #427
        , ReadableProperty('changesPending', Boolean)   #416
        , OptionalProperty('command', NetworkPortCommand)   #417
        , OptionalProperty('macAddress', OctetString)   #423
        , ReadableProperty('apduLength', Unsigned)  #388
        , ReadableProperty('linkSpeed', Real)   #420
        , OptionalProperty('linkSpeeds', ArrayOf(Real)) #421
        , OptionalProperty('eventTimeStamps', ArrayOf(TimeStamp))   #130
        , OptionalProperty('linkSpeedAutonegotiate', Boolean)   #422
        , OptionalProperty('networkInterfaceName', CharacterString) #424
        , OptionalProperty('ipMode', IPMode)    #408
        , OptionalProperty('ipAddress', OctetString) #400
        , OptionalProperty('ipUDPPort', Unsigned16) #412
        , OptionalProperty('ipSubnetMask', OctetString) #411
        , OptionalProperty('ipDefaultGateway', OctetString) #401
        , OptionalProperty('ipMulticastAddress', OctetString)   #409
        , OptionalProperty('ipDNSServer', ArrayOf(OctetString)) #406
        , OptionalProperty('ipDHCPEnable', Boolean) #402
        , OptionalProperty('ipDHCPLeaseTime', Unsigned) #403
        , OptionalProperty('ipDHCPLeaseTimeRemaining', Unsigned)    #404
        , OptionalProperty('ipDHCPServer', OctetString) #405
        , OptionalProperty('ipNATTraversal', Boolean)   #410
        , OptionalProperty('ipGlobalAddress', HostNPort)    #407
        , OptionalProperty('broadcastDistributionTable', ListOf(BDTEntry))  #414
        , OptionalProperty('acceptFDRegistrations', Boolean)    #413
        , OptionalProperty('bbmdForeignDeviceTable', ListOf(FDTEntry))  #415
        , OptionalProperty('fdBBMDAddress', HostNPort)  #418
        , OptionalProperty('fdSubscriptionLifetime', Unsigned16)    #419
        , OptionalProperty('ipv6Mode', IPMode)  #435
        , OptionalProperty('ipv6Address', OctetString)  #436
        , OptionalProperty('ipv6PrefixLength', Unsigned8)   #437
        , OptionalProperty('ipv6UDPPort', Unsigned16)   #438
        , OptionalProperty('ipv6DefaultGateway', OctetString)   #439
        , OptionalProperty('ipv6MulticastAddress', OctetString) #440
        , OptionalProperty('ipv6DNSServer', OctetString)    #441
        , OptionalProperty('ipv6AutoAddressingEnabled', Boolean)    #442
        , OptionalProperty('ipv6DHCPLeaseTime', Unsigned)   #443
        , OptionalProperty('ipv6DHCPLeaseTimeRemaining', Unsigned)  #444
        , OptionalProperty('ipv6DHCPServer', OctetString)   #445
        , OptionalProperty('ipv6ZoneIndex', CharacterString)    #446
        , OptionalProperty('maxMasters', Unsigned8) # range 0-127   #64
        , OptionalProperty('maxInfoFrames', Unsigned8)  #63
        , OptionalProperty('slaveProxyEnable', Boolean) #172
        , OptionalProperty('manualSlaveAddressBinding', ListOf(AddressBinding)) #170
        , OptionalProperty('autoSlaveDiscovery', Boolean)   #169
        , OptionalProperty('slaveAddressBinding', ListOf(AddressBinding))   #171
        , OptionalProperty('virtualMACAddressTable', ListOf(VMACEntry)) #429
        , OptionalProperty('routingTable', ListOf(RouterEntry)) #428
        , OptionalProperty('eventDetectionEnabled', Boolean)    #353
        , OptionalProperty('notificationClass', Unsigned)   #17
        , OptionalProperty('eventEnable', EventTransitionBits)  #35
        , OptionalProperty('ackedTransitions', EventTransitionBits) #0
        , OptionalProperty('notifyType', NotifyType)    #72
        , OptionalProperty('eventTimeStamps', ArrayOf(TimeStamp, 3))    #130
        , OptionalProperty('eventMessageTexts', ArrayOf(CharacterString, 3))    #351
        , OptionalProperty('eventMessageTextsConfig', ArrayOf(CharacterString, 3))  #352
        , OptionalProperty('eventState', EventState)    #36
        , ReadableProperty('reliabilityEvaluationInhibit', Boolean) #357
        , OptionalProperty('propertyList', ArrayOf(PropertyIdentifier)) #371
        , OptionalProperty('tags', ArrayOf(NameValue))  #486
        , OptionalProperty('profileLocation', CharacterString)  #91
        , OptionalProperty('profileName', CharacterString)  #168
        ]