Add slots for catching output of underlying update_psa_script.
iSetting timeout to 200000 when in maintenance-mode.
This commit is contained in:
parent
58684cf3c4
commit
c34944af8b
46
update.cpp
46
update.cpp
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include <QSharedMemory>
|
#include <QSharedMemory>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QProcess>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@ -134,19 +133,26 @@ bool Update::execUpdateScript() {
|
|||||||
QScopedPointer<QProcess> p(new QProcess(this));
|
QScopedPointer<QProcess> p(new QProcess(this));
|
||||||
p->setProcessChannelMode(QProcess::MergedChannels);
|
p->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
|
||||||
|
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
|
||||||
|
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
|
||||||
|
|
||||||
p->start(update_psa);
|
p->start(update_psa);
|
||||||
|
|
||||||
if (p->waitForStarted(1000)) {
|
if (p->waitForStarted(1000)) {
|
||||||
if (p->state() == QProcess::ProcessState::Running) {
|
if (p->state() == QProcess::ProcessState::Running) {
|
||||||
int const timeout = 200000; // sometimes signal strength of modem is quite low
|
// maintenance_mode: update_psa script enters an infinite loop
|
||||||
|
int const timeout = (m_maintenanceMode ? 200000: -1);
|
||||||
if (p->waitForFinished(timeout)) {
|
if (p->waitForFinished(timeout)) {
|
||||||
QString output = p->readAllStandardOutput().toStdString().c_str();
|
QString output = p->readAllStandardOutput().toStdString().c_str();
|
||||||
QStringList lst = output.split('\n');
|
QStringList lst = output.split('\n');
|
||||||
for (int i = 0; i < lst.size(); ++i) {
|
for (int i = 0; i < lst.size(); ++i) {
|
||||||
qDebug() << lst[i];
|
qDebug() << lst[i];
|
||||||
}
|
}
|
||||||
qInfo() << "EXECUTED" << update_psa;
|
if (p->exitStatus() == QProcess::NormalExit) {
|
||||||
return ((p->exitStatus() == QProcess::NormalExit)
|
qInfo() << "EXECUTED" << update_psa
|
||||||
&& (p->exitCode() == 0));
|
<< "with code" << p->exitCode();
|
||||||
|
return (p->exitCode() == 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "update-script TIMEDOUT after"
|
qCritical() << "update-script TIMEDOUT after"
|
||||||
<< timeout/1000 << "seconds";
|
<< timeout/1000 << "seconds";
|
||||||
@ -531,7 +537,26 @@ QStringList Update::split(QString line, QChar sep) {
|
|||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update::readyReadStandardOutput() {
|
||||||
|
QProcess *p = (QProcess *)sender();
|
||||||
|
QByteArray buf = p->readAllStandardOutput();
|
||||||
|
qCritical() << buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::readyReadStandardError() {
|
||||||
|
QProcess *p = (QProcess *)sender();
|
||||||
|
QByteArray buf = p->readAllStandardError();
|
||||||
|
qCritical() << buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
|
||||||
|
QProcess *p = (QProcess *)sender();
|
||||||
|
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardOutput()));
|
||||||
|
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
|
||||||
|
}
|
||||||
|
|
||||||
bool Update::doUpdate() {
|
bool Update::doUpdate() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The file referred to by 'update_data' has the following structure for
|
The file referred to by 'update_data' has the following structure for
|
||||||
each line:
|
each line:
|
||||||
@ -626,7 +651,7 @@ bool Update::doUpdate() {
|
|||||||
} else if (name.contains("DC2C_cash", Qt::CaseInsensitive)
|
} else if (name.contains("DC2C_cash", Qt::CaseInsensitive)
|
||||||
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
||||||
res = true;
|
res = true;
|
||||||
#if UPDATE_CASH_TEMPLATE
|
#if UPDATE_CASH_TEMPLATE == 1
|
||||||
if ((res = updateCashConf(name))) {
|
if ((res = updateCashConf(name))) {
|
||||||
qInfo() << "downloaded cash template"<< name;
|
qInfo() << "downloaded cash template"<< name;
|
||||||
}
|
}
|
||||||
@ -634,7 +659,7 @@ bool Update::doUpdate() {
|
|||||||
} else if (name.contains("DC2C_conf", Qt::CaseInsensitive)
|
} else if (name.contains("DC2C_conf", Qt::CaseInsensitive)
|
||||||
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
||||||
res = true;
|
res = true;
|
||||||
#if UPDATE_CONF_TEMPLATE
|
#if UPDATE_CONF_TEMPLATE == 1
|
||||||
if ((res= updateConfig(name))) {
|
if ((res= updateConfig(name))) {
|
||||||
qInfo() << "downloaded config template"<< name;
|
qInfo() << "downloaded config template"<< name;
|
||||||
}
|
}
|
||||||
@ -642,7 +667,7 @@ bool Update::doUpdate() {
|
|||||||
} else if (name.contains("DC2C_device", Qt::CaseInsensitive)
|
} else if (name.contains("DC2C_device", Qt::CaseInsensitive)
|
||||||
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
&& name.endsWith(".json", Qt::CaseInsensitive)) {
|
||||||
res = true;
|
res = true;
|
||||||
#if UPDATE_DEVICE_TEMPLATE
|
#if UPDATE_DEVICE_TEMPLATE == 1
|
||||||
if ((res = updateDeviceConf(name))) {
|
if ((res = updateDeviceConf(name))) {
|
||||||
qInfo() << "downloaded device template"<< name;
|
qInfo() << "downloaded device template"<< name;
|
||||||
}
|
}
|
||||||
@ -657,7 +682,12 @@ bool Update::doUpdate() {
|
|||||||
#if UPDATE_OPKG == 1
|
#if UPDATE_OPKG == 1
|
||||||
QScopedPointer<QProcess> p(new QProcess(this));
|
QScopedPointer<QProcess> p(new QProcess(this));
|
||||||
p->setProcessChannelMode(QProcess::MergedChannels);
|
p->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
|
||||||
|
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
|
||||||
|
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
|
||||||
|
|
||||||
p->start(name.trimmed());
|
p->start(name.trimmed());
|
||||||
|
|
||||||
if (p->waitForStarted(1000)) {
|
if (p->waitForStarted(1000)) {
|
||||||
if (p->state() == QProcess::ProcessState::Running) {
|
if (p->state() == QProcess::ProcessState::Running) {
|
||||||
if (p->waitForFinished(100000)) {
|
if (p->waitForFinished(100000)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user