From 86311de486609f232f495b1417a6a2ca568efdfc Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 18 Apr 2023 12:23:18 +0200 Subject: [PATCH] Add use of shared memory. Add changes for version 3.4. of library. --- src/hwapi.cpp | 273 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 223 insertions(+), 50 deletions(-) diff --git a/src/hwapi.cpp b/src/hwapi.cpp index ca0ad84..169c4e7 100644 --- a/src/hwapi.cpp +++ b/src/hwapi.cpp @@ -21,8 +21,11 @@ #include "controlBus.h" #include "storeINdata.h" #include "dcBL.h" +#include "shared_mem_buffer.h" #include -#include <../plugins/interfaces.h> +#include + +#include "interfaces.h" static const QMap baudrateMap = { @@ -30,20 +33,29 @@ static const QMap baudrateMap = { {"57600" , 4}, {"115200" , 5} }; -hwapi::hwapi(QWidget *parent) : QObject(parent) -{ - // constructor - //epi_resetAllDOs(); - //PI_INI(); +hwapi::hwapi(QWidget *parent) : QObject(parent) { + // create or attach shared memory segment + // !!! The compoment creating the shared memory MUST be ATBQT !!! + m_sharedMem = SharedMemBuffer::getShm(sizeof(SharedMemBuffer)); + if (m_sharedMem) { + if (m_sharedMem->isAttached()) { + qInfo() << "Shared memory (" + << sizeof(SharedMemBuffer) << "bytes) created and attached"; + } + } else { + qCritical() << "Creating/attaching shared memory failed"; + } sendWRcmd_INI(); - myDatif = new T_datif(); } +hwapi::~hwapi() { + if (m_sharedMem && m_sharedMem->isAttached()) { + m_sharedMem->detach(); + } +} - -void hwapi::sub_storeSendingText(QByteArray *buf) const -{ +void hwapi::sub_storeSendingText(QByteArray *buf) const { char local[70], copie[1350]; // 64byte more then max buffer size! int LL, nn, len, maxruns=20; @@ -739,13 +751,16 @@ QString hwapi::rtc_getTimStr() const { uint8_t hh, mm, ss, buf[20], nn; QString qbuf; - + char ctmp; qbuf.clear(); for (nn=0; nn<20; nn++) buf[nn]=0; epi_getTime(&hh, &mm, &ss); GetTimeString(hh, mm, ss, HourSys24h, MITSEK, buf); // about 12byte long - for (nn=0; nn<20; nn++) qbuf[nn]=buf[nn]; - + for (nn=0; nn<20; nn++) + { + ctmp=buf[nn]; + qbuf[nn]=ctmp; + } return qbuf; } @@ -753,14 +768,17 @@ QString hwapi::rtc_getDatStr() const { uint8_t day, month, year, buf[20], nn; QString qbuf; + char ctmp; qbuf.clear(); for (nn=0; nn<20; nn++) buf[nn]=0; epi_getDate(&year, &month, &day); GetDateString(day, month, 0x20, year, DateFormatDeutsch, 0, buf); for (nn=0; nn<20; nn++) - qbuf[nn]=buf[nn]; - + { + ctmp= buf[nn]; + qbuf[nn]=ctmp; + } return qbuf; } @@ -2221,7 +2239,8 @@ bool hwapi::pri_TD_addText(QByteArray text) const bool hwapi::pri_TD_addValue(int val) const { - QString tmpStr; +// QString tmpStr; + QByteArray tmpStr; tmpStr.setNum(val,10); // up to 12 chars if (ticketTemplate.length()>1266) return false; @@ -3071,7 +3090,7 @@ bool hwapi::bl_isUp(void) const } -void hwapi::bl_sendAddress(u_int16_t blockNumber) const +void hwapi::bl_sendAddress(uint16_t blockNumber) const { // send start address, nr of 64byte-block, start with 0 // will be sent only for folling block-numbers: @@ -3106,7 +3125,7 @@ void hwapi::bl_openBinary(void) const dcBL_loadBinary(0); } -void hwapi::bl_sendDataBlock(uint8_t length, u_int8_t *buffer) const +void hwapi::bl_sendDataBlock(uint8_t length, uint8_t *buffer) const { // send 64 byte from bin file uint8_t LL=length, sendBuf[80], sendLen; @@ -3137,6 +3156,7 @@ void hwapi::bl_sendLastBlock(void) const len=dcBL_writeLastPage(buf); sendWRcmd_setSendBlock160(len, buf); + } uint8_t hwapi::bl_wasSendingDataOK(void) const @@ -3309,6 +3329,60 @@ bool hwapi::rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const } +bool hwapi::rtc_getExtendedTime(struct T_extTime *exTime) const +{ + uint8_t len; + uint16_t LL, nn; + uint8_t *start; + uint8_t buf[66]; + + epi_restoreExtendedTime(&len, buf); + // Puffer in struct eintragen: + LL=sizeof(struct T_extTime); + start = &(exTime->Hours); + nn=0; + do + { + *start = buf[nn]; + start++; + } while(++nnstartbuffer[0]; + nn=0; + do + { + *start = buf[nn]; + start++; + } while(++nnram; + nn=0; + do + { + *start = buf[nn]; + start++; + } while(++nnallDoorsDebounced; + nn=0; + do + { + *start = buf[nn]; + start++; + } while(++nn