Skip to content

Commit

Permalink
bdx working
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Oct 20, 2023
1 parent 5accc92 commit c4348e7
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 316 deletions.
276 changes: 0 additions & 276 deletions examples/all-clusters-app/linux/#main-common.cpp#

This file was deleted.

27 changes: 16 additions & 11 deletions src/app/bdx/DiagnosticLogsBDXTransferHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <platform/CHIPDeviceLayer.h>
#include <messaging/ExchangeMgr.h>

#include <fstream>
#include <string.h>
Expand Down Expand Up @@ -51,7 +52,7 @@ constexpr System::Clock::Timeout kBdxTimeout = System::Clock::Seconds16(5 * 60);

constexpr uint16_t kBdxMaxBlockSize = 1024;

CHIP_ERROR DiagnosticLogsBDXTransferHandler::InitializeTransfer(Messaging::ExchangeContext * exchangeCtx, FabricIndex fabricIndex, NodeId nodeId, /*Delegate * delegate, */IntentEnum intent, CharSpan fileDesignator)
CHIP_ERROR DiagnosticLogsBDXTransferHandler::InitializeTransfer(chip::Messaging::ExchangeContext * exchangeCtx, FabricIndex fabricIndex, NodeId nodeId, /*Delegate * delegate, */IntentEnum intent, CharSpan fileDesignator)
{
if (mInitialized) {
// Prevent a new node connection since another is active.
Expand All @@ -64,7 +65,8 @@ CHIP_ERROR DiagnosticLogsBDXTransferHandler::InitializeTransfer(Messaging::Excha
VerifyOrReturnError(exchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE);
//VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE);

mExchangeCtx = exchangeCtx;
mExchangeCtx = exchangeCtx->GetExchangeMgr()->NewContext(exchangeCtx->GetSessionHandle(), this);
VerifyOrReturnError(mExchangeCtx != nullptr, CHIP_ERROR_NO_MEMORY);
//mIntent = intent;
//mDelegate = delegate;

Expand Down Expand Up @@ -158,12 +160,15 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi
// call the delegate api to give me the next block in the completion handler
// send a block
uint16_t blockSize = mTransfer.GetTransferBlockSize();

ChipLogError(BDX, "bytestoread %hu", blockSize);
uint16_t bytesToRead = blockSize;

if (mTransfer.GetTransferLength() > 0 && mNumBytesSent + blockSize > mTransfer.GetTransferLength())
{
// cast should be safe because of condition above
bytesToRead = static_cast<uint16_t>(mTransfer.GetTransferLength() - mNumBytesSent);
ChipLogError(BDX, "bytestoread cast safe %hu", blockSize);
}

chip::System::PacketBufferHandle blockBuf = chip::System::PacketBufferHandle::New(bytesToRead);
Expand Down Expand Up @@ -214,13 +219,14 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi
mTransfer.AbortTransfer(StatusCode::kFileDesignatorUnknown);
return;
}

ChipLogError(BDX, "creating block data");
TransferSession::BlockData blockData;
blockData.Data = blockBuf->Start();
blockData.Length = static_cast<size_t>(otaFile.gcount());
blockData.Length = static_cast<size_t>(bytesToRead);
blockData.IsEof = (blockData.Length < blockSize) ||
(mNumBytesSent + static_cast<uint64_t>(blockData.Length) == mTransfer.GetTransferLength() || (otaFile.peek() == EOF));
mNumBytesSent = static_cast<uint32_t>(mNumBytesSent + blockData.Length);
ChipLogError(BDX, "creating block data mNumBytesSent %hu", mNumBytesSent);
otaFile.close();

/*TransferSession::BlockData blockData;
Expand All @@ -229,6 +235,7 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi
blockData.IsEof = isEOF;
mNumBytesSent = static_cast<uint32_t>(mNumBytesSent + blockData.Length);*/

ChipLogError(BDX, "PrepareBlock");
err = mTransfer.PrepareBlock(blockData);
if (err != CHIP_NO_ERROR)
{
Expand All @@ -254,9 +261,6 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi
return;
}

// Send a success to the LogRetreiveRequest
DiagnosticLogsServer::Instance().HandleBDXResponse(CHIP_NO_ERROR);

/*MutableByteSpan buffer;
buffer = MutableByteSpan(blockBuf->Start(), bytesToRead);
Expand All @@ -277,7 +281,7 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi
mDelegate->EndLogCollection(mLogSessionHandle);
mLogSessionHandle = kInvalidLogSessionHandle;
}*/

ChipLogError(BDX, "PrepareBlock ack received open otaFile");
std::ifstream otaFile(mFileDesignator, std::ifstream::in);
if (!otaFile.good())
{
Expand All @@ -297,10 +301,11 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi

TransferSession::BlockData blockData;
blockData.Data = blockBuf->Start();
blockData.Length = static_cast<size_t>(otaFile.gcount());
blockData.Length = static_cast<size_t>(bytesToRead);
blockData.IsEof = (blockData.Length < blockSize) ||
(mNumBytesSent + static_cast<uint64_t>(blockData.Length) == mTransfer.GetTransferLength() || (otaFile.peek() == EOF));
mNumBytesSent = static_cast<uint32_t>(mNumBytesSent + blockData.Length);
mNumBytesSent += static_cast<uint32_t>(mNumBytesSent + blockData.Length);
ChipLogError(BDX, "PrepareBlock ack received mNumBytesSent = %hu", mNumBytesSent);
otaFile.close();

/*TransferSession::BlockData blockData;
Expand All @@ -309,7 +314,7 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi
blockData.Length = static_cast<size_t>(blockBuf->DataLength());
blockData.IsEof = isEOF;
mNumBytesSent = static_cast<uint32_t>(mNumBytesSent + blockData.Length);*/

ChipLogError(BDX, "PrepareBlock ack received");
err = mTransfer.PrepareBlock(blockData);
if (err != CHIP_NO_ERROR)
{
Expand Down
Loading

0 comments on commit c4348e7

Please sign in to comment.