DCLibraries/src/controlBus.cpp

511 lines
12 KiB
C++
Raw Normal View History

2023-11-08 13:02:26 +01:00
#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
void epi_setSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect)
{
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
}
void epi_closeSerial(void)
{
rs_connect=0;
}
void gpi_serialChanged(void)
{
// serial confirms that port was closed or opened
rs_connect=2; // Flanke, nur 1x öffnen/schließen
}
uint8_t gpi_getSerialConn(void)
{
return rs_connect;
}
int gpi_getBaudNr(void)
{
return rs_baudNr;
}
QString gpi_getComPortName(void)
{
return rs_comportName;
}
//#endif
void gpi_serialIsOpen(bool offen)
{
SharedMem::write()->rs_portIsOpen=offen;
}
bool epi_isSerialPortOpen()
{
// true: port is open false: port is closed
return SharedMem::read()->rs_portIsOpen;
}
// ///////////////////////////////////////////////////////////////////////////////////
// Control transfer gui <--> serial
// ///////////////////////////////////////////////////////////////////////////////////
void epi_startEmmision(bool start)
{
SharedMem::write()->AutoEmissionOn=start;
}
bool gpi_isEmmisionOn(void)
{
// used in HWapi
return SharedMem::read()->AutoEmissionOn;
}
// ///////////////////////////////////////////////////////////////////////////////////
// Status Display gui <--> serial
// ///////////////////////////////////////////////////////////////////////////////////
// linke Spalte, über Connect Button
static QString txt4comStateLine;
QString epi_getTxt4comStateLine(void)
{
// GUI: get Text for serial Comport-State Line
return txt4comStateLine;
}
void gpi_setTxt4comStateLine(QString txtline) // gpi
{
// serial: write Text to be displayed in serial Comport-State line (like "connected")
txt4comStateLine.clear();
if (txtline=="")
txt4comStateLine.clear();
else
txt4comStateLine=txtline;
}
void epi_clrTxt4comStateLine()
{
txt4comStateLine.clear();
}
//---------------------------------------------------------------------------------------------
// rechte Spalte, oberste Statuszeile
// I) "Handshakes" (serial Control) flow.cpp
// geht überhaupt was raus? kommt überhaupt was zurück?
static QString txt4HsStateLine;
QString epi_getTxt4HsStateLine(void)
{
return txt4HsStateLine;
}
void gpi_setTxt4HsStateLine(QString txtline)
{
txt4HsStateLine.clear();
if (txtline=="")
txt4HsStateLine.clear();
else
txt4HsStateLine=txtline;
}
void epi_clrTxt4HsStateLine()
{
txt4HsStateLine.clear();
}
//---------------------------------------------------------------------------------------------
// II) Master receive state (empfangenes Telgramm OK? crc? length? )
// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
static QString txt4masterStateLine;
QString epi_getTxt4masterStateLine(void)
{
return txt4masterStateLine;
}
void gpi_setTxt4masterStateLine(QString txtline)
{
txt4masterStateLine.clear();
if (txtline=="")
txt4masterStateLine.clear();
else
txt4masterStateLine=txtline;
}
void epi_clrTxt4masterStateLine()
{
txt4masterStateLine.clear();
}
//---------------------------------------------------------------------------------------------
// 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
static QString txt4resultStateLine;
QString epi_getTxt4resultStateLine(void)
{
return txt4resultStateLine;
}
void gpi_setTxt4resultStateLine(QString txtline)
{
txt4resultStateLine.clear();
if (txtline=="")
txt4resultStateLine.clear();
else
txt4resultStateLine=txtline;
}
void epi_clrTxt4resultStateLine()
{
txt4resultStateLine.clear();
}
//---------------------------------------------------------------------------------------------
// IV Statuszeile Empfangsdaten
static QString txt4dataLine;
QString epi_getTxt4dataStateLine(void)
{
// GUI: get Text for serial Comport-State Line
return txt4dataLine;
}
void gpi_setTxt4dataStateLine(QString txtline)
{
// serial: write Text to be displayed in serial Comport-State line (like "connected")
txt4dataLine.clear();
if (txtline=="")
txt4dataLine.clear();
else
txt4dataLine=txtline;
}
void epi_clrTxt4dataStateLine()
{
txt4dataLine.clear();
}
//---------------------------------------------------------------------------------------------
// 5. Zeile: Datif Ergebnis, Daten brauchbar?
static QString txt4datifReceive;
QString epi_getTxt4datifLine(void)
{
return txt4datifReceive;
}
void gpi_setTxt4datifLine(QString txtline)
{
txt4datifReceive.clear();
if (txtline=="")
txt4datifReceive.clear();
else
txt4datifReceive=txtline;
}
void epi_clrTxt4datifLine()
{
txt4datifReceive.clear();
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
static QString txt4diagWindow;
QString epi_getTxt4RsDiagWin(void)
{
return txt4diagWindow;
}
void gpi_setTxt4RsDiagWin(QString txtline)
{
txt4diagWindow.clear();
if (txtline=="")
txt4diagWindow.clear();
else
txt4diagWindow=txtline;
}
void epi_clrTxt4RsDiagWin()
{
txt4diagWindow.clear();
}
//---------------------------------------------------------------------------------------------
static QString sndTxt4diagWindow;
QString epi_get2ndTxt4RsDiagWin(void)
{
return sndTxt4diagWindow;
}
void gpi_set2ndTxt4RsDiagWin(QString txtline)
{
sndTxt4diagWindow.clear();
if (txtline=="")
sndTxt4diagWindow.clear();
else
sndTxt4diagWindow=txtline;
}
void epi_clr2ndTxt4RsDiagWin()
{
sndTxt4diagWindow.clear();
}
// ///////////////////////////////////////////////////////////////////////////////////
// Memory for Slave responses, common data
// ///////////////////////////////////////////////////////////////////////////////////
//static bool Sdata_serialTestResult;
void gpi_storeResult_serialTestOK(bool wasOk)
{
//Sdata_serialTestResult=wasOk;
SharedMem::write()->Sdata_serialTestResult=wasOk;
}
bool epi_getResult_serialTestOK()
{
// retval: true: test was successful, got right response
//return Sdata_serialTestResult;
return SharedMem::read()->Sdata_serialTestResult;
}
// ///////////////////////////////////////////////////////////////////////////////////
// Store received data for hwapi
// ///////////////////////////////////////////////////////////////////////////////////
//static uint8_t Sdata_pProtResultOk;
void gpi_startNewRequest()
{
//Sdata_pProtResultOk=0;
SharedMem::write()->Sdata_pProtResultOk=0;
SharedMem::write()->Sdata_lastResult=0;
}
void gpi_storeResultOfLastRequest(bool answisok)
{
if (answisok)
//Sdata_pProtResultOk=1;
SharedMem::write()->Sdata_pProtResultOk=1;
else
//Sdata_pProtResultOk=2;
SharedMem::write()->Sdata_pProtResultOk=2;
}
uint8_t epi_getResultOfLastRequest()
{
// retval: 0: in progress 1: OK 2: error
//return Sdata_pProtResultOk;
return SharedMem::read()->Sdata_pProtResultOk;
}
//static uint16_t Sdata_receivedDataLength;
//static uint8_t Sdata_receivedDataBlock[64];
void gpi_storeRecPayLoad(uint8_t RdDlen, uint8_t *receivedData)
{
SharedMem::write()->Sdata_receivedDataLength=uint16_t(RdDlen);
if (SharedMem::read()->Sdata_receivedDataLength>64)
SharedMem::write()->Sdata_receivedDataLength=64;
tslib_strclr(SharedMem::write()->Sdata_receivedDataBlock,0,64);
tslib_strcpy(receivedData, SharedMem::write()->Sdata_receivedDataBlock, SharedMem::read()->Sdata_receivedDataLength);
}
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=plBufSiz, nn;
if (ml>64) ml=64;
if (SharedMem::read()->Sdata_receivedDataLength<ml)
ml=SharedMem::read()->Sdata_receivedDataLength;
//tslib_strcpy(SharedMem::read()->Sdata_receivedDataBlock, payLoad, ml);
for (nn=0; nn<ml; nn++)
payLoad[nn]=SharedMem::read()->Sdata_receivedDataBlock[nn];
return SharedMem::read()->Sdata_receivedDataLength;
}
//static uint8_t ndbs, pari, nsb, br;
void gpi_storeSlaveSerParams(uint8_t slaveBaudRate, uint8_t NrDataBits,
uint8_t parity, uint8_t NrStopBits)
{
// store numbers
SharedMem::write()->ndbs=NrDataBits;
SharedMem::write()->pari=parity;
SharedMem::write()->nsb=NrStopBits;
SharedMem::write()->br=slaveBaudRate;
}
void epi_getSlaveSerParams(uint8_t *slaveBaudRate, uint8_t *NrDataBits,
uint8_t *parity, uint8_t *NrStopBits)
{
*NrDataBits=SharedMem::read()->ndbs;
*parity=SharedMem::read()->pari;
*NrStopBits=SharedMem::read()->nsb;
*slaveBaudRate=SharedMem::read()->br;
}
QString epi_getSlaveParamSTR()
{
QString mySt;
char ctmp;
// uint8_t ndbs;
// uint8_t pari;
// uint8_t nsb;
// uint8_t br;
mySt.clear();
// br=SharedMemBuffer::read()->br;
// ndbs=SharedMemBuffer::read()->ndbs;
// pari =SharedMemBuffer::read()->pari;
// nsb=SharedMemBuffer::read()->nsb;
switch (SharedMem::read()->br)
{
case 1: mySt="1200 ";break;
case 2: mySt="9600 ";break;
case 3: mySt="19200 ";break;
case 4: mySt="38400 ";break;
case 5: mySt="57600 ";break;
case 6: mySt="115200 ";break;
}
ctmp=SharedMem::read()->ndbs;
ctmp+=0x30;
mySt.append(ctmp);
ctmp=SharedMem::read()->pari;
mySt.append(ctmp);
ctmp=SharedMem::read()->nsb;
ctmp+=0x30;
mySt.append(ctmp);
//mySt="Hallo";
return mySt;
}
//void gpi_startNewRequest(): SharedMem::write()->Sdata_lastResult=0;
void gpi_storeLastResult(uint8_t letzteAntwort)
{
SharedMem::write()->Sdata_lastResult=letzteAntwort;
}
uint8_t epi_getLastResult()
{
return SharedMem::read()->Sdata_lastResult;
}
void epi_startSupervision()
{
SharedMem::write()->Sdata_startSV=true;
}
bool gpi_wantToResetSupervision()
{
bool chk=SharedMem::read()->Sdata_startSV;
SharedMem::write()->Sdata_startSV=false;
return chk;
}
void gpi_storeOverallResult(uint8_t letzteAntwort)
{
SharedMem::write()->Sdata_OverallResult=letzteAntwort;
}
uint8_t epi_getBatchResult()
{
return SharedMem::read()->Sdata_OverallResult;
}