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