Exemplo n.º 1
0
class MyScheduleObject(ScheduleObject):

    properties = [
        WritableProperty('weeklySchedule', ArrayOf(DailySchedule)),
        WritableProperty('priorityForWriting', Unsigned),
    ]

    def __init__(self, **kwargs):
        if _debug: MyScheduleObject._debug("__init__ %r", kwargs)
        ScheduleObject.__init__(self, **kwargs)
Exemplo n.º 2
0
class SampleWritableLocation(Object):

    objectType = 'sampleWritableLocation'
    properties = [
        WritableProperty('location', CharacterString),
    ]

    def __init__(self, **kwargs):
        if _debug: SampleWritableLocation._debug("__init__ %r", kwargs)
        Object.__init__(self, **kwargs)
Exemplo n.º 3
0
class SampleLocationObject(CurrentPropertyListMixIn, Object):

    objectType = 'sampleLocationObject'
    properties = [
        WritableProperty('location', CharacterString),
    ]

    def __init__(self, **kwargs):
        if _debug: SampleWritableArray._debug("__init__ %r", kwargs)
        Object.__init__(self, **kwargs)
Exemplo n.º 4
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.º 5
0
class WritableAnalogValueObject(CurrentPropertyListMixIn, AnalogValueObject):

    properties = [WritableProperty("presentValue", Real)]
Exemplo n.º 6
0
class WritableAnalogValueObject(AnalogValueObject):
    properties = [WritableProperty("presentValue", Real)]
Exemplo n.º 7
0
class LocalScheduleObject(CurrentPropertyListMixIn, ScheduleObject):

    properties = [
        WritableProperty('presentValue', AnyAtomic),
    ]

    def __init__(self, **kwargs):
        if _debug: LocalScheduleObject._debug("__init__ %r", kwargs)
        ScheduleObject.__init__(self, **kwargs)

        # attach an interpreter task
        self._task = LocalScheduleInterpreter(self)

        # add some monitors
        for prop in ('weeklySchedule', 'exceptionSchedule', 'scheduleDefault'):
            self._property_monitors[prop].append(self._check_reliability)

        # check it now
        self._check_reliability()

    def _check_reliability(self, old_value=None, new_value=None):
        """This function is called when the object is created and after
        one of its configuration properties has changed.  The new and old value
        parameters are ignored, this is called after the property has been
        changed and this is only concerned with the current value."""
        if _debug:
            LocalScheduleObject._debug("_check_reliability %r %r", old_value,
                                       new_value)

        try:
            schedule_default = self.scheduleDefault

            if schedule_default is None:
                raise ValueError("scheduleDefault expected")
            if not isinstance(schedule_default, Atomic):
                raise TypeError(
                    "scheduleDefault must be an instance of an atomic type")

            if (self.weeklySchedule is None) and (self.exceptionSchedule is
                                                  None):
                raise ValueError("schedule required")

            schedule_datatype = schedule_default.__class__
            if _debug:
                LocalScheduleObject._debug("    - schedule_datatype: %r",
                                           schedule_datatype)

            # check the weekly schedule values
            if self.weeklySchedule:
                for daily_schedule in self.weeklySchedule:
                    for time_value in daily_schedule.daySchedule:
                        if _debug:
                            LocalScheduleObject._debug(
                                "    - daily time_value: %r", time_value)
                        if time_value is None:
                            pass
                        elif not isinstance(time_value.value,
                                            (Null, schedule_datatype)):
                            if _debug:
                                LocalScheduleObject._debug(
                                    "    - wrong type: expected %r, got %r",
                                    schedule_datatype,
                                    time_value.__class__,
                                )
                            raise TypeError("wrong type")
                        elif 255 in time_value.time:
                            if _debug:
                                LocalScheduleObject._debug(
                                    "    - wildcard in time")
                            raise ValueError("must be a specific time")

            # check the exception schedule values
            if self.exceptionSchedule:
                for special_event in self.exceptionSchedule:
                    for time_value in special_event.listOfTimeValues:
                        if _debug:
                            LocalScheduleObject._debug(
                                "    - special event time_value: %r",
                                time_value)
                        if time_value is None:
                            pass
                        elif not isinstance(time_value.value,
                                            (Null, schedule_datatype)):
                            if _debug:
                                LocalScheduleObject._debug(
                                    "    - wrong type: expected %r, got %r",
                                    schedule_datatype,
                                    time_value.__class__,
                                )
                            raise TypeError("wrong type")

            # check list of object property references
            obj_prop_refs = self.listOfObjectPropertyReferences
            if obj_prop_refs:
                for obj_prop_ref in obj_prop_refs:
                    obj_type = obj_prop_ref.objectIdentifier[0]

                    # get the datatype of the property to be written
                    datatype = get_datatype(obj_type,
                                            obj_prop_ref.propertyIdentifier)
                    if _debug:
                        LocalScheduleObject._debug("    - datatype: %r",
                                                   datatype)

                    if issubclass(datatype,
                                  Array) and (obj_prop_ref.propertyArrayIndex
                                              is not None):
                        if obj_prop_ref.propertyArrayIndex == 0:
                            datatype = Unsigned
                        else:
                            datatype = datatype.subtype
                        if _debug:
                            LocalScheduleObject._debug("    - datatype: %r",
                                                       datatype)

                    if datatype is not schedule_datatype:
                        if _debug:
                            LocalScheduleObject._debug(
                                "    - wrong type: expected %r, got %r",
                                datatype,
                                schedule_datatype,
                            )
                        raise TypeError("wrong type")

            # all good
            self.reliability = 'noFaultDetected'
            if _debug: LocalScheduleObject._debug("    - no fault detected")

        except Exception as err:
            if _debug: LocalScheduleObject._debug("    - exception: %r", err)
            self.reliability = 'configurationError'