Added maintenance-mode parameter. Activated handling of opkg-commands.

This commit is contained in:
Gerhard Hoffmann 2023-06-20 16:14:13 +02:00
parent 88013e82f0
commit e79d6c6fef

View File

@ -72,6 +72,7 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
Update::Update(hwinf *hw, Update::Update(hwinf *hw,
QString update_ctrl_file, QString update_ctrl_file,
QString workingDir, QString workingDir,
bool maintenanceMode,
QObject *parent, QObject *parent,
char const *serialInterface, char const *serialInterface,
char const *baudrate) char const *baudrate)
@ -82,6 +83,7 @@ Update::Update(hwinf *hw,
, m_update_ctrl_file(update_ctrl_file) , m_update_ctrl_file(update_ctrl_file)
, m_update_ctrl_file_copy(update_ctrl_file + ".copy") , m_update_ctrl_file_copy(update_ctrl_file + ".copy")
, m_workingDir(workingDir) , m_workingDir(workingDir)
, m_maintenanceMode(maintenanceMode)
, m_init(true) { , m_init(true) {
execUpdateScript(); execUpdateScript();
@ -113,20 +115,14 @@ Update::~Update() {
bool Update::execUpdateScript() { bool Update::execUpdateScript() {
// path of update-script 'update_psa' // path of update-script 'update_psa'
QString update_psa("/opt/app/tools/atbupdate/update_psa -m --wdir "); QString update_psa("/opt/app/tools/atbupdate/update_psa ");
if (m_maintenanceMode) {
update_psa += " -m ";
}
update_psa += " --wdir ";
update_psa += m_workingDir; update_psa += m_workingDir;
qCritical() << "update_psa: " << update_psa; qCritical() << "update_psa: " << update_psa;
//QApplication::processEvents();
//for (int i=0;i<10;++i) {
// QThread::sleep(1);
//QApplication::processEvents();
//}
// debug
return true;
//QStringList const params(QStringList() << "-c" << update_psa);
QScopedPointer<QProcess> p(new QProcess(this)); QScopedPointer<QProcess> p(new QProcess(this));
p->setProcessChannelMode(QProcess::MergedChannels); p->setProcessChannelMode(QProcess::MergedChannels);
@ -367,6 +363,8 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
} }
bool Update::updateBinary(char const *fileToSendToDC) { bool Update::updateBinary(char const *fileToSendToDC) {
return true;
// TODO
QFile fn(fileToSendToDC); QFile fn(fileToSendToDC);
bool r; bool r;
if ((r = fn.exists()) == true) { if ((r = fn.exists()) == true) {
@ -436,6 +434,9 @@ bool Update::updatePrinterTemplate(enum FileTypeJson type,
return false; return false;
} }
qDebug() << "updating: " << fname << br << serial << "..."; qDebug() << "updating: " << fname << br << serial << "...";
return true;
if (!serial.isNull()) { if (!serial.isNull()) {
if (!openSerial(baudrateMap.value(br), br, serial)) { if (!openSerial(baudrateMap.value(br), br, serial)) {
return false; return false;
@ -475,6 +476,8 @@ bool Update::updatePrinterTemplate(enum FileTypeJson type,
} }
bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) { bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) {
return true;
// TODO
qCritical() << "updating printer template: " << fileToSendToDC; qCritical() << "updating printer template: " << fileToSendToDC;
return updatePrinterTemplate(FileTypeJson::PRINTER, return updatePrinterTemplate(FileTypeJson::PRINTER,
templateIdx, templateIdx,
@ -483,8 +486,8 @@ bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) {
QString(m_serialInterface)); QString(m_serialInterface));
} }
QStringList Update::getOpenLines() { QStringList Update::getLinesToWorkOn() {
QStringList openLines; QStringList linesToWorkOn;
QTextStream in(&m_update_ctrl_file); QTextStream in(&m_update_ctrl_file);
while (!in.atEnd()) { while (!in.atEnd()) {
@ -493,10 +496,10 @@ QStringList Update::getOpenLines() {
m_update_ctrl_file_copy.write(line.toUtf8().constData()); m_update_ctrl_file_copy.write(line.toUtf8().constData());
m_update_ctrl_file_copy.write("\n"); m_update_ctrl_file_copy.write("\n");
} else { } else {
openLines << line; linesToWorkOn << line;
} }
} }
return openLines; return linesToWorkOn;
} }
QStringList Update::split(QString line, QChar sep) { QStringList Update::split(QString line, QChar sep) {
@ -533,24 +536,23 @@ bool Update::doUpdate() {
# #
*/ */
if (!m_init) { if (!m_init) {
return false; return false;
} }
QStringList openLines = getOpenLines(); QStringList linesToWorkOn = getLinesToWorkOn();
if (openLines.size() == 0) { if (linesToWorkOn.size() == 0) {
qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName(); qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName();
return false; return true;
} }
qDebug() << "open lines..."; qDebug() << "open lines...";
for (int i=0; i< openLines.size(); ++i) { for (int i=0; i< linesToWorkOn.size(); ++i) {
qDebug() << "line" << i << ":" << openLines.at(i).trimmed(); qDebug() << "line" << i << ":" << linesToWorkOn.at(i).trimmed();
} }
QList<QString>::const_iterator it; QList<QString>::const_iterator it;
for (it = openLines.cbegin(); it != openLines.cend(); ++it) { for (it = linesToWorkOn.cbegin(); it != linesToWorkOn.cend(); ++it) {
bool res = false; bool res = false;
QString line = (*it).trimmed(); QString line = (*it).trimmed();
if (line.size() == 0 || line.startsWith(QChar('#'))) { if (line.size() == 0 || line.startsWith(QChar('#'))) {
@ -564,19 +566,15 @@ bool Update::doUpdate() {
QString const &request = lst[COLUMN_REQUEST]; QString const &request = lst[COLUMN_REQUEST];
QString const &name = lst[COLUMN_NAME]; QString const &name = lst[COLUMN_NAME];
// QString const &datetime = lst[COLUMN_DATE_TIME]; // QString const &datetime = lst[COLUMN_DATE_TIME];
QString const &result = lst[COLUMN_RESULT]; // QString const &result = lst[COLUMN_RESULT];
if ((!request.contains("DOWNLOAD") && !request.contains("EXECUTE")) || qDebug() << "request=" << request << ", name=" << name;
!result.contains("N/A")) { if (request.trimmed() == "DOWNLOAD") {
qCritical() << "parsing error for" << m_update_ctrl_file.fileName();
return false;
}
if (name.contains("dc2c") && name.endsWith(".bin")) { if (name.contains("dc2c") && name.endsWith(".bin")) {
qInfo() << "downloading" << name.trimmed() << "to DC"; qInfo() << "downloading" << name.trimmed() << "to DC";
if ((res = updateBinary(name.toStdString().c_str())) == true) { if ((res = updateBinary(name.toStdString().c_str())) == true) {
qInfo() << "downloaded binary" << name; qInfo() << "downloaded binary" << name;
} }
} else } else if (name.contains("DC2C_print") && name.endsWith(".json")) {
if (name.contains("DC2C_print") && name.endsWith(".json")) {
int i = name.indexOf("DC2C_print"); int i = name.indexOf("DC2C_print");
int templateIdx = name.mid(i).midRef(10, 2).toInt(); int templateIdx = name.mid(i).midRef(10, 2).toInt();
if ((templateIdx < 1) || (templateIdx > 32)) { if ((templateIdx < 1) || (templateIdx > 32)) {
@ -587,8 +585,10 @@ bool Update::doUpdate() {
qInfo() << "downloaded printer template" << name; qInfo() << "downloaded printer template" << name;
} }
} }
} else } else {
if (name.contains("opkg")) { // TODO
}
} else if (request == "EXECUTE" && name.contains("opkg")) {
qInfo() << "starting" << name.trimmed(); qInfo() << "starting" << name.trimmed();
QScopedPointer<QProcess> p(new QProcess(this)); QScopedPointer<QProcess> p(new QProcess(this));
p->setProcessChannelMode(QProcess::MergedChannels); p->setProcessChannelMode(QProcess::MergedChannels);
@ -601,27 +601,36 @@ bool Update::doUpdate() {
for (int line=0; line < outputLst.size(); ++line) { for (int line=0; line < outputLst.size(); ++line) {
qDebug() << outputLst[line]; qDebug() << outputLst[line];
} }
if (p->exitStatus() == QProcess::NormalExit) {
qInfo() << "EXECUTED" << name
<< "with code" << p->exitCode();
res = true; res = true;
qInfo() << "EXECUTED" << name; } else {
qCritical() << "PROCESS" << name << "CRASHED";
} }
} else {
qCritical() << "PROCESS" << name << "DID NOT FINISH";
} }
} else {
qCritical() << "WRONG PROCESS STATE" << p->state();
}
} else {
qCritical() << "PROCESS" << name << "TIMEOUT AT START";
} }
} else { } else {
// TODO // TODO
} }
char buf[80]; char buf[128];
memset(buf, 0x00, sizeof(buf));
int const bytesWritten = int const bytesWritten =
snprintf(buf, sizeof(buf)-1, "DONE, %*.*s, %*.*s, %*.*s\n", snprintf(buf, sizeof(buf)-1, "DONE, %*.*s, %*.*s, %*.*s\n",
35, 35, name.toStdString().c_str(), 35, 35, name.toStdString().c_str(),
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");
if (bytesWritten < 80) {
buf[bytesWritten] = '\0';
}
m_update_ctrl_file_copy.write(buf); m_update_ctrl_file_copy.write(buf);
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) { } // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
return finishUpdate(openLines.size() > 0); return finishUpdate(linesToWorkOn.size() > 0);
} }
bool Update::finishUpdate(bool swapCtrlFiles) { bool Update::finishUpdate(bool swapCtrlFiles) {