Add worker-object to be able to update for the worker.
This commit is contained in:
parent
b508c0517d
commit
332d689b8c
44
update.cpp
44
update.cpp
@ -1,4 +1,5 @@
|
|||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
#include "worker.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -25,9 +26,9 @@
|
|||||||
#define UPDATE_OPKG (1)
|
#define UPDATE_OPKG (1)
|
||||||
#define UPDATE_DC (1)
|
#define UPDATE_DC (1)
|
||||||
#define UPDATE_PRINTER_TEMPLATES (1)
|
#define UPDATE_PRINTER_TEMPLATES (1)
|
||||||
#define UPDATE_CASH_TEMPLATE (0)
|
#define UPDATE_CASH_TEMPLATE (1)
|
||||||
#define UPDATE_CONF_TEMPLATE (0)
|
#define UPDATE_CONF_TEMPLATE (1)
|
||||||
#define UPDATE_DEVICE_TEMPLATE (0)
|
#define UPDATE_DEVICE_TEMPLATE (1)
|
||||||
|
|
||||||
static const QMap<QString, int> baudrateMap = {
|
static const QMap<QString, int> baudrateMap = {
|
||||||
{"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3},
|
{"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3},
|
||||||
@ -75,6 +76,7 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Update::Update(hwinf *hw,
|
Update::Update(hwinf *hw,
|
||||||
|
Worker *worker,
|
||||||
QString customerRepository,
|
QString customerRepository,
|
||||||
QString customerNrStr,
|
QString customerNrStr,
|
||||||
QString branchName,
|
QString branchName,
|
||||||
@ -85,6 +87,7 @@ Update::Update(hwinf *hw,
|
|||||||
char const *baudrate)
|
char const *baudrate)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_hw(hw)
|
, m_hw(hw)
|
||||||
|
, m_worker(worker)
|
||||||
, m_serialInterface(serialInterface)
|
, m_serialInterface(serialInterface)
|
||||||
, m_baudrate(baudrate)
|
, m_baudrate(baudrate)
|
||||||
, m_customerRepository(customerRepository)
|
, m_customerRepository(customerRepository)
|
||||||
@ -510,7 +513,7 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
|
|||||||
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
|
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// ACHTUNG !!!
|
// ACHTUNG !!!
|
||||||
@ -542,7 +545,6 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
|||||||
bool res = false;
|
bool res = false;
|
||||||
QString fToWorkOn = (*it).trimmed();
|
QString fToWorkOn = (*it).trimmed();
|
||||||
|
|
||||||
|
|
||||||
if (fToWorkOn.contains("dc2c", Qt::CaseInsensitive) &&
|
if (fToWorkOn.contains("dc2c", Qt::CaseInsensitive) &&
|
||||||
fToWorkOn.endsWith(".bin", Qt::CaseInsensitive)) {
|
fToWorkOn.endsWith(".bin", Qt::CaseInsensitive)) {
|
||||||
|
|
||||||
@ -582,6 +584,10 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
|||||||
|
|
||||||
if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
|
if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
|
||||||
qCritical() << "downloaded binary" << fToWorkOn;
|
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
|
m_hw->dc_autoRequest(true); // turn auto-request setting on
|
||||||
@ -607,6 +613,10 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
|||||||
} else {
|
} else {
|
||||||
if ((res = updatePrinterTemplate(templateIdx, fToWorkOn))) {
|
if ((res = updatePrinterTemplate(templateIdx, fToWorkOn))) {
|
||||||
qInfo() << "downloaded printer template"<< fToWorkOn;
|
qInfo() << "downloaded printer template"<< fToWorkOn;
|
||||||
|
++displayIndex;
|
||||||
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")")
|
||||||
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
||||||
|
Worker::UPDATE_STEP_DONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -614,24 +624,36 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
|||||||
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
||||||
res = true;
|
res = true;
|
||||||
#if UPDATE_CASH_TEMPLATE == 1
|
#if UPDATE_CASH_TEMPLATE == 1
|
||||||
if ((res = updateCashConf(name))) {
|
if ((res = updateCashConf(fToWorkOn))) {
|
||||||
qInfo() << "downloaded cash template"<< name;
|
qInfo() << "downloaded cash template"<< fToWorkOn;
|
||||||
|
++displayIndex;
|
||||||
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")")
|
||||||
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
||||||
|
Worker::UPDATE_STEP_DONE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (fToWorkOn.contains("DC2C_conf", Qt::CaseInsensitive)
|
} else if (fToWorkOn.contains("DC2C_conf", Qt::CaseInsensitive)
|
||||||
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
||||||
res = true;
|
res = true;
|
||||||
#if UPDATE_CONF_TEMPLATE == 1
|
#if UPDATE_CONF_TEMPLATE == 1
|
||||||
if ((res= updateConfig(name))) {
|
if ((res= updateConfig(fToWorkOn))) {
|
||||||
qInfo() << "downloaded config template"<< name;
|
qInfo() << "downloaded config template"<< fToWorkOn;
|
||||||
|
++displayIndex;
|
||||||
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")")
|
||||||
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
||||||
|
Worker::UPDATE_STEP_DONE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (fToWorkOn.contains("DC2C_device", Qt::CaseInsensitive)
|
} else if (fToWorkOn.contains("DC2C_device", Qt::CaseInsensitive)
|
||||||
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
||||||
res = true;
|
res = true;
|
||||||
#if UPDATE_DEVICE_TEMPLATE == 1
|
#if UPDATE_DEVICE_TEMPLATE == 1
|
||||||
if ((res = updateDeviceConf(name))) {
|
if ((res = updateDeviceConf(fToWorkOn))) {
|
||||||
qInfo() << "downloaded device template"<< name;
|
qInfo() << "downloaded device template"<< fToWorkOn;
|
||||||
|
++displayIndex;
|
||||||
|
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")")
|
||||||
|
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
|
||||||
|
Worker::UPDATE_STEP_DONE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
11
update.h
11
update.h
@ -9,7 +9,6 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
#include "plugins/interfaces.h"
|
#include "plugins/interfaces.h"
|
||||||
#include "apism/apism_client.h"
|
|
||||||
|
|
||||||
#ifdef PTU5
|
#ifdef PTU5
|
||||||
#define SERIAL_PORT "ttymxc2"
|
#define SERIAL_PORT "ttymxc2"
|
||||||
@ -17,15 +16,12 @@
|
|||||||
#define SERIAL_PORT "ttyUSB0"
|
#define SERIAL_PORT "ttyUSB0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Update;
|
class Worker;
|
||||||
|
|
||||||
// TODO: check hardware compatibility
|
|
||||||
// TODO: opkg commandos
|
|
||||||
|
|
||||||
class Update : public QObject {
|
class Update : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
hwinf *m_hw;
|
hwinf *m_hw;
|
||||||
|
Worker *m_worker;
|
||||||
char const *m_serialInterface;
|
char const *m_serialInterface;
|
||||||
char const *m_baudrate;
|
char const *m_baudrate;
|
||||||
QString m_customerRepository;
|
QString m_customerRepository;
|
||||||
@ -44,6 +40,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
explicit Update(hwinf *hw,
|
explicit Update(hwinf *hw,
|
||||||
|
Worker *worker,
|
||||||
QString customerRepository,
|
QString customerRepository,
|
||||||
QString customerNrStr,
|
QString customerNrStr,
|
||||||
QString branchName,
|
QString branchName,
|
||||||
@ -53,7 +50,7 @@ public:
|
|||||||
char const *serialInterface = SERIAL_PORT,
|
char const *serialInterface = SERIAL_PORT,
|
||||||
char const *baudrate = "115200");
|
char const *baudrate = "115200");
|
||||||
virtual ~Update() override;
|
virtual ~Update() override;
|
||||||
bool doUpdate(QStringList const &linesToWorkOn);
|
bool doUpdate(int &displayIndex, QStringList const &linesToWorkOn);
|
||||||
|
|
||||||
//QString customerId() { return m_customerId; }
|
//QString customerId() { return m_customerId; }
|
||||||
//QString const customerId() const { return m_customerId; }
|
//QString const customerId() const { return m_customerId; }
|
||||||
|
Loading…
Reference in New Issue
Block a user