Aupdate updateBinary() to download device controller using new library fucntions.

This commit is contained in:
Gerhard Hoffmann 2023-11-21 10:07:50 +01:00
parent f2844aa4d9
commit 0db39746db

View File

@ -243,111 +243,78 @@ bool Update::isSerialOpen() const {
// There is no problem to repeat this command until the
// bootloader is really not running anymore.
*/
bool Update::updateBinary(char const *fileToSendToDC) {
bool Update::updateBinary(QString const &fileToSendToDC) {
return false;
qInfo() << "UPDATING DEVICE CONTROLLER FIRMWARE BINARY" << fileToSendToDC;
QFile fn(fileToSendToDC);
bool r;
if ((r = fn.exists()) == true) {
QFileInfo fi(fn);
if ((r = updateDC(fileToSendToDC)) == true) {
Utils::printInfoMsg(
QString(" UPDATING BINARY ") + fi.fileName()
+ QString(" (size=%1").arg(fi.size()) + ") DONE");
} else {
Utils::printCriticalErrorMsg(
QString(" UPDATING BINARY ") + fi.fileName()
+ QString(" (size=%1").arg(fi.size()) + ") FAILED");
}
} else {
Utils::printCriticalErrorMsg(
QString(fileToSendToDC) + " DOES NOT EXIST -> NO UPDATE OF DC FIRMWARE");
}
return r;
}
bool Update::updateDC(QString bFile) const {
qDebug() << "IN UPDATEDC: UPDATING DC: FILE TO SEND" << bFile;
m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::NONE);
QApplication::postEvent( // step 1: reset device controller
m_worker->mainWindow(),
new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::DC_REBOOT, 1));
QThread::sleep(1);
for (int i=1; i <= MainWindow::BL_START_COUNT; ++i) {
QApplication::postEvent( // step 2: start bootloader (5x)
m_worker->mainWindow(),
new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_START, i));
QThread::sleep(1);
}
int const cntLimit = 100; // wait until its for sure that bl_startBL()
int cnt = 0; // has been excuted
while (++cnt < cntLimit &&
m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_START) {
// wait until all bl_startBL() are done
QThread::msleep(200);
}
if (cnt == cntLimit) {
// start events not received ???
Utils::printCriticalErrorMsg("BL_START EVENT NOT RECEIVED AFTER 20 SECS");
if (!fn.exists()) {
// output via CONSOLE() etc
return false;
}
m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK);
for (int i=1; i <= MainWindow::BL_IS_UP_COUNT; ++i) {
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_CHECK, i));
QThread::sleep(1);
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_IS_UP, i));
if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
bool bl_isUp = false;
if (m_hw->bl_completeStart()) {
int cnt = 5;
while (--cnt > 0) {
if (m_hw->bl_isUp()) {
bl_isUp = true;
break;
}
QThread::sleep(1);
}
}
cnt = 0;
while (++cnt < cntLimit &&
m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_IS_UP) {
// wait until all bl_startBL() are done
QThread::msleep(200);
}
if (cnt == cntLimit) {
// really not up
Utils::printCriticalErrorMsg("BL_IS_UP EVENT NOT RECEIVED AFTER 20 SECS");
stopBootloader(); // try to stop bootloader whichhas been already started
if (!bl_isUp) {
return false;
}
if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
// bootloader MUST be running to download device-controller
#if 0
if (!downloadBinaryToDC(bFile)) {
Utils::printCriticalErrorMsg(
QString("UPDATING DC: ") + bFile + " ...DOWNLOAD FAILED");
}
#endif
} else {
Utils::printCriticalErrorMsg(
QString("UPDATING DC: ") + bFile + " BOOT LOADER NOT RUNNING -> NO DOWNLOAD ("
+ QThread::currentThread()->objectName() + ")");
if (!m_hw->bl_storeFirmware(fileToSendToDC)) {
m_hw->bl_stopBL();
return false;
}
// do this unconditionally, even if bootloader is not running at all ->
// the controller possibly tells us nonsense.
if (!stopBootloader()) {
Utils::printCriticalErrorMsg(
QString("UPDATING DC: ") + bFile + " BOOT LOADER STILL RUNNING ("
+ QThread::currentThread()->objectName() + ")");
uint16_t const nrOfFirmwareBlocks = m_hw->bl_getNrOfFirmwareBlocks();
for (uint16_t blockNr = 0; blockNr <= nrOfFirmwareBlocks; ++blockNr) {
m_hw->bl_blockAutoLoad(blockNr);
int sleepTime = 0;
while (1) {
if (sleepTime > 1500) {
m_hw->bl_stopBL();
return false;
}
Utils::printInfoMsg(QString("UPDATING DC: ") + bFile + " ...OK");
int8_t const r = m_hw->bl_blockAutoResponse();
// after every "bl_blockAutoLoad()" call this until response
// retval 0: wait 1: OK, blk was sent 2: OK, transfer complete
// 3: error despite repeating, cancel. probably bin file corrupted
// Max duration: 3x no response from BL = 900ms
switch(r) {
case 1:
/* fall through */
case 2:
sleepTime = 0;
break;
case 0: {
QThread::msleep(100);
sleepTime += 100;
} break;
case 3:
m_hw->bl_stopBL();
return false;
default:
m_hw->bl_stopBL();
return false; // unknown error code
}
}
m_hw->bl_stopBL();
}
return true;
}