2023-06-16 16:47:13 +02:00
|
|
|
#ifndef WORKER_H_INCLUDED
|
|
|
|
#define WORKER_H_INCLUDED
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2023-07-14 13:32:00 +02:00
|
|
|
#include <QStringList>
|
2023-06-16 16:47:13 +02:00
|
|
|
#include <QTimer>
|
2023-07-11 16:58:49 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QJsonObject>
|
2023-07-14 13:32:00 +02:00
|
|
|
#include <QHash>
|
2023-06-16 16:47:13 +02:00
|
|
|
|
|
|
|
#include "worker_thread.h"
|
2023-07-11 16:58:49 +02:00
|
|
|
#include "update.h"
|
|
|
|
#include "git/git_client.h"
|
|
|
|
#include "ismas/ismas_client.h"
|
|
|
|
#include "apism/apism_client.h"
|
2023-06-16 16:47:13 +02:00
|
|
|
|
2023-07-11 16:58:49 +02:00
|
|
|
#ifdef PTU5
|
|
|
|
#define SERIAL_PORT "ttymxc2"
|
|
|
|
#else
|
|
|
|
#define SERIAL_PORT "ttyUSB0"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2023-07-17 16:38:53 +02:00
|
|
|
enum class UPDATE_STATUS : quint8 {
|
|
|
|
ISMAS_EMULATE_DATA_AVAILABLE,
|
|
|
|
ISMAS_UPDATE_REQUEST_PENDING,
|
|
|
|
ISMAS_UPDATE_REQUEST_FAILURE,
|
|
|
|
ISMAS_UPDATE_REQUEST_TIMEOUT,
|
|
|
|
ISMAS_UPDATE_REQUEST_SUCCESS,
|
2023-07-19 16:35:48 +02:00
|
|
|
ISMAS_RESPONSE_RECEIVED,
|
2023-07-17 16:38:53 +02:00
|
|
|
GIT_CHECKOUT_BRANCH_REQUEST,
|
|
|
|
GIT_CHECKOUT_BRANCH_REQUEST_FAILURE,
|
|
|
|
GIT_CHECKOUT_BRANCH_NOT_EXISTS,
|
|
|
|
GIT_CHECKOUT_BRANCH_CHECKOUT_ERROR,
|
|
|
|
GIT_FETCH_UPDATES_REQUEST,
|
|
|
|
GIT_FETCH_UPDATES_REQUEST_FAILURE,
|
2023-07-19 16:35:48 +02:00
|
|
|
GIT_FETCH_UPDATES_REQUEST_SUCCESS,
|
|
|
|
GIT_PULL_UPDATES_SUCCESS,
|
|
|
|
GIT_PULL_UPDATES_FAILURE,
|
|
|
|
EXEC_OPKG_COMMANDS,
|
2023-07-17 16:38:53 +02:00
|
|
|
EXEC_OPKG_COMMAND_FAILURE,
|
|
|
|
EXEC_OPKG_COMMAND_SUCCESS,
|
|
|
|
EXEC_OPKG_COMMANDS_SUCCESS,
|
|
|
|
RSYNC_UPDATES,
|
|
|
|
RSYNC_UPDATES_FAILURE,
|
|
|
|
RSYNC_UPDATES_SUCESS,
|
|
|
|
DEVICE_CONTROLLER_UPDATE,
|
|
|
|
DEVICE_CONTROLLER_UPDATE_FAILURE,
|
|
|
|
DEVICE_CONTROLLER_UPDATE_SUCCESS,
|
|
|
|
JSON_UPDATE,
|
|
|
|
JSON_UPDATE_FAILURE,
|
|
|
|
JSON_UPDATE_SUCCESS,
|
|
|
|
ISMAS_UPDATE_INFO_CONFIRM,
|
|
|
|
ISMAS_UPDATE_INFO_CONFIRM_FAILURE,
|
|
|
|
ISMAS_UPDATE_INFO_CONFIRM_SUCCESS,
|
|
|
|
ISMAS_CURRENT_PSA_STATUS_CONFIRM,
|
|
|
|
ISMAS_CURRENT_PSA_STATUS_CONFIRM_FAILURE,
|
|
|
|
ISMAS_CURRENT_PSA_STATUS_CONFIRM_SUCCESS
|
|
|
|
};
|
|
|
|
|
2023-07-19 16:35:48 +02:00
|
|
|
struct UpdateStatus {
|
|
|
|
UPDATE_STATUS m_updateStatus;
|
|
|
|
QString m_statusDescription;
|
|
|
|
|
|
|
|
explicit UpdateStatus(UPDATE_STATUS s, QString const &d)
|
|
|
|
: m_updateStatus(s), m_statusDescription(d) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
QDebug operator<<(QDebug debug, UpdateStatus status);
|
|
|
|
QString& operator<<(QString &str, UpdateStatus status);
|
|
|
|
|
|
|
|
#define ISMAS_UPDATE_REQUESTS (10)
|
2023-07-17 16:38:53 +02:00
|
|
|
|
2023-07-11 16:58:49 +02:00
|
|
|
class hwinf;
|
2023-06-16 16:47:13 +02:00
|
|
|
class Worker : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2023-07-19 16:35:48 +02:00
|
|
|
hwinf *m_hw;
|
2023-06-16 16:47:13 +02:00
|
|
|
WorkerThread m_workerThread;
|
2023-07-14 13:32:00 +02:00
|
|
|
QTimer m_startUpdateProcess;
|
2023-07-19 16:35:48 +02:00
|
|
|
QTimer m_emergencyTimer;
|
2023-07-11 16:58:49 +02:00
|
|
|
Update *m_update;
|
|
|
|
ApismClient m_apismClient;
|
2023-07-17 16:38:53 +02:00
|
|
|
int const m_customerNr;
|
|
|
|
QString const m_customerNrStr;
|
|
|
|
int const m_machineNr;
|
|
|
|
int const m_zoneNr;
|
2023-07-14 13:32:00 +02:00
|
|
|
QString const m_workingDirectory;
|
|
|
|
QString const m_branchName;
|
2023-07-19 16:35:48 +02:00
|
|
|
QString const m_customerRepositoryPath;
|
2023-07-14 13:32:00 +02:00
|
|
|
QString const m_customerRepository;
|
2023-07-17 16:38:53 +02:00
|
|
|
GitClient m_gc;
|
2023-07-14 13:32:00 +02:00
|
|
|
bool m_maintenanceMode;
|
2023-07-17 16:38:53 +02:00
|
|
|
QString const m_osVersion;
|
2023-07-19 16:35:48 +02:00
|
|
|
QString const m_atbqtVersion;
|
|
|
|
QString const m_cpuSerial;
|
|
|
|
QString const m_raucVersion;
|
|
|
|
QString const m_opkgVersion;
|
|
|
|
QString const m_pluginVersionATBDeciceController;
|
|
|
|
QString const m_pluginVersionIngenicoISelf;
|
|
|
|
QString const m_pluginVersionMobilisisCalc;
|
|
|
|
QString const m_pluginVersionMobilisisCalcConfig;
|
|
|
|
QString const m_pluginVersionPrmCalc;
|
|
|
|
QString const m_pluginVersionPrmCalcConfig;
|
|
|
|
QString const m_pluginVersionTcpZvt;
|
|
|
|
|
2023-07-14 13:32:00 +02:00
|
|
|
int m_ismasUpdateRequests;
|
|
|
|
QTimer m_waitForNewUpdates;
|
|
|
|
IsmasClient m_ismasClient;
|
|
|
|
|
2023-07-17 16:38:53 +02:00
|
|
|
UPDATE_STATUS m_updateStatus;
|
|
|
|
QString m_statusDescription;
|
2023-07-14 13:32:00 +02:00
|
|
|
|
2023-07-17 16:38:53 +02:00
|
|
|
void executeOpkgCommand(QString opkgCommand);
|
|
|
|
QString getOsVersion() const;
|
2023-07-19 16:35:48 +02:00
|
|
|
QString getATBQTVersion() const;
|
|
|
|
QString getCPUSerial() const;
|
|
|
|
QString getRaucVersion() const;
|
|
|
|
QString getOpkgVersion() const;
|
|
|
|
QString getPluginVersion(QString const &pluginFileName) const;
|
|
|
|
QStringList getDCVersion() const;
|
|
|
|
|
|
|
|
qint64 getFileSize(QString const &fileName) const;
|
2023-07-11 16:58:49 +02:00
|
|
|
|
2023-06-16 16:47:13 +02:00
|
|
|
public:
|
2023-07-11 16:58:49 +02:00
|
|
|
explicit Worker(hwinf *hw,
|
2023-07-17 16:38:53 +02:00
|
|
|
int customerNr, // 281
|
|
|
|
int machineNr,
|
|
|
|
int zoneNr,
|
2023-07-14 13:32:00 +02:00
|
|
|
QString branchName,
|
2023-07-11 16:58:49 +02:00
|
|
|
QString workingDir = ".",
|
|
|
|
bool maintenanceMode = false,
|
|
|
|
bool dryRun = false,
|
|
|
|
QObject *parent = nullptr,
|
|
|
|
char const *serialInterface = SERIAL_PORT,
|
|
|
|
char const *baudrate = "115200");
|
2023-06-16 16:47:13 +02:00
|
|
|
~Worker();
|
|
|
|
void quit() { return m_workerThread.quit(); }
|
|
|
|
|
2023-07-17 16:38:53 +02:00
|
|
|
static int read1stLineOfFile(QString fileName);
|
|
|
|
|
2023-07-19 16:35:48 +02:00
|
|
|
//friend QDebug operator<<(QDebug debug, Worker const &w) {
|
|
|
|
// Q_UNUSED(w);
|
|
|
|
// return debug;
|
|
|
|
//}
|
|
|
|
//friend QString& operator<<(QString &str, Worker const &w) {
|
|
|
|
// Q_UNUSED(w);
|
|
|
|
// return str;
|
|
|
|
//}
|
|
|
|
|
2023-06-16 16:47:13 +02:00
|
|
|
signals:
|
2023-07-14 13:32:00 +02:00
|
|
|
void handleChangedFiles(QStringList);
|
|
|
|
void summarizeUpload(QStringList);
|
|
|
|
void summarizeRepositoryStatus();
|
|
|
|
void sendCmdSendVersionToIsmas();
|
|
|
|
void finishUpdateProcess(bool changes);
|
|
|
|
void terminateUpdateProcess();
|
2023-06-16 16:47:13 +02:00
|
|
|
|
|
|
|
public slots:
|
2023-07-11 16:58:49 +02:00
|
|
|
void onIsmasResponseReceived(QJsonObject ismasResponse);
|
|
|
|
|
|
|
|
private slots:
|
2023-07-14 13:32:00 +02:00
|
|
|
void askIsmasForNewData();
|
|
|
|
void onSendCmdSendVersionToIsmas();
|
|
|
|
void onSummarizeRepositoryStatus();
|
|
|
|
void onFinishUpdateProcess(bool changes);
|
|
|
|
void onTerminateUpdateProcess();
|
|
|
|
void onSummarizeUpload(QStringList);
|
|
|
|
void onHandleChangedFiles(QStringList);
|
2023-06-16 16:47:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // WORKER_H_INCLUDED
|