Using ismas-client it sends requests to APISM and gets results in a synchronous fashion. Add previous emits to git client and apism client have been removed.
200 lines
5.5 KiB
C++
200 lines
5.5 KiB
C++
#ifndef WORKER_H_INCLUDED
|
|
#define WORKER_H_INCLUDED
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QTimer>
|
|
#include <QFile>
|
|
#include <QJsonObject>
|
|
#include <QHash>
|
|
|
|
#include "worker_thread.h"
|
|
#include "update.h"
|
|
#include "git/git_client.h"
|
|
#include "ismas/ismas_client.h"
|
|
|
|
#ifdef PTU5
|
|
#define SERIAL_PORT "ttymxc2"
|
|
#else
|
|
#define SERIAL_PORT "ttyUSB0"
|
|
#endif
|
|
|
|
|
|
enum class UPDATE_STATUS : quint8 {
|
|
NOT_DEFINED,
|
|
STEP_OK,
|
|
STEP_DONE,
|
|
STEP_FAIL,
|
|
ISMAS_WAIT_STATE_CHECK_PENDING,
|
|
ISMAS_WAIT_STATE_CHECK_FAILURE,
|
|
ISMAS_WAIT_STATE_CHECK_TIMEOUT,
|
|
ISMAS_WAIT_STATE_CHECK_SUCCESS,
|
|
ISMAS_RESPONSE_RECEIVED,
|
|
BACKEND_CONNECTED,
|
|
BACKEND_NOT_CONNECTED,
|
|
UPDATE_TRIGGER_SET,
|
|
UPDATE_TRIGGER_NOT_SET_OR_WRONG,
|
|
GIT_CLONE_AND_CHECKOUT_SUCCESS,
|
|
GIT_CLONE_AND_CHECKOUT_FAILURE,
|
|
GIT_CHECKOUT_BRANCH,
|
|
GIT_CHECKOUT_BRANCH_REQUEST_FAILURE,
|
|
GIT_CHECKOUT_BRANCH_NOT_EXISTS,
|
|
GIT_CHECKOUT_BRANCH_CHECKOUT_ERROR,
|
|
GIT_FETCH_UPDATES,
|
|
GIT_FETCH_UPDATES_REQUEST_FAILURE,
|
|
GIT_FETCH_UPDATES_REQUEST_SUCCESS,
|
|
GIT_PULL_UPDATES_SUCCESS,
|
|
GIT_PULL_UPDATES_FAILURE,
|
|
EXEC_OPKG_COMMAND,
|
|
EXEC_OPKG_COMMANDS,
|
|
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,
|
|
UPDATE_PROCESS_SUCCESS,
|
|
UPDATE_PROCESS_FAILURE,
|
|
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
|
|
};
|
|
|
|
struct UpdateStatus {
|
|
UPDATE_STATUS m_updateStatus;
|
|
QString m_statusDescription;
|
|
|
|
explicit UpdateStatus(UPDATE_STATUS s = UPDATE_STATUS::NOT_DEFINED,
|
|
QString const &d = QString(""))
|
|
: m_updateStatus(s), m_statusDescription(d) {}
|
|
};
|
|
|
|
QDebug operator<<(QDebug debug, UpdateStatus status);
|
|
QString& operator<<(QString &str, UpdateStatus status);
|
|
|
|
#define ISMAS_UPDATE_REQUESTS (10)
|
|
|
|
class hwinf;
|
|
class Worker : public QObject {
|
|
Q_OBJECT
|
|
|
|
hwinf *m_hw;
|
|
WorkerThread m_workerThread;
|
|
int const m_customerNr;
|
|
QString const m_customerNrStr;
|
|
int const m_machineNr;
|
|
int const m_zoneNr;
|
|
QString const m_workingDirectory;
|
|
QString const m_branchName;
|
|
QString const m_customerRepositoryPath;
|
|
QString const m_customerRepository;
|
|
Update *m_update;
|
|
IsmasClient m_ismasClient;
|
|
GitClient m_gc;
|
|
QString const m_osVersion;
|
|
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;
|
|
|
|
int m_ismasUpdateRequests;
|
|
QTimer m_waitForNewUpdates;
|
|
|
|
UpdateStatus m_updateStatus;
|
|
|
|
QStringList m_filesToUpdate;
|
|
bool m_updateProcessRunning;
|
|
int m_displayIndex;
|
|
|
|
bool executeOpkgCommand(QString opkgCommand);
|
|
QString getOsVersion() const;
|
|
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;
|
|
|
|
public:
|
|
static const QString UPDATE_STEP_OK;
|
|
static const QString UPDATE_STEP_DONE;
|
|
static const QString UPDATE_STEP_FAIL;
|
|
static const QString UPDATE_STEP_SUCCESS;
|
|
|
|
explicit Worker(hwinf *hw,
|
|
int customerNr, // 281
|
|
int machineNr,
|
|
int zoneNr,
|
|
QString branchName,
|
|
QString workingDir = ".",
|
|
bool dryRun = false,
|
|
QObject *parent = nullptr,
|
|
char const *serialInterface = SERIAL_PORT,
|
|
char const *baudrate = "115200");
|
|
~Worker();
|
|
|
|
IsmasClient &getIsmasClient() { return m_ismasClient; }
|
|
IsmasClient const &getIsmasClient() const { return m_ismasClient; }
|
|
|
|
bool updateProcessRunning() const { return m_updateProcessRunning; }
|
|
|
|
int machineNr() const { return m_machineNr; }
|
|
int customerNr() const { return m_customerNr; }
|
|
int zoneNr() const { return m_zoneNr; }
|
|
|
|
//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;
|
|
//}
|
|
|
|
signals:
|
|
void appendText(QString, QString);
|
|
void showErrorMessage(QString title, QString description);
|
|
void setProgress(quint8);
|
|
void stopStartTimer();
|
|
void restartExitTimer();
|
|
|
|
public slots:
|
|
void update();
|
|
|
|
private slots:
|
|
bool backendConnected();
|
|
bool updateTriggerSet();
|
|
bool customerEnvironment();
|
|
bool filesToUpdate();
|
|
bool updateFiles(quint8 percent);
|
|
bool syncCustomerRepositoryAndFS();
|
|
bool sendIsmasLastVersionNotification();
|
|
bool saveLogFile();
|
|
|
|
private:
|
|
PSAInstalled getPSAInstalled();
|
|
QString sendCmdSendVersionToIsmas();
|
|
void privateUpdate();
|
|
};
|
|
|
|
#endif // WORKER_H_INCLUDED
|