Shift several device controller related variables to shared memory.

This commit is contained in:
Gerhard Hoffmann 2023-04-18 12:20:23 +02:00
parent ef7932102f
commit c724b5b9fb

View File

@ -2,129 +2,107 @@
#include <QString>
#include <QDebug>
#include "tslib.h"
#include "shared_mem_buffer.h"
//#include "controlBus.h"
// ///////////////////////////////////////////////////////////////////////////////////
// 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
//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, QString BaudStr, QString ComName, uint8_t connect)
{
// qDebug() << "ENTER" << BaudNr << BaudStr << ComName << connect;
void epi_setSerial(int BaudNr,
QString BaudStr,
QString ComName,
uint8_t connect) {
memset(&SharedMemBuffer::getData()->rs.comportName[0], 0x00,
sizeof(SharedMemBuffer::getData()->rs.comportName));
strncpy(SharedMemBuffer::getData()->rs.comportName,
ComName.toStdString().c_str(),
sizeof(SharedMemBuffer::getData()->rs.comportName)-1);
rs_comportName = ComName;
rs_baudStr = BaudStr;
rs_baudNr = BaudNr; // 0=1200 1=9600 2=19200 3=38400 4=57600 5=115200 oder -1
rs_connect = connect; // 0/1
memset(&SharedMemBuffer::getData()->rs.baudStr[0], 0x00,
sizeof(SharedMemBuffer::getData()->rs.baudStr));
strncpy(SharedMemBuffer::getData()->rs.baudStr,
BaudStr.toStdString().c_str(),
sizeof(SharedMemBuffer::getData()->rs.baudStr)-1);
// qDebug() << "LEAVE" << rs_baudNr << rs_baudStr << rs_comportName << rs_connect;
SharedMemBuffer::getData()->rs.baudNr = BaudNr;
SharedMemBuffer::getData()->rs.connect = connect;
}
void epi_closeSerial(void)
{
rs_connect=0;
// qDebug() << "ENTER/LEAVE rc_connect=0";
void epi_closeSerial(void) {
SharedMemBuffer::getData()->rs.connect = 0;
}
void gpi_serialChanged(void)
{
void gpi_serialChanged(void) {
// serial confirms that port was closed or opened
rs_connect=2; // Flanke, nur 1x öffnen/schließen
//qDebug() << "ENTER/LEAVE rc_connect=2";
// rs_connect=2; // Flanke, nur 1x öffnen/schließen
SharedMemBuffer::getData()->rs.connect = 2;
}
uint8_t gpi_getSerialConn(void)
{
return rs_connect;
uint8_t gpi_getSerialConn(void) {
return SharedMemBuffer::getDataConst()->rs.connect;
}
int gpi_getBaudNr(void)
{
return rs_baudNr;
int gpi_getBaudNr(void) {
return SharedMemBuffer::getDataConst()->rs.baudNr;
}
QString gpi_getComPortName(void)
{
return rs_comportName;
QString gpi_getComPortName(void) {
return SharedMemBuffer::getDataConst()->rs.comportName;
}
static bool rs_portIsOpen;
void gpi_serialIsOpen(bool offen)
{
//qDebug() << "ENTER/LEAVE offen=" << offen;
rs_portIsOpen=offen;
void gpi_serialIsOpen(bool offen) {
SharedMemBuffer::getData()->rs.portIsOpen = offen;
}
bool epi_isSerialPortOpen()
{
bool epi_isSerialPortOpen() {
// true: port is open false: port is closed
//qDebug() << "ENTER/LEAVE offen=" << rs_portIsOpen;
return rs_portIsOpen;
return SharedMemBuffer::getDataConst()->rs.portIsOpen;
}
// ///////////////////////////////////////////////////////////////////////////////////
// Control transfer gui <--> serial
// ///////////////////////////////////////////////////////////////////////////////////
static char AutoEmissionOn; // 1: zyklisch Anfragen zum Slave senden
void epi_startEmmision(char start)
{
AutoEmissionOn=start;
void epi_startEmmision(char start) {
SharedMemBuffer::getData()->AutoEmissionOn = start;
}
bool gpi_isEmmisionOn(void)
{
return AutoEmissionOn;
bool gpi_isEmmisionOn(void) {
return SharedMemBuffer::getDataConst()->AutoEmissionOn;
}
//-----------------------------------------------------
static uint16_t datif_sendingPeriod;
static bool datif_sendingPer_changed;
uint16_t gpi_getPeriodicSendTimeVal()
{
datif_sendingPer_changed=0;
if (datif_sendingPeriod<3 || datif_sendingPeriod>10000)
uint16_t gpi_getPeriodicSendTimeVal() {
SharedMemBuffer::getData()->datif.sendingPer_changed = 0;
if ((SharedMemBuffer::getDataConst()->datif.sendingPeriod < 3) ||
(SharedMemBuffer::getDataConst()->datif.sendingPeriod > 10000)) {
return 130; // ms, default
else
return datif_sendingPeriod;
}
return SharedMemBuffer::getDataConst()->datif.sendingPeriod;
}
void epi_setPeriodicSendTimeVal(uint16_t val)
{
if (val>=3 && val<10000)
{
datif_sendingPer_changed=1;
datif_sendingPeriod=val;
void epi_setPeriodicSendTimeVal(uint16_t val) {
if (val>=3 && val<10000) {
SharedMemBuffer::getData()->datif.sendingPer_changed = 1;
SharedMemBuffer::getData()->datif.sendingPeriod = val;
}
}
bool gpi_PeriodicSendTimeHasChanged()
{
return datif_sendingPer_changed;
bool gpi_PeriodicSendTimeHasChanged() {
return SharedMemBuffer::getDataConst()->datif.sendingPer_changed;
}
//-----------------------------------------------------
//-----------------------------------------------------
// ///////////////////////////////////////////////////////////////////////////////////
// Status Display gui <--> serial
// ///////////////////////////////////////////////////////////////////////////////////
// linke Spalte, über Connect Button
static QString txt4comStateLine;