diff --git a/src/knx/coupler/bau091A.cpp b/src/knx/coupler/bau091A.cpp index 59f168a..eda8fae 100644 --- a/src/knx/coupler/bau091A.cpp +++ b/src/knx/coupler/bau091A.cpp @@ -188,18 +188,25 @@ namespace Knx { // ACK for broadcasts if (address == 0) + { ack = TPAckType::AckReqAck; - - if (lcconfig & LCCONFIG::GROUP_IACK_ROUT) - - // is group address in filter table? ACK if yes, No if not - if (_netLayer.isRoutedGroupAddress(address, 1)) - ack = TPAckType::AckReqAck; - else - ack = TPAckType::AckReqNone; + } else - // all are ACKED - ack = TPAckType::AckReqAck; + { + if (lcconfig & LCCONFIG::GROUP_IACK_ROUT) + { + // is group address in filter table? ACK if yes, No if not + if (_netLayer.isRoutedGroupAddress(address, 1)) + ack = TPAckType::AckReqAck; + else + ack = TPAckType::AckReqNone; + } + else + { + // all are ACKED + ack = TPAckType::AckReqAck; + } + } #ifdef KNX_TUNNELING diff --git a/src/knx/interface_object/device_object.h b/src/knx/interface_object/device_object.h index eeb68c5..c7167cf 100644 --- a/src/knx/interface_object/device_object.h +++ b/src/knx/interface_object/device_object.h @@ -11,7 +11,7 @@ namespace Knx public: // increase this version anytime DeviceObject-API changes // the following value represents the serialized representation of DeviceObject. - const uint16_t apiVersion = 1; + const uint16_t apiVersion = 2; DeviceObject(); uint8_t* save(uint8_t* buffer) override; diff --git a/src/knx/ip/ip_data_link_layer.cpp b/src/knx/ip/ip_data_link_layer.cpp index b8c6055..28a19f5 100644 --- a/src/knx/ip/ip_data_link_layer.cpp +++ b/src/knx/ip/ip_data_link_layer.cpp @@ -500,8 +500,6 @@ namespace Knx if (searchRequest.srpRequestDIBs) { - println("srpRequestDIBs"); - if (searchRequest.requestedDIB(IP_CONFIG)) dibLength += LEN_IP_CONFIG_DIB; //16 @@ -556,9 +554,9 @@ namespace Knx #endif } - if (searchResponse.totalLength() > 150) + if (searchResponse.totalLength() > 500) { - println("skipped response cause length is not plausible"); + printf("skipped response length > 500. Length: %d bytes\n", searchResponse.totalLength()); return; } @@ -716,7 +714,7 @@ namespace Knx } - if (tunnelResActive[i]) // tunnel reserve feature active for this tunnel + if (resTunActive && tunnelResActive[i]) // tunnel reserve feature active for this tunnel { #ifdef KNX_LOG_TUNNELING print("tunnel reserve feature active for this tunnel: "); @@ -835,7 +833,8 @@ namespace Knx break; } - tun->IndividualAddress = tunPa; + if (tun) + tun->IndividualAddress = tunPa; } if (tun == nullptr) @@ -869,9 +868,9 @@ namespace Knx _lastChannelId = 0; tun->IpAddress = srcIP; - tun->PortData = srcPort; - tun->PortCtrl = connRequest.hpaiCtrl().ipPortNumber() ? connRequest.hpaiCtrl().ipPortNumber() : srcPort; - + tun->PortData = connRequest.hpaiData().ipPortNumber()?connRequest.hpaiData().ipPortNumber():srcPort; + tun->PortCtrl = connRequest.hpaiCtrl().ipPortNumber()?connRequest.hpaiCtrl().ipPortNumber():srcPort; + print("New Tunnel-Connection["); print(tunIdx); print("], Channel: 0x"); diff --git a/src/knx/ip/ip_data_link_layer.h b/src/knx/ip/ip_data_link_layer.h index 3b61029..45380d5 100644 --- a/src/knx/ip/ip_data_link_layer.h +++ b/src/knx/ip/ip_data_link_layer.h @@ -52,7 +52,7 @@ namespace Knx DataLinkLayerCallbacks* _dllcb; #ifdef KNX_TUNNELING KnxIpTunnelConnection tunnels[KNX_TUNNELING]; - uint8_t _lastChannelId = 1; + uint8_t _lastChannelId = 0; #endif }; } \ No newline at end of file diff --git a/src/knx/ip/knx_ip_connect_response.cpp b/src/knx/ip/knx_ip_connect_response.cpp index f760a4c..5811bd6 100644 --- a/src/knx/ip/knx_ip_connect_response.cpp +++ b/src/knx/ip/knx_ip_connect_response.cpp @@ -18,7 +18,9 @@ namespace Knx _crd.length((type == 4) ? 4 : 2); //TunnelConnectionResponse length = 4; ConfigConnectionResponse length = 2; _crd.type(type); - _crd.address(address); + + if (type == 4) // only fill address when it is a TunnelConnectionResponse + _crd.address(address); } KnxIpConnectResponse::KnxIpConnectResponse(uint8_t channel, uint8_t errorCode) diff --git a/src/knx/ip/knx_ip_search_response_extended.cpp b/src/knx/ip/knx_ip_search_response_extended.cpp index 52d9b0e..02d8490 100644 --- a/src/knx/ip/knx_ip_search_response_extended.cpp +++ b/src/knx/ip/knx_ip_search_response_extended.cpp @@ -36,7 +36,6 @@ namespace Knx void KnxIpSearchResponseExtended::setDeviceInfo(IpParameterObject& parameters, DeviceObject& deviceObject) { - println("setDeviceInfo"); KnxIpDeviceInformationDIB _deviceInfo(_data + currentPos); _deviceInfo.length(LEN_DEVICE_INFORMATION_DIB); _deviceInfo.code(DEVICE_INFO); @@ -67,7 +66,6 @@ namespace Knx void KnxIpSearchResponseExtended::setSupportedServices() { - println("setSupportedServices"); KnxIpSupportedServiceDIB _supportedServices(_data + currentPos); _supportedServices.length(LEN_SERVICE_DIB); _supportedServices.code(SUPP_SVC_FAMILIES); @@ -84,7 +82,6 @@ namespace Knx void KnxIpSearchResponseExtended::setIpConfig(IpParameterObject& parameters) { - println("setIpConfig"); KnxIpConfigDIB _ipConfig(_data + currentPos); _ipConfig.length(LEN_IP_CONFIG_DIB); _ipConfig.code(IP_CONFIG); @@ -99,7 +96,6 @@ namespace Knx void KnxIpSearchResponseExtended::setIpCurrentConfig(IpParameterObject& parameters) { - println("setIpCurrentConfig"); KnxIpConfigDIB _ipCurConfig(_data + currentPos, true); _ipCurConfig.length(LEN_IP_CURRENT_CONFIG_DIB); _ipCurConfig.code(IP_CUR_CONFIG); @@ -115,7 +111,6 @@ namespace Knx void KnxIpSearchResponseExtended::setKnxAddresses(IpParameterObject& parameters, DeviceObject& deviceObject) { - println("setKnxAddresses"); KnxIpKnxAddressesDIB _knxAddresses(_data + currentPos); _knxAddresses.length(4); //minimum _knxAddresses.code(KNX_ADDRESSES); @@ -138,7 +133,6 @@ namespace Knx #ifdef KNX_TUNNELING void KnxIpSearchResponseExtended::setTunnelingInfo(IpParameterObject& parameters, DeviceObject& deviceObject, KnxIpTunnelConnection tunnels[]) { - println("setTunnelingInfo"); KnxIpTunnelingInfoDIB _tunnelInfo(_data + currentPos); _tunnelInfo.length(4); //minlength _tunnelInfo.code(TUNNELING_INFO); @@ -204,7 +198,6 @@ namespace Knx #endif void KnxIpSearchResponseExtended::setExtendedDeviceInfo() { - println("setExtendedDeviceInfo"); KnxIpExtendedDeviceInformationDIB _extended(_data + currentPos); _extended.length(LEN_EXTENDED_DEVICE_INFORMATION_DIB); _extended.code(EXTENDED_DEVICE_INFO); diff --git a/src/knx/platform/esp32_platform.cpp b/src/knx/platform/esp32_platform.cpp index 1552ffc..e123ec4 100644 --- a/src/knx/platform/esp32_platform.cpp +++ b/src/knx/platform/esp32_platform.cpp @@ -1,4 +1,5 @@ #ifdef ARDUINO_ARCH_ESP32 +#pragma once #include "esp32_platform.h" #include @@ -8,7 +9,17 @@ #ifndef KNX_SERIAL #define KNX_SERIAL Serial1 + #pragma warn "KNX_SERIAL not defined, using Serial1" #endif + +#ifdef KNX_IP_LAN + #include "ETH.h" + #define KNX_NETIF ETH +#else // KNX_IP_WIFI + #include + #define KNX_NETIF WiFi +#endif + namespace Knx { @@ -46,17 +57,17 @@ namespace Knx uint32_t Esp32Platform::currentIpAddress() { - return WiFi.localIP(); + return KNX_NETIF.localIP(); } uint32_t Esp32Platform::currentSubnetMask() { - return WiFi.subnetMask(); + return KNX_NETIF.subnetMask(); } uint32_t Esp32Platform::currentDefaultGateway() { - return WiFi.gatewayIP(); + return KNX_NETIF.gatewayIP(); } void Esp32Platform::macAddress(uint8_t* addr) @@ -83,7 +94,7 @@ namespace Knx IPAddress mcastaddr(htonl(addr)); KNX_DEBUG_SERIAL.printf("setup multicast addr: %s port: %d ip: %s\n", mcastaddr.toString().c_str(), port, - WiFi.localIP().toString().c_str()); + KNX_NETIF.localIP().toString().c_str()); uint8_t result = _udp.beginMulticast(mcastaddr, port); KNX_DEBUG_SERIAL.printf("result %d\n", result); } diff --git a/src/knx/platform/esp32_platform.h b/src/knx/platform/esp32_platform.h index 660afd4..7190554 100644 --- a/src/knx/platform/esp32_platform.h +++ b/src/knx/platform/esp32_platform.h @@ -1,9 +1,7 @@ #ifdef ARDUINO_ARCH_ESP32 #include "arduino_platform.h" -#include #include - namespace Knx { class Esp32Platform : public ArduinoPlatform diff --git a/src/knx/platform/rp2040_arduino_platform.cpp b/src/knx/platform/rp2040_arduino_platform.cpp index 37c5f51..87bd9ea 100644 --- a/src/knx/platform/rp2040_arduino_platform.cpp +++ b/src/knx/platform/rp2040_arduino_platform.cpp @@ -471,12 +471,7 @@ namespace Knx } void RP2040ArduinoPlatform::macAddress(uint8_t* addr) { -#if defined(KNX_IP_LAN) - addr = KNX_NETIF.getNetIf()->hwaddr; -#else - uint8_t macaddr[6] = {0, 0, 0, 0, 0, 0}; - addr = KNX_NETIF.macAddress(macaddr); -#endif + KNX_NETIF.macAddress(addr); } // multicast diff --git a/src/knx/tp/tpuart_data_link_layer.cpp b/src/knx/tp/tpuart_data_link_layer.cpp index 4a42657..d999a51 100644 --- a/src/knx/tp/tpuart_data_link_layer.cpp +++ b/src/knx/tp/tpuart_data_link_layer.cpp @@ -636,6 +636,15 @@ namespace Knx if (markerMode()) _platform.writeUart(U_CONFIGURE_REQ | U_CONFIGURE_MARKER_REQ); +#endif + + // Set Address for AutoACK Unicast + const uint16_t address = _deviceObject.individualAddress(); + _platform.writeUart(U_SET_ADDRESS_REQ); + _platform.writeUart((address >> 8) & 0xFF); + _platform.writeUart(address & 0xFF); +#ifdef NCN5120 + _platform.writeUart(0xFF); // Dummy Byte needed by NCN only #endif // Deviating Config