Activate updating device-controller-firmware.

This commit is contained in:
Gerhard Hoffmann 2023-07-06 14:32:57 +02:00
parent 06a9eba177
commit d89520d58e

View File

@ -28,7 +28,7 @@
#define COLUMN_RESULT (3) #define COLUMN_RESULT (3)
#define UPDATE_OPKG (1) #define UPDATE_OPKG (1)
#define UPDATE_DC (0) #define UPDATE_DC (1)
#define UPDATE_PRINTER_TEMPLATES (0) #define UPDATE_PRINTER_TEMPLATES (0)
#define UPDATE_CASH_TEMPLATE (0) #define UPDATE_CASH_TEMPLATE (0)
#define UPDATE_CONF_TEMPLATE (0) #define UPDATE_CONF_TEMPLATE (0)
@ -672,39 +672,74 @@ bool Update::doUpdate() {
} }
QString const &request = lst[COLUMN_REQUEST]; QString const &request = lst[COLUMN_REQUEST];
QString const &name = lst[COLUMN_NAME]; QString const &name = lst[COLUMN_NAME];
QTextStream out(&m_update_ctrl_file_copy);
// QString const &datetime = lst[COLUMN_DATE_TIME]; // QString const &datetime = lst[COLUMN_DATE_TIME];
// QString const &result = lst[COLUMN_RESULT]; // QString const &result = lst[COLUMN_RESULT];
qDebug() << "request=" << request << ", name=" << name; qDebug() << "request=" << request << ", name=" << name;
if (request.trimmed() == "DOWNLOAD") { if (request.trimmed() == "DOWNLOAD") {
if (!serialOpened) { // open serial code once if (!serialOpen) {
if (!openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) { if (!isSerialOpen()) { // open serial only if not already open
qCritical() << "CANNOT OPEN" << m_serialInterface << "(BAUDRATE=" if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) == false) {
<< m_baudrate << ")"; qCritical() << "CANNOT OPEN" << m_serialInterface << "(BAUDRATE="
return false; << m_baudrate << ")";
return false;
}
} }
serialOpen = true;
qCritical() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
}
serialOpened = true; if (name.contains("dc2c", Qt::CaseInsensitive) &&
name.endsWith(".bin", Qt::CaseInsensitive)) {
QString fwVersion = m_hw->dc_getSWversion(); qDebug() << "sending sw/hw-requests...";
QString const hwVersion = m_hw->dc_getHWversion(); 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-hardware-version" << hwVersion;
qInfo() << "current dc-firmware-version" << fwVersion; qInfo() << "current dc-firmware-version" << fwVersion;
m_hw->dc_autoRequest(false);// default: turn auto-request setting off QFile fn(name);
QThread::sleep(3); // wait to be sure that there are no more QFileInfo linkTarget(fn.symLinkTarget());
// commands sent to dc-hardware if (!linkTarget.exists()) { // check for broken link
qDebug() << "SET AUTO-REQUEST=FALSE"; res = false;
} } else {
if (name.contains("dc2c", Qt::CaseInsensitive) && if (fwVersion.startsWith(linkTarget.completeBaseName())) {
name.endsWith(".bin", Qt::CaseInsensitive)) { qCritical() << "current dc-firmware-version" << fwVersion
qInfo() << "downloading" << name.trimmed() << "to DC"; << "already installed";
res = true; res = false;
} else {
res = true;
qCritical() << "downloading" << name.trimmed() << "->"
<< linkTarget.completeBaseName() << "to DC";
#if UPDATE_DC == 1 #if UPDATE_DC == 1
if ((res = updateBinary(name.toStdString().c_str())) == true) { m_hw->dc_autoRequest(false);// default: turn auto-request setting off
qInfo() << "downloaded binary" << name; QThread::sleep(1); // wait to be sure that there are no more
} // commands sent to dc-hardware
qDebug() << "SET AUTO-REQUEST=FALSE";
if ((res = updateBinary(name.toStdString().c_str())) == true) {
qCritical() << "downloaded binary" << name;
}
m_hw->dc_autoRequest(true); // turn auto-request setting on
qDebug() << "SET AUTO-REQUEST=TRUE";
qDebug() << "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();
#endif #endif
}
}
} else if (name.contains("DC2C_print", Qt::CaseInsensitive) } else if (name.contains("DC2C_print", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) { && name.endsWith(".json", Qt::CaseInsensitive)) {
res = true; res = true;