Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user