192 lines
6.3 KiB
C++
192 lines
6.3 KiB
C++
|
|
#include <QtGlobal>
|
|
#include <QCoreApplication>
|
|
#include <QByteArray>
|
|
|
|
#include <QProcess>
|
|
#include <QStandardPaths>
|
|
#include <QSettings>
|
|
#include <QDir>
|
|
#include <QDebug>
|
|
#include <QThread>
|
|
#include <QRegularExpression>
|
|
|
|
#include "message_handler.h"
|
|
#include "commandline_parser.h"
|
|
#include "utils.h"
|
|
#include "utils_internal.h"
|
|
#include "update.h"
|
|
#include "System.h"
|
|
|
|
#include <DeviceController/interfaces.h>
|
|
|
|
#ifdef __linux__
|
|
#include <sys/sysinfo.h>
|
|
#endif
|
|
|
|
#ifdef PTU5
|
|
#define SERIAL_PORT "ttymxc2"
|
|
#else
|
|
#define SERIAL_PORT "ttyUSB0"
|
|
#endif
|
|
|
|
int read1stLineOfFile(QString fileName) {
|
|
QFile f(fileName);
|
|
if (f.exists()) {
|
|
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream in(&f);
|
|
in.setCodec("UTF-8");
|
|
while(!in.atEnd()) {
|
|
return in.readLine().toInt();
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
QByteArray const value = qgetenv("LC_ALL");
|
|
if (value != "C") {
|
|
qputenv("LC_ALL", "C");
|
|
}
|
|
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
|
|
|
|
openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER);
|
|
|
|
QCoreApplication a(argc, argv);
|
|
QCoreApplication::setOrganizationName("ATB Automatentechnik Baumann GmBH");
|
|
QCoreApplication::setApplicationName("ATBUpdateDC");
|
|
QCoreApplication::setApplicationVersion(APP_VERSION);
|
|
|
|
|
|
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
|
|
atbInstallMessageHandler(atbDebugOutput);
|
|
setDebugLevel(LOG_NOTICE);
|
|
}
|
|
|
|
/*
|
|
CommandLineParser parser;
|
|
parser.process(a);
|
|
parser.readSettings();
|
|
|
|
QString repositoryUrl = parser.repositoryUrl();
|
|
QString plugInDir = parser.plugInDir();
|
|
QString plugInName = parser.plugInName();
|
|
QString workingDir = parser.workingDir();
|
|
QString psaConfigDir = parser.psaConfigDir();
|
|
QString psaTariffDir = parser.psaTariffDir();
|
|
QString psaDcDir = parser.dcDir();
|
|
QString iniFileName = parser.iniFileName();
|
|
bool const dryRun = parser.dryRun();
|
|
bool const noUpdatePsaHardware = parser.noUpdatePsaHardware();
|
|
bool const showYoctoVersion = parser.yoctoVersion();
|
|
bool const showYoctoInstallStatus = parser.yoctoInstallStatus();
|
|
bool const showExtendedVersion = parser.extendedVersion();
|
|
bool const alwaysDownloadConfig = parser.alwaysDownloadConfig();
|
|
bool const alwaysDownloadDC = parser.alwaysDownloadDC();
|
|
bool const readDCVersion = parser.readDCVersion();
|
|
|
|
QString const rtPath = QCoreApplication::applicationDirPath();
|
|
|
|
int const machineNr = read1stLineOfFile("/mnt/system_data/machine_nr");
|
|
int const customerNr = read1stLineOfFile("/mnt/system_data/cust_nr");
|
|
int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
|
|
QString const branchName = (zoneNr != 0)
|
|
? QString("zg1/zone%1").arg(zoneNr) : "master";
|
|
|
|
qInfo() << "pwd ......................" << rtPath;
|
|
qInfo() << "repositoryUrl ............" << repositoryUrl;
|
|
qInfo() << "plugInDir ................" << plugInDir;
|
|
qInfo() << "plugInName ..............." << plugInName;
|
|
qInfo() << "workingDir ..............." << workingDir;
|
|
qInfo() << "psaConfigDir ............." << psaConfigDir;
|
|
qInfo() << "psaTariffDir ............." << psaTariffDir;
|
|
qInfo() << "dryRun ..................." << dryRun;
|
|
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
|
|
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
|
|
qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
|
|
qInfo() << "showYoctoVersion ........." << showYoctoVersion;
|
|
qInfo() << "showYoctoInstallStatus ..." << showYoctoInstallStatus;
|
|
qInfo() << "showExtendedVersion ......" << showExtendedVersion;
|
|
qInfo() << "iniFileName .............." << iniFileName;
|
|
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
|
|
qInfo() << "machineNr ................" << machineNr;
|
|
qInfo() << "customerNr ..............." << customerNr;
|
|
qInfo() << "zoneNr ..................." << zoneNr;
|
|
qInfo() << "readDCVersion ............" << readDCVersion;
|
|
qInfo() << "dcDir ...................." << psaDcDir;
|
|
|
|
if (!QDir(plugInDir).exists()) {
|
|
qCritical() << plugInDir
|
|
<< "does not exists, but has to contain dc-library";
|
|
exit(-1);
|
|
}
|
|
|
|
if (showExtendedVersion) {
|
|
printf(APP_EXTENDED_VERSION"\n");
|
|
return 0;
|
|
}
|
|
*/
|
|
|
|
bool debug = false;
|
|
bool noaction = true;
|
|
QString libDir;
|
|
QString libca;
|
|
QString workingDir;
|
|
|
|
std::unique_ptr<QSettings> settings = internal::readSettings();
|
|
|
|
if (settings) {
|
|
settings->beginGroup("DIRECTORIES");
|
|
workingDir = settings->value("workingdir", "/tmp").toString();
|
|
libDir = settings->value("plugin-directory", "/usr/lib/").toString();
|
|
settings->endGroup();
|
|
|
|
settings->beginGroup("FLAGS");
|
|
debug = settings->value("debug", false).toBool();
|
|
settings->endGroup();
|
|
|
|
settings->beginGroup("PLUGINS");
|
|
libca = libDir + settings->value("plugin-name", "libCAslave.so").toString();
|
|
settings->endGroup();
|
|
}
|
|
|
|
QFileInfo fi;
|
|
|
|
// ------------------- single command line argument is DC-firmware binary file -----------------
|
|
QStringList args = a.arguments();
|
|
if (args.size() != 2) {
|
|
qCritical() << "ERROR: missing parameter <dc-firmware>";
|
|
exit(1);
|
|
}
|
|
|
|
qCritical() << "------------------------------------------------------";
|
|
qCritical() << "main: argument dc-firmware: " << args.at(1);
|
|
qCritical() << "------------------------------------------------------";
|
|
|
|
fi.setFile(args.at(1));
|
|
|
|
if (!fi.isFile()) {
|
|
qCritical() << "ERROR: parameter " << fi.absoluteFilePath() << " is not a file";
|
|
exit(1);
|
|
}
|
|
|
|
if (!fi.isReadable()) {
|
|
qCritical() << "ERROR: parameter " << fi.absoluteFilePath() << " is not readable";
|
|
exit(1);
|
|
}
|
|
|
|
qCritical() << "------------------------------------------------------";
|
|
qCritical() << "uploading dc-firmware" << fi.absoluteFilePath();
|
|
qCritical() << "dc-firmware size (bytes)" << fi.size();
|
|
qCritical() << "dc-version" << Update::dcVersion(fi.absoluteFilePath());
|
|
qCritical() << "------------------------------------------------------";
|
|
|
|
Update u(fi.absoluteFilePath(), libca, debug, noaction);
|
|
u.run();
|
|
|
|
qInfo() << "<DC-UPDATE-FINISH>";
|
|
|
|
return 0;
|
|
}
|