示例#1
0
    def test_whoHas(self):
        request_object = WhoHasObject()
        request_object.objectIdentifier = ("binaryInput", 12)
        request = WhoHasRequest(object=request_object)
        apdu = APDU()
        request.encode(apdu)
        pdu = PDU()
        apdu.encode(pdu)
        buf_size = 1024
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.sendto(pdu.pduData, self.address)
        data = s.recvfrom(buf_size)
        s.close()
        received_data = data[0]

        expected = IHaveRequest()
        expected.pduDestination = GlobalBroadcast()
        expected.deviceIdentifier = 36113
        expected.objectIdentifier = 12
        expected.objectName = "BI 01"

        exp_apdu = APDU()
        expected.encode(exp_apdu)
        exp_pdu = PDU()
        exp_apdu.encode(exp_pdu)
        self.assertEqual(exp_pdu.pduData, received_data)
示例#2
0
    def test_whoHas(self):
        request_object = WhoHasObject()
        request_object.objectIdentifier = ('binaryInput', 12)
        request = WhoHasRequest(object=request_object)
        apdu = APDU()
        request.encode(apdu)
        pdu = PDU()
        apdu.encode(pdu)
        buf_size = 1024
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.sendto(pdu.pduData, ('127.0.0.1', self.bacnet_server.server.server_port))
        data = s.recvfrom(buf_size)

        received_data = data[0]

        expected = IHaveRequest()
        expected.pduDestination = GlobalBroadcast()
        expected.deviceIdentifier = 36113
        expected.objectIdentifier = 12
        expected.objectName = 'BI 01'

        exp_apdu = APDU()
        expected.encode(exp_apdu)
        exp_pdu = PDU()
        exp_apdu.encode(exp_pdu)

        self.assertEquals(exp_pdu.pduData, received_data)
    def test_whoHas(self):
        request_object = WhoHasObject()
        request_object.objectIdentifier = ('binaryInput', 12)
        request = WhoHasRequest(object=request_object)
        apdu = APDU()
        request.encode(apdu)
        pdu = PDU()
        apdu.encode(pdu)
        buf_size = 1024
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.sendto(pdu.pduData, ('127.0.0.1', self.bacnet_server.server.server_port))
        data = s.recvfrom(buf_size)

        received_data = data[0]

        expected = IHaveRequest()
        expected.pduDestination = GlobalBroadcast()
        expected.deviceIdentifier = 36113
        expected.objectIdentifier = 12
        expected.objectName = 'BI 01'

        exp_apdu = APDU()
        expected.encode(exp_apdu)
        exp_pdu = PDU()
        exp_apdu.encode(exp_pdu)

        self.assertEquals(exp_pdu.pduData, received_data)
        from bacpypes.apdu import WhoIsRequest, WhoHasObject, WhoHasRequest
        # code for generating adpu - who-is
        # request = WhoIsRequest(deviceInstanceRangeLowLimit=500, deviceInstanceRangeHighLimit=50000)
        # test_pdu = PDU()
        # test_apdu = APDU()
        # request.encode(test_apdu)
        # test_apdu.encode(test_pdu)
        # bacnet_app = BACnetApp(test.thisDevice, test)
        # bacnet_app.get_objects_and_properties(test.dom)
        # bacnet_app.indication(test_apdu, ('127.0.0.1', 9999), test.thisDevice)
        # print(bacnet_app._response)
        # bacnet_app.response(bacnet_app._response, ('127.0.0.1', 9999))
        # # logger.debug('Starting BACnet Server! at {}:{}'.format('localhost', 9999))
        # # test.start('127.0.0.1', 9999)

        # testing who-has
        request_object = WhoHasObject()
        request_object.objectIdentifier = ('binaryInput', 12)
        request = WhoHasRequest(object=request_object)
        test_apdu = APDU()
        request.encode(test_apdu)
        test_pdu = PDU()
        test_apdu.encode(test_pdu)
        bacnet_app = BACnetApp(test.thisDevice, test)
        bacnet_app.get_objects_and_properties(test.dom)
        bacnet_app.indication(test_apdu, ('127.0.0.1', 9999), test.thisDevice)
        print(bacnet_app._response)
        bacnet_app.response(bacnet_app._response, ('127.0.0.1', 9999))
    except KeyboardInterrupt:
        logger.debug('Stopping BACnet server')
        test.stop()
示例#5
0
        from bacpypes.apdu import WhoIsRequest, WhoHasObject, WhoHasRequest
        # code for generating adpu - who-is
        # request = WhoIsRequest(deviceInstanceRangeLowLimit=500, deviceInstanceRangeHighLimit=50000)
        # test_pdu = PDU()
        # test_apdu = APDU()
        # request.encode(test_apdu)
        # test_apdu.encode(test_pdu)
        # bacnet_app = BACnetApp(test.thisDevice, test)
        # bacnet_app.get_objects_and_properties(test.dom)
        # bacnet_app.indication(test_apdu, ('127.0.0.1', 9999), test.thisDevice)
        # print(bacnet_app._response)
        # bacnet_app.response(bacnet_app._response, ('127.0.0.1', 9999))
        # # logger.debug('Starting BACnet Server! at {}:{}'.format('localhost', 9999))
        # # test.start('127.0.0.1', 9999)

        # testing who-has
        request_object = WhoHasObject()
        request_object.objectIdentifier = ('binaryInput', 12)
        request = WhoHasRequest(object=request_object)
        test_apdu = APDU()
        request.encode(test_apdu)
        test_pdu = PDU()
        test_apdu.encode(test_pdu)
        bacnet_app = BACnetApp(test.thisDevice, test)
        bacnet_app.get_objects_and_properties(test.dom)
        bacnet_app.indication(test_apdu, ('127.0.0.1', 9999), test.thisDevice)
        print(bacnet_app._response)
        bacnet_app.response(bacnet_app._response, ('127.0.0.1', 9999))
    except KeyboardInterrupt:
        logger.debug('Stopping BACnet server')
        test.stop()