Major Changes:
- Merged latest Qt5 devel content from dlbo (292 files changed, 7 new dirs)
- Consolidated forward-declarations and include folders
- Removed unneeded modules per Niklas' repo check list
Build System Fixes:
- Fixed CMake VERSION_GREATER syntax in ParticipantManagement/CMakeLists.txt
- Added VLC packages (libvlc-dev, vlc-plugin-base) to docker_build.sh
- Added PostgreSQL dev packages (libpq-dev, postgresql-server-dev-all) to Dockerfile
- Fixed locale warnings (ANSI_X3.4-1968 → C.UTF-8)
- Fixed ArcGIS SDK path warnings when BUILD_ARCGIS=OFF
Code Generation Fixes:
- Fixed IDL enum collisions (PortType→CorePortType/DdsutPortType, PdmEventType)
- Fixed Grantlee template svc_translation.cpp.grantlee:
- Changed {{ idl_enum.name }}_def:: to {{ idl_enum.name }}::
- Fixed .underlying() calls for C++11 scoped enums (enum class)
- Removed generated files from repo (moc_*, *_dtc.h, *_ftc.h)
Validation:
- BUILD_RTI=ON: SUCCESS
- BUILD_RTI=OFF: SUCCESS
- C++17 standard maintained for RTI 7.7 compatibility
- Ubuntu 26.04 Docker environment verified
Remaining Warnings (expected):
- BgViewer, KDChart, KDReports, Poppler-Qt6 not found (optional features)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
240 lines
8.3 KiB
C++
240 lines
8.3 KiB
C++
/**
|
|
* Send / Receive telegrams to/from PrtCnv
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2016-09-26
|
|
*/
|
|
|
|
#include "plugin.h"
|
|
#include "NGLLogger/INGLLogger.h"
|
|
#include "socket_dispatcher_json.h"
|
|
#include <nglsettings/nglsettings_connections.h>
|
|
#include <QCoreApplication>
|
|
#include <QFile>
|
|
#include <QSqlDatabase>
|
|
#include <QJsonDocument>
|
|
#include <QSettings>
|
|
#include <ngldb/dbcommon.h>
|
|
#include <CoPrtCnv/CoPrtCnvTelegramConverter.hpp>
|
|
#include <QSettings>
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <qglobal.h>
|
|
|
|
namespace TetraRadio
|
|
{
|
|
|
|
//
|
|
// TetraXdrPlugin
|
|
//
|
|
std::shared_ptr<TrainingAreaBase::Plugin::Interface> TetraJsonPlugin::createInterface(TrainingAreaBase::Plugin::DataProvider *pdp,
|
|
const std::shared_ptr<TrainingAreaBase::RecvFromTab> &recvFromTabCb,
|
|
const std::shared_ptr<TrainingAreaBase::TxMixin> &,
|
|
const std::shared_ptr<TrainingAreaBase::DdsHandler> &,
|
|
NGL::Settings *settings)
|
|
{
|
|
return std::make_shared<TetraJsonInterfaceImpl>(pdp, recvFromTabCb, settings);
|
|
}
|
|
|
|
TetraJsonInterfaceImpl::TetraJsonInterfaceImpl(TrainingAreaBase::Plugin::DataProvider *pdp,
|
|
const std::shared_ptr<TrainingAreaBase::RecvFromTab> &recvFromTabCb,
|
|
NGL::Settings *settings)
|
|
: m_socketDispatcher(new SocketDispatcher(pdp, recvFromTabCb))
|
|
, m_pdp(pdp)
|
|
, m_prtCnvApp(nullptr)
|
|
, m_exerciseId(0)
|
|
, m_radioGrpId(0)
|
|
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("TAB.Plugin.TetraJsonInterfaceImpl"))
|
|
{
|
|
N_CoPrtCnv::CoPrtCnvTelegramConverter::setUse2BytesForSingleFireDiameter(
|
|
settings->settings()->value(QLatin1String("AES/use2BytesForSingleFireDiameter"), true).toBool());
|
|
N_CoPrtCnv::CoPrtCnvTelegramConverter::setUsePvSan(
|
|
settings->settings()->value(QLatin1String("TrainingAreaBase/UsePvSan"), false).toBool());
|
|
ERROR_LOG(m_logger) << "hello i got this!";
|
|
}
|
|
|
|
TetraJsonInterfaceImpl::~TetraJsonInterfaceImpl()
|
|
{
|
|
cleanupProcess();
|
|
}
|
|
|
|
bool TetraJsonInterfaceImpl::init()
|
|
{
|
|
m_exerciseId = m_pdp->exerciseId();
|
|
NOTICE_LOG(m_logger) << "Our exercise id is " << m_exerciseId;
|
|
|
|
if (m_exerciseId == 0) // its sufficient to check only in exercise 0
|
|
if (!checkConfigTemplates())
|
|
return false;
|
|
|
|
return updatePrtCnv();
|
|
}
|
|
|
|
void TetraJsonInterfaceImpl::exerciseChanged()
|
|
{
|
|
NOTICE_LOG(m_logger) << "TetraJsonInterfaceImpl::exerciseChanged";
|
|
if (m_pdp->exerciseRadioGroup().id() != m_radioGrpId) // radio grp changed
|
|
if (!updatePrtCnv())
|
|
ERROR_LOG(m_logger) << "Error changing PrtCnv state from radio grp id: "
|
|
<< m_radioGrpId
|
|
<< " to " << m_pdp->exerciseRadioGroup().id();
|
|
}
|
|
|
|
bool TetraJsonInterfaceImpl::updatePrtCnv()
|
|
{
|
|
int newRadioGrpId = m_pdp->exerciseRadioGroup().id();
|
|
|
|
if (newRadioGrpId == m_radioGrpId) //nothing changed for PrtCnv
|
|
{
|
|
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)
|
|
{
|
|
// Create Prtcnv.dat with specific config
|
|
QFile::remove(iniFileOut());
|
|
if (!QFile::copy(iniFileIn(), iniFileOut()))
|
|
{
|
|
ERROR_LOG(m_logger) << "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")); // direct connection thorugh signals/slots
|
|
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"), m_socketDispatcher->randomListenPort());
|
|
NOTICE_LOG(m_logger) << "TetraJson Injection/Port = " << s.value(QStringLiteral("Injection/Port")).toInt();
|
|
s.sync();
|
|
}
|
|
|
|
// Start PrtCnv
|
|
if (!startPrtCnv())
|
|
return false;
|
|
}
|
|
else // new radio grp ID is 0 and PrtCnv has ben running
|
|
cleanupProcess(); // quit running PrtCnv
|
|
|
|
// set radio grp at the end of update process
|
|
m_radioGrpId = newRadioGrpId;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TetraJsonInterfaceImpl::checkConfigTemplates()
|
|
{
|
|
if (!QFile::exists(iniFileIn()))
|
|
{
|
|
INFO_LOG(m_logger) << "Creating " << iniFileIn();
|
|
if (!QFile::copy(QStringLiteral(":/PrtCnv.dat"), iniFileIn()))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating " << iniFileIn();
|
|
return false;
|
|
}
|
|
else
|
|
QFile(iniFileIn()).setPermissions(QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::WriteOwner);
|
|
}
|
|
|
|
if (!QFile::exists(playerIdsFile()))
|
|
{
|
|
INFO_LOG(m_logger) << "Creating " << playerIdsFile();
|
|
if (!QFile::copy(QStringLiteral(":/playerIds.dat"), playerIdsFile()))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating " << playerIdsFile();
|
|
return false;
|
|
}
|
|
else
|
|
QFile(playerIdsFile()).setPermissions(QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::WriteOwner);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TetraJsonInterfaceImpl::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());
|
|
m_prtCnvApp->startApp();
|
|
m_socketDispatcher->init(m_prtCnvApp);
|
|
|
|
onTetraConnectionChanged(false); // initial
|
|
connect(m_socketDispatcher.get(), &SocketDispatcher::tetraConnectionChanged,
|
|
this, &TetraJsonInterfaceImpl::onTetraConnectionChanged);
|
|
|
|
connect(m_socketDispatcher.get(), &SocketDispatcher::warehouseMessage,
|
|
this, &TetraJsonInterfaceImpl::directMessage);
|
|
|
|
return true;
|
|
}
|
|
|
|
std::shared_ptr<TrainingAreaBase::SendToTab> TetraJsonInterfaceImpl::sendToTab()
|
|
{
|
|
return m_socketDispatcher->sendToTab();
|
|
}
|
|
|
|
bool TetraJsonInterfaceImpl::canSendData() const
|
|
{
|
|
return m_socketDispatcher->canSendData() && m_prtCnvApp != nullptr;
|
|
}
|
|
|
|
void TetraJsonInterfaceImpl::onTetraConnectionChanged(bool bConnected)
|
|
{
|
|
emit connectionState(QString::fromUtf8(name()), bConnected);
|
|
}
|
|
|
|
void TetraJsonInterfaceImpl::cleanupProcess()
|
|
{
|
|
m_socketDispatcher->init(nullptr);
|
|
if (!m_prtCnvApp)
|
|
return;
|
|
m_prtCnvApp->shutdownApp();
|
|
delete m_prtCnvApp;
|
|
m_prtCnvApp = nullptr;
|
|
onTetraConnectionChanged(false);
|
|
}
|
|
|
|
QString TetraJsonInterfaceImpl::iniFileIn()
|
|
{
|
|
return iniPath() + QStringLiteral("/PrtCnv.dat");
|
|
}
|
|
|
|
QString TetraJsonInterfaceImpl::iniFileOut() const
|
|
{
|
|
return iniPath() + QStringLiteral("/PrtCnv_ex_%1.dat").arg(m_exerciseId);
|
|
}
|
|
|
|
QString TetraJsonInterfaceImpl::iniPath()
|
|
{
|
|
return QCoreApplication::applicationDirPath() + QLatin1Char('/');
|
|
}
|
|
|
|
QString TetraJsonInterfaceImpl::playerIdsFile()
|
|
{
|
|
return iniPath() + QStringLiteral("/playerIds.dat");
|
|
}
|
|
|
|
} // namespace TetraRadio
|