ATBUpdateTool/main.cpp

54 lines
1.4 KiB
C++

#include <QCoreApplication>
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include "message_handler.h"
#include "load_dc_plugin.h"
#include "serial.h"
#include "commands_to_update_dc.h"
#include "plugins/interfaces.h"
#include "DCPlugin/include/hwapi.h"
#include <unistd.h>
#include <thread>
#include <memory>
//static void updateDC(hwinf const *hw) {
static void updateDC(std::unique_ptr<hwinf> hw,
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] << "<file to send to dc>";
return -1;
}
std::unique_ptr<hwinf> hw(new hwapi());
#ifdef PTU5
std::thread t(updateDC, std::move(hw), argv[1], "115200", "ttymxc2");
#else
std::thread t(updateDC, std::move(hw), "dc2c4.bin", "115200", "ttyUSB0");
#endif
int ret = a.exec();
t.join();
return ret;
}