From 57fb4e2854c966a0fa7168ed2b1e21f7dac4ac4b Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Tue, 14 May 2024 09:22:42 +0200 Subject: [PATCH] Improve BTP engine logging by using ChipLogByteSpan --- src/ble/BtpEngine.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/ble/BtpEngine.cpp b/src/ble/BtpEngine.cpp index 59cc73222e5722..75958169a785d5 100644 --- a/src/ble/BtpEngine.cpp +++ b/src/ble/BtpEngine.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -45,8 +46,10 @@ #ifdef CHIP_BTP_PROTOCOL_ENGINE_DEBUG_LOGGING_ENABLED #define ChipLogDebugBtpEngine(MOD, MSG, ...) ChipLogError(MOD, MSG, ##__VA_ARGS__) +#define ChipLogDebugBufferBtpEngine(MOD, BUF) ChipLogByteSpan(MOD, ByteSpan((BUF)->Start(), (BUF)->DataLength())) #else #define ChipLogDebugBtpEngine(MOD, MSG, ...) +#define ChipLogDebugBufferBtpEngine(MOD, BUF) #endif namespace chip { @@ -63,18 +66,6 @@ static inline bool DidReceiveData(BitFlags rx_flags) BtpEngine::HeaderFlags::kEndMessage); } -static void PrintBufDebug(const System::PacketBufferHandle & buf) -{ -#ifdef CHIP_BTP_PROTOCOL_ENGINE_DEBUG_LOGGING_ENABLED - uint8_t * b = buf->Start(); - - for (int i = 0; i < buf->DataLength(); i++) - { - ChipLogError(Ble, "\t%02x", b[i]); - } -#endif -} - const uint16_t BtpEngine::sDefaultFragmentSize = 20; // 23-byte minimum ATT_MTU - 3 bytes for ATT operation header const uint16_t BtpEngine::sMaxFragmentSize = 244; // Maximum size of BTP segment @@ -289,7 +280,7 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle && data->ConsumeHead(static_cast(reader.OctetsRead())); ChipLogDebugBtpEngine(Ble, ">>> BTP reassembler received data:"); - PrintBufDebug(data); + ChipLogDebugBufferBtpEngine(Ble, data); } if (mRxState == kState_Idle) @@ -434,7 +425,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s mTxLength = static_cast(mTxBuf->DataLength()); ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send whole message:"); - PrintBufDebug(mTxBuf); + ChipLogDebugBufferBtpEngine(Ble, mTxBuf); // Determine fragment header size. uint8_t header_size = @@ -485,7 +476,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s characteristic[0] = headerFlags.Raw(); ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send first fragment:"); - PrintBufDebug(mTxBuf); + ChipLogDebugBufferBtpEngine(Ble, mTxBuf); } else if (mTxState == kState_InProgress) { @@ -531,7 +522,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s characteristic[0] = headerFlags.Raw(); ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send additional fragment:"); - PrintBufDebug(mTxBuf); + ChipLogDebugBufferBtpEngine(Ble, mTxBuf); } else {