Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+108
@@ -0,0 +1,108 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
#
|
||||
# --- Library svcCnrHelper --------------------------------------------------------------------------------
|
||||
#
|
||||
SET(SRCS_helper
|
||||
Helper/cnr_frequency_planning_helper.cpp
|
||||
Helper/cnr_frequency_planning_helper.h
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY2(WS SV svcCnrHelper SHARED ${SRCS_helper})
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(svcCnrHelper
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(svcCnrHelper
|
||||
# PRIVATE
|
||||
# RTI::nddscpp2
|
||||
# ddsconnector
|
||||
# ddsfts
|
||||
PUBLIC
|
||||
svcAvmCommon
|
||||
Qt5::Core
|
||||
# svcAesCommon
|
||||
# ngldb
|
||||
)
|
||||
NGL_INSTALL_TARGET(svcCnrHelper)
|
||||
|
||||
#
|
||||
# --- Executable svcCombatNetRadio (pCNR) -------------------------------------------------
|
||||
#
|
||||
SET(xml_FILE cnr_service.xml)
|
||||
|
||||
SET(SRCS_exe
|
||||
dds_handler.cpp
|
||||
dds_handler.h
|
||||
logger.cpp
|
||||
logger.h
|
||||
main.cpp
|
||||
main_handler.cpp
|
||||
main_handler.h
|
||||
active_exercises.cpp
|
||||
active_exercises.h
|
||||
exercise_manager.cpp
|
||||
exercise_manager.h
|
||||
dds_handler_exercise.cpp
|
||||
dds_handler_exercise.h
|
||||
training_area.cpp
|
||||
training_area.h
|
||||
config_cnr.cpp
|
||||
config_cnr.h
|
||||
positions_cnr.cpp
|
||||
positions_cnr.h
|
||||
helper.cpp
|
||||
helper.h
|
||||
|
||||
WebSocketInterface/json_keys.h
|
||||
WebSocketInterface/websocket_interface_handler.cpp
|
||||
WebSocketInterface/websocket_interface_handler.h
|
||||
WebSocketInterface/Connection/client_connection.cpp
|
||||
WebSocketInterface/Connection/client_connection.h
|
||||
WebSocketInterface/Connection/connection_handler.cpp
|
||||
WebSocketInterface/Connection/connection_handler.h
|
||||
WebSocketInterface/Messages/client_message.cpp
|
||||
WebSocketInterface/Messages/client_message.h
|
||||
WebSocketInterface/Messages/message_handler.cpp
|
||||
WebSocketInterface/Messages/message_handler.h
|
||||
WebSocketInterface/Messages/message_transmitter.h
|
||||
WebSocketInterface/Messages/reply_message.cpp
|
||||
WebSocketInterface/Messages/reply_message.h
|
||||
|
||||
cnr_service.xml
|
||||
log4cxx_cnr.props
|
||||
)
|
||||
# make sure xml file is properly installed
|
||||
CODEGEN_HANDLE_SVC_XML(SRCS_exe ${xml_FILE})
|
||||
|
||||
NGL_ADD_SVC_ICON(SRCS_exe)
|
||||
NGL_ADD_EXECUTABLE(AAR SV svcCombatNetRadio ${SRCS_exe})
|
||||
NGL_TARGET_LINK_LIBRARIES(svcCombatNetRadio
|
||||
ddsconnector
|
||||
ddscore
|
||||
LtsCommandLineParser
|
||||
LtsCoordTrans
|
||||
LtsUtilsCore
|
||||
nglcoreapplication
|
||||
NGLLogger
|
||||
Qt5::Core
|
||||
Qt5::Network
|
||||
Qt5::WebSockets
|
||||
ngltools
|
||||
svcCoreClient
|
||||
svcCnrHelper
|
||||
svcIsmClient
|
||||
svcExmClient
|
||||
svcPpmClient
|
||||
svcAvmClient
|
||||
svcAsmClient
|
||||
)
|
||||
NGL_INSTALL_TARGET(svcCombatNetRadio)
|
||||
NGL_INSTALL(AAR SV FILES log4cxx_cnr.props DESTINATION bin)
|
||||
NGL_ADD_TARGET_LINK(svcCombatNetRadio pCNR)
|
||||
@@ -0,0 +1,273 @@
|
||||
#include "cnr_frequency_planning_helper.h"
|
||||
#include <AudioVideoManagement/avm_translation.h>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QSet>
|
||||
#include <QVector>
|
||||
// Todo: Better tr() ?
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace AudioVideoManagement {
|
||||
|
||||
template<typename T>
|
||||
T fromJson(const QByteArray &json)
|
||||
{
|
||||
QJsonParseError jError;
|
||||
QJsonDocument doc(QJsonDocument::fromJson(json, &jError));
|
||||
if (jError.error)
|
||||
return {};
|
||||
QJsonObject obj = doc.object();
|
||||
return T::fromJson(obj);
|
||||
}
|
||||
|
||||
// Todo:
|
||||
|
||||
//
|
||||
// FreqPlanningDataSet ist nur noch ein pro FreqPlanningData vorhanden. Also integrieren in die Relation.
|
||||
// DB und DDS Typen anpassen
|
||||
// Die Properties einer FreqPlanningData(Set) sind ein Array (REL) (VHF/UHF/HF)
|
||||
// wie in der Methode unter diesem Kommentar (bei dem die RadioSpecificaJSON schon mit rein geht!),
|
||||
// siehe avm_edit_frequency_planning_resource_dialog.cpp:120
|
||||
// Aus dieser einen Zeile müssen dann im Übersichtsdialog entweder ein Eintrag oder (mindestens) 3 Einträge (REL) gemacht werden.
|
||||
// Die RadioSpecificaHelper also um Hilfsmethoden erweitern, damit man passende Objekte bekommt.
|
||||
// Vielleicht die drei items Name, FreqBand, RadioStation ID gleich mit in die Specifica, bzw. von was ableiten, dass das beinhaltet!
|
||||
|
||||
// Method to obtain all "FrequencySetDataId" from an QJsonObject
|
||||
QJsonObject frequencyPlanningJson(QJsonObject obj, const QString &name, FrequencyBand freqBand, int radioStationId)
|
||||
{
|
||||
obj.insert(QStringLiteral("Name"), name);
|
||||
obj.insert(QStringLiteral("FrequencyBand"), freqBand.underlying());
|
||||
obj.insert(QStringLiteral("RadioStationId"), radioStationId);
|
||||
return obj;
|
||||
}
|
||||
|
||||
bool RadioCircuitHF::isValid() const
|
||||
{
|
||||
if ((modulationType != ModulationType::AM && modulationType != ModulationType::FM) ||
|
||||
(channelSpacing != ChannelSpacingHF::CS_100_Hz) ||
|
||||
frequency < FREQ_MIN || frequency > FREQ_MAX ||
|
||||
squelch < (SQUELCH_MIN-1) || squelch > SQUELCH_MAX
|
||||
)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QJsonObject RadioCircuitHF::toJson() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("ModulationType"), modulationType.underlying());
|
||||
obj.insert(QStringLiteral("ChannelSpacing"), channelSpacing.underlying());
|
||||
obj.insert(QStringLiteral("Frequency"), frequency);
|
||||
obj.insert(QStringLiteral("Squelch"), squelch);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
RadioCircuitHF* RadioCircuitHF::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
RadioCircuitHF *spec = new RadioCircuitHF();
|
||||
spec->modulationType = static_cast<ModulationType::inner_enum>(obj.value(QStringLiteral("ModulationType")).toInt(-1));
|
||||
spec->channelSpacing = static_cast<ChannelSpacingHF::inner_enum>(obj.value(QStringLiteral("ChannelSpacing")).toInt());
|
||||
spec->frequency = obj.value(QStringLiteral("Frequency")).toInt();
|
||||
spec->squelch = obj.value(QStringLiteral("Squelch")).toInt(-1);
|
||||
if (spec->isValid())
|
||||
return spec;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool RadioCircuitUHF::isValid() const
|
||||
{
|
||||
if ((modulationType != ModulationType::AM && modulationType != ModulationType::FM) ||
|
||||
(channelSpacing != ChannelSpacing::CS_8_33_kHz && channelSpacing != ChannelSpacing::CS_12_50_kHz && channelSpacing != ChannelSpacing::CS_25_00_kHz) ||
|
||||
frequency < FREQ_MIN || frequency > FREQ_MAX ||
|
||||
((squelchDB < SQUELCH_MIN || squelchDB > SQUELCH_MAX) && squelchDB != 0) // 0 or Min <squelch < max
|
||||
)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QJsonObject RadioCircuitUHF::toJson() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("ModulationType"), modulationType.underlying());
|
||||
obj.insert(QStringLiteral("ChannelSpacing"), channelSpacing.underlying());
|
||||
obj.insert(QStringLiteral("Frequency"), frequency);
|
||||
obj.insert(QStringLiteral("Squelch"), squelchDB);
|
||||
obj.insert(QStringLiteral("Clipper"), clipper);
|
||||
obj.insert(QStringLiteral("AGC"), agc);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
RadioCircuitUHF* RadioCircuitUHF::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
RadioCircuitUHF *spec = new RadioCircuitUHF();
|
||||
spec->modulationType = static_cast<ModulationType::inner_enum>(obj.value(QStringLiteral("ModulationType")).toInt(-1));
|
||||
spec->channelSpacing = static_cast<ChannelSpacing::inner_enum>(obj.value(QStringLiteral("ChannelSpacing")).toInt());
|
||||
spec->frequency = obj.value(QStringLiteral("Frequency")).toInt();
|
||||
spec->squelchDB = obj.value(QStringLiteral("Squelch")).toInt(-1);
|
||||
auto clipper = obj.value(QStringLiteral("Clipper"));
|
||||
if (clipper.isUndefined() || !clipper.isBool())
|
||||
return nullptr;
|
||||
spec->clipper = clipper.toBool();
|
||||
auto agc = obj.value(QStringLiteral("AGC"));
|
||||
if (agc.isUndefined() || !agc.isBool())
|
||||
return {};
|
||||
spec->agc = agc.toBool();
|
||||
|
||||
if (spec->isValid())
|
||||
return spec;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QJsonObject RadioCircuitVHF::toJson() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("OperatingMode"), operatingMode.underlying());
|
||||
obj.insert(QStringLiteral("FrequencySetDataId"), freqSetDataId);
|
||||
obj.insert(QStringLiteral("PilotTone"), pilotTone);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
RadioCircuitVHF* RadioCircuitVHF::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
RadioCircuitVHF *spec = new RadioCircuitVHF();
|
||||
spec->operatingMode = static_cast<RcOperatingMode::inner_enum>(obj.value(QStringLiteral("OperatingMode")).toInt(-1));
|
||||
spec->freqSetDataId = obj.value(QStringLiteral("FrequencySetDataId")).toInt();
|
||||
auto pilotTone = obj.value(QStringLiteral("PilotTone"));
|
||||
if (pilotTone.isUndefined() || !pilotTone.isBool())
|
||||
return nullptr;
|
||||
spec->pilotTone = pilotTone.toBool();
|
||||
|
||||
if (spec->isValid())
|
||||
return spec;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QString RadioCircuitHF::toString() const
|
||||
{
|
||||
|
||||
return QCoreApplication::translate("AVM", "Frequency: %1, ModulationType: %2, ChannelSpacing: %3, Squelch: %4")
|
||||
.arg(frequency)
|
||||
.arg(AudioVideoManagement::toString(modulationType))
|
||||
.arg(100)
|
||||
.arg(squelch);
|
||||
}
|
||||
|
||||
QString RadioCircuitUHF::toString() const
|
||||
{
|
||||
return QCoreApplication::translate("AVM", "Frequency: %1, ModulationType: %2, ChannelSpacing: %3, Squelch: %4, Clipper: %5, AGC: %6")
|
||||
.arg(frequency)
|
||||
.arg(AudioVideoManagement::toString(modulationType))
|
||||
.arg(AudioVideoManagement::toString(channelSpacing))
|
||||
.arg(squelchDB)
|
||||
.arg(clipper)
|
||||
.arg(agc);
|
||||
}
|
||||
|
||||
QString RadioCircuitVHF::toString() const
|
||||
{
|
||||
return QCoreApplication::translate("AVM", "OperatingMode: %1, PilotTone: %2")
|
||||
.arg(AudioVideoManagement::toString(operatingMode))
|
||||
.arg(pilotTone);
|
||||
}
|
||||
|
||||
QVector<RadioCircuit*> fromJson(const std::string &json)
|
||||
{
|
||||
QVector<RadioCircuit*> vec;
|
||||
QJsonParseError err;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(json), &err);
|
||||
|
||||
if(err.error != QJsonParseError::NoError)
|
||||
return {};
|
||||
|
||||
QJsonArray arr = doc.object().value(QStringLiteral("subCircuits")).toArray();
|
||||
|
||||
// Todo? Check if values are correctly filled and values are present...
|
||||
// maybe VHF is missing a frequencysetid : show ErrorMessage?
|
||||
for(const QJsonValue &val : qAsConst(arr))
|
||||
{
|
||||
RadioCircuit *rc = nullptr;
|
||||
const QJsonObject obj = val.toObject();
|
||||
FrequencyBand ft = static_cast<FrequencyBand::inner_enum>(obj[QStringLiteral("FrequencyBand")].toInt());
|
||||
switch (ft.underlying())
|
||||
{
|
||||
case FrequencyBand_def::HF:
|
||||
rc = RadioCircuitHF::fromJson(obj);
|
||||
break;
|
||||
case FrequencyBand_def::UHF:
|
||||
rc = RadioCircuitUHF::fromJson(obj);
|
||||
break;
|
||||
case FrequencyBand_def::VHF:
|
||||
rc = RadioCircuitVHF::fromJson(obj);
|
||||
break;
|
||||
case FrequencyBand_def::REL:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(rc)
|
||||
{
|
||||
rc->freqBand = ft;
|
||||
rc->name = obj[QStringLiteral("Name")].toString();
|
||||
rc->radioStationId = obj[QStringLiteral("RadioStationId")].toInt();
|
||||
vec << rc;
|
||||
}
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
QSet<int> frequencySetDataIds(const std::string &frequencyPlanDataProperties)
|
||||
{
|
||||
QSet<int> set;
|
||||
QJsonParseError err;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(frequencyPlanDataProperties), &err);
|
||||
|
||||
if(err.error != QJsonParseError::NoError)
|
||||
return {};
|
||||
|
||||
QJsonArray arr = doc.object().value(QStringLiteral("subCircuits")).toArray();
|
||||
|
||||
// Todo? Check if values are correctly filled and values are present...
|
||||
for(const QJsonValue &val : qAsConst(arr))
|
||||
{
|
||||
const QJsonObject obj = val.toObject();
|
||||
FrequencyBand ft = static_cast<FrequencyBand::inner_enum>(obj[QStringLiteral("FrequencyBand")].toInt());
|
||||
switch (ft.underlying())
|
||||
{
|
||||
case FrequencyBand_def::VHF:
|
||||
{
|
||||
RadioCircuitVHF *rcVhf = RadioCircuitVHF::fromJson(obj);
|
||||
if(!rcVhf)
|
||||
break;
|
||||
set << rcVhf->frequencySetDataId();
|
||||
delete rcVhf;
|
||||
break;
|
||||
}
|
||||
case FrequencyBand_def::UHF:
|
||||
case FrequencyBand_def::HF:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
bool isReadOnly(const std::string &frequencyPlanDataProperties)
|
||||
{
|
||||
QJsonParseError err;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(frequencyPlanDataProperties), &err);
|
||||
|
||||
if(err.error != QJsonParseError::NoError)
|
||||
return false;
|
||||
|
||||
return doc.object().value(QStringLiteral("readOnly")).toBool();
|
||||
}
|
||||
|
||||
bool isAkwMode(RcOperatingMode mode)
|
||||
{
|
||||
return mode == RcOperatingMode::AkwEncEccm || mode == RcOperatingMode::AkwEncNone;
|
||||
}
|
||||
|
||||
} // AudioVideoManagement
|
||||
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
#include <QJsonDocument>
|
||||
#include <AudioVideoManagement/avm_enums.hpp>
|
||||
#include <CombatNetRadio/svccnrhelper_export.h>
|
||||
#include <CombatNetRadio/Helper/cnr_frequency_planning_helper.h>
|
||||
|
||||
namespace AudioVideoManagement {
|
||||
|
||||
struct SVCCNRHELPER_EXPORT RadioCircuit
|
||||
{
|
||||
RadioCircuit() = default;
|
||||
virtual ~RadioCircuit() = default;
|
||||
|
||||
QString name;
|
||||
FrequencyBand freqBand {FrequencyBand_def::VHF};
|
||||
int radioStationId {0};
|
||||
|
||||
|
||||
virtual bool isValid() const = 0;
|
||||
virtual QJsonObject toJson() const = 0;
|
||||
virtual QString toString() const = 0;
|
||||
virtual int frequencySetDataId() const = 0;
|
||||
};
|
||||
|
||||
struct SVCCNRHELPER_EXPORT RadioCircuitHF : public RadioCircuit
|
||||
{
|
||||
ModulationType modulationType {ModulationType::AM};
|
||||
ChannelSpacingHF channelSpacing {ChannelSpacingHF::CS_100_Hz};
|
||||
int frequency {0}; // Valid: 20.000-30.0000 [Hz]
|
||||
int squelch {0}; // Valid: 0..9
|
||||
|
||||
static const int FREQ_MIN = 2000000;
|
||||
static const int FREQ_MAX = 29975000;
|
||||
static const int SQUELCH_MIN = 1;
|
||||
static const int SQUELCH_MAX = 9;
|
||||
|
||||
RadioCircuitHF()
|
||||
: RadioCircuit()
|
||||
{}
|
||||
bool isValid() const;
|
||||
QJsonObject toJson() const;
|
||||
static RadioCircuitHF* fromJson(const QJsonObject &obj);
|
||||
QString toString() const;
|
||||
int frequencySetDataId() const { return 0; }
|
||||
};
|
||||
|
||||
struct SVCCNRHELPER_EXPORT RadioCircuitUHF: public RadioCircuit
|
||||
{
|
||||
ModulationType modulationType {ModulationType::AM};
|
||||
ChannelSpacing channelSpacing {ChannelSpacing::CS_25_00_kHz};
|
||||
int frequency {0}; // Valid: 225.000.000 - 399.975.000 [Hz]
|
||||
int squelchDB {0}; // Valid: 0 (off), 6-20 [dB]
|
||||
bool clipper {false};
|
||||
bool agc {false};
|
||||
|
||||
static const int FREQ_MIN = 225000000;
|
||||
static const int FREQ_MAX = 399975000;
|
||||
static const int SQUELCH_MIN = 6;
|
||||
static const int SQUELCH_MAX = 20;
|
||||
|
||||
RadioCircuitUHF()
|
||||
: RadioCircuit()
|
||||
{}
|
||||
|
||||
bool isValid() const;
|
||||
QJsonObject toJson() const;
|
||||
static RadioCircuitUHF* fromJson(const QJsonObject &obj);
|
||||
QString toString() const;
|
||||
int frequencySetDataId() const { return 0; }
|
||||
};
|
||||
|
||||
struct SVCCNRHELPER_EXPORT RadioCircuitVHF: public RadioCircuit
|
||||
{
|
||||
RcOperatingMode operatingMode {RcOperatingMode_def::FixedFreqEncNone};
|
||||
int freqSetDataId {0};
|
||||
bool pilotTone {false};
|
||||
|
||||
RadioCircuitVHF(RcOperatingMode _operatingMode, int _frequencySetDataId, bool _pilotTone)
|
||||
: RadioCircuit()
|
||||
, operatingMode(_operatingMode)
|
||||
, freqSetDataId(_frequencySetDataId)
|
||||
, pilotTone(_pilotTone)
|
||||
{}
|
||||
|
||||
RadioCircuitVHF() = default;
|
||||
int frequencySetDataId() const { return freqSetDataId; }
|
||||
bool isValid() const {return freqSetDataId > 0; }
|
||||
QJsonObject toJson() const;
|
||||
static RadioCircuitVHF* fromJson(const QJsonObject &obj);
|
||||
QString toString() const;
|
||||
|
||||
};
|
||||
|
||||
bool SVCCNRHELPER_EXPORT isReadOnly(const std::string& json);
|
||||
QVector<RadioCircuit*> SVCCNRHELPER_EXPORT fromJson(const std::string& json);
|
||||
QSet<int> SVCCNRHELPER_EXPORT frequencySetDataIds(const std::string &frequencyPlanDataProperties);
|
||||
QJsonObject SVCCNRHELPER_EXPORT frequencyPlanningJson(QJsonObject obj, const QString &name, FrequencyBand freqBand, int radioStationId);
|
||||
bool SVCCNRHELPER_EXPORT isAkwMode(RcOperatingMode mode);
|
||||
|
||||
} // namespace AudioVideoManagement
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientConnection class represents a connection to a single client.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "client_connection.h"
|
||||
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
using namespace CombatNetRadio::WebSocketInterface::Connection;
|
||||
|
||||
ClientConnection::ClientConnection(QWebSocket *socket, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_socket(socket)
|
||||
, m_ip(socket->peerAddress())
|
||||
, m_logger(getLogger(QLatin1String("ClientConnection")))
|
||||
{}
|
||||
|
||||
ClientConnection::~ClientConnection()
|
||||
{
|
||||
if (m_socket)
|
||||
{
|
||||
m_socket->disconnect(this);
|
||||
m_socket->close();
|
||||
}
|
||||
delete m_socket;
|
||||
}
|
||||
|
||||
bool ClientConnection::init()
|
||||
{
|
||||
if (m_socket == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation failed due to an invalid socket";
|
||||
return false;
|
||||
}
|
||||
|
||||
connect(m_socket, &QWebSocket::textMessageReceived, this, &ClientConnection::onNewTextMessageFromSocket);
|
||||
connect(m_socket, &QWebSocket::connected, this, &ClientConnection::sendMessagesFromQueue);
|
||||
connect(m_socket, &QWebSocket::disconnected, this, &ClientConnection::onSocketDisconnect);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QHostAddress ClientConnection::ip() const
|
||||
{
|
||||
return m_ip;
|
||||
}
|
||||
|
||||
void ClientConnection::addMessage(const CombatNetRadio::WebSocketInterface::Messages::ReplyMessage &message)
|
||||
{
|
||||
if (!m_socket || m_socket->state() != QAbstractSocket::ConnectedState)
|
||||
{
|
||||
m_messageQueue.enqueue(message);
|
||||
DEBUG_LOG(m_logger) << "Adding message to queue, size: " << m_messageQueue.size();
|
||||
return;
|
||||
}
|
||||
const QString msg(message.toJsonString());
|
||||
DEBUG_LOG(m_logger) << "Send msg: " << msg;
|
||||
m_socket->sendTextMessage(msg);
|
||||
}
|
||||
|
||||
void ClientConnection::onNewTextMessageFromSocket(const QString &message)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Recv msg: " << message;
|
||||
emit newTextMessage(this, message);
|
||||
}
|
||||
|
||||
void ClientConnection::sendMessagesFromQueue()
|
||||
{
|
||||
if (m_socket->state() != QAbstractSocket::ConnectedState)
|
||||
return;
|
||||
while (!m_messageQueue.isEmpty())
|
||||
{
|
||||
Messages::ReplyMessage message = m_messageQueue.dequeue();
|
||||
const QString msg(message.toJsonString());
|
||||
TRACE_LOG(m_logger) << "Send msg: " << msg;
|
||||
m_socket->sendTextMessage(msg);
|
||||
DEBUG_LOG(m_logger) << "Sent message from queue, new size: " << m_messageQueue.size();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientConnection::onSocketDisconnect()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Client with ip "
|
||||
<< m_ip.toString()
|
||||
<< " disconnected";
|
||||
emit disconnected(this);
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientConnection class represents a connection to a single client.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QQueue>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
|
||||
#include "WebSocketInterface/Messages/message_transmitter.h"
|
||||
#include "logger.h"
|
||||
|
||||
class QWebSocket;
|
||||
class QTimer;
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Connection
|
||||
{
|
||||
class ClientConnection
|
||||
: public QObject
|
||||
, public Messages::MessageTransmitter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClientConnection(QWebSocket *socket, QObject *parent = nullptr);
|
||||
~ClientConnection();
|
||||
|
||||
bool init();
|
||||
QHostAddress ip() const;
|
||||
void addMessage(const Messages::ReplyMessage &message) override final;
|
||||
|
||||
Q_SIGNALS:
|
||||
void newTextMessage(MessageTransmitter *transmitter, const QString &message);
|
||||
void disconnected(ClientConnection *conn);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onNewTextMessageFromSocket(const QString &message);
|
||||
void sendMessagesFromQueue();
|
||||
void onSocketDisconnect();
|
||||
|
||||
private: // methods
|
||||
void sendMessages();
|
||||
|
||||
private: // attributes
|
||||
QWebSocket *m_socket;
|
||||
QQueue<Messages::ReplyMessage> m_messageQueue;
|
||||
QHostAddress m_ip;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
}; // class ClientConnection
|
||||
} // namespace Connection
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ConnectionHandler class functions as a WebSocket server and manages incoming client connections.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "connection_handler.h"
|
||||
|
||||
#include "client_connection.h"
|
||||
|
||||
#include <QtWebSockets/QWebSocketServer>
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
|
||||
using namespace CombatNetRadio::WebSocketInterface::Connection;
|
||||
|
||||
ConnectionHandler::ConnectionHandler()
|
||||
: m_server(nullptr)
|
||||
, m_logger(getLogger("ConnectionHandler"))
|
||||
{
|
||||
}
|
||||
|
||||
ConnectionHandler::~ConnectionHandler()
|
||||
{
|
||||
for (auto s : qAsConst(m_connections))
|
||||
s->disconnect(this);
|
||||
qDeleteAll(m_connections);
|
||||
}
|
||||
|
||||
bool ConnectionHandler::init()
|
||||
{
|
||||
if (m_server != nullptr)
|
||||
{
|
||||
m_server->disconnect();
|
||||
delete m_server;
|
||||
}
|
||||
// TODO: get a server name from config ?
|
||||
// TODO: get the SslMode from config ?
|
||||
m_server = new QWebSocketServer(QStringLiteral("RDE-EXC"), QWebSocketServer::NonSecureMode, this);
|
||||
|
||||
connect(m_server, &QWebSocketServer::newConnection, this, &ConnectionHandler::onNewConnection);
|
||||
connect(m_server, &QWebSocketServer::serverError, this, &ConnectionHandler::onServerError);
|
||||
|
||||
// TODO: read port from config?
|
||||
quint16 port = 2081;
|
||||
DEBUG_LOG(m_logger) << "Trying to listen to port " << port;
|
||||
if (!m_server->listen(QHostAddress::Any, port))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Not possible to listen to port " << port;
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "... ok";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConnectionHandler::onUpdate()
|
||||
{
|
||||
emit clearFrequencyPlanningStatus();
|
||||
for (ClientConnection *currentConnection : qAsConst(m_connections))
|
||||
currentConnection->addMessage(Messages::UpdateMessage());
|
||||
}
|
||||
|
||||
void ConnectionHandler::onNewMessage(CombatNetRadio::WebSocketInterface::Messages::MessageTransmitter *transmitter, const QString &message)
|
||||
{
|
||||
emit newTextMessageFromClient(transmitter, message);
|
||||
}
|
||||
|
||||
void ConnectionHandler::onServerError(QWebSocketProtocol::CloseCode closeCode)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Got server error with close code " << closeCode;
|
||||
}
|
||||
|
||||
void ConnectionHandler::onNewConnection()
|
||||
{
|
||||
while (m_server->hasPendingConnections())
|
||||
{
|
||||
QWebSocket *socket = m_server->nextPendingConnection();
|
||||
ClientConnection *newConnection = new ClientConnection(socket, this);
|
||||
|
||||
if (!newConnection->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise new client";
|
||||
delete newConnection;
|
||||
newConnection = nullptr;
|
||||
continue;
|
||||
}
|
||||
|
||||
connect(newConnection, &ClientConnection::newTextMessage, this, &ConnectionHandler::onNewMessage);
|
||||
connect(newConnection, &ClientConnection::disconnected, this, &ConnectionHandler::onDisconnected);
|
||||
|
||||
m_connections.append(newConnection);
|
||||
DEBUG_LOG(m_logger) << "New client with ip " << newConnection->ip().toString() << " connected";
|
||||
emit newClientConnection((qint64) static_cast<WebSocketInterface::Connection::ClientConnection::MessageTransmitter*>(newConnection));
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionHandler::onDisconnected(ClientConnection *conn)
|
||||
{
|
||||
bool removeCount = m_connections.removeOne(conn);
|
||||
Q_ASSERT(removeCount == 1);
|
||||
conn->deleteLater(); // use deleteLater() as the signal is emitted from with ClientConnection
|
||||
|
||||
emit clientConnectionClosed((qint64) static_cast<WebSocketInterface::Connection::ClientConnection::MessageTransmitter*>(conn));
|
||||
if (m_connections.empty())
|
||||
emit lastConnectionClosed();
|
||||
}
|
||||
|
||||
void ConnectionHandler::onPositions(const CombatNetRadio::WebSocketInterface::Messages::ReplyMessage &positionsCnr)
|
||||
{
|
||||
for (ClientConnection *currentConnection : qAsConst(m_connections))
|
||||
currentConnection->addMessage(positionsCnr);
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ConnectionHandler class functions as a WebSocket server and manages incoming client connections.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtNetwork/QHostAddress>
|
||||
#include <QtWebSockets/qwebsocketprotocol.h>
|
||||
|
||||
#include "../Messages/reply_message.h"
|
||||
#include "logger.h"
|
||||
|
||||
class QWebSocketServer;
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter;
|
||||
}
|
||||
namespace Connection
|
||||
{
|
||||
class ClientConnection;
|
||||
|
||||
class ConnectionHandler
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConnectionHandler();
|
||||
~ConnectionHandler();
|
||||
|
||||
bool init();
|
||||
|
||||
Q_SIGNALS:
|
||||
void newTextMessageFromClient(Messages::MessageTransmitter *transmitter, const QString &message);
|
||||
void lastConnectionClosed();
|
||||
void newClientConnection(qint64 id);
|
||||
void clientConnectionClosed(qint64 id);
|
||||
void clearFrequencyPlanningStatus();
|
||||
|
||||
public Q_SLOTS:
|
||||
void onUpdate();
|
||||
void onPositions(const Messages::ReplyMessage &positionsCnr);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onNewMessage(Messages::MessageTransmitter *transmitter, const QString &message);
|
||||
void onServerError(QWebSocketProtocol::CloseCode closeCode);
|
||||
void onNewConnection();
|
||||
void onDisconnected(ClientConnection *conn);
|
||||
|
||||
private: // attributes
|
||||
QWebSocketServer *m_server;
|
||||
QVector<ClientConnection *> m_connections;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace Connection
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,210 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "client_message.h"
|
||||
#include "reply_message.h"
|
||||
#include "exercise_manager.h"
|
||||
#include "WebSocketInterface/Messages/message_transmitter.h"
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include "WebSocketInterface/json_keys.h"
|
||||
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtCore/QUuid>
|
||||
#include <chrono>
|
||||
|
||||
/*
|
||||
*python testing:
|
||||
|
||||
import websocket
|
||||
import json
|
||||
import time
|
||||
ws = websocket.create_connection("ws://127.0.0.1:2081")
|
||||
d = { 'type' : 'getEssentials', 'uuid': 'blub' }
|
||||
ws.send(json.dumps(d))
|
||||
d = { 'type' : 'getConfigCNR', 'uuid': 'blub' }
|
||||
ws.send(json.dumps(d))
|
||||
d = { 'type' : 'getPositionsCNR', 'uuid': 'blub', 'data': {'repeat': 10}}
|
||||
ws.send(json.dumps(d))
|
||||
while True:
|
||||
ws.recv()
|
||||
|
||||
*/
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
using namespace JsonKeys;
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
// ####### ClientMessage begin #######
|
||||
ClientMessage *ClientMessage::create(const QString &message, NGL::INGLLogger &logger)
|
||||
{
|
||||
ClientMessage *result = nullptr;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message which is not JSON conform: " << message;
|
||||
return new InvalidMessage(QString(), QStringLiteral("Got message which is not JSON conform"));
|
||||
}
|
||||
|
||||
QJsonObject obj = doc.object();
|
||||
|
||||
QJsonObject dataPart = obj.value(DATA()).toObject();
|
||||
QString type = obj.value(TYPE()).toString();
|
||||
QString uuid = obj.value(UUID_()).toString();
|
||||
|
||||
if (type.isEmpty())
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message without type: " << message;
|
||||
result = new InvalidMessage(uuid, QStringLiteral("Message has no type"));
|
||||
}
|
||||
else if (type == ERROR_() && dataPart.contains(ERROR_MESSAGE()) && dataPart.contains(ERROR_CLASS()) && dataPart.contains(UUID_()))
|
||||
{
|
||||
ERROR_LOG(logger) << "Got error message: " << QJsonDocument(dataPart).toJson();
|
||||
return nullptr;
|
||||
}
|
||||
else if (uuid.isEmpty())
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message without uuid: " << message;
|
||||
result = new InvalidMessage(QString(), QStringLiteral("Got message without uuid"));
|
||||
}
|
||||
else if (type == GET_ESSENTIALS())
|
||||
result = new GetEssentialsMessage(type, uuid, dataPart);
|
||||
else if (type == GET_CONFIG_CNR())
|
||||
result = new GetConfigCnrMessage(type, uuid, dataPart);
|
||||
else if (type == GET_POSITIONS_CNR())
|
||||
result = new GetPositionsCnrMessage(type, uuid, dataPart);
|
||||
else if (type == ALIVE_REQUEST())
|
||||
result = new AliveRequest(type, uuid, dataPart);
|
||||
else if (type == OK())
|
||||
result = new OkMessageC(type, uuid, dataPart);
|
||||
else if (type == CONFIG_CNR())
|
||||
result = new ConfigCnrMessageC(type, uuid, dataPart);
|
||||
|
||||
if (result == nullptr)
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message with invalid type: " << message;
|
||||
result = new InvalidMessage(uuid, QStringLiteral("Invalid type"));
|
||||
}
|
||||
|
||||
if (!result->hasValidData())
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message with invalid data part: " << message;
|
||||
delete result;
|
||||
result = new InvalidMessage(uuid, QStringLiteral("Has invalid data part"));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ClientMessage::ClientMessage(const QString &type, const QString &uuid, const QJsonObject &data)
|
||||
: m_type(type)
|
||||
, m_uuid(uuid)
|
||||
, m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
// ####### ClientMessage end #######
|
||||
|
||||
// ####### InvalidMessage begin #######
|
||||
void InvalidMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
Q_UNUSED(exerciseManager);
|
||||
ErrorMessage::ErrorData errorData;
|
||||
|
||||
errorData.errorClass = 1; // ??????????
|
||||
errorData.errorMessage = m_errorText;
|
||||
errorData.uuid = m_uuid;
|
||||
|
||||
transmitter->addMessage(ErrorMessage(errorData));
|
||||
}
|
||||
|
||||
bool InvalidMessage::hasValidData() const
|
||||
{
|
||||
// always true because there is no data part
|
||||
return true;
|
||||
}
|
||||
|
||||
// ####### InvalidMessage end #######
|
||||
|
||||
|
||||
// ####### GetEssentialsMessage begin #######
|
||||
void GetEssentialsMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
using namespace Messages;
|
||||
transmitter->addMessage(exerciseManager->trainingAreaData(m_uuid));
|
||||
|
||||
for (const ReplyMessage ¤tMessage : exerciseManager->radioStations(m_uuid))
|
||||
transmitter->addMessage(currentMessage);
|
||||
|
||||
QString requester = m_data.value(REQUESTER()).toString();
|
||||
bool isActiveClient = m_data.value(ISACTIVECLIENT()).toBool();
|
||||
|
||||
transmitter->addMessage(exerciseManager->configCnr(m_uuid));
|
||||
exerciseManager->onConfigCnrSent((qint64) transmitter, m_uuid, requester, isActiveClient);
|
||||
}
|
||||
|
||||
// ####### GetEssentialsMessage end #######
|
||||
|
||||
// ####### GetConfigCnrMessage begin #######
|
||||
void GetConfigCnrMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
QString requester = m_data.value(REQUESTER()).toString();
|
||||
bool isActiveClient = m_data.value(ISACTIVECLIENT()).toBool();
|
||||
transmitter->addMessage(exerciseManager->configCnr(m_uuid));
|
||||
exerciseManager->onConfigCnrSent((qint64) transmitter, m_uuid, requester, isActiveClient);
|
||||
}
|
||||
|
||||
// ####### GetConfigCnrMessage end #######
|
||||
|
||||
void OkMessageC::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
exerciseManager->onConfigCnrReceived((qint64) transmitter, m_uuid);
|
||||
}
|
||||
|
||||
// ####### GetPositionsCnrMessage begin #######
|
||||
void GetPositionsCnrMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
transmitter->addMessage(exerciseManager->positionsCnr(m_uuid));
|
||||
|
||||
int updateInterval = m_data.value(REPEAT()).toInt();
|
||||
if (updateInterval > 0)
|
||||
exerciseManager->setPositionsUpdateInterval(std::chrono::seconds(updateInterval));
|
||||
else
|
||||
exerciseManager->stopPositionsUpdate();
|
||||
}
|
||||
|
||||
bool GetPositionsCnrMessage::hasValidData() const
|
||||
{
|
||||
return m_data.contains(REPEAT());
|
||||
}
|
||||
|
||||
// ####### GetPositionsCnrMessage end #######
|
||||
|
||||
// ####### GetPositionsCnrMessage begin #######
|
||||
void AliveRequest::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
Q_UNUSED(exerciseManager);
|
||||
transmitter->addMessage(AliveResponse(m_uuid));
|
||||
}
|
||||
|
||||
void ConfigCnrMessageC::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
exerciseManager->onConfigCnrProcessed((qint64) transmitter, m_uuid, m_data);
|
||||
}
|
||||
|
||||
// ####### GetPositionsCnrMessage end #######
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QJsonObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
class ExerciseManager;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter;
|
||||
|
||||
class ClientMessage
|
||||
{
|
||||
public:
|
||||
static ClientMessage *create(const QString &message, NGL::INGLLogger &logger);
|
||||
|
||||
virtual void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) = 0;
|
||||
virtual bool hasValidData() const = 0;
|
||||
virtual ~ClientMessage() = default;
|
||||
ClientMessage(const QString &type, const QString &uuid, const QJsonObject &data = QJsonObject());
|
||||
|
||||
protected: // attributes
|
||||
const QString m_type;
|
||||
const QString m_uuid;
|
||||
const QJsonObject m_data;
|
||||
|
||||
}; // class ClientMessage
|
||||
|
||||
|
||||
class GetEssentialsMessage final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // class GetEssentialsMessage
|
||||
|
||||
class GetConfigCnrMessage final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // GetConfigCnrMessage
|
||||
|
||||
class GetPositionsCnrMessage final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override;
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // PositionsCnrMessage
|
||||
|
||||
class AliveRequest final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
};
|
||||
|
||||
|
||||
class OkMessageC final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
};
|
||||
|
||||
class ConfigCnrMessageC final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // ConfigCnrMessageC
|
||||
|
||||
class InvalidMessage final : public ClientMessage
|
||||
{
|
||||
friend class ClientMessage;
|
||||
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override;
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
|
||||
private: // attributes
|
||||
QString m_errorText;
|
||||
|
||||
}; // class InvalidMessage
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The MessageHandler class processes messages from the client an creates appropriate replys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "message_handler.h"
|
||||
#include "message_transmitter.h"
|
||||
#include "client_message.h"
|
||||
#include <memory>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
MessageHandler::MessageHandler(ExerciseManager *exerciseManager)
|
||||
: m_exerciseManager(exerciseManager)
|
||||
, m_logger(getLogger("MessageHandler"))
|
||||
{
|
||||
Q_ASSERT(exerciseManager);
|
||||
}
|
||||
|
||||
void MessageHandler::onNewTextMessage(MessageTransmitter *transmitter, const QString &message)
|
||||
{
|
||||
Q_ASSERT(transmitter);
|
||||
|
||||
const QString pingMsg(QStringLiteral("ping"));
|
||||
if (message.startsWith(pingMsg))
|
||||
{
|
||||
transmitter->addMessage(PongMessage(message.mid(pingMsg.size())));
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<ClientMessage> clientMessage(ClientMessage::create(message, m_logger));
|
||||
|
||||
if (!clientMessage)
|
||||
return;
|
||||
|
||||
clientMessage->process(m_exerciseManager, transmitter);
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace Messages
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The MessageHandler class processes messages from the client an creates appropriate replys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
class ExerciseManager;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter;
|
||||
|
||||
class MessageHandler
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MessageHandler(ExerciseManager *exerciseManager);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onNewTextMessage(MessageTransmitter *transmitter, const QString &message);
|
||||
|
||||
private:
|
||||
ExerciseManager *m_exerciseManager;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The MessageTransmitter Interface offers an extremely lightweight API for a class to just write textmessages to
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "reply_message.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter
|
||||
{
|
||||
public:
|
||||
virtual void addMessage(const ReplyMessage &message) = 0;
|
||||
};
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "reply_message.h"
|
||||
|
||||
#include "WebSocketInterface/json_keys.h"
|
||||
#include "helper.h"
|
||||
|
||||
#include <QtCore/QUuid>
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtGlobal>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
using namespace JsonKeys;
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
// ####### ReplyMessage begin #######
|
||||
QJsonObject ReplyMessage::LonLatPoint::toJSon() const
|
||||
{
|
||||
if (lon < 0 || lat < 0)
|
||||
return QJsonObject();
|
||||
return {{LONGITUDE(), lon}, {LATITUDE(), lat}};
|
||||
}
|
||||
|
||||
QJsonObject ReplyMessage::XYPoint::toJSon() const
|
||||
{
|
||||
return {{X(), x}, {Y(), y}};
|
||||
}
|
||||
|
||||
QString ReplyMessage::toJsonString() const
|
||||
{
|
||||
return QString::fromUtf8(QJsonDocument(m_jsonRepresentation).toJson()); //QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
ReplyMessage::ReplyMessage(const QString &type, const QString &uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(TYPE(), type);
|
||||
|
||||
Q_ASSERT(!uuid.isEmpty());
|
||||
m_jsonRepresentation.insert(UUID_(), uuid);
|
||||
}
|
||||
|
||||
QString ReplyMessage::uuid() const
|
||||
{
|
||||
return m_jsonRepresentation.value(UUID_()).toString();
|
||||
}
|
||||
|
||||
// ####### ReplyMessage end #######
|
||||
|
||||
// ####### OkMessage begin #######
|
||||
OkMessage::OkMessage(const OkMessage::OkData &data)
|
||||
: ReplyMessage(OK(), data.uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{MESSAGE_TYPE(), data.messageType},
|
||||
{INFO(), data.info}
|
||||
}));
|
||||
}
|
||||
// ####### OkMessage end #######
|
||||
|
||||
// ####### ErrorMessage begin #######
|
||||
ErrorMessage::ErrorMessage(const ErrorMessage::ErrorData &data)
|
||||
: ReplyMessage(ERROR_(), data.uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{ERROR_CLASS(), data.errorClass},
|
||||
{ERROR_MESSAGE(), data.errorMessage}
|
||||
}));
|
||||
}
|
||||
|
||||
// ####### ErrorMessage end #######
|
||||
|
||||
// ####### TrainingAreaMessage begin #######
|
||||
TrainingAreaMessage::TrainingAreaMessage(const TrainingAreaMessage::TrainingAreaData &data, const QString &uuid)
|
||||
: ReplyMessage(TRAINING_AREA(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{ID(), data.id},
|
||||
{DESIGNATION(), data.designation},
|
||||
{REF_POINT(), data.refPoint.toJSon()},
|
||||
{PATH(), vecToPath(data.path)}
|
||||
}));
|
||||
}
|
||||
// ####### TrainingAreaMessage end #######
|
||||
|
||||
// ####### RadioStationMessage begin #######
|
||||
RadioStationMessage::RadioStationMessage(const RadioStationMessage::RadioStationData &data, const QString &uuid)
|
||||
: ReplyMessage(RADIO_STATION(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{ID(), data.id},
|
||||
{DESIGNATION(), data.designation},
|
||||
{GEO_POINT(), data.geoPoint.toJSon()},
|
||||
{TRAINING_AREA_ID(), data.trainingAreaId}
|
||||
}));
|
||||
}
|
||||
// ####### RadioStationMessage end #######
|
||||
|
||||
// ####### ConfigCnrMessage begin #######
|
||||
QJsonObject ConfigCnrMessage::SubRadioCircuit::toJSon() const
|
||||
{
|
||||
|
||||
return QJsonObject({{RC_ID(), rcSubId},
|
||||
{RC_SUB_NAME(), rcSubName},
|
||||
{RC_MODE(), rcMode},
|
||||
{STATION(), station},
|
||||
{PT_SIG(), ptSig},
|
||||
{RC_TYPE(), rcType},
|
||||
{CROSSBEAM(), crossbeam},
|
||||
{ORIENTATION(), orientation},
|
||||
{FREQUENCY(), frequency},
|
||||
{AKW(), akw},
|
||||
{FSB(), fsb},
|
||||
{RC_AKW(), rcAkw},
|
||||
{COMSEC(), comsec},
|
||||
{MODULATION_TYPE(), modulationType},
|
||||
{CHANNEL_SPACING(), channelSpacing},
|
||||
{SQUELCH(), squelch},
|
||||
{CLIPPER(), clipper},
|
||||
{AGC(), agc}
|
||||
});
|
||||
}
|
||||
|
||||
QJsonObject ConfigCnrMessage::RadioCircuit::toJSon() const
|
||||
{
|
||||
return QJsonObject({{RC_ID(), rcId},
|
||||
{SSRC(), ssrc},
|
||||
{RC_NAME(), rcName},
|
||||
{IS_ROAMING(), isRoaming},
|
||||
{SUB_CIRCUIT(), vecToPath(subCircuits)}
|
||||
});
|
||||
}
|
||||
|
||||
ConfigCnrMessage::ConfigCnrMessage(const ConfigCnrMessage::ConfigCnrData &data, const QString &uuid)
|
||||
: ReplyMessage(CONFIG_CNR(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{SET_ID(), data.setId},
|
||||
{TIME(), QDateTime::currentDateTime().toString(Qt::ISODate)},
|
||||
{RADIO_CIRCUIT(), vecToPath(data.radioCircuit)}
|
||||
}));
|
||||
}
|
||||
// ####### ConfigCnrMessage end #######
|
||||
|
||||
// ####### PositionsCnrMessage begin #######
|
||||
QJsonObject PositionsCnrMessage::RadioCircuit::toJSon() const
|
||||
{
|
||||
return QJsonObject{{RC_ID(), rcId}, {POSITIONS(), vecToPath(positions)}};
|
||||
}
|
||||
|
||||
PositionsCnrMessage::PositionsCnrMessage(const PositionsCnrMessage::PositionsCnrMessageData &data, const QString &uuid)
|
||||
: ReplyMessage(POSITIONS_CNR(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{TIME(), data.time},
|
||||
{RADIO_CIRCUIT(), vecToPath(data.radioCircuit)}
|
||||
}));
|
||||
}
|
||||
// ####### PositionsCnrMessage end #######
|
||||
|
||||
// ####### UpdateMessage begin ######
|
||||
UpdateMessage::UpdateMessage(const QString &info)
|
||||
: ReplyMessage(UPDATE(), QUuid::createUuid().toString())
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(), QJsonObject({{INFO(), info}}));
|
||||
}
|
||||
// ####### UpdateMessage end ######
|
||||
|
||||
// ####### UpdateMessage begin ######
|
||||
AliveResponse::AliveResponse(const QString &uuid)
|
||||
: ReplyMessage(ALIVE_RESPONSE(), uuid)
|
||||
{
|
||||
}
|
||||
// ####### UpdateMessage end ######
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QJsonObject>
|
||||
#include <QtCore/QJsonArray>
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
class ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct LonLatPoint
|
||||
{
|
||||
double lon = 0.;
|
||||
double lat = 0.;
|
||||
|
||||
LonLatPoint() = default;
|
||||
LonLatPoint(double _lon, double _lat)
|
||||
: lon(_lon)
|
||||
, lat(_lat)
|
||||
{}
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct XYPoint
|
||||
{
|
||||
double x = 0.;
|
||||
double y = 0.;
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
ReplyMessage() = default; //!< QVector requires this; don't use directly
|
||||
|
||||
virtual ~ReplyMessage() = default;
|
||||
|
||||
virtual QString toJsonString() const;
|
||||
QString uuid() const;
|
||||
|
||||
|
||||
protected:
|
||||
template<typename T>
|
||||
static QJsonArray vecToPath(const QVector<T> &points)
|
||||
{
|
||||
QJsonArray result;
|
||||
for (const T &p : points)
|
||||
result.append(p.toJSon());
|
||||
return result;
|
||||
}
|
||||
|
||||
protected: // methods
|
||||
explicit ReplyMessage(const QString &type, const QString &uuid);
|
||||
|
||||
protected: // attributes
|
||||
QJsonObject m_jsonRepresentation;
|
||||
|
||||
}; // class Reply Message
|
||||
|
||||
class ErrorMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct ErrorData
|
||||
{
|
||||
int errorClass = 0;
|
||||
QString uuid;
|
||||
QString errorMessage;
|
||||
|
||||
ErrorData() = default;
|
||||
explicit ErrorData(int errorClass_, const QString &uuid_, const QString &errorMessage_)
|
||||
: errorClass(errorClass_)
|
||||
, uuid(uuid_)
|
||||
, errorMessage(errorMessage_)
|
||||
{}
|
||||
};
|
||||
|
||||
explicit ErrorMessage(const ErrorData &data);
|
||||
explicit ErrorMessage(int errorClass, const QString &uuid, const QString &errorMessage)
|
||||
: ErrorMessage(ErrorData(errorClass, uuid, errorMessage))
|
||||
{}
|
||||
}; // class ErrorMessage
|
||||
|
||||
|
||||
class OkMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct OkData
|
||||
{
|
||||
QString uuid;
|
||||
QString messageType;
|
||||
QString info;
|
||||
};
|
||||
|
||||
explicit OkMessage(const OkData &data);
|
||||
}; // class OkMessage
|
||||
|
||||
class TrainingAreaMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct TrainingAreaData
|
||||
{
|
||||
int32_t id;
|
||||
QString designation;
|
||||
LonLatPoint refPoint;
|
||||
QVector<LonLatPoint> path;
|
||||
};
|
||||
|
||||
explicit TrainingAreaMessage(const TrainingAreaData &data, const QString &uuid);
|
||||
}; // class TrainingAreaMessage
|
||||
|
||||
class RadioStationMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
|
||||
struct RadioStationData
|
||||
{
|
||||
int32_t id;
|
||||
QString designation;
|
||||
LonLatPoint geoPoint;
|
||||
int32_t trainingAreaId;
|
||||
};
|
||||
|
||||
explicit RadioStationMessage(const RadioStationData &data, const QString &uuid);
|
||||
}; // RadioStationMessage
|
||||
|
||||
class ConfigCnrMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct SubRadioCircuit
|
||||
{
|
||||
QString rcSubId;
|
||||
QString rcSubName;
|
||||
int32_t frequencyBand = 0;
|
||||
int32_t rcMode = 0;
|
||||
int32_t station = 0;
|
||||
int32_t ptSig = 0;
|
||||
int32_t rcType;
|
||||
int32_t crossbeam;
|
||||
int32_t orientation;
|
||||
int32_t frequency = 0;
|
||||
int32_t akw = 0;
|
||||
int32_t fsb = 0;
|
||||
int32_t rcAkw = 0;
|
||||
int32_t comsec = 0;
|
||||
int32_t modulationType;
|
||||
int32_t channelSpacing;
|
||||
int32_t squelch = 0;
|
||||
bool clipper;
|
||||
bool agc;
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct RadioCircuit
|
||||
{
|
||||
QString rcId;
|
||||
int32_t ssrc = 0;
|
||||
QString rcName;
|
||||
bool isRoaming;
|
||||
|
||||
QVector<SubRadioCircuit> subCircuits;
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct ConfigCnrData
|
||||
{
|
||||
int32_t setId = 0;
|
||||
QString time;
|
||||
QVector<RadioCircuit> radioCircuit;
|
||||
};
|
||||
|
||||
explicit ConfigCnrMessage(const ConfigCnrData &data, const QString &uuid);
|
||||
}; // ConfigCnrMessage
|
||||
|
||||
class PositionsCnrMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct RadioCircuit
|
||||
{
|
||||
QString rcId;
|
||||
QVector<LonLatPoint> positions;
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct PositionsCnrMessageData
|
||||
{
|
||||
QString time;
|
||||
QVector<RadioCircuit> radioCircuit;
|
||||
};
|
||||
|
||||
explicit PositionsCnrMessage(const PositionsCnrMessageData &data, const QString &uuid);
|
||||
}; // PositionsCnrMessage
|
||||
|
||||
class UpdateMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit UpdateMessage(const QString &info = QString());
|
||||
}; // UpdateMessage
|
||||
|
||||
class PongMessage final : public ReplyMessage
|
||||
{
|
||||
public:
|
||||
static QString strPong() { return QStringLiteral("pong"); }
|
||||
explicit PongMessage(const QString &payload)
|
||||
: ReplyMessage(strPong(), QString())
|
||||
, m_payload(payload)
|
||||
{}
|
||||
|
||||
QString toJsonString() const override
|
||||
{
|
||||
return m_payload.isEmpty() ? strPong() : QStringLiteral("%1 %2").arg(strPong(), m_payload);
|
||||
}
|
||||
private:
|
||||
QString m_payload;
|
||||
};
|
||||
|
||||
class AliveResponse final : public ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit AliveResponse(const QString &uuid);
|
||||
};
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Header file which holds all occuring JSON keys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace JsonKeys
|
||||
{
|
||||
// TODO: add constexpr once we do no longer support msvc2013
|
||||
// root keys
|
||||
inline QString DATA() { return QLatin1String("data"); }
|
||||
inline QString UUID_() { return QStringLiteral("uuid"); } // Windows: typedef GUID UUUID; ...
|
||||
inline QString TYPE() { return QStringLiteral("type"); }
|
||||
|
||||
// types for client --> server messages
|
||||
inline QString GET_ESSENTIALS() { return QStringLiteral("getEssentials"); }
|
||||
inline QString GET_CONFIG_CNR() { return QLatin1String("getConfigCNR"); }
|
||||
inline QString GET_POSITIONS_CNR() { return QLatin1String("getPositionsCNR"); }
|
||||
inline QString ALIVE_REQUEST() { return QLatin1String("aliveRequest"); }
|
||||
inline QString ERROR_() { return QLatin1String("error"); }
|
||||
|
||||
// types for server --> client messages
|
||||
inline QString TRAINING_AREA() { return QLatin1String("trainingArea"); }
|
||||
inline QString RADIO_STATION() { return QLatin1String("radioStation"); }
|
||||
inline QString POSITIONS_CNR() { return QLatin1String("positionsCNR"); }
|
||||
inline QString UPDATE() { return QLatin1String("update"); }
|
||||
inline QString ALIVE_RESPONSE() { return QLatin1String("aliveResponse"); }
|
||||
|
||||
// types for both directions
|
||||
inline QString OK() { return QStringLiteral("ok"); }
|
||||
inline QString CONFIG_CNR() { return QLatin1String("configCNR"); }
|
||||
|
||||
// data keys
|
||||
inline QString ID() { return QLatin1String("id"); }
|
||||
inline QString DESIGNATION() { return QLatin1String("designation"); }
|
||||
inline QString PATH() { return QLatin1String("path"); }
|
||||
inline QString GEO_POINT() { return QLatin1String("geoPoint"); }
|
||||
inline QString LATITUDE() { return QLatin1String("lat"); }
|
||||
inline QString LONGITUDE() { return QLatin1String("lon"); }
|
||||
inline QString POINT() { return QLatin1String("point"); }
|
||||
inline QString X() { return QLatin1String("x"); }
|
||||
inline QString Y() { return QLatin1String("y"); }
|
||||
inline QString REF_POINT() { return QLatin1String("refPoint"); }
|
||||
inline QString MGRS() { return QLatin1String("MGRS"); }
|
||||
inline QString TRAINING_AREA_ID() { return QLatin1String("trainingAreaId"); }
|
||||
inline QString TIME() { return QLatin1String("time"); }
|
||||
inline QString RADIO_CIRCUIT() { return QLatin1String("radioCircuit"); }
|
||||
inline QString RC_ID() { return QLatin1String("rcId"); }
|
||||
inline QString SSRC() { return QLatin1String("SSRC"); }
|
||||
inline QString RC_NAME() { return QLatin1String("rcName"); }
|
||||
inline QString IS_ROAMING() { return QLatin1String("isRoaming"); }
|
||||
inline QString SUB_CIRCUIT() { return QLatin1String("subCircuit"); }
|
||||
inline QString RC_SUB_ID() { return QLatin1String("rcSubId"); }
|
||||
inline QString RC_SUB_NAME() { return QLatin1String("rcSubName"); }
|
||||
inline QString RC_MODE() { return QLatin1String("rcMode"); }
|
||||
inline QString STATION() { return QLatin1String("station"); }
|
||||
inline QString PT_SIG() { return QLatin1String("ptSig"); }
|
||||
inline QString RC_TYPE() { return QLatin1String("rcType"); }
|
||||
inline QString CROSSBEAM() { return QLatin1String("crossbeam"); }
|
||||
inline QString ORIENTATION() { return QLatin1String("orientation"); }
|
||||
inline QString FREQUENCY() { return QLatin1String("frequency"); }
|
||||
inline QString AKW() { return QLatin1String("AKW"); }
|
||||
inline QString FSB() { return QLatin1String("FSB"); }
|
||||
inline QString RC_AKW() { return QLatin1String("rcAKW"); }
|
||||
inline QString COMSEC() { return QLatin1String("COMSEC"); }
|
||||
inline QString MODULATION_TYPE() { return QLatin1String("modulationType"); }
|
||||
inline QString CHANNEL_SPACING() { return QLatin1String("channelSpacing"); }
|
||||
inline QString SQUELCH() { return QLatin1String("squelch"); }
|
||||
inline QString CLIPPER() { return QLatin1String("clipper"); }
|
||||
inline QString AGC() { return QLatin1String("agc"); }
|
||||
inline QString REPEAT() { return QLatin1String("repeat"); }
|
||||
inline QString ERROR_CLASS() { return QLatin1String("errorClass"); }
|
||||
inline QString ERROR_MESSAGE() { return QLatin1String("errorMessage"); }
|
||||
inline QString MESSAGE_TYPE() { return QLatin1String("msgType"); }
|
||||
inline QString INFO() { return QLatin1String("info"); }
|
||||
inline QString SET_ID() { return QLatin1String("setId"); }
|
||||
inline QString POSITIONS() { return QLatin1String("positions"); }
|
||||
inline QString REQUESTER() { return QLatin1String("requester"); }
|
||||
inline QString REASON() { return QLatin1String("reason"); }
|
||||
inline QString ISACTIVECLIENT() { return QLatin1String("isActiveClient"); }
|
||||
|
||||
} // namespace JsonKeys
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "websocket_interface_handler.h"
|
||||
|
||||
#include "Connection/connection_handler.h"
|
||||
#include "Messages/message_handler.h"
|
||||
#include "Messages/message_transmitter.h"
|
||||
#include "dds_handler.h"
|
||||
#include "exercise_manager.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
WebSocketInterfaceHandler::WebSocketInterfaceHandler(ExerciseManager *exerciseManager)
|
||||
: m_exerciseManager(exerciseManager)
|
||||
, m_connectionHandler(nullptr)
|
||||
, m_messageHandler(nullptr)
|
||||
, m_logger(getLogger("WebSocketInterfaceHandler"))
|
||||
{
|
||||
Q_ASSERT(exerciseManager);
|
||||
}
|
||||
|
||||
WebSocketInterfaceHandler::~WebSocketInterfaceHandler()
|
||||
{
|
||||
delete m_connectionHandler;
|
||||
delete m_messageHandler;
|
||||
}
|
||||
|
||||
bool WebSocketInterfaceHandler::init()
|
||||
{
|
||||
Q_ASSERT(!m_connectionHandler);
|
||||
|
||||
m_connectionHandler = new Connection::ConnectionHandler;
|
||||
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::newClientConnection, m_exerciseManager, &ExerciseManager::onNewClientConnection);
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::clientConnectionClosed, m_exerciseManager, &ExerciseManager::onClientConnectionClosed);
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::clearFrequencyPlanningStatus, m_exerciseManager, &ExerciseManager::onClearFrequencyPlanningStatus);
|
||||
|
||||
if (!m_connectionHandler->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise ConnectionHandler";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_messageHandler = new Messages::MessageHandler(m_exerciseManager);
|
||||
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::lastConnectionClosed, m_exerciseManager, &ExerciseManager::stopPositionsUpdate);
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::newTextMessageFromClient, m_messageHandler, &Messages::MessageHandler::onNewTextMessage);
|
||||
QObject::connect(m_exerciseManager, &ExerciseManager::essentialsUpdate, m_connectionHandler, &Connection::ConnectionHandler::onUpdate);
|
||||
QObject::connect(m_exerciseManager, &ExerciseManager::positionsUpdate, m_connectionHandler, &Connection::ConnectionHandler::onPositions);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
class ExerciseManager;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageHandler;
|
||||
}
|
||||
namespace Connection
|
||||
{
|
||||
class ConnectionHandler;
|
||||
}
|
||||
|
||||
class WebSocketInterfaceHandler final
|
||||
{
|
||||
public:
|
||||
explicit WebSocketInterfaceHandler(ExerciseManager *exerciseManager);
|
||||
~WebSocketInterfaceHandler();
|
||||
|
||||
bool init();
|
||||
|
||||
private:
|
||||
ExerciseManager *m_exerciseManager;
|
||||
Connection::ConnectionHandler *m_connectionHandler;
|
||||
Messages::MessageHandler *m_messageHandler;
|
||||
LOGGER_T m_logger;
|
||||
}; // class WebSocketInterfaceHandle
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ActiveExercises
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-01
|
||||
*/
|
||||
|
||||
#include "active_exercises.h"
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include <ExerciseManagement/exm.hpp>
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
bool isActive(ExerciseManagement::ExerciseState state)
|
||||
{
|
||||
return (state == ExerciseManagement::ExerciseState::Started ||
|
||||
state == ExerciseManagement::ExerciseState::Paused);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
ActiveExercises::ActiveExercises(ExerciseManagement::Interface::Dtc *exmDtc)
|
||||
: m_exmDtc(exmDtc)
|
||||
{
|
||||
Q_ASSERT(exmDtc);
|
||||
|
||||
connect(m_exmDtc, &ExerciseManagement::Interface::Dtc::exerciseChanged, this, &ActiveExercises::onExerciseChanged);
|
||||
|
||||
// Make sure that the topic is enabled *after* construction.
|
||||
Q_ASSERT(!m_exmDtc->isExerciseEnabled());
|
||||
}
|
||||
|
||||
void ActiveExercises::onExerciseChanged(const ExerciseManagement::Exercise &exercise, DataModification modType)
|
||||
{
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
Q_FALLTHROUGH();
|
||||
case DataModification::eModified:
|
||||
check(exercise);
|
||||
break;
|
||||
|
||||
case DataModification::eRemoved:
|
||||
tryDeactivate(exercise.id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ActiveExercises::check(const ExerciseManagement::Exercise &exercise)
|
||||
{
|
||||
Q_ASSERT(exercise.id() > 0);
|
||||
|
||||
if (isActive(exercise.state()))
|
||||
tryActivate(exercise.id());
|
||||
else
|
||||
tryDeactivate(exercise.id());
|
||||
}
|
||||
|
||||
void ActiveExercises::tryActivate(int exerciseId)
|
||||
{
|
||||
Q_ASSERT(exerciseId > 0);
|
||||
|
||||
auto found = m_activeExercises.find(exerciseId);
|
||||
if (found != m_activeExercises.end())
|
||||
return;
|
||||
|
||||
m_activeExercises.insert(exerciseId);
|
||||
emit activated(exerciseId);
|
||||
}
|
||||
|
||||
void ActiveExercises::tryDeactivate(int exerciseId)
|
||||
{
|
||||
Q_ASSERT(exerciseId > 0);
|
||||
|
||||
auto found = m_activeExercises.find(exerciseId);
|
||||
if (found == m_activeExercises.end())
|
||||
return;
|
||||
|
||||
m_activeExercises.erase(found);
|
||||
emit deactivated(exerciseId);
|
||||
}
|
||||
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ActiveExercises
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-01
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <set>
|
||||
|
||||
namespace ExerciseManagement
|
||||
{
|
||||
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
|
||||
class Exercise;
|
||||
|
||||
} // namespace ExerciseManagement
|
||||
|
||||
enum class DataModification;
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
/**
|
||||
* Observes the Exercises and signals whenever an Exercise gets activated or deactivated.
|
||||
* An Exercise is considered active if its state is either Started or Paused.
|
||||
* Whether the Exercise has an active FrequencyPlanning is irrelevant.
|
||||
*
|
||||
* @author Christian Fröbel
|
||||
*/
|
||||
class ActiveExercises : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ActiveExercises(ExerciseManagement::Interface::Dtc *exmDtc);
|
||||
|
||||
signals:
|
||||
void activated(int exerciseId);
|
||||
void deactivated(int exerciseId);
|
||||
|
||||
private:
|
||||
void onExerciseChanged(const ExerciseManagement::Exercise &exercise, DataModification modType);
|
||||
|
||||
private:
|
||||
void check(const ExerciseManagement::Exercise &exercise);
|
||||
void tryActivate(int exerciseId);
|
||||
void tryDeactivate(int exerciseId);
|
||||
|
||||
ExerciseManagement::Interface::Dtc *m_exmDtc;
|
||||
std::set<int> m_activeExercises;
|
||||
};
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<service namespace="CombatNetRadio" abbreviation="CNR" procNames="CombatNetRadio" exerciseDependency="Global" groups="Core" prio="3">
|
||||
<rcs>
|
||||
<Id Id="$Id: ea_export_script.txt 33922 2017-06-27 12:34:31Z ehrlicher $"/>
|
||||
<HeadURL HeadURL="$HeadURL: svn://slssvn/TDS/branches/product/devel/trunk/Lts/Common/CodeGen/ea_export_script.txt $"/>
|
||||
<Author Author="$Author: ehrlicher $"/>
|
||||
</rcs>
|
||||
<tables/>
|
||||
<views/>
|
||||
<dbServiceStructs/>
|
||||
<topicTypes/>
|
||||
<functionTopics/>
|
||||
<enumerations/>
|
||||
</service>
|
||||
Executable
+261
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ConfigCnr
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-05
|
||||
*/
|
||||
|
||||
#include "config_cnr.h"
|
||||
#include "helper.h"
|
||||
#include <AudioVideoManagement/avm_dtc.h>
|
||||
#include <AudioVideoManagement/avm_translation.h>
|
||||
#include <InfrastructureManagement/ism_dtc.h>
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QJsonDocument>
|
||||
#include <Proxies/CombatNetRadio/Helper/cnr_frequency_planning_helper.h>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
ConfigCnr::ConfigCnr(int exerciseId, AudioVideoManagement::Interface::Dtc *avmDtc, InfrastructureManagement::Interface::Dtc *ismDtc)
|
||||
: m_exerciseId(exerciseId)
|
||||
, m_avmDtc(avmDtc)
|
||||
, m_ismDtc(ismDtc)
|
||||
, m_logger(getLogger("ConfigCnr"))
|
||||
, m_loggerJson(getLogger("ConfigCnr.Json"))
|
||||
{
|
||||
Q_ASSERT(avmDtc);
|
||||
Q_ASSERT(ismDtc);
|
||||
|
||||
m_timer.setSingleShot(true);
|
||||
m_timer.setInterval(200);
|
||||
connect(&m_timer, &QTimer::timeout, this, &ConfigCnr::buildConfigCnrData);
|
||||
|
||||
connect(m_avmDtc, &AudioVideoManagement::Interface::Dtc::activeFrequencyPlanningChanged, this, &ConfigCnr::onActiveFrequencyPlanningChanged);
|
||||
connect(m_avmDtc, &AudioVideoManagement::Interface::Dtc::frequencyPlanningChanged, this, &ConfigCnr::onFrequencyPlanningChanged);
|
||||
connect(m_avmDtc, &AudioVideoManagement::Interface::Dtc::cnrConfigChanged, this, &ConfigCnr::onCnrConfigChanged);
|
||||
|
||||
buildConfigCnrData();
|
||||
}
|
||||
|
||||
const WebSocketInterface::Messages::ConfigCnrMessage::ConfigCnrData &ConfigCnr::data() const
|
||||
{
|
||||
Q_ASSERT(hasActiveFrequencyPlanning());
|
||||
return m_configCnrData;
|
||||
}
|
||||
|
||||
void ConfigCnr::buildConfigCnrData()
|
||||
{
|
||||
WebSocketInterface::Messages::ConfigCnrMessage::ConfigCnrData configCnr;
|
||||
|
||||
boost::optional<AudioVideoManagement::FrequencyPlanning> plan = activePlan();
|
||||
if (!plan)
|
||||
{
|
||||
m_configCnrData = configCnr;
|
||||
emit changed();
|
||||
return;
|
||||
}
|
||||
|
||||
AudioVideoManagement::FrequencySet frequencySet = m_avmDtc->frequencySet(plan->frequencySetId());
|
||||
QMap<int, AudioVideoManagement::FrequencySetDataWithId> fsdMap;
|
||||
for (const auto &fsd : qAsConst(frequencySet.data()))
|
||||
fsdMap.insert(fsd.id(), fsd);
|
||||
|
||||
configCnr.setId = plan->frequencySetId();
|
||||
configCnr.time = QDateTime::fromMSecsSinceEpoch(plan->date()).toString(Qt::ISODate);
|
||||
configCnr.radioCircuit.reserve(plan->data().size());
|
||||
|
||||
for (const auto ¤tData : plan->data())
|
||||
{
|
||||
|
||||
WebSocketInterface::Messages::ConfigCnrMessage::RadioCircuit radioCircuit;
|
||||
AudioVideoManagement::CnrConfig cnrConfig = m_avmDtc->cnrConfig(currentData.cnrConfigId());
|
||||
AudioVideoManagement::CnrChannel cnrChannel = m_avmDtc->cnrChannel(cnrConfig.cnrChannelId());
|
||||
QVector<AudioVideoManagement::RadioCircuit*> circuits = AudioVideoManagement::fromJson(currentData.properties());
|
||||
|
||||
int subCircuitCount = 0;
|
||||
for (AudioVideoManagement::RadioCircuit* circuit : qAsConst(circuits))
|
||||
{
|
||||
|
||||
InfrastructureManagement::MainStructureElement radioStation = m_ismDtc->mainStructureElement(circuit->radioStationId);
|
||||
|
||||
|
||||
WebSocketInterface::Messages::ConfigCnrMessage::SubRadioCircuit subCircuit;
|
||||
switch (circuit->freqBand.underlying())
|
||||
{
|
||||
case AudioVideoManagement::FrequencyBand_def::VHF:
|
||||
{
|
||||
AudioVideoManagement::RadioCircuitVHF *rcVhf = dynamic_cast<AudioVideoManagement::RadioCircuitVHF*>(circuit);
|
||||
if (!rcVhf)
|
||||
break;
|
||||
|
||||
AudioVideoManagement::FrequencySetDataWithId &fsd = fsdMap[rcVhf->freqSetDataId];
|
||||
subCircuit.agc = false;
|
||||
subCircuit.akw = fsd.akwBundle().is_set() ? fsd.akwBundle().get() : 0;
|
||||
subCircuit.channelSpacing = 0;
|
||||
subCircuit.clipper = false;
|
||||
subCircuit.comsec = fsd.comsec().is_set() ? fsd.comsec().get() : 0;
|
||||
subCircuit.crossbeam = 0;
|
||||
subCircuit.frequency = fsd.frequency() * 1000; // kHz --> Hz
|
||||
subCircuit.frequencyBand = fsd.frequencyBand().underlying();
|
||||
subCircuit.fsb = fsd.fsbBundle().is_set() ? fsd.fsbBundle().get() : 0;
|
||||
subCircuit.modulationType = 0;
|
||||
subCircuit.orientation = 0;
|
||||
subCircuit.ptSig = rcVhf->pilotTone;
|
||||
subCircuit.rcAkw = fsd.akwRadioCircuit().is_set() ? fsd.akwRadioCircuit().get() : 0;
|
||||
subCircuit.rcMode = rcVhf->operatingMode.underlying();
|
||||
subCircuit.rcSubId = toRcIdString(cnrChannel);
|
||||
subCircuit.rcSubName = rcVhf->name;
|
||||
subCircuit.rcType = 2;//circuit->freqBand.underlying();
|
||||
subCircuit.squelch = 0;
|
||||
subCircuit.station = stationId(radioStation);
|
||||
|
||||
break;
|
||||
}
|
||||
case AudioVideoManagement::FrequencyBand_def::UHF:
|
||||
{
|
||||
AudioVideoManagement::RadioCircuitUHF *rcUhf = dynamic_cast<AudioVideoManagement::RadioCircuitUHF*>(circuit);
|
||||
if (!rcUhf)
|
||||
break;
|
||||
|
||||
subCircuit.agc = rcUhf->agc;
|
||||
subCircuit.akw = 0;
|
||||
subCircuit.channelSpacing = rcUhf->channelSpacing.underlying();
|
||||
subCircuit.clipper = rcUhf->clipper;
|
||||
subCircuit.comsec = 0;
|
||||
subCircuit.crossbeam = 0;
|
||||
subCircuit.frequency = rcUhf->frequency; // Really? ICD says different
|
||||
subCircuit.frequencyBand = 0; // == rcType?
|
||||
subCircuit.fsb = 0;
|
||||
subCircuit.modulationType = rcUhf->modulationType.underlying();
|
||||
subCircuit.orientation = 0;
|
||||
subCircuit.ptSig = 0;
|
||||
subCircuit.rcAkw = 0;
|
||||
subCircuit.rcMode = 0; // VHF only?
|
||||
subCircuit.rcSubId = toRcIdString(cnrChannel);
|
||||
subCircuit.rcSubName = rcUhf->name;
|
||||
subCircuit.rcType = 3;//circuit->freqBand.underlying();
|
||||
subCircuit.squelch = rcUhf->squelchDB;
|
||||
subCircuit.station = stationId(radioStation);
|
||||
break;
|
||||
}
|
||||
case AudioVideoManagement::FrequencyBand_def::HF:
|
||||
{
|
||||
AudioVideoManagement::RadioCircuitHF *rcHf = dynamic_cast<AudioVideoManagement::RadioCircuitHF*>(circuit);
|
||||
if (!rcHf)
|
||||
break;
|
||||
|
||||
subCircuit.agc = 0;
|
||||
subCircuit.akw = 0;
|
||||
subCircuit.channelSpacing = rcHf->channelSpacing.underlying();
|
||||
subCircuit.clipper = 0;
|
||||
subCircuit.comsec = 0;
|
||||
subCircuit.crossbeam = 0;
|
||||
subCircuit.frequency = rcHf->frequency; // Really? ICD says different
|
||||
subCircuit.frequencyBand = 0; // == rcType?
|
||||
subCircuit.fsb = 0;
|
||||
subCircuit.modulationType = rcHf->modulationType.underlying();
|
||||
subCircuit.orientation = 0;
|
||||
subCircuit.ptSig = 0;
|
||||
subCircuit.rcAkw = 0;
|
||||
subCircuit.rcMode = 0; // VHF only?
|
||||
subCircuit.rcSubId = toRcIdString(cnrChannel);
|
||||
subCircuit.rcSubName = rcHf->name;
|
||||
subCircuit.rcType = 1;//circuit->freqBand.underlying();
|
||||
subCircuit.squelch = rcHf->squelch;
|
||||
subCircuit.station = stationId(radioStation);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (circuits.count() > 1)
|
||||
subCircuit.rcSubId.append(QChar('A' + subCircuitCount++));
|
||||
radioCircuit.subCircuits.append(subCircuit);
|
||||
}
|
||||
qDeleteAll(circuits);
|
||||
|
||||
radioCircuit.rcId = toRcIdString(cnrChannel);
|
||||
radioCircuit.rcName = QString::fromStdString(cnrConfig.radioCircuit());
|
||||
radioCircuit.ssrc = cnrChannel.ssrc();
|
||||
|
||||
configCnr.radioCircuit.append(radioCircuit);
|
||||
}
|
||||
// NOTICE_LOG(m_loggerJson) << WebSocketInterface::Messages::ConfigCnrMessage(configCnr, QUuid::createUuid().toString()).toJsonString();
|
||||
|
||||
m_configCnrData = configCnr;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
boost::optional<AudioVideoManagement::FrequencyPlanning> ConfigCnr::activePlan() const
|
||||
{
|
||||
AudioVideoManagement::ActiveFrequencyPlanning activePlanning = m_avmDtc->activeFrequencyPlanning(m_exerciseId);
|
||||
|
||||
if (activePlanning.exerciseId() != m_exerciseId)
|
||||
return boost::none;
|
||||
|
||||
AudioVideoManagement::FrequencyPlanning frequencyPlanning = m_avmDtc->frequencyPlanning(activePlanning.frequencyPlanningId());
|
||||
|
||||
return frequencyPlanning;
|
||||
}
|
||||
|
||||
void ConfigCnr::onActiveFrequencyPlanningChanged(const AudioVideoManagement::ActiveFrequencyPlanning &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << ": " << data;
|
||||
|
||||
Q_UNUSED(modType);
|
||||
if (data.exerciseId() == m_exerciseId)
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
void ConfigCnr::onFrequencyPlanningChanged(const AudioVideoManagement::FrequencyPlanning &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << ": " << data;
|
||||
|
||||
Q_UNUSED(modType);
|
||||
|
||||
boost::optional<AudioVideoManagement::FrequencyPlanning> plan = activePlan();
|
||||
if (!plan)
|
||||
return;
|
||||
|
||||
if (data.id() == plan->id() || !data.exerciseId().is_set())
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
//Daten nur rausschicken, wenn cnrConfig Data gerade in einer aktiven Übung verwendet wird
|
||||
void ConfigCnr::onCnrConfigChanged(const AudioVideoManagement::CnrConfig &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << ": " << data;
|
||||
|
||||
Q_UNUSED(modType);
|
||||
bool isGlobal = !data.exerciseId().is_set();
|
||||
if ((isGlobal || data.exerciseId().get() == m_exerciseId) && modType != DataModification::eAdded && isInActiveFrequencyPlanning(data))
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
//todo: wird das noch wo anders benötigt?
|
||||
bool ConfigCnr::isInActiveFrequencyPlanning(const AudioVideoManagement::CnrConfig &data)
|
||||
{
|
||||
//globale Änderung immer schicken
|
||||
if(!data.exerciseId().is_set())
|
||||
return true;
|
||||
|
||||
const auto activePlans = m_avmDtc->activeFrequencyPlannings();
|
||||
for (const AudioVideoManagement::ActiveFrequencyPlanning &activePlan : activePlans)
|
||||
{
|
||||
const auto frequencyPlannings = m_avmDtc->frequencyPlanning(activePlan.frequencyPlanningId());
|
||||
for(const auto &frequencyPlanningData : frequencyPlannings.data())
|
||||
{
|
||||
|
||||
if(frequencyPlanningData.cnrConfigId() == data.id())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ConfigCnr
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-05
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include "logger.h"
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
|
||||
class ActiveFrequencyPlanning;
|
||||
class FrequencyPlanning;
|
||||
class CnrConfig;
|
||||
|
||||
}
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
enum class DataModification;
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
/**
|
||||
* Will be constructed for each active Exercise in order to build the corresponding data
|
||||
* for the Exercise's active FrequencyPlanning.
|
||||
* The associated Exercise need not have an active FrequencyPlanning.
|
||||
*
|
||||
* @author Christian Fröbel
|
||||
*/
|
||||
class ConfigCnr : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigCnr(int exerciseId, AudioVideoManagement::Interface::Dtc *avmDtc, InfrastructureManagement::Interface::Dtc *ismDtc);
|
||||
|
||||
bool hasActiveFrequencyPlanning() const { return !m_configCnrData.radioCircuit.empty(); }
|
||||
|
||||
/** Must only be called when hasActiveFrequencyPlanning() == true. */
|
||||
const WebSocketInterface::Messages::ConfigCnrMessage::ConfigCnrData &data() const;
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
private:
|
||||
void buildConfigCnrData();
|
||||
boost::optional<AudioVideoManagement::FrequencyPlanning> activePlan() const;
|
||||
|
||||
void onActiveFrequencyPlanningChanged(const AudioVideoManagement::ActiveFrequencyPlanning &data, DataModification modType);
|
||||
void onFrequencyPlanningChanged(const AudioVideoManagement::FrequencyPlanning &data, DataModification modType);
|
||||
void onCnrConfigChanged(const AudioVideoManagement::CnrConfig &data, DataModification modType);
|
||||
bool isInActiveFrequencyPlanning(const AudioVideoManagement::CnrConfig &data);
|
||||
|
||||
int m_exerciseId;
|
||||
AudioVideoManagement::Interface::Dtc *m_avmDtc;
|
||||
InfrastructureManagement::Interface::Dtc *m_ismDtc;
|
||||
WebSocketInterface::Messages::ConfigCnrMessage::ConfigCnrData m_configCnrData;
|
||||
QTimer m_timer;
|
||||
LOGGER_T m_logger;
|
||||
LOGGER_T m_loggerJson;
|
||||
};
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* DdsHandler for CombatNetRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-05
|
||||
*/
|
||||
|
||||
#include "dds_handler.h"
|
||||
#include <AssetManagement/asm_dtc.h>
|
||||
#include <AudioVideoManagement/avm_dtc.h>
|
||||
#include <AudioVideoManagement/avm_ftc.h>
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include <InfrastructureManagement/ism_dtc.h>
|
||||
#include <DDS/Core/pacemaker.h>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
DdsHandler::DdsHandler(int domainId)
|
||||
: m_ddsConnector(std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Global))
|
||||
, m_logger(getLogger("DdsHandler"))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "DdsHandler(" << domainId << ") for partition: " << m_ddsConnector->getDefaultPartition();
|
||||
}
|
||||
|
||||
bool DdsHandler::init(const QStringList &qosFileList)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION;
|
||||
|
||||
if (!m_ddsConnector->init(qosFileList))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error initializing dds connections - aborting";
|
||||
return false;
|
||||
}
|
||||
|
||||
// default initialize Publisher and Subscriber
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
// Pacemaker
|
||||
m_pacemaker.reset(new Core::Pacemaker(m_ddsConnector));
|
||||
|
||||
m_asmDtc = AssetManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
m_avmDtc = AudioVideoManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
m_avmFtc = AudioVideoManagement::Interface::Ftc::create(m_ddsConnector);
|
||||
m_exmDtc = ExerciseManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
m_ismDtc = InfrastructureManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DdsHandler::enableDtcs()
|
||||
{
|
||||
Q_ASSERT(m_avmDtc);
|
||||
Q_ASSERT(m_exmDtc);
|
||||
bool status = m_asmDtc->enableTrainingArea() &&
|
||||
m_avmDtc->enableFrequencySet() &&
|
||||
m_avmDtc->enableFrequencyPlanning() &&
|
||||
m_avmDtc->enableActiveFrequencyPlanning() &&
|
||||
m_avmDtc->enableCnrChannel() &&
|
||||
m_avmDtc->enableCnrConfig() &&
|
||||
m_exmDtc->enableExercise() &&
|
||||
m_avmFtc->enableClearFrequencyPlanningStatus() &&
|
||||
m_avmFtc->enableModifyFrequencyPlanningStatus() &&
|
||||
m_avmFtc->enableRemoveFrequencyPlanningStatusByClient() &&
|
||||
m_ismDtc->enableMainStructureElement();
|
||||
|
||||
m_asmDtc->waitForHistoricalDataTrainingArea();
|
||||
m_avmDtc->waitForHistoricalDataCnrChannel();
|
||||
m_avmDtc->waitForHistoricalDataFrequencySet();
|
||||
m_ismDtc->waitForHistoricalDataMainStructureElement();
|
||||
|
||||
Q_ASSERT(status);
|
||||
}
|
||||
|
||||
dds::domain::DomainParticipant DdsHandler::domainParticipant() const
|
||||
{
|
||||
return m_ddsConnector->getDomainParticipant();
|
||||
}
|
||||
|
||||
|
||||
} // Namespace CombatNetRadio
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* DdsHandler for CombatNetRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
|
||||
#include "logger.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
class Pacemaker;
|
||||
}
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ExerciseManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace AssetManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
class DdsHandler final
|
||||
{
|
||||
public:
|
||||
explicit DdsHandler(int domainId);
|
||||
~DdsHandler() = default;
|
||||
|
||||
bool init(const QStringList &qosFileList = QStringList());
|
||||
|
||||
/**
|
||||
* Must be called *after* init and *after* all DTC-consuming instances
|
||||
* have been setup. This is to avoid data races that otherwise could arise
|
||||
* when
|
||||
* - connecting to the onFooChanged() signal and
|
||||
* - shortly after that calling foo() to get all received entities so far.
|
||||
*/
|
||||
void enableDtcs();
|
||||
|
||||
dds::domain::DomainParticipant domainParticipant() const;
|
||||
|
||||
Core::Pacemaker *pacemaker() const { return m_pacemaker.get(); }
|
||||
|
||||
AssetManagement::Interface::Dtc *asmDtc() const { return m_asmDtc.get(); }
|
||||
AudioVideoManagement::Interface::Dtc *avmDtc() const { return m_avmDtc.get(); }
|
||||
AudioVideoManagement::Interface::Ftc *avmFtc() const { return m_avmFtc.get(); }
|
||||
ExerciseManagement::Interface::Dtc *exmDtc() const { return m_exmDtc.get(); }
|
||||
InfrastructureManagement::Interface::Dtc *ismDtc() const { return m_ismDtc.get(); }
|
||||
|
||||
std::shared_ptr<DDSConnector::DdsConnector> dds() const
|
||||
{
|
||||
return m_ddsConnector;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
|
||||
std::unique_ptr<Core::Pacemaker> m_pacemaker;
|
||||
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
||||
std::shared_ptr<AudioVideoManagement::Interface::Dtc> m_avmDtc;
|
||||
std::shared_ptr<AudioVideoManagement::Interface::Ftc> m_avmFtc;
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Dtc> m_ismDtc;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* DdsHandlerExercise
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-02
|
||||
*/
|
||||
|
||||
#include "dds_handler_exercise.h"
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
DdsHandlerExercise::DdsHandlerExercise(const dds::domain::DomainParticipant &domainParticipant, int exerciseId)
|
||||
: m_ddsConnector(new DDSConnector::DdsConnector(domainParticipant, IDL::PartitionType::Exercise, exerciseId))
|
||||
{
|
||||
bool ok = m_ddsConnector->init();
|
||||
Q_ASSERT(ok);
|
||||
m_ddsConnector->initSubscriber();
|
||||
|
||||
m_ppmDtc = ParticipantManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
}
|
||||
|
||||
void DdsHandlerExercise::enableDtcs()
|
||||
{
|
||||
bool ok = m_ppmDtc->enableParticipant() &&
|
||||
m_ppmDtc->enableParticipantPosition() &&
|
||||
m_ppmDtc->enableType();
|
||||
Q_ASSERT(ok);
|
||||
}
|
||||
|
||||
DdsHandlerExercise::~DdsHandlerExercise() = default;
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* DdsHandlerExercise
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-02
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dds/domain/DomainParticipant.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace DDSConnector
|
||||
{
|
||||
class DdsConnector;
|
||||
}
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
/**
|
||||
* @author Christian Fröbel
|
||||
*/
|
||||
class DdsHandlerExercise
|
||||
{
|
||||
public:
|
||||
explicit DdsHandlerExercise(const dds::domain::DomainParticipant &domainParticipant, int exerciseId);
|
||||
virtual ~DdsHandlerExercise();
|
||||
|
||||
/**
|
||||
* Must be called *after* all DTC-consuming instances have been setup.
|
||||
* This is to avoid data races that otherwise could arise
|
||||
* when
|
||||
* - connecting to the onFooChanged() signal and
|
||||
* - shortly after that calling foo() to get all received entities so far.
|
||||
*/
|
||||
void enableDtcs();
|
||||
|
||||
ParticipantManagement::Interface::Dtc *ppmDtc() const { return m_ppmDtc.get(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
|
||||
};
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ExerciseManager
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-02
|
||||
*/
|
||||
|
||||
#include "exercise_manager.h"
|
||||
#include "active_exercises.h"
|
||||
#include "dds_handler.h"
|
||||
#include "dds_handler_exercise.h"
|
||||
#include "main_handler.h"
|
||||
#include "training_area.h"
|
||||
#include "config_cnr.h"
|
||||
#include "positions_cnr.h"
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include <QUuid>
|
||||
#include <QDateTime>
|
||||
#include <QJsonDocument>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void merge(WebSocketInterface::Messages::ConfigCnrMessage::ConfigCnrData &data, const WebSocketInterface::Messages::ConfigCnrMessage::ConfigCnrData &toBeMerged)
|
||||
{
|
||||
Q_ASSERT(data.setId == toBeMerged.setId);
|
||||
|
||||
data.radioCircuit.reserve(data.radioCircuit.size() + toBeMerged.radioCircuit.size());
|
||||
|
||||
for (const auto &entry : toBeMerged.radioCircuit)
|
||||
data.radioCircuit.append(entry);
|
||||
}
|
||||
|
||||
void merge(WebSocketInterface::Messages::PositionsCnrMessage::PositionsCnrMessageData &data, const WebSocketInterface::Messages::PositionsCnrMessage::PositionsCnrMessageData &toBeMerged)
|
||||
{
|
||||
data.radioCircuit.reserve(data.radioCircuit.size() + toBeMerged.radioCircuit.size());
|
||||
|
||||
for (const auto &pos : toBeMerged.radioCircuit)
|
||||
data.radioCircuit.append(pos);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
/**
|
||||
* Will be instantiated for every active Exercise -- even when the Exercise
|
||||
* does not have an active FrequencyPlanning. This is because there might be another
|
||||
* active Exercise with a global CnrConfig in its active FrequencyPlanning.
|
||||
* Then each active Exercise must provide the positions for the global CnrConfig
|
||||
* regardsless of whether it has an active FrequencyPlanning or not.
|
||||
*/
|
||||
struct ExerciseManager::ExerciseParts
|
||||
{
|
||||
explicit ExerciseParts(int exerciseId, ExerciseManager *exerciseManager, DdsHandler *ddsHandler)
|
||||
: m_ddsHandlerEx(new DdsHandlerExercise(ddsHandler->domainParticipant(), exerciseId))
|
||||
, configCnr(new ConfigCnr(exerciseId, ddsHandler->avmDtc(), ddsHandler->ismDtc()))
|
||||
, positionsCnr(exerciseId ? new PositionsCnr(exerciseId, exerciseManager, m_ddsHandlerEx->ppmDtc(), ddsHandler->avmDtc()) : nullptr)
|
||||
{
|
||||
m_ddsHandlerEx->enableDtcs();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<DdsHandlerExercise> m_ddsHandlerEx;
|
||||
|
||||
public:
|
||||
std::unique_ptr<ConfigCnr> configCnr;
|
||||
std::unique_ptr<PositionsCnr> positionsCnr;
|
||||
};
|
||||
|
||||
|
||||
ExerciseManager::ExerciseManager(ActiveExercises *activeExercises, DdsHandler *ddsHandler)
|
||||
: m_activeExercises(activeExercises)
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_logger(getLogger("ExerciseManager"))
|
||||
{
|
||||
Q_ASSERT(activeExercises);
|
||||
Q_ASSERT(ddsHandler);
|
||||
|
||||
m_positionsUpdateTimer.setSingleShot(false);
|
||||
m_essentialsUpdateTimer.setSingleShot(true);
|
||||
m_essentialsUpdateTimer.setInterval(200);
|
||||
|
||||
connect(m_activeExercises, &ActiveExercises::activated, this, &ExerciseManager::onExerciseActivated);
|
||||
connect(m_activeExercises, &ActiveExercises::deactivated, this, &ExerciseManager::onExerciseDeactivated);
|
||||
connect(&m_positionsUpdateTimer, &QTimer::timeout, this, &ExerciseManager::onPositionsUpdateTimeout);
|
||||
connect(&m_essentialsUpdateTimer, &QTimer::timeout, this, &ExerciseManager::essentialsUpdate); // signal -> signal
|
||||
|
||||
auto result = m_parts.emplace(0, ExerciseParts(0, this, m_ddsHandler));
|
||||
connect(result.first->second.configCnr.get(), &ConfigCnr::changed, &m_essentialsUpdateTimer, QOverload<>::of(&QTimer::start));
|
||||
}
|
||||
|
||||
ExerciseManager::~ExerciseManager() = default;
|
||||
|
||||
WebSocketInterface::Messages::ReplyMessage ExerciseManager::trainingAreaData(const QString &uuid) const
|
||||
{
|
||||
if (!m_trainingArea)
|
||||
return WebSocketInterface::Messages::ErrorMessage(1, uuid, QStringLiteral("There is no active Training Area"));
|
||||
|
||||
return WebSocketInterface::Messages::TrainingAreaMessage(m_trainingArea->trainingArea(), uuid);
|
||||
}
|
||||
|
||||
std::vector<WebSocketInterface::Messages::ReplyMessage> ExerciseManager::radioStations(const QString &uuid) const
|
||||
{
|
||||
if (!m_trainingArea)
|
||||
return {};
|
||||
|
||||
std::vector<WebSocketInterface::Messages::ReplyMessage> result;
|
||||
const auto &radioStations = m_trainingArea->radioStations();
|
||||
result.reserve(radioStations.size());
|
||||
|
||||
for (const auto &radioStation : radioStations)
|
||||
result.push_back(WebSocketInterface::Messages::RadioStationMessage(radioStation, uuid));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
WebSocketInterface::Messages::ReplyMessage ExerciseManager::configCnr(const QString &uuid)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION;
|
||||
|
||||
const WebSocketInterface::Messages::ErrorMessage noActivePlanning(1, uuid, QStringLiteral("No active frequency planning found"));
|
||||
|
||||
if (m_parts.empty())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "No active frequency planning due to empty m_parts.";
|
||||
|
||||
return noActivePlanning;
|
||||
}
|
||||
|
||||
bool isFirst = true;
|
||||
WebSocketInterface::Messages::ConfigCnrMessage::ConfigCnrData configCnrData;
|
||||
for (const auto &keyValue : m_parts)
|
||||
{
|
||||
if (!keyValue.second.configCnr->hasActiveFrequencyPlanning())
|
||||
continue;
|
||||
|
||||
if (isFirst)
|
||||
{
|
||||
configCnrData = keyValue.second.configCnr->data();
|
||||
isFirst = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
merge(configCnrData, keyValue.second.configCnr->data());
|
||||
}
|
||||
|
||||
if (configCnrData.radioCircuit.empty())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "No active frequency planning due to empty radio circuits.";
|
||||
|
||||
return noActivePlanning;
|
||||
}
|
||||
|
||||
return WebSocketInterface::Messages::ConfigCnrMessage(configCnrData, uuid);
|
||||
}
|
||||
|
||||
WebSocketInterface::Messages::ReplyMessage ExerciseManager::positionsCnr(const QString &uuid) const
|
||||
{
|
||||
const WebSocketInterface::Messages::ErrorMessage noPositions(1, uuid, QStringLiteral("No positions available"));
|
||||
|
||||
if (m_parts.empty())
|
||||
return noPositions;
|
||||
|
||||
bool isFirst = true;
|
||||
WebSocketInterface::Messages::PositionsCnrMessage::PositionsCnrMessageData positionsData;
|
||||
for (const auto &keyValue : m_parts)
|
||||
{
|
||||
if (!keyValue.second.positionsCnr)
|
||||
continue;
|
||||
|
||||
if (isFirst)
|
||||
{
|
||||
positionsData = keyValue.second.positionsCnr->data();
|
||||
isFirst = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
merge(positionsData, keyValue.second.positionsCnr->data());
|
||||
}
|
||||
|
||||
if (positionsData.radioCircuit.empty())
|
||||
return noPositions;
|
||||
|
||||
return WebSocketInterface::Messages::PositionsCnrMessage(positionsData, uuid);
|
||||
}
|
||||
|
||||
void ExerciseManager::onModifyFrequencyPlanningStatusReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
if (replyObject.error())
|
||||
ERROR_LOG(m_logger) << "Error while modifying FrequencyPlanningStatus: " << replyObject.str();
|
||||
else
|
||||
INFO_LOG(m_logger) << "onModifyFrequencyPlanningStatusReply ok";
|
||||
}
|
||||
|
||||
void ExerciseManager::onClearFrequencyPlanningStatusReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
if (replyObject.error())
|
||||
ERROR_LOG(m_logger) << "Error while clearing FrequencyPlanningStatus: " << replyObject.str();
|
||||
else
|
||||
INFO_LOG(m_logger) << "onClearFrequencyPlanningStatusReply ok";
|
||||
}
|
||||
|
||||
void ExerciseManager::onRemoveFrequencyPlanningStatusByClientReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
if (replyObject.error())
|
||||
ERROR_LOG(m_logger) << "Error while removing FrequencyPlanningStatus: " << replyObject.str();
|
||||
else
|
||||
INFO_LOG(m_logger) << "onRemoveFrequencyPlanningStatusByClientReply ok";
|
||||
}
|
||||
|
||||
void ExerciseManager::setPositionsUpdateInterval(std::chrono::milliseconds interval)
|
||||
{
|
||||
m_positionsUpdateTimer.start(interval.count());
|
||||
}
|
||||
|
||||
void ExerciseManager::stopPositionsUpdate()
|
||||
{
|
||||
m_positionsUpdateTimer.stop();
|
||||
}
|
||||
|
||||
void ExerciseManager::onNewClientConnection(qint64 id)
|
||||
{
|
||||
AudioVideoManagement::ModifyFrequencyPlanningStatusRequest request;
|
||||
request.client(id);
|
||||
request.isActive(true);
|
||||
m_ddsHandler->avmFtc()->modifyFrequencyPlanningStatusRequest(request, this);
|
||||
}
|
||||
|
||||
void ExerciseManager::onClientConnectionClosed(qint64 id)
|
||||
{
|
||||
AudioVideoManagement::RemoveFrequencyPlanningStatusByClientRequest request;
|
||||
request.client(id);
|
||||
m_ddsHandler->avmFtc()->removeFrequencyPlanningStatusByClientRequest(request, this);
|
||||
}
|
||||
|
||||
void ExerciseManager::onClearFrequencyPlanningStatus()
|
||||
{
|
||||
AudioVideoManagement::ClearFrequencyPlanningStatusRequest request;
|
||||
m_ddsHandler->avmFtc()->clearFrequencyPlanningStatusRequest(request, this);
|
||||
}
|
||||
|
||||
void ExerciseManager::onConfigCnrSent(qint64 id, const QString &uuid, const QString &requester, bool isActiveClient)
|
||||
{
|
||||
AudioVideoManagement::ModifyFrequencyPlanningStatusRequest request;
|
||||
request.client(id);
|
||||
request.uuid(uuid.toStdString());
|
||||
request.sent(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch());
|
||||
request.requester(requester.toStdString());
|
||||
request.isActive(isActiveClient);
|
||||
m_ddsHandler->avmFtc()->modifyFrequencyPlanningStatusRequest(request, this);
|
||||
}
|
||||
|
||||
void ExerciseManager::onConfigCnrReceived(qint64 id, const QString &uuid)
|
||||
{
|
||||
AudioVideoManagement::ModifyFrequencyPlanningStatusRequest request;
|
||||
request.client(id);
|
||||
request.uuid(uuid.toStdString());
|
||||
request.received(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch());
|
||||
m_ddsHandler->avmFtc()->modifyFrequencyPlanningStatusRequest(request, this);
|
||||
}
|
||||
|
||||
void ExerciseManager::onConfigCnrProcessed(qint64 id, const QString &uuid, const QJsonObject &configCnrData)
|
||||
{
|
||||
AudioVideoManagement::ModifyFrequencyPlanningStatusRequest request;
|
||||
request.client(id);
|
||||
request.uuid(uuid.toStdString());
|
||||
request.activated(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch());
|
||||
request.content(QJsonDocument(configCnrData).toJson().toStdString());
|
||||
request.requester(QJsonDocument(configCnrData).object()[QStringLiteral("requester")].toString().toStdString());
|
||||
request.reason(static_cast<AudioVideoManagement::TransmissionReason::inner_enum>(QJsonDocument(configCnrData).object()[QStringLiteral("reason")].toInt(0)));
|
||||
request.isActive(true); // Muss ja, sonst würde er das nicht senden...
|
||||
m_ddsHandler->avmFtc()->modifyFrequencyPlanningStatusRequest(request, this);
|
||||
}
|
||||
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> ExerciseManager::positionsForGlobal(const AudioVideoManagement::CnrConfig &config) const
|
||||
{
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> positions;
|
||||
for (const auto &keyValue : m_parts)
|
||||
{
|
||||
if (!keyValue.second.positionsCnr)
|
||||
continue;
|
||||
|
||||
positions.append(keyValue.second.positionsCnr->positionsForGlobal(config));
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
void ExerciseManager::onExerciseActivated(int exerciseId)
|
||||
{
|
||||
auto result = m_parts.emplace(exerciseId, ExerciseParts(exerciseId, this, m_ddsHandler));
|
||||
Q_ASSERT(result.second);
|
||||
|
||||
connect(result.first->second.configCnr.get(), &ConfigCnr::changed, &m_essentialsUpdateTimer, QOverload<>::of(&QTimer::start));
|
||||
|
||||
bool isFirstActiveExercise = m_parts.size() == 2;
|
||||
if (isFirstActiveExercise)
|
||||
{
|
||||
ExerciseManagement::Exercise exercise = m_ddsHandler->exmDtc()->exercise(exerciseId);
|
||||
m_trainingArea.reset(new TrainingArea(exercise.trainingAreaId(), m_ddsHandler->asmDtc(), m_ddsHandler->ismDtc()));
|
||||
}
|
||||
|
||||
emit essentialsUpdate();
|
||||
}
|
||||
|
||||
void ExerciseManager::onExerciseDeactivated(int exerciseId)
|
||||
{
|
||||
auto found = m_parts.find(exerciseId);
|
||||
Q_ASSERT(found != m_parts.end());
|
||||
m_parts.erase(found);
|
||||
|
||||
bool isLastActiveExercise = m_parts.size() == 1;
|
||||
if (isLastActiveExercise)
|
||||
m_trainingArea.reset();
|
||||
|
||||
emit essentialsUpdate();
|
||||
}
|
||||
|
||||
void ExerciseManager::onPositionsUpdateTimeout()
|
||||
{
|
||||
emit positionsUpdate(positionsCnr(QUuid::createUuid().toString()));
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ExerciseManager
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-02
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QVector>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <AudioVideoManagement/avm_ftc.h>
|
||||
#include "logger.h"
|
||||
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
class CnrConfig;
|
||||
}
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
class ActiveExercises;
|
||||
class DdsHandler;
|
||||
class TrainingArea;
|
||||
|
||||
/**
|
||||
* Observes ActiveExercises for active Exercises that have an active FrequencyPlanning.
|
||||
* For those it sets up the neccessary parts.
|
||||
*
|
||||
* @author Christian Fröbel
|
||||
*/
|
||||
class ExerciseManager : public QObject
|
||||
, protected AudioVideoManagement::Interface::Ftc::ModifyFrequencyPlanningStatusReplyHandler
|
||||
, protected AudioVideoManagement::Interface::Ftc::ClearFrequencyPlanningStatusReplyHandler
|
||||
, protected AudioVideoManagement::Interface::Ftc::RemoveFrequencyPlanningStatusByClientReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExerciseManager(ActiveExercises *activeExercises, DdsHandler *ddsHandler);
|
||||
virtual ~ExerciseManager();
|
||||
|
||||
WebSocketInterface::Messages::ReplyMessage trainingAreaData(const QString &uuid) const;
|
||||
std::vector<WebSocketInterface::Messages::ReplyMessage> radioStations(const QString &uuid) const;
|
||||
WebSocketInterface::Messages::ReplyMessage configCnr(const QString &uuid);
|
||||
WebSocketInterface::Messages::ReplyMessage positionsCnr(const QString &uuid) const;
|
||||
|
||||
void onModifyFrequencyPlanningStatusReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onClearFrequencyPlanningStatusReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onRemoveFrequencyPlanningStatusByClientReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
/**
|
||||
* For a global CnrConfig collect the positions of all Participants from each Exercise.
|
||||
* Will be called by PositionsCnr.
|
||||
*/
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> positionsForGlobal(const AudioVideoManagement::CnrConfig &config) const;
|
||||
|
||||
public slots:
|
||||
void setPositionsUpdateInterval(std::chrono::milliseconds interval);
|
||||
void stopPositionsUpdate();
|
||||
void onNewClientConnection(qint64 id);
|
||||
void onClientConnectionClosed(qint64 id);
|
||||
void onClearFrequencyPlanningStatus();
|
||||
void onConfigCnrSent(qint64 id, const QString &uuid, const QString &requester = {}, bool isActiveClient = false);
|
||||
void onConfigCnrReceived(qint64 id, const QString &uuid);
|
||||
void onConfigCnrProcessed(qint64 id, const QString &uuid, const QJsonObject &configCnrData = {});
|
||||
|
||||
signals:
|
||||
void essentialsUpdate();
|
||||
void positionsUpdate(const WebSocketInterface::Messages::ReplyMessage &positionsCnr);
|
||||
|
||||
private:
|
||||
void onExerciseActivated(int exerciseId);
|
||||
void onExerciseDeactivated(int exerciseId);
|
||||
void onPositionsUpdateTimeout();
|
||||
|
||||
struct ExerciseParts;
|
||||
|
||||
ActiveExercises *m_activeExercises;
|
||||
DdsHandler *m_ddsHandler;
|
||||
std::map<int, ExerciseParts> m_parts; //!< exerciseId -> ExerciseParts
|
||||
std::unique_ptr<TrainingArea> m_trainingArea; //!< set when there is at least one active Exercise
|
||||
QTimer m_positionsUpdateTimer;
|
||||
QTimer m_essentialsUpdateTimer; //!< to cope with repeated updates in a short period of time
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
};
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Helper
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-05
|
||||
*/
|
||||
|
||||
#include "helper.h"
|
||||
#include <LtsUtilsCore/json_object.h>
|
||||
#include <AudioVideoManagement/avm.hpp>
|
||||
#include <InfrastructureManagement/ism.hpp>
|
||||
#include <QString>
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
int stationId(const InfrastructureManagement::MainStructureElement &radioStation)
|
||||
{
|
||||
return LtsUtils::JsonObject::fromJson(radioStation.properties()).valueOr<int>("stationId", 0);
|
||||
}
|
||||
|
||||
QString toRcIdString(const AudioVideoManagement::CnrChannel &cnrChannel)
|
||||
{
|
||||
QString result = QString::fromStdString(cnrChannel.name());
|
||||
result.remove(1, 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Helper
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-05
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
class CnrChannel;
|
||||
}
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
class MainStructureElement;
|
||||
}
|
||||
|
||||
class QString;
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the station Id from the properties of the MainStructureElement.
|
||||
*/
|
||||
int stationId(const InfrastructureManagement::MainStructureElement &radioStation);
|
||||
|
||||
QString toRcIdString(const AudioVideoManagement::CnrChannel &cnrChannel);
|
||||
|
||||
inline double toDeg(double rad)
|
||||
{
|
||||
return LtsCoordTrans::rad2deg() * rad;
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
log4j.reset=true
|
||||
log4j.rootLogger=INFO, file
|
||||
|
||||
# Service: CombatNetRadio
|
||||
###########################################################
|
||||
|
||||
#log4j.logger.CNR.main=DEBUG
|
||||
#log4j.logger.CNR.DdsHandler=WARN
|
||||
#log4j.logger.CNR.MainHandler=WARN
|
||||
#log4j.logger.CNR.ConnectionHandler=DEBUG
|
||||
#log4j.logger.CNR.ClientConnection=DEBUG
|
||||
#log4j.logger.CNR.DataManager=DEBUG
|
||||
#log4j.logger.CNR.WebSocketInterfaceHandler=DEBUG
|
||||
#log4j.logger.CNR.MessageHandler=DEBUG
|
||||
#log4j.logger.CNR.ConfigCnr=DEBUG
|
||||
log4j.logger.CNR.ConfigCnr.Json=WARN, file2
|
||||
|
||||
# File
|
||||
###########################################################
|
||||
log4j.appender.file=Lts::RollingFileAppender
|
||||
log4j.appender.file.MaxFileSize=1MB
|
||||
log4j.appender.file.MaxBackupIndex=9
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d %-5p %c |#| %m (%.50F:%L) %n
|
||||
|
||||
# File2
|
||||
###########################################################
|
||||
log4j.appender.file2=Lts::RollingFileAppender
|
||||
log4j.appender.file2.MaxFileSize=1MB
|
||||
log4j.appender.file2.File=./jsonOut.log
|
||||
log4j.appender.file2.MaxBackupIndex=9
|
||||
log4j.appender.file2.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file2.layout.ConversionPattern=%d %-5p %c |#| %m (%.50F:%L) %n
|
||||
|
||||
# Appnd_Console
|
||||
###########################################################
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern= %d %p %c %c{1} - %m (%-.30F:%L) %n
|
||||
|
||||
# Appnd_Syslog
|
||||
###########################################################
|
||||
log4j.appender.syslog=org.apache.log4j.SyslogAppender
|
||||
log4j.appender.syslog.Threshold=ERROR
|
||||
log4j.appender.syslog.SysLogHost=localhost
|
||||
log4j.appender.syslog.Facility=LOCAL7
|
||||
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.syslog.layout.ConversionPattern= %-4r %-5p %c %x - %m
|
||||
log4j.appender.syslog.LevelRangeFilter.AcceptOnMatch=true
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMin=INFO
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMax=FATAL
|
||||
|
||||
|
||||
###########################################################
|
||||
###########################################################
|
||||
###########################################################
|
||||
# 1) Available Levels in LOG4CXX Version 0.10.0:
|
||||
# TRACE,
|
||||
# DEBUG,
|
||||
# INFO,
|
||||
# WARN,
|
||||
# ERROR
|
||||
# FATAL
|
||||
#
|
||||
# d = date/time
|
||||
# p = priority (Level)
|
||||
# c = category/channel
|
||||
# m = message
|
||||
# F = file
|
||||
# L = line
|
||||
# n = platform dependent line separator character or characters.
|
||||
# ....
|
||||
#
|
||||
# Examples for console:
|
||||
# a)
|
||||
# %d %p %c #%m# (%.50F:%L)%n
|
||||
# date/time
|
||||
# priority
|
||||
# category/channel
|
||||
# #message#
|
||||
# (Maximal 50Character des Filename von rechts:Line)
|
||||
# line separator
|
||||
#
|
||||
# b)
|
||||
# %d (%.15F:%L) %-5p %c |#| %m%n
|
||||
# date/time
|
||||
# (Maximal 15Character des Filename von rechts:Line)
|
||||
# priority, Right pad with spaces if the priority name is less than 5 characters long.
|
||||
# category/channel
|
||||
# message
|
||||
# line separator
|
||||
#
|
||||
# Examples for files:
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Logging for CombatNetRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-05
|
||||
*/
|
||||
|
||||
#include "logger.h"
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
LOGGER_T getLogger(const char *name)
|
||||
{
|
||||
static const char ns[] = "CNR.";
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Logging for CombatNetRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-05
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
using LOGGER_T = NGL::INGLLogger &;
|
||||
|
||||
LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Main for CombatNetRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-05
|
||||
*/
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
|
||||
#include "main_handler.h"
|
||||
#include "logger.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
|
||||
int iRet = -1;
|
||||
LtsCommandLineParser::LtsCommandLineParser options;
|
||||
if (!options.init())
|
||||
return iRet;
|
||||
app.createLogger("CNR", options.exerciseId());
|
||||
|
||||
{
|
||||
CombatNetRadio::MainHandler mainHandler;
|
||||
if (mainHandler.init(options.domainId()))
|
||||
{
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
iRet = app.exec();
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
}
|
||||
}
|
||||
|
||||
return iRet;
|
||||
} // end of main()
|
||||
//-----------------------------------------------------------------------------
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* MainHandler for CombatNetRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-05
|
||||
*/
|
||||
|
||||
#include "main_handler.h"
|
||||
#include "dds_handler.h"
|
||||
#include "active_exercises.h"
|
||||
#include "exercise_manager.h"
|
||||
#include "WebSocketInterface/websocket_interface_handler.h"
|
||||
#include <DDS/Core/pacemaker.h>
|
||||
|
||||
using namespace CombatNetRadio;
|
||||
|
||||
MainHandler::MainHandler()
|
||||
: m_logger(getLogger("MainHandler"))
|
||||
{
|
||||
}
|
||||
|
||||
MainHandler::~MainHandler() = default;
|
||||
|
||||
bool MainHandler::init(int domainId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION;
|
||||
|
||||
m_ddsHandler.reset(new DdsHandler(domainId));
|
||||
if (!m_ddsHandler->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation DdsHandler failed.";
|
||||
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_activeExercises.reset(new ActiveExercises(m_ddsHandler->exmDtc()));
|
||||
m_exerciseManager.reset(new ExerciseManager(m_activeExercises.get(), m_ddsHandler.get()));
|
||||
|
||||
m_webSocketInterfaceHandler.reset(new WebSocketInterface::WebSocketInterfaceHandler(m_exerciseManager.get()));
|
||||
if (!m_webSocketInterfaceHandler->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation WebSocketInterfaceHandler failed.";
|
||||
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ddsHandler->enableDtcs();
|
||||
// Remove all Entries
|
||||
m_exerciseManager->onClientConnectionClosed(0);
|
||||
|
||||
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::Running);
|
||||
|
||||
return true;
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* MainHandler for CombatNetRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-05
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "logger.h"
|
||||
#include <memory>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
class WebSocketInterfaceHandler;
|
||||
}
|
||||
class DdsHandler;
|
||||
class ActiveExercises;
|
||||
class ExerciseManager;
|
||||
|
||||
class MainHandler
|
||||
{
|
||||
public:
|
||||
MainHandler();
|
||||
~MainHandler();
|
||||
|
||||
bool init(int domainId);
|
||||
|
||||
private: // attributes
|
||||
std::unique_ptr<DdsHandler> m_ddsHandler;
|
||||
std::unique_ptr<ActiveExercises> m_activeExercises;
|
||||
std::unique_ptr<ExerciseManager> m_exerciseManager;
|
||||
std::unique_ptr<WebSocketInterface::WebSocketInterfaceHandler> m_webSocketInterfaceHandler;
|
||||
|
||||
LOGGER_T &m_logger;
|
||||
};
|
||||
} // namespace VideoOverlayManagement
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* PositionsCnr
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-05
|
||||
*/
|
||||
|
||||
#include "positions_cnr.h"
|
||||
#include "exercise_manager.h"
|
||||
#include "helper.h"
|
||||
#include <AudioVideoManagement/avm_dtc.h>
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
#include <LtsUtilsCore/outdated_position.h>
|
||||
#include <QtGlobal>
|
||||
#include <QDateTime>
|
||||
#include <QSet>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
QSet<int> participantIdsFromParty(const QMap<int32_t, ParticipantManagement::Participant> &participants, int partyId, bool isGlobal)
|
||||
{
|
||||
QSet<int> ret;
|
||||
if (isGlobal)
|
||||
{
|
||||
ret.reserve(participants.size());
|
||||
for (const auto &p : participants)
|
||||
ret += p.id();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const auto &participant : participants)
|
||||
if (participant.partyId() == partyId)
|
||||
ret += participant.id();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
PositionsCnr::PositionsCnr(int exerciseId, ExerciseManager *exerciseManager, ParticipantManagement::Interface::Dtc *ppmDtc, AudioVideoManagement::Interface::Dtc *avmDtc)
|
||||
: m_exerciseId(exerciseId)
|
||||
, m_exerciseManager(exerciseManager)
|
||||
, m_ppmDtc(ppmDtc)
|
||||
, m_avmDtc(avmDtc)
|
||||
{
|
||||
Q_ASSERT(exerciseId > 0);
|
||||
Q_ASSERT(exerciseManager);
|
||||
Q_ASSERT(ppmDtc);
|
||||
Q_ASSERT(avmDtc);
|
||||
}
|
||||
|
||||
WebSocketInterface::Messages::PositionsCnrMessage::PositionsCnrMessageData PositionsCnr::data() const
|
||||
{
|
||||
WebSocketInterface::Messages::PositionsCnrMessage::PositionsCnrMessageData positionsData;
|
||||
|
||||
positionsData.time = QDateTime::currentDateTime().toString(Qt::ISODate);
|
||||
|
||||
boost::optional<AudioVideoManagement::FrequencyPlanning> plan = activePlan();
|
||||
if (!plan)
|
||||
return positionsData;
|
||||
|
||||
for (const auto &entry : plan->data())
|
||||
{
|
||||
AudioVideoManagement::CnrConfig cnrConfig = m_avmDtc->cnrConfig(entry.cnrConfigId());
|
||||
AudioVideoManagement::CnrChannel cnrChannel = m_avmDtc->cnrChannel(cnrConfig.cnrChannelId());
|
||||
|
||||
positionsData.radioCircuit.push_back({toRcIdString(cnrChannel), positionsFor(cnrConfig)});
|
||||
}
|
||||
|
||||
return positionsData;
|
||||
}
|
||||
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> PositionsCnr::positionsForGlobal(const AudioVideoManagement::CnrConfig &config) const
|
||||
{
|
||||
bool isGlobal = !config.exerciseId().is_set();
|
||||
Q_ASSERT(isGlobal);
|
||||
return positionsForLocal(config);
|
||||
}
|
||||
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> PositionsCnr::positionsFor(const AudioVideoManagement::CnrConfig &config) const
|
||||
{
|
||||
bool isLocal = config.exerciseId().is_set();
|
||||
if (isLocal)
|
||||
return positionsForLocal(config);
|
||||
else
|
||||
return m_exerciseManager->positionsForGlobal(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be called for a global config, too. But then only positions for Participants of this Exercise will be returned.
|
||||
*/
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> PositionsCnr::positionsForLocal(const AudioVideoManagement::CnrConfig &config) const
|
||||
{
|
||||
auto allParticipants = m_ppmDtc->participants();
|
||||
|
||||
QSet<int> participantIdsInUnit;
|
||||
if (config.unitId().is_set())
|
||||
m_ppmDtc->participantIdsByUnit(config.unitId().get(), allParticipants, participantIdsInUnit);
|
||||
else
|
||||
{
|
||||
bool isGlobal = !config.exerciseId().is_set();
|
||||
participantIdsInUnit = participantIdsFromParty(allParticipants, config.partyId(), isGlobal);
|
||||
}
|
||||
|
||||
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> positions;
|
||||
for (int participantId : qAsConst(participantIdsInUnit))
|
||||
{
|
||||
const ParticipantManagement::Participant &participant = allParticipants.value(participantId);
|
||||
if (!participant.equipmentNumber().is_set())
|
||||
continue;
|
||||
|
||||
const ParticipantManagement::Type &type = m_ppmDtc->type(participant.typeId());
|
||||
if (type.radioCount() < 1)
|
||||
continue; // participant has no radio equipped
|
||||
|
||||
const auto &pos = m_ppmDtc->participantPosition(participantId);
|
||||
if (pos.participantId() != participantId)
|
||||
continue; // participant has no position
|
||||
|
||||
if (LtsUtils::isPositionTimeOutdated(now, pos.sampleTime()))
|
||||
continue; // position invalid
|
||||
|
||||
positions.push_back({toDeg(pos.pos().lon()), toDeg(pos.pos().lat())});
|
||||
}
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
boost::optional<AudioVideoManagement::FrequencyPlanning> PositionsCnr::activePlan() const
|
||||
{
|
||||
AudioVideoManagement::ActiveFrequencyPlanning activePlanning = m_avmDtc->activeFrequencyPlanning(m_exerciseId);
|
||||
if (activePlanning.exerciseId() != m_exerciseId)
|
||||
return boost::none;
|
||||
return m_avmDtc->frequencyPlanning(activePlanning.frequencyPlanningId());
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* PositionsCnr
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-05
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include <QVector>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace AudioVideoManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
|
||||
class CnrConfig;
|
||||
class FrequencyPlanning;
|
||||
}
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
|
||||
class Participant;
|
||||
|
||||
}
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
class ExerciseManager;
|
||||
|
||||
/**
|
||||
* Will be instantiated for each Exercise in order to provide the relevant positions
|
||||
* according to the active FrequencyPlanning
|
||||
*
|
||||
* @author Christian Fröbel
|
||||
*/
|
||||
class PositionsCnr
|
||||
{
|
||||
public:
|
||||
explicit PositionsCnr(int exerciseId, ExerciseManager *exerciseManager, ParticipantManagement::Interface::Dtc *ppmDtc, AudioVideoManagement::Interface::Dtc *avmDtc);
|
||||
|
||||
WebSocketInterface::Messages::PositionsCnrMessage::PositionsCnrMessageData data() const;
|
||||
|
||||
/**
|
||||
* For a global CnrConfig return die positions of the Participants from this Exercise.
|
||||
* Will be called by ExerciseManager which will collect the positions from all Exercises for a global CnrConfig.
|
||||
*/
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> positionsForGlobal(const AudioVideoManagement::CnrConfig &config) const;
|
||||
|
||||
private:
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> positionsFor(const AudioVideoManagement::CnrConfig &config) const;
|
||||
QVector<WebSocketInterface::Messages::ReplyMessage::LonLatPoint> positionsForLocal(const AudioVideoManagement::CnrConfig &config) const;
|
||||
boost::optional<AudioVideoManagement::FrequencyPlanning> activePlan() const;
|
||||
|
||||
int m_exerciseId;
|
||||
ExerciseManager *m_exerciseManager;
|
||||
ParticipantManagement::Interface::Dtc *m_ppmDtc;
|
||||
AudioVideoManagement::Interface::Dtc *m_avmDtc;
|
||||
};
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+95
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* TrainingArea
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-02
|
||||
*/
|
||||
|
||||
#include "training_area.h"
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include "helper.h"
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <LtsUtilsCore/json_object.h>
|
||||
#include <AssetManagement/asm_dtc.h>
|
||||
#include <InfrastructureManagement/ism_dtc.h>
|
||||
#include <QtGlobal>
|
||||
#include <QPointF>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
TrainingArea::TrainingArea(int trainingAreaId, AssetManagement::Interface::Dtc *asmDtc, InfrastructureManagement::Interface::Dtc *ismDtc)
|
||||
: m_logger(getLogger("TrainingArea"))
|
||||
{
|
||||
Q_ASSERT(trainingAreaId > 0);
|
||||
Q_ASSERT(asmDtc);
|
||||
Q_ASSERT(ismDtc);
|
||||
|
||||
getTrainingArea(trainingAreaId, asmDtc);
|
||||
getRadioStations(ismDtc);
|
||||
}
|
||||
|
||||
void TrainingArea::getTrainingArea(int trainingAreaId, AssetManagement::Interface::Dtc *asmDtc)
|
||||
{
|
||||
AssetManagement::TrainingArea ddsTrainingArea = asmDtc->trainingArea(trainingAreaId);
|
||||
|
||||
m_trainingAreaData.designation = QString::fromStdString(ddsTrainingArea.name());
|
||||
m_trainingAreaData.id = trainingAreaId;
|
||||
m_trainingAreaData.refPoint.lat = -1.;
|
||||
m_trainingAreaData.refPoint.lon = -1.;
|
||||
|
||||
WebSocketInterface::Messages::ReplyMessage::LonLatPoint point;
|
||||
|
||||
// bottom left
|
||||
LtsCoordTrans::UtmCoordinate utmCoordinate = LtsCoordTrans::UtmCoordinate::fromGeographic(ddsTrainingArea.bottomLeft().lon(), ddsTrainingArea.bottomLeft().lat());
|
||||
point.lat = toDeg(ddsTrainingArea.bottomLeft().lat());
|
||||
point.lon = toDeg(ddsTrainingArea.bottomLeft().lon());
|
||||
m_trainingAreaData.path << point;
|
||||
|
||||
// bottom right
|
||||
QPointF coord = utmCoordinate.geographic(ddsTrainingArea.width());
|
||||
point.lon = toDeg(coord.x());
|
||||
point.lat = toDeg(coord.y());
|
||||
m_trainingAreaData.path << point;
|
||||
|
||||
// upper right
|
||||
coord = utmCoordinate.geographic(ddsTrainingArea.width(), ddsTrainingArea.height());
|
||||
point.lon = toDeg(coord.x());
|
||||
point.lat = toDeg(coord.y());
|
||||
m_trainingAreaData.path << point;
|
||||
|
||||
// upper left
|
||||
coord = utmCoordinate.geographic(0, ddsTrainingArea.height());
|
||||
point.lon = toDeg(coord.x());
|
||||
point.lat = toDeg(coord.y());
|
||||
m_trainingAreaData.path << point;
|
||||
}
|
||||
|
||||
void TrainingArea::getRadioStations(InfrastructureManagement::Interface::Dtc *ismDtc)
|
||||
{
|
||||
auto cb = [this](const InfrastructureManagement::MainStructureElement &mse)
|
||||
{
|
||||
if (mse.structureElementTypeId() != InfrastructureManagement::StructureElementType::RadioStation || mse.isDeleted())
|
||||
return;
|
||||
|
||||
WebSocketInterface::Messages::RadioStationMessage::RadioStationData data;
|
||||
data.id = stationId(mse);
|
||||
if (data.id == 0)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got MainStructureElement of type 'RadioStation' but property 'stationId' was not set"
|
||||
<< " - database id: " << mse.id() << " - ignoring!";
|
||||
return;
|
||||
}
|
||||
data.geoPoint.lon = toDeg(mse.geoPosition().lon());
|
||||
data.geoPoint.lat = toDeg(mse.geoPosition().lat());
|
||||
data.trainingAreaId = m_trainingAreaData.id;
|
||||
data.designation = QString::fromStdString(mse.name());
|
||||
|
||||
m_radioStations.push_back(data);
|
||||
};
|
||||
ismDtc->mainStructureElements(cb);
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* TrainingArea
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Fröbel, NLE, 2019-08-02
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include "logger.h"
|
||||
#include <vector>
|
||||
|
||||
namespace AssetManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
|
||||
/**
|
||||
* Collects the data for the TrainingArea and the RadioStations.
|
||||
* There is one instance for all active Exercises as they must share the same TrainingArea then.
|
||||
*
|
||||
* @author Christian Fröbel
|
||||
*/
|
||||
class TrainingArea
|
||||
{
|
||||
public:
|
||||
explicit TrainingArea(int trainingAreaId, AssetManagement::Interface::Dtc *asmDtc, InfrastructureManagement::Interface::Dtc *ismDtc);
|
||||
virtual ~TrainingArea() = default;
|
||||
|
||||
const WebSocketInterface::Messages::TrainingAreaMessage::TrainingAreaData &trainingArea() const { return m_trainingAreaData; }
|
||||
const std::vector<WebSocketInterface::Messages::RadioStationMessage::RadioStationData> &radioStations() const { return m_radioStations; }
|
||||
|
||||
private:
|
||||
void getTrainingArea(int trainingAreaId, AssetManagement::Interface::Dtc *asmDtc);
|
||||
void getRadioStations(InfrastructureManagement::Interface::Dtc *ismDtc);
|
||||
|
||||
WebSocketInterface::Messages::TrainingAreaMessage::TrainingAreaData m_trainingAreaData;
|
||||
std::vector<WebSocketInterface::Messages::RadioStationMessage::RadioStationData> m_radioStations;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
Reference in new issue
Block a user