/** * Telegrams at WsTelegram * $Id$ * $HeadURL$ * $Author$ * Created by Christian Ehrlicher, NLE, 2019-09-18 */ #pragma once #include #include #include #include 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 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 struct WsTelegramBaseTmpl : WsTelegramBase { QString type() const override final { return Constraints::type(); } }; // ------------------------------------------------------------------ struct WsTelegramPosition final : public WsTelegramBaseTmpl { GeoPosition3D position; // conversion functions static WsTelegramPosition fromJson(const QJsonObject &obj); QJsonObject toJson() const override; }; template <> struct Constraints { static QString type() { return QStringLiteral("WsTelegramPosition"); } }; // ------------------------------------------------------------------ struct WsTelegramRemoveAesObject final : public WsTelegramBaseTmpl { // conversion functions static WsTelegramRemoveAesObject fromJson(const QJsonObject &obj); QJsonObject toJson() const override; }; template <> struct Constraints { static QString type() { return QStringLiteral("WsTelegramRemoveAesObject"); } }; // ------------------------------------------------------------------ struct WsTelegramMineFieldObject final : public WsTelegramBaseTmpl { 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 { static QString type() { return QStringLiteral("WsTelegramMineFieldObject"); } }; } // namespace HighLevelArchitecture