Aupdate updateBinary() to download device controller using new library fucntions.
This commit is contained in:
parent
f2844aa4d9
commit
0db39746db
141
update.cpp
141
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);
|
|
||||||
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");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK);
|
bool bl_isUp = false;
|
||||||
|
if (m_hw->bl_completeStart()) {
|
||||||
for (int i=1; i <= MainWindow::BL_IS_UP_COUNT; ++i) {
|
int cnt = 5;
|
||||||
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_CHECK, i));
|
while (--cnt > 0) {
|
||||||
QThread::sleep(1);
|
if (m_hw->bl_isUp()) {
|
||||||
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_IS_UP, i));
|
bl_isUp = true;
|
||||||
if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QThread::sleep(1);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt = 0;
|
if (!bl_isUp) {
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
|
if (!m_hw->bl_storeFirmware(fileToSendToDC)) {
|
||||||
// bootloader MUST be running to download device-controller
|
m_hw->bl_stopBL();
|
||||||
#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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do this unconditionally, even if bootloader is not running at all ->
|
uint16_t const nrOfFirmwareBlocks = m_hw->bl_getNrOfFirmwareBlocks();
|
||||||
// the controller possibly tells us nonsense.
|
|
||||||
if (!stopBootloader()) {
|
for (uint16_t blockNr = 0; blockNr <= nrOfFirmwareBlocks; ++blockNr) {
|
||||||
Utils::printCriticalErrorMsg(
|
m_hw->bl_blockAutoLoad(blockNr);
|
||||||
QString("UPDATING DC: ") + bFile + " BOOT LOADER STILL RUNNING ("
|
|
||||||
+ QThread::currentThread()->objectName() + ")");
|
int sleepTime = 0;
|
||||||
|
while (1) {
|
||||||
|
if (sleepTime > 1500) {
|
||||||
|
m_hw->bl_stopBL();
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user