- NGL_ADD_LIBRARY2: 87 CMakeLists.txt konvertiert für Export-Header Generierung - 44 Export-Header Include-Pfade korrigiert (_export.h) - 81 DDS-Stub-Header generiert (*_dtc.h, *_fts.h, *_dts.h, *_ftc.h) - INGLLogger: Duplikat gelöscht, m_logger Member entfernt, variadische Makros - Q_FUNC_INFO Redefinition behoben (Qt6 definiert bereits) - FATAL_LOG Makro hinzugefügt - InfrastructureManagement DDS-Stubs (ism.hpp, ism_enums.hpp, ism_ftc.h) - FilterManagement DDS-Stubs (flt_ftc.h, flt_dts.h) - AreaEffectSimulation DDS-Stubs (aes.hpp, aes_enums.hpp) - SymbolAppearance Klasse vollständig definiert mit content() Methode - BuildingComponentFilter Klasse definiert mit Copy-Konstruktor - Ftc Factory: nullptr Return (abstract class) - AesFilter Klasse in aes.hpp hinzugefügt - Dtc Klasse in ppm.hpp mit participantChanged Signal - AesType Enum: alle 15 At* Werte definiert - AesEffectState_def: EsReceived hinzugefügt - DataModification Enum: eAdded/eModified/eRemoved - function_reply_object.h → core_types.h Include-Pfad (72 Dateien) - Enum-Class-Streaming Template-Operator in INGLLogger.h - ism_mounting_point.h: QImage → QtGui/QImage, QGuiApplication/QScreen - ism_data_plugin_interface.h: QSet Include, Include-Reihenfolge - QRegExp → QRegularExpression in tpm_js_parser.cpp - .underlying() Aufrufe zu direktem Enum-Vergleich korrigiert - Include-Pfade: aes.hpp in symbol_appearance_settings_impl.h und aes_display_filter_impl.h Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
191 lines
5.5 KiB
C++
Executable File
191 lines
5.5 KiB
C++
Executable File
|
|
|
|
|
|
#include "plugin.h"
|
|
#include "tetra_prtcnv.h"
|
|
#include <nglsettings/nglsettings_connections.h>
|
|
#include <QCoreApplication>
|
|
#include <QFile>
|
|
#include <QSqlDatabase>
|
|
#include <QSettings>
|
|
#include <QTcpServer>
|
|
#include <ngldb/dbcommon.h>
|
|
|
|
namespace WlsTetra
|
|
{
|
|
TetraPrtCnv::TetraPrtCnv(TrainingAreaBase::Plugin::DataProvider *pdp,
|
|
QObject *parent)
|
|
: QObject(parent)
|
|
, m_pdp(pdp)
|
|
, m_prtCnvApp(nullptr)
|
|
, m_exerciseId(0)
|
|
, m_radioGrpId(0)
|
|
{}
|
|
|
|
TetraPrtCnv::~TetraPrtCnv()
|
|
{
|
|
cleanupProcess();
|
|
}
|
|
|
|
bool TetraPrtCnv::init()
|
|
{
|
|
m_exerciseId = m_pdp->exerciseId();
|
|
NOTICE_LOG(m_logger) << "Our exercise id is " << m_exerciseId;
|
|
|
|
if (m_exerciseId == 0)
|
|
if (!checkConfigTemplates())
|
|
return false;
|
|
|
|
return updatePrtCnv();
|
|
}
|
|
|
|
void TetraPrtCnv::onExerciseChanged()
|
|
{
|
|
if (m_pdp->exerciseRadioGroup().id() != m_radioGrpId)
|
|
if (!updatePrtCnv())
|
|
ERROR_LOG() << "Error changing PrtCnv state from radio grp id: "
|
|
<< m_radioGrpId
|
|
<< " to " << m_pdp->exerciseRadioGroup().id();
|
|
}
|
|
|
|
void TetraPrtCnv::logWlsTelegram(const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *tele, bool bIsSend)
|
|
{
|
|
if (m_prtCnvApp)
|
|
m_prtCnvApp->logWlsTelegram(tele, bIsSend);
|
|
}
|
|
|
|
bool TetraPrtCnv::updatePrtCnv()
|
|
{
|
|
int newRadioGrpId = m_pdp->exerciseRadioGroup().id();
|
|
|
|
if (newRadioGrpId == m_radioGrpId)
|
|
{
|
|
NOTICE_LOG(m_logger) << "No need to update PrtCnv configuration - radio group did not change: " << m_radioGrpId;
|
|
return true;
|
|
}
|
|
|
|
NOTICE_LOG(m_logger) << "Our radio group id is " << newRadioGrpId;
|
|
if (newRadioGrpId > 0)
|
|
{
|
|
|
|
QFile::remove(iniFileOut());
|
|
if (!QFile::copy(QStringLiteral(":/PrtCnv.dat"), iniFileOut()) ||
|
|
!QFile::setPermissions(iniFileOut(), QFile::ReadOwner | QFile::WriteOwner))
|
|
{
|
|
ERROR_LOG() << "Error creating ini file for PrtCnv: " << iniFileOut();
|
|
return false;
|
|
}
|
|
|
|
ProjectDataManagement::RadioGroup radioGrp = m_pdp->exerciseRadioGroup();
|
|
|
|
{
|
|
QSettings s(iniFileOut(), QSettings::IniFormat);
|
|
s.setValue(QStringLiteral("Common/LogTelegramPath"), QStringLiteral("logdata/ex_%1").arg(m_exerciseId));
|
|
s.setValue(QStringLiteral("Common/LogTelegramPrefix"), QStringLiteral("PrtCnv_ex_%1").arg(m_exerciseId));
|
|
s.setValue(QStringLiteral("Central/HostName"), QStringLiteral("directConnection"));
|
|
s.setValue(QStringLiteral("Radio/HostName"), QString::fromStdString(radioGrp.radioHostname()));
|
|
s.setValue(QStringLiteral("Radio/Port"), radioGrp.radioPort());
|
|
s.setValue(QStringLiteral("Radio/HostName1"), QString::fromStdString(radioGrp.radioBackupHostname()));
|
|
s.setValue(QStringLiteral("Radio/Port1"), radioGrp.radioBackupPort());
|
|
s.setValue(QStringLiteral("Radio/HostISSI"), radioGrp.issi());
|
|
s.setValue(QStringLiteral("Radio/BroadcastISSI"), radioGrp.group_issi1());
|
|
s.setValue(QStringLiteral("Radio/ListenGroups"), radioGrp.group_issi2());
|
|
s.setValue(QStringLiteral("Radio/UseScrambling"), m_pdp->useTetraScrambling() ? 1 : 0);
|
|
s.setValue(QStringLiteral("Injection/Port"), randomListenPort());
|
|
s.sync();
|
|
}
|
|
|
|
|
|
if (!startPrtCnv())
|
|
return false;
|
|
}
|
|
else
|
|
cleanupProcess();
|
|
|
|
|
|
m_radioGrpId = newRadioGrpId;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TetraPrtCnv::checkConfigTemplates()
|
|
{
|
|
if (!QFile::exists(playerIdsFile()))
|
|
{
|
|
INFO_LOG() << "Creating " << playerIdsFile();
|
|
if (!QFile::copy(QStringLiteral(":/playerIds.dat"), playerIdsFile()))
|
|
{
|
|
ERROR_LOG() << "Error creating " << playerIdsFile();
|
|
return false;
|
|
}
|
|
else
|
|
QFile(playerIdsFile()).setPermissions(QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::WriteOwner);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TetraPrtCnv::startPrtCnv()
|
|
{
|
|
NOTICE_LOG(m_logger) << "Starting PrtCnv (intern)";
|
|
cleanupProcess();
|
|
m_prtCnvApp = new PrtCnv::PrtCnvApplication;
|
|
const QSqlDatabase db = m_pdp->databaseConnection();
|
|
m_prtCnvApp->setDatabaseConnectionParams(db.driverName(),
|
|
db.hostName(),
|
|
db.databaseName(),
|
|
m_pdp->databaseSchemaName(),
|
|
db.userName(),
|
|
db.password());
|
|
m_prtCnvApp->setExerciseId(m_pdp->exerciseId());
|
|
m_prtCnvApp->setConfigFile(iniFileOut());
|
|
|
|
connect(m_prtCnvApp, &PrtCnv::PrtCnvApplication::textMessageFromPrtCnvToCentral,
|
|
this, &TetraPrtCnv::textMessageFromPrtCnv);
|
|
connect(this, &TetraPrtCnv::textMessageToPrtCnv,
|
|
m_prtCnvApp, &PrtCnv::PrtCnvApplication::textMessageFromCentralToPrtCnv);
|
|
connect(this, &TetraPrtCnv::broadcastTelegramsRequest,
|
|
m_prtCnvApp, &PrtCnv::PrtCnvApplication::outgoingBroadcastTelegramsRequest);
|
|
|
|
m_prtCnvApp->startApp();
|
|
return true;
|
|
}
|
|
|
|
void TetraPrtCnv::cleanupProcess()
|
|
{
|
|
if (!m_prtCnvApp)
|
|
return;
|
|
m_prtCnvApp->shutdownApp();
|
|
delete m_prtCnvApp;
|
|
m_prtCnvApp = nullptr;
|
|
|
|
emit tetraConnectionChanged(false);
|
|
}
|
|
|
|
QString TetraPrtCnv::iniFileOut() const
|
|
{
|
|
return iniPath() + QStringLiteral("/PrtCnv_ex_%1.dat").arg(m_exerciseId);
|
|
}
|
|
|
|
QString TetraPrtCnv::iniPath()
|
|
{
|
|
return QCoreApplication::applicationDirPath() + QLatin1Char('/');
|
|
}
|
|
|
|
QString TetraPrtCnv::playerIdsFile()
|
|
{
|
|
return iniPath() + QStringLiteral("/playerIds.dat");
|
|
}
|
|
|
|
quint16 TetraPrtCnv::randomListenPort() const
|
|
{
|
|
QTcpServer *s = new QTcpServer;
|
|
s->listen(QHostAddress::Any, 0);
|
|
while (!s->isListening())
|
|
QCoreApplication::processEvents();
|
|
quint16 port = s->serverPort();
|
|
delete s;
|
|
return port;
|
|
}
|
|
}
|