Compare commits

..

No commits in common. "100ada06f8a0f5ad1d9768a68539f29315819817" and "f6efb1ee9ac141449b5ef5249bb3da5febd2a752" have entirely different histories.

9 changed files with 103 additions and 244 deletions

View File

@ -321,10 +321,6 @@ struct SharedMem
std::atomic_bool m_finished{false}; std::atomic_bool m_finished{false};
} m_downLoadDC; } m_downLoadDC;
// meta-data
char os_release[64];
char date_of_creation[32];
char creator[128]; // name of application plus pid
static QSharedMemory *getShm(std::size_t s = 0); static QSharedMemory *getShm(std::size_t s = 0);

View File

@ -1,6 +1,6 @@
TEMPLATE = lib TEMPLATE = lib
TARGET = CAmaster TARGET = CAmaster
VERSION="1.0.2" VERSION="1.0.1"
HEADERS += \ HEADERS += \
../include/com.h \ ../include/com.h \

View File

@ -1,6 +1,6 @@
TEMPLATE = lib TEMPLATE = lib
TARGET = CAslave TARGET = CAslave
VERSION="1.0.2" VERSION="1.0.1"
HEADERS += \ HEADERS += \
../include/reporting_thread.h ../include/reporting_thread.h

View File

@ -9,14 +9,10 @@ History:
#include "sendWRcmd.h" #include "sendWRcmd.h"
#include "controlBus.h" #include "controlBus.h"
#include "storeINdata.h" #include "storeINdata.h"
#include "download_thread.h"
#include <QDebug> #include <QDebug>
#include <datei.h> #include <datei.h>
#include <QDir> #include <QDir>
#include <QString>
#include <QDateTime>
@ -58,10 +54,8 @@ static uint8_t datif_pNextCmd, datif_sendSlowCmd;
//#define DATIF_CTR_GOTRESPVAL 100 //#define DATIF_CTR_GOTRESPVAL 100
T_datif::T_datif(hwinf *hw, QObject *parent) : QObject(parent) T_datif::T_datif(QObject *parent) : QObject(parent)
{ {
m_hw = hw;
QByteArray myBA; QByteArray myBA;
QDir myDir("../dmd"); QDir myDir("../dmd");
@ -176,22 +170,10 @@ char T_datif::datif_cycleSend()
// b) Antwort meldet Fehler -> 2x wiederholen (nach einer Luecke von 10ms ) // b) Antwort meldet Fehler -> 2x wiederholen (nach einer Luecke von 10ms )
// c) gar keine Antwort, Timeout nach 100ms -> 2x wiederholen (nach einer Luecke von 10ms ) // c) gar keine Antwort, Timeout nach 100ms -> 2x wiederholen (nach einer Luecke von 10ms )
// cycl_running=0: nichts zu tun 1: Mitteilung: Kommando wurde soeben abgesendet, 2,3,4 = Wiederholung // cycl_running=0: nichts zu tun 1: Mitteilung: Kommando wurde soeben abgesendet, 2,3,4 = Wiederholung
if (cycl_running == 0) {
if (m_hw) {
if (m_hw->dcDownloadRequested()) { // only happens in ca-master
qCritical() << "DOWNLOAD REQUESTED";
if (!m_hw->dcDownloadThreadStart()) {
qCritical() << "DOWNLOAD-THREAD NOT RUNNING WITHIN 1000ms";
} else {
qCritical() << "DOWNLOAD-THREAD RUNNING";
}
return 0;
}
}
} else {
// 21.9.23 doRepeat hier raus sonst gehts warten auch nicht mehr (BL)
// if (cycl_running && doRepeat)
if (cycl_running) // 21.9.23 doRepeat hier raus sonst gehts warten auch nicht mehr (BL)
// if (cycl_running && doRepeat)
{
// request is still running, wait for response before next sending // request is still running, wait for response before next sending
//qDebug()<< "datif wait for response"; //qDebug()<< "datif wait for response";
datif_trigger->stop(); datif_trigger->stop();

View File

@ -104,10 +104,8 @@ void DownloadThread::run() {
m_hw->dcDownloadRequestAck(); m_hw->dcDownloadRequestAck();
qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED:"; qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED";
qCritical() << " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
#if 1
// load binary device controller file into memory // load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName()); QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) { if (ba.size() > 0) {
@ -117,17 +115,13 @@ void DownloadThread::run() {
// fill last block of data to be sent with 0xFF // fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF)); ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
resetDeviceController();
if (startBootloader()) {
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size(); qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks; qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
m_hw->dc_autoRequest(true); // turn auto-request setting on int currentBlock = 0;
resetDeviceController();
QThread::sleep(1);
if (startBootloader()) {
m_hw->dc_autoRequest(false);// turn auto-request setting off for
#if 0
int currentBlock = 0; // download of binary dc
DownloadResult res = DownloadResult::OK; DownloadResult res = DownloadResult::OK;
qCritical() << "64-byte block " << currentBlock; qCritical() << "64-byte block " << currentBlock;
while (res != DownloadResult::ERROR && currentBlock < totalBlocks) { while (res != DownloadResult::ERROR && currentBlock < totalBlocks) {
@ -155,32 +149,20 @@ void DownloadThread::run() {
} else { } else {
m_hw->bl_sendLastBlock(); m_hw->bl_sendLastBlock();
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
// QThread::msleep(250);
} }
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK()); qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
#endif
m_hw->dc_autoRequest(true); // turn auto-request setting on again
} }
stopBootloader(); // there is no harm in stopping the bootloader even stopBootloader(); // there is no harm in stopping the bootloader even
} // if it was not started at all } // if it was not started at all
#else #if 0
// load binary device controller file into memory // test code:
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName()); uint16_t const totalBlocks = 100;
if (ba.size() > 0) {
uint16_t const totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks); m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) { for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock; QThread::msleep(100);
QThread::msleep(250);
}
} }
#endif #endif
@ -283,12 +265,11 @@ bool DownloadThread::startBootloader() const {
int nTry = 5; int nTry = 5;
while (--nTry >= 0) { while (--nTry >= 0) {
m_hw->bl_startBL(); m_hw->bl_startBL();
QThread::msleep(1000); QThread::msleep(5000);
m_hw->bl_checkBL(); m_hw->bl_checkBL();
QThread::msleep(1000);
if (m_hw->bl_isUp()) { if (m_hw->bl_isUp()) {
qInfo() << "starting bootloader...OK"; qInfo() << "starting bootloader...OK";
QThread::msleep(1000); QThread::msleep(5000);
return true; return true;
} else { } else {
qCritical() << "bootloader not up (" << nTry << ")"; qCritical() << "bootloader not up (" << nTry << ")";

View File

@ -22,12 +22,11 @@
#include "hwapi.h" #include "hwapi.h"
#include "download_thread.h" #include "download_thread.h"
#include "reporting_thread.h" #include "reporting_thread.h"
#include "shared_mem_buffer.h"
#include <cstring> #include <cstring>
#include <QThread> #include <QThread>
#include <QDebug> #include <QDebug>
#include <QApplication>
static uint32_t hwapi_lastStartAmount; static uint32_t hwapi_lastStartAmount;
static uint32_t hwapi_lastTotalAmount; static uint32_t hwapi_lastTotalAmount;
@ -59,9 +58,6 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
qCritical() << "Creating/attaching shared memory failed"; qCritical() << "Creating/attaching shared memory failed";
} }
Q_ASSERT_X(sizeof(SharedMem) != m_sharedMem->size(),
"compare sizes", "sizes different");
//if (shdMem_firstUse()) // für Master raus //if (shdMem_firstUse()) // für Master raus
// { // {
@ -71,7 +67,7 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
#error "SLAVE LIB COMPILED INTO MASTER" #error "SLAVE LIB COMPILED INTO MASTER"
#endif #endif
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren! myDatif = new T_datif(); // für die CAslave-Lib auskommentieren!
#endif #endif
@ -4416,7 +4412,6 @@ QObject const *hwapi::getAPI() {
} }
bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const { bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
// called by worker-thread (see atbupdatetool)
SharedMem *data = SharedMem::getData(); SharedMem *data = SharedMem::getData();
if (!data) { if (!data) {
return false; return false;
@ -4440,15 +4435,9 @@ bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
} }
bool hwapi::dcDownloadRequested() const { bool hwapi::dcDownloadRequested() const {
SharedMem *data = SharedMem::getData(); SharedMem const *data = SharedMem::getData();
Q_ASSERT_X(data != nullptr, "check", "pointer invalid"); // should be false at entry
Q_ASSERT_X((void *)data != m_sharedMem->data(), "compare pointers", "pointers different"); return data ? data->m_downLoadDC.m_requested.load() : false;
Q_ASSERT_X(sizeof(*data) != m_sharedMem->size(), "compare sizes", "sizes different");
// called by download-thread
// 1: true at entry: reset atomically to false
// 2: false at entry: no change
return data ? data->m_downLoadDC.m_requested.exchange(false) : false;
} }
bool hwapi::dcDownloadResetRequest() const { bool hwapi::dcDownloadResetRequest() const {
@ -4460,12 +4449,14 @@ bool hwapi::dcDownloadResetRequest() const {
} }
bool hwapi::dcDownloadRequestAck() const { bool hwapi::dcDownloadRequestAck() const {
// called by download-thread
SharedMem *data = SharedMem::getData(); SharedMem *data = SharedMem::getData();
if (data) { if (data) {
if (data->m_downLoadDC.m_requested) {
data->m_downLoadDC.m_requested = false;
data->m_downLoadDC.m_running = true; data->m_downLoadDC.m_running = true;
data->m_downLoadDC.m_finished = false; data->m_downLoadDC.m_finished = false;
} }
}
return false; return false;
} }
@ -4474,16 +4465,14 @@ bool hwapi::dcDownloadRunning() const {
if (data) { if (data) {
int cnt = 10; int cnt = 10;
while (--cnt > 0) { while (--cnt > 0) {
bool running = data->m_downLoadDC.m_running; bool running = data->m_downLoadDC.m_running.load();
bool finished = data->m_downLoadDC.m_finished; bool finished = data->m_downLoadDC.m_finished.load();
if ((running == true) && (finished == false)) { if (!running || finished) {
// see dcDownloadRequestAck()
break;
}
if (cnt < 3) { if (cnt < 3) {
qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished; qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished;
} }
QThread::msleep(500); QThread::msleep(500);
} else break;
} }
// qCritical() << "DOWNLOAD RUNNING" << cnt << (cnt > 0); // qCritical() << "DOWNLOAD RUNNING" << cnt << (cnt > 0);
return (cnt > 0); return (cnt > 0);
@ -4492,16 +4481,18 @@ bool hwapi::dcDownloadRunning() const {
} }
void hwapi::dcDownloadThreadFinalize(DownloadThread *dthread) { void hwapi::dcDownloadThreadFinalize(DownloadThread *dthread) {
Q_UNUSED(dthread); delete dthread;
// delete dthread;
m_downloadThread = nullptr; m_downloadThread = nullptr;
} }
bool hwapi::dcDownloadFinished() { bool hwapi::dcDownloadFinished() {
SharedMem const *data = SharedMem::getDataConst();
if (data) {
int cnt = 10; int cnt = 10;
while (dcDownloadRunning()) { while ((--cnt > 0) &&
if (--cnt == 0) { ((data->m_downLoadDC.m_running.load() == true) &&
return false; (data->m_downLoadDC.m_finished.load() == false))) {
QThread::sleep(1);
} }
//if (cnt > 0) { //if (cnt > 0) {
@ -4510,13 +4501,12 @@ bool hwapi::dcDownloadFinished() {
// return true; // return true;
//} //}
} }
return true; return false;
} }
// download thread // download thread
bool hwapi::dcDownloadThreadStart() { bool hwapi::dcDownloadThreadStart() {
// called by timer in datIf.cpp: T_datif::datif_cycleSend()
m_downloadThread = new DownloadThread(this); m_downloadThread = new DownloadThread(this);
if (m_downloadThread) { if (m_downloadThread) {
m_downloadThread->start(); m_downloadThread->start();
@ -4548,7 +4538,6 @@ bool hwapi::dcDownloadReportThreadStart() { // only start reporting thread
if (cnt > 0) { if (cnt > 0) {
m_reportingThread = new ReportingThread(this); m_reportingThread = new ReportingThread(this);
if (m_reportingThread) { if (m_reportingThread) {
m_reportingThread->moveToThread(QApplication::instance()->thread());
m_reportingThread->start(); m_reportingThread->start();
cnt = 10; cnt = 10;
while (--cnt > 0 && !dcDownloadReportThreadRunning()) { while (--cnt > 0 && !dcDownloadReportThreadRunning()) {
@ -4580,9 +4569,7 @@ void hwapi::dcDownloadReportThreadQuit() {
} }
bool hwapi::dcDownloadReportThreadFinished() const { bool hwapi::dcDownloadReportThreadFinished() const {
// if the pointer to the underlying c++-object is not valid, the thread return m_reportingThread ? m_reportingThread->isFinished() : false;
// counts as finished
return m_reportingThread ? m_reportingThread->isFinished() : true;
} }
bool hwapi::dcDownloadReportStart() const { bool hwapi::dcDownloadReportStart() const {
@ -4608,11 +4595,9 @@ bool hwapi::dcDownloadReportFinished() {
} }
if (dcDownloadReportThreadFinished()) { if (dcDownloadReportThreadFinished()) {
if (m_reportingThread) {
delete m_reportingThread; delete m_reportingThread;
m_reportingThread = nullptr; m_reportingThread = nullptr;
} }
}
return true; return true;
} }

View File

@ -641,11 +641,8 @@ void T_runProc::bl_rebootDC(void)
// BL is working for 5s after power-on-reset. // BL is working for 5s after power-on-reset.
uint8_t len, buf[20]; uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_restartDC(buf); len=dcBL_restartDC(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf); sendWRcmd_setSendBlock160(len, buf);
} }
@ -655,13 +652,8 @@ void T_runProc::bl_startBL(void)
// otherwise the BL jumps to normal DC application // otherwise the BL jumps to normal DC application
uint8_t len, buf[20]; uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_activatBootloader(buf); len=dcBL_activatBootloader(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf); sendWRcmd_setSendBlock160(len, buf);
epi_setNowIsBootload(true); epi_setNowIsBootload(true);
} }
@ -669,11 +661,8 @@ void T_runProc::bl_checkBL(void)
{ {
// call this function in order to get information, afterwards use "bl_isUp()" // call this function in order to get information, afterwards use "bl_isUp()"
uint8_t len, buf[20]; uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_readFWversion(buf); len=dcBL_readFWversion(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf); sendWRcmd_setSendBlock160(len, buf);
} }

View File

@ -1,13 +1,7 @@
#include "shared_mem_buffer.h" #include "shared_mem_buffer.h"
#include <QDebug> #include <QDebug>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QDateTime>
#include <QCoreApplication>
#include <atomic> #include <atomic>
#include <algorithm>
#ifdef QT_POSIX_IPC #ifdef QT_POSIX_IPC
// The POSIX backend can be explicitly selected using the -feature-ipc_posix // The POSIX backend can be explicitly selected using the -feature-ipc_posix
@ -15,124 +9,33 @@
// macro will be defined. -> we use SystemV shared memory // macro will be defined. -> we use SystemV shared memory
#error "QT_POSIX_IPC defined" #error "QT_POSIX_IPC defined"
#else #else
#ifdef linux #ifdef __linux__
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h> // ftok #include <sys/ipc.h> // ftok
#endif #endif
#endif #endif
//static bool shdMemFirstUse; //static bool shdMemFirstUse;
static QString read1stLineOfFile(QString fileName) { // read for instance /etc/os-release
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();
}
}
}
return "N/A";
}
//QSharedMemory *SharedMemBuffer::getShm(std::size_t size) { //QSharedMemory *SharedMemBuffer::getShm(std::size_t size) {
QSharedMemory *SharedMem::getShm(std::size_t size) { QSharedMemory *SharedMem::getShm(std::size_t size) {
static QSharedMemory shMem; static QSharedMemory shMem;
if (size > 0) { if (size > 0) {
#ifdef linux #ifdef __linux__
static const long nativeKey = ftok("/etc/os-release", 'H'); //static const long nativeKey = ftok("/etc/os-release", 'H');
static const QString fkey = std::to_string(nativeKey).c_str(); //static const QString fkey = std::to_string(nativeKey).c_str();
//static const QString fkey = "0123456?000=7"; static const QString fkey = "0123456?000=7";
#else #else
static const QString fkey = "0123456?000=9"; static const QString fkey = "0123456?000=9";
#endif #endif
qCritical() << __func__ << ":" << __LINE__ << ": size" << size;
shMem.setKey(fkey); shMem.setKey(fkey);
if (!shMem.isAttached()) { if (!shMem.isAttached()) {
if (shMem.create(size)) { if (shMem.create(size)) {
qCritical() << __func__ << ":" << __LINE__ << ": created shared memory";
#ifdef linux
if ((size != (std::size_t)shMem.size()) || (sizeof(SharedMem) != shMem.size())) {
qCritical() << __func__ << ":" << __LINE__
<< "size=" << size
<< "shMem.size=" << shMem.size()
<< "sizeof(SharedMem)=" << sizeof(SharedMem)
<< "ABOUT TO REBOOT SYSTEM...";
if (system("reboot")) {
// reboot system -> shared memory re-created
}
}
struct SharedMem *sh = (SharedMem *)(shMem.data());
memset(sh->indat_HWversion, 0x00, sizeof(sh->indat_HWversion));
memset(sh->indat_SWversion, 0x00, sizeof(sh->indat_SWversion));
memset(sh->os_release, 0x00, sizeof(sh->os_release));
memset(sh->date_of_creation, 0x00, sizeof(sh->date_of_creation));
memset(sh->creator, 0x00, sizeof(sh->creator));
QString const &os_release = read1stLineOfFile("/etc/os-release");
strncpy(sh->os_release, os_release.toStdString().c_str(),
std::min((int)os_release.size(), (int)sizeof(sh->os_release)-1));
QString const &currentDateTime = QDateTime::currentDateTime().toString(Qt::ISODate);
char const *current = currentDateTime.toUtf8().constData();
strncpy(sh->date_of_creation, current,
std::min((int)strlen(current), (int)sizeof(sh->date_of_creation)-1));
QString const &appPid = QString("%1 (%2)").arg(QCoreApplication::applicationName())
.arg(QCoreApplication::applicationPid());
strncpy(sh->creator, appPid.toStdString().c_str(),
std::min((int)strlen(appPid.toStdString().c_str()),
(int)sizeof(sh->creator)-1));
qCritical() << "os-release:" << sh->os_release;
qCritical() << " creator:" << sh->creator;
qCritical() << " date:" << sh->date_of_creation;
#else
Q_ASSERT_X(size != shMem.size(), "compare sizes", "sizes different");
Q_ASSERT_X(sizeof(SharedMem) != shMem.size(), "compare sizes", "sizes different");
#endif
return &shMem; return &shMem;
} else { } else {
if (shMem.error() == QSharedMemory::AlreadyExists) { if (shMem.error() == QSharedMemory::AlreadyExists) {
if (shMem.attach()) { if (shMem.attach()) {
#ifdef linux
if ((size != (std::size_t)shMem.size()) || (sizeof(SharedMem) != shMem.size())) {
qCritical() << __func__ << ":" << __LINE__
<< "size=" << size
<< "shMem.size=" << shMem.size()
<< "sizeof(SharedMem)=" << sizeof(SharedMem)
<< "ABOUT TO REBOOT SYSTEM...";
if (system("reboot")) {
// reboot system -> shared memory re-created
}
}
#else
Q_ASSERT_X(size != shMem.size(), "compare sizes", "sizes different");
Q_ASSERT_X(sizeof(SharedMem) != shMem.size(), "compare sizes", "sizes different");
#endif
QString const &appPid = QString("%1 (%2)").arg(QCoreApplication::applicationName())
.arg(QCoreApplication::applicationPid());
qCritical() << __func__ << ":" << __LINE__ << appPid << "attached shared memory";
struct SharedMem const *sh = (SharedMem const *)(shMem.data());
qCritical() << "os-release:" << sh->os_release;
qCritical() << " creator:" << sh->creator;
qCritical() << " date:" << sh->date_of_creation;
return &shMem; return &shMem;
} }
} }
@ -140,13 +43,6 @@ QSharedMemory *SharedMem::getShm(std::size_t size) {
qCritical() << shMem.nativeKey() << shMem.key() << shMem.data() qCritical() << shMem.nativeKey() << shMem.key() << shMem.data()
<< shMem.error() << shMem.errorString(); << shMem.error() << shMem.errorString();
return nullptr; return nullptr;
} else {
qCritical() << __func__ << ":" << __LINE__ << "shared memory already attached";
struct SharedMem const *sh = (SharedMem const *)(shMem.data());
qCritical() << "os-release:" << sh->os_release;
qCritical() << " creator:" << sh->creator;
qCritical() << " date:" << sh->date_of_creation;
} }
} }
return &shMem; return &shMem;

View File

@ -64,36 +64,66 @@ bool indat_isMdbOn()
void gpi_storeHWver(QString text) void gpi_storeHWver(QString text)
{ {
if (qstrlen(SharedMem::read()->indat_HWversion) == 0) { // change Qstring to array of chars, because shared mem allowes no QString!
char const *p = text.toUtf8().constData(); int nn, LL = text.length();
if (qstrlen(p) > 0) { if (LL >= versionBufferLen)
memset(SharedMem::write()->indat_HWversion, 0, versionBufferLen); LL=versionBufferLen-1; // leave place for termination
memcpy(SharedMem::write()->indat_HWversion, p,
qMin((uint)versionBufferLen, qstrlen(p)) - 1); for (nn=0; nn<LL; nn++)
} {
SharedMem::write()->indat_HWversion[nn] = text.at(nn).toLatin1();
} }
for (nn=LL; nn<versionBufferLen; nn++)
SharedMem::write()->indat_HWversion[nn] =0;
} }
QString epi_loadHWver(void) QString epi_loadHWver(void)
{ {
return QString((char const*)SharedMem::read()->indat_HWversion); // load array of chars from SM and change to QString
int nn, LL = versionBufferLen;
char cc;
QString myStr;
myStr.clear();
for (nn=0; nn<LL; nn++)
{
cc = SharedMem::read()->indat_HWversion[nn];
myStr.append(cc);
}
return myStr;
} }
void gpi_storeSWver(QString text) void gpi_storeSWver(QString text)
{ {
if (qstrlen(SharedMem::read()->indat_SWversion) == 0) { int nn, LL = text.length();
char const *p = text.toUtf8().constData(); if (LL >= versionBufferLen)
if (qstrlen(p) > 0) { LL=versionBufferLen-1; // leave place for termination
memset(SharedMem::write()->indat_SWversion, 0, versionBufferLen);
memcpy(SharedMem::write()->indat_SWversion, p, for (nn=0; nn<LL; nn++)
qMin((uint)versionBufferLen, qstrlen(p)) - 1); {
} SharedMem::write()->indat_SWversion[nn] = text.at(nn).toLatin1();
} }
for (nn=LL; nn<versionBufferLen; nn++)
SharedMem::write()->indat_SWversion[nn] =0;
} }
QString epi_loadSWver(void) QString epi_loadSWver(void)
{ {
return QString((char const*)SharedMem::read()->indat_SWversion); int nn, LL = versionBufferLen;
char cc;
QString myStr;
myStr.clear();
for (nn=0; nn<LL; nn++)
{
cc = SharedMem::read()->indat_SWversion[nn];
myStr.append(cc);
}
return myStr;
} }
void gpi_storeDCstate(QString text) void gpi_storeDCstate(QString text)