From f52dec91244362fabd5df5206412327444c6986c Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 16 Jun 2023 16:54:21 +0200 Subject: [PATCH] Just for saving --- main.cpp.bck | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp.bck2 | 54 ++++++++++++++++++++++++++++++++++ main.cpp.bck3 | 62 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 main.cpp.bck create mode 100644 main.cpp.bck2 create mode 100644 main.cpp.bck3 diff --git a/main.cpp.bck b/main.cpp.bck new file mode 100644 index 0000000..ffe9f71 --- /dev/null +++ b/main.cpp.bck @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include + +#include "message_handler.h" +#include "plugins/interfaces.h" + +#include "DCPlugin/include/hwapi.h" + +#include +#include +#include + +static void updateBinary(std::unique_ptr 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 hw, // update printer-file + 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(); +} + +int main(int argc, char *argv[]) { + 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] << ""; + return -1; + } + + std::unique_ptr hw(new hwapi()); + 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")) { +#ifdef PTU5 + std::thread t(updatePrinterConf, std::move(hw), + fname.toStdString().c_str(), "115200", "ttymxc2"); +#else + std::thread t(updatePrinterConf, std::move(hw), + fname.toStdString().c_str(), "115200", "ttyUSB0"); +#endif + ret = a.exec(); + t.join(); + } + + return ret; +} diff --git a/main.cpp.bck2 b/main.cpp.bck2 new file mode 100644 index 0000000..92c3ead --- /dev/null +++ b/main.cpp.bck2 @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "message_handler.h" +#include "interfaces.h" +#include "DCPlugin/include/hwapi.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "update.h" +#include "worker_thread.h" +#include "worker.h" + +#ifdef PTU5 +#define SERIAL_PORT "ttymxc2" +#else +#define SERIAL_PORT "ttyUSB0" +#endif + +// argv[1]: file to send to dc +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + + if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling + atbInstallMessageHandler(atbDebugOutput); + setDebugLevel(QtMsgType::QtDebugMsg); + //setDebugLevel(QtMsgType::QtDebugMsg); + } + + QByteArray const value = qgetenv("XDG_RUNTIME_DIR"); + if (value.size() == 0) { + qputenv("XDG_RUNTIME_DIR", "/run/user/0"); + } + + QString const update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv"; + QString const workingDir = (argc == 2) ? argv[1] : "."; + + Worker worker(update_ctrl_file, workingDir); + + qCritical() << "starting main event loop"; + int ret = a.exec(); + qCritical() << "stopping main event loop" << ret; + + return ret; +} diff --git a/main.cpp.bck3 b/main.cpp.bck3 new file mode 100644 index 0000000..7864d55 --- /dev/null +++ b/main.cpp.bck3 @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include + +#include "message_handler.h" +#include "plugins/interfaces.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "update.h" +#include "worker_thread.h" +#include "worker.h" + +#include + +#ifdef PTU5 +#define SERIAL_PORT "ttymxc2" +#else +#define SERIAL_PORT "ttyUSB0" +#endif + +static void doWork(QString update_ctrl_file, QString workingDir) { + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + Update update(update_ctrl_file, workingDir); + update.doUpdate(); + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + QCoreApplication::quit(); +} + +// argv[1]: file to send to dc +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + + if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling + atbInstallMessageHandler(atbDebugOutput); + setDebugLevel(QtMsgType::QtDebugMsg); + //setDebugLevel(QtMsgType::QtDebugMsg); + } + + QByteArray const value = qgetenv("XDG_RUNTIME_DIR"); + if (value.size() == 0) { + qputenv("XDG_RUNTIME_DIR", "/run/user/0"); + } + + // QString const update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv"; + // QString const workingDir = (argc == 2) ? argv[1] : "."; + + // std::thread t(doWork, update_ctrl_file, workingDir); + + int ret = a.exec(); + // t.join(); + + return ret; +}