Start repository

This commit is contained in:
Gerhard Hoffmann 2023-11-08 13:02:26 +01:00
parent 726c886492
commit a9041d417d
69 changed files with 31804 additions and 0 deletions

54
CArunGUI/CArunGUI.pro Normal file
View File

@ -0,0 +1,54 @@
QT += core gui
QT +=widgets serialport
QT +=network
# for TCP-IP
TARGET = CArunGui
DESTDIR=$${_PRO_FILE_PWD_}/../build
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += PTU5
# _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
QMAKE_CXXFLAGS += -O
INCLUDEPATH += ../include
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
SOURCES += \
main.cpp \
mainwindow.cpp \
tslib.cpp \
win01_com.cpp \
datei.cpp
HEADERS += \
guidefs.h \
mainwindow.h \
stepList.h \
tslib.h \
versionHistory.txt \
win01_com.h \
datei.h \
plugin.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

945
CArunGUI/datei.cpp Executable file
View File

@ -0,0 +1,945 @@
// written by Thomas Sax, Jan.2022
#include <cstdint>
#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;
}
}

208
CArunGUI/datei.h Executable file
View File

@ -0,0 +1,208 @@
#ifndef DATEI_H
#define DATEI_H
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include "tslib.h"
#include <QString>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
// create csv file with:
#define FILESEPERATOR ','
// pasre csv with:
#define FILESEP1 ','
#define FILESEP2 ';'
#define NEWLINEINFILE '\n'
#define MAXNUMBEROFSEQUENCES 200
// only for csv files
// all seting-files located in sudirectory "static machine data - smd"
// all generated files located in sudirectory "dynamic machine data - dmd"
#define FILENAME_COMPORT "../comport.csv"
#define FILENAME_CONFIG "/own/work2023/PSA1256ptu5/smd/DC2C_conf.json"
#define FILENAME_DEVICE "/own/work2023/PSA1256ptu5/smd/DC2C_device.json"
#define FILENAME_CASH "/own/work2023/PSA1256ptu5/smd/DC2C_cash.json"
#define FILENAME_PRINT "/own/work2023/PSA1256ptu5/smd/DC2C_print32.json"
#define FILENAME_APSERVCONF "../APserviceConfig.csv"
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ create csv file -------------------------------
// -------------------------------------------------------------------------------------------------
// create array with strings and values (to be written to file)
void csv_startCreatingFile(void);
void csv_addTextToFile(QString myText);
void csv_addIntToFile(int myValue);
void csv_addUintToFile(uint myValue);
void csv_addLongvalToFile(qlonglong myValue);
void csv_addUlongvalToFile(qulonglong myValue);
//void csv_addCurrentTimeToFile(void);
//void csv_addCurrentDateToFile(void);
void csv_addNewlineToFile(void);
QByteArray csv_readbackArray(void);
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ parse csv file -------------------------------
// -------------------------------------------------------------------------------------------------
// return number of entries in the just read file (entries are seperated by
// comma or line-feed)
uint32_t csv_nrOfEntriesInFile(QByteArray readFromFile);
// before: QByteArray sourceFile=datei_readFromFile(filename);
QByteArray csv_getOneFileSequence(QByteArray sourceFile, uint32_t sequNr);
// not needed, just for test // sequNr: 0....(size-1)
// get single entries of of the just read fie:
int csv_getEntryAsInt(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
int32_t csv_getEntryAsLong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint8_t csv_getEntryAsUshort(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint16_t csv_getEntryAsUint(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint32_t csv_getEntryAsUlong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint64_t csv_getEntryAs2Ulong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
QString csv_getEntryAsString(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ create Json Record -------------------------------
// -------------------------------------------------------------------------------------------------
void json_startRecord(void);
// clear buffer and write opening curly bracket {
void json_enterIntToRecord(QString attribute, ulong i_value);
// example: "parameter":1234567890
void json_enterTextToRecord(QString attribute, QString txt_value);
// example: "parameter":"slow"
//void json_addCurrentTimeToRecord(QString attribute);
// example: if attribute=myTime: "myTime":"hh_mm_ss"
//void json_addCurrentDateToRecord(QString attribute);
// example: if attribute=myDate: "myDate":"dd.mm.yyyy"
// also / possible as seperator
// further possible forms:
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
void json_enterArrayToRecord(QString attribute, uint8_t *buf, ulong nrofVals);
// add array of numbers with "nrofVals" elements
void json_enterStructToRecord(QString attribute);
// every call must be concluded with an extra "json_finishFile()"
// example: "sname":{
void json_finishStruct(void);
void json_finishRecord(void);
// close curly bracket
QString json_readbackRecordStr(void);
QByteArray json_readbackRecordBa(void);
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ parse Json file -------------------------------
// -------------------------------------------------------------------------------------------------
// first: QByteArray datei_readFromFile(QString filename);
//void datei_json_readTestFile(QString filename);
int json_nrOfPairsInFile(QByteArray filename);
bool json_exists(QByteArray filename, QString searchForKey);
// look for "searchForKey" =name of the pair (left of : )
// retval true if exists
bool json_remove(QByteArray filename, QString searchFor);
// look for "searchFor" =name of the pair (left of : ) and remove the record from file
// retval true if removed
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
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
//.......................
QJsonObject json_searchForObjectInFile(QByteArray filename, QString searchFor);
// return an object from the json file
int json_nrOfPairsInObject(QJsonObject objname);
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
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
//.......................
QJsonArray json_searchForArrayInFile(QByteArray filename, QString searchFor);
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
int json_nrOfValuesInArray(QJsonArray arrayname);
bool json_getValuesOfArray(QJsonArray arrayname, int *buf, int MaxBufferSize);
// assuming that the array consists of integers
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ read, write, copy files -------------------
// -------------------------------------------------------------------------------------------------
void datei_closeFile(QString filename);
// read content of an exiting file:
QByteArray datei_readFromFile(QString filename);
bool datei_ifFileExists(QString filename);
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
bool datei_copyFile(QString currentFileName, QString newFileName);
// retval=true if successful
bool datei_clearFile(QString filename);
// retval=true if successful
#endif // DATEI_H

24
CArunGUI/guidefs.h Executable file
View File

@ -0,0 +1,24 @@
#ifndef GUIDEFS_H
#define GUIDEFS_H
#define PIXELSIZE_BUTTONS 18
#define PIXELSIZE_LABEL 18
#define PIXELSIZE_DATA 16
#define PIXELSIZE_BIGFONT 22
#define PIXELSIZE_SMALLFONT 14
#define BUTTONCOLOR "background-color: rgb(150,250,150)"
#define COLORGREEN "background-color: rgb(160,250,190)"
#define COLOR_RED "background-color: rgb(150,0,0)"
#define COLOR_LIGHTRED "background-color: rgb(250,150,150)"
//#define COLORGREY "background-color: rgb(160,250,190)"
#define COLORGREY "background-color: grey"
#define COLORYELLOW "background-color: yellow"
#define COLORWHITE "background-color: white"
// "background-color: lightgrey"
#endif

43
CArunGUI/main.cpp Executable file
View File

@ -0,0 +1,43 @@
#include "mainwindow.h"
//#include "message_handler.h"
#include <QApplication>
int thisisglobal;
int main(int argc, char *argv[])
{
int ret;
QApplication myapp(argc, argv);
QApplication::setApplicationName("CArunGui");
QApplication::setApplicationVersion(APP_VERSION);
/*
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtDebugMsg);
//setDebugLevel(QtMsgType::QtDebugMsg);
}
*/
MainWindow myMainWin;
QSize myMainSize={800, 480}; // breite, höhe, PTU: 800x440
myMainWin.setMinimumSize(myMainSize);
myMainWin.setMaximumSize(myMainSize);
myMainWin.setWindowTitle("CArun_V4.2 run cash agent master lib");
myMainWin.show();
ret=myapp.exec();
return ret;
}
//QApplication a(argc, argv);
//MainWindow CatMW;
//QSize myMainSize={800, 480}; // breite, höhe
//CatMW.setMinimumSize(myMainSize);
//CatMW.setMaximumSize(myMainSize);
//CatMW.setWindowTitle("ATB CashAgent V2.0");
// QPalette mainPal;
// mainPal.setColor(QPalette::Window, Qt::red );
// CatMW.setPalette(mainPal); sieht man nicht mehr

438
CArunGUI/mainwindow.cpp Executable file
View File

@ -0,0 +1,438 @@
#include "mainwindow.h"
char MainWindow::loadPlugIn(char lade1_entlade2)
{
plugInDir.cd("plugins");
QPluginLoader *pluginLoader = new QPluginLoader();
// select system:
//pluginLoader->setFileName("../MasterPlug/libCAmaster.so"); // for suse
//pluginLoader->setFileName("../SlavePlug/libCAslave.so"); // for ptu5
//pluginLoader->setFileName("../../MasterPlug/CAmaster.dll"); // for windows
pluginLoader->setFileName("CAmaster.dll"); // for windows
if (lade1_entlade2==2)
{
pluginLoader->unload();
return 0;
}
if (!pluginLoader->load())
{
qDebug()<<"cannot load plugin";
} else
qDebug() <<"loaded plugin: " << pluginLoader->fileName();
if (!pluginLoader->isLoaded())
{
qDebug()<<pluginLoader->errorString();
return 0;
}
QObject *plugin = pluginLoader->instance();
if ( plugin == nullptr)
{
// make instance of the root component (which can hold more then one clases)
// also loads the lib if not yet done
qDebug()<<"cannot start instance";
return 0;
}
//int rr=hwapi->giveVal(2); funktioniert :))
//qDebug()<<"got value from plugin"<<rr; funktioniert :))
// aber besser globaler pointer:
// im h-file
// hwinf *hwapi=nullptr; // pointer to plugin-class
HWaccess= qobject_cast<hwinf *>(plugin);
// make instance to class "hwinf" in dll_HWapi.h over "interfaces.h"
qDebug()<<"loadPlugIn, HWAccess: " << HWaccess;
return 0;
}
#define WINCTRMIN 0
// 0 is always the home screen
#define WINCTRMAX 30
// number of needed application screens, up to 255
// All screens must be defined below in mainwindow-class first before increasing the nr
// numbers must be consecutively from 0 always, 0 is the home screen always
#define FORMWIDTH 725
//#define FORMWIDTH 690
// this width is the same for ALL windows
#define FORMHEIGHT 440
// this height is the same for ALL windows
#define NAVIBUTTONHEIGHT 70
#define NAVIBUTTONWIDHT 50
#define HOMEPAGE_BACKGROUND_COLOR "background-color: lightgrey"
#define BUTTON_COLOR "background-color: rgb(160,250,190)"
#define ACTIVE_NAVI_COLOR "background-color: rgb(160,250,190)"
#define DISABL_NAVI_COLOR "background-color: grey"
#define APPPAGE_BACKGROUND_COLOR "background-color: lightgrey"
#define UPDATE_PERIOD_MS 100
// period to call chain steps
#define VENDINGTIMEOUT_MS 30000
// after this time without any operation the program returns to idle state
// time in ms, that means 30.000 gives 30seconds
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
loadPlugIn(1);
// define all working moduls (besides gui) here, call ini and working in chainControl() (~Line 1000)
//mifCard = new T_Mifare(HWaccess); // ganz wichtig: HWaccess an sub-Konstruktor übergeben
// sonst crash bei HW-Zugriff!!!!
//diary = new T_lib_diary(); absturz!!!!!!
//conf = new T_lib_config(HWaccess);
timerChainCtrl = new QTimer(this);
connect(timerChainCtrl, SIGNAL(timeout()), this, SLOT(chainControl()));
timerChainCtrl->setSingleShot(0);
timerChainCtrl->start(UPDATE_PERIOD_MS); // 1000: call every 1000ms
timerVendingTimeout = new QTimer(this);
connect(timerVendingTimeout, SIGNAL(timeout()), this, SLOT(vendingTimeout()));
timerVendingTimeout->setSingleShot(true);
timerVendingTimeout->start(VENDINGTIMEOUT_MS); // in ms
// ##########################################################################################
// für jedes anzuzeigende Fenster eine eigene Groupbox mit eigenem Grid anlegen:
frame01 = new QGroupBox;
frame01->setStyleSheet(APPPAGE_BACKGROUND_COLOR);
frame01->setMinimumSize(FORMWIDTH,FORMHEIGHT);
QVBoxLayout *smallLay01 = new QVBoxLayout;
frame01->setLayout(smallLay01);
// Fensterinhalt aus externer Klasse einfügen:
myFenster01 = new T_winComPort(HWaccess); // HWaccess damit auf das HW-Plugin zugegriffen werden kann, sonst crash
smallLay01->addWidget(myFenster01);
// ##########################################################################################
// draw Mainwindow:
bigGroupbox = new QGroupBox;
bigGroupbox->setStyleSheet("background-color: grey");
bigGroupbox->setMinimumSize(800,480);
// bigLayout = new QVBoxLayout; // navi buttons on bottom side
bigLayout = new QHBoxLayout; // navi buttons right hand
// ##########################################################################################
// add all windows (but display only one)
// display only one: then all windows are shown at the same place
// display more then one: the windows are listed in vertical order
bigLayout->addWidget(frame01);
bigGroupbox->setLayout(bigLayout);
switchScreen(1);
//HideAllWindows();
// ##########################################################################################
// Steuer Leiste
//QHBoxLayout *ButtonLayout = new QHBoxLayout();
QVBoxLayout *ButtonLayout = new QVBoxLayout();
QFont myTabFont;
myTabFont.setPixelSize(26);
pBback = new QPushButton("<"); //b\na\nc\nk");
pBback->setFont(myTabFont);
pBback->setStyleSheet(ACTIVE_NAVI_COLOR);
pBback->setMinimumHeight(NAVIBUTTONHEIGHT);
pBback->setMaximumWidth(NAVIBUTTONWIDHT);
connect(pBback, SIGNAL( clicked() ), myFenster01, SLOT( Nav_back()));
myTabFont.setPixelSize(22);
pBhome = new QPushButton("<<"); //h\no\nm\ne");
pBhome->setFont(myTabFont);
pBhome->setStyleSheet(ACTIVE_NAVI_COLOR);
pBhome->setMinimumHeight(NAVIBUTTONHEIGHT);
pBhome->setMaximumWidth(NAVIBUTTONWIDHT);
connect(pBhome, SIGNAL( clicked() ), myFenster01, SLOT( Nav_home()));
myTabFont.setPixelSize(26);
pBforward = new QPushButton(">"); //n\ne\nx\nt");
pBforward->setFont(myTabFont);
pBforward->setStyleSheet(ACTIVE_NAVI_COLOR);
pBforward->setMinimumHeight(NAVIBUTTONHEIGHT);
pBforward->setMaximumWidth(NAVIBUTTONWIDHT);
connect(pBforward, SIGNAL( clicked() ), myFenster01, SLOT( Nav_next()));
QLabel *buttonSpace = new QLabel(" ");
ButtonLayout->addWidget(pBback);
ButtonLayout->addWidget(buttonSpace);
//ButtonLayout->addWidget(buttonSpace);
ButtonLayout->addWidget(pBhome);
ButtonLayout->addWidget(buttonSpace);
//ButtonLayout->addWidget(buttonSpace);
ButtonLayout->addWidget(pBforward);
QLabel *bottomSpace = new QLabel(" ");
ButtonLayout->addWidget(bottomSpace);
bigLayout->addLayout(ButtonLayout);
setCentralWidget(bigGroupbox);
// AUTOSTART serial transmission
//HWaccess->dc_openSerial(5,"115200","ttyS0",1); // my suse computer
//HWaccess->dc_openSerial(1,"9600","COM5",1); // my suse computer
//HWaccess->dc_openSerial(5,"115200","ttymxc2",1); // ptu5
//HWaccess->dc_autoRequest(true);
//myFenster01->setButtons4autoStart();
//HWaccess->alarm_switchSiren(0); // test
enableNaviButtons(BACKBUTTON,true);
enableNaviButtons(HOMEBUTTON,true);
enableNaviButtons(FORWBUTTON,true);
this->chainIni();
//connect(myFenster02, SIGNAL(quitMyApp()), this, SLOT(close()));
}
MainWindow::~MainWindow()
{
loadPlugIn(2);
}
void MainWindow::HideAllWindows()
{
// vorsicht: Fenster muss oben definiert sein sonst Programmabsturz ohne Kommentar
frame01->setEnabled(false);
frame01->setVisible(false);
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Call Windows
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void MainWindow::switchScreen(uint16_t winNr) // 0...30
{
HideAllWindows();
//qDebug()<<"switch screen to " << winNr;
switch (winNr)
{
case 1:
frame01->setEnabled(true);
frame01->setVisible(true);
break;
default:
break;
}
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Navigation buttons
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void MainWindow::enableNaviButtons(uint8_t switchBitwise)
{
// switchBitwise=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
if (switchBitwise &1)
{
pBforward->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBforward->setText("next");
pBforward->setEnabled(true);
} else
if (switchBitwise &2)
{
pBforward->setStyleSheet(DISABL_NAVI_COLOR);
//pBforward->setText(" ");
pBforward->setEnabled(false);
}
if (switchBitwise &4)
{
pBhome->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBhome->setText("home");
pBhome->setEnabled(true);
} else
if (switchBitwise &8)
{
pBhome->setStyleSheet(DISABL_NAVI_COLOR);
//pBhome->setText(" ");
pBhome->setEnabled(false);
}
if (switchBitwise &16)
{
pBback->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBback->setText("back");
pBback->setEnabled(true);
} else
if (switchBitwise &32)
{
pBback->setStyleSheet(DISABL_NAVI_COLOR);
//pBback->setText(" ");
pBback->setEnabled(false);
}
}
void MainWindow::enableNaviButtons(uint8_t buttonNr, bool enabled)
{
if (buttonNr==1)
{
if (enabled)
{
pBback->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBback->setText("back");
pBback->setEnabled(true);
} else
{
pBback->setStyleSheet(DISABL_NAVI_COLOR);
//pBback->setText(" ");
pBback->setEnabled(false);
}
} else
if (buttonNr==2)
{
if (enabled)
{
pBhome->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBhome->setText("home");
pBhome->setEnabled(true);
} else
{
pBhome->setStyleSheet(DISABL_NAVI_COLOR);
//pBhome->setText(" ");
pBhome->setEnabled(false);
}
} else
if (buttonNr==3)
{
if (enabled)
{
pBforward->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBforward->setText("next");
pBforward->setEnabled(true);
} else
{
pBforward->setStyleSheet(DISABL_NAVI_COLOR);
//pBforward->setText(" ");
pBforward->setEnabled(false);
}
}
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// control work flow by Finite state machine
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
static uint16_t chainCurrentStep, chainNextStep;
static bool chain_stepIni;
void MainWindow::chainIni(void)
{
// called once after power-up by constructor
chainCurrentStep=WCS_STARTSCREEN; // start screen
chainNextStep=chainCurrentStep;
switchScreen(chainCurrentStep);
chain_stepIni=true;
//qDebug()<<"chain ini, call step "<<WCS_STARTUP << " " << chainCurrentStep;
}
void MainWindow::chainControl(void)
{
uint16_t nextScreen=0;
uint8_t useNavi=0;
bool busy=false;
// working step chain:
if (chainCurrentStep != chainNextStep)
{
if (chainNextStep!=WCS_STARTSCREEN)
{
timerVendingTimeout->stop();
timerVendingTimeout->start(VENDINGTIMEOUT_MS);
}
//qDebug()<<"found new sreen";
chainCurrentStep=chainNextStep;
switchScreen(chainCurrentStep);
chain_stepIni=true;
}
if (chainCurrentStep==1)
{
if (chain_stepIni)
busy=myFenster01->work_ini(&nextScreen, &useNavi);
else
busy=myFenster01->working(&nextScreen, &useNavi);
} else
{
// error undefined step
qDebug()<<"error main chain control, wrong step ("<<chainCurrentStep<<") selected";
}
if (chain_stepIni)
{
chain_stepIni=false;
switchScreen(chainCurrentStep); // the mainWindow frame has always the same number as the working step
}
if (nextScreen>0)
{
// call next chain step
//qDebug()<<"chain control: new step selected: "<< nextScreen;
chainNextStep=nextScreen;
}
if (useNavi>0)
{
//qDebug()<<"chain control: navi buttons "<< useNavi;
enableNaviButtons(useNavi);
}
if (busy>0)
{
// reset time-out
timerVendingTimeout->start();
}
}
void MainWindow::vendingTimeout(void)
{
// there was no user operation for 30s so return to start screen
// uint16_t nextScreen=WCS_STARTSCREEN;
// chainNextStep=nextScreen; erstmal stilllegen, stört bei IBN
//qDebug()<<"chain control: vending TO";
timerVendingTimeout->stop();
}

72
CArunGUI/mainwindow.h Executable file
View File

@ -0,0 +1,72 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <QGroupBox>
#include <QStyle>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QDebug>
#include <QPushButton>
#include <QDialog>
#include <QWidget>
#include <QApplication>
#include <QObject>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include <QPluginLoader>
#include <QDir>
#include "plugin.h"
#include "stepList.h"
//#include "stepList.h" // define all working chain steps here
#include "win01_com.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
QPushButton *pBback;
QPushButton *pBhome;
QPushButton *pBforward;
QGroupBox *bigGroupbox;
QHBoxLayout *bigLayout;
QTimer *timerChainCtrl;
QTimer *timerVendingTimeout;
QGroupBox *frame01;
T_winComPort *myFenster01;
void HideAllWindows();
void switchScreen(uint16_t winNr);
char loadPlugIn(char lade1_entlade2);
QDir plugInDir;
void chainIni(void);
public:
hwinf *HWaccess=nullptr; // global pointer to plugin-class
MainWindow(QWidget *parent = nullptr);
~MainWindow();
#define BACKBUTTON 1
#define HOMEBUTTON 2
#define FORWBUTTON 3
void enableNaviButtons(uint8_t buttonNr, bool enabled);
void enableNaviButtons(uint8_t switchBitwise);
private slots:
void chainControl();
void vendingTimeout();
};
#endif // MAINWINDOW_H

6
CArunGUI/plugin.h Executable file
View File

@ -0,0 +1,6 @@
#ifndef PLUGIN_H
#define PLUGIN_H
#include "interfaces.h"
#endif

210
CArunGUI/stepList.h Executable file
View File

@ -0,0 +1,210 @@
#ifndef STEPLIST_H
#define STEPLIST_H
// define all working chain steps
// every FSM-Step get's a frame in MainWindow with the same number and a self-designed GUI
// labels are used for switchScreen( label=nr );
// numbers are important: e.g. number 3 calls frame3 and frame3 includes subClass "T_fenster03"
// so best solution: label = same name like class (in example: Fenster03). Label is fixed bound to number, never change!
// numbers are fixed assosiated with the function (e.g. ComPort), can't be changed.
// but screen order can be called in step chain randomly
// Windownumbers for certain function, never change
#define PAGE_COMPORT 1
#define PAGE_SERVICEMAIN 2
#define PAGE_TIMEDATEVERSION 3
#define PAGE_MACHINESTATUS 4
#define PAGE_CHECKDOORS 5
#define PAGE_PRINTER 6
#define PAGE_COINMECHANIC 7
#define PAGE_MIFARE 8
#define PAGE_MODEM 9
#define PAGE_COINPAYMENT 10
#define PAGE_VAULTRECORD 11
#define PAGE_BOOTLOADER 12
#define PAGE_PROG_JSON 13
#define PAGE_COINCHANGER 14
#define PAGE_BILLREADER 15
#define PAGE_NEXT16 16
#define PAGE_NEXT17 17
#define PAGE_NEXT18 18
#define PAGE_NEXT19 19
#define PAGE_NEXT20 20
// fix: customize:
#define WCS_STARTSCREEN PAGE_COMPORT
// PAGE_COMPORT:
#define WCS_WIN01BAK PAGE_COMPORT
#define WCS_WIN01MID PAGE_SERVICEMAIN
#define WCS_WIN01FWD PAGE_SERVICEMAIN
// PAGE_SERVICEMAIN:
#define WCS_WIN02BAK PAGE_COMPORT
#define WCS_WIN02MID PAGE_SERVICEMAIN
#define WCS_WIN02FWD PAGE_TIMEDATEVERSION
// PAGE_TIMEDATEVERSION:
#define WCS_WIN03BAK PAGE_SERVICEMAIN
#define WCS_WIN03MID PAGE_SERVICEMAIN
#define WCS_WIN03FWD PAGE_MACHINESTATUS
// PAGE_MACHINESTATUS:
#define WCS_WIN04BAK PAGE_TIMEDATEVERSION
#define WCS_WIN04MID PAGE_SERVICEMAIN
#define WCS_WIN04FWD PAGE_CHECKDOORS
// PAGE_CHECKDOORS:
#define WCS_WIN05BAK PAGE_MACHINESTATUS
#define WCS_WIN05MID PAGE_SERVICEMAIN
#define WCS_WIN05FWD PAGE_COINMECHANIC
// PAGE_COINMECHANIC:
#define WCS_WIN07BAK PAGE_CHECKDOORS
#define WCS_WIN07MID PAGE_SERVICEMAIN
#define WCS_WIN07FWD PAGE_COINPAYMENT
// PAGE_COINPAYMENT:
#define WCS_WIN10BAK PAGE_COINMECHANIC
#define WCS_WIN10MID PAGE_SERVICEMAIN
#define WCS_WIN10FWD PAGE_COINCHANGER
// PAGE_COINCHANGER:
#define WCS_WIN14BAK PAGE_COINPAYMENT
#define WCS_WIN14MID PAGE_SERVICEMAIN
#define WCS_WIN14FWD PAGE_BILLREADER
// PAGE_BILLREADER:
#define WCS_WIN15BAK PAGE_COINCHANGER
#define WCS_WIN15MID PAGE_SERVICEMAIN
#define WCS_WIN15FWD PAGE_PRINTER
// PAGE_PRINTER:
#define WCS_WIN06BAK PAGE_BILLREADER
#define WCS_WIN06MID PAGE_SERVICEMAIN
#define WCS_WIN06FWD PAGE_MIFARE
// PAGE_MIFARE:
#define WCS_WIN08BAK PAGE_PRINTER
#define WCS_WIN08MID PAGE_SERVICEMAIN
#define WCS_WIN08FWD PAGE_MODEM
// PAGE_MODEM:
#define WCS_WIN09BAK PAGE_MIFARE
#define WCS_WIN09MID PAGE_SERVICEMAIN
#define WCS_WIN09FWD PAGE_VAULTRECORD
// PAGE_VAULTRECORD:
#define WCS_WIN11BAK PAGE_MODEM
#define WCS_WIN11MID PAGE_SERVICEMAIN
#define WCS_WIN11FWD PAGE_PROG_JSON
// PAGE_PROG_JSON:
#define WCS_WIN13BAK PAGE_VAULTRECORD
#define WCS_WIN13MID PAGE_SERVICEMAIN
#define WCS_WIN13FWD PAGE_BOOTLOADER
// PAGE_BOOTLOADER:
#define WCS_WIN12BAK PAGE_PROG_JSON
#define WCS_WIN12MID PAGE_SERVICEMAIN
#define WCS_WIN12FWD PAGE_NEXT16
// PAGE_NEXT16
#define WCS_WIN16BAK PAGE_BOOTLOADER
#define WCS_WIN16MID PAGE_SERVICEMAIN
#define WCS_WIN16FWD PAGE_NEXT17
// PAGE_NEXT17
#define WCS_WIN17BAK PAGE_NEXT16
#define WCS_WIN17MID PAGE_SERVICEMAIN
#define WCS_WIN17FWD PAGE_NEXT18
// PAGE_NEXT18
#define WCS_WIN18BAK PAGE_NEXT17
#define WCS_WIN18MID PAGE_SERVICEMAIN
#define WCS_WIN18FWD PAGE_NEXT19
// PAGE_NEXT19
#define WCS_WIN19BAK PAGE_NEXT18
#define WCS_WIN19MID PAGE_SERVICEMAIN
#define WCS_WIN19FWD PAGE_NEXT20
// PAGE_NEXT20
#define WCS_WIN20BAK PAGE_NEXT19
#define WCS_WIN20MID PAGE_SERVICEMAIN
#define WCS_WIN20FWD PAGE_SERVICEMAIN
// just for Template
#define WCS_WIN99BAK PAGE_SERVICEMAIN
#define WCS_WIN99MID PAGE_SERVICEMAIN
#define WCS_WIN99FWD PAGE_SERVICEMAIN
#define WIN02_LABEL_SHORT01 " Status"
#define WCS_WIN02SHORT01 PAGE_MACHINESTATUS
#define WIN02_LABEL_SHORT02 " Doors "
#define WCS_WIN02SHORT02 PAGE_CHECKDOORS
#define WIN02_LABEL_SHORT03 "Coin mech"
#define WCS_WIN02SHORT03 PAGE_COINMECHANIC
#define WIN02_LABEL_SHORT04 "Payment"
#define WCS_WIN02SHORT04 PAGE_COINPAYMENT
#define WIN02_LABEL_SHORT05 "Changer"
#define WCS_WIN02SHORT05 PAGE_COINCHANGER
#define WIN02_LABEL_SHORT06 " Bill "
#define WCS_WIN02SHORT06 PAGE_BILLREADER
#define WIN02_LABEL_SHORT07 "Printer"
#define WCS_WIN02SHORT07 PAGE_PRINTER
#define WIN02_LABEL_SHORT08 "Program"
#define WCS_WIN02SHORT08 PAGE_VAULTRECORD
#define WIN02_LABEL_SHORT09 " "
#define WCS_WIN02SHORT09 PAGE_SERVICEMAIN
#define WIN02_LABEL_SHORT10 " "
#define WCS_WIN02SHORT10 PAGE_SERVICEMAIN
// set needed navigation buttons, use | to combine more then one:
#define SWITCH_NEXT_ON 1
#define SWITCH_NEXT_OFF 2
#define SWITCH_HOME_ON 4
#define SWITCH_HOME_OFF 8
#define SWITCH_BACK_ON 16
#define SWITCH_BACK_OFF 32
// example: *useNavi=SWITCH_BACK_ON; // change only this one, or set all:
// *useNavi=SWITCH_BACK_OFF | SWITCH_HOME_OFF | SWITCH_NEXT_ON;
// some defines for Widget design:
#define TS_VALUEBOX_FRAMESTYLE 0x0032
#define TS_VALUEBOX_LINEWIDTH 3
//genDatPort->setFrameStyle(QFrame::Panel | QFrame::Sunken ); funktioniert aber gibt unverständliche Warnung
// QFrame::Panel = 0x0002 QFrame::Sunken=0x0030
//genDatPort->setFrameStyle(0x0032); // funktioniert und gibt keine Warnung
//genDatPort->setFrameStyle(TS_VALUEBOX_FRAMESTYLE); // funktioniert und gibt keine Warnung
#define TS_LED_FRAMESTYLE 0x0031
// QFrame::Box | QFrame::Sunken
#endif // STEPLIST_H

267
CArunGUI/subwindows.cpp Executable file
View File

@ -0,0 +1,267 @@
#include "subwindows.h"
/*
// %%%%%%%%%%%%%%%%%%%% TabChanger
T_fenster12::T_fenster12(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Coin Changer");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster12::updateGui(void)
{
}
// %%%%%%%%%%%%%%%%%%%% TabBill
T_fenster13::T_fenster13(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Bank note acceptor");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster13::updateGui(void)
{
}
T_fenster14::T_fenster14(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 14");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster14::updateGui(void)
{
}
T_fenster15::T_fenster15(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 15");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster15::updateGui(void)
{
}
T_fenster16::T_fenster16(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 16");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster16::updateGui(void)
{
}
T_fenster17::T_fenster17(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 17");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster17::updateGui(void)
{
}
T_fenster18::T_fenster18(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 18");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster18::updateGui(void)
{
}
T_fenster19::T_fenster19(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 19");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster19::updateGui(void)
{
}
T_fenster20::T_fenster20(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 20");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster20::updateGui(void)
{
}
T_fenster21::T_fenster21(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 21");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster21::updateGui(void)
{
}
T_fenster22::T_fenster22(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 22");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster22::updateGui(void)
{
}
T_fenster23::T_fenster23(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 23");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster23::updateGui(void)
{
}
T_fenster24::T_fenster24(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 24");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster24::updateGui(void)
{
}
T_fenster25::T_fenster25(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 25");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster25::updateGui(void)
{
}
T_fenster26::T_fenster26(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 26");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster26::updateGui(void)
{
}
T_fenster27::T_fenster27(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 27");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster27::updateGui(void)
{
}
T_fenster28::T_fenster28(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 28");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster28::updateGui(void)
{
}
T_fenster29::T_fenster29(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 29");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster29::updateGui(void)
{
}
T_fenster30::T_fenster30(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 30");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster30::updateGui(void)
{
}
*/

161
CArunGUI/subwindows.h Executable file
View File

@ -0,0 +1,161 @@
#ifndef SUBWINDOWS_H
#define SUBWINDOWS_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QObject>
#include <QTimer>
#include <QDebug>
#include <QScrollBar>
#include <QPlainTextEdit>
#include <QComboBox>
#include <QLabel>
#include <QScrollArea>
#include <QWidget>
#include <QListWidget>
#include <QGroupBox>
#include <QPushButton>
#include <QRadioButton>
#include "tslib.h"
#include "stepList.h" // define all working chain steps here
#include "../plugins/interfaces.h"
class T_fenster12 : public QWidget // TabChanger
{
public:
explicit T_fenster12(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster13 : public QWidget // TabBill
{
public:
explicit T_fenster13(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster14 : public QWidget
{
public:
explicit T_fenster14(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster15 : public QWidget
{
public:
explicit T_fenster15(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster16 : public QWidget
{
public:
explicit T_fenster16(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster17 : public QWidget
{
public:
explicit T_fenster17(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster18 : public QWidget
{
public:
explicit T_fenster18(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster19 : public QWidget
{
public:
explicit T_fenster19(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster20 : public QWidget
{
public:
explicit T_fenster20(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster21 : public QWidget
{
public:
explicit T_fenster21(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster22 : public QWidget
{
public:
explicit T_fenster22(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster23 : public QWidget
{
public:
explicit T_fenster23(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster24 : public QWidget
{
public:
explicit T_fenster24(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster25 : public QWidget
{
public:
explicit T_fenster25(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster26 : public QWidget
{
public:
explicit T_fenster26(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster27 : public QWidget
{
public:
explicit T_fenster27(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster28 : public QWidget
{
public:
explicit T_fenster28(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster29 : public QWidget
{
public:
explicit T_fenster29(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster30 : public QWidget
{
public:
explicit T_fenster30(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
#endif

1016
CArunGUI/tslib.cpp Executable file

File diff suppressed because it is too large Load Diff

168
CArunGUI/tslib.h Executable file
View File

@ -0,0 +1,168 @@
#ifndef TSLIB_H
#define TSLIB_H
#include <stdint.h>
#include <QByteArray>
typedef uint8_t UCHAR;
typedef uint16_t UINT;
typedef uint32_t ULONG;
#define LOWBYTE false
#define HIGHBYTE true
uint16_t uchar2uint(char Highbyte, char Lowbyte);
uint16_t uchar2uint(uint8_t Highbyte, uint8_t Lowbyte);
uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t Lowbyte);
uint8_t uint2uchar(uint16_t uival, bool getHighB);
void delay(uint16_t MilliSec);
#define MITSEK 1
#define OHNESEK 0
#define HourSys12h 1
#define HourSys24h 0
void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf);
// generate time as ascii string from integers hours/minutes/seconds
// System12h=0: 24h system =1: 12h System
// ShowSec=0: String has 5 digits (hh:mm) =1: String has 8 digits (hh:mm:ss)
// return String in *buf // 12 byte für buf!
#define DateFormatDeutsch 0
#define DateFormatAmerica 1
#define UsePointSeperator 0
#define UseSlashSeperator 1
void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// yearhigh in europe always 20 (not in arabia)
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11 byte für buf!
void GetShortDateString(uint8_t day, uint8_t month, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// format= 0: dd.mm.yy (deutsch)
// 1: mm.dd.yy (amerika)
// 2: yy.mm.dd (Iran, Dubai)
// 3: dd.yy.mm
// 4: mm.yy.dd
// 5: yy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11byte für buf!
uint16_t tslib_strlen(char *buf);
void tslib_strclr(char *buf, char clrsign, uint16_t len);
void tslib_strclr(uint8_t *buf, char clrsign, uint16_t len);
void tslib_strcpy(char *srcbuf, char *destbuf, uint16_t len);
void tslib_strcpy(char *srcbuf, uint8_t *destbuf, uint16_t len);
void tslib_strcpy(uint8_t *srcbuf, uint8_t *destbuf, uint16_t len);
uint16_t tslib_calcCrcCcitt(uint16_t BufLength, uint8_t *buf);
bool tslib_isDecAsciiNumber(char sign);
bool tslib_isHexAsciiNumber(char sign);
int tslib_getMinimum(int val1, int val2);
void tslib_text2array(QByteArray text, char *aray, uint16_t maxArayLen);
// usage: tslib_text2array("my text", ctmp, 50);
bool tslib_strComp(uint8_t *buf, char *compStr);
bool tslib_plausiChkTime(uint8_t hour, uint8_t min, uint8_t sec );
// retval: true: time is OK
bool tslib_plausiChkDate(uint8_t year, uint8_t month, uint8_t dom );
// retval: true: time is OK
UCHAR swl_LengthCurrentMonth(UCHAR month, UCHAR year);
// return nr of days for this month, respecting leap years
UINT swl_GetDaysOfaCompleteYear(UCHAR year);
// year: 0=2000 4=2004 99=2099
// retval: 365 or 366 (leap year)
UINT swl_GetDaysOfYear(UCHAR year, UCHAR month, UCHAR day);
// number of days of momentary year from 1. Jan until
// (inclusive) given date with respect to leap years
// year: 0..99 month=1..12 day=1..31
unsigned long swl_getNrOfDaysSince2000Jan1(UCHAR thisYear, UCHAR thisMonth, UCHAR thisDay);
// till today
unsigned long swl_getNrOfHoursSince_Midnight2000Jan1(UCHAR thisYear, UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow);
unsigned long swl_getNrOfMinutesSince_Midnight2000Jan1(UCHAR thisYear, \
UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow, UCHAR minuteNow);
unsigned long swl_getNrOfSecondsSince_Midnight2000Jan1(UCHAR thisYear, \
UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow, UCHAR minuteNow, UCHAR secondNow);
char swl_isLeap(UCHAR year);
UCHAR swl_getNextLeapYear(UCHAR year);
UCHAR swl_getLastLeapYear(UCHAR year);
UCHAR swl_hoursOfThisWeek(UCHAR dow, UCHAR hoursNow);
// always calculate from monday 0 o'clock
// dow: 1=monday 7=sunday
UINT swl_minutesOfThisWeek(UCHAR dow, UCHAR hoursNow, UCHAR minutesNow);
// always calculate from monday 0 o'clock
// dow: 1=monday 7=sunday
UINT swl_hoursOfThisMonth(UCHAR thisDay, UCHAR hoursNow);
UINT swl_minutesOfThisMonth(UCHAR thisDay, UCHAR hoursNow, UCHAR minutesNow);
UINT swl_GetHoursOfYear(UCHAR year, UCHAR month, UCHAR day, UCHAR hourNow);
ULONG swl_GetMinutesOfYear(UCHAR year, UCHAR month, UCHAR day, UCHAR hourNow, UCHAR minutesNow);
UCHAR swl_weekday(UCHAR year, UCHAR month, UCHAR dayOfMonth);
// return 1...7 = monday...sunday, starting from 1.1.2000
QString swl_int2str(int val);
QString swl_hex2str(double val);
void swl_text2ui8buf(QString text, uint8_t *outbuf, uint16_t length);
// copy text byte-by-byte to outbuf
QString swl_ulong2str(uint32_t val);
QString swl_long2str(long val);
uint16_t swl_str2uint(QString myIntStr);
uint32_t swl_str2ulong(QString myIntStr);
QString swl_labelAndValToStr(QString label, uint32_t val);
QString swl_8valInaRowToStr(QString label, uint8_t val[8]);
QString swl_8valInaRowToStr(QString label, uint16_t val[8]);
QString swl_8intsInaRowToStr(QString label, int val[8]);
QString swl_centToEuroString(uint32_t amount_in_cent);
#endif // TSLIB_H
// qDebug << QDateTime::currentDateTime().toString(Qt::ISODateWithMs) << QByteArray((const char*)dataSendBuf,dataBufLen).toHex(':');

13
CArunGUI/versionHistory.txt Executable file
View File

@ -0,0 +1,13 @@
#ifndef VERSIONHISTORY_H
#define VERSIONHISTORY_H
APservice3.0 bis September2023 fuer DBM, Szeged
APservice3.2 12.10.23
screen Abfolge komplett mit defines aufgebaut, kann jetzt in "stepList.h" veraendert werden
Neuen Screen Muenzwechsler und Banknote
passend zu CashAgent-Plugin: "Atb.Psa1256ptu5.software.HWapi/5.0"
Farben und Schriftgroessen vereinheitlichen (guidefs.h)
#endif

578
CArunGUI/win01_com.cpp Executable file
View File

@ -0,0 +1,578 @@
#include "win01_com.h"
#include "stepList.h" // define all working chain steps here
#include "datei.h"
//#include "globVars.h"
// %%%%%%%%%%%%%%%%%%%% TabComPort
Console::Console(QWidget *parent) : QPlainTextEdit(parent)
{
document()->setMaximumBlockCount(100);
QPalette p = palette();
p.setColor(QPalette::Base, Qt::black); //geht nicht weil untergrund schon farbig
p.setColor(QPalette::Text, Qt::blue);
setPalette(p);
}
void Console::putData(const QByteArray &data)
{
insertPlainText(data);
insertPlainText("\n");
QScrollBar *bar = verticalScrollBar();
bar->setValue(bar->maximum());
}
void Console::putText(QString text)
{
insertPlainText(text);
insertPlainText("\n");
QScrollBar *bar = verticalScrollBar();
bar->setValue(bar->maximum());
}
void T_winComPort::subPortInfo()
{
// Port Info Anzeige Feld, 2. Zeile links
QStringList myStringList;
QStringList comboPortList;
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos)
{
myStringList.append(QObject::tr(" \n Port: ") + info.portName() );
myStringList.append(QObject::tr("Location: ") + info.systemLocation()); // + "\n");
myStringList.append(QObject::tr("Description: ") + info.description() );
myStringList.append(QObject::tr("Manufacturer: ") + info.manufacturer());
myStringList.append(QObject::tr("Serial number: ") + info.serialNumber());
myStringList.append (QObject::tr("Vendor Id: ") + QString::number(info.vendorIdentifier(), 16));
myStringList.append(QObject::tr("Product Id: ") +QString::number(info.productIdentifier(), 16));
//myStringList.append(QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")));
comboPortList.append(info.portName()); // wenn Comport im System vorhanden dann in die Liste eintragen
}
QListWidget *myListWidget = new QListWidget;
myListWidget->insertItems(0, myStringList);
myListWidget->setMaximumWidth(250);
myTabComLayout->addWidget(myListWidget,1,0);
// ComboBox Comport Nr:
CB_portSel = new QComboBox();
CB_portSel->addItems(comboPortList); // string Liste mit addItems (s am Schluss) !
CB_portSel->setMinimumHeight(30);
CB_portSel->setMaximumWidth(150);
QFont myCBfont;
//myCBfont.setBold(true);
myCBfont.setPixelSize(15);
CB_portSel->setFont(myCBfont);
CB_portSel->setCurrentIndex(2); // default 3. Comport in der Liste = ttymxc2 in PTU5
myTabComLayout->addWidget(CB_portSel, 4,0);
}
void T_winComPort::callOpenSerial()
{
// Taste Connect wurde gedrückt, eine Klasse/einen Slot aus einer übergeordneten Klasse:
// openSerialPort();
// kann man nicht aufrufen. deshalb: speichere ComPort, Baudrate und Startbefehl global.
// Von dort wird mit einem zyklischen Timer ausgelesen
int br, ci;
QString bs, cn;
//br=CB_baudSel->currentIndex();
//bs=CB_baudSel->currentText();
br=5;
bs="115200";
cn=CB_portSel->currentText();
ci=CB_portSel->currentIndex();
// aktuell: br=5 bs=115200 cn=0 (=Com5)
//epi_setSerial(5,"115200","COM5",1);
// epi_setSerial(br, bs, cn, 1);
// new: save values for next time
QByteArray myBA, tmpBA;
myBA.clear(); tmpBA.clear();
myBA.append('s'); // start sign, not used
myBA.append(FILESEPERATOR);
tmpBA.setNum(br,10);
myBA.append(tmpBA);
myBA.append(FILESEPERATOR);
myBA.append(bs.toLatin1());
myBA.append(FILESEPERATOR);
myBA.append(cn.toLatin1());
myBA.append(FILESEPERATOR);
tmpBA.clear();
tmpBA.setNum(ci,10);
myBA.append(tmpBA);
myBA.append(FILESEPERATOR);
datei_clearFile(FILENAME_COMPORT);
datei_writeToFile(FILENAME_COMPORT, myBA);
qDebug() << "winComPort opening serial with: " << br << " " << bs << " " << cn;
HWaccess->dc_openSerial(br, bs, cn, 1);// same function with hwapi
// void dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect)
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
// BaudStr: for exapmle "19200"
// ComName: for example "COM48"
// connect: 0, 1
emit connectButtonPressed();
}
void T_winComPort::callCloseSerial()
{
HWaccess->dc_closeSerial();
// epi_closeSerial(); // same function without hwapi
emit closeButtonPressed();
}
void T_winComPort::callAutoSend()
{
if (AutSendButton->isChecked())
{
HWaccess->dc_autoRequest(1);
emit autoSendButtonIsOn();
} else
{
HWaccess->dc_autoRequest(0);
emit autoSendButtonIsOff();
}
}
void T_winComPort::callRefresh(void)
{
subPortInfo();
}
void T_winComPort::callConnectToggle()
{
if (connectButton->isChecked())
{
//qDebug() << "down";
callOpenSerial();
} else
{
//qDebug() << "released";
callCloseSerial();
}
}
void T_winComPort::getDcTestRS232()
{
//qDebug() << "request test response...";
HWaccess->dc_requTestResponse();
}
void T_winComPort::newBaud(void)
{
qDebug() << "new baud selected...";
}
void T_winComPort::setButtons4autoStart()
{
connectButton->setEnabled(true);
connectButton->setDown(true);
connectButton->setChecked(true);
AutSendButton->setEnabled(true);
AutSendButton->setDown(true);
AutSendButton->setChecked(true);
}
T_winComPort::T_winComPort(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
this->HWaccess = HWaccess;
myTabComLayout = new QGridLayout;
//QGridLayout *myGridLayout = new QGridLayout();
// Überschrift linke Spalte
QLabel *portListLabel2 = new QLabel(tr("in System available Ports:"));
myTabComLayout->addWidget(portListLabel2, 0,0);
// Überschrift rechte Spalte
QLabel *lab_headlineR = new QLabel(tr("Serial traffic:"));
myTabComLayout->addWidget(lab_headlineR, 0, 1);
subPortInfo();
// sende-empfangs-Rohdaten-Fenster, 2. Zeile rechts
myDiagWindow = new Console();
myDiagWindow->setReadOnly(true);
myDiagWindow->setEnabled(true);
//myDiagWindow->setLocalEchoEnabled(p.localEchoEnabled);
//myDiagWindow->setMinimumWidth(300);
//myDiagWindow->putData("ongoing serial traffic: ");
myTabComLayout->addWidget(myDiagWindow, 1,1);
// links:
// refresh button:
refreshButton = new QPushButton(tr("&refresh"));
refreshButton->setCheckable(false); // true = toggle button
refreshButton->setAutoDefault(false); // beim start aus
//refreshButton->setMaximumWidth(90);
myTabComLayout->addWidget(refreshButton, 2,0);
//connect(refreshButton, &QAbstractButton::clicked, this, &T_fenster01::callRefresh);
connect(refreshButton, SIGNAL(clicked()), this, SLOT(callRefresh()));
QLabel *Label3 = new QLabel(tr("Port:"));
myTabComLayout->addWidget(Label3, 3,0);
QLabel *Label4 = new QLabel(tr("Baud:"));
myTabComLayout->addWidget(Label4, 5,0);
// ComboBox Baudrate:
QFont my2CBfont;
//my2CBfont.setBold(true);
my2CBfont.setPixelSize(15);
/*
CB_baudSel = new QComboBox();
CB_baudSel->addItem(tr("1200"));
CB_baudSel->addItem(tr("9600"));
CB_baudSel->addItem(tr("19200"));
CB_baudSel->addItem(tr("38400"));
CB_baudSel->addItem(tr("57600"));
CB_baudSel->addItem(tr("115200"));
CB_baudSel->setMinimumHeight(30);
CB_baudSel->setMaximumWidth(150);
CB_baudSel->setFont(my2CBfont);
CB_baudSel->setCurrentIndex(5); // default 115k baud
//CB_baudSel->setCurrentIndex(1); // default 9600 baud
myTabComLayout->addWidget(CB_baudSel, 6,0);
//connect(CB_baudSel, SIGNAL(currentIndexChanged(int)), this, SLOT(newBaud()));
connect(CB_baudSel, SIGNAL(currentIndexChanged(int)), this, SLOT(newBaud()));
*/
// Statuszeile COM Port (serial Port)
LabelComState = new QLabel(tr("not connected"));
myTabComLayout->addWidget(LabelComState, 7,0);
// Connect button:
connectButton = new QPushButton(tr("&Connect"));
connectButton->setCheckable(true); // true = toggle button
connectButton->setAutoDefault(true); // beim start ein
connectButton->setMaximumWidth(90);
connectButton->setMinimumHeight(50);
myTabComLayout->addWidget(connectButton, 8,0);
//connect(connectButton, &QAbstractButton::clicked, this, &T_fenster01::callConnectToggle);
connect(connectButton, SIGNAL(clicked()), this, SLOT(callConnectToggle()));
// rechts:
// test serial line:
TestButton = new QPushButton(tr("test Connection"));
TestButton->setMaximumWidth(150);
myTabComLayout->addWidget(TestButton,2,1);
TestButton->setCheckable(false); // true = toggle button
TestButton->setAutoDefault(false); // beim start aus
// connect(TestButton, &QAbstractButton::clicked, this, &T_fenster01::getDcTestRS232);
connect(TestButton, SIGNAL(clicked()), this, SLOT(getDcTestRS232()));
// I Statuszeile Handshakes (serial Control) flow.cpp
// geht überhaupt was raus? kommt überhaupt was zurück?
//LabelHandshakes = new QLabel(tr("control line"));
LabelHandshakes = new QLabel("HS"); // not used
myTabComLayout->addWidget(LabelHandshakes, 3,1);
// II Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
LabelRecieveFrame = new QLabel(tr("slave receive"));
myTabComLayout->addWidget(LabelRecieveFrame, 4,1);
// III Anzeige der Slave-Results (Datif)
LabelResults = new QLabel(tr("results line"));
myTabComLayout->addWidget(LabelResults, 5,1);
// IV Statuszeile Sende- und Empfangsdaten brauchbar? (Datif)
LabelDataState = new QLabel(tr("datif line"));
myTabComLayout->addWidget(LabelDataState, 6,1);
// V
LabelDatif = new QLabel(tr("datif line"));
myTabComLayout->addWidget(LabelDatif, 7,1);
// Autosend:
AutSendButton = new QPushButton(tr("&Automatic reading")); // &A --> also keycode Alt-A possible
//AutSendButton->setMaximumWidth(90);
myTabComLayout->addWidget(AutSendButton,8,1);
AutSendButton->setCheckable(true); // true = toggle button
AutSendButton->setAutoDefault(true); // beim start aus
AutSendButton->setMinimumHeight(50);
// connect(AutSendButton, &QAbstractButton::clicked, this, &T_fenster01::callAutoSend);
connect(AutSendButton, SIGNAL(clicked()), this, SLOT(callAutoSend()));
setLayout(myTabComLayout);
myNextStep=0;
myStep=0;
callConnectToggle();
callAutoSend();
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(2000);
}
// not needed:
T_winComPort::~T_winComPort()
{
close();
}
void T_winComPort::Nav_back(void)
{
myNextStep=WCS_WIN01BAK;
}
void T_winComPort::Nav_home(void)
{
myNextStep=WCS_WIN01MID;
}
void T_winComPort::Nav_next(void)
{
myNextStep=WCS_WIN01FWD;
}
bool T_winComPort::work_ini(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called ONE time after selecting this state (initialization)
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
*nextScreen=0; // needed 0=no change
// *useNavi=SWITCH_BACK_OFF | SWITCH_HOME_OFF | SWITCH_NEXT_ON;
*useNavi=SWITCH_BACK_OFF | SWITCH_HOME_OFF | SWITCH_NEXT_OFF; // bei CArun alle aus
return false;
}
bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called cyclic until this state changes intentionally to another state
// display informations for human operator, react on operators inputs or wait for payment media
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
this->updateGui();
*nextScreen=0; // 0=no change
*useNavi=0;
if (myStep==0)
{
// load and use last settings: --------------------
QByteArray myBA;
myBA=datei_readFromFile(FILENAME_COMPORT);
//uint32_t len= datei_nrOfEntriesInFile(myBA);
//uint64_t ulltmp=csv_getEntryAs2Ulong(myBA,0);
//qDebug()<<"win_startup load long numer: "<<ulltmp;
QString bs=csv_getEntryAsString(myBA,0); // read the 's' war 2!??
int br=csv_getEntryAsInt(myBA,1); // z.B. 5 (5.Eintrag in der Baud-Liste)
bs=csv_getEntryAsString(myBA,2); // z.B 115200
QString cn=csv_getEntryAsString(myBA,3); // z.B. COM9
int ci=csv_getEntryAsInt(myBA,4); // Eintragsnummer in COM-Fenster
//qDebug()<<"win_startup loaded com settings: "<<br<<" "<<bs<<" "<<cn;
HWaccess->dc_openSerial(br,bs,cn,1);
//CB_baudSel->setCurrentIndex(br); // im BR auswahlfenster diese Baud vorgeben
CB_portSel->setCurrentIndex(ci); // den Port aus der Datei hier vorgeben
connectButton->setChecked(true); // connect Taste "druecken"
myTO->start(100); // restart
myStep++;
} else
if (myStep==1)
{
if (!myTO->isActive())
{
if (HWaccess->dc_isPortOpen())
myStep++;
else
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
} else
if (myStep==2)
{
if (!myTO->isActive())
{
HWaccess->dc_requTestResponse();
myStep++;
myTO->start(100);
}
} else
if (myStep==3)
{
if (!myTO->isActive())
{
if (HWaccess->dc_readAnswTestResponse())
myStep++; // response was correct
else
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
} else
if (myStep==4)
{
HWaccess->dc_autoRequest(1);
AutSendButton->setChecked(true); // taste "druecken"
myStep++;
} else
if (myStep==5)
{
// got next screen:
//myNextStep=2; // nicht bei CArun
myStep++;
} else
if (myStep==6)
{
// stop here, everything done
} else
if (myStep==7)
{
} else
{
}
if (myNextStep)
{
//qDebug()<<"fenster1 working: "<< myNextStep;
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}
void T_winComPort::updateGui(void)
{
QByteArray myBA;
QString ms;
ms=HWaccess->dc_getTxt4RsDiagWin();
if (ms.length()>1) // sonst ständig scrolling
{
myDiagWindow->putText(ms);
HWaccess->dc_clrTxt4RsDiagWin();
}
ms=HWaccess->dc_get2ndTxt4RsDiagWin();
if (ms.length()>1) // sonst ständig scrolling
{
myDiagWindow->putText(ms);
HWaccess->dc_clr2ndTxt4RsDiagWin();
}
// state of the COM Port (open, closed)
ms=HWaccess->dc_getSerialState();
if (ms.length()>1) // sonst ständig scrolling
{
LabelComState->setText(ms);
}
// --------------------------------------------------------------------------
// I Statuszeile Handshakes (serial Control)
ms=HWaccess->dc_getTxt4HsStateLine();
if (!connectButton->isChecked())
ms="";
if (ms.length()>1) // sonst ständig scrolling
{
LabelHandshakes->setText(ms);
HWaccess->dc_clrTxt4HsStateLine();
// clear to avoid multiple displaying
}
// II Master receive state (empfangenes Telgramm OK? crc? length? )
// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
ms=HWaccess->dc_getTxt4masterStateLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelRecieveFrame->setText(ms);
HWaccess->dc_clrTxt4masterStateLine();
}
// 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
ms=HWaccess->dc_getTxt4resultStateLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelResults->setText(ms);
HWaccess->dc_clrTxt4resultStateLine();
}
// IV Statuszeile Empfangsdaten
ms=HWaccess->dc_getdataStateLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelDataState->setText(ms);
HWaccess->dc_clrTxt4dataStateLine();
// clear to avoid multiple displaying
}
// 5. Zeile: Datif Ergebnis, Daten brauchbar?
ms=HWaccess->dc_getdatifLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelDatif->setText(ms);
HWaccess->dc_clrTxt4datifLine();
}
// -----------------------------------------------------------------------------
}

107
CArunGUI/win01_com.h Executable file
View File

@ -0,0 +1,107 @@
#ifndef WINCOMPORT_H
#define WINCOMPORT_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QObject>
#include <QTimer>
#include <QDebug>
#include <QTabWidget>
#include <QScrollBar>
#include <QPlainTextEdit>
#include <QComboBox>
#include <QLabel>
#include <QScrollArea>
#include <QSerialPortInfo>
#include <QWidget>
#include <QListWidget>
#include <QGroupBox>
#include <QPushButton>
#include <QRadioButton>
//#include "tslib.h"
//#include "stepList.h" // define all working chain steps here
//#include "datei.h"
#include "plugin.h"
//#include "globVars.h"
class Console : public QPlainTextEdit
{
Q_OBJECT
public:
explicit Console(QWidget *parent = nullptr);
void putData(const QByteArray &data);
void putText(QString text);
};
class T_winComPort : public QWidget // former TabComport
{
Q_OBJECT
Console *myDiagWindow; // Ausgabefenster
QComboBox *CB_portSel;
//QComboBox *CB_baudSel;
QPushButton *connectButton;
QPushButton *AutSendButton;
QPushButton *TestButton;
QPushButton *refreshButton;
QLabel *LabelComState; // Statusanzeige
QLabel *LabelPort;
QLabel *LabelHandshakes;
QLabel *LabelRecieveFrame;
QLabel *LabelResults;
QLabel *LabelDataState;
QLabel *LabelDatif;
QGridLayout *myTabComLayout;
void subPortInfo();
hwinf *HWaccess;
void updateGui(void);
uint16_t myNextStep;
uint8_t myStep;
QTimer *myTO;
private slots:
void callOpenSerial();
void callCloseSerial();
void callAutoSend();
//void tabComTime100ms();
void callConnectToggle();
void getDcTestRS232();
void callRefresh(void);
public:
explicit T_winComPort(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
bool work_ini(uint16_t *nextScreen, uint8_t *useNavi);
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
bool working (uint16_t *nextScreen, uint8_t *useNavi);
~T_winComPort();
void writeRSdiagBytes(const QByteArray &bytarray);
void writeRSdiagText(QString text);
void writeComState(const QString text);
void writeDataState(const QString text);
void setButtons4autoStart();
signals:
void connectButtonPressed();
void closeButtonPressed();
void autoSendButtonIsOn();
void autoSendButtonIsOff();
private slots:
void newBaud(void); // just for test
public slots:
void Nav_back(void);
void Nav_home(void);
void Nav_next(void);
};
#endif

118
DCLibraries.pri Normal file
View File

@ -0,0 +1,118 @@
CONFIG += plugin
QT -= gui
QT += widgets serialport
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
INCLUDEPATH += $${PWD}/include
DEPENDPATH += $${PWD}
DESTDIR=$${_PRO_FILE_PWD_}/build
CONFIG += c++11
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
# keep comments, as /* fall through */
QMAKE_CXXFLAGS += -C
# _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
QMAKE_CXXFLAGS += -O
QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy
# default
ARCH = PTU5
CONFIG += PTU5
contains( CONFIG, DesktopLinux ) {
# QMAKE_CC = ccache $$QMAKE_CC
# QMAKE_CXX = ccache $$QMAKE_CXX
QMAKE_CXXFLAGS += -std=c++17
# QMAKE_CXXFLAGS += -Wno-deprecated-ctor
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
ARCH = DesktopLinux
}
contains( CONFIG, PTU5 ) {
# QMAKE_CC = ccache $$QMAKE_CC
# QMAKE_CXX = ccache $$QMAKE_CXX
QMAKE_CXXFLAGS += -std=c++17
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
CONFIG += link_pkgconfig
ARCH = PTU5
}
contains( CONFIG, PTU5_YOCTO ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
PTU5BASEPATH = /opt/devel/ptu5
ARCH = PTU5
# add qmqtt lib
#LIBS += -lQt5Qmqtt
}
HEADERS += \
$${PWD}/include/com.h \
$${PWD}/include/datei.h \
$${PWD}/include/runProc.h \
$${PWD}/include/controlBus.h \
$${PWD}/include/datIf.h \
$${PWD}/include/dcBL.h \
$${PWD}/include/hwapi.h \
$${PWD}/include/interfaces.h \
$${PWD}/include/prot.h \
$${PWD}/include/sendWRcmd.h \
$${PWD}/include/storeINdata.h \
$${PWD}/include/tslib.h \
$${PWD}/include/shared_mem_buffer.h
SOURCES += \
$${PWD}/src/com.cpp \
$$PWD/src/datei.cpp \
$$PWD/src/runProc.cpp \
$$PWD/src/main.cpp \
$${PWD}/src/controlBus.cpp \
$${PWD}/src/datIf.cpp \
$${PWD}/src/dcBL.cpp \
$${PWD}/src/hwapi.cpp \
$${PWD}/src/prot.cpp \
$${PWD}/src/sendWRcmd.cpp \
$${PWD}/src/storeINdata.cpp \
$${PWD}/src/tslib.cpp \
$${PWD}/src/shared_mem_buffer.cpp
# INTERFACE = DeviceController
# INTERFACE_DEFINITION = $${PWD}/include/ATBAPP/DeviceControllerInterface.h
#
# DISTFILES += \
# generate-version.sh
# Define how to create version.h
# VERSION_H = $$PWD/include/version.h
# version.output = $$PWD/include/version.h
# version.commands = $$PWD/generate-version.sh $${ARCH} $${TARGET} $${INTERFACE} $${INTERFACE_DEFINITION} $${VERSION_H}
# version.depends = FORCE
# version.input = VERSION_H
# version.variable_out = HEADERS
# QMAKE_EXTRA_COMPILERS += version
# QMAKE_CLEAN += $${PWD}/include/version.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

6
DCLibraries.pro Normal file
View File

@ -0,0 +1,6 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = lib_ca_master lib_ca_slave CArunGUI dCArun
CArunGUI.depends = lib_ca_master lib_ca_slave
dCArun.depends = lib_ca_master lib_ca_slave

58
dCArun/dCArun.pro Normal file
View File

@ -0,0 +1,58 @@
QT += core gui
QT +=widgets serialport
QT +=network
# for TCP-IP
TARGET = dCArun
DESTDIR=$${_PRO_FILE_PWD_}/../build
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += PTU5
# _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
QMAKE_CXXFLAGS += -O
INCLUDEPATH += ../include
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
SOURCES += \
main.cpp \
mainwindow.cpp \
tslib.cpp \
win01_com.cpp \
datei.cpp
HEADERS += \
guidefs.h \
mainwindow.h \
stepList.h \
tslib.h \
versionHistory.txt \
win01_com.h \
datei.h \
plugin.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

944
dCArun/datei.cpp Executable file
View File

@ -0,0 +1,944 @@
// 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;
}
}

209
dCArun/datei.h Executable file
View File

@ -0,0 +1,209 @@
#ifndef DATEI_H
#define DATEI_H
#include <stdint.h>
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include "tslib.h"
#include <QString>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
// create csv file with:
#define FILESEPERATOR ','
// pasre csv with:
#define FILESEP1 ','
#define FILESEP2 ';'
#define NEWLINEINFILE '\n'
#define MAXNUMBEROFSEQUENCES 200
// only for csv files
// all seting-files located in sudirectory "static machine data - smd"
// all generated files located in sudirectory "dynamic machine data - dmd"
#define FILENAME_COMPORT "../comport.csv"
#define FILENAME_CONFIG "/own/work2023/PSA1256ptu5/smd/DC2C_conf.json"
#define FILENAME_DEVICE "/own/work2023/PSA1256ptu5/smd/DC2C_device.json"
#define FILENAME_CASH "/own/work2023/PSA1256ptu5/smd/DC2C_cash.json"
#define FILENAME_PRINT "/own/work2023/PSA1256ptu5/smd/DC2C_print32.json"
#define FILENAME_APSERVCONF "../APserviceConfig.csv"
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ create csv file -------------------------------
// -------------------------------------------------------------------------------------------------
// create array with strings and values (to be written to file)
void csv_startCreatingFile(void);
void csv_addTextToFile(QString myText);
void csv_addIntToFile(int myValue);
void csv_addUintToFile(uint myValue);
void csv_addLongvalToFile(qlonglong myValue);
void csv_addUlongvalToFile(qulonglong myValue);
//void csv_addCurrentTimeToFile(void);
//void csv_addCurrentDateToFile(void);
void csv_addNewlineToFile(void);
QByteArray csv_readbackArray(void);
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ parse csv file -------------------------------
// -------------------------------------------------------------------------------------------------
// return number of entries in the just read file (entries are seperated by
// comma or line-feed)
uint32_t csv_nrOfEntriesInFile(QByteArray readFromFile);
// before: QByteArray sourceFile=datei_readFromFile(filename);
QByteArray csv_getOneFileSequence(QByteArray sourceFile, uint32_t sequNr);
// not needed, just for test // sequNr: 0....(size-1)
// get single entries of of the just read fie:
int csv_getEntryAsInt(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
int32_t csv_getEntryAsLong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint8_t csv_getEntryAsUshort(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint16_t csv_getEntryAsUint(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint32_t csv_getEntryAsUlong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint64_t csv_getEntryAs2Ulong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
QString csv_getEntryAsString(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ create Json Record -------------------------------
// -------------------------------------------------------------------------------------------------
void json_startRecord(void);
// clear buffer and write opening curly bracket {
void json_enterIntToRecord(QString attribute, ulong i_value);
// example: "parameter":1234567890
void json_enterTextToRecord(QString attribute, QString txt_value);
// example: "parameter":"slow"
//void json_addCurrentTimeToRecord(QString attribute);
// example: if attribute=myTime: "myTime":"hh_mm_ss"
//void json_addCurrentDateToRecord(QString attribute);
// example: if attribute=myDate: "myDate":"dd.mm.yyyy"
// also / possible as seperator
// further possible forms:
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
void json_enterArrayToRecord(QString attribute, uint8_t *buf, ulong nrofVals);
// add array of numbers with "nrofVals" elements
void json_enterStructToRecord(QString attribute);
// every call must be concluded with an extra "json_finishFile()"
// example: "sname":{
void json_finishStruct(void);
void json_finishRecord(void);
// close curly bracket
QString json_readbackRecordStr(void);
QByteArray json_readbackRecordBa(void);
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ parse Json file -------------------------------
// -------------------------------------------------------------------------------------------------
// first: QByteArray datei_readFromFile(QString filename);
//void datei_json_readTestFile(QString filename);
int json_nrOfPairsInFile(QByteArray filename);
bool json_exists(QByteArray filename, QString searchForKey);
// look for "searchForKey" =name of the pair (left of : )
// retval true if exists
bool json_remove(QByteArray filename, QString searchFor);
// look for "searchFor" =name of the pair (left of : ) and remove the record from file
// retval true if removed
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
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
//.......................
QJsonObject json_searchForObjectInFile(QByteArray filename, QString searchFor);
// return an object from the json file
int json_nrOfPairsInObject(QJsonObject objname);
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
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
//.......................
QJsonArray json_searchForArrayInFile(QByteArray filename, QString searchFor);
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
int json_nrOfValuesInArray(QJsonArray arrayname);
bool json_getValuesOfArray(QJsonArray arrayname, int *buf, int MaxBufferSize);
// assuming that the array consists of integers
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ read, write, copy files -------------------
// -------------------------------------------------------------------------------------------------
void datei_closeFile(QString filename);
// read content of an exiting file:
QByteArray datei_readFromFile(QString filename);
bool datei_ifFileExists(QString filename);
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
bool datei_copyFile(QString currentFileName, QString newFileName);
// retval=true if successful
bool datei_clearFile(QString filename);
// retval=true if successful
#endif // DATEI_H

24
dCArun/guidefs.h Executable file
View File

@ -0,0 +1,24 @@
#ifndef GUIDEFS_H
#define GUIDEFS_H
#define PIXELSIZE_BUTTONS 18
#define PIXELSIZE_LABEL 18
#define PIXELSIZE_DATA 16
#define PIXELSIZE_BIGFONT 22
#define PIXELSIZE_SMALLFONT 14
#define BUTTONCOLOR "background-color: rgb(150,250,150)"
#define COLORGREEN "background-color: rgb(160,250,190)"
#define COLOR_RED "background-color: rgb(150,0,0)"
#define COLOR_LIGHTRED "background-color: rgb(250,150,150)"
//#define COLORGREY "background-color: rgb(160,250,190)"
#define COLORGREY "background-color: grey"
#define COLORYELLOW "background-color: yellow"
#define COLORWHITE "background-color: white"
// "background-color: lightgrey"
#endif

43
dCArun/main.cpp Executable file
View File

@ -0,0 +1,43 @@
#include "mainwindow.h"
//#include "message_handler.h"
#include <QApplication>
int thisisglobal;
int main(int argc, char *argv[])
{
int ret;
QApplication myapp(argc, argv);
QApplication::setApplicationName("CArunGui");
QApplication::setApplicationVersion(APP_VERSION);
/*
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtDebugMsg);
//setDebugLevel(QtMsgType::QtDebugMsg);
}
*/
MainWindow myMainWin;
QSize myMainSize={800, 480}; // breite, höhe, PTU: 800x440
myMainWin.setMinimumSize(myMainSize);
myMainWin.setMaximumSize(myMainSize);
myMainWin.setWindowTitle("CArun_V4.2 run cash agent master lib");
//myMainWin.show();
ret=myapp.exec();
return ret;
}
//QApplication a(argc, argv);
//MainWindow CatMW;
//QSize myMainSize={800, 480}; // breite, höhe
//CatMW.setMinimumSize(myMainSize);
//CatMW.setMaximumSize(myMainSize);
//CatMW.setWindowTitle("ATB CashAgent V2.0");
// QPalette mainPal;
// mainPal.setColor(QPalette::Window, Qt::red );
// CatMW.setPalette(mainPal); sieht man nicht mehr

438
dCArun/mainwindow.cpp Executable file
View File

@ -0,0 +1,438 @@
#include "mainwindow.h"
char MainWindow::loadPlugIn(char lade1_entlade2)
{
plugInDir.cd("plugins");
QPluginLoader *pluginLoader = new QPluginLoader();
// select system:
//pluginLoader->setFileName("../MasterPlug/libCAmaster.so"); // for suse
//pluginLoader->setFileName("../SlavePlug/libCAslave.so"); // for ptu5
//pluginLoader->setFileName("../../MasterPlug/CAmaster.dll"); // for windows
pluginLoader->setFileName("CAmaster.dll"); // for windows
if (lade1_entlade2==2)
{
pluginLoader->unload();
return 0;
}
if (!pluginLoader->load())
{
qDebug()<<"cannot load plugin";
} else
qDebug() <<"loaded plugin: " << pluginLoader->fileName();
if (!pluginLoader->isLoaded())
{
qDebug()<<pluginLoader->errorString();
return 0;
}
QObject *plugin = pluginLoader->instance();
if ( plugin == nullptr)
{
// make instance of the root component (which can hold more then one clases)
// also loads the lib if not yet done
qDebug()<<"cannot start instance";
return 0;
}
//int rr=hwapi->giveVal(2); funktioniert :))
//qDebug()<<"got value from plugin"<<rr; funktioniert :))
// aber besser globaler pointer:
// im h-file
// hwinf *hwapi=nullptr; // pointer to plugin-class
HWaccess= qobject_cast<hwinf *>(plugin);
// make instance to class "hwinf" in dll_HWapi.h over "interfaces.h"
qDebug()<<"loadPlugIn, HWAccess: " << HWaccess;
return 0;
}
#define WINCTRMIN 0
// 0 is always the home screen
#define WINCTRMAX 30
// number of needed application screens, up to 255
// All screens must be defined below in mainwindow-class first before increasing the nr
// numbers must be consecutively from 0 always, 0 is the home screen always
#define FORMWIDTH 725
//#define FORMWIDTH 690
// this width is the same for ALL windows
#define FORMHEIGHT 440
// this height is the same for ALL windows
#define NAVIBUTTONHEIGHT 70
#define NAVIBUTTONWIDHT 50
#define HOMEPAGE_BACKGROUND_COLOR "background-color: lightgrey"
#define BUTTON_COLOR "background-color: rgb(160,250,190)"
#define ACTIVE_NAVI_COLOR "background-color: rgb(160,250,190)"
#define DISABL_NAVI_COLOR "background-color: grey"
#define APPPAGE_BACKGROUND_COLOR "background-color: lightgrey"
#define UPDATE_PERIOD_MS 100
// period to call chain steps
#define VENDINGTIMEOUT_MS 30000
// after this time without any operation the program returns to idle state
// time in ms, that means 30.000 gives 30seconds
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
loadPlugIn(1);
// define all working moduls (besides gui) here, call ini and working in chainControl() (~Line 1000)
//mifCard = new T_Mifare(HWaccess); // ganz wichtig: HWaccess an sub-Konstruktor übergeben
// sonst crash bei HW-Zugriff!!!!
//diary = new T_lib_diary(); absturz!!!!!!
//conf = new T_lib_config(HWaccess);
timerChainCtrl = new QTimer(this);
connect(timerChainCtrl, SIGNAL(timeout()), this, SLOT(chainControl()));
timerChainCtrl->setSingleShot(0);
timerChainCtrl->start(UPDATE_PERIOD_MS); // 1000: call every 1000ms
timerVendingTimeout = new QTimer(this);
connect(timerVendingTimeout, SIGNAL(timeout()), this, SLOT(vendingTimeout()));
timerVendingTimeout->setSingleShot(true);
timerVendingTimeout->start(VENDINGTIMEOUT_MS); // in ms
// ##########################################################################################
// für jedes anzuzeigende Fenster eine eigene Groupbox mit eigenem Grid anlegen:
frame01 = new QGroupBox;
frame01->setStyleSheet(APPPAGE_BACKGROUND_COLOR);
frame01->setMinimumSize(FORMWIDTH,FORMHEIGHT);
QVBoxLayout *smallLay01 = new QVBoxLayout;
frame01->setLayout(smallLay01);
// Fensterinhalt aus externer Klasse einfügen:
myFenster01 = new T_winComPort(HWaccess); // HWaccess damit auf das HW-Plugin zugegriffen werden kann, sonst crash
smallLay01->addWidget(myFenster01);
// ##########################################################################################
// draw Mainwindow:
bigGroupbox = new QGroupBox;
bigGroupbox->setStyleSheet("background-color: grey");
bigGroupbox->setMinimumSize(800,480);
// bigLayout = new QVBoxLayout; // navi buttons on bottom side
bigLayout = new QHBoxLayout; // navi buttons right hand
// ##########################################################################################
// add all windows (but display only one)
// display only one: then all windows are shown at the same place
// display more then one: the windows are listed in vertical order
bigLayout->addWidget(frame01);
bigGroupbox->setLayout(bigLayout);
switchScreen(1);
//HideAllWindows();
// ##########################################################################################
// Steuer Leiste
//QHBoxLayout *ButtonLayout = new QHBoxLayout();
QVBoxLayout *ButtonLayout = new QVBoxLayout();
QFont myTabFont;
myTabFont.setPixelSize(26);
pBback = new QPushButton("<"); //b\na\nc\nk");
pBback->setFont(myTabFont);
pBback->setStyleSheet(ACTIVE_NAVI_COLOR);
pBback->setMinimumHeight(NAVIBUTTONHEIGHT);
pBback->setMaximumWidth(NAVIBUTTONWIDHT);
connect(pBback, SIGNAL( clicked() ), myFenster01, SLOT( Nav_back()));
myTabFont.setPixelSize(22);
pBhome = new QPushButton("<<"); //h\no\nm\ne");
pBhome->setFont(myTabFont);
pBhome->setStyleSheet(ACTIVE_NAVI_COLOR);
pBhome->setMinimumHeight(NAVIBUTTONHEIGHT);
pBhome->setMaximumWidth(NAVIBUTTONWIDHT);
connect(pBhome, SIGNAL( clicked() ), myFenster01, SLOT( Nav_home()));
myTabFont.setPixelSize(26);
pBforward = new QPushButton(">"); //n\ne\nx\nt");
pBforward->setFont(myTabFont);
pBforward->setStyleSheet(ACTIVE_NAVI_COLOR);
pBforward->setMinimumHeight(NAVIBUTTONHEIGHT);
pBforward->setMaximumWidth(NAVIBUTTONWIDHT);
connect(pBforward, SIGNAL( clicked() ), myFenster01, SLOT( Nav_next()));
QLabel *buttonSpace = new QLabel(" ");
ButtonLayout->addWidget(pBback);
ButtonLayout->addWidget(buttonSpace);
//ButtonLayout->addWidget(buttonSpace);
ButtonLayout->addWidget(pBhome);
ButtonLayout->addWidget(buttonSpace);
//ButtonLayout->addWidget(buttonSpace);
ButtonLayout->addWidget(pBforward);
QLabel *bottomSpace = new QLabel(" ");
ButtonLayout->addWidget(bottomSpace);
bigLayout->addLayout(ButtonLayout);
setCentralWidget(bigGroupbox);
// AUTOSTART serial transmission
//HWaccess->dc_openSerial(5,"115200","ttyS0",1); // my suse computer
//HWaccess->dc_openSerial(1,"9600","COM5",1); // my suse computer
//HWaccess->dc_openSerial(5,"115200","ttymxc2",1); // ptu5
//HWaccess->dc_autoRequest(true);
//myFenster01->setButtons4autoStart();
//HWaccess->alarm_switchSiren(0); // test
enableNaviButtons(BACKBUTTON,true);
enableNaviButtons(HOMEBUTTON,true);
enableNaviButtons(FORWBUTTON,true);
this->chainIni();
//connect(myFenster02, SIGNAL(quitMyApp()), this, SLOT(close()));
}
MainWindow::~MainWindow()
{
loadPlugIn(2);
}
void MainWindow::HideAllWindows()
{
// vorsicht: Fenster muss oben definiert sein sonst Programmabsturz ohne Kommentar
frame01->setEnabled(false);
frame01->setVisible(false);
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Call Windows
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void MainWindow::switchScreen(uint16_t winNr) // 0...30
{
HideAllWindows();
//qDebug()<<"switch screen to " << winNr;
switch (winNr)
{
case 1:
frame01->setEnabled(true);
frame01->setVisible(true);
break;
default:
break;
}
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Navigation buttons
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void MainWindow::enableNaviButtons(uint8_t switchBitwise)
{
// switchBitwise=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
if (switchBitwise &1)
{
pBforward->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBforward->setText("next");
pBforward->setEnabled(true);
} else
if (switchBitwise &2)
{
pBforward->setStyleSheet(DISABL_NAVI_COLOR);
//pBforward->setText(" ");
pBforward->setEnabled(false);
}
if (switchBitwise &4)
{
pBhome->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBhome->setText("home");
pBhome->setEnabled(true);
} else
if (switchBitwise &8)
{
pBhome->setStyleSheet(DISABL_NAVI_COLOR);
//pBhome->setText(" ");
pBhome->setEnabled(false);
}
if (switchBitwise &16)
{
pBback->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBback->setText("back");
pBback->setEnabled(true);
} else
if (switchBitwise &32)
{
pBback->setStyleSheet(DISABL_NAVI_COLOR);
//pBback->setText(" ");
pBback->setEnabled(false);
}
}
void MainWindow::enableNaviButtons(uint8_t buttonNr, bool enabled)
{
if (buttonNr==1)
{
if (enabled)
{
pBback->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBback->setText("back");
pBback->setEnabled(true);
} else
{
pBback->setStyleSheet(DISABL_NAVI_COLOR);
//pBback->setText(" ");
pBback->setEnabled(false);
}
} else
if (buttonNr==2)
{
if (enabled)
{
pBhome->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBhome->setText("home");
pBhome->setEnabled(true);
} else
{
pBhome->setStyleSheet(DISABL_NAVI_COLOR);
//pBhome->setText(" ");
pBhome->setEnabled(false);
}
} else
if (buttonNr==3)
{
if (enabled)
{
pBforward->setStyleSheet(ACTIVE_NAVI_COLOR);
//pBforward->setText("next");
pBforward->setEnabled(true);
} else
{
pBforward->setStyleSheet(DISABL_NAVI_COLOR);
//pBforward->setText(" ");
pBforward->setEnabled(false);
}
}
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// control work flow by Finite state machine
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
static uint16_t chainCurrentStep, chainNextStep;
static bool chain_stepIni;
void MainWindow::chainIni(void)
{
// called once after power-up by constructor
chainCurrentStep=WCS_STARTSCREEN; // start screen
chainNextStep=chainCurrentStep;
switchScreen(chainCurrentStep);
chain_stepIni=true;
//qDebug()<<"chain ini, call step "<<WCS_STARTUP << " " << chainCurrentStep;
}
void MainWindow::chainControl(void)
{
uint16_t nextScreen=0;
uint8_t useNavi=0;
bool busy=false;
// working step chain:
if (chainCurrentStep != chainNextStep)
{
if (chainNextStep!=WCS_STARTSCREEN)
{
timerVendingTimeout->stop();
timerVendingTimeout->start(VENDINGTIMEOUT_MS);
}
//qDebug()<<"found new sreen";
chainCurrentStep=chainNextStep;
switchScreen(chainCurrentStep);
chain_stepIni=true;
}
if (chainCurrentStep==1)
{
if (chain_stepIni)
busy=myFenster01->work_ini(&nextScreen, &useNavi);
else
busy=myFenster01->working(&nextScreen, &useNavi);
} else
{
// error undefined step
qDebug()<<"error main chain control, wrong step ("<<chainCurrentStep<<") selected";
}
if (chain_stepIni)
{
chain_stepIni=false;
switchScreen(chainCurrentStep); // the mainWindow frame has always the same number as the working step
}
if (nextScreen>0)
{
// call next chain step
//qDebug()<<"chain control: new step selected: "<< nextScreen;
chainNextStep=nextScreen;
}
if (useNavi>0)
{
//qDebug()<<"chain control: navi buttons "<< useNavi;
enableNaviButtons(useNavi);
}
if (busy>0)
{
// reset time-out
timerVendingTimeout->start();
}
}
void MainWindow::vendingTimeout(void)
{
// there was no user operation for 30s so return to start screen
// uint16_t nextScreen=WCS_STARTSCREEN;
// chainNextStep=nextScreen; erstmal stilllegen, stört bei IBN
//qDebug()<<"chain control: vending TO";
timerVendingTimeout->stop();
}

72
dCArun/mainwindow.h Executable file
View File

@ -0,0 +1,72 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <QGroupBox>
#include <QStyle>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QDebug>
#include <QPushButton>
#include <QDialog>
#include <QWidget>
#include <QApplication>
#include <QObject>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include <QPluginLoader>
#include <QDir>
#include "plugin.h"
#include "stepList.h"
//#include "stepList.h" // define all working chain steps here
#include "win01_com.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
QPushButton *pBback;
QPushButton *pBhome;
QPushButton *pBforward;
QGroupBox *bigGroupbox;
QHBoxLayout *bigLayout;
QTimer *timerChainCtrl;
QTimer *timerVendingTimeout;
QGroupBox *frame01;
T_winComPort *myFenster01;
void HideAllWindows();
void switchScreen(uint16_t winNr);
char loadPlugIn(char lade1_entlade2);
QDir plugInDir;
void chainIni(void);
public:
hwinf *HWaccess=nullptr; // global pointer to plugin-class
MainWindow(QWidget *parent = nullptr);
~MainWindow();
#define BACKBUTTON 1
#define HOMEBUTTON 2
#define FORWBUTTON 3
void enableNaviButtons(uint8_t buttonNr, bool enabled);
void enableNaviButtons(uint8_t switchBitwise);
private slots:
void chainControl();
void vendingTimeout();
};
#endif // MAINWINDOW_H

5
dCArun/plugin.h Executable file
View File

@ -0,0 +1,5 @@
#ifndef PLUGIN_H
#define PLUGIN_H
#include "interfaces.h"
#endif

210
dCArun/stepList.h Executable file
View File

@ -0,0 +1,210 @@
#ifndef STEPLIST_H
#define STEPLIST_H
// define all working chain steps
// every FSM-Step get's a frame in MainWindow with the same number and a self-designed GUI
// labels are used for switchScreen( label=nr );
// numbers are important: e.g. number 3 calls frame3 and frame3 includes subClass "T_fenster03"
// so best solution: label = same name like class (in example: Fenster03). Label is fixed bound to number, never change!
// numbers are fixed assosiated with the function (e.g. ComPort), can't be changed.
// but screen order can be called in step chain randomly
// Windownumbers for certain function, never change
#define PAGE_COMPORT 1
#define PAGE_SERVICEMAIN 2
#define PAGE_TIMEDATEVERSION 3
#define PAGE_MACHINESTATUS 4
#define PAGE_CHECKDOORS 5
#define PAGE_PRINTER 6
#define PAGE_COINMECHANIC 7
#define PAGE_MIFARE 8
#define PAGE_MODEM 9
#define PAGE_COINPAYMENT 10
#define PAGE_VAULTRECORD 11
#define PAGE_BOOTLOADER 12
#define PAGE_PROG_JSON 13
#define PAGE_COINCHANGER 14
#define PAGE_BILLREADER 15
#define PAGE_NEXT16 16
#define PAGE_NEXT17 17
#define PAGE_NEXT18 18
#define PAGE_NEXT19 19
#define PAGE_NEXT20 20
// fix: customize:
#define WCS_STARTSCREEN PAGE_COMPORT
// PAGE_COMPORT:
#define WCS_WIN01BAK PAGE_COMPORT
#define WCS_WIN01MID PAGE_SERVICEMAIN
#define WCS_WIN01FWD PAGE_SERVICEMAIN
// PAGE_SERVICEMAIN:
#define WCS_WIN02BAK PAGE_COMPORT
#define WCS_WIN02MID PAGE_SERVICEMAIN
#define WCS_WIN02FWD PAGE_TIMEDATEVERSION
// PAGE_TIMEDATEVERSION:
#define WCS_WIN03BAK PAGE_SERVICEMAIN
#define WCS_WIN03MID PAGE_SERVICEMAIN
#define WCS_WIN03FWD PAGE_MACHINESTATUS
// PAGE_MACHINESTATUS:
#define WCS_WIN04BAK PAGE_TIMEDATEVERSION
#define WCS_WIN04MID PAGE_SERVICEMAIN
#define WCS_WIN04FWD PAGE_CHECKDOORS
// PAGE_CHECKDOORS:
#define WCS_WIN05BAK PAGE_MACHINESTATUS
#define WCS_WIN05MID PAGE_SERVICEMAIN
#define WCS_WIN05FWD PAGE_COINMECHANIC
// PAGE_COINMECHANIC:
#define WCS_WIN07BAK PAGE_CHECKDOORS
#define WCS_WIN07MID PAGE_SERVICEMAIN
#define WCS_WIN07FWD PAGE_COINPAYMENT
// PAGE_COINPAYMENT:
#define WCS_WIN10BAK PAGE_COINMECHANIC
#define WCS_WIN10MID PAGE_SERVICEMAIN
#define WCS_WIN10FWD PAGE_COINCHANGER
// PAGE_COINCHANGER:
#define WCS_WIN14BAK PAGE_COINPAYMENT
#define WCS_WIN14MID PAGE_SERVICEMAIN
#define WCS_WIN14FWD PAGE_BILLREADER
// PAGE_BILLREADER:
#define WCS_WIN15BAK PAGE_COINCHANGER
#define WCS_WIN15MID PAGE_SERVICEMAIN
#define WCS_WIN15FWD PAGE_PRINTER
// PAGE_PRINTER:
#define WCS_WIN06BAK PAGE_BILLREADER
#define WCS_WIN06MID PAGE_SERVICEMAIN
#define WCS_WIN06FWD PAGE_MIFARE
// PAGE_MIFARE:
#define WCS_WIN08BAK PAGE_PRINTER
#define WCS_WIN08MID PAGE_SERVICEMAIN
#define WCS_WIN08FWD PAGE_MODEM
// PAGE_MODEM:
#define WCS_WIN09BAK PAGE_MIFARE
#define WCS_WIN09MID PAGE_SERVICEMAIN
#define WCS_WIN09FWD PAGE_VAULTRECORD
// PAGE_VAULTRECORD:
#define WCS_WIN11BAK PAGE_MODEM
#define WCS_WIN11MID PAGE_SERVICEMAIN
#define WCS_WIN11FWD PAGE_PROG_JSON
// PAGE_PROG_JSON:
#define WCS_WIN13BAK PAGE_VAULTRECORD
#define WCS_WIN13MID PAGE_SERVICEMAIN
#define WCS_WIN13FWD PAGE_BOOTLOADER
// PAGE_BOOTLOADER:
#define WCS_WIN12BAK PAGE_PROG_JSON
#define WCS_WIN12MID PAGE_SERVICEMAIN
#define WCS_WIN12FWD PAGE_NEXT16
// PAGE_NEXT16
#define WCS_WIN16BAK PAGE_BOOTLOADER
#define WCS_WIN16MID PAGE_SERVICEMAIN
#define WCS_WIN16FWD PAGE_NEXT17
// PAGE_NEXT17
#define WCS_WIN17BAK PAGE_NEXT16
#define WCS_WIN17MID PAGE_SERVICEMAIN
#define WCS_WIN17FWD PAGE_NEXT18
// PAGE_NEXT18
#define WCS_WIN18BAK PAGE_NEXT17
#define WCS_WIN18MID PAGE_SERVICEMAIN
#define WCS_WIN18FWD PAGE_NEXT19
// PAGE_NEXT19
#define WCS_WIN19BAK PAGE_NEXT18
#define WCS_WIN19MID PAGE_SERVICEMAIN
#define WCS_WIN19FWD PAGE_NEXT20
// PAGE_NEXT20
#define WCS_WIN20BAK PAGE_NEXT19
#define WCS_WIN20MID PAGE_SERVICEMAIN
#define WCS_WIN20FWD PAGE_SERVICEMAIN
// just for Template
#define WCS_WIN99BAK PAGE_SERVICEMAIN
#define WCS_WIN99MID PAGE_SERVICEMAIN
#define WCS_WIN99FWD PAGE_SERVICEMAIN
#define WIN02_LABEL_SHORT01 " Status"
#define WCS_WIN02SHORT01 PAGE_MACHINESTATUS
#define WIN02_LABEL_SHORT02 " Doors "
#define WCS_WIN02SHORT02 PAGE_CHECKDOORS
#define WIN02_LABEL_SHORT03 "Coin mech"
#define WCS_WIN02SHORT03 PAGE_COINMECHANIC
#define WIN02_LABEL_SHORT04 "Payment"
#define WCS_WIN02SHORT04 PAGE_COINPAYMENT
#define WIN02_LABEL_SHORT05 "Changer"
#define WCS_WIN02SHORT05 PAGE_COINCHANGER
#define WIN02_LABEL_SHORT06 " Bill "
#define WCS_WIN02SHORT06 PAGE_BILLREADER
#define WIN02_LABEL_SHORT07 "Printer"
#define WCS_WIN02SHORT07 PAGE_PRINTER
#define WIN02_LABEL_SHORT08 "Program"
#define WCS_WIN02SHORT08 PAGE_VAULTRECORD
#define WIN02_LABEL_SHORT09 " "
#define WCS_WIN02SHORT09 PAGE_SERVICEMAIN
#define WIN02_LABEL_SHORT10 " "
#define WCS_WIN02SHORT10 PAGE_SERVICEMAIN
// set needed navigation buttons, use | to combine more then one:
#define SWITCH_NEXT_ON 1
#define SWITCH_NEXT_OFF 2
#define SWITCH_HOME_ON 4
#define SWITCH_HOME_OFF 8
#define SWITCH_BACK_ON 16
#define SWITCH_BACK_OFF 32
// example: *useNavi=SWITCH_BACK_ON; // change only this one, or set all:
// *useNavi=SWITCH_BACK_OFF | SWITCH_HOME_OFF | SWITCH_NEXT_ON;
// some defines for Widget design:
#define TS_VALUEBOX_FRAMESTYLE 0x0032
#define TS_VALUEBOX_LINEWIDTH 3
//genDatPort->setFrameStyle(QFrame::Panel | QFrame::Sunken ); funktioniert aber gibt unverständliche Warnung
// QFrame::Panel = 0x0002 QFrame::Sunken=0x0030
//genDatPort->setFrameStyle(0x0032); // funktioniert und gibt keine Warnung
//genDatPort->setFrameStyle(TS_VALUEBOX_FRAMESTYLE); // funktioniert und gibt keine Warnung
#define TS_LED_FRAMESTYLE 0x0031
// QFrame::Box | QFrame::Sunken
#endif // STEPLIST_H

267
dCArun/subwindows.cpp Executable file
View File

@ -0,0 +1,267 @@
#include "subwindows.h"
/*
// %%%%%%%%%%%%%%%%%%%% TabChanger
T_fenster12::T_fenster12(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Coin Changer");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster12::updateGui(void)
{
}
// %%%%%%%%%%%%%%%%%%%% TabBill
T_fenster13::T_fenster13(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Bank note acceptor");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster13::updateGui(void)
{
}
T_fenster14::T_fenster14(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 14");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster14::updateGui(void)
{
}
T_fenster15::T_fenster15(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 15");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster15::updateGui(void)
{
}
T_fenster16::T_fenster16(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 16");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster16::updateGui(void)
{
}
T_fenster17::T_fenster17(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 17");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster17::updateGui(void)
{
}
T_fenster18::T_fenster18(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 18");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster18::updateGui(void)
{
}
T_fenster19::T_fenster19(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 19");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster19::updateGui(void)
{
}
T_fenster20::T_fenster20(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 20");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster20::updateGui(void)
{
}
T_fenster21::T_fenster21(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 21");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster21::updateGui(void)
{
}
T_fenster22::T_fenster22(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 22");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster22::updateGui(void)
{
}
T_fenster23::T_fenster23(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 23");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster23::updateGui(void)
{
}
T_fenster24::T_fenster24(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 24");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster24::updateGui(void)
{
}
T_fenster25::T_fenster25(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 25");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster25::updateGui(void)
{
}
T_fenster26::T_fenster26(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 26");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster26::updateGui(void)
{
}
T_fenster27::T_fenster27(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 27");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster27::updateGui(void)
{
}
T_fenster28::T_fenster28(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 28");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster28::updateGui(void)
{
}
T_fenster29::T_fenster29(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 29");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster29::updateGui(void)
{
}
T_fenster30::T_fenster30(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
QGridLayout *myLayout = new QGridLayout();
QLabel *Lab1 = new QLabel("Dialog 30");
myLayout->addWidget(Lab1,1,1);
setLayout(myLayout);
}
void T_fenster30::updateGui(void)
{
}
*/

161
dCArun/subwindows.h Executable file
View File

@ -0,0 +1,161 @@
#ifndef SUBWINDOWS_H
#define SUBWINDOWS_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QObject>
#include <QTimer>
#include <QDebug>
#include <QScrollBar>
#include <QPlainTextEdit>
#include <QComboBox>
#include <QLabel>
#include <QScrollArea>
#include <QWidget>
#include <QListWidget>
#include <QGroupBox>
#include <QPushButton>
#include <QRadioButton>
#include "tslib.h"
#include "stepList.h" // define all working chain steps here
#include "../plugins/interfaces.h"
class T_fenster12 : public QWidget // TabChanger
{
public:
explicit T_fenster12(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster13 : public QWidget // TabBill
{
public:
explicit T_fenster13(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster14 : public QWidget
{
public:
explicit T_fenster14(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster15 : public QWidget
{
public:
explicit T_fenster15(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster16 : public QWidget
{
public:
explicit T_fenster16(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster17 : public QWidget
{
public:
explicit T_fenster17(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster18 : public QWidget
{
public:
explicit T_fenster18(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster19 : public QWidget
{
public:
explicit T_fenster19(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster20 : public QWidget
{
public:
explicit T_fenster20(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster21 : public QWidget
{
public:
explicit T_fenster21(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster22 : public QWidget
{
public:
explicit T_fenster22(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster23 : public QWidget
{
public:
explicit T_fenster23(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster24 : public QWidget
{
public:
explicit T_fenster24(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster25 : public QWidget
{
public:
explicit T_fenster25(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster26 : public QWidget
{
public:
explicit T_fenster26(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster27 : public QWidget
{
public:
explicit T_fenster27(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster28 : public QWidget
{
public:
explicit T_fenster28(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster29 : public QWidget
{
public:
explicit T_fenster29(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
class T_fenster30 : public QWidget
{
public:
explicit T_fenster30(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
void updateGui(void);
};
#endif

1016
dCArun/tslib.cpp Executable file

File diff suppressed because it is too large Load Diff

168
dCArun/tslib.h Executable file
View File

@ -0,0 +1,168 @@
#ifndef TSLIB_H
#define TSLIB_H
#include <stdint.h>
#include <QByteArray>
typedef uint8_t UCHAR;
typedef uint16_t UINT;
typedef uint32_t ULONG;
#define LOWBYTE false
#define HIGHBYTE true
uint16_t uchar2uint(char Highbyte, char Lowbyte);
uint16_t uchar2uint(uint8_t Highbyte, uint8_t Lowbyte);
uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t Lowbyte);
uint8_t uint2uchar(uint16_t uival, bool getHighB);
void delay(uint16_t MilliSec);
#define MITSEK 1
#define OHNESEK 0
#define HourSys12h 1
#define HourSys24h 0
void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf);
// generate time as ascii string from integers hours/minutes/seconds
// System12h=0: 24h system =1: 12h System
// ShowSec=0: String has 5 digits (hh:mm) =1: String has 8 digits (hh:mm:ss)
// return String in *buf // 12 byte für buf!
#define DateFormatDeutsch 0
#define DateFormatAmerica 1
#define UsePointSeperator 0
#define UseSlashSeperator 1
void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// yearhigh in europe always 20 (not in arabia)
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11 byte für buf!
void GetShortDateString(uint8_t day, uint8_t month, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// format= 0: dd.mm.yy (deutsch)
// 1: mm.dd.yy (amerika)
// 2: yy.mm.dd (Iran, Dubai)
// 3: dd.yy.mm
// 4: mm.yy.dd
// 5: yy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11byte für buf!
uint16_t tslib_strlen(char *buf);
void tslib_strclr(char *buf, char clrsign, uint16_t len);
void tslib_strclr(uint8_t *buf, char clrsign, uint16_t len);
void tslib_strcpy(char *srcbuf, char *destbuf, uint16_t len);
void tslib_strcpy(char *srcbuf, uint8_t *destbuf, uint16_t len);
void tslib_strcpy(uint8_t *srcbuf, uint8_t *destbuf, uint16_t len);
uint16_t tslib_calcCrcCcitt(uint16_t BufLength, uint8_t *buf);
bool tslib_isDecAsciiNumber(char sign);
bool tslib_isHexAsciiNumber(char sign);
int tslib_getMinimum(int val1, int val2);
void tslib_text2array(QByteArray text, char *aray, uint16_t maxArayLen);
// usage: tslib_text2array("my text", ctmp, 50);
bool tslib_strComp(uint8_t *buf, char *compStr);
bool tslib_plausiChkTime(uint8_t hour, uint8_t min, uint8_t sec );
// retval: true: time is OK
bool tslib_plausiChkDate(uint8_t year, uint8_t month, uint8_t dom );
// retval: true: time is OK
UCHAR swl_LengthCurrentMonth(UCHAR month, UCHAR year);
// return nr of days for this month, respecting leap years
UINT swl_GetDaysOfaCompleteYear(UCHAR year);
// year: 0=2000 4=2004 99=2099
// retval: 365 or 366 (leap year)
UINT swl_GetDaysOfYear(UCHAR year, UCHAR month, UCHAR day);
// number of days of momentary year from 1. Jan until
// (inclusive) given date with respect to leap years
// year: 0..99 month=1..12 day=1..31
unsigned long swl_getNrOfDaysSince2000Jan1(UCHAR thisYear, UCHAR thisMonth, UCHAR thisDay);
// till today
unsigned long swl_getNrOfHoursSince_Midnight2000Jan1(UCHAR thisYear, UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow);
unsigned long swl_getNrOfMinutesSince_Midnight2000Jan1(UCHAR thisYear, \
UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow, UCHAR minuteNow);
unsigned long swl_getNrOfSecondsSince_Midnight2000Jan1(UCHAR thisYear, \
UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow, UCHAR minuteNow, UCHAR secondNow);
char swl_isLeap(UCHAR year);
UCHAR swl_getNextLeapYear(UCHAR year);
UCHAR swl_getLastLeapYear(UCHAR year);
UCHAR swl_hoursOfThisWeek(UCHAR dow, UCHAR hoursNow);
// always calculate from monday 0 o'clock
// dow: 1=monday 7=sunday
UINT swl_minutesOfThisWeek(UCHAR dow, UCHAR hoursNow, UCHAR minutesNow);
// always calculate from monday 0 o'clock
// dow: 1=monday 7=sunday
UINT swl_hoursOfThisMonth(UCHAR thisDay, UCHAR hoursNow);
UINT swl_minutesOfThisMonth(UCHAR thisDay, UCHAR hoursNow, UCHAR minutesNow);
UINT swl_GetHoursOfYear(UCHAR year, UCHAR month, UCHAR day, UCHAR hourNow);
ULONG swl_GetMinutesOfYear(UCHAR year, UCHAR month, UCHAR day, UCHAR hourNow, UCHAR minutesNow);
UCHAR swl_weekday(UCHAR year, UCHAR month, UCHAR dayOfMonth);
// return 1...7 = monday...sunday, starting from 1.1.2000
QString swl_int2str(int val);
QString swl_hex2str(double val);
void swl_text2ui8buf(QString text, uint8_t *outbuf, uint16_t length);
// copy text byte-by-byte to outbuf
QString swl_ulong2str(uint32_t val);
QString swl_long2str(long val);
uint16_t swl_str2uint(QString myIntStr);
uint32_t swl_str2ulong(QString myIntStr);
QString swl_labelAndValToStr(QString label, uint32_t val);
QString swl_8valInaRowToStr(QString label, uint8_t val[8]);
QString swl_8valInaRowToStr(QString label, uint16_t val[8]);
QString swl_8intsInaRowToStr(QString label, int val[8]);
QString swl_centToEuroString(uint32_t amount_in_cent);
#endif // TSLIB_H
// qDebug << QDateTime::currentDateTime().toString(Qt::ISODateWithMs) << QByteArray((const char*)dataSendBuf,dataBufLen).toHex(':');

13
dCArun/versionHistory.txt Executable file
View File

@ -0,0 +1,13 @@
#ifndef VERSIONHISTORY_H
#define VERSIONHISTORY_H
APservice3.0 bis September2023 fuer DBM, Szeged
APservice3.2 12.10.23
screen Abfolge komplett mit defines aufgebaut, kann jetzt in "stepList.h" veraendert werden
Neuen Screen Muenzwechsler und Banknote
passend zu CashAgent-Plugin: "Atb.Psa1256ptu5.software.HWapi/5.0"
Farben und Schriftgroessen vereinheitlichen (guidefs.h)
#endif

578
dCArun/win01_com.cpp Executable file
View File

@ -0,0 +1,578 @@
#include "win01_com.h"
#include "stepList.h" // define all working chain steps here
#include "datei.h"
//#include "globVars.h"
// %%%%%%%%%%%%%%%%%%%% TabComPort
Console::Console(QWidget *parent) : QPlainTextEdit(parent)
{
document()->setMaximumBlockCount(100);
QPalette p = palette();
p.setColor(QPalette::Base, Qt::black); //geht nicht weil untergrund schon farbig
p.setColor(QPalette::Text, Qt::blue);
setPalette(p);
}
void Console::putData(const QByteArray &data)
{
insertPlainText(data);
insertPlainText("\n");
QScrollBar *bar = verticalScrollBar();
bar->setValue(bar->maximum());
}
void Console::putText(QString text)
{
insertPlainText(text);
insertPlainText("\n");
QScrollBar *bar = verticalScrollBar();
bar->setValue(bar->maximum());
}
void T_winComPort::subPortInfo()
{
// Port Info Anzeige Feld, 2. Zeile links
QStringList myStringList;
QStringList comboPortList;
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos)
{
myStringList.append(QObject::tr(" \n Port: ") + info.portName() );
myStringList.append(QObject::tr("Location: ") + info.systemLocation()); // + "\n");
myStringList.append(QObject::tr("Description: ") + info.description() );
myStringList.append(QObject::tr("Manufacturer: ") + info.manufacturer());
myStringList.append(QObject::tr("Serial number: ") + info.serialNumber());
myStringList.append (QObject::tr("Vendor Id: ") + QString::number(info.vendorIdentifier(), 16));
myStringList.append(QObject::tr("Product Id: ") +QString::number(info.productIdentifier(), 16));
//myStringList.append(QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")));
comboPortList.append(info.portName()); // wenn Comport im System vorhanden dann in die Liste eintragen
}
QListWidget *myListWidget = new QListWidget;
myListWidget->insertItems(0, myStringList);
myListWidget->setMaximumWidth(250);
myTabComLayout->addWidget(myListWidget,1,0);
// ComboBox Comport Nr:
CB_portSel = new QComboBox();
CB_portSel->addItems(comboPortList); // string Liste mit addItems (s am Schluss) !
CB_portSel->setMinimumHeight(30);
CB_portSel->setMaximumWidth(150);
QFont myCBfont;
//myCBfont.setBold(true);
myCBfont.setPixelSize(15);
CB_portSel->setFont(myCBfont);
CB_portSel->setCurrentIndex(2); // default 3. Comport in der Liste = ttymxc2 in PTU5
myTabComLayout->addWidget(CB_portSel, 4,0);
}
void T_winComPort::callOpenSerial()
{
// Taste Connect wurde gedrückt, eine Klasse/einen Slot aus einer übergeordneten Klasse:
// openSerialPort();
// kann man nicht aufrufen. deshalb: speichere ComPort, Baudrate und Startbefehl global.
// Von dort wird mit einem zyklischen Timer ausgelesen
int br, ci;
QString bs, cn;
//br=CB_baudSel->currentIndex();
//bs=CB_baudSel->currentText();
br=5;
bs="115200";
cn=CB_portSel->currentText();
ci=CB_portSel->currentIndex();
// aktuell: br=5 bs=115200 cn=0 (=Com5)
//epi_setSerial(5,"115200","COM5",1);
// epi_setSerial(br, bs, cn, 1);
// new: save values for next time
QByteArray myBA, tmpBA;
myBA.clear(); tmpBA.clear();
myBA.append('s'); // start sign, not used
myBA.append(FILESEPERATOR);
tmpBA.setNum(br,10);
myBA.append(tmpBA);
myBA.append(FILESEPERATOR);
myBA.append(bs.toLatin1());
myBA.append(FILESEPERATOR);
myBA.append(cn.toLatin1());
myBA.append(FILESEPERATOR);
tmpBA.clear();
tmpBA.setNum(ci,10);
myBA.append(tmpBA);
myBA.append(FILESEPERATOR);
datei_clearFile(FILENAME_COMPORT);
datei_writeToFile(FILENAME_COMPORT, myBA);
qDebug() << "winComPort opening serial with: " << br << " " << bs << " " << cn;
HWaccess->dc_openSerial(br, bs, cn, 1);// same function with hwapi
// void dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect)
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
// BaudStr: for exapmle "19200"
// ComName: for example "COM48"
// connect: 0, 1
emit connectButtonPressed();
}
void T_winComPort::callCloseSerial()
{
HWaccess->dc_closeSerial();
// epi_closeSerial(); // same function without hwapi
emit closeButtonPressed();
}
void T_winComPort::callAutoSend()
{
if (AutSendButton->isChecked())
{
HWaccess->dc_autoRequest(1);
emit autoSendButtonIsOn();
} else
{
HWaccess->dc_autoRequest(0);
emit autoSendButtonIsOff();
}
}
void T_winComPort::callRefresh(void)
{
subPortInfo();
}
void T_winComPort::callConnectToggle()
{
if (connectButton->isChecked())
{
//qDebug() << "down";
callOpenSerial();
} else
{
//qDebug() << "released";
callCloseSerial();
}
}
void T_winComPort::getDcTestRS232()
{
//qDebug() << "request test response...";
HWaccess->dc_requTestResponse();
}
void T_winComPort::newBaud(void)
{
qDebug() << "new baud selected...";
}
void T_winComPort::setButtons4autoStart()
{
connectButton->setEnabled(true);
connectButton->setDown(true);
connectButton->setChecked(true);
AutSendButton->setEnabled(true);
AutSendButton->setDown(true);
AutSendButton->setChecked(true);
}
T_winComPort::T_winComPort(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
this->HWaccess = HWaccess;
myTabComLayout = new QGridLayout;
//QGridLayout *myGridLayout = new QGridLayout();
// Überschrift linke Spalte
QLabel *portListLabel2 = new QLabel(tr("in System available Ports:"));
myTabComLayout->addWidget(portListLabel2, 0,0);
// Überschrift rechte Spalte
QLabel *lab_headlineR = new QLabel(tr("Serial traffic:"));
myTabComLayout->addWidget(lab_headlineR, 0, 1);
subPortInfo();
// sende-empfangs-Rohdaten-Fenster, 2. Zeile rechts
myDiagWindow = new Console();
myDiagWindow->setReadOnly(true);
myDiagWindow->setEnabled(true);
//myDiagWindow->setLocalEchoEnabled(p.localEchoEnabled);
//myDiagWindow->setMinimumWidth(300);
//myDiagWindow->putData("ongoing serial traffic: ");
myTabComLayout->addWidget(myDiagWindow, 1,1);
// links:
// refresh button:
refreshButton = new QPushButton(tr("&refresh"));
refreshButton->setCheckable(false); // true = toggle button
refreshButton->setAutoDefault(false); // beim start aus
//refreshButton->setMaximumWidth(90);
myTabComLayout->addWidget(refreshButton, 2,0);
//connect(refreshButton, &QAbstractButton::clicked, this, &T_fenster01::callRefresh);
connect(refreshButton, SIGNAL(clicked()), this, SLOT(callRefresh()));
QLabel *Label3 = new QLabel(tr("Port:"));
myTabComLayout->addWidget(Label3, 3,0);
QLabel *Label4 = new QLabel(tr("Baud:"));
myTabComLayout->addWidget(Label4, 5,0);
// ComboBox Baudrate:
QFont my2CBfont;
//my2CBfont.setBold(true);
my2CBfont.setPixelSize(15);
/*
CB_baudSel = new QComboBox();
CB_baudSel->addItem(tr("1200"));
CB_baudSel->addItem(tr("9600"));
CB_baudSel->addItem(tr("19200"));
CB_baudSel->addItem(tr("38400"));
CB_baudSel->addItem(tr("57600"));
CB_baudSel->addItem(tr("115200"));
CB_baudSel->setMinimumHeight(30);
CB_baudSel->setMaximumWidth(150);
CB_baudSel->setFont(my2CBfont);
CB_baudSel->setCurrentIndex(5); // default 115k baud
//CB_baudSel->setCurrentIndex(1); // default 9600 baud
myTabComLayout->addWidget(CB_baudSel, 6,0);
//connect(CB_baudSel, SIGNAL(currentIndexChanged(int)), this, SLOT(newBaud()));
connect(CB_baudSel, SIGNAL(currentIndexChanged(int)), this, SLOT(newBaud()));
*/
// Statuszeile COM Port (serial Port)
LabelComState = new QLabel(tr("not connected"));
myTabComLayout->addWidget(LabelComState, 7,0);
// Connect button:
connectButton = new QPushButton(tr("&Connect"));
connectButton->setCheckable(true); // true = toggle button
connectButton->setAutoDefault(true); // beim start ein
connectButton->setMaximumWidth(90);
connectButton->setMinimumHeight(50);
myTabComLayout->addWidget(connectButton, 8,0);
//connect(connectButton, &QAbstractButton::clicked, this, &T_fenster01::callConnectToggle);
connect(connectButton, SIGNAL(clicked()), this, SLOT(callConnectToggle()));
// rechts:
// test serial line:
TestButton = new QPushButton(tr("test Connection"));
TestButton->setMaximumWidth(150);
myTabComLayout->addWidget(TestButton,2,1);
TestButton->setCheckable(false); // true = toggle button
TestButton->setAutoDefault(false); // beim start aus
// connect(TestButton, &QAbstractButton::clicked, this, &T_fenster01::getDcTestRS232);
connect(TestButton, SIGNAL(clicked()), this, SLOT(getDcTestRS232()));
// I Statuszeile Handshakes (serial Control) flow.cpp
// geht überhaupt was raus? kommt überhaupt was zurück?
//LabelHandshakes = new QLabel(tr("control line"));
LabelHandshakes = new QLabel("HS"); // not used
myTabComLayout->addWidget(LabelHandshakes, 3,1);
// II Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
LabelRecieveFrame = new QLabel(tr("slave receive"));
myTabComLayout->addWidget(LabelRecieveFrame, 4,1);
// III Anzeige der Slave-Results (Datif)
LabelResults = new QLabel(tr("results line"));
myTabComLayout->addWidget(LabelResults, 5,1);
// IV Statuszeile Sende- und Empfangsdaten brauchbar? (Datif)
LabelDataState = new QLabel(tr("datif line"));
myTabComLayout->addWidget(LabelDataState, 6,1);
// V
LabelDatif = new QLabel(tr("datif line"));
myTabComLayout->addWidget(LabelDatif, 7,1);
// Autosend:
AutSendButton = new QPushButton(tr("&Automatic reading")); // &A --> also keycode Alt-A possible
//AutSendButton->setMaximumWidth(90);
myTabComLayout->addWidget(AutSendButton,8,1);
AutSendButton->setCheckable(true); // true = toggle button
AutSendButton->setAutoDefault(true); // beim start aus
AutSendButton->setMinimumHeight(50);
// connect(AutSendButton, &QAbstractButton::clicked, this, &T_fenster01::callAutoSend);
connect(AutSendButton, SIGNAL(clicked()), this, SLOT(callAutoSend()));
setLayout(myTabComLayout);
myNextStep=0;
myStep=0;
callConnectToggle();
callAutoSend();
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(2000);
}
// not needed:
T_winComPort::~T_winComPort()
{
close();
}
void T_winComPort::Nav_back(void)
{
myNextStep=WCS_WIN01BAK;
}
void T_winComPort::Nav_home(void)
{
myNextStep=WCS_WIN01MID;
}
void T_winComPort::Nav_next(void)
{
myNextStep=WCS_WIN01FWD;
}
bool T_winComPort::work_ini(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called ONE time after selecting this state (initialization)
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
*nextScreen=0; // needed 0=no change
// *useNavi=SWITCH_BACK_OFF | SWITCH_HOME_OFF | SWITCH_NEXT_ON;
*useNavi=SWITCH_BACK_OFF | SWITCH_HOME_OFF | SWITCH_NEXT_OFF; // bei CArun alle aus
return false;
}
bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called cyclic until this state changes intentionally to another state
// display informations for human operator, react on operators inputs or wait for payment media
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
this->updateGui();
*nextScreen=0; // 0=no change
*useNavi=0;
if (myStep==0)
{
// load and use last settings: --------------------
QByteArray myBA;
myBA=datei_readFromFile(FILENAME_COMPORT);
//uint32_t len= datei_nrOfEntriesInFile(myBA);
//uint64_t ulltmp=csv_getEntryAs2Ulong(myBA,0);
//qDebug()<<"win_startup load long numer: "<<ulltmp;
QString bs=csv_getEntryAsString(myBA,0); // read the 's' war 2!??
int br=csv_getEntryAsInt(myBA,1); // z.B. 5 (5.Eintrag in der Baud-Liste)
bs=csv_getEntryAsString(myBA,2); // z.B 115200
QString cn=csv_getEntryAsString(myBA,3); // z.B. COM9
int ci=csv_getEntryAsInt(myBA,4); // Eintragsnummer in COM-Fenster
//qDebug()<<"win_startup loaded com settings: "<<br<<" "<<bs<<" "<<cn;
HWaccess->dc_openSerial(br,bs,cn,1);
//CB_baudSel->setCurrentIndex(br); // im BR auswahlfenster diese Baud vorgeben
CB_portSel->setCurrentIndex(ci); // den Port aus der Datei hier vorgeben
connectButton->setChecked(true); // connect Taste "druecken"
myTO->start(100); // restart
myStep++;
} else
if (myStep==1)
{
if (!myTO->isActive())
{
if (HWaccess->dc_isPortOpen())
myStep++;
else
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
} else
if (myStep==2)
{
if (!myTO->isActive())
{
HWaccess->dc_requTestResponse();
myStep++;
myTO->start(100);
}
} else
if (myStep==3)
{
if (!myTO->isActive())
{
if (HWaccess->dc_readAnswTestResponse())
myStep++; // response was correct
else
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
} else
if (myStep==4)
{
HWaccess->dc_autoRequest(1);
AutSendButton->setChecked(true); // taste "druecken"
myStep++;
} else
if (myStep==5)
{
// got next screen:
//myNextStep=2; // nicht bei CArun
myStep++;
} else
if (myStep==6)
{
// stop here, everything done
} else
if (myStep==7)
{
} else
{
}
if (myNextStep)
{
//qDebug()<<"fenster1 working: "<< myNextStep;
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}
void T_winComPort::updateGui(void)
{
QByteArray myBA;
QString ms;
ms=HWaccess->dc_getTxt4RsDiagWin();
if (ms.length()>1) // sonst ständig scrolling
{
myDiagWindow->putText(ms);
HWaccess->dc_clrTxt4RsDiagWin();
}
ms=HWaccess->dc_get2ndTxt4RsDiagWin();
if (ms.length()>1) // sonst ständig scrolling
{
myDiagWindow->putText(ms);
HWaccess->dc_clr2ndTxt4RsDiagWin();
}
// state of the COM Port (open, closed)
ms=HWaccess->dc_getSerialState();
if (ms.length()>1) // sonst ständig scrolling
{
LabelComState->setText(ms);
}
// --------------------------------------------------------------------------
// I Statuszeile Handshakes (serial Control)
ms=HWaccess->dc_getTxt4HsStateLine();
if (!connectButton->isChecked())
ms="";
if (ms.length()>1) // sonst ständig scrolling
{
LabelHandshakes->setText(ms);
HWaccess->dc_clrTxt4HsStateLine();
// clear to avoid multiple displaying
}
// II Master receive state (empfangenes Telgramm OK? crc? length? )
// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
ms=HWaccess->dc_getTxt4masterStateLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelRecieveFrame->setText(ms);
HWaccess->dc_clrTxt4masterStateLine();
}
// 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
ms=HWaccess->dc_getTxt4resultStateLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelResults->setText(ms);
HWaccess->dc_clrTxt4resultStateLine();
}
// IV Statuszeile Empfangsdaten
ms=HWaccess->dc_getdataStateLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelDataState->setText(ms);
HWaccess->dc_clrTxt4dataStateLine();
// clear to avoid multiple displaying
}
// 5. Zeile: Datif Ergebnis, Daten brauchbar?
ms=HWaccess->dc_getdatifLine();
if (!connectButton->isChecked())
ms="---";
if (ms.length()>1) // sonst ständig scrolling
{
LabelDatif->setText(ms);
HWaccess->dc_clrTxt4datifLine();
}
// -----------------------------------------------------------------------------
}

107
dCArun/win01_com.h Executable file
View File

@ -0,0 +1,107 @@
#ifndef WINCOMPORT_H
#define WINCOMPORT_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QObject>
#include <QTimer>
#include <QDebug>
#include <QTabWidget>
#include <QScrollBar>
#include <QPlainTextEdit>
#include <QComboBox>
#include <QLabel>
#include <QScrollArea>
#include <QSerialPortInfo>
#include <QWidget>
#include <QListWidget>
#include <QGroupBox>
#include <QPushButton>
#include <QRadioButton>
//#include "tslib.h"
//#include "stepList.h" // define all working chain steps here
//#include "datei.h"
#include "plugin.h"
//#include "globVars.h"
class Console : public QPlainTextEdit
{
Q_OBJECT
public:
explicit Console(QWidget *parent = nullptr);
void putData(const QByteArray &data);
void putText(QString text);
};
class T_winComPort : public QWidget // former TabComport
{
Q_OBJECT
Console *myDiagWindow; // Ausgabefenster
QComboBox *CB_portSel;
//QComboBox *CB_baudSel;
QPushButton *connectButton;
QPushButton *AutSendButton;
QPushButton *TestButton;
QPushButton *refreshButton;
QLabel *LabelComState; // Statusanzeige
QLabel *LabelPort;
QLabel *LabelHandshakes;
QLabel *LabelRecieveFrame;
QLabel *LabelResults;
QLabel *LabelDataState;
QLabel *LabelDatif;
QGridLayout *myTabComLayout;
void subPortInfo();
hwinf *HWaccess;
void updateGui(void);
uint16_t myNextStep;
uint8_t myStep;
QTimer *myTO;
private slots:
void callOpenSerial();
void callCloseSerial();
void callAutoSend();
//void tabComTime100ms();
void callConnectToggle();
void getDcTestRS232();
void callRefresh(void);
public:
explicit T_winComPort(hwinf *HWaccess = nullptr, QWidget *parent = nullptr);
bool work_ini(uint16_t *nextScreen, uint8_t *useNavi);
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
bool working (uint16_t *nextScreen, uint8_t *useNavi);
~T_winComPort();
void writeRSdiagBytes(const QByteArray &bytarray);
void writeRSdiagText(QString text);
void writeComState(const QString text);
void writeDataState(const QString text);
void setButtons4autoStart();
signals:
void connectButtonPressed();
void closeButtonPressed();
void autoSendButtonIsOn();
void autoSendButtonIsOff();
private slots:
void newBaud(void); // just for test
public slots:
void Nav_back(void);
void Nav_home(void);
void Nav_next(void);
};
#endif

107
include/com.h Normal file
View File

@ -0,0 +1,107 @@
//CAT is always master, no receive before request
#ifndef SER_H
#define SER_H
#include <stdint.h>
#include <QMainWindow>
//#include <QString>
#include <QTimer>
#include <QSerialPort>
#include "tslib.h"
#include "controlBus.h"
#include "interfaces.h"
#define MAXTELEGRAMLEN 90
// display all inputs and outputs in output window:
//#define PRINTALLDEBUGS 1
class T_com : public QObject //, public QPlainTextEdit
{
Q_OBJECT
// complete send message (protocol frame)
QByteArray sendBuffer; //[MAXTELEGRAMLEN];
uint16_t sendLen; // >0: Daten Sendebereit, nach senden wieder auf 0 setzen
// right after reception:
QByteArray rawInput; //[MAXTELEGRAMLEN];
uint16_t rawInLen; // 0: keine neuen Daten erhalten
// QSerialPort *CatSerial = nullptr;
QSerialPort *CatSerial;
//char oeffneSerialPort();
char open_Serial_Port();
void closeSerialPort();
void receiveByLength(void);
private slots:
void readSomeBytes(void);
void serialSendComplete(void);
//void incomingWake(void); //bool LevelOfTheBit);
void receiveTO(void);
void ser_ISR100ms();
public:
T_com(QObject *parent = nullptr);
~T_com();
QTimer *serRecTime;
bool isPortOpen(void);
void writeToSerial(const QByteArray &data, uint16_t sendLength);
void receiveFixLen(int64_t nrOfbytesToReceive);
bool readFromSerial(QByteArray &data, uint16_t &sendLength);
// retval: true: data available
/*
uint8_t getAllPortPins(void);
// rs232pins: all signals bitwise coded in one byte:
// readback output: bit 0=TxD(=output) bit2=DTR (=output) bit 6=RTS (=output)
// unused inputs: bit1=RxD bit 3=DCD bit 5 = RING
// handshake inputs: bit 4=DSR (0x10) bit 7=CTS (0x80)
bool getHSin_CTS(void);
// return the CTS Handshake input): true= high level (+8V)
bool getHSin_DSR(void);
// return the DSR Handshake input): true= high level (+8V)
bool setHSout_RTS(bool hsout);
// hsout true=positiv voltage +12V false= -12V
// retval: true=setting OK
bool setHSout_DTR(bool hsout);
// hsout true=positiv voltage +12V false= -12V
// retval: true=setting OK
*/
signals:
void receivingFinished();
void sendingFinished();
//void wasWokenBySerialHandshake();
};
#endif // SER_H

213
include/controlBus.h Normal file
View File

@ -0,0 +1,213 @@
#ifndef CONTROLBUS_H
#define CONTROLBUS_H
#include "tslib.h"
#include <QString>
#include "interfaces.h"
//#include "hwapi.h"
#include <QDebug>
#include "shared_mem_buffer.h"
// ///////////////////////////////////////////////////////////////////////////////////
// control serial interface gui <--> serial
// ///////////////////////////////////////////////////////////////////////////////////
void epi_setSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect);
// Actions: open serial port with parameters
void epi_closeSerial(void);
// Actions: close serial port
// Port -> API
void gpi_serialChanged(void);
// serial confirms that port was closed or opened
// Actions, API -> serialPort
uint8_t gpi_getSerialConn(void); // connect if 1, disconnect if 0
int gpi_getBaudNr(void);
QString gpi_getComPortName(void);
//#endif
void gpi_serialIsOpen(bool offen);
bool epi_isSerialPortOpen();
// true: port is open false: port is closed
// Actions, GUI Buttons -> API, start cyclic transmission
void epi_startEmmision(bool start); // 1: start sending activated
// Meldung von TabCom an Datif: starte zyklische Sendung:
bool gpi_isEmmisionOn(void);
// ///////////////////////////////////////////////////////////////////////////////////
// Status Display gui <--> serial
// ///////////////////////////////////////////////////////////////////////////////////
// Statuszeile COM Port (serial Port) (open, closed)
// Display in tab_com
QString epi_getTxt4comStateLine(void);
void epi_clrTxt4comStateLine();
// GUI: get Text for serial Comport-State Line
//---------------------
// Statuszeile Handshakes (serial Control) flow.cpp
// geht überhaupt was raus? kommt überhaupt was zurück?
// I
QString epi_getTxt4HsStateLine(void);
void epi_clrTxt4HsStateLine();
// GUI: get Text
// II Master receive state (empfangenes Telgramm OK? crc? length? )
// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp)
QString epi_getTxt4masterStateLine(void);
void epi_clrTxt4masterStateLine();
// 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);
void epi_clrTxt4resultStateLine();
// IV Statuszeile Sende- und Empfangsdaten (Datif)
// Display in tab_com
QString epi_getTxt4dataStateLine(void);
void epi_clrTxt4dataStateLine();
// GUI: get Text for serial Comport-State Line
// V, unten, Datif
QString epi_getTxt4datifLine(void);
void epi_clrTxt4datifLine();
//---------------------
// sende-empfangs-Rohdaten-Fenster
// Display in tab_com
QString epi_getTxt4RsDiagWin(void);
void epi_clrTxt4RsDiagWin();
QString epi_get2ndTxt4RsDiagWin(void);
void epi_clr2ndTxt4RsDiagWin();
// Statuszeile COM Port (serial Port) (open, closed)
// Display in tab_com
void gpi_setTxt4comStateLine(QString txtline);
// serial: write Text to be displayed in serial Comport-State line (like "connected")
// used in vcp.cpp, links in tabCom
// Statuszeile Handshakes (serial Control)
// I obere Zeile
void gpi_setTxt4HsStateLine(QString txtline);
// used in flow.cc
// II
void gpi_setTxt4masterStateLine(QString txtline);
// III
void gpi_setTxt4resultStateLine(QString txtline);
// IV
void gpi_setTxt4dataStateLine(QString txtline);
// serial: write Text to be displayed in serial Comport-State line (like "connected")
// used in prot.cpp
// V unten:
void gpi_setTxt4datifLine(QString txtline);
// sende-empfangs-Rohdaten-Fenster
// Display in tab_com
void gpi_setTxt4RsDiagWin(QString txtline);
void gpi_set2ndTxt4RsDiagWin(QString txtline);
//#endif
// ///////////////////////////////////////////////////////////////////////////////////
// Memory for Slave responses, common data
// ///////////////////////////////////////////////////////////////////////////////////
bool epi_getResult_serialTestOK();
// retval: true: test was successful, got right response
// result of serial line test, slave sent fixed string
void gpi_storeResult_serialTestOK(bool wasOn);
// ///////////////////////////////////////////////////////////////////////////////////
// restore just received data
// ///////////////////////////////////////////////////////////////////////////////////
void gpi_startNewRequest();
// called by Datif
void gpi_storeResultOfLastRequest(bool answisok);
// written by Datif
uint8_t epi_getResultOfLastRequest();
// retval: 0: in progress 1: OK 2: error
void gpi_storeRecPayLoad(uint8_t RdDlen, uint8_t *receivedData);
// stored by Datif
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
void gpi_storeSlaveSerParams(uint8_t slaveBaudRate, uint8_t NrDataBits,
uint8_t parity, uint8_t NrStopBits);
void epi_getSlaveSerParams(uint8_t *slaveBaudRate, uint8_t *NrDataBits,
uint8_t *parity, uint8_t *NrStopBits);
QString epi_getSlaveParamSTR();
void gpi_storeLastResult(uint8_t letzteAntwort);
uint8_t epi_getLastResult(void);
// return: 0xFF: result unknown 0=OK
// 1= wrong length 2=wrong start sign 5= wrong crc
// 6= slave: master cmd was wrong 7: slave: could not write/read data
// 8=timeout, got no response from slave
void epi_startSupervision();
bool gpi_wantToResetSupervision();
void gpi_storeOverallResult(uint8_t letzteAntwort);
uint8_t epi_getBatchResult(void );
// 0xFF: no command sent by now
// 0: started, in progress
// 1: done and OK
// done and error
#endif

206
include/datIf.h Normal file
View File

@ -0,0 +1,206 @@
// Data Interface between slave (DC) and pi buffer
// determines sending and receiving order of data
// cares for storing input data and restoring output data
#ifndef DIF_H
#define DIF_H
#include "tslib.h"
#include "prot.h"
#include "dcBL.h"
//#include <QMainWindow>
#include <QString>
#include <QTimer>
#include <QDebug>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include "interfaces.h"
#define CMD2DC_sendTime 20
#define CMD2DC_setWakeFrequ 112
#define CMD2DC_MOV_UPLOCK 113
#define CMD2DC_MOV_DNLOCK 114
#define CMD2DC_UPPER_DOOR 115
#define CMD2DC_LOWER_DOOR 116
#define CMD2DC_VAULT_DOOR 117
#define CMD2DC_REJMOT_ON 118
#define CMD2DC_REJMOT_RUN 119
#define CMD2DC_LED_COIN 100
#define CMD2DC_LED_ILLU 101
#define CMD2DC_LED_TICKET 102
#define CMD2DC_LED_START 104
#define CMD2DC_LED_PIN 103
#define CMD2DC_LED_IN 105
#define CMD2DC_FAN 106
#define CMD2DC_SIREN 107
#define CMD2DC_BARRIER 108
#define CMD2DC_WAKEPTU 109
#define CMD2DC_SWITCHAUXPWR 110
#define CMD2DC_SWITCHAUXDDR 18
#define CMD2DC_SWITCHAUXOUT 19
#define CMD2DC_UCONTACTON 111
#define CMD2DC_DEVICE_PARAM 23
#define CMD2DC_SEND_MACH_ID 11
#define CMD2DC_RDBK_DEV_PARA 14
#define CMD2DC_RDBK_MACH_ID 15
#define CMD2DC_MDB_ON 120
#define CMD2DC_MDB_GET_STATE 107 // REQ
#define CMD2DC_MDB_DORESET 121
#define CMD2DC_MDB_SETWAK 122
#define CMD2DC_MDB_SENDCMD 123
#define CMD2DC_MDB_SENDMSG 12
#define CMD2DC_MDB_GETRESP 22 // REQ
#define CMD2DC_EMP_SET 24
#define CMD2DC_EMP_GET_ALL 23 // REQ
#define CMD2DC_EMP_STARTPOLL 124
#define CMD2DC_EMP_STARTPAY 125
#define CMD2DC_EMP_STOPPAY 126
#define CMD2DC_EMP_GOTCOIN 108 // REQ
#define CMD2DC_SHUTTER_OPEN 129
#define CMD2DC_ESCR_OPEN 132
#define CMD2DC_ESCR_TAKE 133
#define CMD2DC_ESCR_RETURN 134
#define CMD2DC_MOD_ON 135
#define CMD2DC_MOD_WAK 136
#define CMD2DC_CRED_ON 137
#define CMD2DC_CRED_WAK 138
// READ Commands ((e.g. get input)
#define CMD2DC_TestSerial 10
#define CMD2DC_GetSerialConfig 105
#define CMD2DC_RdBkHWversion 11
#define CMD2DC_RdBkSWversion 12
#define CMD2DC_RdBkDCstate 101
#define CMD2DC_RdBkUID 18
#define CMD2DC_RdBkTime 104
#define CMD2DC_RdBkAnalog 106
#define CMD2DC_GetAllInputs 102
#define CMD2DC_RdBkAllOutputs 103
#define CMD2DC_MIFREADERON 127
#define CMD2DC_ATB_CREATE 128
// Mif read data:
//#define CMD2DC_RdBk_MifState 109
//#define CMD2DC_RdBk_MifData 24
#define CMD2DC_RdBk_AtbCardType 25
#define CMD2DC_SHUTTER_COIN 131
#define CMD2DC_SHUTTER_OPEN3S 130
//#define CMD2DC_SEND_SHUT_TIME 0x2915
#define CMD2DC_ESCR_TAKE 133
#define CMD2DC_ESCR_RETURN 134
#define CMD2DC_PRINTERON 139
#define CMD2DC_RdBk_PrnState 110
#define CMD2DC_RdBk_PrnFonts 26
#define CMD2DC_RdBk_AllPrnData 27
// nr of params:
#define CMD2DC_PRI_SYS_CMD 25 // 3
#define CMD2DC_PRI_ESC_CMD 26 // 4
#define CMD2DC_PRI_SETUP 27 // 5
#define CMD2DC_PRI_MOVE 140 // 2
#define CMD2DC_PRI_SETFONT 141 // 4
#define CMD2DC_PRI_SETLETTER 142 // 3
#define CMD2DC_PRI_CUT 143 // 1
#define CMD2DC_PRI_PRINT_TXT 13 // 64
#define CMD2DC_PRI_LF 144 // 1
#define CMD2DC_PRI_PRIFONTTABLE 145
#define CMD2DC_PRI_BARCODE 14 // ca 15...25
#define CMD2DC_STOR_QR_DATA 15 // 150
#define CMD2DC_PRI_QR_CODE 146 // 0
#define CMD2DC_PRI_LOGOFROMFLASH 147 // 2
#define CMD2DC_PRI_STORE_DOC 16 // 1
#define CMD2DC_PRI_DOCUMENT_NR 17 // 1 + 64
#define CMD2DC_PRI_CLEAR_DOC 148 // 1
#define FIX_SLAVE_ADDR 0
#define SEND_ATONCE 1
#define SENDCOMBINED 0
class T_datif : public QObject
{
Q_OBJECT
char sendINrequestsAutomatic(void);
// sende alle Befehle um die Eingangsdaten abzufragen der Reihe nach
char loadRecDataFromFrame();
void datif_startSending(void);
void datif_sendIOrequest(uint16_t WRcmd, uint16_t RDcmd, uint8_t nrOfWrData);
void datif_send8byteOutCmd(uint16_t WRcmd, uint16_t RDcmd);
bool verifyLineTestresponse(uint8_t RdDlen, uint8_t *receivedData);
void datif_OUT_setTime(void);
uint8_t datif_OUT_SendRandomData(uint8_t *buf, uint8_t Length);
//void datif_send64byteOutCmd(uint16_t WRcmd, uint16_t addr, uint16_t RDcmd);
void datif_sendToMemory(uint16_t WRcmd, uint16_t docNr, uint16_t blockNr, uint8_t *data64);
// send printer documents to DC2 memory
// docNr: 0...15(31) with 1280 byte each (20 blocks a 64byte)
// blockNr=0...19 with 64byte each
// docNr =transmitted in WRITEADDRESS high byte
// blockNr=transmitted in WRITEADDRESS low byte
int datif_noResponseCtr;
T_prot *myDCIF;
QTimer *datif_trigger;
uint8_t selectedSlaveAddr;
private slots:
char datif_cycleSend();
void StoredRecData();
public:
T_datif(QObject *parent = nullptr);
void resetChain(void);
char isPortOpen(void);
//void sendWRcommand(uint16_t nxtAsCmd);
// Sende Schreibbefehle die bereits vorher asynchron gespeichert wurden
//void send_requests(uint16_t nextWrCmd);
//void sendHighLevel(uint16_t nxtHLCmd);
void startSupervision(void);
//void getOverallResult(void);
// 0xFF: no command sent by now
// 0: started, in progress
// 1: done and OK
// 2: done and error
void getOverallResult(void);
signals:
void ResponseRecieved();
//the requested data are stored in peripheral image
// can be loaded with epi
void datif_templatePrintFinished_OK();
void datif_templatePrintFinished_Err();
void datif_gotNewCoin();
};
#endif // CI_H

201
include/datei.h Normal file
View File

@ -0,0 +1,201 @@
#ifndef DATEI_H
#define DATEI_H
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include "tslib.h"
#include <QString>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
// create csv file with:
#define FILESEPERATOR ','
// pasre csv with:
#define FILESEP1 ','
#define FILESEP2 ';'
#define NEWLINEINFILE '\n'
#define MAXNUMBEROFSEQUENCES 200
// only for csv files
// all generated files located in sudirectory "dynamic machine data - dmd"
#define FILENAME_SHAREDDATA "../dmd/DCshare.csv"
#define FILENAME_SHARED_UID "../dmd/DC_UID.csv"
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ create csv file -------------------------------
// -------------------------------------------------------------------------------------------------
// create array with strings and values (to be written to file)
void csv_startCreatingFile(void);
void csv_addTextToFile(QString myText);
void csv_addIntToFile(int myValue);
void csv_addUintToFile(uint myValue);
void csv_addLongvalToFile(qlonglong myValue);
void csv_addUlongvalToFile(qulonglong myValue);
//void csv_addCurrentTimeToFile(void);
//void csv_addCurrentDateToFile(void);
void csv_addNewlineToFile(void);
QByteArray csv_readbackArray(void);
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ parse csv file -------------------------------
// -------------------------------------------------------------------------------------------------
// return number of entries in the just read file (entries are seperated by
// comma or line-feed)
uint32_t csv_nrOfEntriesInFile(QByteArray readFromFile);
// before: QByteArray sourceFile=datei_readFromFile(filename);
QByteArray csv_getOneFileSequence(QByteArray sourceFile, uint32_t sequNr);
// not needed, just for test // sequNr: 0....(size-1)
// get single entries of of the just read file:
int csv_getEntryAsInt(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
int32_t csv_getEntryAsLong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint8_t csv_getEntryAsUshort(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint16_t csv_getEntryAsUint(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint32_t csv_getEntryAsUlong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
uint64_t csv_getEntryAs2Ulong(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
QString csv_getEntryAsString(QByteArray sourceFile, uint32_t sequNr);
// sequNr: 0....(size-1)
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ create Json Record -------------------------------
// -------------------------------------------------------------------------------------------------
void json_startRecord(void);
// clear buffer and write opening curly bracket {
void json_enterIntToRecord(QString attribute, ulong i_value);
// example: "parameter":1234567890
void json_enterTextToRecord(QString attribute, QString txt_value);
// example: "parameter":"slow"
//void json_addCurrentTimeToRecord(QString attribute);
// example: if attribute=myTime: "myTime":"hh_mm_ss"
//void json_addCurrentDateToRecord(QString attribute);
// example: if attribute=myDate: "myDate":"dd.mm.yyyy"
// also / possible as seperator
// further possible forms:
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
void json_enterArrayToRecord(QString attribute, uint8_t *buf, ulong nrofVals);
// add array of numbers with "nrofVals" elements
void json_enterStructToRecord(QString attribute);
// every call must be concluded with an extra "json_finishFile()"
// example: "sname":{
void json_finishStruct(void);
void json_finishRecord(void);
// close curly bracket
QString json_readbackRecordStr(void);
QByteArray json_readbackRecordBa(void);
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ parse Json file -------------------------------
// -------------------------------------------------------------------------------------------------
// first: QByteArray datei_readFromFile(QString filename);
//void datei_json_readTestFile(QString filename);
int json_nrOfPairsInFile(QByteArray filename);
bool json_exists(QByteArray filename, QString searchForKey);
// look for "searchForKey" =name of the pair (left of : )
// retval true if exists
bool json_remove(QByteArray filename, QString searchFor);
// look for "searchFor" =name of the pair (left of : ) and remove the record from file
// retval true if removed
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
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
//.......................
QJsonObject json_searchForObjectInFile(QByteArray filename, QString searchFor);
// return an object from the json file
int json_nrOfPairsInObject(QJsonObject objname);
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
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
//.......................
QJsonArray json_searchForArrayInFile(QByteArray filename, QString searchFor);
// look for "searchFor" =name of the pair (left of : ) and return value of this pair (right of : ) as String
int json_nrOfValuesInArray(QJsonArray arrayname);
bool json_getValuesOfArray(QJsonArray arrayname, int *buf, int MaxBufferSize);
// assuming that the array consists of integers
// -------------------------------------------------------------------------------------------------
// ------------------------------------------------------ read, write, copy files -------------------
// -------------------------------------------------------------------------------------------------
void datei_closeFile(QString filename);
// read content of an exiting file:
QByteArray datei_readFromFile(QString filename);
bool datei_ifFileExists(QString filename);
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
bool datei_copyFile(QString currentFileName, QString newFileName);
// retval=true if successful
bool datei_clearFile(QString filename);
// retval=true if successful
#endif // DATEI_H

122
include/dcBL.h Normal file
View File

@ -0,0 +1,122 @@
#ifndef DCBL_H
#define DCBL_H
#include "qbytearray.h"
#include "qstring.h"
#include <QFile>
#include "storeINdata.h"
uint8_t dcBL_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf);
// make BL protocol, retval = outbuf length (5...133)
// bring data in correct form: start always with 0x02 finish with 0x03 and append checksum
// 0x02 Cmd < ...sendData ..> CRC CRC 0x03
// Data length = 0...64
// special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80
// so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64
uint8_t dcBL_readBLversion(uint8_t *sendData);
// minimum size of sendData-buffer: 5byte retval: length
uint8_t dcBL_readFWversion(uint8_t *sendData);
// minimum size of sendData-buffer: 5byte retval: length
uint8_t dcBL_exitBL(uint8_t *sendData);
// minimum size of sendData-buffer: 5byte retval: length
uint8_t dcBL_sendFlashStartAddr2BL(uint32_t startAddr, uint8_t *sendData);
// minimum size of sendData-buffer: 13byte retval: length (9...13)
uint8_t dcBL_writeLastPage(uint8_t *sendData);
// minimum size of sendData-buffer: 5byte retval: length
uint8_t dcBL_restartDC(uint8_t *sendData);
// minimum size of sendData-buffer: 20 byte retval: length
uint8_t dcBL_activatBootloader(uint8_t *sendData);
// minimum size of sendData-buffer: 20 byte retval: length
bool dcBL_responseOK();
// retval: 0: response OK (cmd |0x80) 1: response error (cmd or "0xe0")
bool dcBL_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl);
char dcBL_loadBinSafe(QString fileName);
bool dcBL_isTextMemFree(void);
void dcBL_writeText(QString newTxt);
bool dcBL_checkForText(void);
// if pointer at 0 then no more content
QString dcBL_readText(void);
// read from 0...9 (oldest first)
uint16_t dcBL_getNrOfBlocks(void);
// size of the loaded bin file in 64byte blocks
uint16_t dcBL_getFileCrc(void);
// checksum of the loaded bin file
uint32_t dcBL_getFileSize(void);
// length of the loaded bin file in byte
uint8_t dcBL_getSizeOfLastBlock(void);
bool dcBL_sendOneBlockCpl(uint16_t blockNumber);
int8_t dcBL_getBlockResult(void);
char dcBL_cycle(void);
// to be called cyclic every 100ms
/*
void dcBL_iniChain(void);
uint8_t dcBL_startChain(void);
uint8_t dcBL_runChain(void);
void dcBL_iniLoading(void);
void dcBL_startLoading(void);
uint8_t dcBL_sendHexfile(void);
uint8_t dcBL_getResult(void);
// call after every step to see what's going on....
// 1: connected to BL
// 2: transmission started
// 3: transmission successful
*/
/* move to storeINdata and use shared mem as ptu-updater uses CAslave Lib 6.9.23TS
#define RAW_BL_DATALEN 150
void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData);
uint8_t epi_getRawReceivedData(uint8_t *receivedData);
// retval=length, will be zeroed after first reading
uint8_t epi_getRawRecLength(void);
// retval=length
//QString epi_getRawReceivedString();
// not used
void epi_clrRawReceivedString();
*/
uint8_t dcBL_sendSuccess(uint8_t lastCommand);
// return val: 0: no response by now 1:error 10: OK
// lastCommand=0x21 for sendAddr or 0x22 for send data
char dcBL_loadBinary(char withDisplay);
#endif // DCBL_H

55
include/dc_result.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef DC_RESULT_H_INCLUDED
#define DC_RESULT_H_INCLUDED
#include <QMetaType>
#include <QString>
#include <QDebug>
class DCResult {
public:
enum class PLUGIN_STATE : quint8 {
NOT_INITIALIZED = 0,
INITIALIZED = 1
};
enum class RESULT_STATE : quint8 {
SUCCESS = 1, // operation was successfull
ERROR_BACKEND, // error from backend (e.g. backend replies with error)
ERROR_TIMEOUT, // the operation timed out
ERROR_PROCESS, // internal plugin error, should not occur (this is a bug in implementation)
ERROR_RETRY, // retry operation
INFO // informational (e.g. display a message, log something etc.)
};
enum class CASH_STATE : quint8 {
CACHE_EMPTY, // Cache still empty, default state
CACHE_INPUT, // Coins are in Cache
OVERPAYED,
NOT_AVAILABLE
/* t.b.d. */
};
explicit DCResult();
explicit DCResult(PLUGIN_STATE, RESULT_STATE, QString errorCode = "",
QString errorDescription = "",
QString cashValue = "");
explicit DCResult(PLUGIN_STATE, RESULT_STATE, CASH_STATE,
QString errorCode = "",
QString errorDescription = "",
QString cashValue = "");
PLUGIN_STATE m_pluginState;
RESULT_STATE m_resultState;
CASH_STATE m_cashState;
QString m_errorCode;
QString m_errorDescription;
QString m_newCashValue;
};
QDebug operator<<(QDebug d, DCResult const &result);
Q_DECLARE_METATYPE(DCResult)
#endif // DC_RESULT_H_INCLUDED

305
include/globdefs.h Executable file
View File

@ -0,0 +1,305 @@
// global defines
// ab 6.Juli2020: neuese Board DC2b
#ifndef GLOBDEFS_H
#define GLOBDEFS_H
#include <bios19/biosdefs.h>
//#define VERSION_DC_HW "DC2b_25.02.2020"
#define VERSION_DC_HW "DC2c_oct2022"
//#define VERSION_PO_HW "PO2d_27.03.2020"
#define VERSION_PO_HW "PO2e_nov2022"
#define VERSION_SW "DC2c.04.12 06.04.2023"
//#define VERSION_SW "DC2c.04.04b14.02.2023"
//#define VERSION_SW "DC2c.04.04c14.02.2023"
#define USE1256MODE 1
#define SEND_DIAG_TO_MASTER 1
#define MAX_DATA_FROM_MASTER 64
#define MAX_RECLEN_FROM_MASTER MAX_DATA_FROM_MASTER+20
#define MAX_DATA_TO_MASTER 64
#define MAX_SENDLEN_TO_MASTER MAX_DATA_TO_MASTER+16
#define WORK_WITHOUT_HANDSHAKES
#define PAGEBUFFERSIZE 1026
extern UCHAR PageBuffer[PAGEBUFFERSIZE];
#define WAKESRC_NONE 0
#define WAKESRC_MDB 1
#define WAKESRC_COIN 2
#define WAKESRC_MASTER 3
#define WAKESRC_RTC 4
#define WAKESRC_DOOR 5
#define WAKESRC_DIAG 6
#define WAKESRC_HB 7
struct T_power
{
char busy;
char sleepAllowed;
UCHAR WakeSource;
char everythingUP;
char WokenByDevice;
char NoExternalEventNow;
char WakePulseNowActive;
UCHAR DC_status; // 0:POR 1:board ini 2:running HWtest 3: device ini 4: start-up-test
// 5: SW Module ini
UCHAR storeWakeReason[6];
char blockRS2forMif;
char blockRS1forPrinter;
};
struct T_globTime
{
UCHAR Year;
UCHAR Month;
UCHAR Day;
UCHAR DOW; // 1(Mo)....7(So)
UCHAR Hours;
UCHAR Min;
UCHAR Sec;
UINT MinOfDay; // Anzahl Minuten des Tages 0...1439
ULONG SecOfDay;
//UCHAR IsLeap;
//UCHAR aktuell; // 0,1 der der liest kann es auf 0 setzen
// und sieht dann wanns wieder aktuell
};
extern struct T_globTime GlobTime;
extern UCHAR main_getWakeEvent(void);
struct T_out // für alle Levels
{
UINT WrCmd; // was soll gemacht/gesetzt werden
UINT address; // z.B. bei Datenspeicher. Binär.
UCHAR datLen; // Anzahl nachfolgender Datenbytes
UCHAR inBuf[MAX_DATA_FROM_MASTER]; // kam so vom Master rein, soll ausgegeben werden
};
struct T_in // für alle Levels
{
UINT RdCmd; // was soll gemacht/gesetzt werden
UINT address; // z.B. bei Datenspeicher. Binär.
};
struct T_serial
{
// basic machine settings ("DIP-Switches")
// to be stored in eeprom
UCHAR crcCheckOn; // 1,0
UCHAR baudRate; // 1...8
UCHAR parity; // 'E' 'O' 'N'
//UCHAR myAddr; // not needed
//UCHAR NowTestmode; // 1=on
UCHAR dataBits; // 8
UCHAR stopBits; // 1
UCHAR pad6;
};
struct T_devices
{
// set by master, used(1) or notused (0) or type 2....20
// to be stored in eeprom
UCHAR kindOfPrinter; // 0:off 1:Gebe
UCHAR kindOfCoinChecker; // 0: without 1=EMP820 2=EMP900 3=currenza c² (MW)
UCHAR kindOfMifareReader; // by now only stronglink SL025 =1
UCHAR suppressSleepMode; // 0:sleep allowed 1: no sleep
UCHAR kindOfModem; // 0:off 1:Sunlink
UCHAR kindOfCreditcard; // 0:off 1:Feig NFC
UCHAR CoinEscrow;
UCHAR CoinRejectUnit;
UCHAR CoinShutter;
UCHAR BillAcceptor;
UCHAR usevaultLock;
UCHAR autoAlarm; // 1: switch on siren for 1min in doors opened unauthorized
UCHAR autoOpen; // 1: open door covers after valid ATBcard
UCHAR printAccReceipt; // 0/1
UCHAR printDoorReceipt;
UCHAR printTokenTicket;
UINT VaultFullWarnLevel;
UINT VaultFullErrorLevel;
};
/*
struct T_cashAccept // 1.version des cash.json files
{
// Values come from Json File
UINT coinsToAccept; // bit 15...0, je 1=accept 0=do not
UCHAR billsToAccept; // bit 7...0, je 1=accept 0=do not
UCHAR tokenChannel;
ULONG exchgRate; // Multiplikator local -->foreign currency
// eg: hungary: 380 (380Ft = 1EUR)
UINT foreignCoinValue[8];
UINT localCoinValues[8]; // read from coin checker
}; */
struct T_cashAccept
{
// all Values come from Json File
// struct will be stored in eeprom. respect 4byte-borders
UINT CoinDenomination[16]; // 15...8 =foreign coins 7..0 =local coins
UINT CoinValues[16]; // 15...8 =foreign coins 7..0 =local coins
// bei der lokalen Landeswährung wird der Wert eines Geldstückes
// direkt verwendet, da steht genau das gleiche drin wie in "Denom"
// Die ausländischen Münzen werden hier umgerechnet, z.B. 100cent=378Huf
//char Coins2Accept[16];
// kommt jetzt direkt aus Json und ersetzt:
UINT coinAcceptance; // bit 15...0, je 1=accept 0=do not
ULONG exchgRate; // Multiplikator local -->foreign currency
// eg: hungary: 380 (380Ft = 1EUR)
UCHAR tokenChannel; // 0=off, oder 1..16
UCHAR res1;
UCHAR res2;
UCHAR res3;
UINT billValues[8];
//UCHAR localTaxRate;
//UCHAR foreignTaxRate;
//UINT surcharge;
//UINT discount;
//UINT res4;
//UINT res5;
};
struct T_machID
{
// liegen im int. eeprom
// to be stored in eeprom
UINT customerNumber;
UINT machineNumber;
UINT borough; // =group
UINT zone;
UINT alias; // for example another machine number for customer
UINT firstrun;
UCHAR location[32];
};
struct T_moduleCondition
{
// store conditon of all system components, hold in RAM
// 0 means unknown, not yet tested/used
// 1 means OK
// 50..99 = HINT / Notification
// 100..150 = WARNING
// 200..250 = ERROR
UCHAR structStart; // always first!!!
UCHAR ram; // v
UCHAR intEe; // v
UCHAR extEe; // v
UCHAR rtc; // 1: time/date OK 100: time not plausible 200: hardware error
UCHAR boardHw; // v
UCHAR printer; // v
UCHAR modem; // v
UCHAR signal; // 1...99
UCHAR regist; // 100:not 1:reg 2:ping OK 3:gotTime
UCHAR mdbBus;
UCHAR coinChecker; // EMP, OMP or mei-cashflow
UCHAR coinEscrow; // v
UCHAR mifareReader; // v
UCHAR creditTerm; // not available
UCHAR coinReject; // v
UCHAR coinSafe; // v
UCHAR billSafe; // v
UCHAR voltage; // v // 1:11..14V
UCHAR temper; // v
UCHAR poweronTest;
UCHAR doorState; // 1: alles zu 200: tür offen + bit1(S) +bit2(CB) + bit3(CB)
UCHAR doorWasOpened; // 1: all doors are closed 200: any door was just opened
UCHAR changer; // can only be tested by usage
UCHAR coinBlocker; // can only be tested by usage
UCHAR billReader; // can only be tested by usage
UCHAR ResetReason;
UCHAR allModulesChecked;
UCHAR alarmState;
UCHAR res11;
UCHAR res12;
UCHAR res13;
};
struct T_dynamicCondition
{
// dynamic conditions, change rapidly and frequently
// these are values for the Heartbeat
// Türschalter entprellt:
char upperDoor; // 0:fehlt 1:drin
char middleDoor;
char lowerDoor;
char coinBox;
char billBox;
char modeAbrech;
char onAlarm;
char nowCardTest;
char nowPayment;
char lastMifCardType;
char openedAuthorized;
char allDoorsDebounced;
UCHAR lastSDoorState;
UCHAR lastVDoorState;
UCHAR CBinDebounced;
UCHAR lastCBstate;
char paymentInProgress;
char res1;
char res2;
char res3;
UINT U_Batt;
UINT Temperatur;
UINT cash_storedaccNumbers[8]; // List all stored accounting numbers in ext. eeprom
UINT nrCoinsInBox;
UINT resui1;
ULONG amountInBox;
ULONG amountJustPaid;
UINT lastInsCoinType; // wahrscheinlich uchar
UINT resui2;
ULONG totalTransVolume;
ULONG totalNrOfVends;
};
#endif

1386
include/hwapi.h Normal file

File diff suppressed because it is too large Load Diff

1683
include/interfaces.h Executable file

File diff suppressed because it is too large Load Diff

6
include/plugin.h Executable file
View File

@ -0,0 +1,6 @@
#ifndef PLUGIN_H
#define PLUGIN_H
//#include "../plugins/interfaces.h"
#include "../MasterPlug/interfaces.h"
#endif

134
include/prot.h Normal file
View File

@ -0,0 +1,134 @@
#ifndef SERIAL_FRAME_H
#define SERIAL_FRAME_H
#include <QMainWindow>
#include <QString>
#include <QTimer>
#include "tslib.h"
#include "com.h"
#include "interfaces.h"
/*
get's OUT-data from datif,
get's IN-data from datif
get's send command from datif
makes frame and calls: isSerialFree(), setSendData(),
if not free retrigger datif sending period (normally 500ms or 50ms for direct cmds)
with control-signal: gotReceiveData():
getRecData();
send results to diag window/line
send IN-data to datif
*/
#define FRAME_DATALEN 64
#define FRAME_MAXLEN FRAME_DATALEN+20
#define BL_DATA_LEN 200
#define DATALEN_SEND_FAST 4
#define DATALEN_SEND_LONG 64
#define HEADERLEN_SEND 4
#define TELEGRAMLEN_SEND_FAST 12
#define TELEGRAMLEN_SEND_LONG 70
#define STARTSIGN_SEND_FAST 0x3F
#define STARTSIGN_SEND_LONG 0x3D
#define DATALEN_RECEIVE_FAST 8
#define DATALEN_RECEIVE_LONG 64
#define HEADERLEN_RECEIVE 2
#define TELEGRAMLEN_RECEIVE_FAST 12
#define TELEGRAMLEN_RECEIVE_LONG 68
#define STARTSIGN_RECEIVE_FAST 0x5F
#define STARTSIGN_RECEIVE_LONG 0x5D
class T_prot : public QMainWindow
{
Q_OBJECT
// Dateneingang von Datif:
uint8_t SendDataValid; // bit1: WR OK bit 2: RD OK
uint16_t slaveAddr;
uint16_t WriteCommand;
uint16_t WriteAddr;
uint8_t WrDataLength;
uint8_t ui8OutputData[FRAME_DATALEN];
char chOut_Data[FRAME_DATALEN];
uint8_t kindOfData; // 0: binaries, 1:text
uint16_t ReadCommand;
//uint16_t ReadAddr;
uint16_t reserve;
// Ausgangs-Daten, werden vom Datif geholt:
// nur wenn CommandState und readState OK
uint8_t RecSlaveAddr;
bool INdataValid; // nur true wenn CommandState OK und readState OK
uint16_t readSource; // diese (Eingangs-)Daten stehen im Puffer
uint16_t readAddress; // von dieser Adr wurden die Daten gelesen
//uint8_t lastWakeSrc; // falls der Slave den Master geweckt hat
uint8_t RdDataLength;
uint8_t InputData[FRAME_DATALEN];
// 11.11.2020:
uint8_t BLsendDataLength;
uint8_t ui8BLsendData[BL_DATA_LEN];
uint8_t prot_storeResult;
T_com *mySerialPort;
void startPacking(void);
void startFastPacking(void);
uint8_t FramecheckInData(uint8_t *Inbuf, uint16_t LL);
uint8_t FastCheckInData(uint8_t *Inbuf, uint16_t LL);
uint8_t CheckInResult(uint8_t *Inbuf);
uint8_t ShowFastInData(uint8_t *recBuffer);
uint8_t ShowInData(uint8_t *recBuffer); // was CheckInData
void setRecLen(uint16_t WriteCmd);
private slots:
void analyseRecData(void);
public:
T_prot();
bool isPortOpen(void);
bool isSerialFree(void);
void setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data);
void setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr);
void setUserWriteData(uint16_t WriteCmd);
void setUserWriteText(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, char *data);
void setUserWrite1DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val);
void setUserWrite2DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val0, uint8_t val1);
void setUserReadData( uint16_t ReadCmd);
void setBLsendData( uint8_t len, uint8_t *buf);
void receiveFixLen(int64_t nrOfbytesToReceive);
void sendUserData(uint16_t slaveAdr);
uint8_t ifDataReceived();
// return: 0xFF: result unknown 0=OK
// 1= wrong length 2=wrong start sign 5= wrong crc
// 6= slave: master cmd was wrong 7: slave: could not write/read data
bool getReceivedInData(uint8_t *SlavAddr, uint16_t *readSrc, uint16_t *readAddr,
uint8_t *RdDlen, uint8_t *receivedData);
// retval: data valid, only one time true
signals:
void framerecieved(); //bool gotINdata);
void rawDataRecieved();
};
#endif // T_prot_H

86
include/runProc.h Executable file
View File

@ -0,0 +1,86 @@
#ifndef RUN_PROCESS_H
#define RUN_PROCESS_H
#include <QMainWindow>
#include <QString>
#include <QTimer>
#include "tslib.h"
#include "com.h"
#include "interfaces.h"
#include <QtPlugin>
#include <QObject>
#include <QDebug>
#include "datIf.h"
#include <QSharedMemory>
#include "sendWRcmd.h"
#include "controlBus.h"
#include "storeINdata.h"
#include "dcBL.h"
#include "shared_mem_buffer.h"
class T_runProc : public QObject
{
Q_OBJECT
QTimer *hwapi_TimerPayment, *hwapi_triggerBL;
void sub_emp_getAllParameters(struct T_emp *emp);
void changer_getAllParameters(struct T_changer *mw);
void sub_getDynMachineConditions(struct T_dynamicCondition *dynMachCond);
void restoreDeviceParameter(struct T_devices *deviceSettings);
private slots:
void runProc_slotProcess(void);
bool bl_performComplStart(void);
public:
T_runProc();
bool cash_startPayment(uint32_t amount);
uint8_t cash_paymentProcessing(void);
uint8_t epi_store64BdevParameter(uint8_t length, uint8_t *buf);
uint8_t epi_restore64BdevParameter(uint8_t *length, uint8_t *buf);
bool doors_supervise(void);
uint8_t prn_getHwState(struct Tprn_hw_state *prn_hw_state);
void bl_completeStart(void);
void dc_autoRequest(bool on);
void bl_rebootDC(void);
void bl_startBL(void);
void bl_checkBL(void);
bool bl_isUp(void);
signals:
//void runProc_templatePrintFinished_OK(void) const override;
//void runProc_templatePrintFinished_Err(void) const override;
void runProc_coinCollectionJustStarted(void);
void runProc_coinCollectionAborted(void);
void runProc_gotNewCoin(void);
void runProc_payStopByMax(void);
void runProc_payStopByPushbutton(void);
void runProc_payStopByEscrow(void);
void runProc_payStopByError(void);
void runProc_payStopByTimeout(void);
void runProc_payCancelled(void);
void runProc_coinProcessJustStopped(void);
void runProc_doorServiceDoorOpened(void);
void runProc_doorVaultDoorOpened(void);
void runProc_doorCoinBoxRemoved(void);
void runProc_doorCoinBoxInserted(void);
void runProc_doorCBinAndAllDoorsClosed(void);
void runProc_doorAllDoorsClosed(void);
};
#endif

262
include/sendWRcmd.h Normal file
View File

@ -0,0 +1,262 @@
#ifndef SENDWRCMDS_DEFS_H
#define SENDWRCMDS_DEFS_H
#include "tslib.h"
#include <QString>
// asynch. Commands
// store OUTPUT commands until time to send
// problem: OUT commands are set if a button is pressed or a transaction event happens
// so it's never synchron with sending grid
// but sending must apply the 100ms time grid as we have to wait for the response before sending the next command!!!
// aug2023: used with setSendCommand0
//#define SENDDIRCMD_TestSerial 1
//#define SENDDIRCMD_MakeReset 2
//#define SENDDIRCMD_setTime 3
//#define SENDDIRCMD_setWakeFrequ 4
//#define SENDDIRCMD_MOVEUP_LOCK 5
//#define SENDDIRCMD_MOVEDN_LOCK 6
//#define SENDDIRCMD_OPENUP_DOOR 7
//#define SENDDIRCMD_OPENDN_DOOR 8
//#define SENDDIRCMD_LEDILLU 9
//#define SENDDIRCMD_LEDCOIN 10
//#define SENDDIRCMD_LEDTICKET 11
//#define SENDDIRCMD_LEDPAD 12
//#define SENDDIRCMD_LEDSTART 13
//#define SENDDIRCMD_LEDINSIDE 14
//#define SENDDIRCMD_LED_ALL 15
//#define SENDDIRCMD_FAN 16
//#define SENDDIRCMD_LAERM 17
//#define SENDDIRCMD_REL1 18
//#define SENDDIRCMD_WAKEPTU 20
//#define SENDDIRCMD_AUXPWR 21
//#define SENDDIRCMD_AUXDDR 22
//#define SENDDIRCMD_AUXOUT 23
//#define SENDDIRCMD_UCONTACT_ON 30
//#define SENDDIRCMD_PRN2_SWONOFF 31
//#define SENDDIRCMD_MIF_SWONOFF 32
//#define SENDDIRCMD_MIF_ATBCREATE 33
//#define SENDDIRCMD_MOD_SWONOFF 40
//#define SENDDIRCMD_MOD_WAKE 41
//#define SENDDIRCMD_MDB_POWER 42
//#define SENDDIRCMD_MDB_WAKE 43
//#define SENDDIRCMD_CRED_ON 44
//#define SENDDIRCMD_CRED_WAKE 45
//#define SENDDIRCMD_SHUT_MOV 50
//#define SENDDIRCMD_ESCRO_MOV 51
//#define SENDDIR_OPENVAULT 52
//#define SENDDIR_REJMOT_ON 53
//#define SENDDIR_REJMOT_RUN 54
// Level 2 (serial from DC to devices)
//#define SEND_REQU_SERCONF 100
//#define SEND_REQU_HWversion 101
//#define SEND_REQU_SWversion 102
//#define SEND_REQU_CONDITION 103
//#define SEND_REQU_UID 104
//#define SEND_REQU_TIME 105
// includes wake frequency
//#define SEND_REQU_ANALOGS 110
//#define SEND_REQU_DIG_INPUTS 111
//#define SEND_REQU_DIG_OUTPUTS 112
//#define SEND_REQU_PRN_STATE 120
//#define SEND_REQU_PRN_FONTS 121
//#define SEND_REQU_PRN_ALL 122
//#define SEND_REQU_MIFSTATE 123
// Type and state of reader
//#define SEND_REQU_MIFDATA 124
// Type, UID, Header of card
// read one card sector
// sectors must be addressed by RD_ADD
//#define SEND_REQU_MIF_ATB_TYPE 125
//#define SEND_REQU_MDB_GETSTAT 126
//#define SEND_REQU_MDB_GETWAK 127
//#define SEND_REQU_MDB_GETRESP 128
//#define SEND_REQU_EMP_GETALL 129
//#define SEND_REQU_EMP_GETCOIN 130
//#define SENDDIRCMD_DEVICE_PARA 131
//#define SENDDIRCMD_MACHINE_ID 132
//#define SEND_REQU_DEVICE_PARA 133
//#define SEND_REQU_MACINE_ID 134
// TODO:
//#define SENDDIRCMD_PRN_SETUP 72
//#define SENDDIRCMD_MDB_SNDMSG 92
//#define SENDDIRCMD_EMP_SETT 93
//#define SENDDIRCMD_PRN_BC 80
// further: mdb state, coinchecker state, bill state, modem state, credit_state....
/*
#define SENDDIRCMD_SHUTOPENBYTIME 60
#define SENDDIRCMD_SHUTOPENBYCOIN 61
//#define SENDDIRCMD_SHUT_SENDTIME 62
#define SENDDIRCMD_ESCRO_TAKE 63
#define SENDDIRCMD_ESCRO_GIVE 64
#define SENDDIRCMD_PRN_SYS_CMD 70
#define SENDDIRCMD_PRN_ESC_CMD 71
#define SENDDIRCMD_PRN_MOVE 73
#define SENDDIRCMD_PRN_SETFONT 74
#define SENDDIRCMD_PRN_SETLETT 75
#define SENDDIRCMD_PRN_CUT 76
//#define SENDDIRCMD_PRN_TXT // not needed
#define SENDDIRCMD_PRN_LF 78
#define SENDDIRCMD_PRN_FONTTAB 79
#define SENDDIRCMD_PRN_QR 81
#define SENDDIRCMD_PRN_STOREDQR 82
#define SENDDIRCMD_PRN_LOGO_FL 83
//#define SENDDIRCMD_PRN_LOGO_GRAF 84
//#define SENDDIRCMD_PRN_LOGODAT 85
//#define SENDDIRCMD_PRN_STORBC 86
#define SENDDIRCMD_PRN_STORQR 87
#define SENDDIRCMD_PRN_DOC 88
#define SENDDIRCMD_PRN_CLEARDOC 89
//#define SENDDIRCMD_MDB_POWER 42
//#define SENDDIRCMD_MDB_WAKE 43
#define SENDDIRCMD_MDB_RES 90
#define SENDDIRCMD_MDB_SENDCMD 91
#define SENDDIRCMD_EMP_POLL 94
#define SENDDIRCMD_EMP_STARPPAY 95
#define SENDDIRCMD_EMP_STOPPAY 96
*/
// obsolete:
/*
#define SENDDIRCMD_PRN1_SENDTEXT 54
#define SENDDIRCMD_PRN1_SENDCMD 55
#define SENDDIRCMD_PRN1_SERPAR 56
#define SENDDIRCMD_PRN_LEVEL2_4B 58
#define SENDDIRCMD_PRN_LEVEL2_64 59
*/
// highest priority
//#define CMDSTACKDEPTH 16
// means: up to 16 cmd can be stored. They are issued one by one every 100ms
//void sendWRcmd_clrCmdStack(void);
//bool sendWRcmd_setSendCommand0(uint16_t nextCmd);
// GUI or app sends a command to DC transfered by serial
//uint16_t sendWRcmd_getSendCommand0(void);
// lower priority
//#define CMD4STACKDEPTH 8
//void sendWRcmd_clrCmd4Stack(void);
//bool sendWRcmd_setSendCommand4(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4);
//uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4);
//#define CMD8STACKDEPTH 4
//void sendWRcmd_clrCmd8Stack(void);
//bool sendWRcmd_setSendCommand8(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint16_t dat3, uint32_t dat4);
//uint16_t sendWRcmd_getSendCommand8(uint8_t *dat1, uint8_t *dat2, uint16_t *dat3, uint32_t *dat4);
// lowest priority
// wait for resonse before send next!
bool sendWRcmd_setSendBlock160(uint8_t leng, uint8_t *buf);
uint8_t sendWRcmd_getSendBlock160(uint8_t *leng, uint8_t *buf);
// retval = *leng
void sendWRcmd_INI(void);
//uint8_t epi_store64ByteSendData(uint8_t length, uint8_t *buf);
// HWapi writes data to be forwarded to DC and further to mdb-device
// not batched! don't use twice within 100ms
//uint8_t gpi_restore64ByteSendData(uint8_t *length, uint8_t *buf);
// datif reads data to forward to dc
// ONE printer doc consists of 20 x 64 byte
//#define MAXNROF_PRNBYTES 64
//#define MAXNROF_PRNBLOCKS 20
/*
void epi_resetPrinterStack(void);
uint8_t epi_storePrnText(char *buf, uint8_t leng);
// store text and binary data from Gui in next higher free memory 0....9
uint8_t gpi_restorePrnText(uint8_t *retbuf);
// read printer text and send to slave, size of retbuf== 64
uint8_t gpi_chk4remainingText(void);
// retval: 0: no more textline left (to send) >0: nr of lines
*/
//void epi_storeUserOfSendingTextBuffer(uint8_t user, uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4 );
// user=1: Text-Print is using this buffer
// 2: QR-code-Printer is using this buffer
//uint8_t gpi_getUserOfSendingTextBuffer(uint8_t *para1, uint8_t *para2, uint8_t *para3, uint8_t *para4);
// user=1: Text-Print is using this buffer
// 2: QR-code-Printer is using this buffer
// #define FDCMD_STACKDEPTH 16 / 32
// short and long commands are queued into the same stack to guaranty right order
void sendFDcmd_clrStack(void);
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
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 check4usedFDstack(void);
// returns number of waiting command, maxFDCMD_STACKDEPTH
uint8_t checkNextFDcmd(void);
// return 0: no command waiting
// 1: short cmd
// 2: long cmd
uint8_t check4freeFDstack(void);
// returns number of free places in FD-command stack
bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t length, uint8_t *data);
bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t length, QByteArray *data);
// write Command to memory, wait for transport
// data buffer size always 64! data[64], padded with 0
bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data);
#endif

351
include/shared_mem_buffer.h Normal file
View File

@ -0,0 +1,351 @@
#ifndef SHARED_MEM_BUFFER_INCLUDED_H
#define SHARED_MEM_BUFFER_INCLUDED_H
#include <cinttypes>
#include <atomic>
#include <QSharedMemory>
#include <QtGlobal>
bool shdMem_firstUse(void);
// Vorsicht: im shared memory ist kein QString erlaubt!!!!!!!!!!!!!!!!!!!!!!
// nur standard C Typen!!!!!!
// also auch kein QByteArray o.ä.
// Vorsicht: Zugriffe auf Comport NICHT ins shared mem --> Absturz!!!!
struct SharedMem
{
// ------------------ Comport Control --------------------------------
bool rs_portIsOpen;
bool AutoEmissionOn;
bool Sdata_serialTestResult;
uint8_t Sdata_pProtResultOk;
uint16_t Sdata_receivedDataLength;
uint8_t Sdata_receivedDataBlock[64];
uint8_t ndbs, pari, nsb, br;
uint8_t Sdata_lastResult;
uint8_t Sdata_OverallResult;
bool Sdata_startSV;
// ------------------ Data INPUT --------------------------------
bool indat_savePrnPwr;
bool indat_saveMifPwr;
bool indat_MdbIsOn;
//QString indat_HWversion;
//QString indat_SWversion;
//QString indat_DCstate;
#define versionBufferLen 32
char indat_HWversion[versionBufferLen];
char indat_SWversion[versionBufferLen];
char indat_DCstate[versionBufferLen];
struct Sdata
{
uint64_t slaveUID;
uint8_t UIDstr[8];
} Sdata;
struct T_globTime
{
// Reihenfolge nicht vertauschen!!!!!
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t Year;
uint8_t Month;
uint8_t DayOfMonth;
uint8_t DayOfWeek; // 1=monday...7
uint8_t reserve1;
uint16_t MinutesOfToday;
uint16_t reserve2;
uint32_t SecondsOfToday;
uint8_t IsLeapyear;
uint8_t nextLeap;
uint8_t lastLeap;
uint8_t hoursOfWeek;
uint16_t minOfWeek;
uint16_t hoursOfMonth;
uint16_t minOfMonth;
uint16_t dayOfYear;
uint16_t hoursOfYear;
uint16_t reserve3;
uint32_t minOfYear;
uint8_t squareOutMode;
uint8_t free1;
uint16_t reserve4;
uint32_t minOfMillenium;
// bis hierher 44byts
uint32_t free2;
uint32_t free3;
uint32_t free4;
} getGlobalTime;
#define MAXNROF_AI 4
uint16_t AI_val[MAXNROF_AI];
#define MAXNROF_MEASURE 4
uint32_t Sdata_measurement[MAXNROF_MEASURE];
uint8_t di_doorSwitch;
uint8_t di_vaultSwitch;
uint8_t di_lockSwitch;
uint8_t di_opto;
uint8_t di_aux;
bool di_wakeFromPtu;
bool di_wakeFromMdb;
bool di_PrnReady;
bool di_CoinAttach;
bool di_CoinEscrowOpen;
bool di_mifCardTap;
bool di_wakeFromModem;
bool di_contactPwrOn;
bool di_mifarePwrOn;
bool di_rdbk_mdbTxd;
bool di_AuxPwrOn;
bool di_gsmPwrOn;
bool di_creditPwrOn;
bool di_printerPwrOn;
bool di_mdbPwrOn;
bool di_rejMot_home;
uint8_t di_npe_sensor;
uint8_t do_mbdRxTst;
uint8_t do_motorBits;
uint8_t do_serialSwitch;
uint8_t do_ledsAndFan;
uint8_t do_laermUndRelay;
uint8_t do_ptuWake;
uint8_t do_auxPower;
uint8_t do_coinShutter;
uint8_t do_coinEscrow;
uint8_t do_printerPower;
//#define NROFMIFSTATEBYTES 40
//uint8_t Sdata_MIF_STATE[NROFMIFSTATEBYTES];
uint8_t Sdata_MIF_DATA[64];
//uint8_t mif_cardType;
//uint8_t mif_cardHolder[8];
uint8_t Sdata_MIF_ATB[64];
#define pi_prnStateArraySize 20
uint8_t Sdata_PRN_STATE[pi_prnStateArraySize];
#define pi_prnFontArraySize 20
uint8_t Sdata_PRN_FONTS[pi_prnFontArraySize];
bool Sdata_mdb_busRdy;
bool Sdata_mdb_V12on;
bool Sdata_mdb_V5on;
uint8_t Sdata_mdbNrOfRecData;
uint8_t Sdata_RecBuff[40];
uint8_t Sdata_empNrOfsettings;
uint8_t Sdata_emp_settingsBuff[66];
struct T_coin
{
uint8_t valid;
uint8_t signal;
uint8_t error;
uint8_t pad;
uint16_t value;
};
#define MEMDEPTH_GOTCOINS 16
struct T_coin gotCoin[MEMDEPTH_GOTCOINS];
uint8_t ctr_gotCoin;
uint8_t Sdata_NrOfDeviceSetting;
uint8_t Sdata_DeviceSettingBuff[66];
uint8_t SizeMachineIDBuff;
uint8_t MachineIDBuff[66];
uint32_t store_insertedAmount;
uint16_t store_lastCoinType[64];
uint16_t store_lastCoinValue[64];
uint8_t p_lastCoin;
char store_curPayNewCoin;
uint64_t stor_wakSrc;
uint8_t stor_reason;
uint8_t store_rbDevParamLen;
uint8_t store_rbDevParams[66];
uint8_t store_deviceCondLen;
uint8_t store_deviceCond[66];
uint8_t store_machCondLen;
uint8_t store_machCond[66];
uint8_t store_DcBackupNrOfAccNr;
uint16_t store_DcBackupAccNr[16]; // z.Z. nur 8
#define PI_SIZOFVAULTRECORD 400
uint8_t store_gotNrBlocksOfVaultRec;
uint8_t store_vaultrecord[PI_SIZOFVAULTRECORD];
uint32_t store_amount;
uint16_t store_nrOfCoins;
bool store_DcDataAreValid;
uint8_t storeDCdynPrinterData[64];
uint8_t DCdynPrinterDataActual;
uint16_t store_DCNextAccountNumber;
uint16_t storeMifCardTypDataLen;
uint8_t storeMcardTypData[64];
// new from 6.9.23:
#define RAW_BL_DATALEN 150
uint8_t Sdata_rawData[RAW_BL_DATALEN];
uint8_t Sdata_LengthRawData;
#define numberOfJsons 36
#define versionStringLength 16
char store_jsonVersion[versionStringLength][numberOfJsons];
uint8_t Sdata_changeResult;
uint32_t Sdata_changedAmount;
uint8_t store_tubeLev[64];
// Mitteilung von Hwapi zu Datif:
bool Sdata_coinPaymentNow;
bool Sdata_bootloadingNow;
// ------------------ Data OUTPUT --------------------------------
// sendWRcmd.cpp
#define CMDSTACKDEPTH 16
uint16_t nextAsynchsendCmd0[CMDSTACKDEPTH];
uint8_t nrOfCmdsInQueue;
#define CMD4STACKDEPTH 8
uint16_t nextAsynchsendCmd4[CMD4STACKDEPTH];
uint8_t nextCmd4para1[CMD4STACKDEPTH];
uint8_t nextCmd4para2[CMD4STACKDEPTH];
uint8_t nextCmd4para3[CMD4STACKDEPTH];
uint8_t nextCmd4para4[CMD4STACKDEPTH];
uint8_t nrOfCmds4InQueue;
#define CMD8STACKDEPTH 4
uint16_t nextAsynchsendCmd8[CMD8STACKDEPTH];
uint8_t nextCmd8para1[CMD8STACKDEPTH];
uint8_t nextCmd8para2[CMD8STACKDEPTH];
uint16_t nextCmd8para3[CMD8STACKDEPTH];
uint32_t nextCmd8para4[CMD8STACKDEPTH];
uint8_t nrOfCmds8InQueue;
#define SENDASYDAT_BUFFSIZE 200
uint8_t sendAsynchDataBuf[SENDASYDAT_BUFFSIZE]; // no stack, only ONE buffer
uint8_t sendAsyDatLen;
#define MDBSEND_BUFFSIZE 64
uint8_t Sdata_mdbSendBuffer[MDBSEND_BUFFSIZE];
uint8_t Sdata_mdbSendLen;
uint8_t prnDataParameters[4];
uint8_t prnDataBufferUser;
// ONE printer doc consists of 20 x 64 byte
#define MAXNROF_PRNBYTES 64
#define MAXNROF_PRNBLOCKS 20
char Sdata_PRN_TEXT[MAXNROF_PRNBLOCKS][MAXNROF_PRNBYTES];
uint8_t pPrnDataBuff; // points to next PRINTER_BLOCK
//#define FDCMD_STACKDEPTH 16 // up to 1024 byte
#define FDCMD_STACKDEPTH 32 // up to 2048 byte
// header
uint8_t nextFDwrCmd[FDCMD_STACKDEPTH];
uint8_t nextFDrdCmd[FDCMD_STACKDEPTH];
uint8_t nextFDblkNr[FDCMD_STACKDEPTH];
uint8_t nextFDshort[FDCMD_STACKDEPTH];
// short data
uint8_t nextFDpara1[FDCMD_STACKDEPTH];
uint8_t nextFDpara2[FDCMD_STACKDEPTH];
uint8_t nextFDpara3[FDCMD_STACKDEPTH];
uint8_t nextFDpara4[FDCMD_STACKDEPTH];
// long data:
uint8_t longFDlength[FDCMD_STACKDEPTH];
uint8_t longFDpara[FDCMD_STACKDEPTH][64];
uint8_t p_nextFDcmdsInQueue;
static QSharedMemory *getShm(std::size_t s = 0);
static SharedMem *getData()
{
Q_ASSERT_X(getShm()->data() != nullptr, "pointer access", "nullptr");
return (SharedMem *)getShm()->data();
}
static SharedMem const *getDataConst()
{
Q_ASSERT_X(getShm()->data() != nullptr, "pointer access", "nullptr");
return (SharedMem const *)getShm()->data();
}
// static SharedMemBuffer *write()
static SharedMem *write()
{
Q_ASSERT_X(getShm()->data() != nullptr, "pointer access", "nullptr");
return (SharedMem *)getShm()->data();
}
// static SharedMemBuffer const *read()
static SharedMem const *read()
{
Q_ASSERT_X(getShm()->data() != nullptr, "pointer access", "nullptr");
return (SharedMem const *)getShm()->data();
}
bool thisIsTheFirstUse(void);
#if 0
static std::atomic<bool> __sharedMemLocked;
static bool sharedMemLocked() {
return __sharedMemLocked;
}
static void setSharedMemLocked() {
__sharedMemLocked = true;
}
static void setSharedMemUnlocked() {
__sharedMemLocked = false;
}
#endif
};
#endif // SHARED_MEM_BUFFER_INCLUDED_H

614
include/storeINdata.h Normal file
View File

@ -0,0 +1,614 @@
#ifndef STOREINDATA_H
#define STOREINDATA_H
#include "tslib.h"
#include <QString>
#define MAXNROF_AO 3
#define MAXNROF_GENSTR 16
#define MAXNROF_CONTR_PORTS 11
#define MAXNROF_DIports 2
#define MAXNROF_DOports 2
#define MAXNROF_CTR 2
#define MEASCHAN_TEMPERATURE 0
#define MEASCHAN_VOLTAGE 1
// gpi: DC-driver stores data for graphic peripheral interface
// epi: gui reads values from external peripheral interface
// store power on/off condition of the devices to control the data request
void indat_storePrinterPower(bool isOn);
bool indat_isPrinterOn();
void indat_storeMifarePower(bool isOn);
bool indat_isMifareOn();
void indat_storeMDBisOn(bool isOn);
bool indat_isMdbOn();
void gpi_storeHWver(QString text);
QString epi_loadHWver(void);
void gpi_storeSWver(QString text);
QString epi_loadSWver(void);
void gpi_storeDCstate(QString text);
QString epi_loadDCstate(void);
void gpi_storeUID(uint8_t const *buf8byteUid);
//void gpi_storeUID(uint8_t *buf8byteUid);
// buffer size: 8 byte
void epi_getUIDdec(uint8_t *buf8byteUid);
// buffer size: 8 byte
QString epi_getUIDstr();
// ///////////////////////////////////////////////////////////////////////////////////
// Time and Date
// ///////////////////////////////////////////////////////////////////////////////////
uint8_t epi_getSquareMode();
void gpi_backupSquareMode(uint8_t squMode);
void gpi_backupTime(uint8_t *timeBuffer, uint8_t Leng); // 104, <=8byte
void epi_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss);
void epi_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd);
void epi_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday);
bool epi_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear);
bool epi_isLeapYear();
void epi_getSpecialWeekTimeDate(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek);
void epi_getSpecialMonthTimeDate(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth);
void epi_getSpecialYearTimeDate(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear);
// ///////////////////////////////////////////////////////////////////////////////////
// Analog values
// ///////////////////////////////////////////////////////////////////////////////////
void gpi_storeAIs(uint8_t aiNr, uint16_t val); // rs -> Sdata
uint8_t gpi_getMaxNrAIs();
uint16_t epi_loadAIs(uint8_t aiNr); // Sdata -> gui
// return value of one ADC with channel nr: aiNr 0...15
uint32_t epi_loadMeasureValue(uint8_t ValueNr);
// ValueNr 0=ADC0, 1=ADC1 aso...
void gpi_storeMeasureValue(uint8_t ValueNr, uint32_t val);
// in mV, also bis 65,535V
QString epi_getSlaveTemperatureStr();
QString epi_getSlaveVoltageStr();
// value in "meas_volt" in mV, also bis 65,535V. Value range [6000...16000] (6V...16V)
// ///////////////////////////////////////////////////////////////////////////////////
// digital inputs
// ///////////////////////////////////////////////////////////////////////////////////
void gpi_storeDI_doorSwitches(uint8_t upperDoor, uint8_t lowerDoor, uint8_t vaultDoor);
uint8_t epi_getDI_doorSwitches(void);
// bit0: upper door 1: low door 2:vault door
void gpi_storeDI_vaultSwitches(uint8_t CashBoxIn, uint8_t BillBoxIn);
uint8_t epi_getDI_vaultSwitches(void);
// bit0: cash box 1: bill box in
void gpi_storeDI_lockSwitches(uint8_t indatUL, uint8_t indatLL);
// D5: bit 0: upper lockbar up bit1:down
// D6: bit 0: lower lockbar up bit1:down
uint8_t epi_getDI_lockSwitches(void);
// retval: bit 0: upper lockbar up bit1: upper lockbar is down
// bit 2: lower lockbar up bit1: lower lockbar is down
void gpi_storeDI_optos(uint8_t indatOpto);
// OptoIn bit 0,1: optoin 1,2
uint8_t epi_getDI_optos(void);
// bit0: opto in 1 1: opto in 2
void gpi_storeDI_auxIn(uint8_t indatAuxIn);
// Aux0...5
uint8_t epi_getDI_auxIn(void);
// bit0: auxin 1 ... 5: auxin 6
void gpi_storeDI_ptuWake(uint8_t indat);
bool epi_getDI_ptuWake(void);
void gpi_storeDI_mbdWake(uint8_t indat);
bool epi_getDI_mdbWake(void);
void gpi_storeDI_prnReady(uint8_t indat);
bool epi_getDI_prnReady(void);
void gpi_storeDI_CoinAttach(uint8_t indat);
bool epi_getDI_CoinAttach(void);
void gpi_storeDI_CoinEscrow(uint8_t indat);
bool epi_getDI_CoinEscrow(void);
void gpi_storeDI_mifareCardTapped(uint8_t indat);
bool epi_getDI_mifareCardTapped(void);
void gpi_storeDI_modemWake(uint8_t indat);
bool epi_getDI_modemWake(void);
void gpi_storeDI_contactPowerIsOn(bool di_contact_PwrOn);
bool epi_getDI_contactPwr(void);
void gpi_storeDI_MifarePowerIsOn(bool di_mifare_PwrOn);
bool epi_getDI_mifarePwr(void);
void gpi_storeDI_readbackMdbTxD(bool di_rdbkMdbTxd);
bool epi_getDI_mdbTxd(void);
void gpi_storeDI_AuxPowerIsOn(bool di_Aux_PwrOn);
bool epi_getDI_auxPwr(void);
void gpi_storeDI_GsmPowerIsOn(bool di_gsm_PwrOn);
bool epi_getDI_gsmPwr(void);
void gpi_storeDI_CreditPowerIsOn(bool di_credit_PwrOn);
bool epi_getDI_creditPwr(void);
void gpi_storeDI_PrinterPowerIsOn(bool di_printer_PwrOn);
bool epi_getDI_printerPwr(void);
void gpi_storeDI_MdbPowerIsOn(bool di_mdb_PwrOn);
bool epi_getDI_mdbPwr(void);
void gpi_storeDI_rejMot_home(bool di);
bool epi_getDI_rejectMotor_homepos(void);
void gpi_storeDI_paperLow(uint8_t di);
uint8_t epi_getDI_npe_sensor(void);
// 0: Sensor sees paper 1: no paper 99: off
// ///////////////////////////////////////////////////////////////////////////////////
// readback digital outputs
// ///////////////////////////////////////////////////////////////////////////////////
void gpi_storeDO_mdbRxTst(uint8_t do_mbdRxTst);
bool epi_getDO_mdbRxTestOut(void);
void gpi_storeDO_motorOutputs(uint8_t Pwr);
uint8_t epi_getDO_motorOuts(void);
// bit0: upper lock forward bit 1 backward
// bit2: lower lock forward bit 3 backward
void gpi_storeDO_serialSwitch(uint8_t state);
// serial drv on/off, Serial mux1, Serial mux2
uint8_t epi_getDO_serialSwitch(void);
// serial drv on/off, Serial mux1, Serial mux2
bool epi_getDO_serialDriverIsOn(void);
bool epi_getDO_serialMux1isSetToPrinter(void);
// mux1 off: serial is switched to printer
bool epi_getDO_serialMux1isSetToModem(void);
// mux1 on: serial is switched to modem
bool epi_getDO_serialMux2isSetToCredit(void);
// mux2 off: serial is switched to credit card terminal
bool epi_getDO_serialMux2isSetToMifare(void);
// mux2 on: serial is switched to mifare reader
void gpi_storeDO_ledsAndFan(uint8_t ledState);
bool epi_getDO_led_coin(void);
bool epi_getDO_led_front(void);
bool epi_getDO_led_ticket(void);
bool epi_getDO_led_pin(void);
bool epi_getDO_led_start(void);
bool epi_getDO_led_inside(void);
bool epi_getDO_fan(void);
void gpi_storeDO_sirenAndRelay(uint8_t sirenRelay);
bool epi_getDO_sirene(void);
bool epi_getDO_relay(void);
void gpi_storeDO_ptuWake(uint8_t state);
bool epi_getDO_ptuWake(void);
void gpi_storeDO_auxPower(uint8_t pwr);
bool epi_getDO_auxPower(void);
void gpi_storeDO_coinShutter(uint8_t state);
bool epi_getDO_coinShutterOpen(void);
bool epi_getDO_coinShutterTest(void);
void gpi_storeDO_coinEscrow(uint8_t state);
uint8_t epi_getDO_coinEscrow(void);
// retval: 1:return flap is open 2:take flap is open 0:closed
void gpi_storeDO_printerPwrOn(uint8_t state);
uint8_t epi_getDO_printerPwr(void);
// ---------------------------------------------------------------------------------------------
// counterchecks, make sure that DC-outputs are correct
/*
bool epi_cntchk_wakePtu(void);
bool epi_cntchk_enabDrv01(void); // no communication possible if 0 !!!!!
bool epi_cntchk_swRs1toModem(void);
bool epi_cntchk_modemWake(void);
bool epi_cntchk_enabDrv2(void);
bool epi_cntchk_swRs2toMIF(void);
bool epi_cntchk_shutterIsOpen(void);
// counter check if shutter is really open, PJ4 must be OUT and HIGH, PB5 must be OUT and HIGH
// retval TRUE: shutter is open FALSE: shutter is closed
bool epi_cntchk_escrowReturnIsOpen(void);
bool epi_cntchk_escrowTakeIsOpen(void);
bool epi_cntchk_aux1DirOut(uint8_t auxNr);
bool epi_cntchk_aux1OutHigh(uint8_t auxNr);
bool epi_cntchk_ledPaperOn(void);
bool epi_cntchk_ledPinpadOn(void);
bool epi_cntchk_ledStartOn(void);
bool epi_cntchk_ledServiceOn(void);
bool epi_cntchk_ledCoinOn(void);
bool epi_cntchk_ledIllumOn(void);
bool epi_cntchk_FanOn(void);
bool epi_cntchk_RelaisOn(void);
bool epi_cntchk_LaermOn(void);
bool epi_cntchk_Mot1Ron(void);
bool epi_cntchk_Mot1Fon(void);
bool epi_cntchk_Mot2Ron(void);
bool epi_cntchk_Mot2Fon(void);
*/
// ------------------------------------------------------------------------------------
// MDB Sendind Data are store here for next transport to DC (Device Controller)
// Transport to Slave runs every 100ms, answer from mdb-slave (e.g. coin changer) comes right
// with next slave answer
// start with: SENDDIRCMD_EXCHGMDB,
// send crude data from here to DC, DC to mdb slaves, mdb answer, return here within 50ms
uint8_t gpi_storeMdbRecData(uint8_t length, uint8_t *buf);
// datif store received mdb data
uint8_t epi_getMdbResponse(void);
// 0=no response 1=ACK 2=NAK 3=ACK with data
uint8_t epi_getMdbRecLength(void);
// 0...31
uint8_t epi_restoreMdbRecData(uint8_t *buf);
// hwapi reads received mdb data from PI
void gpi_clearMifHwData(void);
void gpi_storeMifHwData(uint8_t *receivedData);
// blkNr=0...11 receivedData[64]
uint8_t epi_restoreMifHwData(uint8_t *buf, uint8_t maxBufferSize);
// blkNr=0...11 return buf[64]
// retval: 1=error 0=OK
void gpi_clearMifAtbData(void);
void gpi_storeMifAtbData(uint8_t *receivedData);
uint8_t epi_restoreMifAtbData( uint8_t *buf, uint8_t maxBufferSize);
void epi_restorePrinterState(uint8_t *buf);
void gpi_storePrinterState(uint8_t *buf);
void epi_restorePrinterFonts(uint8_t *buf);
void gpi_storePrinterFonts(uint8_t *buf);
void gpi_storeMdbState(uint8_t busReady, uint8_t V12on, uint8_t V5on );
bool epi_restoreMdbBusReady(void);
bool epi_restoreMdbV12Ready(void);
bool epi_restoreMdbV5Ready(void);
void gpi_storeMdbResponse(uint8_t leng, uint8_t *data);
void epi_restoreMdbResponse(uint8_t *leng, uint8_t *data);
// last received mdb answer (from mdb device)
// only needed if a special command was sent directly
// DB0: mdb Device-Nr
// DB1: last sent mdb command
// DB2: nr of received (payload) data bytes (apart from ACK, can be 0....34)
// DB3...DB38: rec.data (payload)
void gpi_storeEmpSettings(uint8_t leng, uint8_t *data);
void epi_restoreEmpSettings(uint8_t *leng, uint8_t *data);
/*
void gpi_storeEmpCoinSignal(uint8_t leng, uint8_t *data);
void epi_restoreEmpCoinSignal(uint8_t *leng, uint8_t *data);
// return 5 byte:
// data[0]=got coin 0xFF=emp reported an error 0=got nothing
// data[1]=emp-signal of last inserted coin
// data[2,3]=emp-value of last inserted coin
// data[4] = emp-error or warning
void epi_clearEmpCoinSignal();
*/
void gpi_storeEmpCoinSignal(uint8_t leng, uint8_t *data);
uint8_t epi_isNewCoinLeft(void);
// retval: 0...16 coins left in FIFO
void epi_restoreEmpCoinSignal(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value);
void gpi_storeRbDeviceSettings(uint8_t leng, uint8_t *data);
void epi_restoreRbDeviceSettings(uint8_t *leng, uint8_t *data);
void gpi_storeMachineIDsettings(uint8_t leng, uint8_t *data);
void epi_restoreMachineIDsettings(uint8_t *leng, uint8_t *data);
void epi_clearCurrentPayment(void);
void gpi_storeCurrentPayment(uint32_t insertedAmount, uint16_t lastCoinType, uint16_t lastCoinValue);
uint32_t epi_CurrentPaymentGetAmount(void);
uint16_t epi_CurrentPaymentGetLastCoin(void);
bool epi_CurrentPaymentGetAllCoins(uint16_t *types, uint16_t *values);
// alle bei diesem Verkauf eingeworfenen Münzen sind gespeichert falls die jmd. braucht
void gpi_storeWakeSources(uint8_t *receivedData);
uint64_t epi_getWakeSources(void);
uint8_t epi_getWakeReason(void);
void gpi_storeExtendedTime(uint8_t leng, uint8_t *data);
void epi_restoreExtendedTime(uint8_t *leng, uint8_t *data);
void epi_clearDeviceConditions(void);
void gpi_storeDeviceConditions(uint8_t leng, uint8_t *data);
void epi_restoreDeviceConditions(uint8_t *leng, uint8_t *data);
void epi_clearDynMachineConditions(void); // new, 24.6.23
void gpi_storeDynMachineConditions(uint8_t leng, uint8_t *data);
void epi_restoreDynMachineConditions(uint8_t *leng, uint8_t *data);
void gpi_storeDCbackupAccNr(uint8_t leng, uint8_t *data);
void epi_restoreDCbackupAccNr(uint8_t *leng, uint16_t *accNrs);
// return accNrs[0..7]
void epi_iniVRstorage(void);
void gpi_storeVaultRecord(uint8_t blkNr, uint8_t *data );
bool epi_checkIfVaultRecordAvailable(void);
uint8_t epi_getLoadedVaultBlocks(void);
// return 0x0011 1111 if all 6 blocks arer loaded (one bit per block)
bool epi_restoreVaultRecord(uint16_t *length, uint8_t *buf );
// true if completly received
void gpi_storeCBlevel(uint32_t amount, uint16_t nrOfCoins );
uint32_t epi_getCashBoxContent(void);
uint16_t epi_getNrOfCoinsInCashBox(void);
//void gpi_storeNewMifareCard(uint8_t typ, uint8_t *holder );
uint8_t epi_mifGetCardType(uint8_t *holder);
//holder[8] = name of card holder
// retval Type of MifareCard, 1=upper door, 2=lower door 3=test printer 4=test coins
void gpi_storeDcDataValid(bool isVal);
bool epi_areDcDataValid();
void epi_clearDynData(void);
void gpi_storeDynData(uint8_t *DCdynDat);
// buffer size: 64 byte
bool epi_getDynPrnData(uint8_t *DCdynDat);
// buffer size: 64 byte
// return true if data are new and valid
void gpi_storeNextDCaccNr(uint16_t nxtDcAccNr);
uint16_t epi_getNextDCaccNr(void );
void gpi_storeMifCardType(uint16_t length, uint8_t *data);
void epi_restoreMifCardType(uint16_t *length, uint8_t *data);
// move here from dcBL and use shared mem as ptu-updater uses CAslave Lib 6.9.23TS
//#define RAW_BL_DATALEN 150
void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData);
uint8_t epi_getRawReceivedData(uint8_t *receivedData);
// retval=length, will be zeroed after first reading
uint8_t epi_getRawRecLength(void);
// retval=length
//QString epi_getRawReceivedString();
// not used
void epi_clrRawReceivedString();
// new from 28.9.23 and earliest from DC version 4.45
// store all versions of the DC-Jsons
//#define numberOfJsons 36
//#define versionStringLength 16
//char store_jsonVersion[versionStringLength][numberOfJsons];
void gpi_storeJsonVersion(uint8_t jsonNr, uint8_t *versionString);
// jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res.
// 5=printer template 1 ..... 36= template 32
// length of buffer is always 16 byte
void epi_getJsonVersion(uint8_t jsonNr, char *versionString);
// jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res.
// 5=printer template 1 ..... 36= template 32
// length of buffer is always 16 byte
void epi_setNowCoinPay(bool on_off);
bool gpi_getNowCoinPay(void);
void epi_setNowIsBootload(bool on_off);
bool gpi_getNowIsBootload(void);
void gpi_storeChangerResult(uint8_t result, uint32_t amount);
uint8_t epi_getChangerResult(uint32_t *returnedAmount);
// get result of coin dispensing
// receivedData[0]: 0: not yet started 1:amount returned
// 2:only partial return 3: no return possible
// receivedData[2,3,4,5]: returned amount
void gpi_storeTubeLevel(uint8_t *data);
void epi_restoreTubeLevel(uint8_t *data);
#endif

93
include/tslib.h Normal file
View File

@ -0,0 +1,93 @@
#ifndef TSLIB_H
#define TSLIB_H
#include <QByteArray>
#define LOWBYTE false
#define HIGHBYTE true
uint16_t uchar2uint(char Highbyte, char Lowbyte);
uint16_t uchar2uint(uint8_t Highbyte, uint8_t Lowbyte);
uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t Lowbyte);
uint8_t uint2uchar(uint16_t uival, bool getHighB);
uint8_t ulong2uchar(uint32_t ulval, uint8_t getBytNr);
// getBytNr: 0=LSB 3=MSB
void delay(uint16_t MilliSec);
#define MITSEK 1
#define OHNESEK 0
#define HourSys12h 1
#define HourSys24h 0
void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf);
// generate time as ascii string from integers hours/minutes/seconds
// System12h=0: 24h system =1: 12h System
// ShowSec=0: String has 5 digits (hh:mm) =1: String has 8 digits (hh:mm:ss)
// return String in *buf // 12 byte für buf!
#define DateFormatDeutsch 0
#define DateFormatAmerica 1
#define UsePointSeperator 0
#define UseSlashSeperator 1
void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// yearhigh in europe always 20 (not in arabia)
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11 byte für buf!
void GetShortDateString(uint8_t day, uint8_t month, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// format= 0: dd.mm.yy (deutsch)
// 1: mm.dd.yy (amerika)
// 2: yy.mm.dd (Iran, Dubai)
// 3: dd.yy.mm
// 4: mm.yy.dd
// 5: yy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11byte für buf!
uint16_t tslib_strlen(char *buf);
uint16_t tslib_strlen(uint8_t *buf);
void tslib_strclr(char *buf, char clrsign, uint16_t len);
void tslib_strclr(uint8_t *buf, char clrsign, uint16_t len);
void tslib_strcpy(char *srcbuf, char *destbuf, uint16_t len);
void tslib_strcpy(char *srcbuf, uint8_t *destbuf, uint16_t len);
void tslib_strcpy(uint8_t *srcbuf, uint8_t *destbuf, uint16_t len);
uint16_t tslib_calcCrcCcitt(uint16_t BufLength, uint8_t *buf);
bool tslib_isDecAsciiNumber(char sign);
bool tslib_isHexAsciiNumber(char sign);
int tslib_getMinimum(int val1, int val2);
void tslib_text2array(QByteArray text, char *aray, uint16_t maxArayLen);
// usage: tslib_text2array("my text", ctmp, 50);
void biox_CopyBlock(uint8_t *src, uint16_t srcPos, uint8_t *dest, uint16_t destPos, uint16_t len);
// both buffers starting from pos 0
bool tslib_strComp(uint8_t *buf, char *compStr);
#endif // TSLIB_H
// qDebug << QDateTime::currentDateTime().toString(Qt::ISODateWithMs) << QByteArray((const char*)dataSendBuf,dataBufLen).toHex(':');

View File

@ -0,0 +1,10 @@
TEMPLATE = lib
TARGET = CAmaster
VERSION="1.0.0"
include(../DCLibraries.pri)
DEFINES+=THIS_IS_CA_MASTER
DESTDIR=$${_PRO_FILE_PWD_}/../build
system("mkdir -p $${DESTDIR}")
system("cp ../include/interfaces.h $${DESTDIR}")

View File

@ -0,0 +1,10 @@
TEMPLATE = lib
TARGET = CAslave
VERSION="1.0.0"
include(../DCLibraries.pri)
DEFINES+=THIS_IS_CA_SLAVE
DESTDIR=$${_PRO_FILE_PWD_}/../build
system("mkdir -p $${DESTDIR}")
system("cp ../include/interfaces.h $${DESTDIR}")

429
src/com.cpp Normal file
View File

@ -0,0 +1,429 @@
#include "com.h"
#include <QDebug>
//#include "controlBus.h"
//////////////////////////////////////////////////////////////////////////////////
///
/// serial hardware layer
///
//////////////////////////////////////////////////////////////////////////////////
static int64_t com_want2read;
// -------------------------------------------------------------------------------------------------------------
// --------- PUBLIC --------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------
void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
{
sendBuffer=data;
sendLen=sendLength;
if (CatSerial->isOpen())
{
//qDebug() << "sending..." << sendBuffer;
CatSerial->write(sendBuffer);
} else
qDebug() << "error sending, port is not open";
}
bool T_com::readFromSerial(QByteArray &data, uint16_t &sendLength)
{
// return one time true if new data (completly) read.
// return new data in &data and &sendLength to other objects
uint16_t ll=rawInLen;
if (!CatSerial->isOpen())
return false;
data.clear();
data.append(rawInput);
sendLength=ll;
rawInLen=0; // beim 2. Aufruf 0 zurück weil nichts neues da
if (ll>0)
return true;
return false;
}
// -------------------------------------------------------------------------------------------------------------
// --------- PRIVATES --------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------
T_com::T_com(QObject *parent) : QObject(parent)
{
// port settings come from tabCom->Sdata->serial
gpi_serialChanged();
CatSerial = new QSerialPort(); // PortHW object for Control&Analyse Tool
//CatSerial->clear();
//CatSerial->clearError();
connect(CatSerial, &QSerialPort::readyRead, this, &T_com::readSomeBytes);
// still reading, not sure if complete, undefined number of calls while reading
connect(CatSerial, &QSerialPort::bytesWritten, this, &T_com::serialSendComplete);
// system confirms sending complete
//connect(CatSerial, &QSerialPort::dataTerminalReadyChanged, this, &T_com::incomingWake);
//connect(CatSerial, &QSerialPort::requestToSendChanged, this, &T_com::incomingWake);
// timer detects time gap in input flow
serRecTime = new QTimer();
connect(serRecTime, SIGNAL(timeout()), this, SLOT(receiveTO()));
serRecTime->setSingleShot(true); // single shot! only one impulse if receive complete
serRecTime->stop(); // on hold
// check COM-TAB periodic if user wants to connect or disconnect
QTimer *ChkConnectTimer = new QTimer();
connect(ChkConnectTimer, SIGNAL(timeout()), this, SLOT(ser_ISR100ms()));
ChkConnectTimer->setSingleShot(false);
ChkConnectTimer->start(100); // in ms
com_want2read=0;
}
T_com::~T_com()
{
if (CatSerial->isOpen())
CatSerial->close();
}
void T_com::ser_ISR100ms()
{
// 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)
switch (chkConn)
{
case 0: // 0 button "connect" was just released
closeSerialPort();
gpi_serialChanged(); // set chkConn to 2, thus getting edge
break;
case 1: // 1 button "connect" was just pressed
open_Serial_Port();
gpi_serialChanged(); // set chkConn to 2, thus getting edge
break;
}
if (CatSerial->isOpen())
gpi_serialIsOpen(true);
else
gpi_serialIsOpen(false);
}
// -------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------
char T_com::open_Serial_Port()
{
bool ret;
QString myString=nullptr, myPortName=nullptr, myBaudStr=nullptr;
int myBaudNr;
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
switch (myBaudNr)
{
// 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
case 0: CatSerial->setBaudRate(QSerialPort::Baud1200); myBaudStr="1200"; break;
case 1: CatSerial->setBaudRate(QSerialPort::Baud9600); myBaudStr="9600"; break;
case 2: CatSerial->setBaudRate(QSerialPort::Baud19200); myBaudStr="19200"; break;
case 3: CatSerial->setBaudRate(QSerialPort::Baud38400); myBaudStr="38400"; break;
case 4: CatSerial->setBaudRate(QSerialPort::Baud57600); myBaudStr="57600"; break;
case 5: CatSerial->setBaudRate(QSerialPort::Baud115200); myBaudStr="115200"; break;
}
CatSerial->setDataBits(QSerialPort::Data8);
// alt: QSerialPort::Data5,6,7,8
CatSerial->setParity(QSerialPort::NoParity);
// alt: EvenParity, OddParity, NoParity
CatSerial->setStopBits(QSerialPort::OneStop);
// alternative: OneStop, TwoStop, OneAndHalfStop
CatSerial->setFlowControl(QSerialPort::NoFlowControl);
// alt: HardwareControl, SoftwareControl, NoFlowControl
ret=CatSerial->open(QIODevice::ReadWrite);
// alt: QIODevice::ReadWrite QIODevice::ReadOnly QIODevice::WriteOnly
if (!ret)
{
myString.clear();
myString = "error ";
myString.append(CatSerial->errorString());
qDebug() << myString;
gpi_setTxt4comStateLine(myString);
return 0;
} else
{
myString.clear();
myString.append(myPortName);
//lang=myString.size();
myString.append(" opened with ");
myString.append(myBaudStr);
myString.append(" 8N1");
qDebug() << myString;
gpi_setTxt4comStateLine(myString);
gpi_setTxt4RsDiagWin(myString+"\n");
}
return 0;
}
void T_com::closeSerialPort()
{
if (CatSerial->isOpen())
{
qDebug() << "closing connection";
CatSerial->close();
gpi_setTxt4comStateLine("closed");
gpi_setTxt4RsDiagWin("closed");
}
}
void T_com::readSomeBytes(void)
{
// called by serial-read-detection
// restart off-time as input flow is ongoing
// timer for slow receive
// and serves as timeout for fast receive is msg is shorter as expected
serRecTime->stop();
serRecTime->start(20); // in ms
//qDebug()<< "com-rec read some bytes";
this->receiveByLength(); // since 14.12.21: fast receive
}
void T_com::receiveFixLen(int64_t nrOfbytesToReceive)
{
// call this before sending a request to slave
// then we know exactly when reception is complete -> much faster
com_want2read=nrOfbytesToReceive;
// since 14.12.21: FastDevice Protocol has two lengthen:
// fast: 12byte reception long: 68byte
}
void T_com::receiveByLength(void)
{
if (CatSerial->isOpen())
{
QString myString=nullptr, tmpStr=nullptr;
int64_t nrOfBytesreceived = CatSerial->bytesAvailable(); // nr of received bytes
//qDebug()<< "com-rec current Len: "<< nrOfBytesreceived;
if (nrOfBytesreceived >= com_want2read)
{
QByteArray data = CatSerial->readAll(); // erst auslesen wenn alles da! löscht den Empfangspuffer
serRecTime->stop(); // stop timeout to avoid 2nd emit
rawInLen=uint16_t (nrOfBytesreceived);
rawInput.clear();
rawInput.append(data);
//qDebug()<< "com-recFinished by Len "<< rawInLen;
gpi_set2ndTxt4RsDiagWin(myString); // 4.10.23 hier neu
emit receivingFinished();
}
}
}
void T_com::receiveTO(void)
{
// no new input data for 20ms, --> assuming frame complete
// save data in private "rawInput"-buffer
if (CatSerial->isOpen())
{
QString myString=nullptr, tmpStr=nullptr;
int64_t nrOfBytesreceived = CatSerial->bytesAvailable(); // nr of received bytes
QByteArray data = CatSerial->readAll();
rawInLen=uint16_t (nrOfBytesreceived);
rawInput.clear();
rawInput.append(data);
//rawInput[rawInLen]=0; // Zwangsterminierung bei QByteArray nicht nötig
// diag display in serial in/out window and debug window
myString.clear();
myString.setNum(rawInLen);
myString.append(" in: ");
//myString.append(rawInput);
for (int ii=0; ii<rawInLen; ii++)
{
tmpStr.clear();
tmpStr.setNum(rawInput[ii],16); // problem: wenn >0x80 dann wird EIN Byte 16 stellig angezeigt
int ll=tmpStr.length();
if (ll>2)
{
myString.append(tmpStr[ll-2]);
myString.append(tmpStr[ll-1]);
} else
{
myString.append(tmpStr);
}
myString.append(" ");
}
myString.append("\n");
#ifdef PRINTALLDEBUGS
qDebug() << "VCP:" << myString; // display all inputs and outputs in output window
#endif
//gpi_setTxt4RsDiagWin(myString);
gpi_set2ndTxt4RsDiagWin(myString); // 4.10.23: diese verwenden weil die gpi_setTxt4RsDiagWin() durch Ausgabe ueberschrieben wird
//qDebug()<< "com-recFinished by TO";
emit receivingFinished();
}
}
void T_com::serialSendComplete(void)
{
// system confirms sending complete, diag display
QString myString=nullptr, tmpStr=nullptr;
myString.clear();
myString.setNum(sendLen);
myString.append(" out: ");
for (int ii=0; ii<sendLen; ii++)
{
tmpStr.clear();
tmpStr.setNum(sendBuffer[ii],16); // problem: wenn >0x80 dann 16stellig
int ll=tmpStr.length();
if (ll>2)
{
//qDebug() << "long_string" << ll << "\n";
myString.append(tmpStr[ll-2]);
myString.append(tmpStr[ll-1]);
} else
{
myString.append(tmpStr);
}
myString.append(" ");
}
#ifdef PRINTALLDEBUGS
myString.append("\n");
qDebug() << myString; // display all output data in out-window
#endif
gpi_setTxt4RsDiagWin(myString);
emit sendingFinished(); // for whom it may interest
}
bool T_com::isPortOpen(void)
{
if (CatSerial->isOpen())
return true;
return false;
}
// -------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------
/*
uint8_t T_com::getAllPortPins(void)
{
uint8_t rs232pins=0;
rs232pins= uint8_t(CatSerial->pinoutSignals());
// rs232pins: all signals bitwise coded in one byte:
// readback output: bit 0=TxD(=output) bit2=DTR (=output) bit 6=RTS (=output)
// unused inputs: bit1=RxD bit 3=DCD bit 5 = RING
// handshake inputs: bit 4=DSR (0x10) bit 7=CTS (0x80)
//qDebug()<<"serial port pins: " << rs232pins;
return rs232pins;
}
bool T_com::getHSin_CTS(void)
{
// return the used Handshake IN (CTS, alt. DSR): true= high level (+8V)
uint8_t rs232pins=0;
rs232pins= uint8_t(CatSerial->pinoutSignals());
// rs232pins: all signals bitwise coded in one byte:
// readback output: bit 0=TxD(=output) bit2=DTR (=output) bit 6=RTS (=output)
// unused inputs: bit1=RxD bit 3=DCD bit 5 = RING
// handshake inputs: bit 4=DSR (0x10) bit 7=CTS (0x80)
if (rs232pins & 0x80) // CTS
return true;
return false;
}
bool T_com::getHSin_DSR(void)
{
uint8_t rs232pins=0;
rs232pins= uint8_t(CatSerial->pinoutSignals());
if (rs232pins & 0x10) // DSR
return true;
return false;
}
void T_com::incomingWake(void) //(bool LevelOfTheBit)
{
emit wasWokenBySerialHandshake();
}
bool T_com::setHSout_RTS(bool hsout)
{
// hsout true=positiv voltage +12V false= -12V
// retval: true=setting OK
bool cc;
// 10.5.19, am Windows-PC nachgemessen, funktioniert gut
// false ergibt -12V true ergibt +12V
cc=CatSerial->setRequestToSend(hsout); // RTS out
// retval true means "setting was successful"
// alternative: use DTR as Handshake:
//cc=CatSerial->setDataTerminalReady(false); // DTR out
// retval true means "setting was successful"
//qDebug()<<"RTS " <<cc;
return cc;
}
bool T_com::setHSout_DTR(bool hsout)
{
// hsout true=positiv voltage +12V false= -12V
// retval: true=setting OK
bool cc;
// 10.5.19, am Windows-PC nachgemessen, funktioniert gut
// false ergibt -12V true ergibt +12V
cc=CatSerial->setDataTerminalReady(hsout); // DTR out
// retval true means "setting was successful"
//qDebug()<<"DTR " <<cc;
return cc;
}
*/

510
src/controlBus.cpp Normal file
View File

@ -0,0 +1,510 @@
#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;
}

1333
src/datIf.cpp Normal file

File diff suppressed because it is too large Load Diff

943
src/datei.cpp Normal file
View 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;
}
}

1528
src/dcBL.cpp Normal file

File diff suppressed because it is too large Load Diff

0
src/dc_plugin_error.cpp Normal file
View File

91
src/dc_result.cpp Normal file
View File

@ -0,0 +1,91 @@
#include "dc_result.h"
#include <QMetaType>
struct DCResultInit {
DCResultInit() {
qRegisterMetaType<DCResult>();
}
};
static DCResultInit initMetaTypeDCResult;
DCResult::DCResult()
: m_pluginState(PLUGIN_STATE::NOT_INITIALIZED)
, m_errorCode("NOT-INITIALIZED")
, m_errorDescription("NOT-INITIALIZED") {
}
DCResult::DCResult(PLUGIN_STATE pState, RESULT_STATE rState,
QString errorCode, QString errorDescription,
QString cashValue)
: m_pluginState(pState)
, m_resultState(rState)
, m_errorCode(errorCode)
, m_errorDescription(errorDescription)
, m_newCashValue(cashValue) {
}
DCResult::DCResult(PLUGIN_STATE pState, RESULT_STATE rState,
CASH_STATE cState, QString errorCode,
QString errorDescription, QString cashValue)
: m_pluginState(pState)
, m_resultState(rState)
, m_cashState(cState)
, m_errorCode(errorCode)
, m_errorDescription(errorDescription)
, m_newCashValue(cashValue) {
}
QDebug operator<<(QDebug d, DCResult const &result) {
d << "\n";
switch(result.m_pluginState) {
case DCResult::PLUGIN_STATE::INITIALIZED:
d << "DC-PLUGIN-STATE ... INITIALIZED\n";
break;
case DCResult::PLUGIN_STATE::NOT_INITIALIZED:
d << "DC-PLUGIN-STATE ... NOT-INITIALIZED\n";
break;
}
switch(result.m_resultState) {
case DCResult::RESULT_STATE::SUCCESS:
d << "DC-RESULT-STATE ... SUCCESS\n";
break;
case DCResult::RESULT_STATE::ERROR_BACKEND:
d << "DC-RESULT-STATE ... ERROR_BACKEND\n";
break;
case DCResult::RESULT_STATE::ERROR_TIMEOUT:
d << "DC-RESULT-STATE ... ERROR_TIMEOUT\n";
break;
case DCResult::RESULT_STATE::ERROR_PROCESS:
d << "DC-RESULT-STATE ... ERROR_PROCESS\n";
break;
case DCResult::RESULT_STATE::ERROR_RETRY:
d << "DC-RESULT-STATE ... ERROR_RETRY\n";
break;
case DCResult::RESULT_STATE::INFO:
d << "DC-RESULT-STATE ... INFO\n";
break;
}
switch(result.m_cashState) {
case DCResult::CASH_STATE::CACHE_EMPTY:
d << "DC-CASH-STATE ... CASH-EMPTY\n";
break;
case DCResult::CASH_STATE::CACHE_INPUT:
d << "DC-CASH-STATE ... CASH-INPUT\n";
break;
case DCResult::CASH_STATE::OVERPAYED:
d << "DC-CASH-STATE ... OVERPAYED\n";
break;
case DCResult::CASH_STATE::NOT_AVAILABLE:
break;
}
d << "DC-ERROR-CODE ..." << result.m_errorCode << "\n";
d << "DC-ERROR-DESC ..." << result.m_errorDescription << "\n";
return d;
}

4236
src/hwapi.cpp Normal file

File diff suppressed because it is too large Load Diff

9
src/main.cpp Normal file
View File

@ -0,0 +1,9 @@
#include <QCoreApplication>
#include "tslib.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}

623
src/prot.cpp Normal file
View File

@ -0,0 +1,623 @@
#include "prot.h"
#include <QDebug>
#include "controlBus.h"
#include "dcBL.h"
#include "interfaces.h"
T_prot::T_prot()
{
mySerialPort = new T_com();
connect(mySerialPort, SIGNAL(receivingFinished()), this, SLOT( analyseRecData() ));
//connect(mySerialPort, SIGNAL(sendingFinished()), this, SLOT(sendeFin()));
for (int nn=0; nn<FRAME_DATALEN; nn++)
{
chOut_Data[nn]=0;
ui8OutputData[nn]=0;
InputData[nn]=0;
}
for (int nn=0; nn<BL_DATA_LEN; nn++)
{
ui8BLsendData[nn]=0;
}
WriteCommand=0;
WriteAddr=0;
WrDataLength=0;
SendDataValid=0;
kindOfData=0;
slaveAddr=0;
ReadCommand=0;
//ReadAddr=0;
reserve =0;
RecSlaveAddr =0;
INdataValid=0;
readSource =0;
readAddress=0;
RdDataLength=0;
BLsendDataLength=0;
prot_storeResult=0xFF;
}
// ---------------------------------------------------------------------------------------------------------
// sending.....
// ---------------------------------------------------------------------------------------------------------
bool T_prot::isPortOpen(void)
{
return mySerialPort->isPortOpen();
}
bool T_prot::isSerialFree(void)
{
return true; // ohne HS's kann er nicht blockiert sein
}
// 14.9.23 Fehler!!!!!
// hier wird vorausgesetzt dasss die Empfangslaenge von Sendetelegramm abh. ist.
// also cmd>=100 ist kurze Antwort. das stimmt aber nicht, ist unabh. Wahr ist: cmd>=100 = kurzes Sendetelegramm
// Laenge des request-telegramms (PTU-->DC) ist nur abh. vom WRcmd, die Antwort auf WR ist immer kurz (nur result byte)
// WRcmd kurz oder lang: Antwort immer kurz
// RDcmd kurz oder lang: Antwort genauso
// Also Korrektur dieser Funktion: nur der Variablenname "WriteCmd" -> "ReadCmd"
void T_prot::setRecLen(uint16_t ReadCmd)
{
if (ReadCmd<100)
{
RdDataLength=DATALEN_RECEIVE_LONG; // 64, store here already because it's no longer returned from slave
mySerialPort->receiveFixLen(TELEGRAMLEN_RECEIVE_LONG); // 68
} else
{
RdDataLength=DATALEN_RECEIVE_FAST; // 8
mySerialPort->receiveFixLen(TELEGRAMLEN_RECEIVE_FAST); // 12
}
}
/*
* void T_prot::setRecLen(uint16_t WriteCmd)
{
if (WriteCmd<100)
{
RdDataLength=DATALEN_RECEIVE_LONG; // store here already because it's no longer
// returned from slave
mySerialPort->receiveFixLen(TELEGRAMLEN_RECEIVE_LONG); // 68
} else
{
RdDataLength=DATALEN_RECEIVE_FAST;
mySerialPort->receiveFixLen(TELEGRAMLEN_RECEIVE_FAST); // 12
}
}
*/
void T_prot::setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data)
{
WriteCommand=WriteCmd;
WriteAddr=WrAddr;
WrDataLength=WrDatLen;
if (WrDataLength>FRAME_DATALEN)
WrDataLength=FRAME_DATALEN;
for (int nn=0; nn<WrDataLength; nn++)
ui8OutputData[nn]=data[nn];
SendDataValid=1; // always set WR first
kindOfData=0; // 0: binaries, 1:text
this->setRecLen(100); // default: short response
}
void T_prot::setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr)
{
WriteCommand=WriteCmd;
WriteAddr=WrAddr;
WrDataLength=0;
for (int nn=0; nn<FRAME_DATALEN; nn++)
ui8OutputData[nn]=0;
SendDataValid=1; // always set WR first
kindOfData=0; // 0: binaries, 1:text
this->setRecLen(100); // default: short response
}
void T_prot::setUserWriteData(uint16_t WriteCmd)
{
WriteCommand=WriteCmd;
WriteAddr=0;
WrDataLength=0;
for (int nn=0; nn<FRAME_DATALEN; nn++)
ui8OutputData[nn]=0;
SendDataValid=1; // always set WR first
kindOfData=0; // 0: binaries, 1:text
this->setRecLen(100); // default: short response
}
void T_prot::setUserWrite1DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val)
{
// wie oben, jedoch einfachere Datenübergabe
WriteCommand=WriteCmd;
WriteAddr=WrAddr;
WrDataLength=1;
ui8OutputData[0]=val;
SendDataValid=1; // always set WR first
kindOfData=0; // 0: binaries, 1:text
this->setRecLen(100); // default: short response
}
void T_prot::setUserWrite2DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val0, uint8_t val1)
{
WriteCommand=WriteCmd;
WriteAddr=WrAddr;
WrDataLength=2;
ui8OutputData[0]=val0;
ui8OutputData[1]=val1;
SendDataValid=1; // always set WR first
kindOfData=0; // 0: binaries, 1:text
this->setRecLen(100); // default: short response
}
void T_prot::setUserWriteText(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, char *data)
{
WriteCommand=WriteCmd;
WriteAddr=WrAddr;
WrDataLength=WrDatLen;
if (WrDataLength>FRAME_DATALEN)
WrDataLength=FRAME_DATALEN;
for (int nn=0; nn<WrDataLength; nn++)
chOut_Data[nn]=data[nn];
SendDataValid=1; // always set WR first
kindOfData=1; // 0: binaries, 1:text
this->setRecLen(100); // default: short response
}
void T_prot::setUserReadData( uint16_t ReadCmd)
{
ReadCommand=ReadCmd;
//ReadAddr=WriteAddr;
reserve=0;
SendDataValid |=2;
readAddress=WriteAddr; // store here already because it's no longer returned from slave
//qDebug()<<"prot_setUserReadData, read address : " << readAddress;
this->setRecLen(ReadCmd); // long response (68byte) only for ReadCmd < 100
readSource=ReadCmd;
}
void T_prot::setBLsendData( uint8_t len, uint8_t *buf)
{
for (int nn=0; nn<BL_DATA_LEN; nn++)
ui8BLsendData[nn]=0;
BLsendDataLength=len;
if ( BLsendDataLength>BL_DATA_LEN) BLsendDataLength=BL_DATA_LEN;
for (int nn=0; nn<BLsendDataLength; nn++)
ui8BLsendData[nn]=buf[nn];
WriteCommand=0xFFFF;
this->setRecLen(100);
//qDebug()<<"prot: got BL data " << len << "bytes, ";
//for (int i=0; i<len; ++i) {
// printf("%02x ", (unsigned char)buf[i]);
//} printf("\n");
/*
qDebug()<<buf[0] <<buf[1] <<buf[2] <<buf[3] <<buf[4] <<buf[5] <<buf[6] <<buf[7];
qDebug() <<buf[8] <<buf[9] <<buf[10] <<buf[11] <<buf[12] <<buf[13]<<buf[14]<<buf[15];
qDebug() <<buf[16] <<buf[17] <<buf[18] <<buf[19] <<buf[20] <<buf[21]<<buf[22]<<buf[23];
qDebug() <<buf[24] <<buf[25] <<buf[26] <<buf[27] <<buf[28] <<buf[29]<<buf[30]<<buf[31];
qDebug() <<buf[32] <<buf[33] <<buf[34] <<buf[35] <<buf[36] <<buf[37]<<buf[38]<<buf[39];
qDebug() <<buf[40] <<buf[41] <<buf[42] <<buf[43] <<buf[44] <<buf[45]<<buf[46]<<buf[47];
qDebug() <<buf[48] <<buf[49] <<buf[50] <<buf[51] <<buf[52] <<buf[53] <<buf[54]<<buf[55];
qDebug() <<buf[56] <<buf[57] <<buf[58] <<buf[59] <<buf[60] <<buf[61] <<buf[62]<<buf[63];
qDebug() <<buf[64] <<buf[65] <<buf[66] <<buf[67] <<buf[68] <<buf[69] <<buf[70]<<buf[71];
qDebug() <<buf[72] <<buf[73] <<buf[74] <<buf[75] <<buf[76] <<buf[77] <<buf[78]<<buf[79];
*/
}
void T_prot::receiveFixLen(int64_t nrOfbytesToReceive)
{
mySerialPort->receiveFixLen(nrOfbytesToReceive);
}
void T_prot::sendUserData(uint16_t slaveAdr)
{
// man könnte hier noch "SendDataValid" abfragen,
// muss immer 3 sein, muss man aber nicht
//qDebug() << "prot send user data "<<slaveAdr;
QByteArray packBuf_2;
slaveAddr=slaveAdr;
if (WriteCommand==0xFFFF)
{
// Bypass for bootloader, no protocol frame but send as is...
packBuf_2.clear();
for (int nn=0; nn<BLsendDataLength; nn++)
{
// packBuf_2[nn]=char(ui8BLsendData[nn]); // program crash, 4.9.23
packBuf_2.append(ui8BLsendData[nn]);
}
mySerialPort->writeToSerial(packBuf_2, BLsendDataLength);
} else
startFastPacking(); // quicker since 15.12.21TS
//startPacking();
}
void T_prot::startFastPacking(void)
{
uint16_t mycrc;
uint16_t sendLen;
uint8_t uctmp, nn, pp, CrcLp;
char sendBuffer[FRAME_MAXLEN], ctmp;
//qDebug() << "prot start fast packing "<<slaveAddr;
for (int nn=0; nn<FRAME_MAXLEN; nn++)
sendBuffer[nn]=0;
if (WriteCommand>9 && WriteCommand<100)
{
// long command 10...99
// WriteCommand==0 if only read request, then use short sending
sendBuffer[0]=STARTSIGN_SEND_LONG;
WrDataLength=DATALEN_SEND_LONG; // immer
//qDebug() << "send long cmd, len: " << WrDataLength;
} else
{
// fast command
sendBuffer[0]=STARTSIGN_SEND_FAST;
WrDataLength=DATALEN_SEND_FAST; // immer
//qDebug() << "send fast cmd, len: " << WrDataLength;
}
sendBuffer[1]= uint8_t(WriteCommand);
sendBuffer[2]= uint8_t(ReadCommand);
//if (WriteAddr>0)
sendBuffer[3]= char(WriteAddr); // bei fast nur EINE adresse, wr hat Vorrang
//else
// sendBuffer[3]= char(ReadAddr);
// beim Fast prot. ist das reserve dann ists egal was drin steht
if (kindOfData) // 0: binaries, 1:text
{
for (nn=0; nn<WrDataLength; nn++)
{
pp=HEADERLEN_SEND+nn;
ctmp=(chOut_Data[nn]); // text
sendBuffer[pp]= char(ctmp);
}
} else
{
for (nn=0; nn<WrDataLength; nn++)
{
pp=HEADERLEN_SEND+nn;
uctmp=(ui8OutputData[nn]); // bin
sendBuffer[pp]= char(uctmp);
}
}
CrcLp= HEADERLEN_SEND + WrDataLength;
mycrc=0;
for (nn=0; nn<CrcLp; nn++)
{
uctmp=sendBuffer[nn];
mycrc+=uint16_t(uctmp);
//qDebug() << mycrc;
}
sendBuffer[CrcLp]=char(mycrc);
mycrc>>=8;
sendBuffer[CrcLp+1]=char(mycrc);
sendLen=CrcLp+2;
// send to VCP:
QByteArray packBuff;
packBuff.clear();
packBuff.append(sendBuffer, sendLen); // ohne sendLen wird beim ersten \0 abgeschnitten!!!
mySerialPort->writeToSerial(packBuff, sendLen);
}
// ---------------------------------------------------------------------------------------------------------
// receiving.....
// ---------------------------------------------------------------------------------------------------------
void T_prot::analyseRecData(void)
{
// Aufruf per connect aus serialcontrol wenn Daten empfangen wurden
// getRecData(QByteArray &data, uint16_t &sendLength);
QByteArray Indata;
QString myString, tempStr;
//char recBuffer[FRAME_MAXLEN];
uint8_t recBuffer[FRAME_MAXLEN];
uint16_t recLength;
INdataValid=false;
gpi_setTxt4HsStateLine("");
gpi_setTxt4masterStateLine("");
gpi_setTxt4resultStateLine("");
gpi_setTxt4dataStateLine("");
gpi_setTxt4datifLine("");
// read from "VCP":
mySerialPort->readFromSerial(Indata, recLength);
//qDebug()<<"prot: got data " << recLength;
if (recLength>FRAME_MAXLEN)
recLength=FRAME_MAXLEN;
for (int nn=0; nn<recLength; nn++)
recBuffer[nn]=uint8_t(Indata.at(nn));
myString.clear();
tempStr.clear();
uint8_t result=FastCheckInData(recBuffer, recLength); // check input data (response from slave)
if (result>0)
{
// dann anzeige
switch (result)
{
case 1: gpi_setTxt4masterStateLine("wrong length received"); break;
case 2: gpi_setTxt4masterStateLine("wrong start sign received"); break;
case 3: gpi_setTxt4masterStateLine("received datalen too big"); break;
case 4: gpi_setTxt4masterStateLine("wrong data len received"); break;
case 5: gpi_setTxt4masterStateLine("wrong crc received"); break;
case 6: gpi_setTxt4masterStateLine("slave: master cmd was wrong"); break;
case 7: gpi_setTxt4masterStateLine("slave: could not write/read data"); break;
}
myString.setNum(result);
// qDebug()<<"T_prot_analyseRecData: got BL data"<< recLength <<
// recBuffer[0]<< recBuffer[1]<< recBuffer[2]<< recBuffer[3] <<
// recBuffer[4]<< recBuffer[5]<< recBuffer[6]<< recBuffer[7];
// Daten abspeichern, könnten vom BL sein:
gpi_storeRawReceivedData(uint8_t(recLength), recBuffer);
INdataValid=false;
emit rawDataRecieved();
} else
{
gpi_setTxt4masterStateLine("slave response OK");
INdataValid=true;
ShowFastInData(recBuffer); // Eingangs-Daten des Slaves anzeigen
}
prot_storeResult=result;
emit framerecieved(); // always emit, no matter if data valid or not
}
uint8_t T_prot::FastCheckInData(uint8_t *Inbuf, uint16_t LL)
{
uint16_t rawInLen=LL, crcL_Addr, recCrc, myCrc, nn, datalen, nxt;
if (Inbuf[0]!=STARTSIGN_RECEIVE_FAST && Inbuf[0]!=STARTSIGN_RECEIVE_LONG)
{
//qDebug() << "prot: got wrong start sign: " << Inbuf[0];
return 2; // wrong start sign
}
if ( (rawInLen<TELEGRAMLEN_RECEIVE_FAST && Inbuf[0]==STARTSIGN_RECEIVE_FAST) ||
(rawInLen<TELEGRAMLEN_RECEIVE_LONG && Inbuf[0]==STARTSIGN_RECEIVE_LONG) )
{
//qDebug("prot: got %d bytes only", rawInLen);
return 1; // wrong length
}
if (Inbuf[0]==0x5F)
datalen=DATALEN_RECEIVE_FAST;
else
datalen=DATALEN_RECEIVE_LONG;
crcL_Addr=datalen+HEADERLEN_RECEIVE; // weil im definierten protocol 2 bytes vor den Daten stehen
recCrc=0;
recCrc=uchar2uint(uint8_t(Inbuf[crcL_Addr+1]), uint8_t(Inbuf[crcL_Addr]));
myCrc=0;
for (nn=0; nn<crcL_Addr; nn++)
{
nxt=uint16_t (Inbuf[nn]);
nxt &=0x00FF; // the casting makes 0xFFFF out of 0xFF !!!!!!!!!
myCrc+=nxt;
//qDebug("CRC: nxt: %d sum: %d", nxt, myCrc);
}
if (myCrc != recCrc)
{
//qDebug() << "crc does not match"; //: mycrc=" << myCrc<< " receivedCRC=" << recCrc;
//qDebug("calculated over %d bytes", crcL_Addr);
return 5; // crc wrong
}
uint8_t result=Inbuf[1];
// slave reports that 0: OK
// bit 2,1,0: master command was wrong
// bit 4,3: could not write data
// bit 6,5: could not read data
// NEU 17.7.23:
if (result & 0x07)
return 6; // slave: master cmd was wrong
if (result & 0x78)
return 7; // slave: could not write/read data
//if (result>0) schmarrn, kann nie kommen
// qDebug() << "prot, got DC-result: "<< result;
return 0;
}
/*
uint8_t T_prot::CheckInResult(uint8_t *Inbuf)
{
char slaveresult;
QString myString=nullptr, tempStr=nullptr;
// slave results anzeigen
slaveresult=Inbuf[2]; // hier steht das "Command Result" des slaves,
// d.h das Ergebnis der Protokol-Prüfung (Master->Slave)
switch (slaveresult)
{
// received message (from master) analysis:
// 0: got valid request
// this errors can only come back from a single device (not bus)
// or from a bus slave in local mode
// 1: wrong start 2: wrong length
// 3: wrong crc 4: wrong addr
case 1: gpi_setTxt4resultStateLine("slave got wrong start sign"); break;
case 2: gpi_setTxt4resultStateLine("slave got wrong length"); break;
case 3: gpi_setTxt4resultStateLine("slave got wrong crc"); break;
case 4: gpi_setTxt4resultStateLine("slave got wrong addr"); break;
case 10: gpi_setTxt4resultStateLine("slave is in local mode"); break;
case 13: gpi_setTxt4resultStateLine("local mode with wrong crc"); break;
case 14: gpi_setTxt4resultStateLine("local mode with wrong addr"); break;
// wenn 1..4 dann konnte der Slave das Mastertelegramm gar nicht verwenden, also hier Stoppen
}
if (slaveresult>0 && slaveresult<10)
return 1;
// Slave hat gültiges Kommando empfangen:
// 2.result auswerten:
// recBuffer[3]; // Write result, d.h. Ergebnis des Schreibvorganges (z.B. DOs) des Slaves
// recBuffer[4]; // Read result, d.h. Ergebnis des Lesevorganges (z.B. DIs) des Slaves
// bisher nicht bekannt welche Fehlercodes es gibt, also den code direkt ausgeben.
// bisher bekannt: 0=OK
myString.clear();
myString = "Slave OUT and IN Result: ";
tempStr.setNum(Inbuf[3],16);
myString.append(tempStr);
myString.append(" ");
tempStr.setNum(Inbuf[4],16);
myString.append(tempStr);
gpi_setTxt4resultStateLine(myString);
return 0;
}
*/
uint8_t T_prot::ShowFastInData(uint8_t *recBuffer)
{
QString myString=nullptr, tempStr=nullptr;
uint8_t result;
RecSlaveAddr=0;
result=recBuffer[1]; // total result
result &=0x60; // only read result (bit 5,6)
if (result==0) // read result =OK,
// dann sind die Eingangsdaten gültig
{
myString.append("valid INdata: ");
//INdataValid=true; // 17.7. hier raus!
//readSource already set with sending
//readAddress=0; großer Fehler!!!! raus am 17.7
// RdDataLength already set with sending
if (RdDataLength>FRAME_DATALEN)
RdDataLength=FRAME_DATALEN;
for (int ii=0; ii<RdDataLength; ii++)
InputData[ii]=uint8_t(recBuffer[ii+HEADERLEN_RECEIVE]);
tempStr.setNum(readSource,16);
myString.append(tempStr);
myString.append(" add:");
tempStr.setNum(readAddress);
myString.append(tempStr);
//myString.append(" wakeSrc:");
//tempStr.setNum(lastWakeSrc);
//myString.append(tempStr);
myString.append(" Dlen:");
tempStr.setNum(RdDataLength);
myString.append(tempStr);
} else
{
myString=" "; // Eingangsdaten nicht gültig, sieht man aber weiter oben schon
}
gpi_setTxt4dataStateLine(myString);
//qDebug() << myString;
//qDebug("prot_checkInData_bindata: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d ",
// InputData[0], InputData[1], InputData[2], InputData[3],
// InputData[4], InputData[5], InputData[6], InputData[7],
// InputData[8], InputData[9], InputData[10], InputData[11],
// InputData[12], InputData[13], InputData[14], InputData[15]);
return 0;
}
uint8_t T_prot::ifDataReceived()
{
// return: 0xFF: result unknown 0=OK
// 1= wrong length 2=wrong start sign 5= wrong crc
// 6= slave: master cmd was wrong 7: slave: could not write/read data
return prot_storeResult;
}
bool T_prot::getReceivedInData(uint8_t *SlavAddr, uint16_t *readSrc, uint16_t *readAddr,
uint8_t *RdDlen, uint8_t *receivedData)
{
uint8_t nn;
*SlavAddr=RecSlaveAddr;
*readSrc=readSource; // diese (Eingangs-)Daten stehen im Puffer
*readAddr=readAddress; // von dieser Adr wurden die Daten gelesen
//qDebug()<<"prot_get_ReceivedInData, read address : " << readAddress;
//*lastWakSourc=lastWakeSrc; // falls der Slave den Master geweckt hat
*RdDlen=RdDataLength;
for (nn=0; nn<FRAME_DATALEN; nn++)
receivedData[nn]=0;
for (nn=0; nn<RdDataLength; nn++)
receivedData[nn]=InputData[nn];
// neu, 17.10.23: lokalen Puffer löschen
//for (nn=0; nn<FRAME_DATALEN; nn++)
// {
// InputData[nn]=0;
//}
// wieder raus, keinen Vorteil erkannt. Unklar ob das irgendwo Probleme macht! (bootloader?)
RdDataLength=0;
//-------------------------------------------
return INdataValid; // nur true wenn CommandState OK und readState OK
}

748
src/runProc.cpp Executable file
View File

@ -0,0 +1,748 @@
#include "runProc.h"
#include <QDebug>
#include "controlBus.h"
#include "dcBL.h"
#include "interfaces.h"
static uint32_t hwapi_lastStartAmount;
static uint32_t hwapi_lastTotalAmount;
static uint8_t hwapi_cash_lastCollectionState;
static uint8_t hwapi_paymentStarted;
static uint8_t hwapi_lastDoorState;
static uint8_t bl_startupStep;
T_runProc::T_runProc()
{
hwapi_TimerPayment = new QTimer();
hwapi_TimerPayment->setSingleShot(true);
hwapi_lastStartAmount=0;
hwapi_lastTotalAmount=0;
hwapi_cash_lastCollectionState=0;
hwapi_paymentStarted=0;
hwapi_lastDoorState=0;
bl_startupStep=0;
QTimer *runProc_callProcesses = new QTimer();
connect(runProc_callProcesses, SIGNAL(timeout()), this, SLOT(runProc_slotProcess()));
runProc_callProcesses->setSingleShot(false);
runProc_callProcesses->start(100); // in ms
hwapi_lastDoorState=0; // default: all doors (should be) closed, coin box inserted
// bit0: upper door 1:middle 2:lower 3=cash-box out
hwapi_triggerBL = new QTimer();
connect(hwapi_triggerBL, SIGNAL(timeout()), this, SLOT(bl_performComplStart()));
hwapi_triggerBL->setSingleShot(false);
hwapi_triggerBL->stop();
}
void T_runProc::runProc_slotProcess(void)
{
cash_paymentProcessing();
doors_supervise();
dcBL_cycle();
}
bool T_runProc::cash_startPayment(uint32_t amount)
{
uint8_t dat1, dat2, dat3, dat4;
hwapi_lastStartAmount=amount;
epi_clearCurrentPayment();
dat1=ulong2uchar(amount, 0);
dat2=ulong2uchar(amount, 1);
dat3=ulong2uchar(amount, 2);
dat4=ulong2uchar(amount, 3);
hwapi_cash_lastCollectionState=0;
sendFDcmd_set(155, 0,0, dat1,dat2,dat3,dat4);
// wird im DC auf 65500 gesetzt wenn 0 (Maximalwert 0 macht keinen Sinn!)
hwapi_paymentStarted=1;
hwapi_TimerPayment->start(5000); // in ms
hwapi_lastTotalAmount=0;
epi_setNowCoinPay(true); // new since 20.9.23
qDebug() << "payment started with " << amount ;
return true;
}
uint8_t T_runProc::cash_paymentProcessing(void)
{
// run this function periodically while coin payment process to generate necessary signals:
// am 5.10.23 umgebaut, geht jetzt auch fuer MW. Für EMP und MW getestet
// 12.10.23: epi_store64BdevParameter() MUSS vorher aufgerufen werden zur Unterscheidung EMP / MW !!!!!
// return value:
// 0: stopped 1: starting up 2: coin collection
// 3: finished by User (Push button) 4: finished, Max-Value collected
// 5: finished by escrow
// 6: money encashed
// 7: cancelled
// 10,11: error cannot start
// 12: timeout while payment, coins returned
// 13: stopped by unexpected error
struct T_emp empStat;
struct T_changer chgrStat;
struct T_dynamicCondition myDynMachCond;
struct T_devices devParameter;
uint8_t collActiv=0, payInProg, empState, kcc;
uint32_t newSum;
if (hwapi_paymentStarted<1)
return 0; // off
collActiv=1; // starting up payment
devParameter.kindOfCoinChecker=0;
restoreDeviceParameter(&devParameter);
kcc=devParameter.kindOfCoinChecker;
/*
buf66[0]=devPara.kindOfPrinter;
buf66[1]=devPara.kindOfCoinChecker;
buf66[2]=devPara.kindOfMifareReader;
buf66[3]=devPara.suppressSleepMode;
buf66[4]=devPara.kindOfModem;
buf66[5]=devPara.kindOfCreditcard;
buf66[6]=devPara.CoinEscrow;
buf66[7]=devPara.CoinRejectUnit;
buf66[8]=devPara.CoinShutter;
buf66[9]=devPara.BillAcceptor;
buf66[10]=devPara.usevaultLock;
buf66[11]=devPara.autoAlarm;
buf66[12]=devPara.autoOpen;
buf66[13]=devPara.printAccReceipt;
buf66[14]=devPara.printDoorReceipt;
buf66[15]=devPara.printTokenTicket;
uitmp=devPara.VaultFullWarnLevel;
buf66[16]=swl_getOneByteFromUint(uitmp, GETLOWBYT);
buf66[17]=swl_getOneByteFromUint(uitmp, GETHIGHBYT);
uitmp=devPara.VaultFullErrorLevel;
buf66[18]=swl_getOneByteFromUint(uitmp, GETLOWBYT);
buf66[19]=swl_getOneByteFromUint(uitmp, GETHIGHBYT);
*/
if (kcc<3)
{
sub_emp_getAllParameters(&empStat);
empState=empStat.state;
} else
{
changer_getAllParameters(&chgrStat);
empState=chgrStat.state;
}
// 0=start command
// 1=powered, do emp ini, send reset
// 2=delay
// 3=wait for response, requesting status after response
// 4,5 through, startup
// 6: wait for status
// 7: through, startup
// 8: IDLE state. EMP is up and ready, polling is running
// 9: polling on, payment not yet on
// 10: payment, check coins
// 11: through
// 12: wait 1s for last coin
// 90: stop all, 1s delay
// 99: off, all stopped
sub_getDynMachineConditions(&myDynMachCond);
payInProg= myDynMachCond.paymentInProgress;
// 0: stopped by timeout
// 1: running 2: wait4lastCoin
// 3: payment stopped manually, coins in Escrow
// 4: payment stopped autom, amount collected, coins in Escrow
// 5: payment stopped, escrow full, coins in Escrow
// 6: coins encashed
// 7: coins returned 2 cases: due to cancel-button or printer-error
// 8: CoinChecker or MDB on Error
// qCritical() << "emitting signal payCancelled";
// emit runProc_payCancelled();
if (payInProg==8)
{
// coin checker faulty, cannot start
if (hwapi_paymentStarted==1)
{
hwapi_paymentStarted=90; // stop due to error
qCritical() << "emitting signal coinCollectionAborted 1";
emit runProc_coinCollectionAborted();
//sendFDcmd_set(156, 0,0, 2,0,0,0); // cancel payment
}
return 10; // error cannot start
}
if (empState>=10 && empState<=12 && (payInProg==1 || payInProg==2) )
{
// coin acceptance is active now:
if (hwapi_paymentStarted==1) // && (( payInProg==0) || ( payInProg>5))) //16.6.23
{ // 1=wait for coin checker being ready
hwapi_paymentStarted=2; // coins can be inserted now
qCritical() << "emitting signal coinCollectionJustStarted";
emit runProc_coinCollectionJustStarted();
}
}
if (hwapi_paymentStarted==2)
{
// coins can be inserted now, wait for end
collActiv=2; // coin collection active
newSum=epi_CurrentPaymentGetAmount();
if (newSum>hwapi_lastTotalAmount)
{
hwapi_lastTotalAmount=newSum;
qCritical() << "emitting signal gotNewCoin";
emit runProc_gotNewCoin();
}
if (payInProg==0) // timeout, coins returned by DC
{
hwapi_paymentStarted=90;
collActiv=12; // stop by timeout
qCritical() << "emitting signal payStopByTimeout";
emit runProc_payStopByTimeout();
} else
if (payInProg==3) // user pressed "Next/Continue", keep coin
{
hwapi_paymentStarted++;
collActiv=3;
qCritical() << "emitting signal payStopByPushbutton 1";
emit runProc_payStopByPushbutton();
} else
if (payInProg==4) // max achieved, keep coins
{
hwapi_paymentStarted++;
collActiv=4;
qCritical() << "emitting signal payStopByMax";
emit runProc_payStopByMax();
} else
if (payInProg==5) // escrow full, keep coins
{
hwapi_paymentStarted++;
collActiv=5;
qCritical() << "emitting signal payStopByEscrow";
emit runProc_payStopByEscrow();
}
/* 5.10.23 raus, geht auf 99 wenn Betrag erreicht, ist aber kein fehler
if ( (empState<10) || (empState>12)) // error
{
collActiv=13;
hwapi_paymentStarted=90;
qCritical() << "emitting signal payStopByError" << empState;
emit runProc_payStopByError();
} */
}
if (hwapi_paymentStarted==3)
{
// coin collection finished, but coins kept until printing done
collActiv=2;
if (payInProg==6) // coins encashed
{
collActiv=6;
hwapi_paymentStarted++;
qCritical() << "emitting signal coinProcessJustStopped";
emit runProc_coinProcessJustStopped();
} else
if (payInProg==7) // coins returned, printing failed
{
collActiv=7;
hwapi_paymentStarted++;
qCritical() << "emitting signal payCancelled";
emit runProc_payCancelled();
}
}
if (hwapi_paymentStarted==4)
{
// transaction finished
hwapi_paymentStarted=0;
}
//if ( (empState<8) || (empState>12))
// epi_clearCurrentPayment(); // to avoid wrong "got-coin" messages
if (hwapi_paymentStarted==90 )
{
// EMP error, wait till process finished
// everything stopped, no more coins in escrow
hwapi_paymentStarted=0;
}
return collActiv;
}
void T_runProc::sub_emp_getAllParameters(struct T_emp *emp)
{
uint8_t leng, data[66], ii, pp;
epi_restoreEmpSettings(&leng, data); // expected length = 64 byte
// get 64 bytes about EMP: see h-file
emp->gotSetup = data[0];
emp->state = data[1];
emp->shaft = data[2];
emp->countryCode= uchar2uint(data[4], data[3]);
emp->scale = data[5];
emp->decimals = data[6];
for (ii=0; ii<16; ii++)
emp->coinValues[ii] = data[7+ii];
emp->coinAccept = uchar2uint(data[24], data[23]);
emp->tokenChannel = data[25];
emp->pollingRunning = data[26];
emp->paymentRunning = data[27];
pp=28;
for (ii=0; ii<16; ii++)
{
emp->denomination[ii] = uchar2uint(data[pp+1], data[pp]);
pp+=2;
}
emp->routing= uchar2uint(data[61], data[60]);
}
void T_runProc::changer_getAllParameters(struct T_changer *mw)
{
// requested automatically with 23, same like EMP
uint8_t leng, data[66], pp, nn;
epi_restoreEmpSettings(&leng, data); // expected length = 64 byte
// get 64 bytes about Changer (mw), see interfaces.h-file
mw->setup = data[0];
mw->state = data[1];
mw->level = data[2];
mw->countryCode = uchar2uint(data[4], data[3]);
mw->scale = data[5];
mw->decimals= data[6];
for (nn=0; nn<16; nn++)
mw->coinSetup[nn]= data[nn+7]; // 7...22
mw->intendedAcceptance = uchar2uint(data[24], data[23]);
mw->tokenChannel= data[25];
mw->pollingRunning= data[26];
mw->paymentRunning= data[27];
pp=28;
for (nn=0; nn<16; nn++)
{
mw->denomination[nn] = uchar2uint(data[pp+1], data[pp]);
pp+=2;
}
// bis pp=60
mw->availableTubes = uchar2uint(data[61], data[60]);
}
void T_runProc::sub_getDynMachineConditions(struct T_dynamicCondition *dynMachCond)
{
uint16_t LL, nn;
char *start;
uint8_t buf[70], leng;
epi_restoreDynMachineConditions(&leng, buf);
// Puffer in struct eintragen:
LL=sizeof(struct T_dynamicCondition);
start = &dynMachCond->allDoorsDebounced;
nn=0;
do
{
*start = buf[nn];
start++;
} while(++nn<LL);
}
/*
static uint8_t Sdata_DeviceParameter[64];
static uint8_t Sdata_DevParaLen;
uint8_t T_runProc::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 T_runProc::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;
}
*/
void T_runProc::restoreDeviceParameter(struct T_devices *deviceSettings)
{
// attention: only applies if function "sys_sendDeviceParameter()" was used to send this settings before
// cannot be used to see settings programmed by JsonFile
uint8_t buf[64];
uint8_t LL, nn;
tslib_strclr(buf,0,64);
uint8_t *start;
//epi_restore64BdevParameter(&LL, buf); schmarrn
epi_restoreRbDeviceSettings(&LL, buf);
// Puffer in struct eintragen:
start = &deviceSettings->kindOfPrinter;
nn=0;
do
{
*start = buf[nn];
start++;
} while(++nn<LL);
}
bool T_runProc::doors_supervise(void)
{
// new from 2023.06.12, generate some signals:
//virtual void hwapi_ doorServiceDoorOpened(void) const=0;
//virtual void hwapi_ doorVaultDoorOpened(void) const=0;
//virtual void hwapi_ doorCBinAndAllDoorsClosed(void) const=0;
//virtual void hwapi_ doorAllDoorsClosed(void) const=0;
//virtual void hwapi_ doorCoinBoxRemoved(void) const=0;
//hwapi_lastDoorState: // bit0=1: upper door open bit1:middle bit2:lower bit3=1: cash-box out
struct T_dynamicCondition myDynMachCond;
uint8_t uctmp, doorTemp;
sub_getDynMachineConditions(&myDynMachCond);
//uint8_t CBinDebounced; // 0:fehlt 1:drin
//char upperDoor; // 99: undefined 0:closed 1:open
//char middleDoor; // 99: undefined 0:closed 1:open
//char lowerDoor; // 99: undefined 0:closed 1:open
//char billBox;
// PlausiCheck mit analogwerten:
if ( (myDynMachCond.U_Batt<8000) || (myDynMachCond.U_Batt>16000)) // 8...16V erlaubt
return false; // Fehler
if ((myDynMachCond.Temperatur<40) || (myDynMachCond.Temperatur>260)) // -30°C...80°C erleubt
return false; // Fehler
uctmp=(hwapi_lastDoorState & 1); // 0: upper door is closed
if (uctmp==0 && myDynMachCond.upperDoor>0)
{
hwapi_lastDoorState |= 1;
qCritical()<<"hwapi emitting signal ServiceDoorOpened";
emit runProc_doorServiceDoorOpened();
}
uctmp=(hwapi_lastDoorState & 2);
if (uctmp==0 && myDynMachCond.middleDoor>0)
{
hwapi_lastDoorState |= 2;
qCritical()<<"hwapi emitting signal VaultDoorOpened ";
emit runProc_doorVaultDoorOpened();
}
uctmp=(hwapi_lastDoorState & 4);
if (uctmp==0 && myDynMachCond.lowerDoor>0)
{
hwapi_lastDoorState |= 4;
qCritical()<<"hwapi emitting signal ServiceDoorOpened (Batt)";
emit runProc_doorServiceDoorOpened();
}
uctmp=(hwapi_lastDoorState & 8); // 0: cash box was in
if (uctmp==0 && myDynMachCond.CBinDebounced==0) // 0:fehlt 1:drin
{
// wurde gerade entnommen
hwapi_lastDoorState |= 8;
qCritical()<<"hwapi emitting signal CoinBoxRemoved ";
emit runProc_doorCoinBoxRemoved();
}
uctmp=(hwapi_lastDoorState & 8);
if (uctmp>0 && myDynMachCond.CBinDebounced>0) // 0:fehlt 1:drin
{
// war draussen, ist wieder drin
hwapi_lastDoorState &= ~0x08;
qCritical()<<"hwapi emitting signal CoinBoxInserted";
emit runProc_doorCoinBoxInserted();
}
uctmp=(hwapi_lastDoorState & 0x07);
doorTemp=0;
if (myDynMachCond.upperDoor>0) doorTemp |=1;
if (myDynMachCond.middleDoor>0) doorTemp |=2;
if (myDynMachCond.lowerDoor>0) doorTemp |=4;
if (uctmp>0 && doorTemp==0) // vorher war mind. EINE Tuer offen UND jetzt sind alle zu
{
hwapi_lastDoorState &= ~0x07;
// soeben wurde die letzte Tür geschlossen, prüfe ob Kasse eingesetzt wurde:
if (myDynMachCond.CBinDebounced)
{
qCritical()<<"hwapi emitting signal CBinAndAllDoorsClosed";
emit runProc_doorCBinAndAllDoorsClosed();
hwapi_lastDoorState &=~0x08; // keine Wirkung
} else
{
qCritical()<<"hwapi emitting signal AllDoorsClosed";
emit runProc_doorAllDoorsClosed();
}
}
return true;
}
uint8_t T_runProc::prn_getHwState(struct Tprn_hw_state *prn_hw_state)
{
// return printer hardware state: power is on? rs-driver on? rs_switch ok? hw-ready-line ok?
// printer on error or ok?
uint8_t prnHWstate[20];
epi_restorePrinterState(prnHWstate);
// byte 1...6 come right from printer, see printer manual
// byte 0 = all important infos:
// byte 0 = 0: prnter OK, >0: error
// bit0: paper low 1: no paper 2: temperature error
// 3: head open 4: paper jam in cutter
// 6: no response 7: bad response from printer
prn_hw_state->powerRdBk = epi_getDI_printerPwr();
prn_hw_state->rsSwOk = epi_getDO_serialMux1isSetToPrinter(); // mux1 off: serial is switched to printer
prn_hw_state->rsDrvOk = epi_getDO_serialDriverIsOn();
prn_hw_state->ReadyLine = epi_getDI_prnReady();
if (prnHWstate[0]==0)
prn_hw_state->inIdle = true; // no errors
else
prn_hw_state->inIdle = false; // off or errors
if (prnHWstate[0] & 1)
prn_hw_state->paperNearEnd=true;
else
prn_hw_state->paperNearEnd = false;
if (prnHWstate[0] & 2)
prn_hw_state->noPaper=true;
else
prn_hw_state->noPaper = false;
if (prnHWstate[0] & 4)
prn_hw_state->ErrorTemp=true;
else
prn_hw_state->ErrorTemp = false;
if (prnHWstate[0] & 8)
prn_hw_state->HeadOpen=true;
else
prn_hw_state->HeadOpen = false;
if (prnHWstate[0] & 16)
prn_hw_state->cutterJam=true;
else
prn_hw_state->cutterJam = false;
if (prnHWstate[0] & 64)
prn_hw_state->noResponse=true;
else
prn_hw_state->noResponse = false;
if (prnHWstate[0] & 128)
prn_hw_state->badResponse=true;
else
prn_hw_state->badResponse = false;
return prnHWstate[0];
}
void T_runProc::dc_autoRequest(bool on)
{
// automatically request ALL digital and analog sensors, get time/date, get status information
epi_startEmmision(on);
}
void T_runProc::bl_rebootDC(void)
{
// send command to normal DC-Program requesting a restart
// BL is working for 5s after power-on-reset.
uint8_t len, buf[20];
len=dcBL_restartDC(buf);
sendWRcmd_setSendBlock160(len, buf);
}
void T_runProc::bl_startBL(void)
{
// use this function within the first 5s after reboot to startup the BL,
// otherwise the BL jumps to normal DC application
uint8_t len, buf[20];
len=dcBL_activatBootloader(buf);
sendWRcmd_setSendBlock160(len, buf);
epi_setNowIsBootload(true);
}
void T_runProc::bl_checkBL(void)
{
// call this function in order to get information, afterwards use "bl_isUp()"
uint8_t len, buf[20];
len=dcBL_readFWversion(buf);
sendWRcmd_setSendBlock160(len, buf);
}
bool T_runProc::bl_isUp(void)
{
uint8_t receivedData[160];
uint8_t LL, nn;
for (nn=0; nn<160; nn++) receivedData[nn]=0;
LL=epi_getRawRecLength();
if (LL>0)
{
epi_getRawReceivedData(receivedData);
// response to "readFWversion"
if (receivedData[0]==2 && receivedData[1]==146 && receivedData[2]==45 &&
receivedData[3]==45 && receivedData[4] ==95 && receivedData[5]==176)
{
qDebug() << "got BL response to readFWversion";
epi_clrRawReceivedString();
return true;
}
// response to "start BL"
if (receivedData[0]==2 && receivedData[1]==101 && receivedData[2]==48 &&
receivedData[3]==223 && receivedData[4] ==131 )
{
qDebug() << "hwapi_bl_isUp: got BL response to start";
epi_clrRawReceivedString();
return true;
}
}
return false;
}
void T_runProc::bl_completeStart(void)
{
bl_startupStep=1;
}
bool T_runProc::bl_performComplStart(void)
{
// must be called cyclic by timer
static uint8_t retryCtr;
if ((bl_startupStep<1) || (bl_startupStep>10))
return false;
if (bl_startupStep==1)
{
dc_autoRequest(false);
bl_startupStep++;
} else
if (bl_startupStep==2)
{
bl_rebootDC();
hwapi_triggerBL->stop();
hwapi_triggerBL->start(1000); // call next step in 1s
retryCtr=0;
bl_startupStep++;
} else
if (bl_startupStep==3)
{
//qDebug()<<"starting BL";
bl_startBL();
hwapi_triggerBL->stop();
hwapi_triggerBL->start(100);
bl_startupStep++;
} else
if (bl_startupStep==4)
{
//if (!myTO->isActive())
//{
bl_checkBL();
hwapi_triggerBL->stop();
hwapi_triggerBL->start(100);
bl_startupStep++;
//}
} else
if (bl_startupStep==5)
{
hwapi_triggerBL->stop();
if (bl_isUp())
{
bl_startupStep=99;
// BL is up and running
} else
{
retryCtr++; // start again
if (retryCtr>=15)
{
bl_startupStep=99;
//qDebug()<<"BL error!!!";
} else
{
bl_startupStep=3;
//qDebug()<<"BL retry...";
}
}
}
return true;
}

811
src/sendWRcmd sm.cpp Executable file
View File

@ -0,0 +1,811 @@
#include <stdint.h>
#include <QString>
#include <QDebug>
#include <QDateTime>
#include "tslib.h"
#include "sendWRcmd.h"
#include "shared_mem_buffer.h"
void indat_PrnPwr(void);
void sendWRcmd_INI(void)
{
sendWRcmd_clrCmdStack();
sendWRcmd_clrCmd4Stack();
sendFDcmd_clrStack();
}
// Command Stack for commands without parameters
//static uint16_t nextAsynchsendCmd0[CMDSTACKDEPTH];
//static uint8_t nrOfCmdsInQueue;
/* convention: use simple (not rotating) FIFO Stack:
Example: nrOfCmdsInQueue=4 then
nextAsynchsendCmd0[0]=cmd1 // was stored as first
nextAsynchsendCmd0[1]=cmd2
nextAsynchsendCmd0[2]=cmd3
nextAsynchsendCmd0[3]=cmd4 // came in as last
Send: [0] first, then move buffer 1 down:
nextAsynchsendCmd0[0]=cmd2
nextAsynchsendCmd0[1]=cmd3
nextAsynchsendCmd0[2]=cmd4
nextAsynchsendCmd0[3]=0;
nrOfCmdsInQueue=3 now
*/
void sendWRcmd_clrCmdStack(void)
{
uint8_t nn;
for (nn=0; nn<CMDSTACKDEPTH; nn++)
SharedMem::write()->nextAsynchsendCmd0[nn]=0;
SharedMem::write()->nrOfCmdsInQueue=0;
}
bool sendWRcmd_setSendCommand0(uint16_t nextCmd)
{
// write Command to memory, wait for transport
uint8_t ciq=SharedMem::read()->nrOfCmdsInQueue;
if (ciq>=CMDSTACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextAsynchsendCmd0[ciq++]=nextCmd;
SharedMem::write()->nrOfCmdsInQueue=ciq;
//qDebug() << "PI cmd queued:"<< nextCmd << ", saved, pp=" << nrOfCmdsInQueue;
return true; // ok, will be sent
}
uint16_t sendWRcmd_getSendCommand0(void)
{
uint16_t nxtAsynchCmd, data;
uint8_t nn, ll;
uint8_t ciq=SharedMem::read()->nrOfCmdsInQueue;
if (ciq==0 || ciq>CMDSTACKDEPTH)
return 0; // error
nxtAsynchCmd=SharedMem::read()->nextAsynchsendCmd0[0];
// move Puffer down by one element
if (ciq>0)
ll=ciq-1;
else
ll=0;
for (nn=0; nn<ll; nn++)
{
data=SharedMem::read()->nextAsynchsendCmd0[nn+1];
SharedMem::write()->nextAsynchsendCmd0[nn]=data;
}
SharedMem::write()->nrOfCmdsInQueue=ciq;
//qDebug() << "PI cmd queued:"<< nxtAsynchCmd << ", restored, pp now =" << nrOfCmdsInQueue;
return nxtAsynchCmd;
}
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
// Command Stack for commands with 4 parameters
/*
static uint16_t nextAsynchsendCmd4[CMD4STACKDEPTH];
static uint8_t nextCmd4para1[CMD4STACKDEPTH];
static uint8_t nextCmd4para2[CMD4STACKDEPTH];
static uint8_t nextCmd4para3[CMD4STACKDEPTH];
static uint8_t nextCmd4para4[CMD4STACKDEPTH];
static uint8_t nrOfCmds4InQueue;
*/
void sendWRcmd_clrCmd4Stack(void)
{
uint8_t nn;
for (nn=0; nn<CMD4STACKDEPTH; nn++)
{
SharedMem::write()->nextAsynchsendCmd4[nn]=0;
SharedMem::write()->nextCmd4para1[nn]=0;
SharedMem::write()->nextCmd4para2[nn]=0;
SharedMem::write()->nextCmd4para3[nn]=0;
SharedMem::write()->nextCmd4para4[nn]=0;
}
SharedMem::write()->nrOfCmds4InQueue=0;
}
bool sendWRcmd_setSendCommand4(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4)
{
// write Command to memory, wait for transport
uint8_t ciq;
ciq=SharedMem::read()->nrOfCmds4InQueue;
if (ciq>=CMD4STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextAsynchsendCmd4[ciq]=nextCmd;
SharedMem::write()->nextCmd4para1[ciq]=dat1;
SharedMem::write()->nextCmd4para2[ciq]=dat2;
SharedMem::write()->nextCmd4para3[ciq]=dat3;
SharedMem::write()->nextCmd4para4[ciq]=dat4;
ciq++;
SharedMem::write()->nrOfCmds4InQueue=ciq;
//qDebug() << QDateTime::currentDateTime().time()
// << "sendWRcmd 4 byte saved, pp=" << nextCmd
// << " para: " << SharedMem::getDataConst()->nextCmd4para1[pp];
return true; // ok, will be sent
}
/*
uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4)
{
uint16_t nxtAsynchCmd;
uint8_t nn, ll;
if (nrOfCmds4InQueue==0 || nrOfCmds4InQueue>CMD4STACKDEPTH)
return 0; // error
nxtAsynchCmd=nextAsynchsendCmd4[0];
*dat1=nextCmd4para1[0];
*dat2=nextCmd4para2[0];
*dat3=nextCmd4para3[0];
*dat4=nextCmd4para4[0];
//qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue;
//qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] <<
// " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0];
// move Puffer down by one element
if (CMD4STACKDEPTH>0)
ll=CMD4STACKDEPTH-1;
else
ll=0;
for (nn=0; nn<ll; nn++)
{
nextAsynchsendCmd4[nn]=nextAsynchsendCmd4[nn+1];
nextCmd4para1[nn]=nextCmd4para1[nn+1];
nextCmd4para2[nn]=nextCmd4para2[nn+1];
nextCmd4para3[nn]=nextCmd4para3[nn+1];
nextCmd4para4[nn]=nextCmd4para4[nn+1];
}
if (nrOfCmds4InQueue>0)
nrOfCmds4InQueue--;
//qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue;
return nxtAsynchCmd;
}
*/
uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4)
{
uint16_t nxtAsynchCmd, data;
uint8_t nn;
uint8_t ciq=SharedMem::read()->nrOfCmds4InQueue;
if (ciq==0 || ciq > CMD4STACKDEPTH)
return 0; // error
nxtAsynchCmd=SharedMem::read()->nextAsynchsendCmd4[0];
*dat1=SharedMem::read()->nextCmd4para1[0];
*dat2=SharedMem::read()->nextCmd4para2[0];
*dat3=SharedMem::read()->nextCmd4para3[0];
*dat4=SharedMem::read()->nextCmd4para4[0];
//qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue;
//qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] <<
// " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0];
// move Puffer down by one element
if (ciq>0) ciq--;
for (nn=0; nn<ciq; nn++)
{
data=SharedMem::read()->nextAsynchsendCmd4[nn+1];
SharedMem::write()->nextAsynchsendCmd4[nn]=data;
data=SharedMem::read()->nextCmd4para1[nn+1];
SharedMem::write()->nextCmd4para1[nn]=data;
data=SharedMem::read()->nextCmd4para2[nn+1];
SharedMem::write()->nextCmd4para2[nn]=data;
data=SharedMem::read()->nextCmd4para3[nn+1];
SharedMem::write()->nextCmd4para3[nn]=data;
data=SharedMem::read()->nextCmd4para4[nn+1];
SharedMem::write()->nextCmd4para4[nn]=data;
}
SharedMem::write()->nrOfCmds4InQueue=ciq;
return nxtAsynchCmd;
}
void sendWRcmd_clrCmd8Stack(void)
{
uint8_t nn;
for (nn=0; nn<CMD8STACKDEPTH; nn++)
{
SharedMem::write()->nextAsynchsendCmd8[nn]=0;
SharedMem::write()->nextCmd8para1[nn]=0;
SharedMem::write()->nextCmd8para2[nn]=0;
SharedMem::write()->nextCmd8para3[nn]=0;
SharedMem::write()->nextCmd8para4[nn]=0;
}
SharedMem::write()->nrOfCmds8InQueue=0;
}
bool sendWRcmd_setSendCommand8(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint16_t dat3, uint32_t dat4)
{
// write Command to memory, wait for transport
uint8_t ciq;
ciq=SharedMem::read()->nrOfCmds8InQueue;
if (ciq>=CMD8STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextAsynchsendCmd8[ciq]=nextCmd;
SharedMem::write()->nextCmd8para1[ciq]=dat1;
SharedMem::write()->nextCmd8para2[ciq]=dat2;
SharedMem::write()->nextCmd8para3[ciq]=dat3;
SharedMem::write()->nextCmd8para4[ciq]=dat4;
ciq++;
SharedMem::write()->nrOfCmds8InQueue=ciq;
return true; // ok, will be sent
}
uint16_t sendWRcmd_getSendCommand8(uint8_t *dat1, uint8_t *dat2, uint16_t *dat3, uint32_t *dat4)
{
uint16_t nxtAsynchCmd, data;
uint8_t nn;
uint8_t ciq=SharedMem::read()->nrOfCmds8InQueue;
if (ciq==0 || ciq > CMD8STACKDEPTH)
return 0; // error
nxtAsynchCmd=SharedMem::read()->nextAsynchsendCmd8[0];
*dat1=SharedMem::read()->nextCmd8para1[0];
*dat2=SharedMem::read()->nextCmd8para2[0];
*dat3=SharedMem::read()->nextCmd8para3[0];
*dat4=SharedMem::read()->nextCmd8para4[0];
// move buffer down by one element
if (ciq>0) ciq--;
for (nn=0; nn<ciq; nn++)
{
data=SharedMem::read()->nextAsynchsendCmd8[nn+1];
SharedMem::write()->nextAsynchsendCmd8[nn]=data;
data=SharedMem::read()->nextCmd8para1[nn+1];
SharedMem::write()->nextCmd8para1[nn]=data;
data=SharedMem::read()->nextCmd8para2[nn+1];
SharedMem::write()->nextCmd8para2[nn]=data;
data=SharedMem::read()->nextCmd8para3[nn+1];
SharedMem::write()->nextCmd8para3[nn]=data;
data=SharedMem::read()->nextCmd8para4[nn+1];
SharedMem::write()->nextCmd8para4[nn]=data;
}
SharedMem::write()->nrOfCmds8InQueue=ciq;
return nxtAsynchCmd;
}
//static uint8_t sendAsynchDataBuf[160]; // no stack, only ONE buffer
//static uint8_t sendAsyDatLen;
bool sendWRcmd_setSendBlock160(uint8_t leng, uint8_t *buf)
{
if (leng>SENDASYDAT_BUFFSIZE) leng=SENDASYDAT_BUFFSIZE;
SharedMem::write()->sendAsyDatLen=leng;
tslib_strclr(SharedMem::write()->sendAsynchDataBuf, 0, SENDASYDAT_BUFFSIZE);
for (uint8_t nn=0; nn<leng; nn++)
SharedMem::write()->sendAsynchDataBuf[nn]=buf[nn];
return true; // ok, will be sent
}
uint8_t sendWRcmd_getSendBlock160(uint8_t *leng, uint8_t *buf)
{
uint8_t dl=SharedMem::read()->sendAsyDatLen;
*leng=dl;
for (uint8_t nn=0; nn<dl; nn++)
buf[nn]=SharedMem::read()->sendAsynchDataBuf[nn];
SharedMem::write()->sendAsyDatLen=0;
//tslib_strclr(SharedMem::write()->sendAsynchDataBuf, 0, SENDASYDAT_BUFFSIZE);
return *leng;
}
// ------------------------------------------------------------------------------------
// MDB Sendind Data are store here for next transport to DC (Device Controller)
// Transport to Slave runs every 100ms, answer from mdb-slave (e.g. coin changer) comes rigth
// with next slave answer
// start with: SENDDIRCMD_EXCHGMDB,
// send crude data from here to DC, DC to mdb slaves, mdb answer, return here within 50ms
//static uint8_t Sdata_mdbSendBuffer[MDBSEND_BUFFSIZE];
//static uint8_t Sdata_mdbSendLen;
uint8_t epi_store64ByteSendData(uint8_t length, uint8_t *buf)
{
if (length>MDBSEND_BUFFSIZE) length=MDBSEND_BUFFSIZE;
// HWapi writes data to be forwarded to DC and further to mdb-device
for (uint8_t nn=0; nn<length; nn++)
SharedMem::write()->Sdata_mdbSendBuffer[nn]=buf[nn];
SharedMem::write()->Sdata_mdbSendLen=length;
return 0;
}
uint8_t gpi_restore64ByteSendData(uint8_t *length, uint8_t *buf)
{
// datif reads data to forward to dc
uint8_t dl=SharedMem::read()->Sdata_mdbSendLen;
for (uint8_t nn=0; nn<dl; nn++)
buf[nn]=SharedMem::read()->Sdata_mdbSendBuffer[nn];
*length=dl;
SharedMem::write()->Sdata_mdbSendLen=0;
return 0;
}
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
//---------------------------------------- Printer Text Fifo -------------------------
//static uint8_t prnDataParameters[];
//static uint8_t prnDataBufferUser;
void epi_storeUserOfSendingTextBuffer(uint8_t user, uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4 )
{
// user=1: Text-Print is using this buffer
// 2: QR-code-Printer is using this buffer
SharedMem::write()->prnDataBufferUser=user;
SharedMem::write()->prnDataParameters[0]=para1;
SharedMem::write()->prnDataParameters[1]=para2;
SharedMem::write()->prnDataParameters[2]=para3;
SharedMem::write()->prnDataParameters[3]=para4;
// qDebug() << "new user stored: " << user;
}
uint8_t gpi_getUserOfSendingTextBuffer(uint8_t *para1, uint8_t *para2, uint8_t *para3, uint8_t *para4)
{
// user=1: Text-Print is using this buffer
// 2: QR-code-Printer is using this buffer
//qDebug() << "returning user "<< prnDataBufferUser;
*para1=SharedMem::read()->prnDataParameters[0];
*para2=SharedMem::read()->prnDataParameters[1];
*para3=SharedMem::read()->prnDataParameters[2];
*para4=SharedMem::read()->prnDataParameters[3];
return SharedMem::read()->prnDataBufferUser;
}
// Sending Text Fifo
// ONE printer doc consists of 20 x 64 byte
// #define MAXNROF_PRNBYTES 64
// #define MAXNROF_PRNBLOCKS 20
//static char Sdata_PRN_TEXT[MAXNROF_PRNBLOCKS][MAXNROF_PRNBYTES];
//static uint8_t pPrnDataBuff; // points to next PRINTER_BLOCK
//static uint8_t pPrnDataBuff; // points to next waiting printer text
// defined above, needed if more then one text is stored (before sent)
// every block will be sent after 100ms, if 8 blocks are stored within this 100ms
// then pointer goes up to 8. Important: FIFO!!!!!!!!
void epi_resetPrinterStack(void)
{
SharedMem::write()->pPrnDataBuff=0;
}
uint8_t epi_storePrnText(char *buf, uint8_t leng)
{
// store text from Gui in next higher free memory 0....9
uint16_t len;
uint8_t pp, nn;
pp=SharedMem::read()->pPrnDataBuff; // next free memory block with 64byte each
if (pp>=MAXNROF_PRNBLOCKS)
return 1; // not possible, no free mem
//len=tslib_strlen(buf); // kennt keine Binärzeichen!!!!!!
len=leng;
if (len>MAXNROF_PRNBYTES)
len=MAXNROF_PRNBYTES;
tslib_strclr(SharedMem::write()->Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES);
for (nn=0; nn<len; nn++)
SharedMem::write()->Sdata_PRN_TEXT[pp][nn]=buf[nn]; // copy new text into buffer
if (SharedMem::read()->pPrnDataBuff<MAXNROF_PRNBLOCKS)
SharedMem::write()->pPrnDataBuff++; // inc pointer if end not yet reached
return 0; // OK
}
uint8_t gpi_restorePrnText(uint8_t *retbuf)
{
// read printer text and send to slave, size of retbuf == 64
// always read from [0] because this is the oldest (Fifo)
// then move all text lines down by one and dec pointer
uint8_t nn, mm, pp=SharedMem::read()->pPrnDataBuff;
char buf[MAXNROF_PRNBYTES];
if (pp==0) // next free memory block with 64byte each
return 1; // no text in buffer
// example: pp=5: then buffers [0...4] are occupied
for (nn=0; nn<MAXNROF_PRNBYTES; nn++)
retbuf[nn] = uint8_t (SharedMem::read()->Sdata_PRN_TEXT[0][nn]); // restore oldest text
// now copy textline [1] to [0], then
// copy textline [2] to [1], then
// copy textline [3] to [2] .... upto [pp-1] to [pp-2]
// hint: copying from 9....0 would delete all strings!!!!!!
for (nn=0; nn<(pp-1); nn++)
{
for (mm=0; mm<MAXNROF_PRNBYTES; mm++)
buf[mm]=SharedMem::read()->Sdata_PRN_TEXT[nn+1][mm];
for (mm=0; mm<MAXNROF_PRNBYTES; mm++)
SharedMem::write()->Sdata_PRN_TEXT[nn][mm]=buf[mm];
}
if (pp>0) pp--;
SharedMem::write()->pPrnDataBuff=pp;
// example: pp=4: then buffers [0...3] are still occupied, pp=0: all buffers empty
// now clear highest copyed line (which became free now)
tslib_strclr(SharedMem::write()->Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES);
// optionally: clear all remaining higher lines:
for (nn=(pp+1); nn<MAXNROF_PRNBLOCKS; nn++)
tslib_strclr(SharedMem::write()->Sdata_PRN_TEXT[nn], 0, MAXNROF_PRNBYTES);
return 0;
}
uint8_t gpi_chk4remainingText(void)
{
// retval: 0: no more textline left (to send) >0: nr of 64byte-blocks
return (SharedMem::read()->pPrnDataBuff);
}
// ---------------------------------------------------------------------------------
// 11.4.23 neu, Kommando direkt an "FastDevice"-protokoll senden, nicht mehr umsetzen
// ---------------------------------------------------------------------------------
/*
// 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];
// long 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
nextAsynchsendCmd0[1]=cmd2
nextAsynchsendCmd0[2]=cmd3
nextAsynchsendCmd0[3]=cmd4 // came in as last
Send: [0] first, then move buffer 1 down:
nextAsynchsendCmd0[0]=cmd2
nextAsynchsendCmd0[1]=cmd3
nextAsynchsendCmd0[2]=cmd4
nextAsynchsendCmd0[3]=0;
nrOfCmdsInQueue=3 now
*/
void sendFDcmd_clrStack(void)
{
uint8_t nn;
for (nn=0; nn<FDCMD_STACKDEPTH; nn++)
{
SharedMem::write()->nextFDwrCmd[nn]=0;
SharedMem::write()->nextFDrdCmd[nn]=0;
SharedMem::write()->nextFDblkNr[nn]=0;
SharedMem::write()->nextFDshort[nn]=0;
SharedMem::write()->nextFDpara1[nn]=0;
SharedMem::write()->nextFDpara2[nn]=0;
SharedMem::write()->nextFDpara3[nn]=0;
SharedMem::write()->nextFDpara4[nn]=0;
SharedMem::write()->longFDlength[nn]=0;
memset(&SharedMem::write()->longFDpara[nn][0],0,64);
}
SharedMem::write()->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
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd >=FDCMD_STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextFDwrCmd[pFDcmd]=nextWrCmd;
SharedMem::write()->nextFDrdCmd[pFDcmd]=nextRdCmd;
SharedMem::write()->nextFDblkNr[pFDcmd]=blockNum;
SharedMem::write()->nextFDpara1[pFDcmd]=dat1;
SharedMem::write()->nextFDpara2[pFDcmd]=dat2;
SharedMem::write()->nextFDpara3[pFDcmd]=dat3;
SharedMem::write()->nextFDpara4[pFDcmd]=dat4;
//qDebug() << "data with 4 data byte saved, pp=" << pFDcmd;
//qDebug() << " dat1=" << nextCmd4para1[pFDcmd] << " dat2=" << nextCmd4para2[pFDcmd]
// << " dat3=" << nextCmd4para3[pFDcmd] << " dat4=" << nextCmd4para4[pFDcmd];
SharedMem::write()->nextFDshort[pFDcmd]=1; // 1=short
pFDcmd++;
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
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;
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd>=FDCMD_STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextFDwrCmd[pFDcmd]=nextWrCmd;
SharedMem::write()->nextFDrdCmd[pFDcmd]=nextRdCmd;
SharedMem::write()->nextFDblkNr[pFDcmd]=blockNum;
SharedMem::write()->longFDlength[pFDcmd]=length;
for (nn=0; nn<64; nn++)
SharedMem::write()->longFDpara[pFDcmd][nn]=data[nn];
SharedMem::write()->nextFDshort[pFDcmd]=2;
pFDcmd++;
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
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, mm, data; // ll
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd==0 || pFDcmd>FDCMD_STACKDEPTH)
return false; // not possible
*nextWrCmd=SharedMem::read()->nextFDwrCmd[0];
*nextRdCmd=SharedMem::read()->nextFDrdCmd[0];
*blockNum=SharedMem::read()->nextFDblkNr[0];
*dat1=SharedMem::read()->nextFDpara1[0];
*dat2=SharedMem::read()->nextFDpara2[0];
*dat3=SharedMem::read()->nextFDpara3[0];
*dat4=SharedMem::read()->nextFDpara4[0];
//qDebug() << "sendFDcmd_get [0]; pp=" << SharedMem::read()->p_nextFDcmdsInQueue;
//qDebug() << " data1: " << SharedMem::read()->nextCmd4para1[0] << " data2: " << SharedMem::read()->nextCmd4para2[0] <<
// " data3: " << SharedMem::read()->nextCmd4para3[0] << " data4: " << SharedMem::read()->nextCmd4para4[0];
// move Puffer down by one element
//if (FDCMD_STACKDEPTH>0)
// ll=FDCMD_STACKDEPTH-1;
//else
// ll=0;
if (pFDcmd>0) pFDcmd--; else pFDcmd=0;
//for (nn=0; nn<ll; nn++)
for (nn=0; nn<pFDcmd; nn++)
{
data=SharedMem::read()->nextFDwrCmd[nn+1];
SharedMem::write()->nextFDwrCmd[nn]=data;
data=SharedMem::read()->nextFDrdCmd[nn+1];
SharedMem::write()->nextFDrdCmd[nn]=data;
data=SharedMem::read()->nextFDblkNr[nn+1];
SharedMem::write()->nextFDblkNr[nn]=data;
data=SharedMem::read()->nextFDpara1[nn+1];
SharedMem::write()->nextFDpara1[nn]=data;
data=SharedMem::read()->nextFDpara2[nn+1];
SharedMem::write()->nextFDpara2[nn]=data;
data=SharedMem::read()->nextFDpara3[nn+1];
SharedMem::write()->nextFDpara3[nn]=data;
data=SharedMem::read()->nextFDpara4[nn+1];
SharedMem::write()->nextFDpara4[nn]=data;
data=SharedMem::read()->nextFDshort[nn+1];
SharedMem::write()->nextFDshort[nn] = data;
data=SharedMem::read()->longFDlength[nn+1];
SharedMem::write()->longFDlength[nn] = data;
for (mm=0; mm<64; mm++)
{
SharedMem::write()->longFDpara[nn][mm] = SharedMem::read()->longFDpara[nn+1][mm];
}
}
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
//qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue;
// clear released buffer:
//for (nn=p_nextFDcmdsInQueue; nn<FDCMD_STACKDEPTH; nn++)
//{
SharedMem::write()->nextFDwrCmd[pFDcmd]=0;
SharedMem::write()->nextFDrdCmd[pFDcmd]=0;
SharedMem::write()->nextFDblkNr[pFDcmd]=0;
SharedMem::write()->nextFDpara1[pFDcmd]=0;
SharedMem::write()->nextFDpara2[pFDcmd]=0;
SharedMem::write()->nextFDpara3[pFDcmd]=0;
SharedMem::write()->nextFDpara4[pFDcmd]=0;
SharedMem::write()->nextFDshort[pFDcmd]=0;
SharedMem::write()->longFDlength[pFDcmd]=0;
for (mm=0; mm<64; mm++)
SharedMem::write()->longFDpara[pFDcmd][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 (SharedMem::read()->p_nextFDcmdsInQueue==0)
return 0;
if (SharedMem::read()->nextFDshort[0]==1)
return 1;
return 2;
}
uint8_t check4FDshortCmd(void)
{
// returns number of waiting command, max FDCMD_STACKDEPTH
return SharedMem::read()->p_nextFDcmdsInQueue;
}
uint8_t check4freeFDshortCmd(void)
{
// returns number of free places in short-command stack
return FDCMD_STACKDEPTH - SharedMem::read()->p_nextFDcmdsInQueue;
}
bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data)
{
uint8_t nn, mm, uctmp;
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd==0 || pFDcmd>FDCMD_STACKDEPTH)
return false; // not possible
*nextWrCmd=SharedMem::read()->nextFDwrCmd[0];
*nextRdCmd=SharedMem::read()->nextFDrdCmd[0];
*blockNum=SharedMem::read()->nextFDblkNr[0];
*length = SharedMem::read()->longFDlength[0];
for (mm=0; mm<64; mm++)
data[mm] = SharedMem::read()->longFDpara[0][mm];
if (pFDcmd>0) pFDcmd--; else pFDcmd=0;
//for (nn=0; nn<ll; nn++)
for (nn=0; nn<pFDcmd; nn++)
{
uctmp=SharedMem::read()->nextFDwrCmd[nn+1];
SharedMem::write()->nextFDwrCmd[nn]=uctmp;
uctmp=SharedMem::read()->nextFDrdCmd[nn+1];
SharedMem::write()->nextFDrdCmd[nn]=uctmp;
uctmp=SharedMem::read()->nextFDblkNr[nn+1];
SharedMem::write()->nextFDblkNr[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara1[nn+1];
SharedMem::write()->nextFDpara1[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara2[nn+1];
SharedMem::write()->nextFDpara2[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara3[nn+1];
SharedMem::write()->nextFDpara3[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara4[nn+1];
SharedMem::write()->nextFDpara4[nn]=uctmp;
uctmp=SharedMem::read()->nextFDshort[nn+1];
SharedMem::write()->nextFDshort[nn]=uctmp;
uctmp=SharedMem::read()->longFDlength[nn+1];
SharedMem::write()->longFDlength[nn]=uctmp;
for (mm=0; mm<64; mm++)
{
SharedMem::write()->longFDpara[nn][mm] = SharedMem::read()->longFDpara[nn+1][mm];
}
}
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
// clear released buffer:
SharedMem::write()->nextFDwrCmd[pFDcmd]=0;
SharedMem::write()->nextFDrdCmd[pFDcmd]=0;
SharedMem::write()->nextFDblkNr[pFDcmd]=0;
SharedMem::write()->nextFDpara1[pFDcmd]=0;
SharedMem::write()->nextFDpara2[pFDcmd]=0;
SharedMem::write()->nextFDpara3[pFDcmd]=0;
SharedMem::write()->nextFDpara4[pFDcmd]=0;
SharedMem::write()->nextFDshort[pFDcmd]=0;
SharedMem::write()->longFDlength[pFDcmd]=0;
for (mm=0; mm<64; mm++)
SharedMem::write()->longFDpara[pFDcmd][mm] = 0;
return true; // ok, will be sent
}

842
src/sendWRcmd.cpp Normal file
View File

@ -0,0 +1,842 @@
#include <stdint.h>
#include <QString>
#include <QDebug>
#include <QDateTime>
#include "tslib.h"
#include "sendWRcmd.h"
#include "shared_mem_buffer.h"
void indat_PrnPwr(void);
void sendWRcmd_INI(void)
{
//sendWRcmd_clrCmdStack();
//sendWRcmd_clrCmd4Stack();
sendFDcmd_clrStack();
}
// Command Stack for commands without parameters
//static uint16_t nextAsynchsendCmd0[CMDSTACKDEPTH];
//static uint8_t nrOfCmdsInQueue;
/* convention: use simple (not rotating) FIFO Stack:
Example: nrOfCmdsInQueue=4 then
nextAsynchsendCmd0[0]=cmd1 // was stored as first
nextAsynchsendCmd0[1]=cmd2
nextAsynchsendCmd0[2]=cmd3
nextAsynchsendCmd0[3]=cmd4 // came in as last
Send: [0] first, then move buffer 1 down:
nextAsynchsendCmd0[0]=cmd2
nextAsynchsendCmd0[1]=cmd3
nextAsynchsendCmd0[2]=cmd4
nextAsynchsendCmd0[3]=0;
nrOfCmdsInQueue=3 now
*/
void sendWRcmd_clrCmdStack(void)
{
uint8_t nn;
for (nn=0; nn<CMDSTACKDEPTH; nn++)
SharedMem::write()->nextAsynchsendCmd0[nn]=0;
SharedMem::write()->nrOfCmdsInQueue=0;
}
bool sendWRcmd_setSendCommand0(uint16_t nextCmd)
{
// write Command to memory, wait for transport
uint8_t ciq=SharedMem::read()->nrOfCmdsInQueue;
if (ciq>=CMDSTACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextAsynchsendCmd0[ciq++]=nextCmd;
SharedMem::write()->nrOfCmdsInQueue=ciq;
//qDebug() << "PI cmd queued:"<< nextCmd << ", saved, pp=" << nrOfCmdsInQueue;
return true; // ok, will be sent
}
uint16_t sendWRcmd_getSendCommand0(void)
{
uint16_t nxtAsynchCmd, data;
uint8_t nn;
uint8_t ciq=SharedMem::read()->nrOfCmdsInQueue;
if (ciq==0 || ciq>CMDSTACKDEPTH)
return 0; // error
nxtAsynchCmd=SharedMem::read()->nextAsynchsendCmd0[0];
// move Puffer down by one element
if (ciq>0) ciq--;
for (nn=0; nn<ciq; nn++)
{
data=SharedMem::read()->nextAsynchsendCmd0[nn+1];
SharedMem::write()->nextAsynchsendCmd0[nn]=data;
}
SharedMem::write()->nrOfCmdsInQueue=ciq;
//qDebug() << "PI cmd queued:"<< nxtAsynchCmd << ", restored, pp now =" << nrOfCmdsInQueue;
return nxtAsynchCmd;
}
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
// Command Stack for commands with 4 parameters
/*
static uint16_t nextAsynchsendCmd4[CMD4STACKDEPTH];
static uint8_t nextCmd4para1[CMD4STACKDEPTH];
static uint8_t nextCmd4para2[CMD4STACKDEPTH];
static uint8_t nextCmd4para3[CMD4STACKDEPTH];
static uint8_t nextCmd4para4[CMD4STACKDEPTH];
static uint8_t nrOfCmds4InQueue;
*/
/*
void sendWRcmd_clrCmd4Stack(void)
{
uint8_t nn;
for (nn=0; nn<CMD4STACKDEPTH; nn++)
{
SharedMem::write()->nextAsynchsendCmd4[nn]=0;
SharedMem::write()->nextCmd4para1[nn]=0;
SharedMem::write()->nextCmd4para2[nn]=0;
SharedMem::write()->nextCmd4para3[nn]=0;
SharedMem::write()->nextCmd4para4[nn]=0;
}
SharedMem::write()->nrOfCmds4InQueue=0;
}
bool sendWRcmd_setSendCommand4(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4)
{
// write Command to memory, wait for transport
uint8_t ciq;
ciq=SharedMem::read()->nrOfCmds4InQueue;
if (ciq>=CMD4STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextAsynchsendCmd4[ciq]=nextCmd;
SharedMem::write()->nextCmd4para1[ciq]=dat1;
SharedMem::write()->nextCmd4para2[ciq]=dat2;
SharedMem::write()->nextCmd4para3[ciq]=dat3;
SharedMem::write()->nextCmd4para4[ciq]=dat4;
ciq++;
SharedMem::write()->nrOfCmds4InQueue=ciq;
//qDebug() << QDateTime::currentDateTime().time()
// << "sendWRcmd 4 byte saved, pp=" << nextCmd
// << " para: " << SharedMem::getDataConst()->nextCmd4para1[pp];
return true; // ok, will be sent
}
*/
/*
uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4)
{
uint16_t nxtAsynchCmd;
uint8_t nn, ll;
if (nrOfCmds4InQueue==0 || nrOfCmds4InQueue>CMD4STACKDEPTH)
return 0; // error
nxtAsynchCmd=nextAsynchsendCmd4[0];
*dat1=nextCmd4para1[0];
*dat2=nextCmd4para2[0];
*dat3=nextCmd4para3[0];
*dat4=nextCmd4para4[0];
//qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue;
//qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] <<
// " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0];
// move Puffer down by one element
if (CMD4STACKDEPTH>0)
ll=CMD4STACKDEPTH-1;
else
ll=0;
for (nn=0; nn<ll; nn++)
{
nextAsynchsendCmd4[nn]=nextAsynchsendCmd4[nn+1];
nextCmd4para1[nn]=nextCmd4para1[nn+1];
nextCmd4para2[nn]=nextCmd4para2[nn+1];
nextCmd4para3[nn]=nextCmd4para3[nn+1];
nextCmd4para4[nn]=nextCmd4para4[nn+1];
}
if (nrOfCmds4InQueue>0)
nrOfCmds4InQueue--;
//qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue;
return nxtAsynchCmd;
}
*/
/*
uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4)
{
uint16_t nxtAsynchCmd, data;
uint8_t nn;
uint8_t ciq=SharedMem::read()->nrOfCmds4InQueue;
if (ciq==0 || ciq > CMD4STACKDEPTH)
return 0; // error
nxtAsynchCmd=SharedMem::read()->nextAsynchsendCmd4[0];
*dat1=SharedMem::read()->nextCmd4para1[0];
*dat2=SharedMem::read()->nextCmd4para2[0];
*dat3=SharedMem::read()->nextCmd4para3[0];
*dat4=SharedMem::read()->nextCmd4para4[0];
//qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue;
//qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] <<
// " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0];
// move Puffer down by one element
if (ciq>0) ciq--;
for (nn=0; nn<ciq; nn++)
{
data=SharedMem::read()->nextAsynchsendCmd4[nn+1];
SharedMem::write()->nextAsynchsendCmd4[nn]=data;
data=SharedMem::read()->nextCmd4para1[nn+1];
SharedMem::write()->nextCmd4para1[nn]=data;
data=SharedMem::read()->nextCmd4para2[nn+1];
SharedMem::write()->nextCmd4para2[nn]=data;
data=SharedMem::read()->nextCmd4para3[nn+1];
SharedMem::write()->nextCmd4para3[nn]=data;
data=SharedMem::read()->nextCmd4para4[nn+1];
SharedMem::write()->nextCmd4para4[nn]=data;
}
SharedMem::write()->nrOfCmds4InQueue=ciq;
return nxtAsynchCmd;
}
*/
/*
void sendWRcmd_clrCmd8Stack(void)
{
uint8_t nn;
for (nn=0; nn<CMD8STACKDEPTH; nn++)
{
SharedMem::write()->nextAsynchsendCmd8[nn]=0;
SharedMem::write()->nextCmd8para1[nn]=0;
SharedMem::write()->nextCmd8para2[nn]=0;
SharedMem::write()->nextCmd8para3[nn]=0;
SharedMem::write()->nextCmd8para4[nn]=0;
}
SharedMem::write()->nrOfCmds8InQueue=0;
}
bool sendWRcmd_setSendCommand8(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint16_t dat3, uint32_t dat4)
{
// write Command to memory, wait for transport
uint8_t ciq;
ciq=SharedMem::read()->nrOfCmds8InQueue;
if (ciq>=CMD8STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextAsynchsendCmd8[ciq]=nextCmd;
SharedMem::write()->nextCmd8para1[ciq]=dat1;
SharedMem::write()->nextCmd8para2[ciq]=dat2;
SharedMem::write()->nextCmd8para3[ciq]=dat3;
SharedMem::write()->nextCmd8para4[ciq]=dat4;
ciq++;
SharedMem::write()->nrOfCmds8InQueue=ciq;
return true; // ok, will be sent
}
uint16_t sendWRcmd_getSendCommand8(uint8_t *dat1, uint8_t *dat2, uint16_t *dat3, uint32_t *dat4)
{
uint16_t nxtAsynchCmd, data;
uint8_t nn;
uint8_t ciq=SharedMem::read()->nrOfCmds8InQueue;
if (ciq==0 || ciq > CMD8STACKDEPTH)
return 0; // error
nxtAsynchCmd=SharedMem::read()->nextAsynchsendCmd8[0];
*dat1=SharedMem::read()->nextCmd8para1[0];
*dat2=SharedMem::read()->nextCmd8para2[0];
*dat3=SharedMem::read()->nextCmd8para3[0];
*dat4=SharedMem::read()->nextCmd8para4[0];
// move buffer down by one element
if (ciq>0) ciq--;
for (nn=0; nn<ciq; nn++)
{
data=SharedMem::read()->nextAsynchsendCmd8[nn+1];
SharedMem::write()->nextAsynchsendCmd8[nn]=data;
data=SharedMem::read()->nextCmd8para1[nn+1];
SharedMem::write()->nextCmd8para1[nn]=data;
data=SharedMem::read()->nextCmd8para2[nn+1];
SharedMem::write()->nextCmd8para2[nn]=data;
data=SharedMem::read()->nextCmd8para3[nn+1];
SharedMem::write()->nextCmd8para3[nn]=data;
data=SharedMem::read()->nextCmd8para4[nn+1];
SharedMem::write()->nextCmd8para4[nn]=data;
}
SharedMem::write()->nrOfCmds8InQueue=ciq;
return nxtAsynchCmd;
}
*/
//static uint8_t sendAsynchDataBuf[160]; // no stack, only ONE buffer
//static uint8_t sendAsyDatLen;
bool sendWRcmd_setSendBlock160(uint8_t leng, uint8_t *buf)
{
if (leng>SENDASYDAT_BUFFSIZE) leng=SENDASYDAT_BUFFSIZE;
SharedMem::write()->sendAsyDatLen=leng;
tslib_strclr(SharedMem::write()->sendAsynchDataBuf, 0, SENDASYDAT_BUFFSIZE);
for (uint8_t nn=0; nn<leng; nn++)
SharedMem::write()->sendAsynchDataBuf[nn]=buf[nn];
return true; // ok, will be sent
}
uint8_t sendWRcmd_getSendBlock160(uint8_t *leng, uint8_t *buf)
{
uint8_t dl=SharedMem::read()->sendAsyDatLen;
*leng=dl;
for (uint8_t nn=0; nn<dl; nn++)
buf[nn]=SharedMem::read()->sendAsynchDataBuf[nn];
SharedMem::write()->sendAsyDatLen=0;
//tslib_strclr(SharedMem::write()->sendAsynchDataBuf, 0, SENDASYDAT_BUFFSIZE);
return *leng;
}
// ------------------------------------------------------------------------------------
// MDB Sendind Data are store here for next transport to DC (Device Controller)
// Transport to Slave runs every 100ms, answer from mdb-slave (e.g. coin changer) comes rigth
// with next slave answer
// start with: SENDDIRCMD_EXCHGMDB,
// send crude data from here to DC, DC to mdb slaves, mdb answer, return here within 50ms
//static uint8_t Sdata_mdbSendBuffer[MDBSEND_BUFFSIZE];
//static uint8_t Sdata_mdbSendLen;
/*
uint8_t epi_store64ByteSendData(uint8_t length, uint8_t *buf)
{
if (length>MDBSEND_BUFFSIZE) length=MDBSEND_BUFFSIZE;
// HWapi writes data to be forwarded to DC and further to mdb-device
for (uint8_t nn=0; nn<length; nn++)
SharedMem::write()->Sdata_mdbSendBuffer[nn]=buf[nn];
SharedMem::write()->Sdata_mdbSendLen=length;
return 0;
}
uint8_t gpi_restore64ByteSendData(uint8_t *length, uint8_t *buf)
{
// datif reads data to forward to dc
uint8_t dl=SharedMem::read()->Sdata_mdbSendLen;
for (uint8_t nn=0; nn<dl; nn++)
buf[nn]=SharedMem::read()->Sdata_mdbSendBuffer[nn];
*length=dl;
SharedMem::write()->Sdata_mdbSendLen=0;
return 0;
}
*/
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
//---------------------------------------- Printer Text Fifo -------------------------
//static uint8_t prnDataParameters[];
//static uint8_t prnDataBufferUser;
/*
void epi_storeUserOfSendingTextBuffer(uint8_t user, uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4 )
{
// user=1: Text-Print is using this buffer
// 2: QR-code-Printer is using this buffer
SharedMem::write()->prnDataBufferUser=user;
SharedMem::write()->prnDataParameters[0]=para1;
SharedMem::write()->prnDataParameters[1]=para2;
SharedMem::write()->prnDataParameters[2]=para3;
SharedMem::write()->prnDataParameters[3]=para4;
// qDebug() << "new user stored: " << user;
}
uint8_t gpi_getUserOfSendingTextBuffer(uint8_t *para1, uint8_t *para2, uint8_t *para3, uint8_t *para4)
{
// user=1: Text-Print is using this buffer
// 2: QR-code-Printer is using this buffer
//qDebug() << "returning user "<< prnDataBufferUser;
*para1=SharedMem::read()->prnDataParameters[0];
*para2=SharedMem::read()->prnDataParameters[1];
*para3=SharedMem::read()->prnDataParameters[2];
*para4=SharedMem::read()->prnDataParameters[3];
return SharedMem::read()->prnDataBufferUser;
}
*/
// Sending Text Fifo
// ONE printer doc consists of 20 x 64 byte
// #define MAXNROF_PRNBYTES 64
// #define MAXNROF_PRNBLOCKS 20
//static char Sdata_PRN_TEXT[MAXNROF_PRNBLOCKS][MAXNROF_PRNBYTES];
//static uint8_t pPrnDataBuff; // points to next PRINTER_BLOCK
//static uint8_t pPrnDataBuff; // points to next waiting printer text
// defined above, needed if more then one text is stored (before sent)
// every block will be sent after 100ms, if 8 blocks are stored within this 100ms
// then pointer goes up to 8. Important: FIFO!!!!!!!!
/*
void epi_resetPrinterStack(void)
{
SharedMem::write()->pPrnDataBuff=0;
}
uint8_t epi_storePrnText(char *buf, uint8_t leng)
{
// store text from Gui in next higher free memory 0....9
uint16_t len;
uint8_t pp, nn;
pp=SharedMem::read()->pPrnDataBuff; // next free memory block with 64byte each
if (pp>=MAXNROF_PRNBLOCKS)
return 1; // not possible, no free mem
//len=tslib_strlen(buf); // kennt keine Binärzeichen!!!!!!
len=leng;
if (len>MAXNROF_PRNBYTES)
len=MAXNROF_PRNBYTES;
tslib_strclr(SharedMem::write()->Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES);
for (nn=0; nn<len; nn++)
SharedMem::write()->Sdata_PRN_TEXT[pp][nn]=buf[nn]; // copy new text into buffer
if (SharedMem::read()->pPrnDataBuff<MAXNROF_PRNBLOCKS)
SharedMem::write()->pPrnDataBuff++; // inc pointer if end not yet reached
return 0; // OK
}
uint8_t gpi_restorePrnText(uint8_t *retbuf)
{
// read printer text and send to slave, size of retbuf == 64
// always read from [0] because this is the oldest (Fifo)
// then move all text lines down by one and dec pointer
uint8_t nn, mm, pp=SharedMem::read()->pPrnDataBuff;
char buf[MAXNROF_PRNBYTES];
if (pp==0) // next free memory block with 64byte each
return 1; // no text in buffer
// example: pp=5: then buffers [0...4] are occupied
for (nn=0; nn<MAXNROF_PRNBYTES; nn++)
retbuf[nn] = uint8_t (SharedMem::read()->Sdata_PRN_TEXT[0][nn]); // restore oldest text
// now copy textline [1] to [0], then
// copy textline [2] to [1], then
// copy textline [3] to [2] .... upto [pp-1] to [pp-2]
// hint: copying from 9....0 would delete all strings!!!!!!
for (nn=0; nn<(pp-1); nn++)
{
for (mm=0; mm<MAXNROF_PRNBYTES; mm++)
buf[mm]=SharedMem::read()->Sdata_PRN_TEXT[nn+1][mm];
for (mm=0; mm<MAXNROF_PRNBYTES; mm++)
SharedMem::write()->Sdata_PRN_TEXT[nn][mm]=buf[mm];
}
if (pp>0) pp--;
SharedMem::write()->pPrnDataBuff=pp;
// example: pp=4: then buffers [0...3] are still occupied, pp=0: all buffers empty
// now clear highest copyed line (which became free now)
tslib_strclr(SharedMem::write()->Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES);
// optionally: clear all remaining higher lines:
for (nn=(pp+1); nn<MAXNROF_PRNBLOCKS; nn++)
tslib_strclr(SharedMem::write()->Sdata_PRN_TEXT[nn], 0, MAXNROF_PRNBYTES);
return 0;
}
uint8_t gpi_chk4remainingText(void)
{
// retval: 0: no more textline left (to send) >0: nr of 64byte-blocks
return (SharedMem::read()->pPrnDataBuff);
}
*/
// ---------------------------------------------------------------------------------
// 11.4.23 neu, Kommando direkt an "FastDevice"-protokoll senden, nicht mehr umsetzen
// ---------------------------------------------------------------------------------
/*
// 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];
// long 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
nextAsynchsendCmd0[1]=cmd2
nextAsynchsendCmd0[2]=cmd3
nextAsynchsendCmd0[3]=cmd4 // came in as last
Send: [0] first, then move buffer 1 down:
nextAsynchsendCmd0[0]=cmd2
nextAsynchsendCmd0[1]=cmd3
nextAsynchsendCmd0[2]=cmd4
nextAsynchsendCmd0[3]=0;
nrOfCmdsInQueue=3 now
*/
void sendFDcmd_clrStack(void)
{
uint8_t nn;
for (nn=0; nn<FDCMD_STACKDEPTH; nn++)
{
SharedMem::write()->nextFDwrCmd[nn]=0;
SharedMem::write()->nextFDrdCmd[nn]=0;
SharedMem::write()->nextFDblkNr[nn]=0;
SharedMem::write()->nextFDshort[nn]=0;
SharedMem::write()->nextFDpara1[nn]=0;
SharedMem::write()->nextFDpara2[nn]=0;
SharedMem::write()->nextFDpara3[nn]=0;
SharedMem::write()->nextFDpara4[nn]=0;
SharedMem::write()->longFDlength[nn]=0;
memset(&SharedMem::write()->longFDpara[nn][0],0,64);
}
SharedMem::write()->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
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd >=FDCMD_STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextFDwrCmd[pFDcmd]=nextWrCmd;
SharedMem::write()->nextFDrdCmd[pFDcmd]=nextRdCmd;
SharedMem::write()->nextFDblkNr[pFDcmd]=blockNum;
SharedMem::write()->nextFDpara1[pFDcmd]=dat1;
SharedMem::write()->nextFDpara2[pFDcmd]=dat2;
SharedMem::write()->nextFDpara3[pFDcmd]=dat3;
SharedMem::write()->nextFDpara4[pFDcmd]=dat4;
//qDebug() << "data with 4 data byte saved, pp=" << pFDcmd;
//qDebug() << " dat1=" << nextCmd4para1[pFDcmd] << " dat2=" << nextCmd4para2[pFDcmd]
// << " dat3=" << nextCmd4para3[pFDcmd] << " dat4=" << nextCmd4para4[pFDcmd];
SharedMem::write()->nextFDshort[pFDcmd]=1; // 1=short
pFDcmd++;
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
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;
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd>=FDCMD_STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextFDwrCmd[pFDcmd]=nextWrCmd;
SharedMem::write()->nextFDrdCmd[pFDcmd]=nextRdCmd;
SharedMem::write()->nextFDblkNr[pFDcmd]=blockNum;
SharedMem::write()->longFDlength[pFDcmd]=length;
for (nn=0; nn<64; nn++)
SharedMem::write()->longFDpara[pFDcmd][nn]=data[nn];
SharedMem::write()->nextFDshort[pFDcmd]=2;
pFDcmd++;
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
return true; // ok, will be sent
}
bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t length, QByteArray *data)
{
// write Command to memory, wait for transport
// data buffer size always 64! data[64], padded with 0
uint8_t nn;
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
char ctmp;
if (pFDcmd>=FDCMD_STACKDEPTH)
{
qDebug() << "cannot save cmd because stack is full";
return false; // not possible
}
SharedMem::write()->nextFDwrCmd[pFDcmd]=nextWrCmd;
SharedMem::write()->nextFDrdCmd[pFDcmd]=nextRdCmd;
SharedMem::write()->nextFDblkNr[pFDcmd]=blockNum;
SharedMem::write()->longFDlength[pFDcmd]=length;
for (nn=0; nn<64; nn++)
{
ctmp=data->at(nn);
SharedMem::write()->longFDpara[pFDcmd][nn]=ctmp;
}
SharedMem::write()->nextFDshort[pFDcmd]=2;
pFDcmd++;
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
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, mm, data; // ll
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd==0 || pFDcmd>FDCMD_STACKDEPTH)
return false; // not possible
*nextWrCmd=SharedMem::read()->nextFDwrCmd[0];
*nextRdCmd=SharedMem::read()->nextFDrdCmd[0];
*blockNum=SharedMem::read()->nextFDblkNr[0];
*dat1=SharedMem::read()->nextFDpara1[0];
*dat2=SharedMem::read()->nextFDpara2[0];
*dat3=SharedMem::read()->nextFDpara3[0];
*dat4=SharedMem::read()->nextFDpara4[0];
//qDebug() << "sendFDcmd_get [0]; pp=" << SharedMem::read()->p_nextFDcmdsInQueue;
//qDebug() << " data1: " << SharedMem::read()->nextCmd4para1[0] << " data2: " << SharedMem::read()->nextCmd4para2[0] <<
// " data3: " << SharedMem::read()->nextCmd4para3[0] << " data4: " << SharedMem::read()->nextCmd4para4[0];
// move Puffer down by one element
//if (FDCMD_STACKDEPTH>0)
// ll=FDCMD_STACKDEPTH-1;
//else
// ll=0;
if (pFDcmd>0) pFDcmd--; else pFDcmd=0;
//for (nn=0; nn<ll; nn++)
for (nn=0; nn<pFDcmd; nn++)
{
data=SharedMem::read()->nextFDwrCmd[nn+1];
SharedMem::write()->nextFDwrCmd[nn]=data;
data=SharedMem::read()->nextFDrdCmd[nn+1];
SharedMem::write()->nextFDrdCmd[nn]=data;
data=SharedMem::read()->nextFDblkNr[nn+1];
SharedMem::write()->nextFDblkNr[nn]=data;
data=SharedMem::read()->nextFDpara1[nn+1];
SharedMem::write()->nextFDpara1[nn]=data;
data=SharedMem::read()->nextFDpara2[nn+1];
SharedMem::write()->nextFDpara2[nn]=data;
data=SharedMem::read()->nextFDpara3[nn+1];
SharedMem::write()->nextFDpara3[nn]=data;
data=SharedMem::read()->nextFDpara4[nn+1];
SharedMem::write()->nextFDpara4[nn]=data;
data=SharedMem::read()->nextFDshort[nn+1];
SharedMem::write()->nextFDshort[nn] = data;
data=SharedMem::read()->longFDlength[nn+1];
SharedMem::write()->longFDlength[nn] = data;
for (mm=0; mm<64; mm++)
{
SharedMem::write()->longFDpara[nn][mm] = SharedMem::read()->longFDpara[nn+1][mm];
}
}
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
//qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue;
// clear released buffer:
//for (nn=p_nextFDcmdsInQueue; nn<FDCMD_STACKDEPTH; nn++)
//{
SharedMem::write()->nextFDwrCmd[pFDcmd]=0;
SharedMem::write()->nextFDrdCmd[pFDcmd]=0;
SharedMem::write()->nextFDblkNr[pFDcmd]=0;
SharedMem::write()->nextFDpara1[pFDcmd]=0;
SharedMem::write()->nextFDpara2[pFDcmd]=0;
SharedMem::write()->nextFDpara3[pFDcmd]=0;
SharedMem::write()->nextFDpara4[pFDcmd]=0;
SharedMem::write()->nextFDshort[pFDcmd]=0;
SharedMem::write()->longFDlength[pFDcmd]=0;
for (mm=0; mm<64; mm++)
SharedMem::write()->longFDpara[pFDcmd][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 (SharedMem::read()->p_nextFDcmdsInQueue==0)
return 0;
if (SharedMem::read()->nextFDshort[0]==1)
return 1;
return 2;
}
uint8_t check4usedFDstack(void)
{
// returns number of waiting command, max FDCMD_STACKDEPTH
return SharedMem::read()->p_nextFDcmdsInQueue;
}
uint8_t check4freeFDstack(void)
{
// returns number of free places in command stack
return FDCMD_STACKDEPTH - SharedMem::read()->p_nextFDcmdsInQueue;
}
bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data)
{
uint8_t nn, mm, uctmp;
uint8_t pFDcmd=SharedMem::read()->p_nextFDcmdsInQueue;
if (pFDcmd==0 || pFDcmd>FDCMD_STACKDEPTH)
return false; // not possible
*nextWrCmd=SharedMem::read()->nextFDwrCmd[0];
*nextRdCmd=SharedMem::read()->nextFDrdCmd[0];
*blockNum=SharedMem::read()->nextFDblkNr[0];
*length = SharedMem::read()->longFDlength[0];
for (mm=0; mm<64; mm++)
data[mm] = SharedMem::read()->longFDpara[0][mm];
if (pFDcmd>0) pFDcmd--; else pFDcmd=0;
//for (nn=0; nn<ll; nn++)
for (nn=0; nn<pFDcmd; nn++)
{
uctmp=SharedMem::read()->nextFDwrCmd[nn+1];
SharedMem::write()->nextFDwrCmd[nn]=uctmp;
uctmp=SharedMem::read()->nextFDrdCmd[nn+1];
SharedMem::write()->nextFDrdCmd[nn]=uctmp;
uctmp=SharedMem::read()->nextFDblkNr[nn+1];
SharedMem::write()->nextFDblkNr[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara1[nn+1];
SharedMem::write()->nextFDpara1[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara2[nn+1];
SharedMem::write()->nextFDpara2[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara3[nn+1];
SharedMem::write()->nextFDpara3[nn]=uctmp;
uctmp=SharedMem::read()->nextFDpara4[nn+1];
SharedMem::write()->nextFDpara4[nn]=uctmp;
uctmp=SharedMem::read()->nextFDshort[nn+1];
SharedMem::write()->nextFDshort[nn]=uctmp;
uctmp=SharedMem::read()->longFDlength[nn+1];
SharedMem::write()->longFDlength[nn]=uctmp;
for (mm=0; mm<64; mm++)
{
SharedMem::write()->longFDpara[nn][mm] = SharedMem::read()->longFDpara[nn+1][mm];
}
}
SharedMem::write()->p_nextFDcmdsInQueue=pFDcmd;
// clear released buffer:
SharedMem::write()->nextFDwrCmd[pFDcmd]=0;
SharedMem::write()->nextFDrdCmd[pFDcmd]=0;
SharedMem::write()->nextFDblkNr[pFDcmd]=0;
SharedMem::write()->nextFDpara1[pFDcmd]=0;
SharedMem::write()->nextFDpara2[pFDcmd]=0;
SharedMem::write()->nextFDpara3[pFDcmd]=0;
SharedMem::write()->nextFDpara4[pFDcmd]=0;
SharedMem::write()->nextFDshort[pFDcmd]=0;
SharedMem::write()->longFDlength[pFDcmd]=0;
for (mm=0; mm<64; mm++)
SharedMem::write()->longFDpara[pFDcmd][mm] = 0;
return true; // ok, will be sent
}

101
src/shared_mem_buffer.cpp Normal file
View File

@ -0,0 +1,101 @@
#include "shared_mem_buffer.h"
#include <QDebug>
#include <atomic>
#ifdef QT_POSIX_IPC
// The POSIX backend can be explicitly selected using the -feature-ipc_posix
// option to the Qt configure script. If it is enabled, the QT_POSIX_IPC
// macro will be defined. -> we use SystemV shared memory
#error "QT_POSIX_IPC defined"
#else
#ifdef __linux__
#include <sys/ipc.h> // ftok
#endif
#endif
//static bool shdMemFirstUse;
//QSharedMemory *SharedMemBuffer::getShm(std::size_t size) {
QSharedMemory *SharedMem::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();
static const QString fkey = "0123456?000=7";
#else
static const QString fkey = "0123456?000=9";
#endif
shMem.setKey(fkey);
if (!shMem.isAttached()) {
if (shMem.create(size)) {
return &shMem;
} else {
if (shMem.error() == QSharedMemory::AlreadyExists) {
if (shMem.attach()) {
return &shMem;
}
}
}
qCritical() << shMem.nativeKey() << shMem.key() << shMem.data()
<< shMem.error() << shMem.errorString();
return nullptr;
}
}
return &shMem;
}
// std::atomic_bool SharedMemBuffer::__sharedMemLocked{false};
/*
//QSharedMemory *SharedMemBuffer::getShm(std::size_t size) {
QSharedMemory *SharedMem::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
shdMemFirstUse=false;
shMem.setKey(fkey);
if (!shMem.isAttached())
{
if (shMem.create(size))
{
// sm was created successful, did not exist before
shdMemFirstUse=true;
return &shMem;
} else
{
// create was false because mem already existed
if (shMem.error() == QSharedMemory::AlreadyExists)
{
if (shMem.attach())
{
return &shMem;
}
}
}
qCritical() << shMem.nativeKey() << shMem.key() << shMem.data()
<< shMem.error() << shMem.errorString();
return nullptr;
}
}
return &shMem;
}
bool shdMem_firstUse(void)
{
return shdMemFirstUse;
}
*/

2053
src/storeINdata sm.cpp Executable file

File diff suppressed because it is too large Load Diff

2344
src/storeINdata.cpp Normal file

File diff suppressed because it is too large Load Diff

612
src/tslib.cpp Normal file
View File

@ -0,0 +1,612 @@
#include "tslib.h"
#include <QThread>
//tslib::tslib()
//{
//}
/*
uint16_t tslib::uchar2uint(uint8_t Highbyte, uint8_t Lowbyte)
{
uint16_t uitmp;
uitmp=0;
uitmp |= uint8_t(Highbyte);
uitmp<<=8;
uitmp |= uint8_t(Lowbyte);
return uitmp;
}
uint8_t tslib::uint2uchar(uint16_t uival, bool getHighB)
{
// getHighB: low=GetLowByte
uint16_t uitmp=uival;
if (getHighB==0)
return uint8_t(uitmp);
uitmp>>=8;
return uint8_t(uitmp);
}*/
uint16_t uchar2uint(char Highbyte, char Lowbyte)
{
uint16_t uitmp;
uitmp=0;
uitmp |= uint8_t(Highbyte);
uitmp<<=8;
uitmp |= uint8_t(Lowbyte);
return uitmp;
}
uint16_t uchar2uint(uint8_t Highbyte, uint8_t Lowbyte)
{
uint16_t uitmp;
uitmp=0;
uitmp |= uint8_t(Highbyte);
uitmp<<=8;
uitmp |= uint8_t(Lowbyte);
return uitmp;
}
uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t Lowbyte)
{
uint32_t ultmp=0;
ultmp |= uint8_t(Highbyte);
ultmp<<=8;
ultmp |= uint8_t(MHbyte);
ultmp<<=8;
ultmp |= uint8_t(MLbyte);
ultmp<<=8;
ultmp |= uint8_t(Lowbyte);
return ultmp;
}
uint8_t uint2uchar(uint16_t uival, bool getHighB)
{
// getHighB: low=GetLowByte
uint16_t uitmp=uival;
if (getHighB==0)
return uint8_t(uitmp);
uitmp>>=8;
return uint8_t(uitmp);
}
uint8_t ulong2uchar(uint32_t ulval, uint8_t getBytNr)
{
// getBytNr: 0=LSB 3=MSB
uint32_t ultmp=ulval;
if (getBytNr==0)
return uint8_t(ultmp);
ultmp>>=8;
if (getBytNr==1)
return uint8_t(ultmp);
ultmp>>=8;
if (getBytNr==2)
return uint8_t(ultmp);
ultmp>>=8;
return uint8_t(ultmp);
}
void delay(uint16_t MilliSec)
{
QThread::msleep(uint32_t(MilliSec));
}
void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf)
{
// Zahlenwerte in String wandeln, 12/24h-Format // 12byte für buf!
uint8_t usa;
uint16_t jj;
uint8_t hh, mm, ss, with_sec;
// buf[0]= ganz linkes Zeichen
hh=hours;
mm=minutes;
ss=seconds;
// 15.10.12, Plausibilitätsprüfung --------------------------------------------------
if (hh>23) hh=0;
if (mm>59) mm=0;
if (ss>59) ss=0;
with_sec=ShowSec;
for (jj=0; jj<12; jj++) buf[jj]=0;
usa = System12h; // 1:12h 0:24h
// Stunden:
if (usa)
{
// 12h System
if (hh==0 || hh==12)
{
// 12AM (Mitternacht) oder 12PM (Mittag)
buf[0]=0x31;
buf[1]=0x32;
} else
if (hh<12)
{
// 1..11AM
buf[0]=hh/10+0x30;
buf[1]=hh%10+0x30;
} else
{
//13:00 bis 23Uhr
buf[0]=(hh-12)/10+0x30;
buf[1]=(hh-12)%10+0x30;
}
} else
{
// 24h System
buf[0]=hh/10+0x30;
buf[1]=hh%10+0x30;
}
// Minuten:
buf[2]=':';
buf[3]=mm/10+0x30;
buf[4]=mm%10+0x30;
jj=5;
if (with_sec)
{
buf[jj++]=':';
buf[jj++]=ss/10+0x30;
buf[jj++]=ss%10+0x30;
}
if (usa)
{
buf[jj++]=' ';
if (hh<12)
buf[jj++]='A';
else
buf[jj++]='P';
buf[jj++]='M';
}
}
// ------------------- ********************************************************************************
void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf)
{
// generate date as ascii string from integers day/month/year
// yearhigh: 10..29, in europe always 20 (not in arabia!) comes as hex number, e.g. 0x20
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11byte für buf!
uint8_t tag, mon, jahr, d10, d1, m10, m1, y1000, y100, y10, y1;
uint8_t slash;
y100= (yearhigh & 0x0F)+0x30;
y1000=((yearhigh & 0xF0)>>4)+0x30;
// if (yearhigh>=20)
// {
// y1000='2';
// y100=28+yearhigh; // '0' + (yearhigh-20)
// } else
// if (yearhigh<20)
// {
// y1000='1';
// y100=38-yearhigh; // '9' - (19-yearhigh)
// }
tag=day;
mon=month;
jahr=yearlow;
if (mon>12 || mon==0) mon=1; // 23.10.12
if (tag>31 || tag==0) tag=1;
if (jahr>50 || jahr<11) jahr=1;
if (sep==0)
slash='.'; // slash==0
else if (sep==1)
slash='/';
else
if (sep>=0x20)
slash=sep;
else
slash='.';
d10 =tag/10;
d1 =tag%10;
m10 =mon/10;
m1 =mon%10;
y10 =jahr/10;
y1 =jahr%10;
d10 +=0x30; // in Asccii wandeln
d1 +=0x30;
m10 +=0x30;
m1 +=0x30;
y10 +=0x30;
y1 +=0x30;
switch (format)
{
// 0: dd.mm.yyyy
case 0: buf[0]=d10; buf[1]=d1; buf[2]=slash; buf[3]=m10; buf[4]=m1; buf[5]=slash;
buf[6]=y1000; buf[7]=y100; buf[8]=y10; buf[9]=y1; break;
// 1: mm.dd.yyyy
case 1: buf[0]=m10; buf[1]=m1; buf[2]=slash; buf[3]=d10; buf[4]=d1; buf[5]=slash;
buf[6]=y1000; buf[7]=y100; buf[8]=y10; buf[9]=y1; break;
// 2: yyyy.mm.dd
case 2: buf[0]=y1000; buf[1]=y100; buf[2]=y10; buf[3]=y1; buf[4]=slash; buf[5]=m10;
buf[6]=m1; buf[7]=slash; buf[8]=d10; buf[9]=d1; break;
// 3: dd.yyyy.mm
case 3: buf[0]=d10; buf[1]=d1; buf[2]=slash; buf[3]=y1000; buf[4]=y100;
buf[5]=y10; buf[6]=y1; buf[7]=slash; buf[8]=m10; buf[9]=m1; break;
// 4: mm.yyyy.dd
case 4: buf[0]=m10; buf[1]=m1; buf[2]=slash; buf[3]=y1000; buf[4]=y100;
buf[5]=y10; buf[6]=y1; buf[7]=slash; buf[8]=d10; buf[9]=d1; break;
// 5: yyyy.dd.mm
case 5: buf[0]=y1000; buf[1]=y100; buf[2]=y10; buf[3]=y1; buf[4]=slash; buf[5]=d10;
buf[6]=d1; buf[7]=slash; buf[8]=m10; buf[9]=m1; break;
}
buf[10]=0;
}
// ------------------- ********************************************************************************
void GetShortDateString(uint8_t day, uint8_t month, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf)
{
// generate date as ascii string from integers day/month/year
// format= 0: dd.mm.yy (deutsch)
// 1: mm.dd.yy (amerika)
// 2: yy.mm.dd (Iran, Dubai)
// 3: dd.yy.mm
// 4: mm.yy.dd
// 5: yy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11byte für buf!
uint8_t tag, mon, jahr, d10, d1, m10, m1, y10, y1;
uint8_t slash;
tag=day;
mon=month;
jahr=yearlow;
if (mon>12 || mon==0) mon=1; // 23.10.12
if (tag>31 || tag==0) tag=1;
if (jahr>50 || jahr<11) jahr=1;
if (sep==0)
slash='.'; // slash==0
else if (sep==1)
slash='/';
else if (sep>=0x20)
slash=sep;
else
slash='.';
d10 =tag/10;
d1 =tag%10;
m10 =mon/10;
m1 =mon%10;
y10 =jahr/10;
y1 =jahr%10;
d10 +=0x30; // in Asccii wandeln
d1 +=0x30;
m10 +=0x30;
m1 +=0x30;
y10 +=0x30;
y1 +=0x30;
switch (format)
{
// 0: dd.mm.yyyy
case 0: buf[0]=d10; buf[1]=d1; buf[2]=slash; buf[3]=m10; buf[4]=m1; buf[5]=slash;
buf[6]=y10; buf[7]=y1; break;
// 1: mm.dd.yyyy
case 1: buf[0]=m10; buf[1]=m1; buf[2]=slash; buf[3]=d10; buf[4]=d1; buf[5]=slash;
buf[6]=y10; buf[7]=y1; break;
// 2: yyyy.mm.dd
case 2: buf[0]=y10; buf[1]=y1; buf[2]=slash; buf[3]=m10;
buf[4]=m1; buf[5]=slash; buf[6]=d10; buf[7]=d1; break;
// 3: dd.yyyy.mm
case 3: buf[0]=d10; buf[1]=d1; buf[2]=slash;
buf[3]=y10; buf[4]=y1; buf[5]=slash; buf[6]=m10; buf[7]=m1; break;
// 4: mm.yyyy.dd
case 4: buf[0]=m10; buf[1]=m1; buf[2]=slash;
buf[3]=y10; buf[4]=y1; buf[5]=slash; buf[6]=d10; buf[7]=d1; break;
// 5: yyyy.dd.mm
case 5: buf[0]=y10; buf[1]=y1; buf[2]=slash; buf[3]=d10;
buf[4]=d1; buf[5]=slash; buf[6]=m10; buf[7]=m1; break;
}
buf[8]=0;
}
uint16_t tslib_strlen(char *buf)
{
uint16_t nn;
for (nn=0; nn<0xFFF0; nn++)
if (buf[nn]==0)
return nn;
return 0;
}
uint16_t tslib_strlen(uint8_t *buf)
{
uint16_t nn;
for (nn=0; nn<0xFFF0; nn++)
if (buf[nn]==0)
return nn;
return 0;
}
void tslib_strclr(char *buf, char clrsign, uint16_t len)
{
uint16_t nn;
for (nn=0; nn<len; nn++)
buf[nn]=clrsign;
}
void tslib_strclr(uint8_t *buf, char clrsign, uint16_t len)
{
uint16_t nn;
for (nn=0; nn<len; nn++)
buf[nn]=uint8_t (clrsign);
}
void tslib_strcpy(char *srcbuf, char *destbuf, uint16_t len)
{
uint16_t nn;
for (nn=0; nn<len; nn++)
destbuf[nn]=srcbuf[nn];
}
void tslib_strcpy(char *srcbuf, uint8_t *destbuf, uint16_t len)
{
uint16_t nn;
for (nn=0; nn<len; nn++)
destbuf[nn]=uint8_t(srcbuf[nn]);
}
void tslib_strcpy(uint8_t *srcbuf, uint8_t *destbuf, uint16_t len)
{
uint16_t nn;
for (nn=0; nn<len; nn++)
destbuf[nn]=srcbuf[nn];
}
bool tslib_isDecAsciiNumber(char sign)
{
if (sign>=0x30 && sign<=0x39)
return true;
return false;
}
bool tslib_isHexAsciiNumber(char sign)
{
if (sign>=0x30 && sign<=0x39)
return true;
if (sign>=0x61 && sign<=0x66) // a...f
return true;
if (sign>=0x41 && sign<=0x46) // A...F
return true;
return false;
}
int tslib_getMinimum(int val1, int val2)
{
if (val1<val2)
return val1;
return val2;
}
void tslib_text2array(QByteArray text, char *aray, uint16_t maxArayLen)
{
QByteArray sloc;
int ii, LL=text.length();
if (LL>maxArayLen) LL=maxArayLen;
for (ii=0; ii<LL; ii++)
{
aray[ii]=text.at(ii);
}
if (LL==maxArayLen)
aray[LL-1]=0;
else
aray[LL]=0;
}
// -----------------------------------------------------------------------------------------------
// functions for DeviceController's Bootloader ---------------------------------------------------
// -----------------------------------------------------------------------------------------------
/*
uint16_t tslib_calcCrcCcitt(uint16_t BufLength, uint8_t *buf)
{
uint8_t nn, B15H, element;
uint16_t crc = 0x84cf;
while (BufLength--)
{
element = *buf++;
for (nn = 0; nn < 8; nn++)
{
B15H = 0;
if(crc & 0x8000)
B15H = 1;
crc = (crc << 1) | ((element >> (7 - nn)) & 0x01);
if (B15H)
{
crc ^= 0x1021;
}
}
}
for (nn = 0; nn < 16; nn++)
{
B15H = 0;
if(crc & 0x8000)
B15H = 1;
crc = (crc << 1) | 0x00;
if (B15H)
{
crc ^= 0x1021;
}
}
return crc;
}
static uint8_t LastBLcmd; // stored the last sent cmd in order to analys response
// cmd echo'ed: error cmd or'ed with 0x80: OK
uint8_t tslib_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf)
{
// make BL protocol, retval = outbuf length (5...133)
// bring data in correct form: start always with 0x02 finish with 0x03 and append checksum
// 0x02 Cmd < ...sendData ..> CRC CRC 0x03
// Data length = 0...64
// special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80
// so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64
uint8_t myBuf[140], pp=0, nn, uctmp, currLen=0;
uint16_t calcCrc;
tslib_strclr(myBuf, 0, 140);
myBuf[pp++]=2; // STX
myBuf[pp++]=Cmd;
LastBLcmd=Cmd;
// append data:
for (nn=0; nn<SendDataLength; nn++)
{
uctmp=sendData[nn];
if (uctmp==2 || uctmp==3) // STX or ETX in normal data!
{
myBuf[pp++]=0x1B; // ESC
myBuf[pp++]=uctmp | 0x80;
} else
myBuf[pp++]=uctmp;
}
currLen=pp;
// calc crc: (over cmd and data, without STX)
calcCrc=tslib_calcCrcCcitt(uint16_t(currLen), myBuf);
myBuf[pp++]=uint8_t(calcCrc & 0x00FF);
myBuf[pp++]=uint8_t((calcCrc>>8) & 0x00FF);
myBuf[pp++]=3;
currLen=pp;
return currLen;
}
// some special commands (right out of bootloader manual)
uint8_t tslib_readBLversion(uint8_t *sendData)
{
// minimum size of sendData-buffer: 5byte retval: length
uint8_t myBuf[2];
tslib_strclr(myBuf, 0, 2);
return tslib_prepareDC_BLcmd(0x11, 0, myBuf, sendData);
}
uint8_t tslib_readFWversion(uint8_t *sendData)
{
// minimum size of sendData-buffer: 5byte retval: length
uint8_t myBuf[2];
tslib_strclr(myBuf, 0, 2);
return tslib_prepareDC_BLcmd(0x12, 0, myBuf, sendData);
}
uint8_t tslib_exitBL(uint8_t *sendData)
{
// minimum size of sendData-buffer: 5byte retval: length
uint8_t myBuf[2];
tslib_strclr(myBuf, 0, 2);
return tslib_prepareDC_BLcmd(0x18, 0, myBuf, sendData);
}
uint8_t tslib_sendFlashStartAddr2BL(uint32_t startAddr, uint8_t *sendData)
{
// minimum size of sendData-buffer: 13byte retval: length (9...13)
uint8_t myBuf[2];
tslib_strclr(myBuf, 0, 2);
return tslib_prepareDC_BLcmd(0x11, 0, myBuf, sendData);
}
*/
// -----------------------------------------------------------------------------------------------
void biox_CopyBlock(uint8_t *src, uint16_t srcPos, uint8_t *dest, uint16_t destPos, uint16_t len)
{
// both buffers starting from pos 0
uint16_t xx,yy,zz,ii;
xx = srcPos;
yy = destPos;
zz = len;
for (ii = 0; ii < zz; ++ii)
{
dest[yy + ii] = src[xx + ii];
}
}
bool tslib_strComp(uint8_t *buf, char *compStr)
{
uint16_t strLen=tslib_strlen(compStr), pp;
for (pp=0; pp<strLen; pp++)
{
if (buf[pp] != compStr[pp])
return false;
}
return true;
}