Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+128
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @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 "WebSocketInterface/Messages/reply_message.h"
|
||||
#include "WebSocketInterface/json_keys.h"
|
||||
|
||||
#include <QtCore/QUuid>
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtGlobal>
|
||||
namespace TrainingAreaBase
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
using namespace JsonKeys;
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
// ####### ReplyMessage begin #######
|
||||
|
||||
QString ReplyMessage::toJsonString() const
|
||||
{
|
||||
return QString::fromUtf8(QJsonDocument(m_jsonRepresentation).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
ReplyMessage::ReplyMessage(const QString &type, const int typeId, const QString &uuid)
|
||||
: LtsWebSocket::ReplyMessage(type, typeId, uuid)
|
||||
{
|
||||
//we could skip the whole sub class here!
|
||||
}
|
||||
// ####### ReplyMessage end #######
|
||||
|
||||
// ####### OkMessage begin #######
|
||||
OkMessage::OkMessage(const OkMessage::OkData &data)
|
||||
: ReplyMessage(OK(), 1, data.uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{MESSAGE_TYPE(), data.messageType},
|
||||
{INFO(), data.info}
|
||||
}));
|
||||
}
|
||||
// ####### OkMessage end #######
|
||||
|
||||
// ####### ErrorMessage begin #######
|
||||
ErrorMessage::ErrorMessage(const ErrorMessage::ErrorData &data)
|
||||
: ReplyMessage(ERROR_(), -1, data.uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{ERROR_CLASS(), data.errorClass},
|
||||
{ERROR_MESSAGE(), data.errorMessage}
|
||||
}));
|
||||
}
|
||||
|
||||
// ####### ErrorMessage end #######
|
||||
|
||||
// ####### BiteDataMessage begin #######
|
||||
QJsonObject BiteDataMessage::ErrorText::toJson() const
|
||||
{
|
||||
return QJsonObject({{LANG(), lang},
|
||||
{_TEXT(), text}
|
||||
});
|
||||
}
|
||||
|
||||
QJsonObject BiteDataMessage::ConfigurationError::toJson() const
|
||||
{
|
||||
return QJsonObject({{COMPONENT_NAME(), componentName},
|
||||
{_TEXT(), text}
|
||||
});
|
||||
}
|
||||
|
||||
QJsonObject BiteDataMessage::BasicError::toJson() const
|
||||
{
|
||||
return QJsonObject({{ERROR_TEXT(), text}});
|
||||
}
|
||||
|
||||
|
||||
QJsonObject BiteDataMessage::BiteError::toJson() const
|
||||
{
|
||||
return QJsonObject({{ERROR_TEXT(), vecToPath(errorTexts)},
|
||||
{DEVICE_ID(), deviceId},
|
||||
{SUBDEVICE(), subDevice},
|
||||
{UNIQUE_ID(), uniqueId},
|
||||
{ERROR_NO(), errorNo},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
BiteDataMessage::BiteDataMessage(const BiteDataMessage::BiteData &data, const QString &uuid)
|
||||
: ReplyMessage(BITE_DATA(), 2, uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{EQUIP_NO(), data.equipNo},
|
||||
{BOX(), data.box},
|
||||
{LAST_UPDATE(), data.lastUpdate},
|
||||
{BITE_ERRORS(), vecToPath(data.biteErrors)},
|
||||
{CONFIGURATION_ERRORS(), vecToPath(data.configurationErrors)},
|
||||
{BASIC_ERRORS(), vecToPath(data.basicErrors)},
|
||||
{LAST_POSITION_UPDATE(), data.lastPositionUpdate},
|
||||
{IS_LICENSED(), data.isLicensed}
|
||||
}));
|
||||
}
|
||||
// ####### BiteDataMessage end #######
|
||||
|
||||
PositionMessage::PositionMessage(const PositionMessage::PositionData &data, const QString &uuid)
|
||||
: ReplyMessage(POSITION_DATA(), 3, uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{EQUIP_NO(), data.equipNo},
|
||||
{POS_LAT(), data.pos.lat()},
|
||||
{POS_LON(), data.pos.lon()},
|
||||
{POS_Z(), data.pos.z()},
|
||||
{LAST_POSITION_UPDATE(), data.gpsTime}
|
||||
}));
|
||||
}
|
||||
|
||||
// ####### PositionMessage end #######
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
Reference in new issue
Block a user