ATBUpdateTool/UpdatePTUDevCtrl/update.h

102 lines
3.3 KiB
C
Raw Normal View History

2023-05-26 13:03:38 +02:00
#ifndef UPDATE_H_INCLUDED
#define UPDATE_H_INCLUDED
#include <QObject>
#include <QString>
#include <QFile>
#include <QDir>
#include <QByteArray>
#include <QProcess>
#include <QPluginLoader>
2023-05-26 13:03:38 +02:00
#include "plugins/interfaces.h"
2023-05-26 13:03:38 +02:00
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
class Worker;
2023-05-26 13:03:38 +02:00
class Update : public QObject {
Q_OBJECT
hwinf *m_hw = nullptr;
Worker *m_worker = nullptr;
2023-05-26 13:03:38 +02:00
char const *m_serialInterface;
char const *m_baudrate;
QString m_customerRepository;
QString m_customerNrStr;
2023-07-14 13:33:46 +02:00
QString m_branchName;
QString m_pluginName;
2023-05-26 13:03:38 +02:00
QString m_workingDir;
2023-06-20 16:13:11 +02:00
bool m_maintenanceMode;
2023-07-14 13:33:46 +02:00
bool m_dryRun;
bool m_sys_areDCdataValid;
static QPluginLoader pluginLoader;
2023-05-26 13:03:38 +02:00
public:
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6};
static hwinf *loadDCPlugin(QDir const &plugInDir, QString const &fn);
static bool unloadDCPlugin();
2023-07-10 16:00:34 +02:00
static QStringList split(QString line, QChar sep = ',');
explicit Update(Worker *worker,
QString customerRepository,
QString customerNrStr,
2023-07-14 13:33:46 +02:00
QString branchName,
QString plugInDir,
QString pluginName,
QString workingDir,
2023-07-14 13:33:46 +02:00
bool dryRun = false,
2023-05-26 13:03:38 +02:00
QObject *parent = nullptr,
char const *serialInterface = SERIAL_PORT,
char const *baudrate = "115200");
virtual ~Update() override;
bool doUpdate(int &displayIndex, QStringList const &linesToWorkOn);
bool checkDownloadedJsonVersions(QStringList const& jsonFileNames);
2023-05-26 13:03:38 +02:00
hwinf *hw() { return m_hw; }
hwinf const *hw() const { return m_hw; }
//QString customerId() { return m_customerId; }
//QString const customerId() const { return m_customerId; }
2023-07-14 13:33:46 +02:00
QString branchName() { return m_branchName; }
QString const branchName() const { return m_branchName; }
//QString repositoryPath() { return m_repositoryPath; }
//QString const repositoryPath() const { return m_repositoryPath; }
2023-07-14 13:33:46 +02:00
private:
static QString jsonType(enum FileTypeJson type);
bool openSerial(int br, QString baudrate, QString comPort) const;
void closeSerial() const;
bool isSerialOpen() const;
bool resetDeviceController() const;
QByteArray loadBinaryDCFile(QString filename) const;
bool downloadBinaryToDC(QString const &bFile) const;
bool updatePrinterTemplate(int templateIdx, QString fname) const;
bool updateBinary(QString const &fileToSendToDC);
bool updateConfig(QString jsFileToSendToDC);
bool updateCashConf(QString jsFileToSendToDC);
bool updateDeviceConf(QString jsFileToSendToDC);
bool downloadJson(enum FileTypeJson type, int templateIdx,
QString jsFileToSendToDC) const;
QStringList getDcSoftAndHardWareVersion();
QString getFileVersion(QString const& jsonFile);
private slots:
void readyReadStandardOutput();
void readyReadStandardError();
void finished(int exitCode, QProcess::ExitStatus exitStatus);
void onReportDCDownloadStatus(QString const &status);
void onReportDCDownloadSuccess(QString const &msg);
void onReportDCDownloadFailure(QString const &errorMsg);
2023-05-26 13:03:38 +02:00
};
#endif // UPDATE_H_INCLUDED