Merged new function to DCPlugin (01.06.2023).
This commit is contained in:
34
src/com.cpp
34
src/com.cpp
@@ -93,34 +93,29 @@ T_com::~T_com()
|
||||
|
||||
void T_com::ser_ISR100ms()
|
||||
{
|
||||
//qDebug() << "~~>LIB" << "ENTER...";
|
||||
// call every 100ms to check if user(HMI) wants to connect or disconnect
|
||||
|
||||
//qDebug() << "~~>LIB" << "checking connect button... " ;
|
||||
|
||||
uint8_t chkConn = gpi_getSerialConn(); // from global GUI buffer (Sdata)
|
||||
|
||||
//qDebug() << "~~>LIB" << "checking connect button... " << chkConn;
|
||||
|
||||
switch (chkConn)
|
||||
{
|
||||
case 0: // 0 button "connect" was just released
|
||||
//qDebug() << "close serial port" << chkConn;
|
||||
closeSerialPort();
|
||||
gpi_serialChanged(); // set chkConn to 2, thus getting edge
|
||||
break;
|
||||
case 1: // 1 button "connect" was just pressed
|
||||
//qDebug() << "open serial port" << chkConn;
|
||||
open_Serial_Port();
|
||||
gpi_serialChanged(); // set chkConn to 2, thus getting edge
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (CatSerial->isOpen()) {
|
||||
if (CatSerial->isOpen())
|
||||
gpi_serialIsOpen(true);
|
||||
} else {
|
||||
else
|
||||
gpi_serialIsOpen(false);
|
||||
}
|
||||
|
||||
//qDebug() << "LEAVE " << chkConn;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------
|
||||
@@ -129,24 +124,17 @@ void T_com::ser_ISR100ms()
|
||||
|
||||
char T_com::open_Serial_Port()
|
||||
{
|
||||
//qDebug() << "ENTER";
|
||||
|
||||
bool ret;
|
||||
QString myString=nullptr, myPortName=nullptr, myBaudStr=nullptr;
|
||||
int myBaudNr;
|
||||
|
||||
if (CatSerial->isOpen()) {
|
||||
qDebug() << "!!!IS OPEN!!!";
|
||||
if (CatSerial->isOpen())
|
||||
return 0; // opening twice is not allowed
|
||||
}
|
||||
|
||||
//qDebug() << "connecting..." << myPortName;
|
||||
myPortName=gpi_getComPortName(); // was selected and stored from GUI
|
||||
CatSerial->setPortName(myPortName);
|
||||
myBaudNr=gpi_getBaudNr(); // was selected and stored from GUI
|
||||
|
||||
//qDebug() << "myPortName" << myPortName << ", myBaudNr" << myBaudNr;
|
||||
|
||||
switch (myBaudNr)
|
||||
{
|
||||
// 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
||||
@@ -179,9 +167,6 @@ char T_com::open_Serial_Port()
|
||||
myString.append(CatSerial->errorString());
|
||||
qDebug() << myString;
|
||||
gpi_setTxt4comStateLine(myString);
|
||||
|
||||
//qDebug() << "LEAVE";
|
||||
|
||||
return 0;
|
||||
} else
|
||||
{
|
||||
@@ -197,14 +182,11 @@ char T_com::open_Serial_Port()
|
||||
|
||||
}
|
||||
|
||||
//qDebug() << "LEAVE";
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void T_com::closeSerialPort()
|
||||
{
|
||||
//qDebug() << "ENTER";
|
||||
|
||||
if (CatSerial->isOpen())
|
||||
{
|
||||
qDebug() << "closing connection";
|
||||
@@ -213,8 +195,6 @@ void T_com::closeSerialPort()
|
||||
gpi_setTxt4RsDiagWin("closed");
|
||||
|
||||
}
|
||||
|
||||
//qDebug() << "LEAVE";
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,110 +1,134 @@
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include "tslib.h"
|
||||
#include "shared_mem_buffer.h"
|
||||
//#include "controlBus.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);
|
||||
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
|
||||
|
||||
SharedMemBuffer::getData()->rs.baudNr = BaudNr;
|
||||
SharedMemBuffer::getData()->rs.connect = connect;
|
||||
}
|
||||
|
||||
void epi_closeSerial(void) {
|
||||
SharedMemBuffer::getData()->rs.connect = 0;
|
||||
void epi_closeSerial(void)
|
||||
{
|
||||
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
|
||||
SharedMemBuffer::getData()->rs.connect = 2;
|
||||
rs_connect=2; // Flanke, nur 1x öffnen/schließen
|
||||
}
|
||||
|
||||
uint8_t gpi_getSerialConn(void) {
|
||||
return SharedMemBuffer::getDataConst()->rs.connect;
|
||||
uint8_t gpi_getSerialConn(void)
|
||||
{
|
||||
return rs_connect;
|
||||
}
|
||||
|
||||
int gpi_getBaudNr(void) {
|
||||
return SharedMemBuffer::getDataConst()->rs.baudNr;
|
||||
|
||||
int gpi_getBaudNr(void)
|
||||
{
|
||||
return rs_baudNr;
|
||||
}
|
||||
|
||||
QString gpi_getComPortName(void) {
|
||||
return SharedMemBuffer::getDataConst()->rs.comportName;
|
||||
QString gpi_getComPortName(void)
|
||||
{
|
||||
return rs_comportName;
|
||||
}
|
||||
|
||||
void gpi_serialIsOpen(bool offen) {
|
||||
SharedMemBuffer::getData()->rs.portIsOpen = offen;
|
||||
static bool rs_portIsOpen;
|
||||
|
||||
void gpi_serialIsOpen(bool offen)
|
||||
{
|
||||
rs_portIsOpen=offen;
|
||||
}
|
||||
|
||||
bool epi_isSerialPortOpen() {
|
||||
bool epi_isSerialPortOpen()
|
||||
{
|
||||
// true: port is open false: port is closed
|
||||
return SharedMemBuffer::getDataConst()->rs.portIsOpen;
|
||||
return rs_portIsOpen;
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////////////
|
||||
// Control transfer gui <--> serial
|
||||
// ///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void epi_startEmmision(char start) {
|
||||
SharedMemBuffer::getData()->AutoEmissionOn = start;
|
||||
|
||||
static char AutoEmissionOn; // 1: zyklisch Anfragen zum Slave senden
|
||||
|
||||
void epi_startEmmision(char start)
|
||||
{
|
||||
AutoEmissionOn=start;
|
||||
}
|
||||
|
||||
bool gpi_isEmmisionOn(void) {
|
||||
return SharedMemBuffer::getDataConst()->AutoEmissionOn;
|
||||
bool gpi_isEmmisionOn(void)
|
||||
{
|
||||
return AutoEmissionOn;
|
||||
}
|
||||
|
||||
uint16_t gpi_getPeriodicSendTimeVal() {
|
||||
SharedMemBuffer::getData()->datif.sendingPer_changed = 0;
|
||||
if ((SharedMemBuffer::getDataConst()->datif.sendingPeriod < 3) ||
|
||||
(SharedMemBuffer::getDataConst()->datif.sendingPeriod > 10000)) {
|
||||
//-----------------------------------------------------
|
||||
|
||||
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)
|
||||
return 130; // ms, default
|
||||
}
|
||||
return SharedMemBuffer::getDataConst()->datif.sendingPeriod;
|
||||
else
|
||||
return datif_sendingPeriod;
|
||||
}
|
||||
|
||||
void epi_setPeriodicSendTimeVal(uint16_t val) {
|
||||
if (val>=3 && val<10000) {
|
||||
SharedMemBuffer::getData()->datif.sendingPer_changed = 1;
|
||||
SharedMemBuffer::getData()->datif.sendingPeriod = val;
|
||||
void epi_setPeriodicSendTimeVal(uint16_t val)
|
||||
{
|
||||
if (val>=3 && val<10000)
|
||||
{
|
||||
datif_sendingPer_changed=1;
|
||||
datif_sendingPeriod=val;
|
||||
}
|
||||
}
|
||||
|
||||
bool gpi_PeriodicSendTimeHasChanged() {
|
||||
return SharedMemBuffer::getDataConst()->datif.sendingPer_changed;
|
||||
bool gpi_PeriodicSendTimeHasChanged()
|
||||
{
|
||||
return datif_sendingPer_changed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////////////
|
||||
// Status Display gui <--> serial
|
||||
// ///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// linke Spalte, über Connect Button
|
||||
static QString txt4comStateLine;
|
||||
|
||||
QString epi_getTxt4comStateLine(void) {
|
||||
QString epi_getTxt4comStateLine(void)
|
||||
{
|
||||
// GUI: get Text for serial Comport-State Line
|
||||
return txt4comStateLine;
|
||||
}
|
||||
|
||||
void gpi_setTxt4comStateLine(QString txtline) {
|
||||
void gpi_setTxt4comStateLine(QString txtline) // gpi
|
||||
{
|
||||
// serial: write Text to be displayed in serial Comport-State line (like "connected")
|
||||
txt4comStateLine.clear();
|
||||
if (txtline=="")
|
||||
@@ -113,20 +137,26 @@ void gpi_setTxt4comStateLine(QString txtline) {
|
||||
txt4comStateLine=txtline;
|
||||
}
|
||||
|
||||
void epi_clrTxt4comStateLine() {
|
||||
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) {
|
||||
QString epi_getTxt4HsStateLine(void)
|
||||
{
|
||||
return txt4HsStateLine;
|
||||
}
|
||||
|
||||
void gpi_setTxt4HsStateLine(QString txtline) {
|
||||
void gpi_setTxt4HsStateLine(QString txtline)
|
||||
{
|
||||
txt4HsStateLine.clear();
|
||||
if (txtline=="")
|
||||
txt4HsStateLine.clear();
|
||||
@@ -134,19 +164,26 @@ void gpi_setTxt4HsStateLine(QString txtline) {
|
||||
txt4HsStateLine=txtline;
|
||||
}
|
||||
|
||||
void epi_clrTxt4HsStateLine() {
|
||||
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) {
|
||||
QString epi_getTxt4masterStateLine(void)
|
||||
{
|
||||
return txt4masterStateLine;
|
||||
}
|
||||
|
||||
void gpi_setTxt4masterStateLine(QString txtline) {
|
||||
void gpi_setTxt4masterStateLine(QString txtline)
|
||||
{
|
||||
txt4masterStateLine.clear();
|
||||
if (txtline=="")
|
||||
txt4masterStateLine.clear();
|
||||
@@ -154,10 +191,13 @@ void gpi_setTxt4masterStateLine(QString txtline) {
|
||||
txt4masterStateLine=txtline;
|
||||
}
|
||||
|
||||
void epi_clrTxt4masterStateLine() {
|
||||
void epi_clrTxt4masterStateLine()
|
||||
{
|
||||
txt4masterStateLine.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
|
||||
// III Slave receive (from Master) OK? if then show results, if not then show errors
|
||||
@@ -167,11 +207,13 @@ void epi_clrTxt4masterStateLine() {
|
||||
|
||||
static QString txt4resultStateLine;
|
||||
|
||||
QString epi_getTxt4resultStateLine(void) {
|
||||
QString epi_getTxt4resultStateLine(void)
|
||||
{
|
||||
return txt4resultStateLine;
|
||||
}
|
||||
|
||||
void gpi_setTxt4resultStateLine(QString txtline) {
|
||||
void gpi_setTxt4resultStateLine(QString txtline)
|
||||
{
|
||||
txt4resultStateLine.clear();
|
||||
if (txtline=="")
|
||||
txt4resultStateLine.clear();
|
||||
@@ -179,22 +221,26 @@ void gpi_setTxt4resultStateLine(QString txtline) {
|
||||
txt4resultStateLine=txtline;
|
||||
}
|
||||
|
||||
void epi_clrTxt4resultStateLine() {
|
||||
void epi_clrTxt4resultStateLine()
|
||||
{
|
||||
txt4resultStateLine.clear();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
|
||||
// IV Statuszeile Empfangsdaten
|
||||
static QString txt4dataLine;
|
||||
|
||||
QString epi_getTxt4dataStateLine(void) {
|
||||
QString epi_getTxt4dataStateLine(void)
|
||||
{
|
||||
// GUI: get Text for serial Comport-State Line
|
||||
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")
|
||||
txt4dataLine.clear();
|
||||
if (txtline=="")
|
||||
@@ -203,7 +249,8 @@ void gpi_setTxt4dataStateLine(QString txtline) {
|
||||
txt4dataLine=txtline;
|
||||
}
|
||||
|
||||
void epi_clrTxt4dataStateLine() {
|
||||
void epi_clrTxt4dataStateLine()
|
||||
{
|
||||
txt4dataLine.clear();
|
||||
}
|
||||
|
||||
@@ -213,11 +260,16 @@ void epi_clrTxt4dataStateLine() {
|
||||
|
||||
static QString txt4datifReceive;
|
||||
|
||||
QString epi_getTxt4datifLine(void) {
|
||||
QString epi_getTxt4datifLine(void)
|
||||
{
|
||||
|
||||
return txt4datifReceive;
|
||||
|
||||
}
|
||||
|
||||
void gpi_setTxt4datifLine(QString txtline) {
|
||||
void gpi_setTxt4datifLine(QString txtline)
|
||||
{
|
||||
|
||||
txt4datifReceive.clear();
|
||||
if (txtline=="")
|
||||
txt4datifReceive.clear();
|
||||
@@ -225,7 +277,8 @@ void gpi_setTxt4datifLine(QString txtline) {
|
||||
txt4datifReceive=txtline;
|
||||
}
|
||||
|
||||
void epi_clrTxt4datifLine() {
|
||||
void epi_clrTxt4datifLine()
|
||||
{
|
||||
txt4datifReceive.clear();
|
||||
}
|
||||
|
||||
@@ -234,11 +287,14 @@ void epi_clrTxt4datifLine() {
|
||||
|
||||
static QString txt4diagWindow;
|
||||
|
||||
QString epi_getTxt4RsDiagWin(void) {
|
||||
QString epi_getTxt4RsDiagWin(void)
|
||||
{
|
||||
return txt4diagWindow;
|
||||
|
||||
}
|
||||
|
||||
void gpi_setTxt4RsDiagWin(QString txtline) {
|
||||
void gpi_setTxt4RsDiagWin(QString txtline)
|
||||
{
|
||||
txt4diagWindow.clear();
|
||||
if (txtline=="")
|
||||
txt4diagWindow.clear();
|
||||
@@ -246,7 +302,8 @@ void gpi_setTxt4RsDiagWin(QString txtline) {
|
||||
txt4diagWindow=txtline;
|
||||
}
|
||||
|
||||
void epi_clrTxt4RsDiagWin() {
|
||||
void epi_clrTxt4RsDiagWin()
|
||||
{
|
||||
txt4diagWindow.clear();
|
||||
}
|
||||
|
||||
@@ -254,11 +311,14 @@ void epi_clrTxt4RsDiagWin() {
|
||||
|
||||
static QString sndTxt4diagWindow;
|
||||
|
||||
QString epi_get2ndTxt4RsDiagWin(void) {
|
||||
QString epi_get2ndTxt4RsDiagWin(void)
|
||||
{
|
||||
return sndTxt4diagWindow;
|
||||
|
||||
}
|
||||
|
||||
void gpi_set2ndTxt4RsDiagWin(QString txtline) {
|
||||
void gpi_set2ndTxt4RsDiagWin(QString txtline)
|
||||
{
|
||||
sndTxt4diagWindow.clear();
|
||||
if (txtline=="")
|
||||
sndTxt4diagWindow.clear();
|
||||
@@ -266,61 +326,174 @@ void gpi_set2ndTxt4RsDiagWin(QString txtline) {
|
||||
sndTxt4diagWindow=txtline;
|
||||
}
|
||||
|
||||
void epi_clr2ndTxt4RsDiagWin() {
|
||||
void epi_clr2ndTxt4RsDiagWin()
|
||||
{
|
||||
sndTxt4diagWindow.clear();
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
return SharedMemBuffer::getDataConst()->Sdata.serialTestResult;
|
||||
return Sdata_serialTestResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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) {
|
||||
SharedMemBuffer::getData()->Sdata.pProtResultOk = answisok ? 1 : 2;
|
||||
void gpi_storeResultOfLastRequest(bool answisok)
|
||||
{
|
||||
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
|
||||
return SharedMemBuffer::getDataConst()->Sdata.pProtResultOk;
|
||||
return 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);
|
||||
|
||||
|
||||
|
||||
static uint16_t Sdata_receivedDataLength;
|
||||
static uint8_t Sdata_receivedDataBlock[64];
|
||||
|
||||
void gpi_storeRecPayLoad(uint8_t RdDlen, uint8_t *receivedData)
|
||||
{
|
||||
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
|
||||
// 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;
|
||||
uint16_t ml=plBufSiz;
|
||||
if (ml>64) ml=64;
|
||||
if (Sdata_receivedDataLength<ml)
|
||||
ml=Sdata_receivedDataLength;
|
||||
tslib_strcpy(Sdata_receivedDataBlock, payLoad, ml);
|
||||
return 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
|
||||
ndbs=NrDataBits;
|
||||
pari=parity;
|
||||
nsb=NrStopBits;
|
||||
br=slaveBaudRate;
|
||||
}
|
||||
|
||||
void epi_getSlaveSerParams(uint8_t *slaveBaudRate, uint8_t *NrDataBits,
|
||||
uint8_t *parity, uint8_t *NrStopBits)
|
||||
{
|
||||
*NrDataBits=ndbs;
|
||||
*parity=pari;
|
||||
*NrStopBits=nsb;
|
||||
*slaveBaudRate=br;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void gpi_storeSlaveSerParams(uint8_t slaveBaudRate, uint8_t NrDataBits,
|
||||
uint8_t parity, uint8_t NrStopBits) {
|
||||
// store numbers
|
||||
SharedMemBuffer::write()->ndbs = NrDataBits;
|
||||
SharedMemBuffer::write()->pari = parity;
|
||||
SharedMemBuffer::write()->nsb = NrStopBits;
|
||||
SharedMemBuffer::write()->br = slaveBaudRate;
|
||||
}
|
||||
|
||||
void epi_getSlaveSerParams(uint8_t *slaveBaudRate, uint8_t *NrDataBits,
|
||||
uint8_t *parity, uint8_t *NrStopBits) {
|
||||
|
||||
*NrDataBits = SharedMemBuffer::read()->ndbs;
|
||||
*parity = SharedMemBuffer::read()->pari;
|
||||
*NrStopBits = SharedMemBuffer::read()->nsb;
|
||||
*slaveBaudRate = SharedMemBuffer::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 (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=ndbs;
|
||||
ctmp+=0x30;
|
||||
mySt.append(ctmp);
|
||||
ctmp=pari;
|
||||
mySt.append(ctmp);
|
||||
ctmp=nsb;
|
||||
ctmp+=0x30;
|
||||
mySt.append(ctmp);
|
||||
//mySt="Hallo";
|
||||
return mySt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
142
src/datIf.cpp
142
src/datIf.cpp
@@ -3,13 +3,16 @@
|
||||
#include "controlBus.h"
|
||||
#include "storeINdata.h"
|
||||
#include <QDebug>
|
||||
#include <datei.h>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
// called from MainWindow()
|
||||
|
||||
|
||||
#define DATIF_MAXCMDS 16
|
||||
static uint8_t dif_dataStep;
|
||||
static uint8_t dif_scanStep, RDBLKNR;
|
||||
static uint8_t dif_scanStep; //, RDBLKNR;
|
||||
|
||||
|
||||
static uint8_t datif_OutCmdpara1, datif_OutCmdpara2, datif_OutCmdpara3, datif_OutCmdpara4;
|
||||
@@ -19,6 +22,11 @@ static uint8_t cycl_running;
|
||||
|
||||
T_datif::T_datif(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
QByteArray myBA;
|
||||
QDir myDir("../dmd");
|
||||
|
||||
if (!myDir.exists())
|
||||
myDir.mkdir("../dmd");
|
||||
|
||||
myDCIF = new T_prot();
|
||||
|
||||
@@ -32,7 +40,7 @@ T_datif::T_datif(QWidget *parent) : QMainWindow(parent)
|
||||
datif_trigger = new QTimer();
|
||||
connect(datif_trigger, SIGNAL(timeout()), this, SLOT(datif_cycleSend()));
|
||||
datif_trigger->setSingleShot(false);
|
||||
datif_trigger->start(10); // in ms, 80 gut, default 100 50....200
|
||||
datif_trigger->start(10); // in ms,
|
||||
|
||||
// passing Signal through
|
||||
//connect(myDCIF, SIGNAL(framerecieved()), this, SLOT( ResponseRecieved() ));
|
||||
@@ -46,6 +54,30 @@ T_datif::T_datif(QWidget *parent) : QMainWindow(parent)
|
||||
dif_scanStep=0;
|
||||
selectedSlaveAddr=FIX_SLAVE_ADDR;
|
||||
cycl_running=0;
|
||||
gpi_storeDcDataValid(0);
|
||||
datif_noResponseCtr=0;
|
||||
|
||||
|
||||
// neu, 24.5.23: Alle Daten zusätzlich in Datei speichern
|
||||
// if (datei_ifFileExists(FILENAME_SHAREDDATA))
|
||||
// {
|
||||
// myBA.clear();
|
||||
// myBA=datei_readFromFile(FILENAME_SHAREDDATA);
|
||||
// }
|
||||
|
||||
// Testfile ereugen:
|
||||
csv_startCreatingFile();
|
||||
csv_addUintToFile(0);
|
||||
csv_addUintToFile(1);
|
||||
csv_addUintToFile(2);
|
||||
csv_addUintToFile(3);
|
||||
csv_addUintToFile(4);
|
||||
csv_addUintToFile(5);
|
||||
myBA=csv_readbackArray();
|
||||
datei_clearFile(FILENAME_SHAREDDATA);
|
||||
datei_writeToFile(FILENAME_SHAREDDATA, myBA);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void T_datif::resetChain(void)
|
||||
@@ -65,6 +97,11 @@ char T_datif::datif_cycleSend()
|
||||
uint8_t length, data[66];
|
||||
bool b_ret;
|
||||
|
||||
datif_noResponseCtr++; // inc every 10ms fehlt noch in SysCont
|
||||
if (datif_noResponseCtr>500) // seit 5s kein Lebenszeichen von DC2
|
||||
gpi_storeDcDataValid(0);
|
||||
|
||||
|
||||
if (cycl_running)
|
||||
{
|
||||
// request is still running, wait for response before next sending
|
||||
@@ -95,7 +132,23 @@ char T_datif::datif_cycleSend()
|
||||
|
||||
//void myDCIF->sendUserData(uint16_t slaveAdr);
|
||||
|
||||
if (check4FDshortCmd())
|
||||
if (checkNextFDcmd()==2)
|
||||
{
|
||||
b_ret=longFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &length, data);
|
||||
if (b_ret)
|
||||
{
|
||||
myDCIF->setUserWriteData(nextWrCmd, blockNum, length, data);
|
||||
myDCIF->setUserReadData(nextRdCmd);
|
||||
myDCIF->sendUserData(selectedSlaveAddr);
|
||||
//qDebug()<<"Datif send long cmd "<<nextWrCmd<< " " <<nextRdCmd<< " " <<length << " " << data[0]<< " " << data[1]
|
||||
// << " " << data[2]<< " " << data[3]<< " " << data[4]<< " " << data[5]<< " " << data[6]<< " " << data[7]
|
||||
// << " " << data[8]<< " " << data[9]<< " " << data[10]<< " " << data[11]<< " " << data[12];
|
||||
}
|
||||
cycl_running=1;
|
||||
return 0;
|
||||
} else
|
||||
|
||||
if (checkNextFDcmd()==1)
|
||||
{
|
||||
b_ret=sendFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &dat1, &dat2, &dat3, &dat4);
|
||||
if (b_ret)
|
||||
@@ -104,19 +157,18 @@ char T_datif::datif_cycleSend()
|
||||
myDCIF->setUserWriteData(nextWrCmd, blockNum, 4, data);
|
||||
myDCIF->setUserReadData(nextRdCmd);
|
||||
myDCIF->sendUserData(selectedSlaveAddr);
|
||||
//qDebug()<<"Datif send short cmd "<<nextWrCmd<< " " <<nextRdCmd;
|
||||
}
|
||||
cycl_running=1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (check4FDlongCmd())
|
||||
{
|
||||
b_ret=longFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &length, data);
|
||||
if (b_ret)
|
||||
{
|
||||
myDCIF->setUserWriteData(nextWrCmd, blockNum, length, data);
|
||||
myDCIF->setUserReadData(nextRdCmd);
|
||||
myDCIF->sendUserData(selectedSlaveAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// direct commands have highest prio (setting OUTPUTS)
|
||||
nxtAsCmd=sendWRcmd_getSendCommand0(); // command was stored by Gui
|
||||
@@ -210,7 +262,10 @@ char T_datif::datif_cycleSend()
|
||||
sendINrequestsAutomatic(); // sendCyclicCmd(); // request all cyclic data sequential
|
||||
}
|
||||
else
|
||||
{
|
||||
dif_scanStep=0; // always start from beginning
|
||||
gpi_storeDcDataValid(0); // fehlt in SysCont
|
||||
}
|
||||
}
|
||||
#ifdef USEHANDSHAKES
|
||||
else
|
||||
@@ -221,6 +276,7 @@ char T_datif::datif_cycleSend()
|
||||
} else
|
||||
{
|
||||
//qDebug() << "com port not available"; // wird ununterbrochen ausgegeben
|
||||
gpi_storeDcDataValid(0); // fehlt in SysCont
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -306,6 +362,7 @@ void T_datif::sendWRcommand(uint16_t nextWrCmd)
|
||||
datif_sendIOrequest(CMD2DC_FAN, CMD2DC_RdBkAllOutputs, 1);
|
||||
break;
|
||||
case SENDDIRCMD_LAERM:
|
||||
//qDebug()<<"datif switch siren";
|
||||
datif_sendIOrequest(CMD2DC_SIREN, CMD2DC_RdBkAllOutputs, 1);
|
||||
break;
|
||||
case SENDDIRCMD_REL1:
|
||||
@@ -728,7 +785,7 @@ char T_datif::sendINrequestsAutomatic(void)
|
||||
break;
|
||||
|
||||
case 12:
|
||||
if (indat_isPrinterOn())
|
||||
//if (indat_isPrinterOn())
|
||||
datif_sendIOrequest(0, CMD2DC_RdBk_AllPrnData, 0); // 27
|
||||
// datif_sendIOrequest(0, CMD2DC_RdBk_PrnState, 0);
|
||||
break;
|
||||
@@ -738,7 +795,7 @@ char T_datif::sendINrequestsAutomatic(void)
|
||||
break;
|
||||
|
||||
case 14:
|
||||
if (indat_isMifareOn())
|
||||
//if (indat_isMifareOn())
|
||||
{
|
||||
datif_sendIOrequest(0, CMD2DC_RdBk_MifState, 0); // 109
|
||||
//qDebug()<<"requesting MIF reader state";
|
||||
@@ -751,6 +808,7 @@ char T_datif::sendINrequestsAutomatic(void)
|
||||
break;
|
||||
|
||||
case 16:
|
||||
/*
|
||||
if (indat_isMifareOn())
|
||||
{
|
||||
datif_OutCmdpara1=0; // data block number 0 contains the Mifare-ID
|
||||
@@ -760,7 +818,8 @@ char T_datif::sendINrequestsAutomatic(void)
|
||||
RDBLKNR=0;
|
||||
datif_OutCmdpara1=RDBLKNR;
|
||||
|
||||
} break;
|
||||
}*/
|
||||
break;
|
||||
|
||||
case 17:
|
||||
//datif_sendIOrequest(0, CMD2DC_GetAllInputs, 0);
|
||||
@@ -768,7 +827,7 @@ char T_datif::sendINrequestsAutomatic(void)
|
||||
break;
|
||||
|
||||
case 18:
|
||||
if (indat_isMdbOn())
|
||||
//if (indat_isMdbOn())
|
||||
datif_sendIOrequest(0, CMD2DC_MDB_GET_STATE, 0); // 107
|
||||
//else
|
||||
// dif_scanStep=24; unsinn
|
||||
@@ -815,7 +874,7 @@ char T_datif::sendINrequestsAutomatic(void)
|
||||
|
||||
dif_scanStep++;
|
||||
if (dif_scanStep>26)
|
||||
dif_scanStep=5;
|
||||
dif_scanStep=0; // dif_scanStep=5;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -838,6 +897,7 @@ char T_datif::isPortOpen(void)
|
||||
|
||||
void T_datif::StoredRecData()
|
||||
{
|
||||
datif_noResponseCtr=0;
|
||||
//qDebug() << "StoreRecData called";
|
||||
// call automatically by T_prot
|
||||
//if (myDCIF->ifDataReceived())
|
||||
@@ -847,7 +907,10 @@ void T_datif::StoredRecData()
|
||||
// "neu" is the same as "INdataValid"
|
||||
loadRecDataFromFrame();
|
||||
}
|
||||
cycl_running=0;
|
||||
//cycl_running=0; // send next cmd immediately
|
||||
cycl_running=9; // send next cmd after 10ms
|
||||
// wichtig! bei 0 werden Telegramme verschluckt! 24.5.2023
|
||||
// 9 ergibt 16ms Formel: gap = 110ms (Zeile 80) - cycl_running*10ms
|
||||
}
|
||||
|
||||
char T_datif::loadRecDataFromFrame()
|
||||
@@ -1021,7 +1084,7 @@ char T_datif::loadRecDataFromFrame()
|
||||
//<< receivedData[3] << " " << receivedData[4] << " " << receivedData[5];
|
||||
|
||||
uctmp=receivedData[0];
|
||||
// qDebug()<<"datif single bits: "<< (uctmp&1) << (uctmp&2) << (uctmp&4);
|
||||
//qDebug()<<"datif DOOR bits: "<< (uctmp&1) << (uctmp&2) << (uctmp&4);
|
||||
gpi_storeDI_doorSwitches(uctmp&1, uctmp&2, uctmp&4);
|
||||
|
||||
gpi_storeDI_vaultSwitches(uctmp&8, uctmp&16);
|
||||
@@ -1050,8 +1113,6 @@ char T_datif::loadRecDataFromFrame()
|
||||
gpi_storeDI_GsmPowerIsOn(uctmp&16);
|
||||
gpi_storeDI_CreditPowerIsOn(uctmp&32);
|
||||
gpi_storeDI_PrinterPowerIsOn(uctmp&64);
|
||||
|
||||
//gpi_storeMdbState(uctmp&4, uctmp&128, uctmp&4); // hat ein eigenes Cmd weiter unten!
|
||||
gpi_storeDI_MdbPowerIsOn(uctmp&128);
|
||||
|
||||
gpi_storeDI_paperLow(receivedData[5]);
|
||||
@@ -1179,10 +1240,11 @@ char T_datif::loadRecDataFromFrame()
|
||||
case CMD2DC_MDB_GET_STATE: //107
|
||||
// DB0: mdb_bus_ready (switched on)
|
||||
// DB1: rdBackV12devicePower
|
||||
// DB2: rdBackV5busPwr
|
||||
// DB2: rdBackV5busPwr kommt immer mit 1
|
||||
|
||||
//qDebug() << "got MDB state " << receivedData[0] << " " << receivedData[1] << " " << receivedData[2];
|
||||
gpi_storeMdbState(receivedData[0],receivedData[1],receivedData[2]);
|
||||
|
||||
break;
|
||||
|
||||
case CMD2DC_MDB_GETRESP: //22
|
||||
@@ -1206,6 +1268,15 @@ char T_datif::loadRecDataFromFrame()
|
||||
// DB1: last coin signal (value / scale)
|
||||
// DB2,3: last coin value
|
||||
// DB4: lastError from Emp
|
||||
|
||||
// 0: nr of stored coins
|
||||
// 1: got 2:type 3:err 4=valL 5=valH
|
||||
|
||||
// qDebug() << "got emp coin "<< " " << receivedData[0] <<" " << receivedData[1]
|
||||
// << " " << receivedData[2]<< " " << receivedData[3]
|
||||
// << " " << receivedData[4]<< " " << receivedData[5]
|
||||
// << " " << receivedData[6]<< " " << receivedData[7];
|
||||
|
||||
gpi_storeEmpCoinSignal(receivedData[0], &receivedData[1]);
|
||||
break;
|
||||
|
||||
@@ -1361,13 +1432,19 @@ char T_datif::loadRecDataFromFrame()
|
||||
newInsertedAmount=uchar2ulong(receivedData[3],receivedData[2],receivedData[1],receivedData[0]);
|
||||
uitmp=uchar2uint(receivedData[5],receivedData[4]);
|
||||
uit2=uchar2uint(receivedData[7],receivedData[6]);
|
||||
gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2);
|
||||
if (newInsertedAmount != lastInsertedAmount)
|
||||
if (uitmp>0) // nur 1x bei neuer Münze
|
||||
{
|
||||
emit datif_gotNewCoin();
|
||||
lastInsertedAmount=newInsertedAmount;
|
||||
}
|
||||
gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2);
|
||||
//void gpi_storeCurrentPayment(uint32_t insertedAmount, uint16_t lastCoinType, uint16_t lastCoinValue)
|
||||
if (newInsertedAmount != lastInsertedAmount)
|
||||
{
|
||||
emit datif_gotNewCoin();
|
||||
//qDebug()<<"emit new coin";
|
||||
|
||||
lastInsertedAmount=newInsertedAmount;
|
||||
}
|
||||
qDebug()<<" store new coin"<<newInsertedAmount<<" "<<uitmp<<" "<<uit2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 113: // get wake source, 8byte
|
||||
@@ -1477,6 +1554,9 @@ char T_datif::loadRecDataFromFrame()
|
||||
outBuf[pBuf++]=0;
|
||||
|
||||
*/
|
||||
if (RdDleng>40)
|
||||
//datif_DCdataValid=1; // das hier sind die wichtigsten Daten, deshalb hierrein!
|
||||
gpi_storeDcDataValid(1);
|
||||
|
||||
gpi_storeDynMachineConditions(RdDleng, receivedData);
|
||||
|
||||
@@ -1577,7 +1657,13 @@ struct T_vaultRecord
|
||||
gpi_storeVaultRecord(readAddress, receivedData ); // always 64byte
|
||||
break;
|
||||
|
||||
case 39:
|
||||
gpi_storeDynData(receivedData);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
readSource=0; // 17.05.2023: to avoid multiple recording
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
943
src/datei.cpp
Normal file
943
src/datei.cpp
Normal file
@@ -0,0 +1,943 @@
|
||||
// written by Thomas Sax, Jan.2022
|
||||
#include "datei.h"
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------ create csv file -------------------------------
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
QByteArray datei_writeArray, datei_tempArray;
|
||||
|
||||
void csv_startCreatingFile(void)
|
||||
{
|
||||
datei_writeArray.clear();
|
||||
datei_tempArray.clear();
|
||||
}
|
||||
|
||||
void csv_addTextToFile(QString myText)
|
||||
{
|
||||
datei_writeArray.append(myText.toLatin1());
|
||||
datei_writeArray.append(FILESEPERATOR);
|
||||
}
|
||||
|
||||
void csv_addIntToFile(int myValue)
|
||||
{
|
||||
//qulonglong ullt=12345678901234567890; // max 1,844 x10^19
|
||||
datei_tempArray.setNum(myValue,10); // accepted types: short, ushort, int, uint,
|
||||
// qlonglong, qulonglong, float, double
|
||||
// numerbase can be 2...36(!),10=dec
|
||||
|
||||
datei_writeArray.append(datei_tempArray);
|
||||
datei_writeArray.append(FILESEPERATOR);
|
||||
}
|
||||
|
||||
void csv_addUintToFile(uint myValue)
|
||||
{
|
||||
datei_tempArray.setNum(myValue,10);
|
||||
datei_writeArray.append(datei_tempArray);
|
||||
datei_writeArray.append(FILESEPERATOR);
|
||||
}
|
||||
|
||||
|
||||
void csv_addLongvalToFile(qlonglong myValue)
|
||||
{
|
||||
datei_tempArray.setNum(myValue,10);
|
||||
datei_writeArray.append(datei_tempArray);
|
||||
datei_writeArray.append(FILESEPERATOR);
|
||||
}
|
||||
|
||||
void csv_addUlongvalToFile(qulonglong myValue)
|
||||
{
|
||||
datei_tempArray.setNum(myValue,10);
|
||||
datei_writeArray.append(datei_tempArray);
|
||||
datei_writeArray.append(FILESEPERATOR);
|
||||
}
|
||||
|
||||
/*
|
||||
void csv_addCurrentTimeToFile(void)
|
||||
{
|
||||
uint8_t hour, minute, sec, ui8buf[20];
|
||||
char buf[20];
|
||||
|
||||
config_getSysTime(&hour, &minute, &sec);
|
||||
GetTimeString(hour, minute, sec, 0, 1, ui8buf);
|
||||
for (uint8_t nn=0; nn<20; nn++)
|
||||
buf[nn]=char(ui8buf[nn]);
|
||||
datei_writeArray.append(buf,8); // time string
|
||||
datei_writeArray.append(FILESEPERATOR);
|
||||
|
||||
}
|
||||
|
||||
void csv_addCurrentDateToFile(void)
|
||||
{
|
||||
uint16_t year;
|
||||
uint8_t month, day, ui8buf[20];
|
||||
char buf[20];
|
||||
|
||||
config_getSystemDate(&year, &month, &day);
|
||||
//qDebug()<<"date year: "<<year;
|
||||
GetDateString(day, month, 0x20, uint8_t(year%100), 0, 0, ui8buf);
|
||||
for (uint8_t nn=0; nn<20; nn++)
|
||||
buf[nn]=char(ui8buf[nn]);
|
||||
datei_writeArray.append(buf, 10); // date string
|
||||
datei_writeArray.append(NEWLINEINFILE);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void csv_addNewlineToFile(void)
|
||||
{
|
||||
datei_writeArray.chop(1); // Komma weg
|
||||
datei_writeArray.append(NEWLINEINFILE);
|
||||
}
|
||||
|
||||
QByteArray csv_readbackArray(void)
|
||||
{
|
||||
return datei_writeArray;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
QByteArray csv_writeContent_testValues(void)
|
||||
{
|
||||
QByteArray myBA, tmpBA;
|
||||
uint8_t modCount=5, modAddr=23;
|
||||
uint8_t hour, minute, sec, month, day, ui8buf[20];
|
||||
uint16_t year, modType=45678;
|
||||
char buf[20];
|
||||
uint32_t modNrDIs=1234567890;
|
||||
uint8_t modNrAIs=4, modNrCtr=2, modNrDOs=8;
|
||||
int modNrAOs=-2;
|
||||
|
||||
myBA.clear();
|
||||
tmpBA.clear();
|
||||
myBA.append("scan time");
|
||||
myBA.append(FILESEPERATOR);
|
||||
|
||||
datei_getSysTime(&hour, &minute, &sec);
|
||||
GetTimeString(hour, minute, sec, 0, 1, ui8buf);
|
||||
for (uint8_t nn=0; nn<20; nn++)
|
||||
buf[nn]=char(ui8buf[nn]);
|
||||
myBA.append(buf,8); // time string
|
||||
myBA.append(FILESEPERATOR);
|
||||
|
||||
datei_getSystemDate(&year, &month, &day);
|
||||
//qDebug()<<"date year: "<<year;
|
||||
GetDateString(day, month, 0x20, uint8_t(year%100), 0, 0, ui8buf);
|
||||
for (uint8_t nn=0; nn<20; nn++)
|
||||
buf[nn]=char(ui8buf[nn]);
|
||||
myBA.append(buf, 10); // date string
|
||||
myBA.append(NEWLINEINFILE);
|
||||
|
||||
myBA.append("number of modules");
|
||||
myBA.append(FILESEPERATOR);
|
||||
tmpBA.setNum(modCount,10); //2nd para = number base 2, 8, 10 or 16 (bin, oct, dec, hex)
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(NEWLINEINFILE);
|
||||
|
||||
myBA.append("busaddr");
|
||||
myBA.append(FILESEPERATOR);
|
||||
myBA.append("type");
|
||||
myBA.append(FILESEPERATOR);
|
||||
myBA.append("NrOfDI");
|
||||
myBA.append(FILESEPERATOR);
|
||||
myBA.append("NrOfAI");
|
||||
myBA.append(FILESEPERATOR);
|
||||
myBA.append("NrOfCtrIn");
|
||||
myBA.append(FILESEPERATOR);
|
||||
myBA.append("NrOfDO");
|
||||
myBA.append(FILESEPERATOR);
|
||||
myBA.append("NrOfAO");
|
||||
myBA.append(NEWLINEINFILE);
|
||||
|
||||
tmpBA.setNum(modAddr,10);
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(FILESEPERATOR);
|
||||
tmpBA.setNum(modType,10);
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(FILESEPERATOR);
|
||||
tmpBA.setNum(modNrDIs,10);
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(FILESEPERATOR);
|
||||
tmpBA.setNum(modNrAIs,10);
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(FILESEPERATOR);
|
||||
tmpBA.setNum(modNrCtr,10);
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(FILESEPERATOR);
|
||||
tmpBA.setNum(modNrDOs,10);
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(FILESEPERATOR);
|
||||
tmpBA.setNum(modNrAOs,10);
|
||||
myBA.append(tmpBA);
|
||||
myBA.append(NEWLINEINFILE);
|
||||
return myBA;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------ parse csv file -------------------------------
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
// first: QByteArray datei_readFromFile(QString filename);
|
||||
|
||||
|
||||
uint32_t csv_nrOfEntriesInFile(QByteArray readFromFile)
|
||||
{
|
||||
// count sequences between FILESEPERATOR and NEWLINEINFILE
|
||||
uint32_t filSize=0, pp=0;
|
||||
char oneByt=0;
|
||||
|
||||
int filLen=readFromFile.size();
|
||||
if(filLen>1)
|
||||
filSize=uint32_t(filLen);
|
||||
else
|
||||
return 0;
|
||||
|
||||
// 1) find position of seperators
|
||||
for (uint32_t ii=0; ii<filSize; ii++)
|
||||
{
|
||||
oneByt=readFromFile[ii];
|
||||
if (oneByt==FILESEP1 || oneByt==FILESEP2 || oneByt==NEWLINEINFILE)
|
||||
pp++;
|
||||
}
|
||||
// now: pp = number of seperators
|
||||
// oneByt = last byte in file. If it's not a seperator then
|
||||
// there's one more entry (last entry without termination)
|
||||
if (oneByt !=FILESEP1 && oneByt !=FILESEP2 && oneByt !=NEWLINEINFILE)
|
||||
pp++;
|
||||
//qDebug()<<"csv: nr of sequences="<< pp;
|
||||
return pp;
|
||||
}
|
||||
|
||||
QByteArray csv_getOneFileSequence(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
// seperate file content in single sequences between FILESEPERATOR and NEWLINEINFILE
|
||||
// and return "entryNr" - entry
|
||||
// for this first step leave data type QByteArray
|
||||
// 2nd step can change in numbers and strings
|
||||
QByteArray sequence;
|
||||
uint32_t sepPos[MAXNUMBEROFSEQUENCES];
|
||||
uint32_t filSize=0, pp=0, ii, start=0, ende=0;
|
||||
char oneByt;
|
||||
int filLen, mm;
|
||||
|
||||
filLen=sourceFile.size();
|
||||
//qDebug()<<"fillen="<< filLen;
|
||||
if(filLen<10)
|
||||
return "";
|
||||
filSize=uint32_t(filLen);
|
||||
|
||||
if (sequNr>MAXNUMBEROFSEQUENCES)
|
||||
return "";
|
||||
|
||||
// 1) find position of seperators
|
||||
for (ii=0; ii<filSize; ii++)
|
||||
{
|
||||
oneByt=sourceFile[ii];
|
||||
if (oneByt==FILESEP1 || oneByt==FILESEP2 || oneByt==NEWLINEINFILE)
|
||||
{
|
||||
sepPos[pp++]=ii;
|
||||
}
|
||||
}
|
||||
// now: pp = number of entries
|
||||
//qDebug()<<"nr of seperators="<< pp;
|
||||
|
||||
if (sequNr>=pp)
|
||||
return "";
|
||||
|
||||
// 2) get sequence
|
||||
if (sequNr==0)
|
||||
{
|
||||
start=0;
|
||||
ende=sepPos[sequNr];
|
||||
} else
|
||||
if (sequNr>0)
|
||||
{
|
||||
start=sepPos[sequNr-1]+1;
|
||||
ende=sepPos[sequNr];
|
||||
}
|
||||
|
||||
//qDebug()<<"datei getOneFileSequence start/ende: "<<start << " " << ende;
|
||||
if (start>=ende)
|
||||
return "";
|
||||
//return "-err3-";
|
||||
sequence.clear();
|
||||
//batmp.clear();
|
||||
pp=0;
|
||||
for (ii=start; ii<ende; ii++)
|
||||
{
|
||||
mm=int(ii);
|
||||
if (mm>=int(filSize))
|
||||
mm=0;
|
||||
oneByt=sourceFile.at(mm);
|
||||
sequence.append(oneByt);
|
||||
}
|
||||
return sequence;
|
||||
}
|
||||
|
||||
int csv_getEntryAsInt(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
QByteArray myBA, myVA;
|
||||
int entry=0;
|
||||
bool ok;
|
||||
|
||||
myVA.clear();
|
||||
myBA = csv_getOneFileSequence(sourceFile, sequNr);
|
||||
//qDebug()<<"datei getEntryAsInt, sequence: " << myBA;
|
||||
|
||||
entry=myBA.toInt(&ok,16);
|
||||
if (ok)
|
||||
{
|
||||
//qDebug()<<"datei getEntryAsInt, number: " << entry;
|
||||
return entry;
|
||||
}
|
||||
//qDebug()<<"datei getEntryAsInt, error " << myBA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t csv_getEntryAsLong(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
QByteArray myBA = csv_getOneFileSequence(sourceFile, sequNr);
|
||||
long entry=0;
|
||||
bool ok;
|
||||
|
||||
entry=myBA.toLong(&ok,10);
|
||||
if (ok)
|
||||
return entry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t csv_getEntryAsUshort(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
QByteArray myBA = csv_getOneFileSequence(sourceFile, sequNr);
|
||||
uint8_t entry=0;
|
||||
bool ok;
|
||||
|
||||
entry=uint8_t(myBA.toUShort(&ok,10));
|
||||
if (ok)
|
||||
return entry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t csv_getEntryAsUint(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
QByteArray myBA = csv_getOneFileSequence(sourceFile, sequNr);
|
||||
uint16_t entry=0;
|
||||
bool ok;
|
||||
|
||||
entry=uint16_t(myBA.toUInt(&ok,10));
|
||||
if (ok)
|
||||
return entry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t csv_getEntryAsUlong(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
QByteArray myBA = csv_getOneFileSequence(sourceFile, sequNr);
|
||||
uint32_t entry=0;
|
||||
bool ok;
|
||||
|
||||
entry=myBA.toULong(&ok,10);
|
||||
if (ok)
|
||||
return entry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t csv_getEntryAs2Ulong(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
QByteArray myBA = csv_getOneFileSequence(sourceFile, sequNr);
|
||||
uint64_t entry=0;
|
||||
bool ok;
|
||||
|
||||
entry=myBA.toULongLong(&ok,10);
|
||||
if (ok)
|
||||
return entry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString csv_getEntryAsString(QByteArray sourceFile, uint32_t sequNr)
|
||||
{
|
||||
QByteArray myBA = csv_getOneFileSequence(sourceFile, sequNr);
|
||||
QString entry;
|
||||
|
||||
//qDebug()<<"datei getEntryAsString, sequence: " << myBA;
|
||||
entry=myBA.toStdString().c_str();
|
||||
return entry;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------ create Json file -------------------------------
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
example
|
||||
QString str = "{"
|
||||
" \"Herausgeber\": \"Xema\","
|
||||
" \"Nummer\": \"1234-5678-9012-3456\","
|
||||
" \"Deckung\": 2e+6,"
|
||||
" \"Währung\": \"EURO\","
|
||||
" \"Inhaber\": {"
|
||||
" \"Name\": \"Mustermann\","
|
||||
" \"Vorname\": \"Max\","
|
||||
" \"männlich\": true,"
|
||||
" \"Hobbys\": [ \"Reiten\", \"Golfen\", \"Lesen\" ],"
|
||||
" \"Alter\": 42,"
|
||||
" \"Kinder\": [],"
|
||||
" \"Partner\": null"
|
||||
" }"
|
||||
"}";
|
||||
|
||||
*/
|
||||
|
||||
QString myJsonCon;
|
||||
QString tmpStr;
|
||||
|
||||
void json_startRecord(void)
|
||||
{
|
||||
myJsonCon.clear();
|
||||
tmpStr.clear();
|
||||
myJsonCon.append('{');
|
||||
}
|
||||
|
||||
void json_enterIntToRecord(QString attribute, ulong i_value)
|
||||
{
|
||||
tmpStr.clear();
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(attribute);
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(':');
|
||||
tmpStr.setNum(i_value);
|
||||
myJsonCon.append(tmpStr);
|
||||
myJsonCon.append(',');
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
}
|
||||
|
||||
void json_enterTextToRecord(QString attribute, QString txt_value)
|
||||
{
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(attribute);
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(':');
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(txt_value);
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(',');
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
}
|
||||
/*
|
||||
void json_addCurrentTimeToRecord(QString attribute)
|
||||
{
|
||||
uint8_t hour, minute, sec, ui8buf[20];
|
||||
//char buf[20];
|
||||
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(attribute);
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(':');
|
||||
myJsonCon.append('"');
|
||||
|
||||
datei_getSysTime(&hour, &minute, &sec);
|
||||
GetTimeString(hour, minute, sec, 0, 1, ui8buf);
|
||||
for (uint8_t nn=0; nn<8; nn++)
|
||||
myJsonCon.append(ui8buf[nn]);
|
||||
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(',');
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
|
||||
}
|
||||
|
||||
void json_addCurrentDateToRecord(QString attribute)
|
||||
{
|
||||
uint16_t year;
|
||||
uint8_t month, day, ui8buf[20];
|
||||
//char buf[20];
|
||||
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(attribute);
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(':');
|
||||
myJsonCon.append('"');
|
||||
|
||||
datei_getSystemDate(&year, &month, &day);
|
||||
GetDateString(day, month, 0x20, uint8_t(year%100), 0, 0, ui8buf);
|
||||
for (uint8_t nn=0; nn<10; nn++)
|
||||
myJsonCon.append(ui8buf[nn]);
|
||||
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(',');
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void json_enterArrayToRecord(QString attribute, uint8_t *buf, ulong nrofVals)
|
||||
{
|
||||
// add array of numbers with "nrofVals" elements
|
||||
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(attribute);
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(':');
|
||||
myJsonCon.append('['); // eckig!!!
|
||||
for (ulong ul=0; ul<nrofVals; ul++)
|
||||
{
|
||||
tmpStr.setNum(buf[ul]);
|
||||
myJsonCon.append(tmpStr);
|
||||
myJsonCon.append(',');
|
||||
}
|
||||
myJsonCon.chop(1); // Komma weg
|
||||
myJsonCon.append(']'); // eckig!!!
|
||||
myJsonCon.append(',');
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
}
|
||||
|
||||
void json_enterStructToRecord(QString attribute)
|
||||
{
|
||||
// every call must be concluded with "json_finishFile()"
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(attribute);
|
||||
myJsonCon.append('"');
|
||||
myJsonCon.append(':');
|
||||
myJsonCon.append('{'); // geschweift!!
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
}
|
||||
|
||||
void json_finishStruct(void)
|
||||
{
|
||||
myJsonCon.chop(2); // remove , and \r from the end
|
||||
myJsonCon.append('}');
|
||||
myJsonCon.append(',');
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
|
||||
}
|
||||
|
||||
void json_finishRecord(void)
|
||||
{
|
||||
myJsonCon.chop(2); // remove , and \r from the end
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
myJsonCon.append('}');
|
||||
myJsonCon.append(NEWLINEINFILE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
QString json_readbackRecordStr(void)
|
||||
{
|
||||
return myJsonCon;
|
||||
}
|
||||
|
||||
QByteArray json_readbackRecordBa(void)
|
||||
{
|
||||
return myJsonCon.toLatin1();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------ parse Json file -------------------------------
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
example Json File:
|
||||
{"temperature":28,
|
||||
"snow":"no",
|
||||
"Zeit":"16_21_45",
|
||||
"sunny":"12h",
|
||||
"humidity":75,
|
||||
"wann ":"24.01.2022",
|
||||
"unterstruktur":{
|
||||
"day of week":"tuesday",
|
||||
"year":22,
|
||||
"month":1,
|
||||
"day":24},
|
||||
"fast am":"Ende",
|
||||
"Puffer":[8,3,9,2,10]
|
||||
}
|
||||
*/
|
||||
// first: QByteArray datei_readFromFile(QString filename);
|
||||
|
||||
|
||||
int json_nrOfPairsInFile(QByteArray filename)
|
||||
{
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(filename);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
|
||||
// key value pair consisting of key (unique string) and value (QJsonValue)
|
||||
int nrOfPairs=jobj.size();
|
||||
|
||||
qDebug() << "my Json file has got: " << nrOfPairs<< "pairs";
|
||||
return nrOfPairs;
|
||||
}
|
||||
|
||||
bool json_exists(QByteArray filename, QString searchForKey)
|
||||
{
|
||||
// look for "searchForKey" =name of the pair (left of : )
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(filename);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
|
||||
if (jobj.contains(searchForKey))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool json_remove(QByteArray filename, QString searchFor)
|
||||
{
|
||||
// look for "searchFor" =name of the pair (left of : ) and remove the record from file
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(filename);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
|
||||
if (jobj.contains(searchFor))
|
||||
{
|
||||
jobj.remove(searchFor);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString json_searchForStringInFile(QByteArray filename, QString searchFor)
|
||||
{
|
||||
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(filename);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
|
||||
if (jobj.contains(searchFor))
|
||||
{
|
||||
return jobj[searchFor].toString(); // toObject(); toArray();
|
||||
} else
|
||||
{
|
||||
//qDebug() << "pairname not found in Json file";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
int json_searchForIntInFile(QByteArray filename, QString searchFor)
|
||||
{
|
||||
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(filename);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
|
||||
if (jobj.contains(searchFor))
|
||||
{
|
||||
return jobj[searchFor].toInt(); // toObject(); toArray();
|
||||
} else
|
||||
{
|
||||
//qDebug() << "number not found in Json file";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool json_searchForObjectInFile(QByteArray filename, QString searchFor, QJsonObject *oneObject)
|
||||
{
|
||||
// return an object from the json file
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(filename);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
|
||||
if (jobj.contains(searchFor))
|
||||
{
|
||||
*oneObject = jobj[searchFor].toObject();
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
//qDebug() << "Object not found in Json file";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int json_nrOfPairsInObject(QJsonObject objname)
|
||||
{
|
||||
int nrOfPairs=objname.size();
|
||||
qDebug() << "my Json Object has got: " << nrOfPairs<< "pairs";
|
||||
return nrOfPairs;
|
||||
}
|
||||
|
||||
QString json_searchForStringInObject(QJsonObject objname, QString searchFor)
|
||||
{
|
||||
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
|
||||
|
||||
if (objname.contains(searchFor))
|
||||
{
|
||||
return objname[searchFor].toString();
|
||||
} else
|
||||
{
|
||||
//qDebug() << "string not found in Json object";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
int json_searchForIntInObject(QJsonObject objname, QString searchFor)
|
||||
{
|
||||
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
|
||||
|
||||
if (objname.contains(searchFor))
|
||||
{
|
||||
return objname[searchFor].toInt();
|
||||
} else
|
||||
{
|
||||
//qDebug() << "number not found in Json file";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool json_searchForArrayInFile(QByteArray filename, QString searchFor, QJsonArray *oneArray)
|
||||
{
|
||||
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(filename);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
|
||||
if (jobj.contains(searchFor))
|
||||
{
|
||||
*oneArray = jobj[searchFor].toArray();
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
//qDebug() << "Array not found in Json file";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int json_nrOfValuesInArray(QJsonArray arrayname)
|
||||
{
|
||||
int nrOfPairs=arrayname.size();
|
||||
qDebug() << "my Json Array has got: " << nrOfPairs<< "values";
|
||||
return nrOfPairs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool json_getValuesOfArray(QJsonArray arrayname, int *buf, int MaxBufferSize)
|
||||
{
|
||||
// assuming that the array consists of integers
|
||||
|
||||
/* copy to local buffer:
|
||||
#define MAXNROFARRAYVALUES 100
|
||||
int buf[MAXNROFARRAYVALUES], ii;
|
||||
int nrOfPairs=arrayname.size();
|
||||
|
||||
if (nrOfPairs>MAXNROFARRAYVALUES)
|
||||
nrOfPairs=MAXNROFARRAYVALUES;
|
||||
|
||||
for (ii=0; ii<nrOfPairs; ii++)
|
||||
buf[ii]=arrayname[ii].toInt();
|
||||
*/
|
||||
// copy to host buffer:
|
||||
bool ok=true;
|
||||
int nrOfPairs=arrayname.size();
|
||||
|
||||
if (nrOfPairs>MaxBufferSize)
|
||||
{
|
||||
ok=false; // got not all
|
||||
nrOfPairs=MaxBufferSize;
|
||||
}
|
||||
for (int ii=0; ii<nrOfPairs; ii++)
|
||||
buf[ii]=arrayname[ii].toInt();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
void datei_json_readTestFile(QString filename)
|
||||
{
|
||||
QByteArray my2Ba;
|
||||
QString my2Str;
|
||||
|
||||
my2Str.clear();
|
||||
my2Ba=datei_readFromFile(filename);
|
||||
|
||||
QJsonDocument jdoc = QJsonDocument::fromJson(my2Ba);
|
||||
QJsonObject jobj = jdoc.object();
|
||||
//QJsonParseError jerror;
|
||||
QJsonObject myObj;
|
||||
QJsonArray myArray;
|
||||
|
||||
// key value pair consisting of key (unique string) and value (QJsonValue)
|
||||
int nrOfPairs=jobj.size();
|
||||
qDebug() << "my Json file has got: " << nrOfPairs<< "pairs";
|
||||
|
||||
if (jobj.contains("Zeit"))
|
||||
qDebug() << "my Json file: " << jobj["Zeit"].toString(); // toObject(); toArray();
|
||||
else
|
||||
qDebug() << "my Json file contains no Zeit";
|
||||
|
||||
if (jobj.contains("Humidity"))
|
||||
qDebug() << "my Json file: " << jobj["humidity"].toInt();
|
||||
else
|
||||
qDebug() << "my Json file contains no Humidity";
|
||||
|
||||
if (jobj.contains("month"))
|
||||
qDebug() << "my Json file: " << jobj["month"].toObject(); // anzeige QJsonObject()
|
||||
else
|
||||
qDebug() << "my Json file contains no month";
|
||||
|
||||
|
||||
myObj=jobj["unterstruktur"].toObject();
|
||||
qDebug() << "my unterstruktur: " << myObj["month"].toInt();
|
||||
qDebug() << "my unterstruktur: " << myObj["day of week"].toString();
|
||||
//if (jerror.error == QJsonParseError::NoError)
|
||||
// qDebug() << "no error";
|
||||
|
||||
qDebug() << "my Month: " << myObj["Month"].toInt();
|
||||
//if (myObj["Month"] == QJsonValue::Undefined)
|
||||
// qDebug() << "no found"; geht nicht
|
||||
|
||||
//if (jerror.error != QJsonParseError::NoError)
|
||||
// qDebug() << "no found";
|
||||
|
||||
myArray=jobj["Puffer"].toArray();
|
||||
qDebug() << "my array " <<myArray[2].toInt();
|
||||
//if (jerror.error != QJsonParseError::NoError)
|
||||
// qDebug() << "no found";
|
||||
|
||||
if ( !jobj.contains("Puffer"))
|
||||
qDebug() << "no Puffer found";
|
||||
|
||||
if ( !myArray.contains(20))
|
||||
qDebug() << "no entry found";
|
||||
} */
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------ read, write, copy files -------------------
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
void datei_closeFile(QString filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
file.close();
|
||||
}
|
||||
|
||||
QByteArray datei_readFromFile(QString filename)
|
||||
{
|
||||
//QFile file("/own/H2B/dc2.hex");
|
||||
//QFile file(FILENAME_STRUCTURE);
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
QByteArray myBA;
|
||||
|
||||
myBA.clear();
|
||||
if (!file.exists())
|
||||
{
|
||||
qDebug()<<"file not exists";
|
||||
return myBA;
|
||||
} else
|
||||
{
|
||||
if (!file.open(QIODevice::ReadOnly) )
|
||||
{
|
||||
qDebug()<<"cannot open";
|
||||
|
||||
} else
|
||||
{
|
||||
//qDebug()<<"loading file with " << file.size() <<"byte";
|
||||
myBA = file.readAll();
|
||||
//qDebug()<<"datei read: " << myBA;
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
return myBA;
|
||||
}
|
||||
|
||||
bool datei_ifFileExists(QString filename)
|
||||
{
|
||||
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
|
||||
if (file.exists())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
char datei_writeToFile(QString filename, QByteArray content)
|
||||
{
|
||||
// retval=0 if successful 1: no write access allowed 2:cannot open to append 3:cannot create new file
|
||||
QFile file(filename);
|
||||
QFileInfo myFI(filename);
|
||||
|
||||
//if (!myFI.isWritable()) //geht nur bei NTFS, weg.
|
||||
//{
|
||||
//file.setPermissions(filename, QFile::WriteOther); geht nicht :(
|
||||
// qDebug()<<"datei_writeToFile: writing not allowed. set attributes first!";
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
if (!file.open(QIODevice::Append))
|
||||
{
|
||||
qDebug()<<"datei_writeToFile cannot open to append";
|
||||
return 2;
|
||||
} else
|
||||
{
|
||||
// add new object to the end of the file
|
||||
file.write(content);
|
||||
file.close();
|
||||
return 0; // OK
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
qDebug()<<"datei_writeToFile cannot open new";
|
||||
return 3;
|
||||
} else
|
||||
{
|
||||
qDebug()<<"create new file";
|
||||
// write first lines into file
|
||||
file.write(content);
|
||||
file.close();
|
||||
return 0; // OK
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool datei_copyFile(QString currentFileName, QString newFileName)
|
||||
{
|
||||
// retval=true if successful
|
||||
QFile file;
|
||||
file.setFileName(currentFileName);
|
||||
return file.copy(newFileName);
|
||||
}
|
||||
|
||||
bool datei_clearFile(QString filename)
|
||||
{
|
||||
// retval=true if successful
|
||||
QFile file;
|
||||
file.setFileName(filename);
|
||||
|
||||
file.remove(); // 3.2.22 erst ganz löschen wegen Schreibrechten
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
qDebug()<<"datei_clearFile cannot open file to delete";
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
file.write(0);
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
960
src/hwapi.cpp
960
src/hwapi.cpp
File diff suppressed because it is too large
Load Diff
9
src/main.cpp
Normal file
9
src/main.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <QCoreApplication>
|
||||
#include "tslib.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
return a.exec();
|
||||
}
|
@@ -14,7 +14,7 @@ void sendWRcmd_INI(void)
|
||||
sendWRcmd_clrCmdStack();
|
||||
sendWRcmd_clrCmd4Stack();
|
||||
sendFDcmd_clrStack();
|
||||
longFDcmd_clrStack();
|
||||
|
||||
}
|
||||
|
||||
// Command Stack for commands without parameters
|
||||
@@ -456,18 +456,23 @@ uint8_t gpi_chk4remainingText(void)
|
||||
// ---------------------------------------------------------------------------------
|
||||
// 11.4.23 neu, Kommando direkt an "FastDevice"-protokoll senden, nicht mehr umsetzen
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// short command, 4 data bytes
|
||||
// header
|
||||
static uint8_t nextFDwrCmd[FDCMD_STACKDEPTH];
|
||||
static uint8_t nextFDrdCmd[FDCMD_STACKDEPTH];
|
||||
static uint8_t nextFDblkNr[FDCMD_STACKDEPTH];
|
||||
static uint8_t nextFDshort[FDCMD_STACKDEPTH];
|
||||
|
||||
// short data
|
||||
static uint8_t nextFDpara1[FDCMD_STACKDEPTH];
|
||||
static uint8_t nextFDpara2[FDCMD_STACKDEPTH];
|
||||
static uint8_t nextFDpara3[FDCMD_STACKDEPTH];
|
||||
static uint8_t nextFDpara4[FDCMD_STACKDEPTH];
|
||||
// lon data:
|
||||
static uint8_t longFDlength[FDCMD_STACKDEPTH];
|
||||
static uint8_t longFDpara[FDCMD_STACKDEPTH][64];
|
||||
|
||||
static uint8_t p_nextFDcmdsInQueue;
|
||||
|
||||
/* convention: use simple (not rotating) FIFO Stack:
|
||||
Example: nrOfCmdsInQueue=4 then
|
||||
nextAsynchsendCmd0[0]=cmd1 // was stored as first
|
||||
@@ -492,16 +497,21 @@ void sendFDcmd_clrStack(void)
|
||||
nextFDwrCmd[nn]=0;
|
||||
nextFDrdCmd[nn]=0;
|
||||
nextFDblkNr[nn]=0;
|
||||
nextFDshort[nn]=0;
|
||||
nextFDpara1[nn]=0;
|
||||
nextFDpara2[nn]=0;
|
||||
nextFDpara3[nn]=0;
|
||||
nextFDpara4[nn]=0;
|
||||
longFDlength[nn]=0;
|
||||
memset(&longFDpara[nn][0],0,64);
|
||||
}
|
||||
|
||||
p_nextFDcmdsInQueue=0;
|
||||
}
|
||||
|
||||
bool sendFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4)
|
||||
{
|
||||
|
||||
// write Command to memory, wait for transport
|
||||
if (p_nextFDcmdsInQueue>=FDCMD_STACKDEPTH)
|
||||
{
|
||||
@@ -518,13 +528,68 @@ bool sendFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8
|
||||
//qDebug() << "data with 4 data byte saved, pp=" << nrOfCmds4InQueue;
|
||||
//qDebug() << " dat1=" << nextCmd4para1[nrOfCmds4InQueue] << " dat2=" << nextCmd4para2[nrOfCmds4InQueue]
|
||||
// << " dat3=" << nextCmd4para3[nrOfCmds4InQueue] << " dat4=" << nextCmd4para4[nrOfCmds4InQueue];
|
||||
nextFDshort[p_nextFDcmdsInQueue]=1; // 1=short
|
||||
p_nextFDcmdsInQueue++;
|
||||
/*
|
||||
int nn;
|
||||
if (p_nextFDcmdsInQueue==2)
|
||||
{
|
||||
qDebug() << "sendFDcmd_set, stack has 2 elements: " << p_nextFDcmdsInQueue;
|
||||
for (nn=0; nn<16; nn++)
|
||||
{
|
||||
qDebug() << "header: " << nextFDwrCmd[nn] << " / " << nextFDrdCmd[nn] << " / "<< nextFDblkNr[nn] << " / " << nextFDshort[nn];
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (p_nextFDcmdsInQueue>15)
|
||||
{
|
||||
qDebug() << "sendFDcmd_set, stack is full now: " << p_nextFDcmdsInQueue;
|
||||
for (nn=0; nn<16; nn++)
|
||||
{
|
||||
qDebug() << "header: " << nextFDwrCmd[nn] << " / " << nextFDrdCmd[nn] << " / "<< nextFDblkNr[nn] << " / " << nextFDpara1[nn] << " / " << nextFDpara2[nn] << " / " << nextFDpara3[nn] << " / " << nextFDpara4[nn];
|
||||
|
||||
qDebug() << " long data: " << nextFDshort[nn] << " / "<< longFDlength[nn] << " / "<< longFDpara[nn][0] << " / "<< longFDpara[nn][1]
|
||||
<< " / "<< longFDpara[nn][2] << " / "<< longFDpara[nn][3] << " / "<< longFDpara[nn][4];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
return true; // ok, will be sent
|
||||
}
|
||||
|
||||
|
||||
bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t length, uint8_t *data)
|
||||
{
|
||||
// write Command to memory, wait for transport
|
||||
// data buffer size always 64! data[64], padded with 0
|
||||
uint8_t nn;
|
||||
if (p_nextFDcmdsInQueue>=FDCMD_STACKDEPTH)
|
||||
{
|
||||
qDebug() << "cannot save cmd because stack is full";
|
||||
return false; // not possible
|
||||
}
|
||||
nextFDwrCmd[p_nextFDcmdsInQueue]=nextWrCmd;
|
||||
nextFDrdCmd[p_nextFDcmdsInQueue]=nextRdCmd;
|
||||
nextFDblkNr[p_nextFDcmdsInQueue]=blockNum;
|
||||
|
||||
longFDlength[p_nextFDcmdsInQueue]=length;
|
||||
|
||||
for (nn=0; nn<64; nn++)
|
||||
longFDpara[p_nextFDcmdsInQueue][nn]=data[nn];
|
||||
|
||||
nextFDshort[p_nextFDcmdsInQueue]=2;
|
||||
|
||||
p_nextFDcmdsInQueue++;
|
||||
return true; // ok, will be sent
|
||||
}
|
||||
|
||||
|
||||
bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4)
|
||||
{
|
||||
uint8_t nn, ll;
|
||||
uint8_t nn, ll, mm;
|
||||
|
||||
if (p_nextFDcmdsInQueue==0 || p_nextFDcmdsInQueue>FDCMD_STACKDEPTH)
|
||||
return false; // not possible
|
||||
@@ -536,7 +601,7 @@ bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, ui
|
||||
*dat2=nextFDpara2[0];
|
||||
*dat3=nextFDpara3[0];
|
||||
*dat4=nextFDpara4[0];
|
||||
//qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue;
|
||||
//qDebug() << "sendFDcmd_get [0]; pp=" << p_nextFDcmdsInQueue;
|
||||
//qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] <<
|
||||
// " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0];
|
||||
|
||||
@@ -550,17 +615,74 @@ bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, ui
|
||||
nextFDwrCmd[nn]=nextFDwrCmd[nn+1];
|
||||
nextFDrdCmd[nn]=nextFDrdCmd[nn+1];
|
||||
nextFDblkNr[nn]=nextFDblkNr[nn+1];
|
||||
|
||||
nextFDpara1[nn]=nextFDpara1[nn+1];
|
||||
nextFDpara2[nn]=nextFDpara2[nn+1];
|
||||
nextFDpara3[nn]=nextFDpara3[nn+1];
|
||||
nextFDpara4[nn]=nextFDpara4[nn+1];
|
||||
|
||||
nextFDshort[nn] = nextFDshort[nn+1];
|
||||
|
||||
longFDlength[nn] = longFDlength[nn+1];
|
||||
|
||||
for (mm=0; mm<64; mm++)
|
||||
longFDpara[nn][mm] = longFDpara[nn+1][mm];
|
||||
}
|
||||
|
||||
if (p_nextFDcmdsInQueue>0)
|
||||
p_nextFDcmdsInQueue--;
|
||||
//qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue;
|
||||
|
||||
// clear released buffer:
|
||||
for (nn=p_nextFDcmdsInQueue; nn<FDCMD_STACKDEPTH; nn++)
|
||||
{
|
||||
nextFDwrCmd[nn]=0;
|
||||
nextFDrdCmd[nn]=0;
|
||||
nextFDblkNr[nn]=0;
|
||||
|
||||
nextFDpara1[nn]=0;
|
||||
nextFDpara2[nn]=0;
|
||||
nextFDpara3[nn]=0;
|
||||
nextFDpara4[nn]=0;
|
||||
|
||||
nextFDshort[nn]=0;
|
||||
|
||||
longFDlength[nn]=0;
|
||||
|
||||
for (mm=0; mm<64; mm++)
|
||||
longFDpara[nn][mm] = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
qDebug() << "sendFDcmd_set, stack now: " << p_nextFDcmdsInQueue;
|
||||
for (nn=0; nn<16; nn++)
|
||||
{
|
||||
qDebug() << "header: " << nextFDwrCmd[nn] << " / " << nextFDrdCmd[nn] << " / "<< nextFDblkNr[nn] << " / " << nextFDshort[nn];
|
||||
|
||||
qDebug() << " short data: " << nextFDpara1[nn] << " / "<< nextFDpara2[nn] << " / "<< nextFDpara3[nn]<< " / "<< nextFDpara4[nn];
|
||||
|
||||
qDebug() << " long data: " << longFDlength[nn] << " / "<< longFDpara[nn][0] << " / "<< longFDpara[nn][1]
|
||||
<< " / "<< longFDpara[nn][2] << " / "<< longFDpara[nn][3] << " / "<< longFDpara[nn][4];
|
||||
}
|
||||
*/
|
||||
return true; // ok, will be sent
|
||||
}
|
||||
|
||||
uint8_t checkNextFDcmd(void)
|
||||
{
|
||||
// return 0: no command waiting
|
||||
// 1: short cmd
|
||||
// 2: long cmd
|
||||
//qDebug() << "chk nxt fd cmd: "<<p_nextFDcmdsInQueue<<" "<<nextFDshort[0]<<" "<<nextFDshort[1]<<" "<<nextFDshort[2]<<" "<<nextFDshort[3];
|
||||
if (p_nextFDcmdsInQueue==0)
|
||||
return 0;
|
||||
if (nextFDshort[0]==1)
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
uint8_t check4FDshortCmd(void)
|
||||
{
|
||||
// returns number of waiting command, max FDCMD_STACKDEPTH
|
||||
@@ -576,15 +698,15 @@ uint8_t check4freeFDshortCmd(void)
|
||||
|
||||
|
||||
// long command, 64 data bytes
|
||||
static uint8_t longFDwrCmd[FDLONG_STACKDEPTH];
|
||||
static uint8_t longFDrdCmd[FDLONG_STACKDEPTH];
|
||||
static uint8_t longFDblkNr[FDLONG_STACKDEPTH];
|
||||
static uint8_t longFDlength[FDLONG_STACKDEPTH];
|
||||
|
||||
static uint8_t longFDpara[FDLONG_STACKDEPTH][64];
|
||||
static uint8_t p_longFDcmdsInQueue;
|
||||
//static uint8_t longFDwrCmd[FDLONG_STACKDEPTH];
|
||||
//static uint8_t longFDrdCmd[FDLONG_STACKDEPTH];
|
||||
//static uint8_t longFDblkNr[FDLONG_STACKDEPTH];
|
||||
//static uint8_t longFDlength[FDLONG_STACKDEPTH];
|
||||
|
||||
//static uint8_t longFDpara[FDLONG_STACKDEPTH][64];
|
||||
//static uint8_t p_longFDcmdsInQueue;
|
||||
|
||||
/*
|
||||
void longFDcmd_clrStack(void)
|
||||
{
|
||||
uint8_t nn, mm;
|
||||
@@ -598,66 +720,74 @@ void longFDcmd_clrStack(void)
|
||||
longFDpara[nn][mm]=0;
|
||||
}
|
||||
p_longFDcmdsInQueue=0;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t length, uint8_t *data)
|
||||
{
|
||||
// write Command to memory, wait for transport
|
||||
// data buffer size always 64! data[64], padded with 0
|
||||
uint8_t nn;
|
||||
if (p_longFDcmdsInQueue>=FDLONG_STACKDEPTH)
|
||||
{
|
||||
qDebug() << "cannot save cmd because stack is full";
|
||||
return false; // not possible
|
||||
}
|
||||
longFDwrCmd[p_longFDcmdsInQueue]=nextWrCmd;
|
||||
longFDrdCmd[p_longFDcmdsInQueue]=nextRdCmd;
|
||||
longFDblkNr[p_longFDcmdsInQueue]=blockNum;
|
||||
longFDlength[p_longFDcmdsInQueue]=length;
|
||||
for (nn=0; nn<64; nn++)
|
||||
longFDpara[p_longFDcmdsInQueue][nn]=data[nn];
|
||||
|
||||
p_longFDcmdsInQueue++;
|
||||
return true; // ok, will be sent
|
||||
}
|
||||
|
||||
bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data)
|
||||
{
|
||||
uint8_t nn, mm, ll;
|
||||
|
||||
if (p_longFDcmdsInQueue==0 || p_longFDcmdsInQueue>FDLONG_STACKDEPTH)
|
||||
//p_nextFDcmdsInQueue; nn<FDCMD_STACKDEPTH
|
||||
if (p_nextFDcmdsInQueue==0 || p_nextFDcmdsInQueue>FDCMD_STACKDEPTH)
|
||||
return false; // not possible
|
||||
|
||||
*nextWrCmd= longFDwrCmd[0];
|
||||
*nextRdCmd= longFDrdCmd[0];
|
||||
*blockNum = longFDblkNr[0];
|
||||
*nextWrCmd=nextFDwrCmd[0];
|
||||
*nextRdCmd=nextFDrdCmd[0];
|
||||
*blockNum=nextFDblkNr[0];
|
||||
|
||||
*length = longFDlength[0];
|
||||
for (mm=0; mm<64; mm++)
|
||||
data[mm] = longFDpara[0][mm];
|
||||
|
||||
// move Puffer down by one element
|
||||
if (FDLONG_STACKDEPTH>0)
|
||||
ll=FDLONG_STACKDEPTH-1;
|
||||
if (FDCMD_STACKDEPTH>0)
|
||||
ll=FDCMD_STACKDEPTH-1;
|
||||
else
|
||||
ll=0;
|
||||
for (nn=0; nn<ll; nn++)
|
||||
{
|
||||
longFDwrCmd[nn] = longFDwrCmd[nn+1];
|
||||
longFDrdCmd[nn] = longFDrdCmd[nn+1];
|
||||
longFDblkNr[nn] = longFDblkNr[nn+1];
|
||||
nextFDwrCmd[nn]=nextFDwrCmd[nn+1];
|
||||
nextFDrdCmd[nn]=nextFDrdCmd[nn+1];
|
||||
nextFDblkNr[nn]=nextFDblkNr[nn+1];
|
||||
|
||||
nextFDpara1[nn]=nextFDpara1[nn+1];
|
||||
nextFDpara2[nn]=nextFDpara2[nn+1];
|
||||
nextFDpara3[nn]=nextFDpara3[nn+1];
|
||||
nextFDpara4[nn]=nextFDpara4[nn+1];
|
||||
|
||||
nextFDshort[nn] = nextFDshort[nn+1];
|
||||
|
||||
longFDlength[nn] = longFDlength[nn+1];
|
||||
|
||||
for (mm=0; mm<64; mm++)
|
||||
longFDpara[nn][mm] = longFDpara[nn+1][mm];
|
||||
|
||||
}
|
||||
if (p_longFDcmdsInQueue>0)
|
||||
p_longFDcmdsInQueue--;
|
||||
if (p_nextFDcmdsInQueue>0)
|
||||
p_nextFDcmdsInQueue--;
|
||||
|
||||
// clear released buffer:
|
||||
for (nn=p_nextFDcmdsInQueue; nn<FDCMD_STACKDEPTH; nn++)
|
||||
{
|
||||
nextFDwrCmd[nn]=0;
|
||||
nextFDrdCmd[nn]=0;
|
||||
nextFDblkNr[nn]=0;
|
||||
|
||||
nextFDpara1[nn]=0;
|
||||
nextFDpara2[nn]=0;
|
||||
nextFDpara3[nn]=0;
|
||||
nextFDpara4[nn]=0;
|
||||
|
||||
nextFDshort[nn]=0;
|
||||
|
||||
longFDlength[nn]=0;
|
||||
for (mm=0; mm<64; mm++)
|
||||
longFDpara[nn][mm] = 0;
|
||||
}
|
||||
|
||||
|
||||
return true; // ok, will be sent
|
||||
}
|
||||
|
||||
/*
|
||||
uint8_t check4FDlongCmd(void)
|
||||
{
|
||||
// returns number of waiting command
|
||||
@@ -669,5 +799,33 @@ uint8_t check4freeFDlongCmd(void)
|
||||
// returns number of free places in command stack
|
||||
return FDLONG_STACKDEPTH - p_longFDcmdsInQueue;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static uint8_t Sdata_DeviceParameter[64];
|
||||
static uint8_t Sdata_DevParaLen;
|
||||
|
||||
uint8_t epi_store64BdevParameter(uint8_t length, uint8_t *buf)
|
||||
{
|
||||
// HWapi writes data to be stored
|
||||
uint8_t nn;
|
||||
for (nn=0; nn<length; nn++)
|
||||
Sdata_DeviceParameter[nn]=buf[nn];
|
||||
for (nn=length; nn<64; nn++)
|
||||
Sdata_DeviceParameter[nn]=0;
|
||||
|
||||
Sdata_DevParaLen=length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t epi_restore64BdevParameter(uint8_t *length, uint8_t *buf)
|
||||
{
|
||||
|
||||
for (uint8_t nn=0; nn<Sdata_DevParaLen; nn++)
|
||||
buf[nn]=Sdata_DeviceParameter[nn];
|
||||
*length=Sdata_DevParaLen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -9,16 +9,23 @@
|
||||
// macro will be defined. -> we use SystemV shared memory
|
||||
#error "QT_POSIX_IPC defined"
|
||||
#else
|
||||
#ifdef __linux__
|
||||
#include <sys/ipc.h> // ftok
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// std::atomic_bool SharedMemBuffer::__sharedMemLocked{false};
|
||||
|
||||
QSharedMemory *SharedMemBuffer::getShm(std::size_t size) {
|
||||
static QSharedMemory shMem;
|
||||
if (size > 0) {
|
||||
#ifdef __linux__
|
||||
static const long nativeKey = ftok("/etc/os-release", 'H');
|
||||
static const QString fkey = std::to_string(nativeKey).c_str();
|
||||
#else
|
||||
static const QString fkey = "0123456?000=9";
|
||||
#endif
|
||||
|
||||
shMem.setKey(fkey);
|
||||
if (!shMem.isAttached()) {
|
||||
if (shMem.create(size)) {
|
||||
|
1744
src/storeINdata.cpp
1744
src/storeINdata.cpp
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user