When sending dc-data, fill the last block with 0xFF to stream-line the source code.

This commit is contained in:
Gerhard Hoffmann 2023-07-06 14:27:44 +02:00
parent 7d6b433373
commit fa04e32266

View File

@ -277,29 +277,32 @@ Update::DownloadResult Update::sendNextDataBlock(QByteArray const &binary,
Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const { Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const {
int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1; 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; qInfo() << "total number of blocks to send to dc" << nBlocks;
int bNum = 0; int bNum = 0;
DownloadResult res = DownloadResult::OK; DownloadResult res = DownloadResult::OK;
while (res != DownloadResult::ERROR && bNum < nBlocks) { while (res != DownloadResult::ERROR && bNum < nBlocks) {
if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) { if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(b, bNum)) != DownloadResult::ERROR) { if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) {
bNum += 1; bNum += 1;
} }
} }
} }
qInfo() << "nBlocks" << nBlocks; int const rest = ba.size() % 64;
//if (res != DownloadResult::ERROR) { int const offset = ba.size() - rest;
// always send last block, even when there are no data !!! char const *startAddress = ba.constData() + offset;
int const rest = b.size() % 64;
int const offset = b.size() - rest;
char const *startAddress = b.constData() + offset;
uint8_t local[66];
memset(local, 0x00, sizeof(local));
if (rest > 0) { if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest); memcpy(local, startAddress, rest);
qCritical() << "ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
} }
m_hw->bl_sendLastBlock(); m_hw->bl_sendLastBlock();