Work with device controller file directly, not via link.

Add startProgress/stopProgress().
This commit is contained in:
Gerhard Hoffmann 2023-08-09 15:09:44 +02:00
parent 5f1376cf1e
commit 0fb38013f7

View File

@ -8,6 +8,7 @@
#include <QDebug>
#include <QTextStream>
#include <QRegularExpression>
#include <QRegExp>
//#include <iostream>
//#include <fstream>
@ -350,21 +351,25 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
10 : bl_stopBL() // leave bl and start (the new) application
*/
bool Update::updateBinary(char const *fileToSendToDC) {
qInfo() << "updating device controller binary" << fileToSendToDC;
qInfo() << "UPDATING DEVICE CONTROLLER BINARY" << fileToSendToDC;
QFile fn(fileToSendToDC);
bool r;
if ((r = fn.exists()) == true) {
QString const linkTarget = fn.symLinkTarget();
QFileInfo fi(linkTarget);
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")";
if ((r = updateDC(linkTarget)) == true) {
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done";
QFileInfo fi(fn);
qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ")";
if ((r = updateDC(fileToSendToDC)) == true) {
qCritical() << QString(80, '*');
qInfo() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ") DONE";
qCritical() << QString(80, '*');
} else {
qCritical() << "updating binary (size=" << linkTarget << fi.size() << ")... FAILED";
qCritical() << QString(80, '*');
qCritical() << " UPDATING BINARY" << fi.fileName() << "(size=" << fi.size() << ") FAILED";
qCritical() << QString(80, '*');
}
} else {
qCritical() << "symlink" << fileToSendToDC
<< "does not exist -> NO UPDATE OF DC FIRMWARE";
qCritical() << QString(80, '*');
qCritical() << fileToSendToDC << "does not exist -> NO UPDATE OF DC FIRMWARE";
qCritical() << QString(80, '*');
}
return r;
}
@ -514,7 +519,6 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
}
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
//
// ACHTUNG !!!
//
@ -523,11 +527,6 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
bool serialOpened = false;
bool serialOpen = false;
if (filesToWorkOn.size() == 0) {
qCritical() << "NOTHING TO UPDATE";
return true;
}
if (!serialOpen) {
if (!isSerialOpen()) { // open serial only if not already open
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) == false) {
@ -537,18 +536,23 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
}
}
serialOpen = true;
qCritical() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
qInfo() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
}
bool res = false;
QList<QString>::const_iterator it;
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
bool res = false;
m_worker->startProgressLoop();
QString fToWorkOn = (*it).trimmed();
fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + fToWorkOn);
if (fToWorkOn.contains("dc2c", Qt::CaseInsensitive) &&
fToWorkOn.endsWith(".bin", Qt::CaseInsensitive)) {
static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$");
if (fToWorkOn.contains(version)) {
qInfo() << QString(80, '*');
qInfo() << "DO-UPDATE FILE-TO-WORK-ON" << fToWorkOn;
qInfo() << QString(80, '*');
qDebug() << "sending sw/hw-requests...";
for (int i=0; i < 3; ++i) { // send explicit reuests to get
// current SW/HW-versions
m_hw->request_DC2_SWversion();
@ -558,12 +562,16 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
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);
QFileInfo linkTarget(fn.symLinkTarget());
if (!linkTarget.exists()) { // check for broken link
QFileInfo finfo(fn);
if (!fn.exists()) { // check for broken link
qCritical() << QString(80, '*');
qCritical() << "FILE-TO-WORK-ON" << fn << "DOES NOT EXIST";
qCritical() << QString(80, '*');
res = false;
} else {
if (false) {
@ -574,13 +582,12 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
} else {
res = true;
qCritical() << "downloading" << fToWorkOn.trimmed() << "->"
<< linkTarget.completeBaseName() << "to DC";
qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC";
#if UPDATE_DC == 1
m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(1); // wait to be sure that there are no more
// commands sent to dc-hardware
qDebug() << "SET AUTO-REQUEST=FALSE";
qInfo() << "SET AUTO-REQUEST=FALSE";
if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
qCritical() << "downloaded binary" << fToWorkOn;
@ -591,13 +598,13 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
}
m_hw->dc_autoRequest(true); // turn auto-request setting on
qDebug() << "SET AUTO-REQUEST=TRUE";
qDebug() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
qInfo() << "SET AUTO-REQUEST=TRUE";
qInfo() << "WAIT 10 SECS TO RECEIVE RESPONSES...";
QThread::sleep(10); // wait to be sure that responses
// have been received
qCritical() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
qCritical() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
qInfo() << "updated dc-hardware-version" << m_hw->dc_getHWversion();
qInfo() << "updated dc-firmware-version" << m_hw->dc_getSWversion();
#endif
}
}
@ -660,10 +667,16 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
res = false;
}
m_worker->stopProgressLoop();
m_worker->setProgress(100);
if (res == false) {
break;
}
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON
qDebug() << "SET AUTO-REQUEST=TRUE";
return true;
return res;
}