From cadc6c61246d1b4634fae1ed15fc265cefc29746 Mon Sep 17 00:00:00 2001 From: nanosonde <2073569+nanosonde@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:06:13 +0200 Subject: [PATCH] Refactor broadcast/systembroadcast (#62) * Add missing source files * Fix comment * Refactor Broadcast/SystemBroadcast * Add empty confirm methods * Remove unclean solution to suppress warning about unsed var * Restore old structure * Fix issues * Add more missing source files * Make sure that services from SystemBroadcast are also available from Broadcast on closed media * Make sure that sent broadcast/systembroadcast frames are always marked as broadcast frames on closed media --- examples/knx-linux/CMakeLists.txt | 38 +++++++++++++------ src/knx/application_layer.cpp | 61 ++++++++++++++++++++++++++++++- src/knx/bau.cpp | 14 +++++++ src/knx/bau.h | 8 ++++ src/knx/bau27B0.cpp | 12 +++++- src/knx/bau27B0.h | 5 ++- src/knx/bau_systemB.cpp | 5 +++ src/knx/bau_systemB.h | 2 + src/knx/data_link_layer.cpp | 5 +++ src/knx/network_layer.cpp | 1 - 10 files changed, 135 insertions(+), 16 deletions(-) diff --git a/examples/knx-linux/CMakeLists.txt b/examples/knx-linux/CMakeLists.txt index 9660b58..f654713 100644 --- a/examples/knx-linux/CMakeLists.txt +++ b/examples/knx-linux/CMakeLists.txt @@ -28,8 +28,11 @@ add_executable(knx-linux ../../src/knx/cemi_frame.cpp ../../src/knx/cemi_frame.h ../../src/knx/cemi_server.cpp - ../../src/knx/cemi_server_object.cpp - ../../src/knx/data_link_layer.cpp + ../../src/knx/cemi_server.h + ../../src/knx/cemi_server_object.cpp + ../../src/knx/cemi_server_object.h + ../../src/knx/config.h + ../../src/knx/data_link_layer.cpp ../../src/knx/data_link_layer.h ../../src/knx/data_property.cpp ../../src/knx/data_property.h @@ -50,14 +53,23 @@ add_executable(knx-linux ../../src/knx/ip_parameter_object.cpp ../../src/knx/ip_parameter_object.h ../../src/knx/knx_ip_device_information_dib.cpp - ../../src/knx/knx_ip_dib.cpp - ../../src/knx/knx_ip_frame.cpp - ../../src/knx/knx_ip_routing_indication.cpp - ../../src/knx/knx_ip_search_request.cpp - ../../src/knx/knx_ip_search_response.cpp - ../../src/knx/knx_ip_supported_service_dib.cpp - ../../src/knx/ip_host_protocol_address_information.cpp - ../../src/knx/knx_value.cpp + ../../src/knx/knx_ip_device_information_dib.h + ../../src/knx/knx_ip_dib.cpp + ../../src/knx/knx_ip_dib.h + ../../src/knx/knx_ip_frame.cpp + ../../src/knx/knx_ip_frame.h + ../../src/knx/knx_ip_routing_indication.cpp + ../../src/knx/knx_ip_routing_indication.h + ../../src/knx/knx_ip_search_request.cpp + ../../src/knx/knx_ip_search_request.h + ../../src/knx/knx_ip_search_response.cpp + ../../src/knx/knx_ip_search_response.h + ../../src/knx/knx_ip_supported_service_dib.cpp + ../../src/knx/knx_ip_supported_service_dib.h + ../../src/knx/ip_host_protocol_address_information.cpp + ../../src/knx/ip_host_protocol_address_information.h + ../../src/knx/knx_types.h + ../../src/knx/knx_value.cpp ../../src/knx/knx_value.h ../../src/knx/memory.cpp ../../src/knx/memory.h @@ -65,7 +77,7 @@ add_executable(knx-linux ../../src/knx/network_layer.h ../../src/knx/npdu.cpp ../../src/knx/npdu.h - ../../src/knx/platform.cpp + ../../src/knx/platform.cpp ../../src/knx/platform.h ../../src/knx/property.cpp ../../src/knx/property.h @@ -75,6 +87,7 @@ add_executable(knx-linux ../../src/knx/rf_medium_object.h ../../src/knx/rf_physical_layer.cpp ../../src/knx/rf_physical_layer.h + ../../src/knx/save_restore.h ../../src/knx/table_object.cpp ../../src/knx/table_object.h ../../src/knx/tpdu.cpp @@ -84,7 +97,8 @@ add_executable(knx-linux ../../src/knx/transport_layer.cpp ../../src/knx/transport_layer.h ../../src/knx/usb_tunnel_interface.cpp - ../../src/knx_facade.cpp + ../../src/knx/usb_tunnel_interface.h + ../../src/knx_facade.cpp ../../src/knx_facade.h ../../src/linux_platform.cpp ../../src/linux_platform.h diff --git a/src/knx/application_layer.cpp b/src/knx/application_layer.cpp index c6f6245..421a8f2 100644 --- a/src/knx/application_layer.cpp +++ b/src/knx/application_layer.cpp @@ -118,8 +118,15 @@ void ApplicationLayer::dataBroadcastIndication(HopCountType hopType, Priority pr break; } default: +#if (MEDIUM_TYPE == 5)||(MEDIUM_TYPE == 0) + // Make sure we also check if it is a service normally available only on SystemBroadcast on open media + dataSystemBroadcastIndication(hopType, priority, source, apdu); +#else print("Broadcast-indication: unhandled APDU-Type: "); println(apdu.type()); + +#endif + break; } } @@ -159,8 +166,15 @@ void ApplicationLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, P break; } default: +#if (MEDIUM_TYPE == 5)||(MEDIUM_TYPE == 0) + // Make sure we also check if it is a service normally available only on SystemBroadcast on open media + dataSystemBroadcastConfirm(hopType, priority, apdu, status); +#else print("Broadcast-confirm: unhandled APDU-Type: "); println(apdu.type()); + +#endif + break; } } @@ -198,13 +212,58 @@ void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Prior break; } default: +#if (MEDIUM_TYPE == 5)||(MEDIUM_TYPE == 0) + print("Broadcast-indication: unhandled APDU-Type: "); +#else + print("SystemBroadcast-indication: unhandled APDU-Type: "); +#endif + println(apdu.type()); break; } } void ApplicationLayer::dataSystemBroadcastConfirm(HopCountType hopType, Priority priority, APDU& apdu, bool status) { - + const uint8_t* data = apdu.data(); + switch (apdu.type()) + { + // TODO: testInfo could be of any length + case SystemNetworkParameterRead: + { + uint16_t objectType; + uint16_t propertyId; + uint8_t testInfo[2]; + popWord(objectType, data + 1); + popWord(propertyId, data + 3); + popByte(testInfo[0], data + 4); + popByte(testInfo[1], data + 5); + propertyId = (propertyId >> 4) & 0x0FFF;; + testInfo[0] &= 0x0F; + _bau.systemNetworkParameterReadLocalConfirm(priority, hopType, objectType, propertyId, testInfo, sizeof(testInfo), status); + break; + } + case DomainAddressSerialNumberWrite: + { + const uint8_t* knxSerialNumber = &data[1]; + const uint8_t* domainAddress = &data[7]; + _bau.domainAddressSerialNumberWriteLocalConfirm(priority, hopType, domainAddress, knxSerialNumber, status); + break; + } + case DomainAddressSerialNumberRead: + { + const uint8_t* knxSerialNumber = &data[1]; + _bau.domainAddressSerialNumberReadLocalConfirm(priority, hopType, knxSerialNumber, status); + break; + } + default: +#if (MEDIUM_TYPE == 5)||(MEDIUM_TYPE == 0) + print("Broadcast-confirm: unhandled APDU-Type: "); +#else + print("SystemBroadcast-confirm: unhandled APDU-Type: "); +#endif + println(apdu.type()); + break; + } } void ApplicationLayer::dataIndividualIndication(HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu) diff --git a/src/knx/bau.cpp b/src/knx/bau.cpp index f28c94f..b09f513 100644 --- a/src/knx/bau.cpp +++ b/src/knx/bau.cpp @@ -264,6 +264,20 @@ void BusAccessUnit::domainAddressSerialNumberReadIndication(Priority priority, H { } +void BusAccessUnit::systemNetworkParameterReadLocalConfirm(Priority priority, HopCountType hopType, uint16_t objectType, + uint16_t propertyId, uint8_t* testInfo, uint16_t testInfoLength, bool status) +{ +} + +void BusAccessUnit::domainAddressSerialNumberWriteLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* rfDoA, + const uint8_t* knxSerialNumber, bool status) +{ +} + +void BusAccessUnit::domainAddressSerialNumberReadLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* knxSerialNumber, bool status) +{ +} + void BusAccessUnit::propertyValueRead(ObjectType objectType, uint8_t objectInstance, uint8_t propertyId, uint8_t& numberOfElements, uint16_t startIndex, uint8_t** data, uint32_t& length) diff --git a/src/knx/bau.h b/src/knx/bau.h index 444c61f..d2d9c80 100644 --- a/src/knx/bau.h +++ b/src/knx/bau.h @@ -123,6 +123,14 @@ class BusAccessUnit virtual void domainAddressSerialNumberReadIndication(Priority priority, HopCountType hopType, const uint8_t* knxSerialNumber); + virtual void systemNetworkParameterReadLocalConfirm(Priority priority, HopCountType hopType, uint16_t objectType, + uint16_t propertyId, uint8_t* testInfo, uint16_t testInfoLength, bool status); + + virtual void domainAddressSerialNumberWriteLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* rfDoA, + const uint8_t* knxSerialNumber, bool status); + + virtual void domainAddressSerialNumberReadLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* knxSerialNumber, bool status); + virtual void propertyValueRead(ObjectType objectType, uint8_t objectInstance, uint8_t propertyId, uint8_t& numberOfElements, uint16_t startIndex, uint8_t** data, uint32_t& length); diff --git a/src/knx/bau27B0.cpp b/src/knx/bau27B0.cpp index c9cf495..a938dba 100644 --- a/src/knx/bau27B0.cpp +++ b/src/knx/bau27B0.cpp @@ -150,4 +150,14 @@ void Bau27B0::individualAddressSerialNumberReadIndication(Priority priority, Hop _appLayer.IndividualAddressSerialNumberReadResponse(priority, hopType, _rfMediumObj.rfDomainAddress(), knxSerialNumber); } -#endif // #if MEDIUM_TYPE == 2 +void Bau27B0::domainAddressSerialNumberWriteLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* rfDoA, + const uint8_t* knxSerialNumber, bool status) +{ +} + +void Bau27B0::domainAddressSerialNumberReadLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* knxSerialNumber, bool status) +{ +} + + +#endif // #ifdef USE_RF diff --git a/src/knx/bau27B0.h b/src/knx/bau27B0.h index 8b270b6..678a659 100644 --- a/src/knx/bau27B0.h +++ b/src/knx/bau27B0.h @@ -34,5 +34,8 @@ class Bau27B0 : public BauSystemB void individualAddressSerialNumberWriteIndication(Priority priority, HopCountType hopType, uint16_t newIndividualAddress, uint8_t* knxSerialNumber) override; void individualAddressSerialNumberReadIndication(Priority priority, HopCountType hopType, uint8_t* knxSerialNumber) override; + void domainAddressSerialNumberWriteLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* rfDoA, + const uint8_t* knxSerialNumber, bool status) override; + void domainAddressSerialNumberReadLocalConfirm(Priority priority, HopCountType hopType, const uint8_t* knxSerialNumber, bool status) override; }; -#endif \ No newline at end of file +#endif diff --git a/src/knx/bau_systemB.cpp b/src/knx/bau_systemB.cpp index f3cc234..1a80920 100644 --- a/src/knx/bau_systemB.cpp +++ b/src/knx/bau_systemB.cpp @@ -419,6 +419,11 @@ void BauSystemB::systemNetworkParameterReadIndication(Priority priority, HopCoun } } +void BauSystemB::systemNetworkParameterReadLocalConfirm(Priority priority, HopCountType hopType, uint16_t objectType, + uint16_t propertyId, uint8_t* testInfo, uint16_t testInfoLength, bool status) +{ +} + void BauSystemB::propertyValueRead(ObjectType objectType, uint8_t objectInstance, uint8_t propertyId, uint8_t &numberOfElements, uint16_t startIndex, uint8_t **data, uint32_t &length) diff --git a/src/knx/bau_systemB.h b/src/knx/bau_systemB.h index 2dce5e7..b618fa6 100644 --- a/src/knx/bau_systemB.h +++ b/src/knx/bau_systemB.h @@ -72,6 +72,8 @@ class BauSystemB : protected BusAccessUnit uint8_t* data, uint8_t dataLength) override; void systemNetworkParameterReadIndication(Priority priority, HopCountType hopType, uint16_t objectType, uint16_t propertyId, uint8_t* testInfo, uint16_t testinfoLength) override; + void systemNetworkParameterReadLocalConfirm(Priority priority, HopCountType hopType, uint16_t objectType, + uint16_t propertyId, uint8_t* testInfo, uint16_t testInfoLength, bool status) override; void connectConfirm(uint16_t tsap) override; virtual InterfaceObject* getInterfaceObject(uint8_t idx) = 0; diff --git a/src/knx/data_link_layer.cpp b/src/knx/data_link_layer.cpp index a8421e8..877783d 100644 --- a/src/knx/data_link_layer.cpp +++ b/src/knx/data_link_layer.cpp @@ -140,7 +140,12 @@ bool DataLinkLayer::sendTelegram(NPDU & npdu, AckType ack, uint16_t destinationA frame.addressType(addrType); frame.priority(priority); frame.repetition(RepititionAllowed); +#if (MEDIUM_TYPE == 5)||(MEDIUM_TYPE == 0) + // Make sure to always send as normal Broadcast on closed media (TP and IP) + frame.systemBroadcast(Broadcast); +#else frame.systemBroadcast(systemBroadcast); +#endif if (npdu.octetCount() <= 15) frame.frameType(StandardFrame); diff --git a/src/knx/network_layer.cpp b/src/knx/network_layer.cpp index ffea9d3..869c4fc 100644 --- a/src/knx/network_layer.cpp +++ b/src/knx/network_layer.cpp @@ -45,7 +45,6 @@ void NetworkLayer::dataIndication(AckType ack, AddressType addrType, uint16_t de } // destination == 0 _transportLayer.dataBroadcastIndication(hopType, priority, source, npdu.tpdu()); - } void NetworkLayer::dataConfirm(AckType ack, AddressType addressType, uint16_t destination, FrameFormat format, Priority priority, uint16_t source, NPDU& npdu, bool status)