Compare commits

...

13 Commits

Author SHA1 Message Date
a3aef7594e Minor: add comment 2024-05-14 12:52:09 +02:00
afbcccf785 Minor: add comment about index shift: 4 -> 5 2024-05-14 12:51:32 +02:00
90e4e21391 System::getJsonFilesOnUsbStick(): return list of JSON files for configured
directory under mount path.
2024-05-14 12:49:28 +02:00
4536284f34 getUSBMountPath(): check for directory 'dirPathUnderMountPath' under mount path. 2024-05-14 12:48:19 +02:00
a3a4c09c7f checkForUSBStick(): look for etc/psa_config in mountpath-directory. 2024-05-14 12:46:38 +02:00
a5dd9af29a Add System::allowedJsonFiles to name default JSON file names. 2024-05-14 12:45:43 +02:00
5124e1cca6 Use return value of type std::optional<QString> for
checkForUSBStick() and getUSBMountPath().
Add getJsonFilesOnUsbStick().
2024-05-14 12:43:46 +02:00
fc75585de3 Parse psa-config-directory and psa-tariff-directory. 2024-05-14 12:40:32 +02:00
1964b08349 doUpdate(): use parameter 'usbStickDetected' to use the correct JSON
filenames.
2024-05-14 12:38:31 +02:00
c0d014644c Update (conf) JSON-Files using USB stick. When plugged in, look for
JSON-files in directory psa-config-directory and load them to the PSA.
Note: these files are overwritten during a usual ISMAS-update if not
checked in into the customer repository.
2024-05-14 12:35:18 +02:00
b24c50c572 Parse psa-config-directory and psa-tariff-directory settings. 2024-05-14 12:33:40 +02:00
bbdadc9063 Include psa_config_directory and psa_tariff_directory settings. 2024-05-14 12:32:26 +02:00
dc7f839d3f Include ATBUpdateTool.ini 2024-05-14 12:31:19 +02:00
11 changed files with 196 additions and 44 deletions

View File

@ -4,6 +4,9 @@ repository-url="https://git.mimbach49.de/GerhardHoffmann"
[DIRECTORIES]
plugin-directory="/usr/lib/"
working-directory="/opt/app/tools/atbupdate/"
psa-config-directory="etc/psa_config/"
psa-tariff-directory="etc/psa_tariff/"
[PLUGINS]
plugin-name="libCAslave.so"

View File

@ -90,7 +90,8 @@ HEADERS += \
../common/include/System.h
OTHER_FILES += \
ATBDownloadDCJsonFiles.ini
ATBDownloadDCJsonFiles.ini \
../ATBUpdateTool.ini
##########################################################################################

View File

