Using Utils-class and QRunnable.w
This commit is contained in:
parent
3938051c32
commit
892fae92ad
90
main.cpp
90
main.cpp
@ -5,14 +5,18 @@
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "message_handler.h"
|
||||
#include "interfaces.h"
|
||||
|
||||
#include "interfaces.h"
|
||||
#include "DCPlugin/include/hwapi.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
#include <QSharedMemory>
|
||||
#include <QRunnable>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef PTU5
|
||||
#define SERIAL_PORT "ttymxc2"
|
||||
@ -20,35 +24,14 @@
|
||||
#define SERIAL_PORT "ttyUSB0"
|
||||
#endif
|
||||
|
||||
static void updateBinary(std::unique_ptr<hwinf> hw, // update d2dc*.bin
|
||||
char const *fileToSendToDC,
|
||||
char const *baudrate,
|
||||
char const *serialInterface) {
|
||||
for (int i=0; i < 1;++i) {
|
||||
qDebug() << "file to send to DC ..." << fileToSendToDC;
|
||||
qDebug() << "baudrate ............." << baudrate;
|
||||
qDebug() << "serial interface ....." << serialInterface;
|
||||
hw->dc_updateDC(fileToSendToDC, baudrate, serialInterface);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
||||
}
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
static void updatePrinterConf(std::unique_ptr<hwinf> hw, // update printer-file
|
||||
QVector<int> nrOfTemplate,
|
||||
QVector<QString> fileToSendToDC,
|
||||
QString br, QString serial) {
|
||||
// for (int i = 0; i < 1; ++i) {
|
||||
if (nrOfTemplate.size() == 1 && fileToSendToDC.size() == 1) {
|
||||
hw->dc_updatePrinterTemplate(hwapi::FileTypeJson::PRINTER,
|
||||
nrOfTemplate, fileToSendToDC,
|
||||
br, serial);
|
||||
|
||||
// hw->dc_printTemplate(hwapi::FileTypeJson::PRINTER,
|
||||
// nrOfTemplate, br, serial);
|
||||
}
|
||||
QCoreApplication::quit();
|
||||
class Work : public QRunnable {
|
||||
Utils m_utils;
|
||||
public:
|
||||
explicit Work(QString update_ctrl_file) : m_utils(update_ctrl_file) {}
|
||||
void run() {
|
||||
m_utils.doUpdate();
|
||||
}
|
||||
};
|
||||
|
||||
// argv[1]: file to send to dc
|
||||
int main(int argc, char *argv[]) {
|
||||
@ -60,46 +43,15 @@ int main(int argc, char *argv[]) {
|
||||
//setDebugLevel(QtMsgType::QtDebugMsg);
|
||||
}
|
||||
|
||||
if (argc != 2) {
|
||||
qCritical() << "Usage: " << argv[0] << "<file to send to dc>";
|
||||
return -1;
|
||||
QString update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
|
||||
if (argc == 2) {
|
||||
update_ctrl_file = argv[1];
|
||||
}
|
||||
qCritical() << "Using" << update_ctrl_file << "as update logfile";
|
||||
|
||||
std::unique_ptr<hwinf> hw(new hwapi());
|
||||
QFileInfo fileInfo(argv[1]);
|
||||
QString fname(fileInfo.fileName());
|
||||
int ret = 0;
|
||||
|
||||
if (fname.startsWith("dc") && fname.endsWith(".bin")) {
|
||||
std::thread t(updateBinary, std::move(hw),
|
||||
fname.toStdString().c_str(), "115200", SERIAL_PORT);
|
||||
ret = a.exec();
|
||||
t.join();
|
||||
} else {
|
||||
if (fname.startsWith("DC2C_print") && fname.endsWith(".json")) {
|
||||
qDebug() << "downloading" << fname << "to dc...";
|
||||
|
||||
QVector<QString> fnames;
|
||||
QVector<int> templateIdx;
|
||||
|
||||
int const nrOfTemplate = fname.midRef(10, 2).toInt();
|
||||
if (nrOfTemplate <= 0 && nrOfTemplate > 32) {
|
||||
qCritical() << "wrong template number" << nrOfTemplate;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fnames.append(fname);
|
||||
templateIdx.append(nrOfTemplate);
|
||||
|
||||
std::thread t(updatePrinterConf, std::move(hw),
|
||||
templateIdx,
|
||||
fnames,
|
||||
"115200", SERIAL_PORT);
|
||||
|
||||
ret = a.exec();
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
Work work(update_ctrl_file);
|
||||
work.setAutoDelete(false);
|
||||
QThreadPool *threadPool = QThreadPool::globalInstance();
|
||||
threadPool->start(&work);
|
||||
return threadPool->waitForDone();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user