2023-05-26 13:03:38 +02:00
|
|
|
#ifndef UPDATE_H_INCLUDED
|
|
|
|
#define UPDATE_H_INCLUDED
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QFile>
|
2023-06-16 16:51:30 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QByteArray>
|
2023-05-26 13:03:38 +02:00
|
|
|
|
2023-06-16 16:51:30 +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 Update;
|
|
|
|
|
|
|
|
// TODO: check hardware compatibility
|
|
|
|
// TODO: opkg commandos
|
|
|
|
|
|
|
|
class Update : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2023-06-16 16:51:30 +02:00
|
|
|
hwinf *m_hw;
|
2023-05-26 13:03:38 +02:00
|
|
|
char const *m_serialInterface;
|
|
|
|
char const *m_baudrate;
|
|
|
|
QFile m_update_ctrl_file;
|
|
|
|
QFile m_update_ctrl_file_copy;
|
|
|
|
QString m_workingDir;
|
2023-06-20 16:13:11 +02:00
|
|
|
bool m_maintenanceMode;
|
2023-05-26 13:03:38 +02:00
|
|
|
|
|
|
|
bool m_init;
|
|
|
|
|
|
|
|
bool updateBinary(char const *fileToSendToDC);
|
2023-06-19 16:00:22 +02:00
|
|
|
bool updatePrinterConf(int templateIdx, QString fileToSendToDC);
|
2023-06-21 16:19:45 +02:00
|
|
|
bool updateConf(QString fileToSendToDC);
|
|
|
|
bool updateCashConf(QString fileToSendToDC);
|
2023-05-26 13:03:38 +02:00
|
|
|
bool finishUpdate(bool finish);
|
2023-06-20 16:13:11 +02:00
|
|
|
QStringList getLinesToWorkOn();
|
2023-05-30 16:44:55 +02:00
|
|
|
QStringList split(QString line, QChar sep = ',');
|
2023-05-26 13:03:38 +02:00
|
|
|
|
|
|
|
bool execUpdateScript();
|
2023-06-16 16:51:30 +02:00
|
|
|
|
2023-05-26 13:03:38 +02:00
|
|
|
public:
|
2023-06-16 16:51:30 +02:00
|
|
|
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
|
2023-06-19 16:00:22 +02:00
|
|
|
enum class FileTypeJson {CONFIG=1, DEVICE, CASH, SERIAL, TIME, PRINTER};
|
2023-06-16 16:51:30 +02:00
|
|
|
|
|
|
|
static hwinf *loadDCPlugin(QDir const &plugInDir, QString const &fn);
|
|
|
|
|
|
|
|
|
|
|
|
explicit Update(hwinf *hw,
|
|
|
|
QString update_ctrl_file,
|
2023-05-26 13:03:38 +02:00
|
|
|
QString workingDir = ".",
|
2023-06-20 16:13:11 +02:00
|
|
|
bool maintenanceMode = 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();
|
|
|
|
|
2023-06-16 16:51:30 +02:00
|
|
|
private:
|
|
|
|
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 resetDeviceController() const;
|
|
|
|
QByteArray loadBinaryDCFile(QString filename) const;
|
|
|
|
bool downloadBinaryToDC(QString const &bFile) const;
|
2023-06-21 16:19:45 +02:00
|
|
|
bool updateDC(QString bFile) const;
|
2023-06-19 16:00:22 +02:00
|
|
|
bool updatePrinterTemplate(enum FileTypeJson type, int templateIdx,
|
2023-06-21 16:19:45 +02:00
|
|
|
QString fname) const;
|
2023-05-26 13:03:38 +02:00
|
|
|
};
|
|
|
|
#endif // UPDATE_H_INCLUDED
|