From 000346bd4e66b59f8377f15906d912a313d4c7a6 Mon Sep 17 00:00:00 2001 From: Fabien Proriol Date: Sun, 24 Nov 2019 08:49:11 +0100 Subject: [PATCH] link_layer: Add a way to enable debug traces --- src/knx/data_link_layer.cpp | 76 ++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/knx/data_link_layer.cpp b/src/knx/data_link_layer.cpp index 92d34a6..70707cf 100644 --- a/src/knx/data_link_layer.cpp +++ b/src/knx/data_link_layer.cpp @@ -5,6 +5,7 @@ #include "device_object.h" #include "address_table_object.h" +//#define DEBUG_DATA_LINK_LAYER DataLinkLayer::DataLinkLayer(DeviceObject& devObj, AddressTableObject& addrTab, NetworkLayer& layer, Platform& platform) : @@ -59,7 +60,43 @@ void DataLinkLayer::frameRecieved(CemiFrame& frame) NPDU& npdu = frame.npdu(); uint16_t ownAddr = _deviceObject.induvidualAddress(); SystemBroadcast systemBroadcast = frame.systemBroadcast(); - + +#ifdef DEBUG_DATA_LINK_LAYER + println("Link RX:"); + print("\tSRC: "); + print((source >> 12) & 0x0F); + print("."); + print((source >> 8) & 0x0F); + print("."); + println(source & 0xFF); + + if (addrType == InduvidualAddress) + { + print("\tDST: "); + print((destination >> 12) & 0x0F); + print("."); + print((destination >> 8) & 0x0F); + print("."); + println(destination & 0xFF); + } + else + { + if(destination == 0) + { + println("\tSystem Broadcast"); + } + else + { + print("\tDST: "); + print((destination >> 11) & 0x0F); + print("/"); + print((destination >> 8) & 0x07); + print("/"); + println(destination & 0xFF); + } + } +#endif + if (source == ownAddr) _deviceObject.induvidualAddressDuplication(true); @@ -111,6 +148,43 @@ bool DataLinkLayer::sendTelegram(NPDU & npdu, AckType ack, uint16_t destinationA return false; } +#ifdef DEBUG_DATA_LINK_LAYER + uint16_t source = _deviceObject.induvidualAddress(); + + println("Link TX:"); + print("\tSRC: "); + print((source >> 12) & 0x0F); + print("."); + print((source >> 8) & 0x0F); + print("."); + println(source & 0xFF); + + if (addrType == InduvidualAddress) + { + print("\tDST: "); + print((destinationAddr >> 12) & 0x0F); + print("."); + print((destinationAddr >> 8) & 0x0F); + print("."); + println(destinationAddr & 0xFF); + } + else + { + if(destinationAddr == 0) + { + println("\tSystem Broadcast"); + } + else + { + print("\tDST: "); + print((destinationAddr >> 11) & 0x0F); + print("/"); + print((destinationAddr >> 8) & 0x07); + print("/"); + println(destinationAddr & 0xFF); + } + } +#endif // if (frame.npdu().octetCount() > 0) // { // _print("<- DLL ");