Compare commits
No commits in common. "e79d6c6fefdb46c531de7fd66c57c441e49ad32e" and "810b603d707d1b8ee46072fcc232f66b5c4b9bd5" have entirely different histories.
e79d6c6fef
...
810b603d70
@ -1,13 +1,13 @@
|
||||
# QT -= gui
|
||||
QT += core
|
||||
QT += widgets serialport
|
||||
# QT += network
|
||||
QT += network
|
||||
|
||||
TARGET = ATBUpdateTool
|
||||
|
||||
INCLUDEPATH += plugins
|
||||
|
||||
CONFIG += c++17 console
|
||||
CONFIG += c++17
|
||||
# CONFIG -= app_bundle
|
||||
|
||||
# DEFINES+=LinuxDesktop
|
||||
|
13
main.cpp
13
main.cpp
@ -35,10 +35,9 @@
|
||||
#endif
|
||||
|
||||
class hwinf;
|
||||
static void doWork(hwinf *hw, QString update_ctrl_file,
|
||||
QString workingDir, bool maintenanceMode) {
|
||||
static void doWork(hwinf *hw, QString update_ctrl_file, QString workingDir) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
Update update(hw, update_ctrl_file, workingDir, maintenanceMode);
|
||||
Update update(hw, update_ctrl_file, workingDir);
|
||||
update.doUpdate();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
QCoreApplication::quit();
|
||||
@ -88,16 +87,11 @@ int main(int argc, char *argv[]) {
|
||||
workingDirectoryOption.setDefaultValue(workingDirectoryDefault);
|
||||
parser.addOption(workingDirectoryOption);
|
||||
|
||||
QCommandLineOption maintenanceOption("m",
|
||||
QCoreApplication::translate("main", "Maintenance mode for underlying script"));
|
||||
parser.addOption(maintenanceOption);
|
||||
|
||||
// Process the actual command line arguments given by the user
|
||||
parser.process(a);
|
||||
QString plugInDir = parser.value(pluginDirectoryOption);
|
||||
QString plugInName = parser.value(pluginNameOption);
|
||||
QString workingDir = parser.value(workingDirectoryOption);
|
||||
bool maintenanceMode = parser.isSet(maintenanceOption);
|
||||
QString const rtPath = QCoreApplication::applicationDirPath();
|
||||
|
||||
if (plugInDir == pluginDefault) {
|
||||
@ -112,7 +106,6 @@ int main(int argc, char *argv[]) {
|
||||
qInfo() << "plugInDir" << "=" << plugInDir;
|
||||
qInfo() << "plugInName" << "=" << plugInName;
|
||||
qInfo() << "workingDir" << "=" << workingDir;
|
||||
qInfo() << "maintenanceMode" << "=" << maintenanceMode;
|
||||
|
||||
// before loading the library, delete all possible shared memory segments
|
||||
#if defined Q_OS_LINUX || defined Q_OS_UNIX
|
||||
@ -125,7 +118,7 @@ int main(int argc, char *argv[]) {
|
||||
hw->dc_autoRequest(false);
|
||||
|
||||
QString const update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
|
||||
std::thread t(doWork, hw, update_ctrl_file, workingDir, maintenanceMode);
|
||||
std::thread t(doWork, hw, update_ctrl_file, workingDir);
|
||||
|
||||
int ret = a.exec();
|
||||
t.join();
|
||||
|
121
update.cpp
121
update.cpp
@ -72,7 +72,6 @@ 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)
|
||||
@ -83,7 +82,6 @@ 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();
|
||||
@ -115,14 +113,20 @@ Update::~Update() {
|
||||
|
||||
bool Update::execUpdateScript() {
|
||||
// path of update-script 'update_psa'
|
||||
QString update_psa("/opt/app/tools/atbupdate/update_psa ");
|
||||
if (m_maintenanceMode) {
|
||||
update_psa += " -m ";
|
||||
}
|
||||
update_psa += " --wdir ";
|
||||
QString update_psa("/opt/app/tools/atbupdate/update_psa -m --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<QProcess> p(new QProcess(this));
|
||||
p->setProcessChannelMode(QProcess::MergedChannels);
|
||||
@ -363,8 +367,6 @@ 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) {
|
||||
@ -434,9 +436,6 @@ 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;
|
||||
@ -476,8 +475,6 @@ 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,
|
||||
@ -486,8 +483,8 @@ bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) {
|
||||
QString(m_serialInterface));
|
||||
}
|
||||
|
||||
QStringList Update::getLinesToWorkOn() {
|
||||
QStringList linesToWorkOn;
|
||||
QStringList Update::getOpenLines() {
|
||||
QStringList openLines;
|
||||
|
||||
QTextStream in(&m_update_ctrl_file);
|
||||
while (!in.atEnd()) {
|
||||
@ -496,10 +493,10 @@ QStringList Update::getLinesToWorkOn() {
|
||||
m_update_ctrl_file_copy.write(line.toUtf8().constData());
|
||||
m_update_ctrl_file_copy.write("\n");
|
||||
} else {
|
||||
linesToWorkOn << line;
|
||||
openLines << line;
|
||||
}
|
||||
}
|
||||
return linesToWorkOn;
|
||||
return openLines;
|
||||
}
|
||||
|
||||
QStringList Update::split(QString line, QChar sep) {
|
||||
@ -536,23 +533,24 @@ bool Update::doUpdate() {
|
||||
#
|
||||
*/
|
||||
|
||||
|
||||
if (!m_init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList linesToWorkOn = getLinesToWorkOn();
|
||||
if (linesToWorkOn.size() == 0) {
|
||||
QStringList openLines = getOpenLines();
|
||||
if (openLines.size() == 0) {
|
||||
qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName();
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "open lines...";
|
||||
for (int i=0; i< linesToWorkOn.size(); ++i) {
|
||||
qDebug() << "line" << i << ":" << linesToWorkOn.at(i).trimmed();
|
||||
for (int i=0; i< openLines.size(); ++i) {
|
||||
qDebug() << "line" << i << ":" << openLines.at(i).trimmed();
|
||||
}
|
||||
|
||||
QList<QString>::const_iterator it;
|
||||
for (it = linesToWorkOn.cbegin(); it != linesToWorkOn.cend(); ++it) {
|
||||
for (it = openLines.cbegin(); it != openLines.cend(); ++it) {
|
||||
bool res = false;
|
||||
QString line = (*it).trimmed();
|
||||
if (line.size() == 0 || line.startsWith(QChar('#'))) {
|
||||
@ -566,29 +564,31 @@ 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];
|
||||
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
|
||||
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 (request == "EXECUTE" && name.contains("opkg")) {
|
||||
} 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
|
||||
if (name.contains("opkg")) {
|
||||
qInfo() << "starting" << name.trimmed();
|
||||
QScopedPointer<QProcess> p(new QProcess(this));
|
||||
p->setProcessChannelMode(QProcess::MergedChannels);
|
||||
@ -601,36 +601,27 @@ bool Update::doUpdate() {
|
||||
for (int line=0; line < outputLst.size(); ++line) {
|
||||
qDebug() << outputLst[line];
|
||||
}
|
||||
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";
|
||||
res = true;
|
||||
qInfo() << "EXECUTED" << name;
|
||||
}
|
||||
} else {
|
||||
qCritical() << "WRONG PROCESS STATE" << p->state();
|
||||
}
|
||||
} else {
|
||||
qCritical() << "PROCESS" << name << "TIMEOUT AT START";
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
char buf[128];
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
char buf[80];
|
||||
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");
|
||||
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';
|
||||
}
|
||||
m_update_ctrl_file_copy.write(buf);
|
||||
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
|
||||
|
||||
return finishUpdate(linesToWorkOn.size() > 0);
|
||||
return finishUpdate(openLines.size() > 0);
|
||||
}
|
||||
|
||||
bool Update::finishUpdate(bool swapCtrlFiles) {
|
||||
|
4
update.h
4
update.h
@ -29,14 +29,13 @@ class Update : public QObject {
|
||||
QFile m_update_ctrl_file;
|
||||
QFile m_update_ctrl_file_copy;
|
||||
QString m_workingDir;
|
||||
bool m_maintenanceMode;
|
||||
|
||||
bool m_init;
|
||||
|
||||
bool updateBinary(char const *fileToSendToDC);
|
||||
bool updatePrinterConf(int templateIdx, QString fileToSendToDC);
|
||||
bool finishUpdate(bool finish);
|
||||
QStringList getLinesToWorkOn();
|
||||
QStringList getOpenLines();
|
||||
QStringList split(QString line, QChar sep = ',');
|
||||
|
||||
bool execUpdateScript();
|
||||
@ -51,7 +50,6 @@ public:
|
||||
explicit Update(hwinf *hw,
|
||||
QString update_ctrl_file,
|
||||
QString workingDir = ".",
|
||||
bool maintenanceMode = false,
|
||||
QObject *parent = nullptr,
|
||||
char const *serialInterface = SERIAL_PORT,
|
||||
char const *baudrate = "115200");
|
||||
|
Loading…
x
Reference in New Issue
Block a user