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
|
|
|
|
2023-04-11 15:38:04 +02:00
|
|
|
#include "DCPlugin/include/hwapi.h"
|
|
|
|
|
2023-04-05 14:43:27 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <thread>
|
2023-04-11 15:38:04 +02:00
|
|
|
#include <memory>
|
|
|
|
|
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
|
|
|
|
char const *fileToSendToDC,
|
|
|
|
char const *baudrate,
|
|
|
|
char const *serialInterface) {
|
2023-04-11 15:38:04 +02:00
|
|
|
for (int i=0; i < 1;++i) {
|
|
|
|
hw->dc_updateDC(fileToSendToDC, baudrate, serialInterface);
|
2023-04-05 14:43:27 +02:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
|
|
|
}
|
|
|
|
QCoreApplication::quit();
|
|
|
|
}
|
|
|
|
|
2023-04-11 15:38:04 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-04-11 15:38:04 +02:00
|
|
|
if (argc > 2) {
|
|
|
|
qCritical() << "Usage: " << argv[0] << "<file to send to dc>";
|
2023-04-11 14:03:54 +02:00
|
|
|
return -1;
|
2023-04-05 14:43:27 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 15:38:04 +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")) {
|
|
|
|
#ifdef PTU5
|
|
|
|
std::thread t(updateBinary, std::move(hw),
|
|
|
|
fname.toStdString().c_str(), "115200", "ttymxc2");
|
|
|
|
#else
|
|
|
|
std::thread t(updateBinary, std::move(hw),
|
|
|
|
fname.toStdString().c_str(), "115200", "ttyUSB0");
|
|
|
|
#endif
|
|
|
|
ret = a.exec();
|
|
|
|
t.join();
|
|
|
|
} else
|
|
|
|
if (fname.startsWith("DC") && fname.endsWith(".json")) {
|
2023-04-11 15:38:04 +02:00
|
|
|
#ifdef PTU5
|
2023-04-13 11:22:32 +02:00
|
|
|
std::thread t(updatePrinterConf, std::move(hw),
|
|
|
|
fname.toStdString().c_str(), "115200", "ttymxc2");
|
2023-04-11 15:38:04 +02:00
|
|
|
#else
|
2023-04-13 11:22:32 +02:00
|
|
|
std::thread t(updatePrinterConf, std::move(hw),
|
|
|
|
fname.toStdString().c_str(), "115200", "ttyUSB0");
|
2023-04-11 15:38:04 +02:00
|
|
|
#endif
|
2023-04-13 11:22:32 +02:00
|
|
|
ret = a.exec();
|
|
|
|
t.join();
|
|
|
|
}
|
|
|
|
|
2023-04-05 14:43:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|