diff --git a/update.cpp b/update.cpp index ea6f086..4a0428f 100644 --- a/update.cpp +++ b/update.cpp @@ -72,6 +72,7 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) { Update::Update(hwinf *hw, QString update_ctrl_file, QString workingDir, + bool maintenanceMode, QObject *parent, char const *serialInterface, char const *baudrate) @@ -82,6 +83,7 @@ Update::Update(hwinf *hw, , m_update_ctrl_file(update_ctrl_file) , m_update_ctrl_file_copy(update_ctrl_file + ".copy") , m_workingDir(workingDir) + , m_maintenanceMode(maintenanceMode) , m_init(true) { execUpdateScript(); @@ -113,20 +115,14 @@ Update::~Update() { bool Update::execUpdateScript() { // 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; 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 p(new QProcess(this)); p->setProcessChannelMode(QProcess::MergedChannels); @@ -367,6 +363,8 @@ bool Update::downloadBinaryToDC(QString const &bFile) const { } bool Update::updateBinary(char const *fileToSendToDC) { + return true; + // TODO QFile fn(fileToSendToDC); bool r; if ((r = fn.exists()) == true) { @@ -436,6 +434,9 @@ bool Update::updatePrinterTemplate(enum FileTypeJson type, return false; } qDebug() << "updating: " << fname << br << serial << "..."; + + return true; + if (!serial.isNull()) { if (!openSerial(baudrateMap.value(br), br, serial)) { return false; @@ -475,6 +476,8 @@ bool Update::updatePrinterTemplate(enum FileTypeJson type, } bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) { + return true; + // TODO qCritical() << "updating printer template: " << fileToSendToDC; return updatePrinterTemplate(FileTypeJson::PRINTER, templateIdx, @@ -483,8 +486,8 @@ bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) { QString(m_serialInterface)); } -QStringList Update::getOpenLines() { - QStringList openLines; +QStringList Update::getLinesToWorkOn() { + QStringList linesToWorkOn; QTextStream in(&m_update_ctrl_file); 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("\n"); } else { - openLines << line; + linesToWorkOn << line; } } - return openLines; + return linesToWorkOn; } QStringList Update::split(QString line, QChar sep) { @@ -533,24 +536,23 @@ bool Update::doUpdate() { # */ - if (!m_init) { return false; } - QStringList openLines = getOpenLines(); - if (openLines.size() == 0) { + QStringList linesToWorkOn = getLinesToWorkOn(); + if (linesToWorkOn.size() == 0) { qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName(); - return false; + return true; } qDebug() << "open lines..."; - for (int i=0; i< openLines.size(); ++i) { - qDebug() << "line" << i << ":" << openLines.at(i).trimmed(); + for (int i=0; i< linesToWorkOn.size(); ++i) { + qDebug() << "line" << i << ":" << linesToWorkOn.at(i).trimmed(); } QList::const_iterator it; - for (it = openLines.cbegin(); it != openLines.cend(); ++it) { + for (it = linesToWorkOn.cbegin(); it != linesToWorkOn.cend(); ++it) { bool res = false; QString line = (*it).trimmed(); if (line.size() == 0 || line.startsWith(QChar('#'))) { @@ -564,31 +566,29 @@ bool Update::doUpdate() { QString const &request = lst[COLUMN_REQUEST]; QString const &name = lst[COLUMN_NAME]; // QString const &datetime = lst[COLUMN_DATE_TIME]; - QString const &result = lst[COLUMN_RESULT]; - if ((!request.contains("DOWNLOAD") && !request.contains("EXECUTE")) || - !result.contains("N/A")) { - qCritical() << "parsing error for" << m_update_ctrl_file.fileName(); - return false; - } - if (name.contains("dc2c") && name.endsWith(".bin")) { - qInfo() << "downloading" << name.trimmed() << "to DC"; - if ((res = updateBinary(name.toStdString().c_str())) == true) { - qInfo() << "downloaded binary" << name; - } - } else - if (name.contains("DC2C_print") && name.endsWith(".json")) { - int i = name.indexOf("DC2C_print"); - int templateIdx = name.mid(i).midRef(10, 2).toInt(); - if ((templateIdx < 1) || (templateIdx > 32)) { - qCritical() << "wrong template index"; - res = false; - } else { - if ((res = updatePrinterConf(templateIdx, name)) == true) { - qInfo() << "downloaded printer template" << name; + // QString const &result = lst[COLUMN_RESULT]; + qDebug() << "request=" << request << ", name=" << name; + if (request.trimmed() == "DOWNLOAD") { + if (name.contains("dc2c") && name.endsWith(".bin")) { + qInfo() << "downloading" << name.trimmed() << "to DC"; + if ((res = updateBinary(name.toStdString().c_str())) == true) { + qInfo() << "downloaded binary" << name; } + } else if (name.contains("DC2C_print") && name.endsWith(".json")) { + int i = name.indexOf("DC2C_print"); + int templateIdx = name.mid(i).midRef(10, 2).toInt(); + if ((templateIdx < 1) || (templateIdx > 32)) { + qCritical() << "wrong template index"; + res = false; + } else { + if ((res = updatePrinterConf(templateIdx, name)) == true) { + qInfo() << "downloaded printer template" << name; + } + } + } else { + // TODO } - } else - if (name.contains("opkg")) { + } else if (request == "EXECUTE" && name.contains("opkg")) { qInfo() << "starting" << name.trimmed(); QScopedPointer p(new QProcess(this)); p->setProcessChannelMode(QProcess::MergedChannels); @@ -601,27 +601,36 @@ bool Update::doUpdate() { for (int line=0; line < outputLst.size(); ++line) { qDebug() << outputLst[line]; } - res = true; - qInfo() << "EXECUTED" << name; + if (p->exitStatus() == QProcess::NormalExit) { + qInfo() << "EXECUTED" << name + << "with code" << p->exitCode(); + res = true; + } 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 { // TODO } - char buf[80]; + char buf[128]; + memset(buf, 0x00, sizeof(buf)); int const bytesWritten = snprintf(buf, sizeof(buf)-1, "DONE, %*.*s, %*.*s, %*.*s\n", - 35, 35, name.toStdString().c_str(), - 20, 20, QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), - 10, 10, (res == true) ? "SUCCESS" : "ERROR"); - if (bytesWritten < 80) { - buf[bytesWritten] = '\0'; - } + 35, 35, name.toStdString().c_str(), + 20, 20, QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), + 10, 10, (res == true) ? "SUCCESS" : "ERROR"); m_update_ctrl_file_copy.write(buf); } // for (it = openLines.cbegin(); it != openLines.end(); ++it) { - return finishUpdate(openLines.size() > 0); + return finishUpdate(linesToWorkOn.size() > 0); } bool Update::finishUpdate(bool swapCtrlFiles) {