Compare commits

..

No commits in common. "528b74549a7dc9019018413c6220fd5fbd62f385" and "08122cf7035edd609f7dd4e8bb7f97c78e38919a" have entirely different histories.

2 changed files with 35 additions and 109 deletions

View File

@ -12,6 +12,7 @@
#include <QSharedMemory> #include <QSharedMemory>
#include <QScopedPointer> #include <QScopedPointer>
#include <QProcess>
#include <QDir> #include <QDir>
#include <QThread> #include <QThread>
#include <QDateTime> #include <QDateTime>
@ -133,26 +134,19 @@ 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) {
// maintenance_mode: update_psa script enters an infinite loop int const timeout = 200000; // sometimes signal strength of modem is quite low
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];
} }
if (p->exitStatus() == QProcess::NormalExit) { qInfo() << "EXECUTED" << update_psa;
qInfo() << "EXECUTED" << update_psa return ((p->exitStatus() == QProcess::NormalExit)
<< "with code" << p->exitCode(); && (p->exitCode() == 0));
return (p->exitCode() == 0);
}
} else { } else {
qCritical() << "update-script TIMEDOUT after" qCritical() << "update-script TIMEDOUT after"
<< timeout/1000 << "seconds"; << timeout/1000 << "seconds";
@ -335,11 +329,16 @@ void Update::closeSerial() const {
bool Update::resetDeviceController() const { bool Update::resetDeviceController() const {
qDebug() << "resetting device controller..."; qDebug() << "resetting device controller...";
//if (stopBootloader()) { // first stop a (maybe) running bootloader
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
m_hw->bl_rebootDC(); m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader // wait maximally 3 seconds, before starting bootloader
QThread::msleep(1500); QThread::msleep(1500);
qInfo() << "resetting device controller...OK"; qInfo() << "resetting device controller...OK";
return true; return true;
//}
//qCritical() << "stopping bootloader...FAILED";
//return false;
} }
QByteArray Update::loadBinaryDCFile(QString filename) const { QByteArray Update::loadBinaryDCFile(QString filename) const {
@ -376,38 +375,6 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
return true; return true;
} }
/*
Using the DC bootloader:
1 : bl_reboot() // send to application, want DC2 to reset (in order to start
// the bootloader)
2 : bl_startBL(): // send within 4s after DC poewer-on, otherwise bl is left
3 : bl_check(): // send command to verify if bl is up
4 : bl_isUp(): // returns true if bl is up and running
5 : bl_sendAddress(blockNumber)
// send start address, nr of 64-byte block, start with 0
// will be sent only for following block-numbers:
// 0, 1024, 2048, 3072 and 4096, so basically every 64kByte
// for other addresses nothing happens
6 : bl_wasSendingAddOK()
// return val: 0: no response by now
// 1: error
// 10: OK
7 : bl_sendDataBlock()
// send 64 byte from bin file
8 : bl_sendLastBlock()
// send this command after all data are transferred
9 : bl_wasSendingDataOK()
// return val: 0: no response by now
// 1: error
// 10: OK
10 : bl_stopBL() // leave bl and start (the new) application
*/
bool Update::updateBinary(char const *fileToSendToDC) { bool Update::updateBinary(char const *fileToSendToDC) {
qInfo() << "updating device controller binary" << fileToSendToDC; qInfo() << "updating device controller binary" << fileToSendToDC;
QFile fn(fileToSendToDC); QFile fn(fileToSendToDC);
@ -564,26 +531,7 @@ 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:
@ -605,7 +553,22 @@ bool Update::doUpdate() {
return false; return false;
} }
bool serialOpened = false; if (!openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) {
qCritical() << "CANNOT OPEN" << m_serialInterface << "(BAUDRATE="
<< m_baudrate << ")";
return false;
}
QString fwVersion = m_hw->dc_getSWversion();
QString const hwVersion = m_hw->dc_getHWversion();
qInfo() << "current dc-hardware-version" << hwVersion;
qInfo() << "current dc-firmware-version" << fwVersion;
m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(3); // wait to be sure that there are no more
// commands sent to dc-hardware
qDebug() << "SET AUTO-REQUEST=FALSE";
QStringList linesToWorkOn = getLinesToWorkOn(); QStringList linesToWorkOn = getLinesToWorkOn();
if (linesToWorkOn.size() == 0) { if (linesToWorkOn.size() == 0) {
@ -636,26 +599,6 @@ bool Update::doUpdate() {
// QString const &result = lst[COLUMN_RESULT]; // QString const &result = lst[COLUMN_RESULT];
qDebug() << "request=" << request << ", name=" << name; qDebug() << "request=" << request << ", name=" << name;
if (request.trimmed() == "DOWNLOAD") { if (request.trimmed() == "DOWNLOAD") {
if (!serialOpened) { // open serial code once
if (!openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) {
qCritical() << "CANNOT OPEN" << m_serialInterface << "(BAUDRATE="
<< m_baudrate << ")";
return false;
}
serialOpened = true;
QString fwVersion = m_hw->dc_getSWversion();
QString const hwVersion = m_hw->dc_getHWversion();
qInfo() << "current dc-hardware-version" << hwVersion;
qInfo() << "current dc-firmware-version" << fwVersion;
m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(3); // wait to be sure that there are no more
// commands sent to dc-hardware
qDebug() << "SET AUTO-REQUEST=FALSE";
}
if (name.contains("dc2c", Qt::CaseInsensitive) && if (name.contains("dc2c", Qt::CaseInsensitive) &&
name.endsWith(".bin", Qt::CaseInsensitive)) { name.endsWith(".bin", Qt::CaseInsensitive)) {
qInfo() << "downloading" << name.trimmed() << "to DC"; qInfo() << "downloading" << name.trimmed() << "to DC";
@ -683,7 +626,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 == 1 #if UPDATE_CASH_TEMPLATE
if ((res = updateCashConf(name))) { if ((res = updateCashConf(name))) {
qInfo() << "downloaded cash template"<< name; qInfo() << "downloaded cash template"<< name;
} }
@ -691,7 +634,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 == 1 #if UPDATE_CONF_TEMPLATE
if ((res= updateConfig(name))) { if ((res= updateConfig(name))) {
qInfo() << "downloaded config template"<< name; qInfo() << "downloaded config template"<< name;
} }
@ -699,7 +642,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 == 1 #if UPDATE_DEVICE_TEMPLATE
if ((res = updateDeviceConf(name))) { if ((res = updateDeviceConf(name))) {
qInfo() << "downloaded device template"<< name; qInfo() << "downloaded device template"<< name;
} }
@ -714,12 +657,7 @@ 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)) {
@ -755,19 +693,14 @@ bool Update::doUpdate() {
20, 20, QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), 20, 20, QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(),
10, 10, (res == true) ? "SUCCESS" : "ERROR"); 10, 10, (res == true) ? "SUCCESS" : "ERROR");
m_update_ctrl_file_copy.write(buf); m_update_ctrl_file_copy.write(buf);
qInfo() << "write" << buf << "into file" << m_update_ctrl_file_copy;
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) { } // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
if (serialOpened) { closeSerial();
m_hw->dc_autoRequest(true); m_hw->dc_autoRequest(true);
qDebug() << "SET AUTO-REQUEST=TRUE"; qDebug() << "SET AUTO-REQUEST=TRUE";
qInfo() << "current dc-hardware-version" << m_hw->dc_getHWversion();
qInfo() << "current dc-firmware-version" << m_hw->dc_getSWversion(); qInfo() << "current dc-hardware-version" << m_hw->dc_getHWversion();
closeSerial(); qInfo() << "current dc-firmware-version" << m_hw->dc_getSWversion();
serialOpened = false;
}
return finishUpdate(linesToWorkOn.size() > 0); return finishUpdate(linesToWorkOn.size() > 0);
} }

View File

@ -6,7 +6,6 @@
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QByteArray> #include <QByteArray>
#include <QProcess>
#include "plugins/interfaces.h" #include "plugins/interfaces.h"
@ -80,11 +79,5 @@ private:
bool updateDeviceConf(QString jsFileToSendToDC); bool updateDeviceConf(QString jsFileToSendToDC);
bool downloadJson(enum FileTypeJson type, int templateIdx, bool downloadJson(enum FileTypeJson type, int templateIdx,
QString jsFileToSendToDC) const; QString jsFileToSendToDC) const;
private slots:
void readyReadStandardOutput();
void readyReadStandardError();
void finished(int exitCode, QProcess::ExitStatus exitStatus);
}; };
#endif // UPDATE_H_INCLUDED #endif // UPDATE_H_INCLUDED