@ -15,6 +15,7 @@
#include "commandline_parser.h"
#include "utils.h"
#include "update.h"
#include "System.h"
#include <DeviceController/interfaces.h>
@ -68,6 +69,8 @@ int main(int argc, char **argv) {
QString plugInDir = parser.plugInDir();
QString plugInName = parser.plugInName();
QString workingDir = parser.workingDir();
QString psaConfigDir = parser.psaConfigDir();
QString psaTariffDir = parser.psaTariffDir();
QString iniFileName = parser.iniFileName();
bool const dryRun = parser.dryRun();
bool const noUpdatePsaHardware = parser.noUpdatePsaHardware();
@ -90,6 +93,8 @@ int main(int argc, char **argv) {
qInfo() << "plugInDir ................" << plugInDir;
qInfo() << "plugInName ..............." << plugInName;
qInfo() << "workingDir ..............." << workingDir;
qInfo() << "psaConfigDir ............." << psaConfigDir;
qInfo() << "psaTariffDir ............." << psaTariffDir;
qInfo() << "dryRun ..................." << dryRun;
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
@ -108,15 +113,17 @@ int main(int argc, char **argv) {
return 0;
}
QString const customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
qCritical() << "Using customer repository" << customerRepo;
// always execute contents of opkg_commands-file
QString const &customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
QStringList filesToUpdate;
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config"));
// etc/psa_config: located under mount-path
std::optional<QString> mountPath = System::checkForUSBStick(psaConfigDir);
if (mountPath.has_value()) {
filesToUpdate = System::getJsonFilesOnUsbStick(mountPath.value());
} else {
qCritical() << "Using customer repository" << customerRepo;
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config"));
if (dir.exists()) {
QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files);
if (!jsons.isEmpty()) {
@ -128,8 +135,9 @@ int main(int argc, char **argv) {
qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
return -1;
}
}
qCritical() << "JSON FILES TO UPDATE" << filesToUpdate;
// qCritical() << "JSON FILES TO UPDATE" << filesToUpdate;
Update update(customerRepo,
QString::number(customerNr),
@ -138,10 +146,13 @@ int main(int argc, char **argv) {
plugInName,
workingDir);
//update.checkJsonVersions();
update.doUpdate(filesToUpdate);
update.checkJsonVersions(filesToUpdate);
update.doUpdate(filesToUpdate, mountPath.has_value());
update.checkJsonVersions();
//update.checkJsonVersions(filesToUpdate);
if (mountPath.has_value()) {
System::umountUSBStick();
}
//return a.exec();
return 0;
}

View File

@ -138,10 +138,11 @@ Update::~Update() {
unloadDCPlugin();
}
bool Update::doUpdate(QStringList const &filesToWorkOn) {
bool Update::doUpdate(QStringList const &filesToWorkOn, bool usbStickDetected) {
if (!m_hw) {
qCritical() << "ERROR!!! m_hw == nullptr";
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
<< "ERROR!!! m_hw == nullptr";
return false;
}
@ -149,10 +150,12 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
// must deliver 'true', only then are all data from hwapi valid
if (--tries < 0) {
qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED";
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED";
return false;
}
qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED (" << tries << ")";
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED (" << tries << ")";
m_hw->dc_autoRequest(true);
QThread::msleep(500);
}
@ -161,7 +164,8 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
QList<QString>::const_iterator it;
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
QString const &fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed());
QString const &fToWorkOn = usbStickDetected ? QDir::cleanPath(it->trimmed())
: QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed());
if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive)
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
@ -203,6 +207,25 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
}
bool Update::checkJsonVersions(QStringList const& jsonFileNames) {
if (!m_hw) {
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
<< "ERROR!!! m_hw == nullptr";
return false;
}
int tries = 20;
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
// must deliver 'true', only then are all data from hwapi valid
if (--tries < 0) {
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED";
return false;
}
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED (" << tries << ")";
m_hw->dc_autoRequest(true);
QThread::msleep(500);
}
for (QStringList::size_type i=0; i < jsonFileNames.size(); ++i) {
@ -231,6 +254,7 @@ bool Update::checkJsonVersions(QStringList const& jsonFileNames) {
bool ok = false;
int n = captured.toInt(&ok);
if (ok) {
// note: use 5 (instead of 4 -> index has been shifted)
jsonNr = n + 5;
}
}

View File

@ -58,7 +58,7 @@ public:
virtual ~Update() override;
bool doUpdate(QStringList const &jsonFilesToDownload);
bool doUpdate(QStringList const &jsonFilesToDownload, bool usbStickDetected = false);
bool updatePrinterTemplate(int templateIdx, QString fname) const;
bool updateConfig(QString jsFileToSendToDC);

View File

@ -60,6 +60,16 @@ CommandLineParser::CommandLineParser()
QStringList() << "working-directory" << "working-directory",
QCoreApplication::translate("main", "working directory of update-script."),
QCoreApplication::translate("main", "directory")))
, m_psaConfigDirectoryOption(
QCommandLineOption(
QStringList() << "psa-config-directory" << "psa-config-directory",
QCoreApplication::translate("main", "config directory of json-files sent to dc."),
QCoreApplication::translate("main", "directory")))
, m_psaTariffDirectoryOption(
QCommandLineOption(
QStringList() << "psa-tariff-directory" << "psa-tariff-directory",
QCoreApplication::translate("main", "tariff directory of tariff-json-files."),
QCoreApplication::translate("main", "directory")))
, m_dryRunOption(
QCommandLineOption(
QStringList() << "d" << "dry-run",
@ -111,6 +121,12 @@ void CommandLineParser::configure() {
m_workingDirectoryOption.setDefaultValue("/opt/app/tools/atbupdate/");
m_parser.addOption(m_workingDirectoryOption);
m_psaConfigDirectoryOption.setDefaultValue("etc/psa_config/");
m_parser.addOption(m_psaConfigDirectoryOption);
m_psaTariffDirectoryOption.setDefaultValue("etc/psa_tariff/");
m_parser.addOption(m_psaTariffDirectoryOption);
m_dryRunOption.setDefaultValue("false");
m_parser.addOption(m_dryRunOption);
@ -151,6 +167,12 @@ void CommandLineParser::readSettings() {
if (key.contains("working-directory")) {
m_workingDir = v.toString();
} else
if (key.contains("psa-config-directory")) {
m_psaConfigDir = v.toString();
} else
if (key.contains("psa-tariff-directory")) {
m_psaTariffDir = v.toString();
} else
if (key.contains("dry-run")) {
m_dryRun = (v.toBool() ? "true" : "false");
} else
@ -207,6 +229,20 @@ QString CommandLineParser::plugInName() {
return m_plugInName;
}
QString CommandLineParser::psaConfigDir() {
if (m_parser.isSet(m_psaConfigDirectoryOption)) {
m_psaConfigDir = m_parser.value(m_psaConfigDirectoryOption);
}
return m_psaConfigDir;
}
QString CommandLineParser::psaTariffDir() {
if (m_parser.isSet(m_psaTariffDirectoryOption)) {
m_psaTariffDir = m_parser.value(m_psaTariffDirectoryOption);
}
return m_psaTariffDir;
}
QString CommandLineParser::workingDir() {
if (m_parser.isSet(m_workingDirectoryOption)) {
m_workingDir = m_parser.value(m_workingDirectoryOption);

View File

@ -11,6 +11,8 @@ class CommandLineParser : public QCommandLineParser {
QString m_plugInDir;
QString m_plugInName;
QString m_workingDir;
QString m_psaConfigDir;
QString m_psaTariffDir;
QString m_dryRun;
QString m_noUpdatePsaHardware;
QString m_showYoctoVersion;
@ -29,6 +31,8 @@ class CommandLineParser : public QCommandLineParser {
QCommandLineOption m_alwaysDownloadConfigOption;
QCommandLineOption m_alwaysDownloadDCOption;
QCommandLineOption m_workingDirectoryOption;
QCommandLineOption m_psaConfigDirectoryOption;
QCommandLineOption m_psaTariffDirectoryOption;
QCommandLineOption m_dryRunOption;
QCommandLineOption m_extendedVersionOption;
QCommandLineOption m_yoctoVersionOption;
@ -52,6 +56,8 @@ public:
QString plugInDir();
QString plugInName();
QString workingDir();
QString psaConfigDir();
QString psaTariffDir();
bool dryRun();
bool noUpdatePsaHardware();
bool yoctoVersion();

View File

@ -651,6 +651,7 @@ bool Update::checkDownloadedJsonVersions(QStringList const& jsonFileNames) {
bool ok = false;
int n = captured.toInt(&ok);
if (ok) {
// note: the '5' is correct
jsonNr = n + 5;
}
}

View File

@ -869,6 +869,7 @@ bool Worker::execOpkgCommands() {
QStringList opkgErrorLst;
while (!in.atEnd()) {
QString line = in.readLine();
// TODO: "^\\s*[#]{0,}$" : empty line or comment line starting with #
static const QRegularExpression comment("^\\s*#.*$");
if (line.indexOf(comment, 0) == -1) {
// found opkg command

View File

@ -3,6 +3,10 @@
#include <QObject>
#include <QStringList>
#include <optional>
#include <initializer_list>
class System : public QObject
{
@ -13,16 +17,17 @@ private:
static QString errorMsg;
public:
static const QStringList allowedJsonFiles;
static bool checkForSDCard();
static bool umountSDCard();
static bool checkForUSBStick();
static QString getUSBMountPath();
static QString getUSBDeviceName();
static std::optional<QString> checkForUSBStick(QString const &dirPathUnderMountPath = ".");
static QString getUSBMountPath(QString const &dirPathUnderMountPath = ".");
//static QString getUSBDeviceName();
static bool umountUSBStick();
static bool test_mount(const QString& dev, const QString &mountpoint);
@ -48,7 +53,7 @@ public:
static QString getPTU4SerialNumber();
static QString getPTU4MACAddress();
static QStringList getJsonFilesOnUsbStick(QString const &mountPath);
};

View File

@ -7,10 +7,52 @@
#include <QRegExp>
#include <QStringList>
#include <QDebug>
#include <QDirIterator>
//#include "version.h"
const QStringList System::allowedJsonFiles =
std::initializer_list<QString>{
QString("DC2C_conf.json"),
QString("DC2C_cash.json"),
QString("DC2C_device.json"),
QString("DC2C_print01.json"),
QString("DC2C_print02.json"),
QString("DC2C_print03.json"),
QString("DC2C_print04.json"),
QString("DC2C_print05.json"),
QString("DC2C_print06.json"),
QString("DC2C_print07.json"),
QString("DC2C_print08.json"),
QString("DC2C_print09.json"),
QString("DC2C_print10.json"),
QString("DC2C_print11.json"),
QString("DC2C_print12.json"),
QString("DC2C_print13.json"),
QString("DC2C_print14.json"),
QString("DC2C_print15.json"),
QString("DC2C_print16.json"),
QString("DC2C_print17.json"),
QString("DC2C_print18.json"),
QString("DC2C_print19.json"),
QString("DC2C_print20.json"),
QString("DC2C_print21.json"),
QString("DC2C_print22.json"),
QString("DC2C_print23.json"),
QString("DC2C_print24.json"),
QString("DC2C_print25.json"),
QString("DC2C_print26.json"),
QString("DC2C_print27.json"),
QString("DC2C_print28.json"),
QString("DC2C_print29.json"),
QString("DC2C_print30.json"),
QString("DC2C_print31.json"),
QString("DC2C_print32.json")
};
QString System::errorMsg = "";
System::System(QObject *parent) :
@ -209,8 +251,7 @@ bool System::test_dir(const QString& dir)
bool System::checkForUSBStick()
{
std::optional<QString> System::checkForUSBStick(QString const &dirPathUnderMountPath) {
#if defined (ARCH_DesktopLinux)
// DEBUG / TEST:
if (QFileInfo(getUSBMountPath()).isDir())
@ -219,11 +260,9 @@ bool System::checkForUSBStick()
return false;
#endif
if (getUSBMountPath().isEmpty()) {
return false;
}
return true;
QString const &mountPath = getUSBMountPath(dirPathUnderMountPath);
// qCritical() << "MOUNT-PATH" << mountPath;
return mountPath.isEmpty() ? std::nullopt : std::optional<QString>(mountPath);
}
@ -235,8 +274,7 @@ bool System::checkForUSBStick()
* Note, do not return an empty string ("") here because a calling method (which could not be
* identified till now) is relying on this!
*/
QString System::getUSBMountPath()
{
QString System::getUSBMountPath(QString const &dirPathUnderMountPath) {
#if defined (ARCH_DesktopLinux)
// DEBUG / TEST:
@ -277,8 +315,13 @@ QString System::getUSBMountPath()
mountLine = line.split(' ');
if (mountLine.size() > 3) {
qDebug() << "System::getUSBMountPath(): " << mountLine.at(0) << " is mounted on " << mountLine.at(2);
qCritical() << "System::getUSBMountPath(): " << mountLine.at(0) << " is mounted on " << mountLine.at(2);
QDir d(QDir::cleanPath(mountLine.at(2) + QDir::separator() + dirPathUnderMountPath));
if (d.exists()) {
return mountLine.at(2);
} else {
qCritical() << "directory" << d.absolutePath() << "does not exist";
}
}
}
}
@ -289,6 +332,27 @@ QString System::getUSBMountPath()
return "";
}
QStringList System::getJsonFilesOnUsbStick(QString const &mountPath) {
QStringList jsonFiles;
// /media/sda2/etc/psa_config
QString const &dirPath = QDir::cleanPath(mountPath + QDir::separator() + "etc" + QDir::separator() + "psa_config");
QDir d(dirPath);
if (d.exists()) {
QDirIterator it(dirPath, QStringList() << "*.json", QDir::Files, QDirIterator::NoIteratorFlags);
while (it.hasNext()) {
QString const &jsonFile = it.next();
QFileInfo fi(jsonFile);
if (System::allowedJsonFiles.contains(fi.fileName())) {
jsonFiles << jsonFile;
} else {
qCritical() << "Warning:" << fi.fileName() << "unknown";
}
}
}
return jsonFiles;
}
/********************************************************************************
* static function to check if a mounted sd-card is writable.