2023-05-22 16:06:52 +02:00
|
|
|
#include "update.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTextStream>
|
2023-05-26 13:03:38 +02:00
|
|
|
#include <QRegularExpression>
|
2023-05-22 16:06:52 +02:00
|
|
|
|
2023-07-06 14:21:29 +02:00
|
|
|
//#include <iostream>
|
|
|
|
//#include <fstream>
|
|
|
|
//#include <ctime>
|
|
|
|
|
2023-06-16 16:51:30 +02:00
|
|
|
#include "plugins/interfaces.h"
|
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:36:36 +02:00
|
|
|
#define COLUMN_REQUEST (0)
|
|
|
|
#define COLUMN_NAME (1)
|
|
|
|
#define COLUMN_DATE_TIME (2)
|
|
|
|
#define COLUMN_RESULT (3)
|
|
|
|
|
2023-06-22 15:43:21 +02:00
|
|
|
#define UPDATE_OPKG (1)
|
2023-07-06 14:32:57 +02:00
|
|
|
#define UPDATE_DC (1)
|
2023-07-06 15:14:52 +02:00
|
|
|
#define UPDATE_PRINTER_TEMPLATES (1)
|
2023-06-22 15:36:36 +02:00
|
|
|
#define UPDATE_CASH_TEMPLATE (0)
|
|
|
|
#define UPDATE_CONF_TEMPLATE (0)
|
|
|
|
#define UPDATE_DEVICE_TEMPLATE (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-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);
|
|
|
|
static QPluginLoader pluginLoader(pluginLibName);
|
|
|
|
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-06-16 16:51:30 +02:00
|
|
|
Update::Update(hwinf *hw,
|
|
|
|
QString update_ctrl_file,
|
2023-07-14 13:34:48 +02:00
|
|
|
QString repositoryPath,
|
|
|
|
QString customerId,
|
|
|
|
QString branchName,
|
2023-05-26 13:03:38 +02:00
|
|
|
QString workingDir,
|
2023-06-20 16:14:13 +02:00
|
|
|
bool maintenanceMode,
|
2023-07-06 14:23:04 +02:00
|
|
|
bool testMode,
|
2023-07-14 13:34:48 +02:00
|
|
|
bool executeScriptOnly,
|
|
|
|
bool dryRun,
|
2023-05-22 16:06:52 +02:00
|
|
|
QObject *parent,
|
|
|
|
char const *serialInterface,
|
|
|
|
char const *baudrate)
|
|
|
|
: QObject(parent)
|
2023-06-16 16:51:30 +02:00
|
|
|
, m_hw(hw)
|
2023-05-22 16:06:52 +02:00
|
|
|
, m_serialInterface(serialInterface)
|
|
|
|
, m_baudrate(baudrate)
|
|
|
|
, m_update_ctrl_file(update_ctrl_file)
|
|
|
|
, m_update_ctrl_file_copy(update_ctrl_file + ".copy")
|
2023-07-14 13:34:48 +02:00
|
|
|
, m_repositoryPath(repositoryPath)
|
|
|
|
, m_customerId(customerId)
|
|
|
|
, m_branchName(branchName)
|
2023-05-26 13:03:38 +02:00
|
|
|
, m_workingDir(workingDir)
|
2023-06-20 16:14:13 +02:00
|
|
|
, m_maintenanceMode(maintenanceMode)
|
2023-07-06 14:23:04 +02:00
|
|
|
, m_testMode(testMode)
|
2023-07-14 13:34:48 +02:00
|
|
|
, m_executeScriptOnly(executeScriptOnly)
|
|
|
|
, m_dryRun(dryRun)
|
|
|
|
//, m_apismClient(nullptr, nullptr, nullptr)
|
2023-06-16 16:51:30 +02:00
|
|
|
, m_init(true) {
|
2023-05-22 16:06:52 +02:00
|
|
|
|
2023-07-14 13:34:48 +02:00
|
|
|
// m_apismClient.sendSelfTest();
|
|
|
|
|
2023-07-06 14:23:04 +02:00
|
|
|
if (!m_testMode) {
|
|
|
|
// make sure the files are empty
|
|
|
|
if (m_update_ctrl_file.exists()) {
|
|
|
|
if (m_update_ctrl_file.open(QIODevice::ReadWrite |
|
|
|
|
QIODevice::Truncate |
|
|
|
|
QIODevice::Text)) {
|
|
|
|
m_update_ctrl_file.close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << "Update-file" << m_update_ctrl_file.fileName()
|
|
|
|
<< "does not exist";
|
|
|
|
m_init = false;
|
2023-06-29 12:42:16 +02:00
|
|
|
}
|
2023-07-06 14:23:04 +02:00
|
|
|
if (m_update_ctrl_file_copy.exists()) {
|
|
|
|
if (m_update_ctrl_file_copy.open(QIODevice::ReadWrite |
|
|
|
|
QIODevice::Truncate |
|
|
|
|
QIODevice::Text)) {
|
|
|
|
m_update_ctrl_file_copy.close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << "Update-file-copy" << m_update_ctrl_file_copy.fileName()
|
|
|
|
<< "does not exist";
|
|
|
|
m_init = false;
|
2023-06-29 12:42:16 +02:00
|
|
|
}
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-06-29 12:42:16 +02:00
|
|
|
|
|
|
|
// execute update_psa-script
|
|
|
|
if (m_init) {
|
2023-07-06 14:23:04 +02:00
|
|
|
if (!m_testMode) {
|
|
|
|
if ((m_init = execUpdateScript()) == false) {
|
|
|
|
qCritical() << "UPDATE_SCRIPT FAILED";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_init) {
|
2023-06-29 12:42:16 +02:00
|
|
|
if (!m_update_ctrl_file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
|
|
|
qCritical() << "CAN NOT OPEN" << m_update_ctrl_file.fileName();
|
|
|
|
m_init = false;
|
|
|
|
} else {
|
|
|
|
qDebug() << "OPENED" << m_update_ctrl_file.fileName();
|
|
|
|
}
|
|
|
|
if (!m_update_ctrl_file_copy.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
|
|
|
qCritical() << "CAN NOT OPEN" << m_update_ctrl_file_copy.fileName();
|
|
|
|
m_init = false;
|
|
|
|
} else {
|
|
|
|
qDebug() << "OPENED" << m_update_ctrl_file_copy.fileName();
|
|
|
|
}
|
|
|
|
}
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Update::~Update() {
|
2023-06-29 12:42:16 +02:00
|
|
|
// make sure the files are closed
|
|
|
|
m_update_ctrl_file.close();
|
|
|
|
m_update_ctrl_file_copy.close();
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 13:03:38 +02:00
|
|
|
bool Update::execUpdateScript() {
|
|
|
|
// path of update-script 'update_psa'
|
2023-06-20 16:14:13 +02:00
|
|
|
QString update_psa("/opt/app/tools/atbupdate/update_psa ");
|
|
|
|
if (m_maintenanceMode) {
|
|
|
|
update_psa += " -m ";
|
|
|
|
}
|
|
|
|
update_psa += " --wdir ";
|
2023-05-26 13:03:38 +02:00
|
|
|
update_psa += m_workingDir;
|
|
|
|
|
2023-05-30 16:47:00 +02:00
|
|
|
qCritical() << "update_psa: " << update_psa;
|
2023-05-26 13:03:38 +02:00
|
|
|
|
|
|
|
QScopedPointer<QProcess> p(new QProcess(this));
|
|
|
|
p->setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
|
2023-06-27 17:29:10 +02:00
|
|
|
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
|
|
|
|
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
|
|
|
|
|
2023-05-26 13:03:38 +02:00
|
|
|
p->start(update_psa);
|
2023-06-27 17:29:10 +02:00
|
|
|
|
2023-05-26 13:03:38 +02:00
|
|
|
if (p->waitForStarted(1000)) {
|
|
|
|
if (p->state() == QProcess::ProcessState::Running) {
|
2023-06-27 17:29:10 +02:00
|
|
|
// maintenance_mode: update_psa script enters an infinite loop
|
|
|
|
int const timeout = (m_maintenanceMode ? 200000: -1);
|
2023-06-21 16:25:21 +02:00
|
|
|
if (p->waitForFinished(timeout)) {
|
2023-05-26 13:03:38 +02:00
|
|
|
QString output = p->readAllStandardOutput().toStdString().c_str();
|
|
|
|
QStringList lst = output.split('\n');
|
|
|
|
for (int i = 0; i < lst.size(); ++i) {
|
|
|
|
qDebug() << lst[i];
|
|
|
|
}
|
2023-06-27 17:29:10 +02:00
|
|
|
if (p->exitStatus() == QProcess::NormalExit) {
|
|
|
|
qInfo() << "EXECUTED" << update_psa
|
|
|
|
<< "with code" << p->exitCode();
|
|
|
|
return (p->exitCode() == 0);
|
|
|
|
}
|
2023-06-21 16:25:21 +02:00
|
|
|
} else {
|
|
|
|
qCritical() << "update-script TIMEDOUT after"
|
|
|
|
<< timeout/1000 << "seconds";
|
2023-05-26 13:03:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-16 16:51:30 +02:00
|
|
|
Update::DownloadResult Update::sendStatus(int ret) const {
|
|
|
|
switch (ret) { // return values of dc are:
|
|
|
|
case 0: // 0: no answer by now
|
|
|
|
return DownloadResult::NOP; // 1: error
|
|
|
|
case 10: // 10: success
|
|
|
|
return DownloadResult::OK;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return DownloadResult::ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Update::DownloadResult Update::sendNextAddress(int bNum) const {
|
|
|
|
// sends address only if blockNumber is one of 0, 1024, 2048, 3072, 4096
|
|
|
|
int noAnswerCount = 0;
|
|
|
|
int errorCount = 0;
|
|
|
|
if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) {
|
2023-07-14 13:34:48 +02:00
|
|
|
// qDebug() << "addr-block" << bNum << "...";
|
2023-06-16 16:51:30 +02:00
|
|
|
while (noAnswerCount <= 250) {
|
|
|
|
m_hw->bl_sendAddress(bNum);
|
2023-07-06 14:24:19 +02:00
|
|
|
QThread::msleep(100);
|
2023-06-16 16:51:30 +02:00
|
|
|
DownloadResult const res = sendStatus(m_hw->bl_wasSendingAddOK());
|
|
|
|
if (res != DownloadResult::NOP) {
|
|
|
|
if (res == DownloadResult::ERROR) {
|
|
|
|
if (++errorCount >= 10) {
|
|
|
|
qCritical() << "addr-block" << bNum << "...FAILED";
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
} else { // res == DownloadResult::OK
|
2023-07-14 13:34:48 +02:00
|
|
|
// qInfo() << "addr-block" << bNum << "...OK";
|
2023-06-16 16:51:30 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
noAnswerCount += 1; // no answer by now
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// wait max. about 3 seconds
|
|
|
|
return DownloadResult::TIMEOUT;
|
|
|
|
}
|
|
|
|
// blockNumber is not one of 0, 1024, 2048, 3072, 4096 -> do nothing
|
|
|
|
return DownloadResult::NOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
Update::DownloadResult Update::sendNextDataBlock(QByteArray const &binary,
|
|
|
|
int bNum) const {
|
|
|
|
uint8_t local[66];
|
|
|
|
int const bAddr = bNum * 64;
|
|
|
|
int noAnswerCount = 0;
|
|
|
|
int errorCount = 0;
|
|
|
|
|
|
|
|
memcpy(local, binary.constData() + bAddr, 64);
|
|
|
|
local[64] = local[65] = 0x00;
|
|
|
|
|
2023-07-06 14:21:29 +02:00
|
|
|
// QByteArray b((const char *)(&local[0]), 64);
|
|
|
|
// qCritical() << "SNDB" << bNum << b.size() << b.toHex();
|
2023-06-16 16:51:30 +02:00
|
|
|
|
|
|
|
while (noAnswerCount <= 250) {
|
|
|
|
m_hw->bl_sendDataBlock(64, local);
|
2023-07-06 14:21:29 +02:00
|
|
|
QThread::msleep(10);
|
2023-06-16 16:51:30 +02:00
|
|
|
DownloadResult const res = sendStatus(m_hw->bl_wasSendingDataOK());
|
|
|
|
if (res != DownloadResult::NOP) {
|
|
|
|
if (res == DownloadResult::ERROR) {
|
|
|
|
if (++errorCount >= 10) {
|
|
|
|
qCritical() << "data for block" << bNum << "...FAILED";
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
} else {
|
2023-07-06 14:21:29 +02:00
|
|
|
// qInfo() << "data for block" << bNum << "OK";
|
2023-06-16 16:51:30 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
noAnswerCount += 1; // no answer by now
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// wait max. about 3 seconds
|
|
|
|
return DownloadResult::TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const {
|
|
|
|
int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1;
|
|
|
|
|
2023-07-06 14:27:44 +02:00
|
|
|
// fill lst block of data to be sent with 0xFF
|
|
|
|
QByteArray ba = b.leftJustified(nBlocks*64, (char)(0xFF));
|
|
|
|
|
|
|
|
qInfo() << "total number of bytes to send to dc" << ba.size();
|
2023-06-16 16:51:30 +02:00
|
|
|
qInfo() << "total number of blocks to send to dc" << nBlocks;
|
|
|
|
|
|
|
|
int bNum = 0;
|
|
|
|
DownloadResult res = DownloadResult::OK;
|
2023-07-14 13:34:48 +02:00
|
|
|
fprintf(stderr, "\n64-byte block %04d ", bNum);
|
2023-06-16 16:51:30 +02:00
|
|
|
while (res != DownloadResult::ERROR && bNum < nBlocks) {
|
|
|
|
if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) {
|
2023-07-06 14:27:44 +02:00
|
|
|
if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) {
|
2023-06-16 16:51:30 +02:00
|
|
|
bNum += 1;
|
2023-07-14 13:34:48 +02:00
|
|
|
fprintf(stderr, ".");
|
|
|
|
if ((bNum % 80) == 0) {
|
|
|
|
fprintf(stderr, "\n64-byte block %04d ", bNum);
|
|
|
|
}
|
2023-06-16 16:51:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-14 13:34:48 +02:00
|
|
|
fprintf(stderr, "\nlast 64-byte block %04d\n", bNum);
|
|
|
|
|
2023-07-06 14:27:44 +02:00
|
|
|
int const rest = ba.size() % 64;
|
|
|
|
int const offset = ba.size() - rest;
|
|
|
|
char const *startAddress = ba.constData() + offset;
|
2023-06-16 16:51:30 +02:00
|
|
|
|
|
|
|
if (rest > 0) {
|
2023-07-06 14:27:44 +02:00
|
|
|
// SHOULD NEVER HAPPEN !!!
|
|
|
|
uint8_t local[66];
|
|
|
|
memset(local, 0xFF, sizeof(local));
|
2023-06-16 16:51:30 +02:00
|
|
|
memcpy(local, startAddress, rest);
|
2023-07-06 14:27:44 +02:00
|
|
|
qCritical() << "ERROR SEND REMAINING" << rest << "BYTES";
|
|
|
|
m_hw->bl_sendDataBlock(64, local);
|
2023-06-16 16:51:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m_hw->bl_sendLastBlock();
|
|
|
|
qInfo() << "last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Update::startBootloader() const {
|
|
|
|
qDebug() << "starting bootloader...";
|
|
|
|
int nTry = 5;
|
|
|
|
while (--nTry >= 0) {
|
|
|
|
m_hw->bl_startBL();
|
2023-07-06 14:24:19 +02:00
|
|
|
QThread::msleep(5000);
|
2023-06-16 16:51:30 +02:00
|
|
|
m_hw->bl_checkBL();
|
|
|
|
if (m_hw->bl_isUp()) {
|
|
|
|
qInfo() << "starting bootloader...OK";
|
2023-07-06 14:24:19 +02:00
|
|
|
QThread::msleep(5000);
|
2023-06-16 16:51:30 +02:00
|
|
|
return true;
|
2023-06-22 15:36:36 +02:00
|
|
|
} else {
|
|
|
|
qCritical() << "bootloader not up (" << nTry << ")";
|
2023-06-16 16:51:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
qCritical() << "starting bootloader...FAILED";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Update::stopBootloader() const {
|
|
|
|
qDebug() << "stopping bootloader...";
|
|
|
|
int nTry = 5;
|
|
|
|
while (--nTry >= 0) {
|
|
|
|
m_hw->bl_stopBL();
|
2023-07-06 14:24:19 +02:00
|
|
|
QThread::msleep(500);
|
2023-06-16 16:51:30 +02:00
|
|
|
if (!m_hw->bl_isUp()) {
|
|
|
|
qInfo() << "stopping bootloader...OK";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qCritical() << "stopping bootloader...FAILED";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 << "...";
|
|
|
|
if (m_hw->dc_openSerial(br, baudrate, comPort, 1)) { // 1 for connect
|
|
|
|
qInfo() << "opening serial" << br << baudrate << comPort << "...OK";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
qCritical() << "opening serial" << br << baudrate << comPort << "...FAILED";
|
|
|
|
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-16 16:51:30 +02:00
|
|
|
bool Update::resetDeviceController() const {
|
|
|
|
qDebug() << "resetting device controller...";
|
|
|
|
m_hw->bl_rebootDC();
|
|
|
|
// wait maximally 3 seconds, before starting bootloader
|
2023-07-06 14:24:19 +02:00
|
|
|
QThread::sleep(1);
|
2023-06-16 16:51:30 +02:00
|
|
|
qInfo() << "resetting device controller...OK";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Update::loadBinaryDCFile(QString filename) const {
|
|
|
|
qDebug() << "loading dc binary" << filename << "...";
|
|
|
|
|
|
|
|
QFile file(filename); // closed in destructor call
|
|
|
|
if (!file.exists()) {
|
|
|
|
qCritical() << file.fileName() << "does not exist";
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
qCritical() << "cannot open file" << file.fileName();
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
qInfo() << "loading dc binary" << filename << "...OK";
|
|
|
|
return file.readAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Update::downloadBinaryToDC(QString const &bFile) const {
|
|
|
|
qDebug() << "sending" << bFile << "to dc...";
|
|
|
|
QByteArray const dcBinary = loadBinaryDCFile(bFile);
|
|
|
|
if (dcBinary.size() > 0) {
|
|
|
|
if (dc_downloadBinary(dcBinary) != DownloadResult::OK) {
|
|
|
|
qCritical() << "sending" << bFile << "to dc...FAILED";
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
qInfo() << "sending" << bFile << "to dc...OK";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << "sending" << bFile << "to dc...FAILED";
|
|
|
|
qCritical() << "loading binary" << bFile << "FAILED";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-27 17:31:38 +02:00
|
|
|
/*
|
|
|
|
Using the DC bootloader:
|
|
|
|
1 : bl_reboot() // send to application, want DC2 to reset (in order to start
|
|
|
|
// the bootloader)
|
|
|
|
2 : bl_startBL(): // send within 4s after DC poewer-on, otherwise bl is left
|
|
|
|
3 : bl_check(): // send command to verify if bl is up
|
|
|
|
4 : bl_isUp(): // returns true if bl is up and running
|
|
|
|
|
|
|
|
5 : bl_sendAddress(blockNumber)
|
|
|
|
// send start address, nr of 64-byte block, start with 0
|
|
|
|
// will be sent only for following block-numbers:
|
|
|
|
// 0, 1024, 2048, 3072 and 4096, so basically every 64kByte
|
|
|
|
// 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-05-22 16:06:52 +02:00
|
|
|
bool Update::updateBinary(char const *fileToSendToDC) {
|
2023-06-21 16:25:21 +02:00
|
|
|
qInfo() << "updating device controller binary" << fileToSendToDC;
|
2023-06-16 16:51:30 +02:00
|
|
|
QFile fn(fileToSendToDC);
|
|
|
|
bool r;
|
|
|
|
if ((r = fn.exists()) == true) {
|
|
|
|
QString const linkTarget = fn.symLinkTarget();
|
2023-06-21 16:25:21 +02:00
|
|
|
QFileInfo fi(linkTarget);
|
|
|
|
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")";
|
|
|
|
if ((r = updateDC(linkTarget)) == true) {
|
|
|
|
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done";
|
2023-06-19 16:01:29 +02:00
|
|
|
} else {
|
2023-06-21 16:25:21 +02:00
|
|
|
qCritical() << "updating binary (size=" << linkTarget << fi.size() << ")... FAILED";
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
2023-06-16 16:51:30 +02:00
|
|
|
} else {
|
2023-06-21 16:25:21 +02:00
|
|
|
qCritical() << "symlink" << fileToSendToDC
|
|
|
|
<< "does not exist -> NO UPDATE OF DC FIRMWARE";
|
2023-06-16 16:51:30 +02:00
|
|
|
}
|
|
|
|
return r;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
|
2023-06-21 16:25:21 +02:00
|
|
|
bool Update::updateDC(QString bFile) const {
|
|
|
|
qDebug() << "updating dc...";
|
|
|
|
qDebug() << "updating dc: file to send" << bFile;
|
2023-06-19 16:01:29 +02:00
|
|
|
if (!resetDeviceController()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!startBootloader()) {
|
2023-07-06 14:28:46 +02:00
|
|
|
// even when start seems to fail, stopping the boot loader does not harm
|
|
|
|
stopBootloader();
|
2023-06-19 16:01:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-07-06 14:28:46 +02:00
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
if (!downloadBinaryToDC(bFile)) {
|
|
|
|
stopBootloader();
|
2023-06-21 16:25:21 +02:00
|
|
|
qCritical() << "updating dc: " << bFile << "...FAILED";
|
2023-06-19 16:01:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-06-21 16:25:21 +02:00
|
|
|
qInfo() << "updating dc: " << bFile << "...OK";
|
2023-07-06 14:28:46 +02:00
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
stopBootloader();
|
2023-07-06 14:28:46 +02:00
|
|
|
//resetDeviceController();
|
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
QThread::sleep(3);
|
|
|
|
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
|
|
|
qDebug() << "updating json-file:" << jsFileToSendToDC << "...";
|
|
|
|
qDebug() << " template-index:" << templateIdx;
|
|
|
|
qDebug() << " json-type:" << jsonType(type);
|
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-06-22 15:36:36 +02:00
|
|
|
qCritical() << "SYS NOT READY FOR SENDING AFTER 5 SECONDS";
|
|
|
|
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();
|
|
|
|
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
|
|
|
|
templateIdx,
|
|
|
|
(uint8_t *)ba.data())) {
|
|
|
|
QThread::sleep(1);
|
|
|
|
qDebug() << "SENT" << jsFileToSendToDC;
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << "SIZE OF" << jsFileToSendToDC
|
|
|
|
<< "TOO BIG (" << fi.size() << "BYTES)";
|
2023-06-21 16:25:21 +02:00
|
|
|
}
|
|
|
|
} else {
|
2023-06-22 15:36:36 +02:00
|
|
|
qCritical() << "CANNOT OPEN" << jsFileToSendToDC << "FOR READING";
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
2023-06-21 16:25:21 +02:00
|
|
|
} else {
|
2023-06-22 15:36:36 +02:00
|
|
|
qCritical() << 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-06-20 16:14:13 +02:00
|
|
|
QStringList Update::getLinesToWorkOn() {
|
|
|
|
QStringList linesToWorkOn;
|
2023-05-22 16:06:52 +02:00
|
|
|
|
|
|
|
QTextStream in(&m_update_ctrl_file);
|
|
|
|
while (!in.atEnd()) {
|
|
|
|
QString line = in.readLine().trimmed();
|
|
|
|
if (line.startsWith("DONE")) {
|
|
|
|
m_update_ctrl_file_copy.write(line.toUtf8().constData());
|
|
|
|
m_update_ctrl_file_copy.write("\n");
|
|
|
|
} else {
|
2023-06-20 16:14:13 +02:00
|
|
|
linesToWorkOn << line;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-20 16:14:13 +02:00
|
|
|
return linesToWorkOn;
|
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-07-14 13:34:48 +02:00
|
|
|
// bool Update::executeProcess(QString const &cmd);
|
|
|
|
|
2023-05-22 16:06:52 +02:00
|
|
|
bool Update::doUpdate() {
|
2023-06-27 17:29:10 +02:00
|
|
|
|
2023-07-14 13:34:48 +02:00
|
|
|
//
|
|
|
|
// ACHTUNG !!!
|
|
|
|
//
|
|
|
|
return true;
|
|
|
|
|
2023-05-22 16:06:52 +02:00
|
|
|
/*
|
|
|
|
The file referred to by 'update_data' has the following structure for
|
|
|
|
each line:
|
|
|
|
|
|
|
|
# ======================================================================
|
|
|
|
# REQUEST | NAME | DATE | RESULT
|
|
|
|
# ======================================================================
|
|
|
|
# where
|
|
|
|
#
|
|
|
|
# STATUS: DOWNLOAD, EXECUTE or DONE
|
|
|
|
# NAME : If starting with 'opkg' it is an opkg-command to be executed.
|
|
|
|
# Otherwise its the name of a file which has to be updated.
|
|
|
|
# DATE : 0000-00-00T00:00:00
|
|
|
|
# RESULT: SUCCESS or ERROR (possibly with description)
|
|
|
|
#
|
|
|
|
*/
|
2023-05-30 16:47:00 +02:00
|
|
|
|
2023-05-22 16:06:52 +02:00
|
|
|
if (!m_init) {
|
2023-06-29 12:42:16 +02:00
|
|
|
qCritical() << "DO UPDATE: INITIALIZATION OR UPDATE-SCRIPT FAILED";
|
2023-05-22 16:06:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-14 13:34:48 +02:00
|
|
|
if (m_executeScriptOnly) { // basically a test flag for executing only the
|
|
|
|
return true; // update script.
|
|
|
|
}
|
|
|
|
|
2023-06-27 17:32:13 +02:00
|
|
|
bool serialOpened = false;
|
2023-07-06 14:31:32 +02:00
|
|
|
bool serialOpen = false;
|
2023-06-22 15:36:36 +02:00
|
|
|
|
2023-06-20 16:14:13 +02:00
|
|
|
QStringList linesToWorkOn = getLinesToWorkOn();
|
|
|
|
if (linesToWorkOn.size() == 0) {
|
2023-06-19 16:01:29 +02:00
|
|
|
qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName();
|
2023-06-20 16:14:13 +02:00
|
|
|
return true;
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
2023-06-29 12:42:16 +02:00
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
qDebug() << "open lines...";
|
2023-06-20 16:14:13 +02:00
|
|
|
for (int i=0; i< linesToWorkOn.size(); ++i) {
|
|
|
|
qDebug() << "line" << i << ":" << linesToWorkOn.at(i).trimmed();
|
2023-06-19 16:01:29 +02:00
|
|
|
}
|
2023-05-22 16:06:52 +02:00
|
|
|
|
|
|
|
QList<QString>::const_iterator it;
|
2023-06-20 16:14:13 +02:00
|
|
|
for (it = linesToWorkOn.cbegin(); it != linesToWorkOn.cend(); ++it) {
|
2023-05-22 16:06:52 +02:00
|
|
|
bool res = false;
|
|
|
|
QString line = (*it).trimmed();
|
|
|
|
if (line.size() == 0 || line.startsWith(QChar('#'))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QStringList lst = split(line.trimmed());
|
|
|
|
if (lst.size() != 4) {
|
2023-06-21 16:25:21 +02:00
|
|
|
qCritical() << "PARSING ERROR FOR LINE"
|
|
|
|
<< line << "IN" << m_update_ctrl_file.fileName();
|
|
|
|
continue;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
QString const &request = lst[COLUMN_REQUEST];
|
|
|
|
QString const &name = lst[COLUMN_NAME];
|
2023-07-06 14:32:57 +02:00
|
|
|
|
|
|
|
QTextStream out(&m_update_ctrl_file_copy);
|
2023-05-22 16:06:52 +02:00
|
|
|
// QString const &datetime = lst[COLUMN_DATE_TIME];
|
2023-06-20 16:14:13 +02:00
|
|
|
// QString const &result = lst[COLUMN_RESULT];
|
|
|
|
qDebug() << "request=" << request << ", name=" << name;
|
|
|
|
if (request.trimmed() == "DOWNLOAD") {
|
2023-07-06 14:32:57 +02:00
|
|
|
if (!serialOpen) {
|
|
|
|
if (!isSerialOpen()) { // open serial only if not already open
|
|
|
|
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) == false) {
|
|
|
|
qCritical() << "CANNOT OPEN" << m_serialInterface << "(BAUDRATE="
|
|
|
|
<< m_baudrate << ")";
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-27 17:32:13 +02:00
|
|
|
}
|
2023-07-06 14:32:57 +02:00
|
|
|
serialOpen = true;
|
|
|
|
qCritical() << "SERIAL OPEN" << m_serialInterface << "(BAUDRATE=" << m_baudrate << ")";
|
|
|
|
}
|
2023-06-27 17:32:13 +02:00
|
|
|
|
2023-07-06 14:32:57 +02:00
|
|
|
if (name.contains("dc2c", Qt::CaseInsensitive) &&
|
|
|
|
name.endsWith(".bin", Qt::CaseInsensitive)) {
|
|
|
|
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();
|
|
|
|
m_hw->request_DC2_HWversion();
|
|
|
|
QThread::sleep(1);
|
|
|
|
}
|
|
|
|
QString const hwVersion = m_hw->dc_getHWversion().toLower();
|
|
|
|
QString const fwVersion = m_hw->dc_getSWversion().toLower();
|
2023-06-27 17:32:13 +02:00
|
|
|
qInfo() << "current dc-hardware-version" << hwVersion;
|
|
|
|
qInfo() << "current dc-firmware-version" << fwVersion;
|
|
|
|
|
2023-07-06 14:32:57 +02:00
|
|
|
QFile fn(name);
|
|
|
|
QFileInfo linkTarget(fn.symLinkTarget());
|
|
|
|
if (!linkTarget.exists()) { // check for broken link
|
|
|
|
res = false;
|
|
|
|
} else {
|
2023-07-14 13:34:48 +02:00
|
|
|
if (false) {
|
|
|
|
//if (fwVersion.startsWith(linkTarget.completeBaseName())) {
|
|
|
|
// qCritical() << "current dc-firmware-version" << fwVersion
|
|
|
|
// << "already installed";
|
|
|
|
// res = false;
|
2023-07-06 14:32:57 +02:00
|
|
|
} else {
|
|
|
|
res = true;
|
|
|
|
|
|
|
|
qCritical() << "downloading" << name.trimmed() << "->"
|
|
|
|
<< linkTarget.completeBaseName() << "to DC";
|
2023-06-22 15:36:36 +02:00
|
|
|
#if UPDATE_DC == 1
|
2023-07-06 14:32:57 +02:00
|
|
|
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";
|
|
|
|
|
|
|
|
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();
|
2023-06-22 15:36:36 +02:00
|
|
|
#endif
|
2023-07-06 14:32:57 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-21 16:25:21 +02:00
|
|
|
} else if (name.contains("DC2C_print", Qt::CaseInsensitive)
|
|
|
|
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
2023-06-22 15:36:36 +02:00
|
|
|
res = true;
|
|
|
|
#if UPDATE_PRINTER_TEMPLATES == 1
|
2023-06-21 16:25:21 +02:00
|
|
|
int i = name.indexOf("DC2C_print", Qt::CaseInsensitive);
|
|
|
|
int const templateIdx = name.mid(i).midRef(10, 2).toInt();
|
2023-06-20 16:14:13 +02:00
|
|
|
if ((templateIdx < 1) || (templateIdx > 32)) {
|
2023-06-21 16:25:21 +02:00
|
|
|
qCritical() << "WRONG TEMPLATE INDEX" << templateIdx;
|
2023-06-20 16:14:13 +02:00
|
|
|
res = false;
|
|
|
|
} else {
|
2023-06-22 15:36:36 +02:00
|
|
|
if ((res = updatePrinterTemplate(templateIdx, name))) {
|
|
|
|
qInfo() << "downloaded printer template"<< name;
|
2023-06-20 16:14:13 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-22 15:36:36 +02:00
|
|
|
#endif
|
2023-06-21 16:25:21 +02:00
|
|
|
} else if (name.contains("DC2C_cash", Qt::CaseInsensitive)
|
|
|
|
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
2023-06-22 15:36:36 +02:00
|
|
|
res = true;
|
2023-06-27 17:29:10 +02:00
|
|
|
#if UPDATE_CASH_TEMPLATE == 1
|
2023-06-22 15:36:36 +02:00
|
|
|
if ((res = updateCashConf(name))) {
|
|
|
|
qInfo() << "downloaded cash template"<< name;
|
|
|
|
}
|
|
|
|
#endif
|
2023-06-21 16:25:21 +02:00
|
|
|
} else if (name.contains("DC2C_conf", Qt::CaseInsensitive)
|
|
|
|
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
2023-06-22 15:36:36 +02:00
|
|
|
res = true;
|
2023-06-27 17:29:10 +02:00
|
|
|
#if UPDATE_CONF_TEMPLATE == 1
|
2023-06-22 15:36:36 +02:00
|
|
|
if ((res= updateConfig(name))) {
|
|
|
|
qInfo() << "downloaded config template"<< name;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else if (name.contains("DC2C_device", Qt::CaseInsensitive)
|
|
|
|
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
|
|
|
res = true;
|
2023-06-27 17:29:10 +02:00
|
|
|
#if UPDATE_DEVICE_TEMPLATE == 1
|
2023-06-22 15:36:36 +02:00
|
|
|
if ((res = updateDeviceConf(name))) {
|
|
|
|
qInfo() << "downloaded device template"<< name;
|
|
|
|
}
|
|
|
|
#endif
|
2023-06-20 16:14:13 +02:00
|
|
|
} else {
|
2023-06-21 16:25:21 +02:00
|
|
|
qCritical() << "UNKNOWN JSON FILE NAME" << name;
|
|
|
|
res = false;
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-06-20 16:14:13 +02:00
|
|
|
} else if (request == "EXECUTE" && name.contains("opkg")) {
|
2023-06-19 16:01:29 +02:00
|
|
|
qInfo() << "starting" << name.trimmed();
|
2023-06-22 15:36:36 +02:00
|
|
|
res = true;
|
|
|
|
#if UPDATE_OPKG == 1
|
2023-05-22 16:06:52 +02:00
|
|
|
QScopedPointer<QProcess> p(new QProcess(this));
|
|
|
|
p->setProcessChannelMode(QProcess::MergedChannels);
|
2023-06-27 17:29:10 +02:00
|
|
|
|
|
|
|
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
|
|
|
|
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
|
|
|
|
|
2023-06-19 16:01:29 +02:00
|
|
|
p->start(name.trimmed());
|
2023-06-27 17:29:10 +02:00
|
|
|
|
2023-05-22 16:06:52 +02:00
|
|
|
if (p->waitForStarted(1000)) {
|
|
|
|
if (p->state() == QProcess::ProcessState::Running) {
|
2023-06-19 16:01:29 +02:00
|
|
|
if (p->waitForFinished(100000)) {
|
2023-05-30 16:47:00 +02:00
|
|
|
QString output = p->readAllStandardOutput();
|
|
|
|
QStringList outputLst = split(output, QChar('\n'));
|
2023-06-19 16:01:29 +02:00
|
|
|
for (int line=0; line < outputLst.size(); ++line) {
|
|
|
|
qDebug() << outputLst[line];
|
|
|
|
}
|
2023-06-20 16:14:13 +02:00
|
|
|
if (p->exitStatus() == QProcess::NormalExit) {
|
|
|
|
qInfo() << "EXECUTED" << name
|
|
|
|
<< "with code" << p->exitCode();
|
|
|
|
res = true;
|
|
|
|
} else {
|
|
|
|
qCritical() << "PROCESS" << name << "CRASHED";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << "PROCESS" << name << "DID NOT FINISH";
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-06-20 16:14:13 +02:00
|
|
|
} else {
|
|
|
|
qCritical() << "WRONG PROCESS STATE" << p->state();
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-06-20 16:14:13 +02:00
|
|
|
} else {
|
|
|
|
qCritical() << "PROCESS" << name << "TIMEOUT AT START";
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
2023-06-22 15:36:36 +02:00
|
|
|
#endif
|
2023-05-22 16:06:52 +02:00
|
|
|
} else {
|
|
|
|
// TODO
|
|
|
|
}
|
2023-07-06 14:30:48 +02:00
|
|
|
out << "DONE, " << name << ", "
|
|
|
|
<< QDateTime::currentDateTime().toString(Qt::ISODate) << ", "
|
|
|
|
<< ((res == true) ? "SUCCESS" : "ERROR") << "\n";
|
|
|
|
out.flush();
|
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-07-06 14:32:20 +02:00
|
|
|
m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON
|
|
|
|
qDebug() << "SET AUTO-REQUEST=TRUE";
|
|
|
|
|
|
|
|
return true;
|
2023-06-22 15:36:36 +02:00
|
|
|
|
2023-07-06 14:32:20 +02:00
|
|
|
// return finishUpdate(linesToWorkOn.size() > 0);
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Update::finishUpdate(bool swapCtrlFiles) {
|
|
|
|
if (swapCtrlFiles) {
|
|
|
|
m_update_ctrl_file.close();
|
|
|
|
m_update_ctrl_file_copy.close();
|
|
|
|
|
2023-07-06 14:21:29 +02:00
|
|
|
//std::ifstream source(m_update_ctrl_file_copy.fileName().toStdString().c_str(), std::ios::binary);
|
|
|
|
//std::ofstream dest(m_update_ctrl_file.fileName().toStdString().c_str(), std::ios::binary);
|
2023-05-22 16:06:52 +02:00
|
|
|
|
2023-07-06 14:21:29 +02:00
|
|
|
//dest << source.rdbuf();
|
|
|
|
//source.close();
|
|
|
|
//dest.close();
|
2023-05-22 16:06:52 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|