gpi_storeHW/SWver(): store passed parameter ('QString text') in shared memory.

This commit is contained in:
Gerhard Hoffmann 2024-02-09 12:46:49 +01:00
parent a63e7018a4
commit 35f7d56c2a

View File

@ -6,6 +6,8 @@
#include "shared_mem_buffer.h"
#include "datei.h"
#include <QTextCodec>
// gpi: grafical access to PI: access from external devices over device controller FOR GUI
// epi: external access from GUI to PI: FOR external devices (DC)
@ -64,40 +66,64 @@ bool indat_isMdbOn()
void gpi_storeHWver(QString text)
{
QString hwVersion((char const *)SharedMem::read()->indat_HWversion);
if (hwVersion != text) {
char const *p = text.toUtf8().constData();
if (qstrlen(p) > 0) {
QString prev(QByteArray(SharedMem::read()->indat_HWversion, versionBufferLen-1));
prev = prev.trimmed();
QString const textTruncated = text.mid(0, qMin(versionBufferLen-1, text.size())).trimmed();
if (textTruncated.startsWith("DC2C", Qt::CaseInsensitive)
&& textTruncated != prev) {
QTextCodec *codec = QTextCodec::codecForName("Windows-1252");
QString string = codec->toUnicode(textTruncated.toUtf8());
if (!string.isEmpty()) {
memset(SharedMem::write()->indat_HWversion, 0, versionBufferLen);
memcpy(SharedMem::write()->indat_HWversion, p,
qMin((uint)versionBufferLen, qstrlen(p)) - 1);
char *p = (char *)SharedMem::write()->indat_HWversion;
char *q = (char *)string.constData();
for (int i=0; i < qMin(versionBufferLen, string.size()); ++i) {
int const j = (sizeof(QChar) == 2) ? i*2 : i;
if (q[j]) {
*p++ = q[j];
}
}
}
qCritical() << "Changed" << hwVersion << "to" << epi_loadHWver();
}
}
QString epi_loadHWver(void)
{
return QString((char const*)SharedMem::read()->indat_HWversion);
QString text(SharedMem::read()->indat_HWversion);
return text.mid(0, qMin(versionBufferLen-1, text.size())).trimmed();
}
void gpi_storeSWver(QString text)
{
QString swVersion((char const *)SharedMem::read()->indat_SWversion);
if (swVersion != text) {
char const *p = text.toUtf8().constData();
if (qstrlen(p) > 0) {
QString prev(QByteArray(SharedMem::read()->indat_SWversion, 12));
prev = prev.trimmed();
QString const textTruncated = text.mid(0, qMin(12, text.size())).trimmed();
if (textTruncated.startsWith("DC2C", Qt::CaseInsensitive)
&& textTruncated != prev) {
QTextCodec *codec = QTextCodec::codecForName("Windows-1252");
QString string = codec->toUnicode(textTruncated.toUtf8());
if (!string.isEmpty()) {
memset(SharedMem::write()->indat_SWversion, 0, versionBufferLen);
memcpy(SharedMem::write()->indat_SWversion, p,
qMin((uint)versionBufferLen, qstrlen(p)) - 1);
char *p = (char *)SharedMem::write()->indat_SWversion;
char *q = (char *)string.constData();
for (int i=0; i < qMin(versionBufferLen, string.size()); ++i) {
int const j = (sizeof(QChar) == 2) ? i*2 : i;
if (q[j]) {
*p++ = q[j];
}
}
}
qCritical() << "Changed" << swVersion << "to" << epi_loadSWver();
}
}
QString epi_loadSWver(void)
{
return QString((char const*)SharedMem::read()->indat_SWversion);
QString text(SharedMem::read()->indat_SWversion);
return text.mid(0, qMin(12, text.size())).trimmed();
}
void gpi_storeDCstate(QString text)
@ -2177,8 +2203,8 @@ void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData)
SharedMem::write()->Sdata_LengthRawData=lrd;
for (nn=0; nn<lrd; nn++)
SharedMem::write()->Sdata_rawData[nn]=receivedData[nn];
//qDebug()<<"dcBL got data"<< Sdata_LengthRawData << "bytes :)";
//qDebug()<<"dcBL got data"<< Sdata_LengthRawData << "bytes :)";
}
uint8_t epi_getRawReceivedData(uint8_t *receivedData)