Aupdate updateBinary() to download device controller using new library fucntions.
This commit is contained in:
parent
f2844aa4d9
commit
0db39746db
153
update.cpp
153
update.cpp
@ -243,111 +243,78 @@ bool Update::isSerialOpen() const {
|
|||||||
// There is no problem to repeat this command until the
|
// There is no problem to repeat this command until the
|
||||||
// bootloader is really not running anymore.
|
// 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;
|
qInfo() << "UPDATING DEVICE CONTROLLER FIRMWARE BINARY" << fileToSendToDC;
|
||||||
QFile fn(fileToSendToDC);
|
QFile fn(fileToSendToDC);
|
||||||
bool r;
|
if (!fn.exists()) {
|
||||||
if ((r = fn.exists()) == true) {
|
// output via CONSOLE() etc
|
||||||
QFileInfo fi(fn);
|
return false;
|
||||||
if ((r = updateDC(fileToSendToDC)) == true) {
|
}
|
||||||
Utils::printInfoMsg(
|
|
||||||
QString(" UPDATING BINARY ") + fi.fileName()
|
bool bl_isUp = false;
|
||||||
+ QString(" (size=%1").arg(fi.size()) + ") DONE");
|
if (m_hw->bl_completeStart()) {
|
||||||
} else {
|
int cnt = 5;
|
||||||
Utils::printCriticalErrorMsg(
|
while (--cnt > 0) {
|
||||||
QString(" UPDATING BINARY ") + fi.fileName()
|
if (m_hw->bl_isUp()) {
|
||||||
+ QString(" (size=%1").arg(fi.size()) + ") FAILED");
|
bl_isUp = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} 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()
|
if (!bl_isUp) {
|
||||||
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");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK);
|
if (!m_hw->bl_storeFirmware(fileToSendToDC)) {
|
||||||
|
m_hw->bl_stopBL();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=1; i <= MainWindow::BL_IS_UP_COUNT; ++i) {
|
uint16_t const nrOfFirmwareBlocks = m_hw->bl_getNrOfFirmwareBlocks();
|
||||||
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_CHECK, i));
|
|
||||||
QThread::sleep(1);
|
for (uint16_t blockNr = 0; blockNr <= nrOfFirmwareBlocks; ++blockNr) {
|
||||||
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_IS_UP, i));
|
m_hw->bl_blockAutoLoad(blockNr);
|
||||||
if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
|
|
||||||
break;
|
int sleepTime = 0;
|
||||||
|
while (1) {
|
||||||
|
if (sleepTime > 1500) {
|
||||||
|
m_hw->bl_stopBL();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QThread::sleep(1);
|
|
||||||
|
m_hw->bl_stopBL();
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
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() + ")");
|
|
||||||
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() + ")");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils::printInfoMsg(QString("UPDATING DC: ") + bFile + " ...OK");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user