- tests/CMakeLists.txt: Wrap migration_tests in RELEASE_BUILD conditional - LogViewModels.cpp: Change BackgroundColorRole to BackgroundRole for Qt6 - LogViewField.hpp/cpp: Add m_logger member variable - LogViewInjectionThread.hpp/cpp: Add m_logger member variable - LogViewGui.hpp/cpp: Add m_logger member variable, fix QString::split() usage - LogViewTetraTelegramsParser.hpp: Add m_logger, change QStringRef to QStringView - LogViewTelegramEdit.hpp: Fix QModelIndex include path (QtGui→QtCore) - LogViewModels.hpp: Fix QAbstractTableModel include path (QtGui→QtCore) - PrtCnv/CMakeLists.txt: Add CMAKE_CURRENT_BINARY_DIR for export header, exclude LastTest from release - CoPrtCnv/CMakeLists.txt: Add PrtCnv include paths for prtcnvlib_export.h - Lts/Common/CodeGen/CMakeLists.txt: Add CMAKE_CURRENT_BINARY_DIR for export header - Lts/Proxies/TrainingAreaBase/Plugins/CMakeLists.txt: Exclude WlsTetra from release scope Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
144 lines
3.7 KiB
C++
144 lines
3.7 KiB
C++
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "LogViewInjectionThread.hpp"
|
|
|
|
#include "LogViewTelegram.hpp"
|
|
#include "LogViewOptionDialog.hpp"
|
|
#include <CoPrtCnv/CoPrtCnvInjectionHeader.hpp>
|
|
#include <QtNetwork/QTcpSocket>
|
|
#include <QtCore/QTimer>
|
|
#include <QtCore/QSettings>
|
|
|
|
namespace N_LogView
|
|
{
|
|
LogViewInjectionThread::LogViewInjectionThread()
|
|
: m_logger(getLogger("LogViewInjectionThread"))
|
|
, m_DoStartConnection(false)
|
|
, m_SendingPossible(false)
|
|
, m_Socket(nullptr)
|
|
, m_Timer(nullptr)
|
|
{
|
|
|
|
QSettings settings;
|
|
settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
|
|
m_Hostname = settings.value(LogViewOptionDialog::INJECTION_HOSTNAME).toString();
|
|
if (m_Hostname.isEmpty())
|
|
{
|
|
|
|
m_Hostname = QLatin1String("localhost");
|
|
settings.setValue(LogViewOptionDialog::INJECTION_HOSTNAME, m_Hostname);
|
|
}
|
|
m_Port = settings.value(LogViewOptionDialog::INJECTION_PORT).toInt();
|
|
if (0 == m_Port || m_Port > 65535)
|
|
{
|
|
m_Port = 46666;
|
|
settings.setValue(LogViewOptionDialog::INJECTION_PORT, m_Port);
|
|
}
|
|
}
|
|
|
|
|
|
void LogViewInjectionThread::run()
|
|
{
|
|
emit updateStatus(QLatin1String(":/image/RedLamp.png"),
|
|
tr("LogView ist nicht mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
|
|
QTimer::singleShot(100, this, &LogViewInjectionThread::tryToConnect);
|
|
|
|
exec();
|
|
}
|
|
|
|
|
|
|
|
void LogViewInjectionThread::setPort(uint16_t port)
|
|
{
|
|
m_Port = port;
|
|
QSettings settings;
|
|
settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
|
|
settings.setValue(LogViewOptionDialog::INJECTION_PORT, m_Port);
|
|
}
|
|
|
|
|
|
|
|
bool LogViewInjectionThread::isSendingPossible() const
|
|
{
|
|
return m_SendingPossible;
|
|
}
|
|
|
|
|
|
|
|
void LogViewInjectionThread::tryToConnect()
|
|
{
|
|
|
|
if (!m_Socket)
|
|
{
|
|
m_Socket = new QTcpSocket(this);
|
|
connect(m_Socket, &QTcpSocket::connected, this, &LogViewInjectionThread::doConnect);
|
|
connect(m_Socket, &QTcpSocket::disconnected, this, &LogViewInjectionThread::doDisconnect);
|
|
}
|
|
|
|
|
|
if (!m_Timer)
|
|
{
|
|
m_Timer = new QTimer(this);
|
|
connect(m_Timer, &QTimer::timeout, this, &LogViewInjectionThread::tryToConnect);
|
|
}
|
|
m_Timer->setInterval(3000);
|
|
m_Timer->start();
|
|
|
|
INFO_LOG(m_logger) << "Try to connect to injection-server of TETRA-If (" << m_Hostname << ":" << m_Port << ")";
|
|
m_Socket->connectToHost(m_Hostname, m_Port);
|
|
}
|
|
|
|
|
|
|
|
void LogViewInjectionThread::doConnect()
|
|
{
|
|
INFO_LOG(m_logger) << "LogView has successful connected to injection-server of TETRA-If";
|
|
m_SendingPossible = true;
|
|
m_Timer->stop();
|
|
emit updateStatus(QLatin1String(":/image/GreenLamp.png"),
|
|
tr("LogView ist mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
|
|
}
|
|
|
|
|
|
|
|
void LogViewInjectionThread::doDisconnect()
|
|
{
|
|
INFO_LOG(m_logger) << "LogView was disconnected from injection-server of TETRA-If";
|
|
m_SendingPossible = false;
|
|
emit updateStatus(QLatin1String(":/image/RedLamp.png"),
|
|
tr("LogView ist nicht mehr mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
|
|
tryToConnect();
|
|
}
|
|
|
|
|
|
|
|
void LogViewInjectionThread::sendTelegram(LogViewTelegram* a_telegram, const bool a_doSendAsCentralTelegram)
|
|
{
|
|
INFO_LOG(m_logger) << "inject " << (a_doSendAsCentralTelegram ? "central" : "Tetra") << " telegram";
|
|
if (!m_Socket || m_Socket->state() != QAbstractSocket::ConnectedState)
|
|
{
|
|
ERROR_LOG(m_logger) << "Try to write a telegramm but we are not connected";
|
|
return;
|
|
}
|
|
N_CoPrtCnv::CoPrtCnvInjectionHeader injectionHeader;
|
|
injectionHeader.m_Kind = a_doSendAsCentralTelegram ? N_CoPrtCnv::CoPrtCnvInjectionHeader::eCentral : N_CoPrtCnv::CoPrtCnvInjectionHeader::eRadio;
|
|
const QByteArray &data = a_telegram->getData();
|
|
injectionHeader.m_Size = data.size();
|
|
m_Socket->write((char*)(&injectionHeader), sizeof(injectionHeader));
|
|
m_Socket->write(data);
|
|
}
|
|
|
|
}
|