Skip to content

Commit 59c6615

Browse files
arkqpull[bot]
authored andcommitted
Improve BTP engine logging by using ChipLogByteSpan (#33435)
1 parent 981ad8d commit 59c6615

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/ble/BtpEngine.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <lib/support/BufferReader.h>
3636
#include <lib/support/CodeUtils.h>
3737
#include <lib/support/SafeInt.h>
38+
#include <lib/support/Span.h>
3839
#include <lib/support/logging/CHIPLogging.h>
3940
#include <system/SystemPacketBuffer.h>
4041

@@ -45,8 +46,10 @@
4546

4647
#ifdef CHIP_BTP_PROTOCOL_ENGINE_DEBUG_LOGGING_ENABLED
4748
#define ChipLogDebugBtpEngine(MOD, MSG, ...) ChipLogError(MOD, MSG, ##__VA_ARGS__)
49+
#define ChipLogDebugBufferBtpEngine(MOD, BUF) ChipLogByteSpan(MOD, ByteSpan((BUF)->Start(), (BUF)->DataLength()))
4850
#else
4951
#define ChipLogDebugBtpEngine(MOD, MSG, ...)
52+
#define ChipLogDebugBufferBtpEngine(MOD, BUF)
5053
#endif
5154

5255
namespace chip {
@@ -63,18 +66,6 @@ static inline bool DidReceiveData(BitFlags<BtpEngine::HeaderFlags> rx_flags)
6366
BtpEngine::HeaderFlags::kEndMessage);
6467
}
6568

66-
static void PrintBufDebug(const System::PacketBufferHandle & buf)
67-
{
68-
#ifdef CHIP_BTP_PROTOCOL_ENGINE_DEBUG_LOGGING_ENABLED
69-
uint8_t * b = buf->Start();
70-
71-
for (int i = 0; i < buf->DataLength(); i++)
72-
{
73-
ChipLogError(Ble, "\t%02x", b[i]);
74-
}
75-
#endif
76-
}
77-
7869
const uint16_t BtpEngine::sDefaultFragmentSize = 20; // 23-byte minimum ATT_MTU - 3 bytes for ATT operation header
7970
const uint16_t BtpEngine::sMaxFragmentSize = 244; // Maximum size of BTP segment
8071

@@ -289,7 +280,7 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle &&
289280
data->ConsumeHead(static_cast<uint16_t>(reader.OctetsRead()));
290281

291282
ChipLogDebugBtpEngine(Ble, ">>> BTP reassembler received data:");
292-
PrintBufDebug(data);
283+
ChipLogDebugBufferBtpEngine(Ble, data);
293284
}
294285

295286
if (mRxState == kState_Idle)
@@ -434,7 +425,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
434425
mTxLength = static_cast<uint16_t>(mTxBuf->DataLength());
435426

436427
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send whole message:");
437-
PrintBufDebug(mTxBuf);
428+
ChipLogDebugBufferBtpEngine(Ble, mTxBuf);
438429

439430
// Determine fragment header size.
440431
uint8_t header_size =
@@ -485,7 +476,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
485476

486477
characteristic[0] = headerFlags.Raw();
487478
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send first fragment:");
488-
PrintBufDebug(mTxBuf);
479+
ChipLogDebugBufferBtpEngine(Ble, mTxBuf);
489480
}
490481
else if (mTxState == kState_InProgress)
491482
{
@@ -531,7 +522,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
531522

532523
characteristic[0] = headerFlags.Raw();
533524
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send additional fragment:");
534-
PrintBufDebug(mTxBuf);
525+
ChipLogDebugBufferBtpEngine(Ble, mTxBuf);
535526
}
536527
else
537528
{

0 commit comments

Comments
 (0)