2023-05-22 16:06:52 +02:00
|
|
|
#include "update.h"
|
2023-08-02 15:47:19 +02:00
|
|
|
#include "worker.h"
|
2023-09-09 14:52:40 +02:00
|
|
|
#include "utils.h"
|
|
|
|
#include "update_dc_event.h"
|
|
|
|
#include "mainwindow.h"
|
2023-12-03 19:41:25 +01:00
|
|
|
#include "plugins/interfaces.h"
|
2023-05-22 16:06:52 +02:00
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTextStream>
|
2023-05-26 13:03:38 +02:00
|
|
|
#include <QRegularExpression>
|
2023-08-09 15:09:44 +02:00
|
|
|
#include <QRegExp>
|
2023-09-09 14:52:40 +02:00
|
|
|
#include <QApplication>
|
2023-05-22 16:06:52 +02:00
|
|
|
|
2023-09-11 10:14:04 +02:00
|
|
|
#if defined (Q_OS_UNIX) || defined (Q_OS_LINUX)
|
|
|
|
#include "unistd.h"
|
|
|
|
#endif
|
2023-07-06 14:21:29 +02:00
|
|
|
|
2023-05-22 16:06:52 +02:00
|
|
|
#include <QSharedMemory>
|
|
|
|
#include <QScopedPointer>
|
2023-05-26 13:03:38 +02:00
|
|
|
#include <QDir>
|
2023-06-16 16:51:30 +02:00
|
|
|
#include <QThread>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QPluginLoader>
|
2023-06-19 16:01:29 +02:00
|
|
|
#include <QMap>
|
2023-05-22 16:06:52 +02:00
|
|
|
|
2023-06-22 15:43:21 +02:00
|
|
|
#define UPDATE_OPKG (1)
|
2023-10-06 12:56:03 +02:00
|
|
|
#define UPDATE_DC (0)
|
2023-05-22 16:06:52 +02:00
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
static const QMap<QString, int> baudrateMap = {
|
|
|
|
{"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3},
|
|
|
|
{"57600" , 4}, {"115200" , 5}
|
|
|
|
};
|
|
|
|
|
2023-09-10 16:51:07 +02:00
|
|
|
QPluginLoader Update::pluginLoader;
|
|
|
|
|
2023-06-16 16:51:30 +02:00
|
|
|
hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
|
|
|
hwinf *hw = nullptr;
|
|
|
|
if (plugInDir.exists()) {
|
|
|
|
QString pluginLibName(fname);
|
|
|
|
pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
|
|
|
|
QFileInfo info(pluginLibName);
|
|
|
|
if (info.exists()) {
|
|
|
|
pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
|
2023-09-10 16:51:07 +02:00
|
|
|
pluginLoader.setFileName(pluginLibName);
|
|
|
|
// static QPluginLoader pluginLoader(pluginLibName);
|
2023-06-16 16:51:30 +02:00
|
|
|
if (!pluginLoader.load()) {
|
|
|
|
qCritical() << "in directory" << plugInDir.absolutePath();
|
|
|
|
qCritical() << "cannot load plugin" << pluginLoader.fileName();
|
|
|
|
qCritical() << pluginLoader.errorString();
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if (!pluginLoader.isLoaded()) {
|
|
|
|
qCritical() << pluginLoader.errorString();
|
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
QObject *plugin = pluginLoader.instance();
|
|
|
|
if (!plugin) {
|
|
|
|
qCritical() << "cannot start instance";
|
|
|
|
exit(-3);
|
|
|
|
}
|
|
|
|
if (! (hw = qobject_cast<hwinf *>(plugin))) {
|
|
|
|
qCritical() << "cannot cast plugin" << plugin << "to hwinf";
|
|
|
|
exit(-4);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << pluginLibName << "does not exist";
|
|
|
|
exit(-5);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << "plugins directory" << plugInDir.absolutePath()
|
|
|
|
<< "does not exist";
|
|
|
|
exit(-6);
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-06-16 16:51:30 +02:00
|
|
|
return hw;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
|
2023-09-10 16:51:07 +02:00
|
|
|
bool Update::unloadDCPlugin() {
|
|
|
|
if (pluginLoader.unload()) {
|
|
|
|
qCritical() << "unloaded plugin" << pluginLoader.fileName();
|
|
|
|
// Note: will re-instantiate the library !
|
|
|
|
// QObject *rootObject = pluginLoader.instance();
|
|
|
|
// if (rootObject) {
|
|
|
|
// qCritical() << "reloaded plugin: root object again available";
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// qCritical()unloaded plugin: root object gone";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-03 19:41:25 +01:00
|
|
|
class hwapi;
|
2023-11-07 09:14:49 +01:00
|
|
|
Update::Update(Worker *worker,
|
2023-07-17 16:45:11 +02:00
|
|
|
QString customerRepository,
|
|
|
|
QString customerNrStr,
|
2023-07-14 13:34:48 +02:00
|
|
|
QString branchName,
|
2023-11-07 09:14:49 +01:00
|
|
|
QString plugInDir,
|
2023-09-09 14:52:40 +02:00
|
|
|
QString pluginName,
|
2023-05-26 13:03:38 +02:00
|
|
|
QString workingDir,
|
2023-07-14 13:34:48 +02:00
|
|
|
bool dryRun,
|
2023-05-22 16:06:52 +02:00
|
|
|
QObject *parent,
|
|
|
|
char const *serialInterface,
|
|
|
|
char const *baudrate)
|
|
|
|
: QObject(parent)
|
2023-11-07 09:14:49 +01:00
|
|
|
, m_hw(loadDCPlugin(QDir(plugInDir), pluginName))
|
2023-08-02 15:47:19 +02:00
|
|
|
, m_worker(worker)
|
2023-05-22 16:06:52 +02:00
|
|
|
, m_serialInterface(serialInterface)
|
|
|
|
, m_baudrate(baudrate)
|
2023-07-17 16:45:11 +02:00
|
|
|
, m_customerRepository(customerRepository)
|
|
|
|
, m_customerNrStr(customerNrStr)
|
2023-07-14 13:34:48 +02:00
|
|
|
, m_branchName(branchName)
|
2023-09-09 14:52:40 +02:00
|
|
|
, m_pluginName(pluginName)
|
2023-05-26 13:03:38 +02:00
|
|
|
, m_workingDir(workingDir)
|
2023-11-24 14:08:54 +01:00
|
|
|
, m_dryRun(dryRun)
|
|
|
|
, m_sys_areDCdataValid(false) {
|
|
|
|
|
2023-12-03 19:41:25 +01:00
|
|
|
#if 0
|
2023-11-24 14:08:54 +01:00
|
|
|
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() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED";
|
|
|
|
}
|
|
|
|
m_hw->dc_autoRequest(true);
|
|
|
|
QThread::msleep(500);
|
|
|
|
}
|
2023-12-03 19:41:25 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QObject const *obj = (QObject const *)(m_hw->getAPI());
|
|
|
|
|
|
|
|
if (connect(obj,
|
|
|
|
SIGNAL(hwapi_reportDCDownloadStatus(QString const&)), this,
|
|
|
|
SLOT(onReportDCDownloadStatus(QString const &)))) {
|
|
|
|
qCritical() << "connect ok";
|
|
|
|
}
|
|
|
|
connect(obj,
|
|
|
|
SIGNAL(hwapi_reportDCDownloadSuccess(QString const&)), this,
|
|
|
|
SLOT(onReportDCDownloadSuccess(QString const &)));
|
|
|
|
connect(obj,
|
|
|
|
SIGNAL(hwapi_reportDCDownloadFailure(QString const &)), this,
|
|
|
|
SLOT(onReportDCDownloadFailure(QString const &)));
|
2023-11-24 14:08:54 +01:00
|
|
|
|
|
|
|
qCritical() << "UPDATE: m_sys_areDCDataValid ..." << m_sys_areDCdataValid;
|
|
|
|
|
|
|
|
//qInfo() << "UPDATE: m_serialInterface ..." << m_serialInterface;
|
|
|
|
//qInfo() << "UPDATE: m_baudrate ..." << m_baudrate;
|
|
|
|
//qInfo() << "UPDATE: m_customerRepository ..." << m_customerRepository;
|
|
|
|
//qInfo() << "UPDATE: m_customerNr ..........." << m_customerNrStr;
|
|
|
|
//qInfo() << "UPDATE: m_branchName ..........." << m_branchName;
|
|
|
|
//qInfo() << "UPDATE: m_pluginName ..........." << m_pluginName;
|
|
|
|
//qInfo() << "UPDATE: m_workingDirectory ....." << m_workingDir;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Update::~Update() {
|
2023-05-26 13:03:38 +02:00
|
|
|
}
|
|
|
|
|
2023-12-03 19:41:25 +01:00
|
|
|
void Update::onReportDCDownloadStatus(QString const &status) {
|
|
|
|
qCritical() << "status" << status;
|
|
|
|
//emit m_worker->showStatusMessage("", status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update::onReportDCDownloadSuccess(QString const &msg) {
|
|
|
|
qCritical() << "msg" << msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update::onReportDCDownloadFailure(QString const &errorMsg) {
|
|
|
|
qCritical() << "msg" << errorMsg;
|
|
|
|
}
|
|
|
|
|
2023-06-16 16:51:30 +02:00
|
|
|
// br is a index into a table, used for historical reasons.
|
|
|
|
bool Update::openSerial(int br, QString baudrate, QString comPort) const {
|
|
|
|
qDebug() << "opening serial" << br << baudrate << comPort << "...";
|
2023-09-09 14:53:36 +02:00
|
|
|
if (m_hw->dc_openSerial(br, baudrate, comPort, 1) == true) { // 1 for connect
|
|
|
|
Utils::printInfoMsg(
|
|
|
|
QString("OPENING SERIAL %1").arg(br)
|
|
|
|
+ " " + baudrate + " " + comPort + "...OK");
|
|
|
|
|
|
|
|
// m_hw->dc_autoRequest(true);
|
|
|
|
m_hw->dc_autoRequest(false);
|
|
|
|
QThread::sleep(1);
|
|
|
|
|
|
|
|
Utils::printInfoMsg(QString("IS PORT OPEN %1").arg(m_hw->dc_isPortOpen()));
|
2023-06-16 16:51:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-09-09 14:53:36 +02:00
|
|
|
|
|
|
|
Utils::printCriticalErrorMsg(
|
|
|
|
QString("OPENING SERIAL %1").arg(br)
|
|
|
|
+ " " + baudrate + " " + comPort + "...FAILED");
|
2023-06-16 16:51:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update::closeSerial() const {
|
2023-07-06 14:25:36 +02:00
|
|
|
qInfo() << "CLOSED SERIAL" << m_baudrate << m_serialInterface;
|
2023-06-16 16:51:30 +02:00
|
|
|
m_hw->dc_closeSerial();
|
|
|
|
}
|
|
|
|
|
2023-07-06 14:25:36 +02:00
|
|
|
bool Update::isSerialOpen() const {
|
|
|
|
return m_hw->dc_isPortOpen();
|
|
|
|
}
|
|
|
|
|
2023-06-27 17:31:38 +02:00
|
|
|
/*
|
2023-09-09 14:54:48 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// USING THE DC BOOTLOADER
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
1 : bl_reboot() // send to application, want DC2 to reset (in order to
|
|
|
|
// start the bootloader)
|
|
|
|
//
|
|
|
|
// NOTE: this function is NOT reliable !!! Sometimes it
|
|
|
|
// simply does not work, in which case bl_startBL,
|
|
|
|
// bl_checkBL and bl_isUp do not work as well.
|
|
|
|
// Alas, there is no feedback if bl_reboot worked!
|
|
|
|
//
|
|
|
|
// NOTE: this function can be called only once per
|
|
|
|
// minute, because once called again, the controller
|
|
|
|
// performs some self-checks consuming some time.
|
|
|
|
//
|
|
|
|
// NOTE: after a successful bl_reboot(), the device is
|
|
|
|
// waiting about 4 seconds in the bootloader. To stay in
|
|
|
|
// the bootloader, we have to send the command
|
|
|
|
// bl_startBL(), which is kind of a misnomer, as it
|
|
|
|
// should be bl_doNotLeaveBL().
|
|
|
|
//
|
|
|
|
2 : bl_startBL(): // send within 4s after DC power-on, otherwise
|
|
|
|
// bootloader is left.
|
|
|
|
//
|
|
|
|
// NOTE: a running bootloader is a MUST for the download
|
|
|
|
// process of a device controller firmware as it does
|
|
|
|
// the actual writing of the memory (the bl_reboot()
|
|
|
|
// from above erases the available memory).
|
|
|
|
//
|
2023-06-27 17:31:38 +02:00
|
|
|
3 : bl_check(): // send command to verify if bl is up
|
2023-09-09 14:54:48 +02:00
|
|
|
//
|
|
|
|
// NOTE: this command is kind of a request that we want
|
|
|
|
// to check if the bootloader is up. The device
|
|
|
|
// (actually the bootloader) responds with its version.
|
|
|
|
//
|
2023-06-27 17:31:38 +02:00
|
|
|
4 : bl_isUp(): // returns true if bl is up and running
|
2023-09-09 14:54:48 +02:00
|
|
|
//
|
|
|
|
// NOTE: we know what the bootloader version actually is
|
|
|
|
// as the bootloader does not change. By comparing the
|
|
|
|
// string received in the previous step with this known
|
|
|
|
// version string we know if the bootloader is up.
|
|
|
|
//
|
|
|
|
// NOTE FOR ALL PREVIOUS STEPS: execute them in their
|
|
|
|
// own slots each to be sure to receive any possible
|
|
|
|
// responds from the device.
|
|
|
|
//
|
2023-06-27 17:31:38 +02:00
|
|
|
5 : bl_sendAddress(blockNumber)
|
|
|
|
// send start address, nr of 64-byte block, start with 0
|
|
|
|
// will be sent only for following block-numbers:
|
2023-09-09 14:54:48 +02:00
|
|
|
// 0, 1024, 2048, 3072 and 4096, so basically every
|
|
|
|
// 64kByte.
|
2023-06-27 17:31:38 +02:00
|
|
|
// for other addresses nothing happens
|
|
|
|
|
|
|
|
6 : bl_wasSendingAddOK()
|
|
|
|
// return val: 0: no response by now
|
|
|
|
// 1: error
|
|
|
|
// 10: OK
|
|
|
|
|
|
|
|
7 : bl_sendDataBlock()
|
|
|
|
// send 64 byte from bin file
|
|
|
|
|
|
|
|
8 : bl_sendLastBlock()
|
|
|
|
// send this command after all data are transferred
|
|
|
|
|
|
|
|
9 : bl_wasSendingDataOK()
|
|
|
|
// return val: 0: no response by now
|
|
|
|
// 1: error
|
|
|
|
// 10: OK
|
|
|
|
|
|
|
|
10 : bl_stopBL() // leave bl and start (the new) application
|
2023-09-09 14:55:48 +02:00
|
|
|
//
|
|
|
|
// NOTE: this function MUST work under all conditions.
|
|
|
|
// Alas, there is no direct result for this command, so
|
|
|
|
// the only way of knowing it was successful is to ask
|
|
|
|
// the device if the bootloader is still running.
|
|
|
|
// There is no problem to repeat this command until the
|
|
|
|
// bootloader is really not running anymore.
|
2023-06-27 17:31:38 +02:00
|
|
|
*/
|
2023-11-21 10:07:50 +01:00
|
|
|
bool Update::updateBinary(QString const &fileToSendToDC) {
|
2023-11-21 15:25:20 +01:00
|
|
|
qInfo() << "UPDATING DEVICE CONTROLLER FIRMWARE BINARY" << fileToSendToDC;
|
2023-11-21 10:07:50 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
|
2023-06-16 16:51:30 +02:00
|
|
|
QFile fn(fileToSendToDC);
|
2023-11-21 10:07:50 +01:00
|
|
|
if (!fn.exists()) {
|
|
|
|
// output via CONSOLE() etc
|
|
|
|
return false;
|
2023-06-16 16:51:30 +02:00
|
|
|
}
|
2023-05-22 16:06:52 +02:00
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
bool bl_isUp = false;
|
|
|
|
if (m_hw->bl_completeStart()) {
|
|
|
|
int cnt = 5;
|
|
|
|
while (--cnt > 0) {
|
|
|
|
if (m_hw->bl_isUp()) {
|
|
|
|
bl_isUp = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-09-09 14:59:05 +02:00
|
|
|
}
|
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
if (!bl_isUp) {
|
|
|
|
return false;
|
2023-09-09 14:59:05 +02:00
|
|
|
}
|
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
if (!m_hw->bl_storeFirmware(fileToSendToDC)) {
|
|
|
|
m_hw->bl_stopBL();
|
2023-06-19 16:01:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-09-09 14:59:05 +02:00
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
uint16_t const nrOfFirmwareBlocks = m_hw->bl_getNrOfFirmwareBlocks();
|
2023-09-09 14:59:05 +02:00
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
for (uint16_t blockNr = 0; blockNr <= nrOfFirmwareBlocks; ++blockNr) {
|
|
|
|
m_hw->bl_blockAutoLoad(blockNr);
|
2023-09-09 14:59:05 +02:00
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
int sleepTime = 0;
|
|
|
|
while (1) {
|
|
|
|
if (sleepTime > 1500) {
|
|
|
|
m_hw->bl_stopBL();
|
|
|
|
return false;
|
|
|
|
}
|
2023-07-06 14:28:46 +02:00
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
int8_t const r = m_hw->bl_blockAutoResponse();
|
|
|
|
|
|
|
|
// after every "bl_blockAutoLoad()" call this until response
|
|
|
|
// retval 0: wait 1: OK, blk was sent 2: OK, transfer complete
|
|
|
|
// 3: error despite repeating, cancel. probably bin file corrupted
|
|
|
|
// Max duration: 3x no response from BL = 900ms
|
|
|
|
|
|
|
|
switch(r) {
|
|
|
|
case 1:
|
|
|
|
/* fall through */
|
|
|
|
case 2:
|
|
|
|
sleepTime = 0;
|
|
|
|
break;
|
|
|
|
case 0: {
|
|
|
|
QThread::msleep(100);
|
|
|
|
sleepTime += 100;
|
|
|
|
} break;
|
|
|
|
case 3:
|
|
|
|
m_hw->bl_stopBL();
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
m_hw->bl_stopBL();
|
|
|
|
return false; // unknown error code
|
|
|
|
}
|
2023-09-09 14:59:05 +02:00
|
|
|
}
|
|
|
|
|
2023-11-21 10:07:50 +01:00
|
|
|
m_hw->bl_stopBL();
|
2023-09-09 14:59:05 +02:00
|
|
|
}
|
2023-07-06 14:28:46 +02:00
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-22 15:36:36 +02:00
|
|
|
QString Update::jsonType(enum FileTypeJson type) {
|
|
|
|
switch (type) {
|
|
|
|
case FileTypeJson::CASH: return "CASH";
|
|
|
|
case FileTypeJson::CONFIG: return "CONFIG";
|
|
|
|
case FileTypeJson::PRINTER: return "PRINTER";
|
|
|
|
case FileTypeJson::SERIAL: return "SERIAL";
|
|
|
|
case FileTypeJson::DEVICE: return "DEVICE";
|
|
|
|
case FileTypeJson::TIME: return "TIME";
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
2023-06-22 15:36:36 +02:00
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Update::downloadJson(enum FileTypeJson type,
|
|
|
|
int templateIdx,
|
|
|
|
QString jsFileToSendToDC) const {
|
2023-06-20 16:14:13 +02:00
|
|
|
|
2023-06-22 15:36:36 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
bool ready = false;
|
|
|
|
int nTry = 25;
|
|
|
|
while ((ready = m_hw->sys_ready4sending()) == false) {
|
|
|
|
QThread::msleep(200);
|
2023-06-19 16:01:29 +02:00
|
|
|
if (--nTry <= 0) {
|
2023-10-06 10:47:08 +02:00
|
|
|
Utils::printCriticalErrorMsg("SYS NOT READY FOR SENDING AFTER 5 SECONDS");
|
2023-06-22 15:36:36 +02:00
|
|
|
break;
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-22 15:36:36 +02:00
|
|
|
|
2023-06-21 16:25:21 +02:00
|
|
|
bool ret = false;
|
2023-06-22 15:36:36 +02:00
|
|
|
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() <= 800) {
|
|
|
|
QByteArray ba = file.readAll();
|
2023-10-06 10:47:08 +02:00
|
|
|
// 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
|
2023-06-22 15:36:36 +02:00
|
|
|
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
|
|
|
|
templateIdx,
|
|
|
|
(uint8_t *)ba.data())) {
|
2023-11-21 15:25:20 +01:00
|
|
|
|
2023-11-24 14:08:54 +01:00
|
|
|
m_hw->dc_autoRequest(true);
|
|
|
|
QThread::msleep(500);
|
2023-11-21 15:25:20 +01:00
|
|
|
|
|
|
|
// testing
|
2023-11-24 14:08:54 +01:00
|
|
|
m_hw->request_ReadbackMachineID();
|
|
|
|
QThread::msleep(500);
|
2023-11-21 15:25:20 +01:00
|
|
|
|
2023-11-24 14:08:54 +01:00
|
|
|
uint8_t data[64];
|
|
|
|
memset(data, 0x00, sizeof(data));
|
|
|
|
uint8_t length = 0;
|
2023-11-21 15:25:20 +01:00
|
|
|
|
2023-11-24 14:08:54 +01:00
|
|
|
m_hw->readback_machineIDdata(&length, data);
|
2023-11-21 15:25:20 +01:00
|
|
|
|
2023-11-24 14:08:54 +01:00
|
|
|
QThread::msleep(500);
|
2023-11-21 15:25:20 +01:00
|
|
|
|
2023-11-24 14:08:54 +01:00
|
|
|
QByteArray ba((const char*)data, length);
|
2023-11-21 15:25:20 +01:00
|
|
|
|
2023-11-24 14:08:54 +01:00
|
|
|
qCritical() << length << "MACHINE ID =" << ba.toHex(':');
|
2023-11-21 15:25:20 +01:00
|
|
|
|
2023-06-22 15:36:36 +02:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
} else {
|
2023-10-06 10:47:08 +02:00
|
|
|
Utils::printCriticalErrorMsg(
|
|
|
|
QString("SIZE OF %1 TOO BIG (%2 BYTES)")
|
|
|
|
.arg(jsFileToSendToDC).arg(fi.size()));
|
2023-06-21 16:25:21 +02:00
|
|
|
}
|
|
|
|
} else {
|
2023-10-06 10:47:08 +02:00
|
|
|
Utils::printCriticalErrorMsg(
|
|
|
|
QString("CAN NOT OPEN ") + jsFileToSendToDC + " FOR READING");
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
2023-06-21 16:25:21 +02:00
|
|
|
} else {
|
2023-10-06 10:47:08 +02:00
|
|
|
Utils::printCriticalErrorMsg(
|
|
|
|
QString(jsFileToSendToDC) + " DOES NOT EXIST");
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-22 15:36:36 +02:00
|
|
|
|
|
|
|
m_hw->dc_autoRequest(false);
|
|
|
|
qDebug() << "SET AUTO-REQUEST=FALSE";
|
|
|
|
QThread::sleep(1); // make sure the auto-request flag is acknowledged
|
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-22 15:36:36 +02:00
|
|
|
bool Update::updatePrinterTemplate(int templateIdx, QString jsFile) const {
|
|
|
|
return downloadJson(FileTypeJson::PRINTER, templateIdx, jsFile);
|
2023-06-21 16:25:21 +02:00
|
|
|
}
|
|
|
|
|
2023-06-22 15:36:36 +02:00
|
|
|
bool Update::updateConfig(QString jsFile) {
|
|
|
|
return downloadJson(FileTypeJson::CONFIG, 0, jsFile);
|
2023-06-21 16:25:21 +02:00
|
|
|
}
|
|
|
|
|
2023-06-22 15:36:36 +02:00
|
|
|
bool Update::updateCashConf(QString jsFile) {
|
|
|
|
return downloadJson(FileTypeJson::CASH, 0, jsFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Update::updateDeviceConf(QString jsFile) {
|
|
|
|
return downloadJson(FileTypeJson::DEVICE, 0, jsFile);
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 16:47:00 +02:00
|
|
|
QStringList Update::split(QString line, QChar sep) {
|
2023-05-22 16:06:52 +02:00
|
|
|
QStringList lst;
|
|
|
|
QString next;
|
|
|
|
int start = 0, end;
|
|
|
|
|
2023-05-30 16:47:00 +02:00
|
|
|
while ((end = line.indexOf(sep, start)) != -1) {
|
2023-05-22 16:06:52 +02:00
|
|
|
next = line.mid(start, end - start).trimmed();
|
|
|
|
lst << next;
|
|
|
|
start = end + 1;
|
|
|
|
}
|
|
|
|
next = line.mid(start, end - start).trimmed();
|
|
|
|
lst << next;
|
|
|
|
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
2023-06-27 17:29:10 +02:00
|
|
|
void Update::readyReadStandardOutput() {
|
|
|
|
QProcess *p = (QProcess *)sender();
|
|
|
|
QByteArray buf = p->readAllStandardOutput();
|
|
|
|
qCritical() << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update::readyReadStandardError() {
|
|
|
|
QProcess *p = (QProcess *)sender();
|
|
|
|
QByteArray buf = p->readAllStandardError();
|
|
|
|
qCritical() << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
|
|
|
|
QProcess *p = (QProcess *)sender();
|
|
|
|
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardOutput()));
|
|
|
|
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
|
|
|
|
}
|
|
|
|
|
2023-09-09 14:59:05 +02:00
|
|
|
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
|
2023-07-14 13:34:48 +02:00
|
|
|
|
2023-09-09 14:59:05 +02:00
|
|
|
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) {
|
2023-12-03 19:41:25 +01:00
|
|
|
//if (m_sys_areDCdataValid == false) {
|
|
|
|
// qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED";
|
|
|
|
// return false;
|
|
|
|
//}
|
2023-11-07 09:14:49 +01:00
|
|
|
|
2023-08-09 15:09:44 +02:00
|
|
|
bool res = false;
|
2023-05-22 16:06:52 +02:00
|
|
|
QList<QString>::const_iterator it;
|
2023-07-17 16:45:11 +02:00
|
|
|
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
|
2023-08-09 15:09:44 +02:00
|
|
|
m_worker->startProgressLoop();
|
2023-12-03 19:41:25 +01:00
|
|
|
QString const &fToWorkOn = QDir::cleanPath(QString("/tmp") + QDir::separator() + it->trimmed());
|
|
|
|
//QString const &fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed());
|
2023-09-09 14:59:05 +02:00
|
|
|
static const QRegularExpression version("^.*dc2c[.][0-9]{1,2}[.][0-9]{1,2}[.]bin.*$");
|
2023-08-09 15:09:44 +02:00
|
|
|
if (fToWorkOn.contains(version)) {
|
2023-12-03 19:41:25 +01:00
|
|
|
m_hw->dcDownloadRequest(fToWorkOn);
|
|
|
|
m_hw->dcDownloadReportStart(); // start reporting thread
|
|
|
|
|
|
|
|
|
2023-11-21 10:09:04 +01:00
|
|
|
bool updateBinaryRes = true;
|
2023-07-06 14:32:57 +02:00
|
|
|
|
2023-11-21 10:09:04 +01:00
|
|
|
// CONSOLE()
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if ((updateBinaryRes = updateBinary(fToWorkOn)) == true) {
|
|
|
|
|
|
|
|
// qCritical() << "downloaded binary" << fToWorkOn;
|
|
|
|
|
|
|
|
++displayIndex;
|
|
|
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")")
|
|
|
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
|
|
|
Worker::UPDATE_STEP_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
2023-07-06 14:32:57 +02:00
|
|
|
}
|
2023-07-17 16:45:11 +02:00
|
|
|
}
|
2023-11-21 10:09:04 +01:00
|
|
|
|
|
|
|
res = updateBinaryRes;
|
|
|
|
|
|
|
|
} else if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive)
|
|
|
|
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
2023-07-17 16:45:11 +02:00
|
|
|
res = true;
|
|
|
|
int i = fToWorkOn.indexOf("DC2C_print", Qt::CaseInsensitive);
|
|
|
|
int const templateIdx = fToWorkOn.mid(i).midRef(10, 2).toInt();
|
|
|
|
if ((templateIdx < 1) || (templateIdx > 32)) {
|
|
|
|
qCritical() << "WRONG TEMPLATE INDEX" << templateIdx;
|
|
|
|
res = false;
|
|
|
|
} else {
|
|
|
|
if ((res = updatePrinterTemplate(templateIdx, fToWorkOn))) {
|
2023-10-06 12:56:03 +02:00
|
|
|
Utils::printInfoMsg(
|
|
|
|
QString("DOWNLOADED PRINTER TEMPLATE %1 WITH INDEX=%2")
|
|
|
|
.arg(fToWorkOn)
|
|
|
|
.arg(templateIdx));
|
2023-08-02 15:47:19 +02:00
|
|
|
++displayIndex;
|
2023-10-06 12:56:03 +02:00
|
|
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")")
|
2023-08-02 15:47:19 +02:00
|
|
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
|
|
|
Worker::UPDATE_STEP_DONE);
|
2023-06-20 16:14:13 +02:00
|
|
|
}
|
2023-07-17 16:45:11 +02:00
|
|
|
}
|
|
|
|
} else if (fToWorkOn.contains("DC2C_cash", Qt::CaseInsensitive)
|
|
|
|
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
|
|
|
res = true;
|
2023-08-02 15:47:19 +02:00
|
|
|
if ((res = updateCashConf(fToWorkOn))) {
|
2023-10-06 10:47:08 +02:00
|
|
|
Utils::printInfoMsg(QString("DOWNLOADED CASH TEMPLATE %1").arg(fToWorkOn));
|
2023-08-02 15:47:19 +02:00
|
|
|
++displayIndex;
|
2023-10-06 12:56:03 +02:00
|
|
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")")
|
2023-08-02 15:47:19 +02:00
|
|
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
|
|
|
Worker::UPDATE_STEP_DONE);
|
2023-07-17 16:45:11 +02:00
|
|
|
}
|
|
|
|
} else if (fToWorkOn.contains("DC2C_conf", Qt::CaseInsensitive)
|
|
|
|
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
|
|
|
res = true;
|
2023-08-02 15:47:19 +02:00
|
|
|
if ((res= updateConfig(fToWorkOn))) {
|
2023-10-06 12:56:03 +02:00
|
|
|
Utils::printInfoMsg(QString("DOWNLOADED CONFIG TEMPLATE %1").arg(fToWorkOn));
|
2023-08-02 15:47:19 +02:00
|
|
|
++displayIndex;
|
2023-10-06 12:56:03 +02:00
|
|
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")")
|
2023-08-02 15:47:19 +02:00
|
|
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
|
|
|
Worker::UPDATE_STEP_DONE);
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-07-17 16:45:11 +02:00
|
|
|
} else if (fToWorkOn.contains("DC2C_device", Qt::CaseInsensitive)
|
|
|
|
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
2023-06-22 15:36:36 +02:00
|
|
|
res = true;
|
2023-08-02 15:47:19 +02:00
|
|
|
if ((res = updateDeviceConf(fToWorkOn))) {
|
2023-10-06 12:56:03 +02:00
|
|
|
Utils::printInfoMsg(QString("DOWNLOADED DEVICE TEMPLATE %1").arg(fToWorkOn));
|
2023-08-02 15:47:19 +02:00
|
|
|
++displayIndex;
|
2023-10-06 12:56:03 +02:00
|
|
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")")
|
2023-08-02 15:47:19 +02:00
|
|
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
|
|
|
Worker::UPDATE_STEP_DONE);
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
2023-07-17 16:45:11 +02:00
|
|
|
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
|
|
|
|
res = false;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-10-20 13:55:18 +02:00
|
|
|
// m_worker->stopProgressLoop();
|
|
|
|
// m_worker->setProgress(100);
|
2023-08-09 15:09:44 +02:00
|
|
|
|
|
|
|
if (res == false) {
|
|
|
|
break;
|
|
|
|
}
|
2023-06-27 17:32:13 +02:00
|
|
|
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
|
2023-06-22 15:36:36 +02:00
|
|
|
|
2023-10-06 12:56:03 +02:00
|
|
|
m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON
|
|
|
|
qDebug() << "SET AUTO-REQUEST=TRUE";
|
2023-07-06 14:32:20 +02:00
|
|
|
|
2023-08-09 15:09:44 +02:00
|
|
|
return res;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|