ATBUpdateTool/main.cpp

90 lines
2.7 KiB
C++
Raw Normal View History

2023-04-05 14:43:27 +02:00
#include <QCoreApplication>
#include <QApplication>
#include <QDebug>
#include <QTimer>
2023-04-13 11:22:32 +02:00
#include <QFileInfo>
2023-04-05 14:43:27 +02:00
#include "message_handler.h"
2023-04-13 11:22:32 +02:00
#include "interfaces.h"
2023-04-05 14:43:27 +02:00
#include "DCPlugin/include/hwapi.h"
2023-04-05 14:43:27 +02:00
#include <unistd.h>
#include <thread>
#include <memory>
2023-04-14 09:06:45 +02:00
#include <QSharedMemory>
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
2023-04-13 11:22:32 +02:00
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) {
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
2023-04-13 16:22:46 +02:00
QVector<int> nrOfTemplate,
QVector<QString> fileToSendToDC,
QString br, QString serial) {
for (int i=0; i < 1;++i) {
2023-05-03 09:00:02 +02:00
//hw->dc_updatePrinterTemplate(hwapi::FileTypeJson::PRINTER,
// nrOfTemplate, fileToSendToDC,
// br, serial);
2023-04-13 16:22:46 +02:00
hw->dc_printTemplate(hwapi::FileTypeJson::PRINTER,
nrOfTemplate, br, serial);
2023-04-05 14:43:27 +02:00
}
QCoreApplication::quit();
}
// argv[1]: file to send to dc
int main(int argc, char *argv[]) {
2023-04-05 14:43:27 +02:00
QApplication a(argc, argv);
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtDebugMsg);
//setDebugLevel(QtMsgType::QtDebugMsg);
}
if (argc > 2) {
qCritical() << "Usage: " << argv[0] << "<file to send to dc>";
return -1;
2023-04-05 14:43:27 +02:00
}
std::unique_ptr<hwinf> hw(new hwapi());
2023-04-13 11:22:32 +02:00
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);
2023-04-13 11:22:32 +02:00
ret = a.exec();
t.join();
2023-04-13 16:22:46 +02:00
} else {
QVector<QString> fnames{"DC2C_print01.json",
"DC2C_print02.json",
"DC2C_print03.json"};
QVector<int> templateIdx{1,2,3};
//if (fname.startsWith("DC2C_print") && fname.endsWith(".json")) {
//int const nrOfTemplate = fname.midRef(10, 2).toInt();
std::thread t(updatePrinterConf, std::move(hw), templateIdx, fnames,
"115200", SERIAL_PORT);
2023-04-13 11:22:32 +02:00
ret = a.exec();
t.join();
2023-04-13 16:22:46 +02:00
//}
2023-04-13 11:22:32 +02:00
}
2023-04-05 14:43:27 +02:00
return ret;
}