- training_area_telegrams.cpp: Fixed QJsonObject initializer syntax (Qt6 requires {{}} not ({}))
- training_area_telegrams.cpp: Fixed fromJson() methods to access m_* members directly
- training_area_telegrams.cpp: Fixed brace mismatches in multiple toJson() methods
- training_area_telegrams.h: Changed Header struct to public members for consistency
- tx_mixin.cpp: Fixed getEquipmentNumber() template for direct member access
- lts_coordinate.cpp: Added missing #include <iomanip>
- MIGRATION_STATUS.md: Added migration progress tracking document
C++17 constraint enforced due to RTI Connext DDS 7.7.0 incompatibility with C++20+
Build status: BUILD_RTI=OFF successful (0 errors, warnings only)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
79 lines
2.4 KiB
C++
Executable File
79 lines
2.4 KiB
C++
Executable File
|
|
|
|
|
|
#include "abstract_socket_handler.h"
|
|
#include "guez_nasat_telegrams.h"
|
|
#include "settings.h"
|
|
#include <QtCore/QDateTime>
|
|
#include <QtCore/QJsonDocument>
|
|
|
|
namespace GuezNasat
|
|
{
|
|
AbstractSocketHandler::AbstractSocketHandler(const char *loggerName, QObject *parent)
|
|
: QObject(parent)
|
|
, m_logger(getLogger(loggerName))
|
|
{}
|
|
|
|
void AbstractSocketHandler::setSimulationStatus(int nasatId, bool bActivateSimulation)
|
|
{
|
|
NasatSimulationRequest req;
|
|
req.aircraftId = nasatId;
|
|
req.timestamp = QDateTime::currentSecsSinceEpoch();
|
|
req.enableSimulation = bActivateSimulation;
|
|
const QPointF pos = Settings::simulationPositionDegree();
|
|
req.position.lon = pos.x();
|
|
req.position.lat = pos.y();
|
|
sendTelegram(&req);
|
|
}
|
|
|
|
bool AbstractSocketHandler::sendTelegram(const NasatBase *tele)
|
|
{
|
|
if (!isConnected() || !tele)
|
|
return false;
|
|
|
|
QJsonObject obj;
|
|
obj[QStringLiteral("data")] = tele->toJson();
|
|
obj[QStringLiteral("type")] = tele->type();
|
|
return sendTelegramInternal(QJsonDocument(obj).toJson(QJsonDocument::Compact));
|
|
}
|
|
|
|
void AbstractSocketHandler::textMessageReceived(const QByteArray &msg)
|
|
{
|
|
if (msg.isEmpty())
|
|
{
|
|
ERROR_LOG(m_logger) << "Empty message received";
|
|
return;
|
|
}
|
|
const QJsonObject obj = QJsonDocument::fromJson(msg).object();
|
|
DEBUG_LOG(m_logger) << "incoming telegram: " << msg;
|
|
|
|
const QJsonValue type = obj.value(QStringLiteral("type"));
|
|
if (!type.isString())
|
|
{
|
|
ERROR_LOG(m_logger) << "Can not read type id: " << msg;
|
|
return;
|
|
}
|
|
const QString typeStr = type.toString();
|
|
const QJsonObject data = obj.value(QStringLiteral("data")).toObject();
|
|
try
|
|
{
|
|
if (typeStr.compare(Constraints<NasatPosition>::type(), Qt::CaseInsensitive) == 0)
|
|
emit positionReceived(NasatPosition::fromJson(data));
|
|
else if (typeStr.compare(Constraints<NasatWeaponRelease>::type(), Qt::CaseInsensitive) == 0)
|
|
emit weaponReleaseReceived(NasatWeaponRelease::fromJson(data));
|
|
else if (typeStr.compare(Constraints<NasatNineLiner>::type(), Qt::CaseInsensitive) == 0)
|
|
emit nineLinerReceived(NasatNineLiner::fromJson(data));
|
|
else if (typeStr.compare(Constraints<NasatSimulationStatus>::type(), Qt::CaseInsensitive) == 0)
|
|
emit simulationStatusReceived(NasatSimulationStatus::fromJson(data));
|
|
else
|
|
ERROR_LOG(m_logger) << "Got unknown json telegram: " << msg;
|
|
}
|
|
catch (const JsonException &ex)
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not parse json telegram: " << msg
|
|
<< ", error: " << ex.what();
|
|
}
|
|
}
|
|
|
|
}
|