From bab771cece9dde253d0205c3b566076b04706898 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 9 Oct 2024 12:50:44 +0200 Subject: [PATCH] Add getVersions() and resetVersions() for slave-lib --- include/hwapi.h | 9 ++++++++- src/hwapi.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/hwapi.h b/include/hwapi.h index 8e51519..a9091a2 100644 --- a/include/hwapi.h +++ b/include/hwapi.h @@ -121,8 +121,13 @@ public: explicit hwapi(QObject *parent = nullptr); + #ifdef THIS_IS_CA_MASTER - T_datif *myDatif; + T_datif *myDatif; + #else // THIS_IS_CA_SLAVE + QString getVersions(); + void resetVersions(); + bool m_resetVersions = false; #endif T_runProc *runProcess; @@ -1401,6 +1406,8 @@ public: signals: + void hwapi_restoredVersions(); + void hwapi_reportDCDownloadStatus(QString const&) const override; void hwapi_reportDCDownloadSuccess(QString const&) const override; void hwapi_reportDCDownloadFailure(QString const&) const override; diff --git a/src/hwapi.cpp b/src/hwapi.cpp index 69d561a..5d7501f 100755 --- a/src/hwapi.cpp +++ b/src/hwapi.cpp @@ -11,6 +11,7 @@ #include "hwapi.h" #include "download_thread.h" #include "reporting_thread.h" +#include "storeINdata.h" // epi_loadSWVer, epi_loadHWVer #include #include @@ -25,6 +26,37 @@ static uint8_t hwapi_lastDoorState; static uint8_t bl_startupStep; +#ifdef THIS_IS_CA_MASTER +#else // THIS_IS_CA_SLAVE + QString hwapi::getVersions() { + if (m_sharedMem != nullptr) { + // check if sw/hw-versions have been restored (see resetVersions()). + // emit a signal in such a case. + QString const &sw = epi_loadSWver(); // command 11 + QString const &hw = epi_loadHWver(); // command 12 + if (!sw.isEmpty() && !hw.isEmpty() && m_resetVersions) { + emit hwapi_restoredVersions(); + return sw + " " + hw; + } + } + return ""; + } + + void hwapi::resetVersions() { + if (m_sharedMem != nullptr) { + // command 11 and 12 are included in the requests sent automatically, + // first 11, then 12. The results are used to refresh corresponding + // shared memory locations. + // set these locations to the empty string in the opposite order as + // the commands are sent. + // purpose: only when both locations are not empty again, we can be + // sure that data are not obsolete. + gpi_storeHWver(""); // command 12 + gpi_storeSWver(""); // command 11 + m_resetVersions = true; + } + } +#endif hwapi::hwapi(QObject *parent) : QObject(parent) {