311 lines
12 KiB
C++
311 lines
12 KiB
C++
#include <stdint.h>
|
|
#include <algorithm>
|
|
|
|
#include <QString>
|
|
#include <QDebug>
|
|
#include "tslib.h"
|
|
#include "shared_mem_buffer.h"
|
|
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
// control serial interface gui <--> serial
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
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);
|
|
|
|
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);
|
|
|
|
SharedMemBuffer::getData()->rs.baudNr = BaudNr;
|
|
SharedMemBuffer::getData()->rs.connect = connect;
|
|
}
|
|
|
|
void epi_closeSerial(void) {
|
|
SharedMemBuffer::getData()->rs.connect = 0;
|
|
}
|
|
|
|
void gpi_serialChanged(void) {
|
|
// serial confirms that port was closed or opened
|
|
// rs_connect=2; // Flanke, nur 1x öffnen/schließen
|
|
SharedMemBuffer::getData()->rs.connect = 2;
|
|
}
|
|
|
|
uint8_t gpi_getSerialConn(void) {
|
|
return SharedMemBuffer::getDataConst()->rs.connect;
|
|
}
|
|
|
|
int gpi_getBaudNr(void) {
|
|
return SharedMemBuffer::getDataConst()->rs.baudNr;
|
|
}
|
|
|
|
QString gpi_getComPortName(void) {
|
|
return SharedMemBuffer::getDataConst()->rs.comportName;
|
|
}
|
|
|
|
void gpi_serialIsOpen(bool offen) {
|
|
SharedMemBuffer::getData()->rs.portIsOpen = offen;
|
|
}
|
|
|
|
bool epi_isSerialPortOpen() {
|
|
// true: port is open false: port is closed
|
|
return SharedMemBuffer::getDataConst()->rs.portIsOpen;
|
|
}
|
|
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
// Control transfer gui <--> serial
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void epi_startEmmision(char start) {
|
|
SharedMemBuffer::getData()->AutoEmissionOn = start;
|
|
}
|
|
|
|
bool gpi_isEmmisionOn(void) {
|
|
return SharedMemBuffer::getDataConst()->AutoEmissionOn;
|
|
}
|
|
|
|
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
|
|
}
|
|
return SharedMemBuffer::getDataConst()->datif.sendingPeriod;
|
|
}
|
|
|
|
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 SharedMemBuffer::getDataConst()->datif.sendingPer_changed;
|
|
}
|
|
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
// Status Display gui <--> serial
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// linke Spalte, über Connect Button
|
|
QString epi_getTxt4comStateLine(void) {
|
|
// GUI: get Text for serial Comport-State Line
|
|
return SharedMemBuffer::getDataConst()->txt4.comStateLine;
|
|
}
|
|
|
|
void gpi_setTxt4comStateLine(QString txtline) {
|
|
// serial: write Text to be displayed in serial Comport-State line (like "connected")
|
|
memset(SharedMemBuffer::getData()->txt4.comStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.comStateLine));
|
|
memcpy(SharedMemBuffer::getData()->txt4.comStateLine,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.comStateLine)-1);
|
|
}
|
|
|
|
void epi_clrTxt4comStateLine() {
|
|
memset(SharedMemBuffer::getData()->txt4.comStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.comStateLine));
|
|
}
|
|
|
|
// rechte Spalte, oberste Statuszeile
|
|
// I) "Handshakes" (serial Control) flow.cpp
|
|
// geht überhaupt was raus? kommt überhaupt was zurück?
|
|
QString epi_getTxt4HsStateLine(void) {
|
|
return SharedMemBuffer::getDataConst()->txt4.HsStateLine;
|
|
}
|
|
|
|
void gpi_setTxt4HsStateLine(QString txtline) {
|
|
// serial: write Text to be displayed in serial Comport-State line (like "connected")
|
|
memset(SharedMemBuffer::getData()->txt4.HsStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.HsStateLine));
|
|
memcpy(SharedMemBuffer::getData()->txt4.HsStateLine,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.HsStateLine)-1);
|
|
}
|
|
|
|
void epi_clrTxt4HsStateLine() {
|
|
memset(SharedMemBuffer::getData()->txt4.HsStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.HsStateLine));
|
|
}
|
|
|
|
// II) Master receive state (empfangenes Telgramm OK? crc? length? )
|
|
// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
|
|
QString epi_getTxt4masterStateLine(void) {
|
|
return SharedMemBuffer::getDataConst()->txt4.masterStateLine;
|
|
}
|
|
|
|
void gpi_setTxt4masterStateLine(QString txtline) {
|
|
memset(SharedMemBuffer::getData()->txt4.masterStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.masterStateLine));
|
|
memcpy(SharedMemBuffer::getData()->txt4.masterStateLine,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.masterStateLine)-1);
|
|
}
|
|
|
|
void epi_clrTxt4masterStateLine() {
|
|
memset(SharedMemBuffer::getData()->txt4.masterStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.masterStateLine));
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------
|
|
|
|
// III Slave receive (from Master) OK? if then show results, if not then show errors
|
|
// entweder Empfangsfehler anzeigen (crc? length?) oder result OUT-OK, OUT_ERR, IN_OK, IN_ERR
|
|
// Hintergrund: wenn der Slave Fehler im Master-Telegramm gefunden hat, dann kann er es auch
|
|
// nicht verwenden und nichts ausgeben oder einlesen
|
|
QString epi_getTxt4resultStateLine(void) {
|
|
return SharedMemBuffer::getDataConst()->txt4.resultStateLine;
|
|
}
|
|
|
|
void gpi_setTxt4resultStateLine(QString txtline) {
|
|
memset(SharedMemBuffer::getData()->txt4.resultStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.resultStateLine));
|
|
memcpy(SharedMemBuffer::getData()->txt4.resultStateLine,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.resultStateLine)-1);
|
|
}
|
|
|
|
void epi_clrTxt4resultStateLine() {
|
|
memset(SharedMemBuffer::getData()->txt4.resultStateLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.resultStateLine));
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------
|
|
// IV Statuszeile Empfangsdaten
|
|
QString epi_getTxt4dataStateLine(void) {
|
|
// GUI: get Text for serial Comport-State Line
|
|
return SharedMemBuffer::getDataConst()->txt4.dataLine;
|
|
}
|
|
|
|
void gpi_setTxt4dataStateLine(QString txtline) {
|
|
// serial: write Text to be displayed in serial Comport-State line (like "connected")
|
|
memset(SharedMemBuffer::getData()->txt4.dataLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.dataLine));
|
|
memcpy(SharedMemBuffer::getData()->txt4.dataLine,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.dataLine)-1);
|
|
}
|
|
|
|
void epi_clrTxt4dataStateLine() {
|
|
memset(SharedMemBuffer::getData()->txt4.dataLine,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.dataLine));
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------
|
|
|
|
// 5. Zeile: Datif Ergebnis, Daten brauchbar?
|
|
QString epi_getTxt4datifLine(void) {
|
|
return SharedMemBuffer::getDataConst()->txt4.datifReceive;
|
|
}
|
|
|
|
void gpi_setTxt4datifLine(QString txtline) {
|
|
memset(SharedMemBuffer::getData()->txt4.datifReceive,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.datifReceive));
|
|
memcpy(SharedMemBuffer::getData()->txt4.datifReceive,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.datifReceive)-1);
|
|
}
|
|
|
|
void epi_clrTxt4datifLine() {
|
|
memset(SharedMemBuffer::getData()->txt4.datifReceive,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.datifReceive));
|
|
}
|
|
|
|
QString epi_getTxt4RsDiagWin(void) {
|
|
return SharedMemBuffer::getDataConst()->txt4.diagWindow;
|
|
}
|
|
|
|
void gpi_setTxt4RsDiagWin(QString txtline) {
|
|
memset(SharedMemBuffer::getData()->txt4.diagWindow,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.diagWindow));
|
|
memcpy(SharedMemBuffer::getData()->txt4.diagWindow,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.diagWindow)-1);
|
|
}
|
|
|
|
void epi_clrTxt4RsDiagWin() {
|
|
memset(SharedMemBuffer::getData()->txt4.diagWindow,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.diagWindow));
|
|
}
|
|
|
|
QString epi_get2ndTxt4RsDiagWin(void) {
|
|
return SharedMemBuffer::getDataConst()->txt4.sndDiagWindow;
|
|
}
|
|
|
|
void gpi_set2ndTxt4RsDiagWin(QString txtline) {
|
|
memset(SharedMemBuffer::getData()->txt4.sndDiagWindow,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.sndDiagWindow));
|
|
memcpy(SharedMemBuffer::getData()->txt4.sndDiagWindow,
|
|
txtline.toStdString().c_str(),
|
|
sizeof(SharedMemBuffer::getData()->txt4.sndDiagWindow)-1);
|
|
}
|
|
|
|
void epi_clr2ndTxt4RsDiagWin() {
|
|
memset(SharedMemBuffer::getData()->txt4.sndDiagWindow,
|
|
0x00, sizeof(SharedMemBuffer::getData()->txt4.sndDiagWindow));
|
|
}
|
|
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
// Memory for Slave responses, common data
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
void gpi_storeResult_serialTestOK(bool wasOk) {
|
|
SharedMemBuffer::getData()->Sdata.serialTestResult = wasOk;
|
|
}
|
|
|
|
bool epi_getResult_serialTestOK() {
|
|
// retval: true: test was successful, got right response
|
|
return SharedMemBuffer::getDataConst()->Sdata.serialTestResult;
|
|
}
|
|
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
// Store received data for hwapi
|
|
// ///////////////////////////////////////////////////////////////////////////////////
|
|
void gpi_startNewRequest() {
|
|
SharedMemBuffer::getData()->Sdata.pProtResultOk = 0;
|
|
}
|
|
|
|
void gpi_storeResultOfLastRequest(bool answisok) {
|
|
SharedMemBuffer::getData()->Sdata.pProtResultOk = answisok ? 1 : 2;
|
|
}
|
|
|
|
uint8_t epi_getResultOfLastRequest() {
|
|
// retval: 0: in progress 1: OK 2: error
|
|
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));
|
|
memset((char *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]),
|
|
0x00, sizeof(SharedMemBuffer::getData()->Sdata.receivedDataBlock));
|
|
strncpy((char *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]),
|
|
(char const *)receivedData,
|
|
sizeof(SharedMemBuffer::getData()->Sdata.receivedDataBlock)-1);
|
|
}
|
|
|
|
uint16_t epi_getLastPayLoad(uint16_t plBufSiz, uint8_t *payLoad) {
|
|
// get data back in *pl, max 64 byte
|
|
// retval = nr of bytes received. If host buffer too small then
|
|
// only plBufSíz bytes are copied to pl
|
|
// plBufSíz=size of host buffer
|
|
|
|
uint16_t ml = std::min(plBufSiz, (uint16_t)(64));
|
|
if (SharedMemBuffer::getDataConst()->Sdata.receivedDataLength < ml) {
|
|
ml = SharedMemBuffer::getDataConst()->Sdata.receivedDataLength;
|
|
}
|
|
strncpy((char *)payLoad,
|
|
(char const *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]),
|
|
ml);
|
|
|
|
return SharedMemBuffer::getDataConst()->Sdata.receivedDataLength;
|
|
}
|