Compare commits

...

5 Commits

2 changed files with 109 additions and 35 deletions

View File

@ -12,7 +12,6 @@
#include <QSharedMemory>
#include <QScopedPointer>
#include <QProcess>
#include <QDir>
#include <QThread>
#include <QDateTime>
@ -134,19 +133,26 @@ bool Update::execUpdateScript() {
QScopedPointer<QProcess> p(new QProcess(this));
p->setProcessChannelMode(QProcess::MergedChannels);
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
p->start(update_psa);
if (p->waitForStarted(1000)) {
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)) {
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));
if (p->exitStatus() == QProcess::NormalExit) {
qInfo() << "EXECUTED" << update_psa
<< "with code" << p->exitCode();
return (p->exitCode() == 0);
}
} else {
qCritical() << "update-script TIMEDOUT after"
<< timeout/1000 << "seconds";
@ -329,16 +335,11 @@ void Update::closeSerial() const {
bool Update::resetDeviceController() const {
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();
// wait maximally 3 seconds, before starting bootloader
QThread::msleep(1500);
qInfo() << "resetting device controller...OK";
return true;
//}
//qCritical() << "stopping bootloader...FAILED";
//return false;
}
QByteArray Update::loadBinaryDCFile(QString filename) const {
@ -375,6 +376,38 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
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) {
qInfo() << "updating device controller binary" << fileToSendToDC;
QFile fn(fileToSendToDC);
@ -531,7 +564,26 @@ QStringList Update::split(QString line, QChar sep) {
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() {
/*
The file referred to by 'update_data' has the following structure for
each line:
@ -553,22 +605,7 @@ bool Update::doUpdate() {
return 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";
bool serialOpened = false;
QStringList linesToWorkOn = getLinesToWorkOn();
if (linesToWorkOn.size() == 0) {
@ -599,6 +636,26 @@ bool Update::doUpdate() {
// QString const &result = lst[COLUMN_RESULT];
qDebug() << "request=" << request << ", name=" << name;
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) &&
name.endsWith(".bin", Qt::CaseInsensitive)) {
qInfo() << "downloading" << name.trimmed() << "to DC";
@ -626,7 +683,7 @@ bool Update::doUpdate() {
} else if (name.contains("DC2C_cash", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_CASH_TEMPLATE
#if UPDATE_CASH_TEMPLATE == 1
if ((res = updateCashConf(name))) {
qInfo() << "downloaded cash template"<< name;
}
@ -634,7 +691,7 @@ bool Update::doUpdate() {
} else if (name.contains("DC2C_conf", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_CONF_TEMPLATE
#if UPDATE_CONF_TEMPLATE == 1
if ((res= updateConfig(name))) {
qInfo() << "downloaded config template"<< name;
}
@ -642,7 +699,7 @@ bool Update::doUpdate() {
} else if (name.contains("DC2C_device", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_DEVICE_TEMPLATE
#if UPDATE_DEVICE_TEMPLATE == 1
if ((res = updateDeviceConf(name))) {
qInfo() << "downloaded device template"<< name;
}
@ -657,7 +714,12 @@ bool Update::doUpdate() {
#if UPDATE_OPKG == 1
QScopedPointer<QProcess> p(new QProcess(this));
p->setProcessChannelMode(QProcess::MergedChannels);
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
p->start(name.trimmed());
if (p->waitForStarted(1000)) {
if (p->state() == QProcess::ProcessState::Running) {
if (p->waitForFinished(100000)) {
@ -693,14 +755,19 @@ bool Update::doUpdate() {
20, 20, QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(),
10, 10, (res == true) ? "SUCCESS" : "ERROR");
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) {
closeSerial();
m_hw->dc_autoRequest(true);
qDebug() << "SET AUTO-REQUEST=TRUE";
qInfo() << "current dc-hardware-version" << m_hw->dc_getHWversion();
qInfo() << "current dc-firmware-version" << m_hw->dc_getSWversion();
if (serialOpened) {
m_hw->dc_autoRequest(true);
qDebug() << "SET AUTO-REQUEST=TRUE";
qInfo() << "current dc-hardware-version" << m_hw->dc_getHWversion();
qInfo() << "current dc-firmware-version" << m_hw->dc_getSWversion();
closeSerial();
serialOpened = false;
}
return finishUpdate(linesToWorkOn.size() > 0);
}

View File

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