def __init__(self, vlan_device, vlan_address, aseID=None):
        if _debug: VLANApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID)
        Application.__init__(self, vlan_device, vlan_address, aseID)

        # include a application decoder
        self.asap = ApplicationServiceAccessPoint()

        # pass the device object to the state machine access point so it
        # can know if it should support segmentation
        self.smap = StateMachineAccessPoint(vlan_device)

        # a network service access point will be needed
        self.nsap = NetworkServiceAccessPoint()

        # give the NSAP a generic network layer service element
        self.nse = NetworkServiceElement()
        bind(self.nse, self.nsap)

        # bind the top layers
        bind(self, self.asap, self.smap, self.nsap)

        # create a vlan node at the assigned address
        self.vlan_node = Node(vlan_address)

        # bind the stack to the node, no network number
        self.nsap.bind(self.vlan_node)
Exemple #2
0
    def __init__(self, *args, **kwargs):
        """
        This function constructs the application object.

        :return: BasicApplication instance
        """

        # call constructor of predecessor class
        BACpypesApplication.__init__(self, *args, **kwargs)

        # reset protected properties
        self.protected_properties = (
            # device itself
            self.objectName.keys()[0],

            # python program
            'configuration',

            # program control
            'control',
        )

        # initialize device dictionary
        self.known_devices = {}

        # initialize remote subscriptions
        self.remote_subscriptions = {}

        # set event
        self.update_devices_now = Event()
 def __init__(self, localDevice, localAddress, aseID=None):
     if _debug: TestApplication._debug("__init__ %r %r aseID=%r", localDevice, localAddress, aseID)
     Application.__init__(self, localDevice, localAddress, aseID)
 def confirmation(self, apdu):
     if _debug: VLANApplication._debug("[%s]confirmation %r", self.vlan_node.address, apdu)
     Application.confirmation(self, apdu)
 def response(self, apdu):
     if _debug: VLANApplication._debug("[%s]response %r", self.vlan_node.address, apdu)
     Application.response(self, apdu)
 def indication(self, apdu):
     if _debug: VLANApplication._debug("[%s]indication %r", self.vlan_node.address, apdu)
     Application.indication(self, apdu)
 def __init__(self, localDevice, localAddress, aseID=None):
     if _debug:
         TestApplication._debug("__init__ %r %r aseID=%r", localDevice,
                                localAddress, aseID)
     Application.__init__(self, localDevice, localAddress, aseID)
Exemple #8
0
 def confirmation(self, apdu):
     if _debug:
         VLANApplication._debug("[%s]confirmation %r",
                                self.vlan_node.address, apdu)
     Application.confirmation(self, apdu)
Exemple #9
0
 def response(self, apdu):
     if _debug:
         VLANApplication._debug("[%s]response %r", self.vlan_node.address,
                                apdu)
     Application.response(self, apdu)
Exemple #10
0
 def indication(self, apdu):
     if _debug:
         VLANApplication._debug("[%s]indication %r", self.vlan_node.address,
                                apdu)
     Application.indication(self, apdu)
