Compare commits

...

11 Commits

11 changed files with 115 additions and 80 deletions

View File

@ -1,5 +1,5 @@
[REPOSITORY_URL] [REPOSITORY_URL]
repository-url="gitea@ptu-config.atb-comm.de:ATB/" repository-url="gitea@ptu-config.atb-comm.de:ATB"
[DIRECTORIES] [DIRECTORIES]
plugin-directory="/usr/lib/" plugin-directory="/usr/lib/"
@ -19,3 +19,21 @@ yocto-version=false
yocto-install=false yocto-install=false
always-download-config=true always-download-config=true
always-download-dc=false always-download-dc=false
[ATBUpdateCheck]
[ATBUpdateDC]
debug=true
workingDir=/tmp
libca=/usr/lib/libCAslave.so
[ATBUpdateGit]
[ATBUpdateJsonFiles]
[ATBUpdateOpkg]
[ATBUpdateShow]
[ATBUpdateSync]

View File

@ -145,14 +145,11 @@ int main(int argc, char **argv) {
QString libca; QString libca;
std::unique_ptr<QSettings> settings = internal::readSettings(); std::unique_ptr<QSettings> settings = internal::readSettings();
if (settings) {
settings->beginGroup("COMMON");
debug = settings->value("debug", false).toBool();
settings->endGroup();
settings->beginGroup("RUNTIME"); if (settings) {
noaction = settings->value("noaction", true).toBool(); settings->beginGroup("ATBUpdateDC");
workingDir = settings->value("workingdir", "/tmp").toBool(); debug = settings->value("debug", false).toBool();
workingDir = settings->value("workingdir", "/tmp").toString();
libca = settings->value("libca", "/usr/lib/libCAslave.so").toString(); libca = settings->value("libca", "/usr/lib/libCAslave.so").toString();
settings->endGroup(); settings->endGroup();
} }

View File

@ -26,14 +26,12 @@
#include <QString> #include <QString>
#include <QSerialPort> #include <QSerialPort>
#include <QSerialPortInfo> #include <QSerialPortInfo>
#include <QSettings>
#define UPDATE_OPKG (1) #define UPDATE_OPKG (1)
#define UPDATE_DC (0) #define UPDATE_DC (0)
// TODO: dynamisch setzen
#define TEST_DC_DOWNLOAD (0) // 0/1
static const QMap<QString, int> baudrateMap = { static const QMap<QString, int> baudrateMap = {
{"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3}, {"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3},
{"57600" , 4}, {"115200" , 5} {"57600" , 4}, {"115200" , 5}
@ -135,15 +133,15 @@ Update::sendNextAddress(int bNum) const {
// qDebug() << "addr-block" << bNum << "..."; // qDebug() << "addr-block" << bNum << "...";
while (noAnswerCount <= 250) { while (noAnswerCount <= 250) {
#if TEST_DC_DOWNLOAD==0 DownloadResult res = DownloadResult::OK;
if (!m_debug) {
m_hw->bl_sendAddress(bNum); m_hw->bl_sendAddress(bNum);
QThread::msleep(10); //from 100ms to 20ms QThread::msleep(10); //from 100ms to 20ms
//################################################################################### //###################################################################################
DownloadResult const res = sendStatus(m_hw->bl_wasSendingAddOK()); res = sendStatus(m_hw->bl_wasSendingAddOK());
#else }
DownloadResult const res = DownloadResult::OK;
#endif
if (res != DownloadResult::NOP) { if (res != DownloadResult::NOP) {
if (res == DownloadResult::ERROR) { if (res == DownloadResult::ERROR) {
if (++errorCount >= 10) { if (++errorCount >= 10) {
@ -157,7 +155,7 @@ Update::sendNextAddress(int bNum) const {
} else { } else {
noAnswerCount += 1; // no answer by now noAnswerCount += 1; // no answer by now
} }
} } // while
// wait max. about 3 seconds // wait max. about 3 seconds
return DownloadResult::TIMEOUT; return DownloadResult::TIMEOUT;
} }
@ -190,13 +188,12 @@ Update::sendNextDataBlock(QByteArray const &binary, int bNum) const {
while (noAnswerCount <= 250) { while (noAnswerCount <= 250) {
#if TEST_DC_DOWNLOAD==0 DownloadResult res = DownloadResult::OK;
m_hw->bl_sendDataBlock(64, local);
DownloadResult const res = sendStatus(m_hw->bl_wasSendingDataOK()); if (!m_debug) {
#else m_hw->bl_sendDataBlock(64, local);
DownloadResult const res = DownloadResult::OK; res = sendStatus(m_hw->bl_wasSendingDataOK());
#endif }
if (res != DownloadResult::NOP) { if (res != DownloadResult::NOP) {
if (res == DownloadResult::ERROR) { if (res == DownloadResult::ERROR) {
@ -220,7 +217,7 @@ Update::sendNextDataBlock(QByteArray const &binary, int bNum) const {
bool Update::startBootloader() const { bool Update::startBootloader() const {
qDebug() << "starting bootloader..."; qDebug() << "starting bootloader...";
#if TEST_DC_DOWNLOAD==0 if (!m_debug) {
int nTry = 10; int nTry = 10;
while (--nTry >= 0) { while (--nTry >= 0) {
m_hw->bl_startBL(); m_hw->bl_startBL();
@ -236,18 +233,19 @@ bool Update::startBootloader() const {
} }
} }
qCritical() << "starting bootloader...FAILED"; qCritical() << "starting bootloader...FAILED";
#else return false;
} else {
QThread::msleep(1000); QThread::msleep(1000);
qInfo() << "starting bootloader...OK"; qInfo() << "starting bootloader...OK";
}
return true; return true;
#endif
return false;
} }
bool Update::stopBootloader() const { bool Update::stopBootloader() const {
qDebug() << "stopping bootloader..."; qDebug() << "stopping bootloader...";
#if TEST_DC_DOWNLOAD==0 if (!m_debug) {
int nTry = 5; int nTry = 5;
while (--nTry >= 0) { while (--nTry >= 0) {
m_hw->bl_stopBL(); m_hw->bl_stopBL();
@ -258,22 +256,22 @@ bool Update::stopBootloader() const {
} }
} }
qCritical() << "stopping bootloader...FAILED"; qCritical() << "stopping bootloader...FAILED";
return false;
#else // Test code } else {
QThread::msleep(1000); QThread::msleep(1000);
qInfo() << "stopping bootloader...OK"; qInfo() << "stopping bootloader...OK";
return true; }
#endif
return false; return true;
} }
bool Update::resetDeviceController() const { bool Update::resetDeviceController() const {
qInfo() << nextTimePoint().toUtf8().constData() << "resetting device controller"; qInfo() << nextTimePoint().toUtf8().constData() << "resetting device controller";
#if TEST_DC_DOWNLOAD==0 if (!m_debug) {
m_hw->bl_rebootDC(); m_hw->bl_rebootDC();
#endif }
// wait maximally 3 seconds, before starting bootloader // wait maximally 3 seconds, before starting bootloader
QThread::sleep(1); QThread::sleep(1);
@ -399,9 +397,9 @@ int Update::run() {
qInfo() << "<DC-VERSION>" << Update::dcVersion(m_dcFileName); qInfo() << "<DC-VERSION>" << Update::dcVersion(m_dcFileName);
} }
#if TEST_DC_DOWNLOAD==0 if (!m_debug) {
m_hw->dc_autoRequest(false); m_hw->dc_autoRequest(false);
#endif }
qInfo() << "DC auto request OFF"; qInfo() << "DC auto request OFF";
@ -457,9 +455,10 @@ int Update::run() {
// if starting the bootloader failed // if starting the bootloader failed
qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-SUCCESS>"; qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-SUCCESS>";
#if TEST_DC_DOWNLOAD==0 if (!m_debug) {
m_hw->dc_autoRequest(true); //restart dc_autoRequest after download else E255! m_hw->dc_autoRequest(true); //restart dc_autoRequest after download else E255!
#endif }
return -(int)Result::SUCCESS; return -(int)Result::SUCCESS;
} }

View File

@ -30,7 +30,7 @@ class Update : public QObject {
QString m_dcFileName{}; QString m_dcFileName{};
hwinf *m_hw = nullptr; hwinf *m_hw = nullptr;
bool m_sys_areDCdataValid{}; bool m_sys_areDCdataValid{};
bool m_debug; bool m_debug{false};
bool m_noaction; bool m_noaction;
static QPluginLoader pluginLoader; static QPluginLoader pluginLoader;

View File

@ -144,7 +144,7 @@ int main(int argc, char **argv) {
} }
} }
// qCritical() << "JSON FILES TO UPDATE" << filesToUpdate; qCritical() << __LINE__ << "JSON FILES TO UPDATE" << filesToUpdate;
Update update(customerRepo, Update update(customerRepo,
QString::number(customerNr), QString::number(customerNr),
@ -153,8 +153,10 @@ int main(int argc, char **argv) {
plugInName, plugInName,
workingDir); workingDir);
update.doUpdate(); if (!filesToUpdate.empty()) {
// update.doUpdate(filesToUpdate, mountPath.has_value()); update.doUpdate(filesToUpdate, mountPath.has_value());
}
// update.checkJsonVersions(); // update.checkJsonVersions();
//update.checkJsonVersions(filesToUpdate); //update.checkJsonVersions(filesToUpdate);

View File

@ -107,7 +107,7 @@ Update::Update(QString customerRepository,
char const *serialInterface, char const *serialInterface,
char const *baudrate) char const *baudrate)
: QObject(parent) : QObject(parent)
// , m_hw(loadDCPlugin(QDir(plugInDir), pluginName)) , m_hw(loadDCPlugin(QDir(plugInDir), pluginName))
, m_serialInterface(serialInterface) , m_serialInterface(serialInterface)
, m_baudrate(baudrate) , m_baudrate(baudrate)
, m_customerRepository(customerRepository) , m_customerRepository(customerRepository)
@ -145,7 +145,8 @@ Update::~Update() {
// unloadDCPlugin(); // unloadDCPlugin();
} }
bool Update::doUpdate() { #if 0
bool Update::doUpdate() { // test function
int numberOfFiles = 3; int numberOfFiles = 3;
@ -178,6 +179,7 @@ bool Update::doUpdate() {
return true; return true;
} }
#endif
bool Update::doUpdate(QStringList const &filesToWorkOn, bool usbStickDetected) { bool Update::doUpdate(QStringList const &filesToWorkOn, bool usbStickDetected) {

View File

@ -45,10 +45,6 @@ void UpdateCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
//static constexpr const int PERCENT_UPDATE_DC{80}; //static constexpr const int PERCENT_UPDATE_DC{80};
//static constexpr const int PERCENT_SHOW_FINAL_STATUS{90}; //static constexpr const int PERCENT_SHOW_FINAL_STATUS{90};
qCritical() << __func__ << ":" << __LINE__ << m_command
<< "exitCode" << exitCode
<< "exitStatus" << exitStatus;
if (exitCode == 0 && exitStatus == QProcess::ExitStatus::NormalExit) { if (exitCode == 0 && exitStatus == QProcess::ExitStatus::NormalExit) {
if (m_command.contains("ATBUpdateCheck")) { if (m_command.contains("ATBUpdateCheck")) {
@ -127,10 +123,19 @@ void UpdateCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
if (m_worker->workList().nextExec()) { if (m_worker->workList().nextExec()) {
m_worker->workList().exec(); m_worker->workList().exec();
} else {
// testing
qCritical() << __func__ << ":" << __LINE__ << "TEST: SEND UPDATE SUCCEEDED TO ISMAS";
m_worker->setLastFailedUpdateStep(Worker::UPDATE_STEP::NONE);
Worker::UpdateProcessRunning _(m_worker);
} }
} else { } else {
bool execShowStatus = true; bool execShowStatus = true;
m_worker->workList().exec(execShowStatus); m_worker->workList().exec(execShowStatus);
} }
} else {
Q_ASSERT_X(false,
QString("%1:%2").arg(__func__).arg(__LINE__).toUtf8().constData(),
"empty worker list");
} }
} }

View File

@ -9,7 +9,7 @@ public:
Worker *worker, Worker *worker,
int nextCommandIndex, int nextCommandIndex,
int start_timeout = 100000, int start_timeout = 100000,
int finish_timeout = 100000); int finish_timeout = -1);
public slots: public slots:
virtual void readyReadStandardOutput() override; virtual void readyReadStandardOutput() override;
virtual void finished(int exitCode, QProcess::ExitStatus exitStatus) override; virtual void finished(int exitCode, QProcess::ExitStatus exitStatus) override;

View File

@ -31,6 +31,8 @@ public:
unsigned nextExecIndex() const; unsigned nextExecIndex() const;
bool nextExec() const; bool nextExec() const;
bool exec(bool last=false); bool exec(bool last=false);
unsigned size() { return m_workList.size(); }
}; };
#endif // WORK_LIST_H_INCLUDED #endif // WORK_LIST_H_INCLUDED

View File

@ -231,6 +231,7 @@ class Worker : public QThread{
int sendUpdateSucceededAndActivated(); int sendUpdateSucceededAndActivated();
int sendFinalResult(); int sendFinalResult();
public:
struct UpdateProcessRunning { struct UpdateProcessRunning {
Worker *m_worker; Worker *m_worker;
@ -395,6 +396,14 @@ protected:
virtual void run(); virtual void run();
public: public:
UPDATE_STEP lastFailedUpdateStep() const {
return m_lastFailedUpdateStep;
}
void setLastFailedUpdateStep(UPDATE_STEP step) {
m_lastFailedUpdateStep = step;
}
QDebug CONSOLE(QStringList const &lst = QStringList()) { QDebug CONSOLE(QStringList const &lst = QStringList()) {
m_debugMsg = lst; m_debugMsg = lst;
return QDebug(QtMsgType::QtInfoMsg); return QDebug(QtMsgType::QtInfoMsg);

View File

@ -64,7 +64,8 @@ QString branchName() {
std::unique_ptr<QSettings> readSettings(QString const &optionalDirName) { std::unique_ptr<QSettings> readSettings(QString const &optionalDirName) {
std::unique_ptr<QSettings> settings{std::make_unique<QSettings>()}; std::unique_ptr<QSettings> settings{std::make_unique<QSettings>()};
QString const fileName{settings->applicationName() + ".ini"}; //QString const fileName{settings->applicationName() + ".ini"};
QString const fileName{"ATBUpdateTool.ini"};
QDir d; QDir d;
if (!optionalDirName.isEmpty()) { if (!optionalDirName.isEmpty()) {