preparing dc-update
This commit is contained in:
		@@ -79,7 +79,6 @@ SOURCES += \
 | 
				
			|||||||
        ../common/src/message_handler.cpp \
 | 
					        ../common/src/message_handler.cpp \
 | 
				
			||||||
        ../UpdatePTUDevCtrl/commandline_parser.cpp \
 | 
					        ../UpdatePTUDevCtrl/commandline_parser.cpp \
 | 
				
			||||||
        update.cpp \
 | 
					        update.cpp \
 | 
				
			||||||
        dc_download.cpp \
 | 
					 | 
				
			||||||
        ../common/src/System.cpp \
 | 
					        ../common/src/System.cpp \
 | 
				
			||||||
        ../common/src/utils_internal.cpp \
 | 
					        ../common/src/utils_internal.cpp \
 | 
				
			||||||
        ../common/src/command.cpp
 | 
					        ../common/src/command.cpp
 | 
				
			||||||
@@ -89,7 +88,6 @@ HEADERS += \
 | 
				
			|||||||
        ../common/include/message_handler.h \
 | 
					        ../common/include/message_handler.h \
 | 
				
			||||||
        ../UpdatePTUDevCtrl/commandline_parser.h \
 | 
					        ../UpdatePTUDevCtrl/commandline_parser.h \
 | 
				
			||||||
        update.h \
 | 
					        update.h \
 | 
				
			||||||
        dc_download.h \
 | 
					 | 
				
			||||||
        ../common/include/System.h \
 | 
					        ../common/include/System.h \
 | 
				
			||||||
        ../common/include/utils_internal.h \
 | 
					        ../common/include/utils_internal.h \
 | 
				
			||||||
        ../common/include/command.h
 | 
					        ../common/include/command.h
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -508,236 +508,3 @@ bool Update::doUpdate(QString const &dcFileName) {
 | 
				
			|||||||
    qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-FAILURE>";
 | 
					    qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-FAILURE>";
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
#if 0
 | 
					 | 
				
			||||||
bool Update::checkJsonVersions(QStringList const& jsonFileNames) {
 | 
					 | 
				
			||||||
    if (!m_hw) {
 | 
					 | 
				
			||||||
        qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
 | 
					 | 
				
			||||||
                    << "ERROR!!! m_hw == nullptr";
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int tries = 20;
 | 
					 | 
				
			||||||
    while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
 | 
					 | 
				
			||||||
        // must deliver 'true', only then are all data from hwapi valid
 | 
					 | 
				
			||||||
        if (--tries < 0) {
 | 
					 | 
				
			||||||
            qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
 | 
					 | 
				
			||||||
                        << "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED";
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
 | 
					 | 
				
			||||||
                    << "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED (" << tries << ")";
 | 
					 | 
				
			||||||
        m_hw->dc_autoRequest(true);
 | 
					 | 
				
			||||||
        QThread::msleep(500);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (QStringList::size_type i=0; i < jsonFileNames.size(); ++i) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        uint8_t jsonNr = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        QString const &fName = jsonFileNames[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // send one request for every single version
 | 
					 | 
				
			||||||
        // jsonNr=1...36, 1=config file (cust.Nr) 2=devices  3=cash  4=res.
 | 
					 | 
				
			||||||
        //      6=printer template 1 ..... 36= template 32
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (fName.endsWith("conf.json")) {
 | 
					 | 
				
			||||||
            jsonNr = 1;
 | 
					 | 
				
			||||||
        } else
 | 
					 | 
				
			||||||
        if (fName.endsWith("device.json")) {
 | 
					 | 
				
			||||||
            jsonNr = 2;
 | 
					 | 
				
			||||||
        } else
 | 
					 | 
				
			||||||
        if (fName.endsWith("cash.json")) {
 | 
					 | 
				
			||||||
            jsonNr = 3;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            QRegularExpressionMatch match;
 | 
					 | 
				
			||||||
            static const QRegularExpression re("^(.*print)([0-3][0-9])\\.json\\s*$");
 | 
					 | 
				
			||||||
            int idx = fName.indexOf(re, 0, &match);
 | 
					 | 
				
			||||||
            if (idx != -1) {
 | 
					 | 
				
			||||||
                QString captured = match.captured(match.lastCapturedIndex());
 | 
					 | 
				
			||||||
                bool ok = false;
 | 
					 | 
				
			||||||
                int n = captured.toInt(&ok);
 | 
					 | 
				
			||||||
                if (ok) {
 | 
					 | 
				
			||||||
                    // note: use 5 (instead of 4 -> index has been shifted)
 | 
					 | 
				
			||||||
                    jsonNr = n + 5;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (jsonNr != 0) {
 | 
					 | 
				
			||||||
            // send one request for every single version
 | 
					 | 
				
			||||||
            // jsonNr=1...36, 1=config file (cust.Nr) 2=devices  3=cash  4=res.
 | 
					 | 
				
			||||||
            //      5=printer template 1 ..... 36= template 32
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            m_hw->sys_requestJsonVersions(jsonNr);
 | 
					 | 
				
			||||||
            QThread::msleep(500);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            char buf[64];
 | 
					 | 
				
			||||||
            memset(buf, 0x00, sizeof(buf));
 | 
					 | 
				
			||||||
            m_hw->sys_getJsonVersions(jsonNr, buf);
 | 
					 | 
				
			||||||
            buf[16] = '\0'; // the DC only handles 16 bytes
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            static const QByteArray cb(16, (char)0xff);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            QString const installedVersion(QString::fromStdString(buf));
 | 
					 | 
				
			||||||
            QString const fileVersion = getFileVersion(jsonFileNames[i]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            QFileInfo fi(jsonFileNames[i]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            qCritical() << endl;
 | 
					 | 
				
			||||||
            qCritical() << "                json request nr:" << jsonNr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (installedVersion == fileVersion) {
 | 
					 | 
				
			||||||
                qCritical() << "                      json file:" << fi.fileName();
 | 
					 | 
				
			||||||
                qCritical() << "        installed version in DC:" << installedVersion;
 | 
					 | 
				
			||||||
            } else
 | 
					 | 
				
			||||||
            if (cb == QByteArray(buf) && fileVersion == "") {
 | 
					 | 
				
			||||||
                qCritical() << "unknown json file (repo and DC):" << fi.fileName();
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                qCritical() << "                      json file:" << fi.fileName();
 | 
					 | 
				
			||||||
                qCritical() << "        installed version in DC:" << installedVersion;
 | 
					 | 
				
			||||||
                qCritical() << "     file version in repository:" << fileVersion;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            qCritical() << "CANNOT FIND JSON-NR FOR" << fName;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
QString Update::getFileVersion(QString const& jsonFileName) {
 | 
					 | 
				
			||||||
    // "version":"15.10.2023 14:55 02.00.06",
 | 
					 | 
				
			||||||
    static const QRegularExpression re("^.*(\\\"[Vv]ersion\\\":)([\\s\\\"]{0,})([^,\\\"]{0,}).*$");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    QString fileVersion("");
 | 
					 | 
				
			||||||
    QFile inputFile(QDir::cleanPath(m_customerRepository + QDir::separator() + jsonFileName));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (inputFile.exists()) {
 | 
					 | 
				
			||||||
        if (inputFile.open(QIODevice::ReadOnly)) {
 | 
					 | 
				
			||||||
           QTextStream in(&inputFile);
 | 
					 | 
				
			||||||
           while (!in.atEnd()) {
 | 
					 | 
				
			||||||
              QString line = in.readLine();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
              QRegularExpressionMatch match;
 | 
					 | 
				
			||||||
              int idx = line.indexOf(re, 0, &match);
 | 
					 | 
				
			||||||
              if (idx != -1) {
 | 
					 | 
				
			||||||
                  int const lastCaptured = match.lastCapturedIndex();
 | 
					 | 
				
			||||||
                  // the dc only sends 16 Byte
 | 
					 | 
				
			||||||
                  fileVersion = match.captured(lastCaptured);
 | 
					 | 
				
			||||||
                  fileVersion.truncate(16);
 | 
					 | 
				
			||||||
                  break;
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
           }
 | 
					 | 
				
			||||||
           inputFile.close();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        // qCritical() << "ERROR" << inputFile.fileName() << "does not exist";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return fileVersion;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Update::downloadJson(enum FileTypeJson type,
 | 
					 | 
				
			||||||
                          int templateIdx,
 | 
					 | 
				
			||||||
                          QString jsFileToSendToDC) const {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_hw->dc_autoRequest(true); // downloading Json needs the AutoEmission flag
 | 
					 | 
				
			||||||
    qDebug() << "SET AUTO-REQUEST=TRUE";
 | 
					 | 
				
			||||||
    QThread::sleep(1);  // make sure the auto-request flag is acknowledged
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    QStringList lst;
 | 
					 | 
				
			||||||
    bool ready = false;
 | 
					 | 
				
			||||||
    int nTry = 25;
 | 
					 | 
				
			||||||
    while ((ready = m_hw->sys_ready4sending()) == false) {
 | 
					 | 
				
			||||||
        QThread::msleep(200);
 | 
					 | 
				
			||||||
        if (--nTry <= 0) {
 | 
					 | 
				
			||||||
            qCritical() << "SYS NOT READY FOR SENDING AFTER 5 SECONDS";
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    bool ret = false;
 | 
					 | 
				
			||||||
    QString msg;
 | 
					 | 
				
			||||||
    lst.clear();
 | 
					 | 
				
			||||||
    if (ready) {
 | 
					 | 
				
			||||||
        QFile file(jsFileToSendToDC);
 | 
					 | 
				
			||||||
        QFileInfo fi(jsFileToSendToDC); // max. size of template file is 800 bytes
 | 
					 | 
				
			||||||
        if (file.exists()) {
 | 
					 | 
				
			||||||
            if (file.open(QIODevice::ReadOnly)) {
 | 
					 | 
				
			||||||
                if (fi.size() > 0 && fi.size() <= 800) {
 | 
					 | 
				
			||||||
                    QByteArray ba = file.readAll();
 | 
					 | 
				
			||||||
                    // kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer
 | 
					 | 
				
			||||||
                    //      nrOfTemplate=1...32 if kindOfFile==6
 | 
					 | 
				
			||||||
                    //      content = content of the Json file, max 800byte ascii signs
 | 
					 | 
				
			||||||
                    if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
 | 
					 | 
				
			||||||
                                                   templateIdx,
 | 
					 | 
				
			||||||
                                                   (uint8_t *)ba.data())) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        /*
 | 
					 | 
				
			||||||
                         *  Note: the machine id is contained in DC2C_conf.json.
 | 
					 | 
				
			||||||
                         *  The idea was to use this to check if the download of
 | 
					 | 
				
			||||||
                         *  the json-file was correct. It did not work, as the
 | 
					 | 
				
			||||||
                         *  update of the PSA (to reflect a change in the
 | 
					 | 
				
			||||||
                         *  machine id) did not happen immediately.
 | 
					 | 
				
			||||||
                         *
 | 
					 | 
				
			||||||
                            m_hw->dc_autoRequest(true);
 | 
					 | 
				
			||||||
                            QThread::msleep(500);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            // testing
 | 
					 | 
				
			||||||
                            m_hw->request_ReadbackMachineID();
 | 
					 | 
				
			||||||
                            QThread::msleep(500);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            uint8_t data[64];
 | 
					 | 
				
			||||||
                            memset(data, 0x00, sizeof(data));
 | 
					 | 
				
			||||||
                            uint8_t length = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            m_hw->readback_machineIDdata(&length, data);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            QThread::msleep(500);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            QByteArray ba((const char*)data, length);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            qCritical() << length << "MACHINE ID =" << ba.toHex(':');
 | 
					 | 
				
			||||||
                        */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        ret = true;
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        qCritical() << QString("ERROR SEND JSON-FILE %1 TO DC").arg(file.fileName());
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    qCritical() << QString("SIZE OF %1 TOO BIG (%2 BYTES)").arg(jsFileToSendToDC).arg(fi.size());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                qCritical() << QString("CAN NOT OPEN ") + jsFileToSendToDC + " FOR READING";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            qCritical() << (QString(jsFileToSendToDC) + " DOES NOT EXIST");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_hw->dc_autoRequest(false);
 | 
					 | 
				
			||||||
    qDebug() << "SET AUTO-REQUEST=FALSE";
 | 
					 | 
				
			||||||
    QThread::sleep(1);  // make sure the auto-request flag is acknowledged
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return ret;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Update::updatePrinterTemplate(int templateIdx, QString jsFile) const {
 | 
					 | 
				
			||||||
    return downloadJson(FileTypeJson::PRINTER, templateIdx, jsFile);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Update::updateConfig(QString jsFile) {
 | 
					 | 
				
			||||||
    return downloadJson(FileTypeJson::CONFIG, 0, jsFile);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Update::updateCashConf(QString jsFile) {
 | 
					 | 
				
			||||||
    return downloadJson(FileTypeJson::CASH, 0, jsFile);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Update::updateDeviceConf(QString jsFile) {
 | 
					 | 
				
			||||||
    return downloadJson(FileTypeJson::DEVICE, 0, jsFile);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,6 @@ class Update : public QObject {
 | 
				
			|||||||
        return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0'));
 | 
					        return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0'));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    bool openSerialPort();
 | 
					    bool openSerialPort();
 | 
				
			||||||
    bool closeSerialPort();
 | 
					    bool closeSerialPort();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user