Continues migration with DDS, Common

This commit is contained in:
torsten committed 2026-07-17 12:41:42 +02:00
1 parent 9b15cee841
commit fa48db111e
668 files changed
+111841 -2

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
#
# $Id$
# $HeadURL$
# $Author$
#
#
# Lts SerialPortQuerry library
#
SET(ltsspq_SRCS
lts_serial_port_querry.h
lts_serial_port_querry.cpp
logger.h
logger.cpp
)
NGL_ADD_LIBRARY2(AAR SV LtsSerialPortQuerry SHARED ${ltsspq_SRCS} )
NGL_TARGET_INCLUDE_DIRECTORIES(LtsSerialPortQuerry
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(LtsSerialPortQuerry
PRIVATE
PUBLIC
NGLLogger
Qt5::SerialPort
)
+32
View File
@@ -0,0 +1,32 @@
#include "logger.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
namespace LtsSerialPortQuerry
{
LOGGER_T getLogger(const char *name)
{
static const char ns[] = "SPQ.";
std::string loggerName;
const size_t len = strlen(name);
loggerName.reserve(sizeof(ns) + len);
loggerName.append(ns, sizeof(ns) - 1);
loggerName.append(name, len);
try
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
getNGLLogger(loggerName);
}
catch (const std::exception &ex)
{
fprintf(stderr, "Error retrieving logger: %s", ex.what());
abort();
}
}
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <NGLLogger/INGLLogger.h>
namespace LtsSerialPortQuerry
{
typedef NGL::INGLLogger &LOGGER_T;
LOGGER_T getLogger(const char *name);
inline LOGGER_T getLogger(const QString &loggerName)
{
return getLogger(loggerName.toUtf8().constData());
}
}
+52
View File
@@ -0,0 +1,52 @@
#pragma once
#include "lts_serial_port_querry_export.h"
#include "lts_seri"
#include <QObject>
#include <QtSerialPort/QtSerialPort>
#include <QtSerialPort/QSerialPortInfo>
namespace LtsSerialPortQuerry
{
class LTSSERIALPORTQUERRY_EXPORT LtsSerialPortQuerry : public QObject
{
Q_OBJECT
public:
explicit LtsSerialPortQuerry(QObject *parent = nullptr);
void setSerialPortSettings(const QSerialPort::BaudRate &baudRate,
const QSerialPort::OpenModeFlag &openModeFlag,
const QSerialPort::DataBits &dataBits,
const QSerialPort::FlowControl &flowControll,
const QSerialPort::Parity &parity,
const QSerialPort::StopBits &stopBits);
void continueQuerry();
void restartQuerry();
QSerialPort *currentSerialPort();
signals:
void connectionEstablished();
private:
void querrySerialPort(const QSerialPortInfo &info);
void closeAndDeleteCurrentPort();
private:
void onSerialPortError(QSerialPort::SerialPortError serialPortError);
private:
QList<QSerialPortInfo> m_serialPortInfos;
int m_currentQuerry;
QSerialPort::BaudRate m_baudRate;
QSerialPort::OpenModeFlag m_openModeFlag;
QSerialPort::DataBits m_dataBits;
QSerialPort::FlowControl m_flowControll;
QSerialPort::Parity m_parity;
QSerialPort::StopBits m_stopBits;
QSerialPort *m_currentSerialPort;
};
}
+153
View File
@@ -0,0 +1,153 @@
#include "lts_serial_port_querry.h"
#include <QtSerialPort/QSerialPortInfo>
namespace LtsSerialPortQuerry
{
LtsSerialPortQuerry::LtsSerialPortQuerry(QObject *parent)
: QObject(parent)
, m_currentQuerry(0)
, m_baudRate(QSerialPort::Baud115200)
, m_openModeFlag(QSerialPort::ReadWrite)
, m_dataBits(QSerialPort::Data8)
, m_flowControll(QSerialPort::NoFlowControl)
, m_parity(QSerialPort::NoParity)
, m_stopBits(QSerialPort::OneStop)
, m_currentSerialPort(nullptr)
, m_logger(getLogger("LtsSerialPortQuerry"))
{
}
void LtsSerialPortQuerry::setSerialPortSettings(const QSerialPort::BaudRate &baudRate,
const QIODevice::OpenModeFlag &openModeFlag,
const QSerialPort::DataBits &dataBits,
const QSerialPort::FlowControl &flowControll,
const QSerialPort::Parity &parity,
const QSerialPort::StopBits &stopBits)
{
m_baudRate = baudRate;
m_openModeFlag = openModeFlag;
m_dataBits = dataBits;
m_flowControll = flowControll;
m_parity = parity;
m_stopBits = stopBits;
}
void LtsSerialPortQuerry::continueQuerry()
{
m_currentQuerry++;
if (m_currentQuerry>= m_serialPortInfos.size())
{
restartQuerry();
return;
}
querrySerialPort(m_serialPortInfos.at(m_currentQuerry));
}
void LtsSerialPortQuerry::restartQuerry()
{
DEBUG_LOG(m_logger) << "restart querry ";
m_serialPortInfos = QSerialPortInfo::availablePorts();
m_currentQuerry = 0;
if (m_serialPortInfos.size())
querrySerialPort(m_serialPortInfos.at(m_currentQuerry));
else
QTimer::singleShot(1000, this, &LtsSerialPortQuerry::restartQuerry);
}
QSerialPort *LtsSerialPortQuerry::currentSerialPort()
{
return m_currentSerialPort;
}
void LtsSerialPortQuerry::querrySerialPort(const QSerialPortInfo &info)
{
closeAndDeleteCurrentPort();
m_currentSerialPort = new QSerialPort(info, this);
m_currentSerialPort->setBaudRate(m_baudRate);
m_currentSerialPort->setDataBits(m_dataBits);
m_currentSerialPort->setParity(m_parity);
m_currentSerialPort->setStopBits(m_stopBits);
m_currentSerialPort->setFlowControl(m_flowControll);
DEBUG_LOG(m_logger) << "Try opening Comport:" << m_currentSerialPort->portName() << " index is: " << m_currentQuerry;
if (!m_currentSerialPort->open(QSerialPort::ReadWrite))
{
DEBUG_LOG(m_logger) << "Oppening failed query next";
continueQuerry();
}else
{
connect(m_currentSerialPort, &QSerialPort::errorOccurred,
this, &LtsSerialPortQuerry::onSerialPortError, Qt::UniqueConnection);
DEBUG_LOG(m_logger) << "Oppened comport" << m_currentSerialPort->portName();
emit connectionEstablished();
}
}
void LtsSerialPortQuerry::closeAndDeleteCurrentPort()
{
if (m_currentSerialPort)
{
m_currentSerialPort->disconnect();
if (m_currentSerialPort->isOpen())
m_currentSerialPort->close();
m_currentSerialPort->deleteLater();
m_currentSerialPort = nullptr;
}
}
void LtsSerialPortQuerry::onSerialPortError(QSerialPort::SerialPortError serialPortError)
{
if (!m_currentSerialPort)
return;
DEBUG_LOG(m_logger) << "Spontaneous error " << serialPortError << " doesn't have to be an error ...";
const QString errStr(QStringLiteral("QSerialPort::SerialPortError ") + QString::number(serialPortError) +
QStringLiteral(" from serial port ") + m_currentSerialPort->portName() +
QStringLiteral(" error: ") + m_currentSerialPort->errorString());
switch (serialPortError)
{
case QSerialPort::SerialPortError::NoError:
{
break;
}
case QSerialPort::SerialPortError::DeviceNotFoundError:
case QSerialPort::SerialPortError::PermissionError:
case QSerialPort::SerialPortError::OpenError:
case QSerialPort::SerialPortError::NotOpenError:
case QSerialPort::SerialPortError::UnknownError:
{
ERROR_LOG(m_logger) << "Closing port and try to reopen it. " << m_currentSerialPort->portName();
continueQuerry();
Q_FALLTHROUGH();
}
case QSerialPort::SerialPortError::UnsupportedOperationError:
{
ERROR_LOG(m_logger) << errStr;
break;
}
default:
{
ERROR_LOG(m_logger) << "Got an Error> " << errStr << "restarting";
continueQuerry();
break;
}
}
}
}
+56
View File
@@ -0,0 +1,56 @@
#pragma once
#include <LtsSerialPortQuerry/ltsserialportquerry_export.h>
#include "logger.h"
#include <QObject>
#include <QtSerialPort/QtSerialPort>
#include <QtSerialPort/QSerialPortInfo>
namespace LtsSerialPortQuerry
{
class LTSSERIALPORTQUERRY_EXPORT LtsSerialPortQuerry : public QObject
{
Q_OBJECT
public:
explicit LtsSerialPortQuerry(QObject *parent = nullptr);
void setSerialPortSettings(const QSerialPort::BaudRate &baudRate,
const QSerialPort::OpenModeFlag &openModeFlag,
const QSerialPort::DataBits &dataBits,
const QSerialPort::FlowControl &flowControll,
const QSerialPort::Parity &parity,
const QSerialPort::StopBits &stopBits);
void restartQuerry();
QSerialPort *currentSerialPort();
public slots:
void continueQuerry();
signals:
void connectionEstablished();
private:
void querrySerialPort(const QSerialPortInfo &info);
void closeAndDeleteCurrentPort();
private:
void onSerialPortError(QSerialPort::SerialPortError serialPortError);
private:
QList<QSerialPortInfo> m_serialPortInfos;
int m_currentQuerry;
QSerialPort::BaudRate m_baudRate;
QSerialPort::OpenModeFlag m_openModeFlag;
QSerialPort::DataBits m_dataBits;
QSerialPort::FlowControl m_flowControll;
QSerialPort::Parity m_parity;
QSerialPort::StopBits m_stopBits;
QSerialPort *m_currentSerialPort;
LOGGER_T m_logger;
};
}