Added additional variables into shared memory.

Cleaned source.
This commit is contained in:
Gerhard Hoffmann 2023-04-18 14:42:09 +02:00
parent 81c610c48b
commit c99d0730ce

View File

@ -1,19 +1,14 @@
#include <stdint.h> #include <stdint.h>
#include <algorithm>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include "tslib.h" #include "tslib.h"
#include "shared_mem_buffer.h" #include "shared_mem_buffer.h"
//#include "controlBus.h"
// /////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////
// control serial interface gui <--> serial // control serial interface gui <--> serial
// /////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////
//static QString rs_comportName; // z.B. "COM48"
//static QString rs_baudStr; // z.B. "19200"
//static int rs_baudNr; //0...5 oder -1
//static uint8_t rs_connect; // 0,1
void epi_setSerial(int BaudNr, void epi_setSerial(int BaudNr,
QString BaudStr, QString BaudStr,
QString ComName, QString ComName,
@ -38,7 +33,6 @@ void epi_closeSerial(void) {
SharedMemBuffer::getData()->rs.connect = 0; SharedMemBuffer::getData()->rs.connect = 0;
} }
void gpi_serialChanged(void) { void gpi_serialChanged(void) {
// serial confirms that port was closed or opened // serial confirms that port was closed or opened
// rs_connect=2; // Flanke, nur 1x öffnen/schließen // rs_connect=2; // Flanke, nur 1x öffnen/schließen
@ -49,7 +43,6 @@ uint8_t gpi_getSerialConn(void) {
return SharedMemBuffer::getDataConst()->rs.connect; return SharedMemBuffer::getDataConst()->rs.connect;
} }
int gpi_getBaudNr(void) { int gpi_getBaudNr(void) {
return SharedMemBuffer::getDataConst()->rs.baudNr; return SharedMemBuffer::getDataConst()->rs.baudNr;
} }
@ -106,14 +99,12 @@ bool gpi_PeriodicSendTimeHasChanged() {
// linke Spalte, über Connect Button // linke Spalte, über Connect Button
static QString txt4comStateLine; static QString txt4comStateLine;
QString epi_getTxt4comStateLine(void) QString epi_getTxt4comStateLine(void) {
{
// GUI: get Text for serial Comport-State Line // GUI: get Text for serial Comport-State Line
return txt4comStateLine; return txt4comStateLine;
} }
void gpi_setTxt4comStateLine(QString txtline) // gpi void gpi_setTxt4comStateLine(QString txtline) {
{
// serial: write Text to be displayed in serial Comport-State line (like "connected") // serial: write Text to be displayed in serial Comport-State line (like "connected")
txt4comStateLine.clear(); txt4comStateLine.clear();
if (txtline=="") if (txtline=="")
@ -122,26 +113,20 @@ void gpi_setTxt4comStateLine(QString txtline) // gpi
txt4comStateLine=txtline; txt4comStateLine=txtline;
} }
void epi_clrTxt4comStateLine() void epi_clrTxt4comStateLine() {
{
txt4comStateLine.clear(); txt4comStateLine.clear();
} }
//---------------------------------------------------------------------------------------------
// rechte Spalte, oberste Statuszeile // rechte Spalte, oberste Statuszeile
// I) "Handshakes" (serial Control) flow.cpp // I) "Handshakes" (serial Control) flow.cpp
// geht überhaupt was raus? kommt überhaupt was zurück? // geht überhaupt was raus? kommt überhaupt was zurück?
static QString txt4HsStateLine; static QString txt4HsStateLine;
QString epi_getTxt4HsStateLine(void) QString epi_getTxt4HsStateLine(void) {
{
return txt4HsStateLine; return txt4HsStateLine;
} }
void gpi_setTxt4HsStateLine(QString txtline) void gpi_setTxt4HsStateLine(QString txtline) {
{
txt4HsStateLine.clear(); txt4HsStateLine.clear();
if (txtline=="") if (txtline=="")
txt4HsStateLine.clear(); txt4HsStateLine.clear();
@ -149,26 +134,19 @@ void gpi_setTxt4HsStateLine(QString txtline)
txt4HsStateLine=txtline; txt4HsStateLine=txtline;
} }
void epi_clrTxt4HsStateLine() void epi_clrTxt4HsStateLine() {
{
txt4HsStateLine.clear(); txt4HsStateLine.clear();
} }
//---------------------------------------------------------------------------------------------
// II) Master receive state (empfangenes Telgramm OK? crc? length? ) // II) Master receive state (empfangenes Telgramm OK? crc? length? )
// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp) // Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
static QString txt4masterStateLine; static QString txt4masterStateLine;
QString epi_getTxt4masterStateLine(void) QString epi_getTxt4masterStateLine(void) {
{
return txt4masterStateLine; return txt4masterStateLine;
} }
void gpi_setTxt4masterStateLine(QString txtline) void gpi_setTxt4masterStateLine(QString txtline) {
{
txt4masterStateLine.clear(); txt4masterStateLine.clear();
if (txtline=="") if (txtline=="")
txt4masterStateLine.clear(); txt4masterStateLine.clear();
@ -176,13 +154,10 @@ void gpi_setTxt4masterStateLine(QString txtline)
txt4masterStateLine=txtline; txt4masterStateLine=txtline;
} }
void epi_clrTxt4masterStateLine() void epi_clrTxt4masterStateLine() {
{
txt4masterStateLine.clear(); txt4masterStateLine.clear();
} }
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
// III Slave receive (from Master) OK? if then show results, if not then show errors // III Slave receive (from Master) OK? if then show results, if not then show errors
@ -192,13 +167,11 @@ void epi_clrTxt4masterStateLine()
static QString txt4resultStateLine; static QString txt4resultStateLine;
QString epi_getTxt4resultStateLine(void) QString epi_getTxt4resultStateLine(void) {
{
return txt4resultStateLine; return txt4resultStateLine;
} }
void gpi_setTxt4resultStateLine(QString txtline) void gpi_setTxt4resultStateLine(QString txtline) {
{
txt4resultStateLine.clear(); txt4resultStateLine.clear();
if (txtline=="") if (txtline=="")
txt4resultStateLine.clear(); txt4resultStateLine.clear();
@ -206,26 +179,22 @@ void gpi_setTxt4resultStateLine(QString txtline)
txt4resultStateLine=txtline; txt4resultStateLine=txtline;
} }
void epi_clrTxt4resultStateLine() void epi_clrTxt4resultStateLine() {
{
txt4resultStateLine.clear(); txt4resultStateLine.clear();
} }
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
// IV Statuszeile Empfangsdaten // IV Statuszeile Empfangsdaten
static QString txt4dataLine; static QString txt4dataLine;
QString epi_getTxt4dataStateLine(void) QString epi_getTxt4dataStateLine(void) {
{
// GUI: get Text for serial Comport-State Line // GUI: get Text for serial Comport-State Line
return txt4dataLine; return txt4dataLine;
} }
void gpi_setTxt4dataStateLine(QString txtline) void gpi_setTxt4dataStateLine(QString txtline) {
{
// serial: write Text to be displayed in serial Comport-State line (like "connected") // serial: write Text to be displayed in serial Comport-State line (like "connected")
txt4dataLine.clear(); txt4dataLine.clear();
if (txtline=="") if (txtline=="")
@ -234,8 +203,7 @@ void gpi_setTxt4dataStateLine(QString txtline)
txt4dataLine=txtline; txt4dataLine=txtline;
} }
void epi_clrTxt4dataStateLine() void epi_clrTxt4dataStateLine() {
{
txt4dataLine.clear(); txt4dataLine.clear();
} }
@ -245,16 +213,11 @@ void epi_clrTxt4dataStateLine()
static QString txt4datifReceive; static QString txt4datifReceive;
QString epi_getTxt4datifLine(void) QString epi_getTxt4datifLine(void) {
{
return txt4datifReceive; return txt4datifReceive;
} }
void gpi_setTxt4datifLine(QString txtline) void gpi_setTxt4datifLine(QString txtline) {
{
txt4datifReceive.clear(); txt4datifReceive.clear();
if (txtline=="") if (txtline=="")
txt4datifReceive.clear(); txt4datifReceive.clear();
@ -262,8 +225,7 @@ void gpi_setTxt4datifLine(QString txtline)
txt4datifReceive=txtline; txt4datifReceive=txtline;
} }
void epi_clrTxt4datifLine() void epi_clrTxt4datifLine() {
{
txt4datifReceive.clear(); txt4datifReceive.clear();
} }
@ -272,14 +234,11 @@ void epi_clrTxt4datifLine()
static QString txt4diagWindow; static QString txt4diagWindow;
QString epi_getTxt4RsDiagWin(void) QString epi_getTxt4RsDiagWin(void) {
{
return txt4diagWindow; return txt4diagWindow;
} }
void gpi_setTxt4RsDiagWin(QString txtline) void gpi_setTxt4RsDiagWin(QString txtline) {
{
txt4diagWindow.clear(); txt4diagWindow.clear();
if (txtline=="") if (txtline=="")
txt4diagWindow.clear(); txt4diagWindow.clear();
@ -287,8 +246,7 @@ void gpi_setTxt4RsDiagWin(QString txtline)
txt4diagWindow=txtline; txt4diagWindow=txtline;
} }
void epi_clrTxt4RsDiagWin() void epi_clrTxt4RsDiagWin() {
{
txt4diagWindow.clear(); txt4diagWindow.clear();
} }
@ -296,14 +254,11 @@ void epi_clrTxt4RsDiagWin()
static QString sndTxt4diagWindow; static QString sndTxt4diagWindow;
QString epi_get2ndTxt4RsDiagWin(void) QString epi_get2ndTxt4RsDiagWin(void) {
{
return sndTxt4diagWindow; return sndTxt4diagWindow;
} }
void gpi_set2ndTxt4RsDiagWin(QString txtline) void gpi_set2ndTxt4RsDiagWin(QString txtline) {
{
sndTxt4diagWindow.clear(); sndTxt4diagWindow.clear();
if (txtline=="") if (txtline=="")
sndTxt4diagWindow.clear(); sndTxt4diagWindow.clear();
@ -311,90 +266,61 @@ void gpi_set2ndTxt4RsDiagWin(QString txtline)
sndTxt4diagWindow=txtline; sndTxt4diagWindow=txtline;
} }
void epi_clr2ndTxt4RsDiagWin() void epi_clr2ndTxt4RsDiagWin() {
{
sndTxt4diagWindow.clear(); sndTxt4diagWindow.clear();
} }
// /////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////
// Memory for Slave responses, common data // Memory for Slave responses, common data
// /////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////
void gpi_storeResult_serialTestOK(bool wasOk) {
SharedMemBuffer::getData()->Sdata.serialTestResult = wasOk;
static bool Sdata_serialTestResult;
void gpi_storeResult_serialTestOK(bool wasOk)
{
Sdata_serialTestResult=wasOk;
} }
bool epi_getResult_serialTestOK() bool epi_getResult_serialTestOK() {
{
// retval: true: test was successful, got right response // retval: true: test was successful, got right response
return Sdata_serialTestResult; return SharedMemBuffer::getDataConst()->Sdata.serialTestResult;
} }
// /////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////
// Store received data for hwapi // Store received data for hwapi
// /////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////
void gpi_startNewRequest() {
SharedMemBuffer::getData()->Sdata.pProtResultOk = 0;
static uint8_t Sdata_pProtResultOk;
void gpi_startNewRequest()
{
Sdata_pProtResultOk=0;
} }
void gpi_storeResultOfLastRequest(bool answisok) void gpi_storeResultOfLastRequest(bool answisok) {
{ SharedMemBuffer::getData()->Sdata.pProtResultOk = answisok ? 1 : 2;
if (answisok)
Sdata_pProtResultOk=1;
else
Sdata_pProtResultOk=2;
} }
uint8_t epi_getResultOfLastRequest() uint8_t epi_getResultOfLastRequest() {
{
// retval: 0: in progress 1: OK 2: error // retval: 0: in progress 1: OK 2: error
return Sdata_pProtResultOk; return SharedMemBuffer::getDataConst()->Sdata.pProtResultOk;
} }
void gpi_storeRecPayLoad(uint8_t RdDlen, uint8_t const *receivedData) {
SharedMemBuffer::getData()->Sdata.receivedDataLength
= std::min(RdDlen, (uint8_t)(64));
static uint16_t Sdata_receivedDataLength; memset((char *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]),
static uint8_t Sdata_receivedDataBlock[64]; 0x00, sizeof(SharedMemBuffer::getData()->Sdata.receivedDataBlock));
strncpy((char *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]),
void gpi_storeRecPayLoad(uint8_t RdDlen, uint8_t *receivedData) (char const *)receivedData,
{ sizeof(SharedMemBuffer::getData()->Sdata.receivedDataBlock)-1);
Sdata_receivedDataLength=uint16_t(RdDlen);
if (Sdata_receivedDataLength>64)
Sdata_receivedDataLength=64;
tslib_strclr(Sdata_receivedDataBlock,0,64);
tslib_strcpy(receivedData, Sdata_receivedDataBlock, Sdata_receivedDataLength);
} }
uint16_t epi_getLastPayLoad(uint16_t plBufSiz, uint8_t *payLoad) uint16_t epi_getLastPayLoad(uint16_t plBufSiz, uint8_t *payLoad) {
{
// get data back in *pl, max 64 byte // get data back in *pl, max 64 byte
// retval = nr of bytes received. If host buffer too small then // retval = nr of bytes received. If host buffer too small then
// only plBufSíz bytes are copied to pl // only plBufSíz bytes are copied to pl
// plBufSíz=size of host buffer // plBufSíz=size of host buffer
uint16_t ml=plBufSiz; uint16_t ml = std::min(plBufSiz, (uint16_t)(64));
if (ml>64) ml=64; if (SharedMemBuffer::getDataConst()->Sdata.receivedDataLength < ml) {
if (Sdata_receivedDataLength<ml) ml = SharedMemBuffer::getDataConst()->Sdata.receivedDataLength;
ml=Sdata_receivedDataLength; }
tslib_strcpy(Sdata_receivedDataBlock, payLoad, ml); strncpy((char *)payLoad,
return Sdata_receivedDataLength; (char const *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]),
ml);
return SharedMemBuffer::getDataConst()->Sdata.receivedDataLength;
} }