def test_02_knx_connect(self): """Test regular KNX connection with no message sent. Pass even when no gateway (thx UDP). """ knxnet = knx.KnxNet() knxnet.connect(BOIBOITE) knxnet.disconnect()
def test_05_knx_connect_with_init(self): """Test regular KNX connection. Sends init packet DescrReq and expects DescrResp from dest. """ knxnet = knx.KnxNet() # knxnet.connect("192.168.0.10", 3671) datagram = knxnet.connect(BOIBOITE, 3671, init=True) self.assertTrue(isinstance(datagram, knx.KnxFrame)) self.assertEqual(datagram.sid, "CONNECT RESPONSE") knxnet.disconnect()
def test_07_knxframe_body_from_sid_update_realvalues(self): """Test that a frame can be built from sid using real network link values from KNX connection. """ knxnet = knx.KnxNet() knxnet.connect("localhost", 13671) frame = knx.KnxFrame(type="DESCRIPTION REQUEST") ip, _ = knxnet.source # Returns 127.0.0.1, looks weird frame.body.ip_address.value = ip self.assertEqual(bytes(frame.body), b"\x08\x01\x7f\x00\x00\x01\x00\x00")
def setUp(self): def update_source(knxnet, field): field.ip_address.value = knxnet.source_address field.port.value = knxnet.source_port self.connection = knx.KnxNet() self.connection.connect(BOIBOITE, 3671) # ConnectReq connectreq = knx.KnxFrame(type="CONNECT REQUEST", connection="Tunneling Connection") update_source(self.connection, connectreq.body.control_endpoint) update_source(self.connection, connectreq.body.data_endpoint) #ConnectResp connectresp = self.connection.send_receive(connectreq) self.channel = connectresp.body.communication_channel_id.value
def connect(ip:str, port:int) -> (knx.KnxNet, int): """Set item required for connection (source ip and port), saves connection information returned by the KNXnet/IP server (channel). [ sends: CONNECT REQUEST | expects: CONNECT RESPONSE ] """ knxnet = knx.KnxNet() channel = 0 try: knxnet.connect(ip, port) connectreq = knx.KnxFrame(type="CONNECT REQUEST", connection="DEVICE MANAGEMENT CONNECTION") connectreq.body.control_endpoint.ip_address.value = byte.from_ipv4(knxnet.source[0]) connectreq.body.control_endpoint.port.value = byte.from_int(knxnet.source[1]) connectreq.body.data_endpoint.ip_address.value = byte.from_ipv4(knxnet.source[0]) connectreq.body.data_endpoint.port.value = byte.from_int(knxnet.source[1]) response = knxnet.send_receive(connectreq) if response.sid == "CONNECT RESPONSE" and response.body.status.value == b'\x00': channel = response.body.communication_channel_id.value except BOFNetworkError as bne: print(bne) return None, 0 return knxnet, channel
from bof import BOFNetworkError, knx def all_frames() -> knx.KnxFrame: spec = knx.KnxSpec() for sid, block in spec.codes["service identifier"].items(): # If the frame has a cEMI block, we try all cEMI possibilities if "CEMI" in [template["type"] for template in spec.blocks[block] \ if "type" in template]: for cid, cemi in spec.codes["message code"].items(): print(block, cemi) yield knx.KnxFrame(type=block, cemi=cemi) else: yield knx.KnxFrame(type=block) # RUN if len(argv) < 2: print("Usage: python {0} IP_ADDRESS".format(argv[0])) else: knxnet = knx.KnxNet() knxnet.connect(argv[1], 3671) for frame in all_frames(): print(frame.sid) try: print("[SEND] {0}".format(frame)) response = knxnet.send_receive(frame) print("[RECV] {0}".format(response)) except BOFNetworkError: print("[NO RESPONSE]") knxnet.disconnect()
def setUp(self): self.connection = knx.KnxNet() self.connection.connect(BOIBOITE, 3671)
def test_04_knx_connect_bad_port(self): """Test error handling for bad port.""" with self.assertRaises(BOFNetworkError): knx.KnxNet().connect(BOIBOITE, 666666)
def test_03_knx_connect_bad_addr(self): """Test error handling for bad address.""" with self.assertRaises(BOFNetworkError): knx.KnxNet().connect("invalid")
def test_01_knx_instantiate(self): """Test that BOF object is correctly instantiated.""" knxnet = knx.KnxNet()