ATBUpdateTool/update.h

94 lines
2.7 KiB
C++

#ifndef UPDATE_H_INCLUDED
#define UPDATE_H_INCLUDED
#include <QObject>
#include <QString>
#include <QFile>
#include <QDir>
#include <QByteArray>
#include <QProcess>
#include "plugins/interfaces.h"
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
class Update;
// TODO: check hardware compatibility
// TODO: opkg commandos
class Update : public QObject {
Q_OBJECT
hwinf *m_hw;
char const *m_serialInterface;
char const *m_baudrate;
QFile m_update_ctrl_file;
QFile m_update_ctrl_file_copy;
QString m_workingDir;
bool m_maintenanceMode;
bool m_testMode;
bool m_init;
bool finishUpdate(bool finish);
QStringList getLinesToWorkOn();
QStringList split(QString line, QChar sep = ',');
bool execUpdateScript();
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);
explicit Update(hwinf *hw,
QString update_ctrl_file,
QString workingDir = ".",
bool maintenanceMode = false,
bool testMode = false,
QObject *parent = nullptr,
char const *serialInterface = SERIAL_PORT,
char const *baudrate = "115200");
virtual ~Update() override;
bool doUpdate();
private:
static QString jsonType(enum FileTypeJson type);
DownloadResult sendStatus(int ret) const;
DownloadResult sendNextAddress(int bNum) const;
DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const;
DownloadResult dc_downloadBinary(QByteArray const &binary) const;
bool startBootloader() const;
bool stopBootloader() const;
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 updateDC(QString bFile) const;
bool updatePrinterTemplate(int templateIdx, QString fname) const;
bool updateBinary(char const *fileToSendToDC);
bool updateConfig(QString jsFileToSendToDC);
bool updateCashConf(QString jsFileToSendToDC);
bool updateDeviceConf(QString jsFileToSendToDC);
bool downloadJson(enum FileTypeJson type, int templateIdx,
QString jsFileToSendToDC) const;
private slots:
void readyReadStandardOutput();
void readyReadStandardError();
void finished(int exitCode, QProcess::ExitStatus exitStatus);
};
#endif // UPDATE_H_INCLUDED