Files
qt5-legatus-legacy/Lts/Proxies/HighLevelArchitecture/Hla_test_tool/ws_telegrams.h
T
2026-08-13 18:33:10 +02:00

146 lines
3.5 KiB
C++
Executable File

/**
* Telegrams at WsTelegram
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, NLE, 2019-09-18
*/
#pragma once
#include <cstdint>
#include <exception>
#include <QJsonObject>
#include <QString>
namespace HighLevelArchitecture
{
class JsonException final : public std::exception
{
public:
JsonException(const QJsonObject &obj, const QString &key);
const char *what() const noexcept override { return m_what.data(); }
private:
QJsonObject m_obj;
QString m_key;
QByteArray m_what;
};
template <typename T>
struct Constraints;
//
// Enumerations
//
enum class FinalAttackHeadingMode
{
None = 0,
HeadingOnly = 1,
HeadingWithSector = 2,
};
//
// Structs
//
// ------------------------------------------------------------------
struct GeoPosition2D
{
double lat = 0; // in degree, WGS-84
double lon = 0; // in degree, WGS-84
static GeoPosition2D fromJson(const QJsonObject &obj);
QJsonObject toJson() const;
};
// ------------------------------------------------------------------
struct GeoPosition3D final : public GeoPosition2D
{
double height = 0; // above MSL
static GeoPosition3D fromJson(const QJsonObject &obj);
QJsonObject toJson() const;
};
// ------------------------------------------------------------------
struct Area2D
{
GeoPosition2D centerPoint;
int width{100};
int height{100};
static Area2D fromJson(const QJsonObject &obj);
QJsonObject toJson() const;
};
// ------------------------------------------------------------------
struct WsTelegramBase
{
int objectId = 0;
QString name;
double timestamp = 0; // in msec since epoche // for debugging purpose
virtual ~WsTelegramBase() = default;
virtual QJsonObject toJson() const = 0;
virtual QString type() const = 0;
};
// ------------------------------------------------------------------
template <typename T>
struct WsTelegramBaseTmpl : WsTelegramBase
{
QString type() const override final { return Constraints<T>::type(); }
};
// ------------------------------------------------------------------
struct WsTelegramPosition final : public WsTelegramBaseTmpl<WsTelegramPosition>
{
GeoPosition3D position;
// conversion functions
static WsTelegramPosition fromJson(const QJsonObject &obj);
QJsonObject toJson() const override;
};
template <> struct Constraints<WsTelegramPosition>
{
static QString type() { return QStringLiteral("WsTelegramPosition"); }
};
// ------------------------------------------------------------------
struct WsTelegramRemoveAesObject final : public WsTelegramBaseTmpl<WsTelegramRemoveAesObject>
{
// conversion functions
static WsTelegramRemoveAesObject fromJson(const QJsonObject &obj);
QJsonObject toJson() const override;
};
template <> struct Constraints<WsTelegramRemoveAesObject>
{
static QString type() { return QStringLiteral("WsTelegramRemoveAesObject"); }
};
// ------------------------------------------------------------------
struct WsTelegramMineFieldObject final : public WsTelegramBaseTmpl<WsTelegramMineFieldObject>
{
int activationTime{0};
bool isDeactivated{false};
int duration{0};
Area2D area2D; // define center and optional width, height
// conversion functions
static WsTelegramMineFieldObject fromJson(const QJsonObject &obj);
QJsonObject toJson() const override;
};
template <> struct Constraints<WsTelegramMineFieldObject>
{
static QString type() { return QStringLiteral("WsTelegramMineFieldObject"); }
};
} // namespace HighLevelArchitecture