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 <QFileInfo>
|
||||||
|
|
||||||
#include "message_handler.h"
|
#include "message_handler.h"
|
||||||
#include "interfaces.h"
|
|
||||||
|
|
||||||
|
#include "interfaces.h"
|
||||||
#include "DCPlugin/include/hwapi.h"
|
#include "DCPlugin/include/hwapi.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QSharedMemory>
|
#include <QSharedMemory>
|
||||||
|
#include <QRunnable>
|
||||||
|
#include <QThreadPool>
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#ifdef PTU5
|
#ifdef PTU5
|
||||||
#define SERIAL_PORT "ttymxc2"
|
#define SERIAL_PORT "ttymxc2"
|
||||||
@ -20,35 +24,14 @@
|
|||||||
#define SERIAL_PORT "ttyUSB0"
|
#define SERIAL_PORT "ttyUSB0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void updateBinary(std::unique_ptr<hwinf> hw, // update d2dc*.bin
|
class Work : public QRunnable {
|
||||||
char const *fileToSendToDC,
|
Utils m_utils;
|
||||||
char const *baudrate,
|
public:
|
||||||
char const *serialInterface) {
|
explicit Work(QString update_ctrl_file) : m_utils(update_ctrl_file) {}
|
||||||
for (int i=0; i < 1;++i) {
|
void run() {
|
||||||
qDebug() << "file to send to DC ..." << fileToSendToDC;
|
m_utils.doUpdate();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
// argv[1]: file to send to dc
|
// argv[1]: file to send to dc
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
@ -60,46 +43,15 @@ int main(int argc, char *argv[]) {
|
|||||||
//setDebugLevel(QtMsgType::QtDebugMsg);
|
//setDebugLevel(QtMsgType::QtDebugMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2) {
|
QString update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
|
||||||
qCritical() << "Usage: " << argv[0] << "<file to send to dc>";
|
if (argc == 2) {
|
||||||
return -1;
|
update_ctrl_file = argv[1];
|
||||||
}
|
}
|
||||||
|
qCritical() << "Using" << update_ctrl_file << "as update logfile";
|
||||||
|
|
||||||
std::unique_ptr<hwinf> hw(new hwapi());
|
Work work(update_ctrl_file);
|
||||||
QFileInfo fileInfo(argv[1]);
|
work.setAutoDelete(false);
|
||||||
QString fname(fileInfo.fileName());
|
QThreadPool *threadPool = QThreadPool::globalInstance();
|
||||||
int ret = 0;
|
threadPool->start(&work);
|
||||||
|
return threadPool->waitForDone();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user