def main():
    global args, schedule_objects

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # set up testing
    setup_module()

    # reset the time machine
    reset_time_machine(start_time="1970-01-01")

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=('device', int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a floating application, no network interface
    this_application = Application(this_device)

    #
    #   Simple daily schedule (actually a weekly schedule with every day
    #   being identical.
    #
    so = LocalScheduleObject(
        objectIdentifier=('schedule', 1),
        objectName='Schedule 1',
        presentValue=Real(-1.0),
        effectivePeriod=DateRange(
            startDate=(0, 1, 1, 1),
            endDate=(254, 12, 31, 2),
            ),
        weeklySchedule=ArrayOf(DailySchedule)([
            DailySchedule(
                daySchedule=[
                    TimeValue(time=(8,0,0,0), value=Real(8)),
                    TimeValue(time=(14,0,0,0), value=Null()),
                    TimeValue(time=(17,0,0,0), value=Real(42)),
#                   TimeValue(time=(0,0,0,0), value=Null()),
                    ]
                ),
            ] * 7),
        listOfObjectPropertyReferences=[
            DeviceObjectPropertyReference(
                objectIdentifier=('analogValue', 1),
                propertyIdentifier='presentValue',
#               propertyArrayIndex=5,
#               deviceIdentifier=('device', 999),
                ),
            ],
        priorityForWriting=7,
        scheduleDefault=Real(0.0),
        )
    _log.debug("    - so: %r", so)
    this_application.add_object(so)

    # add an analog value object
    avo = WritableAnalogValueObject(
        objectIdentifier=('analogValue', 1),
        objectName='analog value 1',
        presentValue=0.0,
        )
    _log.debug("    - avo: %r", avo)
    this_application.add_object(avo)

    print("{} @ {}".format(so.presentValue.value, Time().now()))

    for i in range(1, 25):
        hr = "{}:00:01".format(i)

        # let it run until just after midnight
        run_time_machine(stop_time=hr)

        print("{}, {} @ {}".format(
            so.presentValue.value,
            avo.presentValue,
            Time().now(),
            ))

    # done testing
    teardown_module()
 def request(self, apdu):
     TestApplication._debug("request %r", apdu)
     Application.request(self, apdu)
    def test_local_schedule(self):
        if _debug: TestLocalSchedule._debug("test_local_schedule")

        # reset the time machine
        reset_time_machine(start_time="1970-01-01")

        # make a device object
        this_device = LocalDeviceObject(
            objectName="device 1",
            objectIdentifier=('device', 1),
            maxApduLengthAccepted=1024,
            segmentationSupported='segmentedBoth',
            vendorIdentifier=999,
        )

        # make a floating application, no network interface
        this_application = Application(this_device)

        # create a writeable analog value object
        avo = WritableAnalogValueObject(
            objectIdentifier=('analogValue', 1),
            objectName='analog value 1',
            presentValue=0.0,
        )
        _log.debug("    - avo: %r", avo)
        this_application.add_object(avo)

        # create a simple daily schedule, actually a weekly schedule with
        # every day identical
        so = LocalScheduleObject(
            objectIdentifier=('schedule', 1),
            objectName='Schedule 1',
            presentValue=Real(-1.0),
            effectivePeriod=DateRange(
                startDate=(0, 1, 1, 1),
                endDate=(254, 12, 31, 2),
            ),
            weeklySchedule=ArrayOf(DailySchedule)([
                DailySchedule(daySchedule=[
                    TimeValue(time=(8, 0, 0, 0), value=Real(8)),
                    TimeValue(time=(14, 0, 0, 0), value=Null()),
                    TimeValue(time=(17, 0, 0, 0), value=Real(42)),
                ]),
            ] * 7),
            listOfObjectPropertyReferences=ListOf(
                DeviceObjectPropertyReference)([
                    DeviceObjectPropertyReference(
                        objectIdentifier=('analogValue', 1),
                        propertyIdentifier='presentValue',
                    ),
                ], ),
            priorityForWriting=7,
            scheduleDefault=Real(0.0),
        )
        _log.debug("    - so: %r", so)
        this_application.add_object(so)

        # run from midnight to just after midnight the next day
        for hr, val in zip(range(0, 26),
                           [0] * 8 + [8] * 6 + [0] * 3 + [42] * 7 + [0]):
            # let it run
            run_time_machine(stop_time="{}:00:01".format(hr))
            if _debug:
                TestLocalSchedule._debug(
                    "    - hr, val, pv: %s, %s, %s",
                    hr,
                    val,
                    so.presentValue.value,
                )

            assert so.presentValue.value == val
            assert avo.presentValue == val
Exemple #14
0
 def confirmation(self, apdu, forwarded=False):
     if _debug: ModbusVLANApplication._debug("[%s]confirmation %r", self.vlan_node.address, apdu)
     Application.confirmation(self, apdu, forwarded=forwarded)
Exemple #15
0
 def response(self, apdu, forwarded=False):
     if _debug: ModbusVLANApplication._debug("[%s]response %r", self.vlan_node.address, apdu)
     Application.response(self, apdu, forwarded=forwarded)
Exemple #16
0
 def indication(self, apdu, forwarded=False):
     if _debug: ModbusVLANApplication._debug("[%s]indication %r %r", self.vlan_node.address, apdu, forwarded)
     Application.indication(self, apdu, forwarded=forwarded)