doUpdate() and updateDC(): communicate with main window to enter bootloader

(i.e. to prepare device for download of device controller firmware), but do not
perform an actual download at the moment.
This commit is contained in:
Gerhard Hoffmann 2023-09-09 14:59:05 +02:00
parent d0eb1d12d8
commit a07893ddab

View File

@ -491,28 +491,88 @@ bool Update::updateBinary(char const *fileToSendToDC) {
} }
bool Update::updateDC(QString bFile) const { bool Update::updateDC(QString bFile) const {
qDebug() << "updating dc..."; qDebug() << "IN UPDATEDC: UPDATING DC: FILE TO SEND" << bFile;
qDebug() << "updating dc: file to send" << bFile;
if (!resetDeviceController()) { m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::NONE);
return false;
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);
} }
if (!startBootloader()) {
// even when start seems to fail, stopping the boot loader does not harm int const cntLimit = 100; // wait until its for sure that bl_startBL()
stopBootloader(); 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;
} }
if (!downloadBinaryToDC(bFile)) { m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK);
stopBootloader();
qCritical() << "updating dc: " << bFile << "...FAILED"; 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) {
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
return false; return false;
} }
qInfo() << "updating dc: " << bFile << "...OK";
stopBootloader(); if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
//resetDeviceController(); // bootloader MUST be running to download device-controller
#if 0
if (!downloadBinaryToDC(bFile)) {
Utils::printCriticalErrorMsg(
QString("UPDATING DC: ") + bFile + " ...DOWNLOAD FAILED");
}
#endif
QThread::sleep(3); } 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;
} }
@ -634,25 +694,73 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError())); disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
} }
QStringList Update::getDcSoftAndHardWareVersion() {
m_hw->dc_autoRequest(true);
QThread::sleep(1); // make sure the timer-slots are active
for (int i=0; i < 3; ++i) { // send explicit reuests to get
// current SW/HW-versions
m_hw->request_DC2_SWversion();
m_hw->request_DC2_HWversion();
QThread::sleep(1);
}
QString const &hwVersion = m_hw->dc_getHWversion().toLower().trimmed();
QString const &swVersion = m_hw->dc_getSWversion().toLower().trimmed();
m_hw->dc_autoRequest(false);
QThread::sleep(1); // make sure the timer-slots are inactive
if (!hwVersion.isEmpty() && !swVersion.isEmpty()) {
return QStringList() << hwVersion << swVersion;
}
return QStringList() << "DC HW-version not available"
<< "DC SW-version not available";
}
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) { bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
//
// ACHTUNG !!!
//
return true;
bool serialOpened = false; bool serialOpened = false;
bool serialOpen = false;
if (!serialOpen) { QString const &parentName = Utils::getParentName();
if (!isSerialOpen()) { // open serial only if not already open
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) == false) { if (parentName == "ATBQT" || parentName == "systemd") {
qCritical() << "CANNOT OPEN" << m_serialInterface << "(BAUDRATE=" // the tool was not called during 'service' ot during an automatic
<< m_baudrate << ")"; // update procedure. and it was called explicitly with libCAmaster.so
return false; if (m_pluginName.contains("master", Qt::CaseInsensitive)) {
} Utils::printCriticalErrorMsg(parentName
+ " IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so");
return false;
} }
serialOpen = true; } else
qInfo() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")"; if (Utils::isATBQTRunning()) { // manual testing
if (m_pluginName.contains("master", Qt::CaseInsensitive)) {
Utils::printCriticalErrorMsg(
"ATBQT IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so");
return false;
}
} else {
if (m_pluginName.contains("slave", Qt::CaseInsensitive)) {
Utils::printCriticalErrorMsg(
"ATB-UPDATE-TOOL CALLED WITH libCAslave.so ALTHOUGH MASTER");
return false;
}
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate),
m_baudrate,
m_serialInterface)) == false) {
Utils::printCriticalErrorMsg(
QString("CANNOT OPEN ")
+ m_serialInterface
+ "( BAUDRATE=" + m_baudrate + ")");
return false;
}
m_hw->dc_autoRequest(false);
Utils::printInfoMsg(
QString("SERIAL OPEN ") + m_serialInterface
+ " (BAUDRATE=" + m_baudrate + ")");
} }
bool res = false; bool res = false;
@ -662,67 +770,49 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
QString fToWorkOn = (*it).trimmed(); QString fToWorkOn = (*it).trimmed();
fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + fToWorkOn); fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + fToWorkOn);
static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$"); static const QRegularExpression version("^.*dc2c[.][0-9]{1,2}[.][0-9]{1,2}[.]bin.*$");
if (fToWorkOn.contains(version)) { if (fToWorkOn.contains(version)) {
Utils::printInfoMsg("DO-UPDATE FILE-TO-WORK-ON " + fToWorkOn);
qInfo() << QString(80, '*');
qInfo() << "DO-UPDATE FILE-TO-WORK-ON" << fToWorkOn;
qInfo() << QString(80, '*');
for (int i=0; i < 3; ++i) { // send explicit reuests to get
// current SW/HW-versions
m_hw->request_DC2_SWversion();
m_hw->request_DC2_HWversion();
QThread::sleep(1);
}
QString const hwVersion = m_hw->dc_getHWversion().toLower();
QString const fwVersion = m_hw->dc_getSWversion().toLower();
qInfo() << "current dc-hardware-version" << hwVersion;
qInfo() << "current dc-firmware-version" << fwVersion;
QFile fn(fToWorkOn); QFile fn(fToWorkOn);
QFileInfo finfo(fn); QFileInfo finfo(fn);
if (!fn.exists()) { // check for broken link if (!fn.exists()) { // check for broken link
qCritical() << QString(80, '*'); Utils::printCriticalErrorMsg("DO-UPDATE FILE-TO-WORK-ON "
qCritical() << "FILE-TO-WORK-ON" << fn << "DOES NOT EXIST"; + fToWorkOn + " DOES NOT EXIST");
qCritical() << QString(80, '*');
res = false; res = false;
} else { } else {
if (false) { bool updateBinaryRes = true;
//if (fwVersion.startsWith(linkTarget.completeBaseName())) {
// qCritical() << "current dc-firmware-version" << fwVersion
// << "already installed";
// res = false;
} else {
res = true;
qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC"; qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC";
#if UPDATE_DC == 1 #if UPDATE_DC == 1
m_hw->dc_autoRequest(false);// default: turn auto-request setting off m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(1); // wait to be sure that there are no more QThread::sleep(1); // wait to be sure that there are no more
// commands sent to dc-hardware // commands sent to dc-hardware
qInfo() << "SET AUTO-REQUEST=FALSE"; qInfo() << "SET AUTO-REQUEST=FALSE";
if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) { if ((updateBinaryRes = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
qCritical() << "downloaded binary" << fToWorkOn; qCritical() << "downloaded binary" << fToWorkOn;
++displayIndex; ++displayIndex;
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")")
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(), + QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
Worker::UPDATE_STEP_DONE); Worker::UPDATE_STEP_DONE);
}
m_hw->dc_autoRequest(true); // turn auto-request setting on
qInfo() << "SET AUTO-REQUEST=TRUE";
qInfo() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
QThread::sleep(10); // wait to be sure that responses
// have been received
qInfo() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
qInfo() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
#endif
} }
m_hw->dc_autoRequest(true); // turn auto-request setting on
qInfo() << "SET AUTO-REQUEST=TRUE";
QStringList const &versions = Update::getDcSoftAndHardWareVersion();
if (versions.size() >= 2) {
if (updateBinaryRes == true) {
qInfo() << "dc-hardware-version (UPDATED)" << versions[0];
qInfo() << "dc-firmware-version (UPDATED)" << versions[1];
} else {
qInfo() << "dc-hardware-version (NOT UPDATED)" << versions[0];
qInfo() << "dc-firmware-version (NOT UPDATED)" << versions[1];
}
}
#endif
res = updateBinaryRes;
} }
} else if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive) } else if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive)
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
@ -791,8 +881,12 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
} }
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) { } // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON //m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON
qDebug() << "SET AUTO-REQUEST=TRUE"; //qDebug() << "SET AUTO-REQUEST=TRUE";
if (serialOpened) {
m_hw->dc_closeSerial();
}
return res; return res;
} }