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