From fa04e32266d28718a7a38698afdb82c861462416 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 6 Jul 2023 14:27:44 +0200 Subject: [PATCH] When sending dc-data, fill the last block with 0xFF to stream-line the source code. --- update.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/update.cpp b/update.cpp index d47c92e..223d47b 100644 --- a/update.cpp +++ b/update.cpp @@ -277,29 +277,32 @@ Update::DownloadResult Update::sendNextDataBlock(QByteArray const &binary, Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const { int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1; - qInfo() << "total number of bytes to send to dc" << b.size(); + // fill lst block of data to be sent with 0xFF + QByteArray ba = b.leftJustified(nBlocks*64, (char)(0xFF)); + + qInfo() << "total number of bytes to send to dc" << ba.size(); qInfo() << "total number of blocks to send to dc" << nBlocks; int bNum = 0; DownloadResult res = DownloadResult::OK; while (res != DownloadResult::ERROR && bNum < nBlocks) { if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) { - if ((res = sendNextDataBlock(b, bNum)) != DownloadResult::ERROR) { + if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) { bNum += 1; } } } - qInfo() << "nBlocks" << nBlocks; - //if (res != DownloadResult::ERROR) { - // always send last block, even when there are no data !!! - int const rest = b.size() % 64; - int const offset = b.size() - rest; - char const *startAddress = b.constData() + offset; + int const rest = ba.size() % 64; + int const offset = ba.size() - rest; + char const *startAddress = ba.constData() + offset; - uint8_t local[66]; - memset(local, 0x00, sizeof(local)); if (rest > 0) { + // SHOULD NEVER HAPPEN !!! + uint8_t local[66]; + memset(local, 0xFF, sizeof(local)); memcpy(local, startAddress, rest); + qCritical() << "ERROR SEND REMAINING" << rest << "BYTES"; + m_hw->bl_sendDataBlock(64, local); } m_hw->bl_sendLastBlock();