How to use the bacpypes.pdu.Address function in bacpypes

To help you get started, we’ve selected a few bacpypes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JoelBender / bacpypes / tests / test_pdu / test_address.py View on Github external
# test bad integer string
        with self.assertRaises(ValueError):
            Address("256")

        # test modern hex string
        test_addr = Address("0x01")
        self.match_address(test_addr, 2, None, 1, '01')
        assert str(test_addr) == "1"

        test_addr = Address("0x0102")
        self.match_address(test_addr, 2, None, 2, '0102')
        assert str(test_addr) == "0x0102"

        # test old school hex string
        test_addr = Address("X'01'")
        self.match_address(test_addr, 2, None, 1, '01')
        assert str(test_addr) == "1"

        test_addr = Address("X'0102'")
        self.match_address(test_addr, 2, None, 2, '0102')
        assert str(test_addr) == "0x0102"
github JoelBender / bacpypes / tests / test_network / helpers.py View on Github external
def __init__(self, address, vlan):
        if _debug: ApplicationLayerStateMachine._debug("__init__ %r %r", address, vlan)

        # build a name, save the address
        self.name = "app @ %s" % (address,)
        self.address = Address(address)

        # build a local device object
        local_device = TestDeviceObject(
            objectName=self.name,
            objectIdentifier=('device', int(address)),
            vendorIdentifier=999,
            )

        # build an address and save it
        self.address = Address(address)
        if _debug: ApplicationLayerStateMachine._debug("    - address: %r", self.address)

        # continue with initialization
        ApplicationServiceElement.__init__(self)
        ClientStateMachine.__init__(self, name=local_device.objectName)
github JoelBender / bacpypes / tests / test_bvll / helpers.py View on Github external
def confirmation(self, pdu):
        if _debug: FauxMultiplexer._debug("confirmation %r", pdu)

        # the PDU source and destination are tuples, convert them to Address instances
        src = Address(pdu.pduSource)

        # see if the destination was our broadcast address
        if pdu.pduDestination == self.broadcast_tuple:
            dest = LocalBroadcast()
        else:
            dest = Address(pdu.pduDestination)

        # continue upstream
        self.response(PDU(pdu, source=src, destination=dest))
github JoelBender / bacpypes / samples / Discover.py View on Github external
def do_irt(self, args):
        """
        irt 

        Send an empty Initialize-Routing-Table message to an address, a router
        will return an acknowledgement with its routing table configuration.
        """
        args = args.split()
        if _debug: DiscoverConsoleCmd._debug("do_irt %r", args)

        # build a request
        try:
            request = InitializeRoutingTable()
            request.pduDestination = Address(args[0])
        except:
            print("invalid arguments")
            return

        # give it to the network service element
        this_application.nse.request(this_application.nsap.local_adapter, request)
github JoelBender / bacpypes / samples / WhoIsIAmVLAN.py View on Github external
def do_whois(self, args):
        """whois [ ] [   ]"""
        args = args.split()
        if _debug: WhoIsIAmConsoleCmd._debug("do_whois %r", args)

        try:
            # build a request
            request = WhoIsRequest()
            if (len(args) == 1) or (len(args) == 3):
                request.pduDestination = Address(args[0])
                del args[0]
            else:
                request.pduDestination = GlobalBroadcast()

            if len(args) == 2:
                request.deviceInstanceRangeLowLimit = int(args[0])
                request.deviceInstanceRangeHighLimit = int(args[1])
            if _debug: WhoIsIAmConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug: WhoIsIAmConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            this_application.request_io(iocb)
github JoelBender / bacpypes / samples / ReadProperty.py View on Github external
def do_rtn(self, args):
        """rtn   ... """
        args = args.split()
        if _debug: ReadPropertyConsoleCmd._debug("do_rtn %r", args)

        # provide the address and a list of network numbers
        router_address = Address(args[0])
        network_list = [int(arg) for arg in args[1:]]

        # pass along to the service access point
        this_application.nsap.add_router_references(None, router_address, network_list)
github JoelBender / bacpypes / samples / IP2VLANRouter.py View on Github external
action="store_true",
        )

    # add an argument for including the property list
    parser.add_argument('--plist',
        help='enable property list property',
        action="store_true",
        )

    # now parse the arguments
    args = parser.parse_args()

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

    local_address = Address(args.addr1)
    local_network = args.net1
    vlan_network = args.net2

    # create the VLAN router, bind it to the local network
    router = VLANRouter(local_address, local_network)

    # create a VLAN
    vlan = Network(broadcast_address=LocalBroadcast())

    # create a node for the router, address 1 on the VLAN
    router_addr = Address(1)
    router_node = Node(router_addr)
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, vlan_network, router_addr)
github JoelBender / bacpypes / samples / WhoIsIAmVLAN.py View on Github external
local_network = args.net1
    local_address = Address(args.ini.address)
    if _debug: _log.debug("    - local_network, local_address: %r, %r", local_network, local_address)

    vlan_network = args.net2
    vlan_address = Address(args.addr2)
    if _debug: _log.debug("    - vlan_network, vlan_address: %r, %r", vlan_network, vlan_address)

    # create the VLAN router, bind it to the local network
    router = VLANRouter(local_address, local_network)

    # create a VLAN
    vlan = Network(broadcast_address=LocalBroadcast())

    # create a node for the router, address 1 on the VLAN
    router_node = Node(Address(1))
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, vlan_network)
    
    # send network topology
    deferred(router.nse.i_am_router_to_network)

    # make a vlan device object
    this_device = \
        LocalDeviceObject(
            objectName=args.ini.objectname,
            objectIdentifier=("device", int(args.ini.objectidentifier)),
            maxApduLengthAccepted=1024,
            segmentationSupported='noSegmentation',
            vendorIdentifier=15,
github VOLTTRON / volttron / volttron / drivers / grab_bacnet_config_extra.py View on Github external
# make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )


    # make a simple application
    this_application = SynchronousApplication(this_device, args.ini.address)

    _log.debug("starting build")
    
    target_address = Address(args.address)
    
    request = WhoIsRequest()
    request.pduDestination = target_address
    result = this_application.make_request(request, expect_confirmation = False)
    
    if not isinstance(result, IAmRequest):
        result.debug_contents()
        raise TypeError("Error making WhoIs request, you might try again.")
        
    
    device_type, device_instance = result.iAmDeviceIdentifier
    if device_type != 'device':
        raise DecodingError("invalid object type")
    
    _log.debug('pduSource = ' + repr(result.pduSource))
    _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier))