diff --git a/src/download_thread.cpp b/src/download_thread.cpp index 5f430bb..f82c8fd 100644 --- a/src/download_thread.cpp +++ b/src/download_thread.cpp @@ -104,9 +104,9 @@ void DownloadThread::run() { m_hw->dcDownloadRequestAck(); - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) + qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "DownloadThread::run(): DOWNLOAD THREAD STARTED:"; - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) + qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName(); // load binary device controller file into memory @@ -118,9 +118,9 @@ void DownloadThread::run() { // fill last block of data to be sent with 0xFF ba = ba.leftJustified(totalBlocks*64, (char)(0xFF)); - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) + qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size(); - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) + qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks; m_hw->dc_autoRequest(true); // turn auto-request setting on @@ -131,70 +131,46 @@ void DownloadThread::run() { resetDeviceController(); - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) + qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "DownloadThread::run(): RESET DEVICE-CONTROLLER"; QThread::sleep(1); if (startBootloader()) { - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) + qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "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; - qCritical() << "64-byte block " << currentBlock; - while (res != DownloadResult::ERROR && currentBlock < totalBlocks) { - if ((res = sendNextAddress(currentBlock)) != DownloadResult::ERROR) { - if ((res = sendNextDataBlock(ba, currentBlock)) != DownloadResult::ERROR) { - m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); - currentBlock += 1; - } - } - } - - qCritical() << "DownloadThread::run(): last 64-byte block %04d" << currentBlock; - - int const rest = ba.size() % 64; - int const offset = ba.size() - rest; - char const *startAddress = ba.constData() + offset; - - if (rest > 0) { - // SHOULD NEVER HAPPEN !!! - uint8_t local[66]; - memset(local, 0xFF, sizeof(local)); - memcpy(local, startAddress, rest); - qCritical() << "DownloadThread::run(): ERROR SEND REMAINING" << rest << "BYTES"; - m_hw->bl_sendDataBlock(64, local); - } else { - m_hw->bl_sendLastBlock(); - m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); - - qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock; - // 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 - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) + qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "DownloadThread::run(): STOPPED BOOT-LOADER"; } +#endif m_hw->dcDownloadSetRunning(false); m_hw->dcDownloadSetFinished(true); - qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) - << "DOWNLOAD THREAD FINISHED"; + QDateTime const end = QDateTime::currentDateTime(); + quint64 secs = start.secsTo(end); + QString runtime; + if (secs % 60) { + runtime = QString("%1min %2s").arg(secs / 60).arg(secs % 60); + } else { + runtime = QString("%1min").arg((secs / 60) + 1); + } + + qCritical() << end.time().toString(Qt::ISODateWithMs) + << QString("DOWNLOAD THREAD FINISHED (RUNTIME %1)") + .arg(runtime); // the object deletes itself ! This is the last line in run(). // Never touch the object after this statement