Skip to content

Commit

Permalink
Improve BTP engine logging by using ChipLogByteSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed May 14, 2024
1 parent 3219a5f commit 57fb4e2
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/ble/BtpEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <lib/support/BufferReader.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/SafeInt.h>
#include <lib/support/Span.h>
#include <lib/support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>

Expand All @@ -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 {
Expand All @@ -63,18 +66,6 @@ static inline bool DidReceiveData(BitFlags<BtpEngine::HeaderFlags> 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

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

ChipLogDebugBtpEngine(Ble, ">>> BTP reassembler received data:");
PrintBufDebug(data);
ChipLogDebugBufferBtpEngine(Ble, data);
}

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

ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send whole message:");
PrintBufDebug(mTxBuf);
ChipLogDebugBufferBtpEngine(Ble, mTxBuf);

// Determine fragment header size.
uint8_t header_size =
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 57fb4e2

Please sign in to comment.