Added some debug output.

This commit is contained in:
Gerhard Hoffmann 2024-02-05 14:51:16 +01:00
parent ef31911e74
commit 0723ef335c

View File

@ -104,10 +104,11 @@ void DownloadThread::run() {
m_hw->dcDownloadRequestAck();
qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED:";
qCritical() << " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): DOWNLOAD THREAD STARTED:";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
#if 1
// load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) {
@ -117,15 +118,29 @@ void DownloadThread::run() {
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
m_hw->dc_autoRequest(true); // turn auto-request setting on
resetDeviceController();
m_hw->request_DC2_HWversion();
m_hw->request_DC2_SWversion();
QThread::sleep(1);
resetDeviceController();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): RESET DEVICE-CONTROLLER";
QThread::sleep(1);
if (startBootloader()) {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STARTED BOOT-LOADER";
m_hw->dc_autoRequest(false);// turn auto-request setting off for
// download of binary dc
#if 0
int currentBlock = 0; // download of binary dc
DownloadResult res = DownloadResult::OK;
@ -160,34 +175,26 @@ void DownloadThread::run() {
// QThread::msleep(250);
}
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
#else
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
QThread::msleep(250);
}
#endif
m_hw->dc_autoRequest(true); // turn auto-request setting on again
}
stopBootloader(); // there is no harm in stopping the bootloader even
} // if it was not started at all
#else
// load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) {
uint16_t const totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
QThread::msleep(250);
}
// if it was not started at all
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STOPPED BOOT-LOADER";
}
#endif
m_hw->dcDownloadSetRunning(false);
m_hw->dcDownloadSetFinished(true);
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD FINISHED";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DOWNLOAD THREAD FINISHED";
// the object deletes itself ! This is the last line in run().
// Never touch the object after this statement
@ -279,46 +286,59 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
}
bool DownloadThread::startBootloader() const {
qDebug() << "starting bootloader...";
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader...";
int nTry = 5;
while (--nTry >= 0) {
m_hw->bl_startBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_startBL() ..." << nTry;
QThread::msleep(1000);
m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
QThread::msleep(1000);
if (m_hw->bl_isUp()) {
qInfo() << "starting bootloader...OK";
QThread::msleep(1000);
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bootloader... isUP" << nTry;
return true;
} else {
qCritical() << "bootloader not up (" << nTry << ")";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bootloader not up (" << nTry << ")";
}
}
qCritical() << "starting bootloader...FAILED";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader FAILED";
return false;
}
bool DownloadThread::stopBootloader() const {
qDebug() << "stopping bootloader...";
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader...";
int nTry = 5;
while (--nTry >= 0) {
m_hw->bl_stopBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bl_stopBL() ...";
QThread::msleep(500);
m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
if (!m_hw->bl_isUp()) {
qInfo() << "stopping bootloader...OK";
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader OK";
return true;
}
}
qCritical() << "stopping bootloader...FAILED";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader FAILED";
return false;
}
bool DownloadThread::resetDeviceController() const {
qDebug() << "resetting device controller...";
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller...";
m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader
QThread::sleep(1);
qInfo() << "resetting device controller...OK";
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller...OK";
return true;
}