Add handling of update-script
This commit is contained in:
parent
71a6b82d58
commit
35d40e3b3c
34
update.cpp
34
update.cpp
@ -6,6 +6,7 @@
|
||||
#include <QTemporaryFile>
|
||||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "interfaces.h"
|
||||
#include "DCPlugin/include/hwapi.h"
|
||||
@ -13,6 +14,7 @@
|
||||
#include <QSharedMemory>
|
||||
#include <QScopedPointer>
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
|
||||
#define COLUMN_REQUEST (0)
|
||||
#define COLUMN_NAME (1)
|
||||
@ -26,6 +28,7 @@ void ScopedPointerCustomDeleter::cleanup(Update *update) {
|
||||
}
|
||||
|
||||
Update::Update(QString update_ctrl_file,
|
||||
QString workingDir,
|
||||
QObject *parent,
|
||||
hwinf *hw,
|
||||
char const *serialInterface,
|
||||
@ -36,9 +39,12 @@ Update::Update(QString update_ctrl_file,
|
||||
, m_baudrate(baudrate)
|
||||
, m_update_ctrl_file(update_ctrl_file)
|
||||
, m_update_ctrl_file_copy(update_ctrl_file + ".copy")
|
||||
, m_workingDir(workingDir)
|
||||
, m_init(true)
|
||||
, m_delete(hw == nullptr) {
|
||||
|
||||
execUpdateScript();
|
||||
|
||||
if (!m_update_ctrl_file.exists()) {
|
||||
qCritical() << "Update-file" << m_update_ctrl_file.fileName()
|
||||
<< "does not exist";
|
||||
@ -64,6 +70,34 @@ Update::Update(QString update_ctrl_file,
|
||||
Update::~Update() {
|
||||
}
|
||||
|
||||
bool Update::execUpdateScript() {
|
||||
// path of update-script 'update_psa'
|
||||
QString update_psa("/opt/app/tools/atbupdate/update_psa --wdir ");
|
||||
update_psa += m_workingDir;
|
||||
|
||||
//QStringList const params(QStringList() << "-c" << update_psa);
|
||||
|
||||
QScopedPointer<QProcess> p(new QProcess(this));
|
||||
p->setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
p->start(update_psa);
|
||||
if (p->waitForStarted(1000)) {
|
||||
if (p->state() == QProcess::ProcessState::Running) {
|
||||
if (p->waitForFinished(60000)) {
|
||||
QString output = p->readAllStandardOutput().toStdString().c_str();
|
||||
QStringList lst = output.split('\n');
|
||||
for (int i = 0; i < lst.size(); ++i) {
|
||||
qDebug() << lst[i];
|
||||
}
|
||||
qInfo() << "EXECUTED" << update_psa;
|
||||
return ((p->exitStatus() == QProcess::NormalExit)
|
||||
&& (p->exitCode() == 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Update::updateBinary(char const *fileToSendToDC) {
|
||||
return m_hw->dc_updateDC(fileToSendToDC, m_baudrate, m_serialInterface);
|
||||
}
|
||||
|
57
update.h
Normal file
57
update.h
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef UPDATE_H_INCLUDED
|
||||
#define UPDATE_H_INCLUDED
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
|
||||
#include "interfaces.h"
|
||||
#include "DCPlugin/include/hwapi.h"
|
||||
|
||||
#ifdef PTU5
|
||||
#define SERIAL_PORT "ttymxc2"
|
||||
#else
|
||||
#define SERIAL_PORT "ttyUSB0"
|
||||
#endif
|
||||
|
||||
class Update;
|
||||
struct ScopedPointerCustomDeleter {
|
||||
static void cleanup(Update *pointer);
|
||||
};
|
||||
|
||||
// TODO: check hardware compatibility
|
||||
// TODO: opkg commandos
|
||||
|
||||
class Update : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
QScopedPointer<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_init;
|
||||
|
||||
bool updateBinary(char const *fileToSendToDC);
|
||||
bool updatePrinterConf(int nrOfTemplate, char const *fileToSendToDC);
|
||||
bool finishUpdate(bool finish);
|
||||
QStringList getOpenLines();
|
||||
QStringList split(QString line);
|
||||
static constexpr QChar SEPARATOR = QChar(',');
|
||||
|
||||
bool execUpdateScript();
|
||||
public:
|
||||
explicit Update(QString update_ctrl_file,
|
||||
QString workingDir = ".",
|
||||
QObject *parent = nullptr,
|
||||
hwinf *hw = nullptr,
|
||||
char const *serialInterface = SERIAL_PORT,
|
||||
char const *baudrate = "115200");
|
||||
virtual ~Update() override;
|
||||
bool doUpdate();
|
||||
|
||||
bool const m_delete;
|
||||
};
|
||||
#endif // UPDATE_H_INCLUDED
|
Loading…
Reference in New Issue
Block a user