Esempio n. 1
0
    def setup_device(self,
                     async_call,
                     address,
                     max_apdu_len=1024,
                     seg_supported='segmentedBoth',
                     obj_id=599,
                     obj_name='sMap BACnet driver',
                     ven_id=15):

        _log.info('seg_supported ' + str(seg_supported))
        _log.info('max_apdu_len ' + str(max_apdu_len))
        _log.info('obj_id ' + str(obj_id))
        _log.info('obj_name ' + str(obj_name))
        _log.info('ven_id ' + str(ven_id))

        # Check to see if they gave a valid apdu length.
        if encode_max_apdu_length_accepted(max_apdu_len) is None:
            raise ValueError(
                "Invalid max_apdu_len: {} Valid options are 50, "
                "128, 206, 480, 1024, and 1476".format(max_apdu_len))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
        )

        # build a bit string that knows about the bit names.
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        def i_am_callback(address, device_id, max_apdu_len, seg_supported,
                          vendor_id):
            async_call.send(None, self.i_am, address, device_id, max_apdu_len,
                            seg_supported, vendor_id)

        #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz')

        self.this_application = BACnet_application(i_am_callback, this_device,
                                                   address)

        kwargs = {"spin": 0.1, "sigterm": None, "sigusr1": None}

        server_thread = threading.Thread(target=bacpypes.core.run,
                                         kwargs=kwargs)

        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()
Esempio n. 2
0
    def setup_device(self, async_call, address,
                     max_apdu_len=1024,
                     seg_supported='segmentedBoth',
                     obj_id=599,
                     obj_name='sMap BACnet driver',
                     ven_id=15):

        _log.info('seg_supported '+str(seg_supported))
        _log.info('max_apdu_len '+str(max_apdu_len))
        _log.info('obj_id '+str(obj_id))
        _log.info('obj_name '+str(obj_name))
        _log.info('ven_id '+str(ven_id))

        # Check to see if they gave a valid apdu length.
        if encode_max_apdu_length_accepted(max_apdu_len) is None:
            raise ValueError("Invalid max_apdu_len: {} Valid options are 50, "
                             "128, 206, 480, 1024, and 1476".format(
                                 max_apdu_len))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
            )

        # build a bit string that knows about the bit names.
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        def i_am_callback(address, device_id, max_apdu_len,
                          seg_supported, vendor_id):
            async_call.send(None, self.i_am, address, device_id, max_apdu_len,
                            seg_supported, vendor_id)

        #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz')

        self.this_application = BACnet_application(i_am_callback, this_device,
                                                   address)

        kwargs = {"spin":0.1,
                  "sigterm": None,
                  "sigusr1": None}

        server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs)

        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()
Esempio n. 3
0
    def setup_device(self, async_call, address,
                     max_apdu_len=1024,
                     seg_supported='segmentedBoth',
                     obj_id=599,
                     obj_name='sMap BACnet driver',
                     ven_id=15,
                     request_check_interval=100):

        _log.info('seg_supported '+str(seg_supported))
        _log.info('max_apdu_len '+str(max_apdu_len))
        _log.info('obj_id '+str(obj_id))
        _log.info('obj_name '+str(obj_name))
        _log.info('ven_id '+str(ven_id))

        # Check to see if they gave a valid apdu length.
        if encode_max_apdu_length_accepted(max_apdu_len) is None:
            raise ValueError("Invalid max_apdu_len: {} Valid options are 50, "
                             "128, 206, 480, 1024, and 1476".format(
                                 max_apdu_len))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
            )

        # build a bit string that knows about the bit names.
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        def i_am_callback(address, device_id, max_apdu_len,
                          seg_supported, vendor_id):
            async_call.send(None, self.i_am, address, device_id, max_apdu_len,
                            seg_supported, vendor_id)

        def send_cov_subscription_callback(device_address,
                                           subscriberProcessIdentifier,
                                           monitoredObjectIdentifier, lifetime,
                                           point_name):
            """Asynchronus cov subscription callback for gevent"""
            async_call.send(None, self.send_cov_subscription, device_address,
                            subscriberProcessIdentifier,
                            monitoredObjectIdentifier, lifetime, point_name)

        def forward_cov_callback(point_name, apdu, result_dict):
            """Asynchronus callback to forward cov values to the master driver
            for gevent"""
            async_call.send(None, self.forward_cov, point_name, apdu, result_dict)


        #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz')

        self.this_application = BACnet_application(i_am_callback,
                                                   send_cov_subscription_callback,
                                                   forward_cov_callback,
                                                   request_check_interval,
                                                   this_device,
                                                   address)

        # Having a recurring task makes the spin value kind of irrelevant.
        kwargs = {"spin": 0.1,
                  "sigterm": None,
                  "sigusr1": None}

        server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs)

        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()
Esempio n. 4
0
    def setup_device(self,
                     async_call,
                     address,
                     max_apdu_len=1024,
                     seg_supported='segmentedBoth',
                     obj_id=599,
                     obj_name='sMap BACnet driver',
                     ven_id=15,
                     request_check_interval=100):

        _log.info('seg_supported ' + str(seg_supported))
        _log.info('max_apdu_len ' + str(max_apdu_len))
        _log.info('obj_id ' + str(obj_id))
        _log.info('obj_name ' + str(obj_name))
        _log.info('ven_id ' + str(ven_id))

        # Check to see if they gave a valid apdu length.
        if encode_max_apdu_length_accepted(max_apdu_len) is None:
            raise ValueError(
                "Invalid max_apdu_len: {} Valid options are 50, 128, 206, 480, 1024, and 1476"
                .format(max_apdu_len))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
        )

        # build a bit string that knows about the bit names.
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        def i_am_callback(address, device_id, max_apdu_len, seg_supported,
                          vendor_id):
            async_call.send(None, self.i_am, address, device_id, max_apdu_len,
                            seg_supported, vendor_id)

        def send_cov_subscription_callback(device_address,
                                           subscriber_process_identifier,
                                           monitored_object_identifier,
                                           lifetime, point_name):
            """
            Asynchronous cov subscription callback for gevent
            """
            async_call.send(None, self.send_cov_subscription, device_address,
                            subscriber_process_identifier,
                            monitored_object_identifier, lifetime, point_name)

        def forward_cov_callback(point_name, apdu, result_dict):
            """
            Asynchronous callback to forward cov values to the platform driver
            for gevent
            """
            async_call.send(None, self.forward_cov, point_name, apdu,
                            result_dict)

        self.bacnet_application = BACnetApplication(
            i_am_callback, send_cov_subscription_callback,
            forward_cov_callback, request_check_interval, this_device, address)

        # Having a recurring task makes the spin value kind of irrelevant.
        kwargs = {"spin": 0.1, "sigterm": None, "sigusr1": None}

        server_thread = threading.Thread(target=bacpypes.core.run,
                                         kwargs=kwargs)

        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()
    def test_max_apdu_length_accepted_encode(self):
        if _debug: TestMaxAPDULengthAccepted._debug("test_max_apdu_length_accepted_encode")

        assert encode_max_apdu_length_accepted(50) == 0