def test_address_equality(self): if _debug: TestAddressEquality._debug("test_address_equality") assert Address(1) == LocalStation(1) assert Address("2") == LocalStation(2) assert Address("*") == LocalBroadcast() assert Address("3:4") == RemoteStation(3, 4) assert Address("5:*") == RemoteBroadcast(5) assert Address("*:*") == GlobalBroadcast()
def test_local_station(self): if _debug: TestLocalStation._debug("test_local_station") # one parameter with self.assertRaises(TypeError): LocalStation() # test integer test_addr = LocalStation(1) self.match_address(test_addr, 2, None, 1, '01') assert str(test_addr) == "1" test_addr = LocalStation(254) self.match_address(test_addr, 2, None, 1, 'fe') assert str(test_addr) == "254" # test bad integer with self.assertRaises(ValueError): LocalStation(-1) with self.assertRaises(ValueError): LocalStation(256) # test bytes test_addr = LocalStation(xtob('01')) self.match_address(test_addr, 2, None, 1, '01') assert str(test_addr) == "1" test_addr = LocalStation(xtob('fe')) self.match_address(test_addr, 2, None, 1, 'fe') assert str(test_addr) == "254" # multi-byte strings are hex encoded test_addr = LocalStation(xtob('0102')) self.match_address(test_addr, 2, None, 2, '0102') assert str(test_addr) == "0x0102" test_addr = LocalStation(xtob('010203')) self.match_address(test_addr, 2, None, 3, '010203') assert str(test_addr) == "0x010203" # match with an IPv4 address test_addr = LocalStation(xtob('01020304bac0')) self.match_address(test_addr, 2, None, 6, '01020304bac0') assert str(test_addr) == "1.2.3.4"
pdu.get() # 104 pdu.get_short() # 25964 pdu.get_long() # 1819222305 pdu.put_long(1819222305) pdu.put_short(25964) pdu.put(104) pdu.debug_contents() print(str(pdu.pduData.decode('utf-8'))) #%% Addresses # Local stations hold address data from bacpypes.pdu import LocalStation, LocalBroadcast from bacpypes.pdu import RemoteStation, RemoteBroadcast, GlobalBroadcast addr1 = LocalStation(b'123456') # 6 octet long address addr2 = LocalStation(12) addr1.addrAddr addr2.addrAddr # When the byte string is six octets long followed by \xba \xc0 the # Address is interpreted as an IP address addr3 = LocalStation(b'\x01\x02\x03\x04\xba\xc0') addr3.__repr__() # the last octet is the port address addr4 = LocalStation(b'1234\xba\xc1') addr4.__repr__() # Local broadcast - sent to all devices on the network print(LocalBroadcast()) # Remote station - Destination other than local network print(RemoteStation(15, 75)) # Network number, integer
def topic2addr(topic): """Convert decimal encoded topic name to a local station address. This assumes that the ADDRESS_LENGTH is 3 octets.""" return LocalStation(pack(">I", int(topic))[-3:])