SimsWorld/MessageBasic/messagebasic.cpp

172 lines
3.8 KiB
C++
Raw Normal View History

2025-05-25 04:43:37 +00:00
#include "messagebasic.h"
#include <QVariant>
void from_to_save(uint64_t f, uint64_t t, QJsonObject& o) {
o["source_entity"] = QJsonValue::fromVariant(QVariant::fromValue(f));
o["target_entity"] = QJsonValue::fromVariant(QVariant::fromValue(t));
}
void from_to_recovery(uint64_t& f, uint64_t& t, const QJsonObject& o) {
f = o["source_entity"].toVariant().toULongLong();
t = o["target_entity"].toVariant().toULongLong();
}
2025-06-07 15:58:50 +00:00
DeduceRequest::DeduceRequest()
:AbstractMessage(NAME(DeduceRequest)) {
}
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
SyncRequest::SyncRequest()
:AbstractMessage(NAME(SyncRequest)),
_time_current(0) {
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void SyncRequest::recoveryFrom(const QJsonObject& obj)
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::recoveryFrom(obj);
DOUOBLE_PEAK(_time_current);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void SyncRequest::saveTo(QJsonObject& obj) const
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_time_current);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
RespondDefault::RespondDefault()
:AbstractMessage(NAME(RespondDefault)),
_time_consume(0) {
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void RespondDefault::recoveryFrom(const QJsonObject& obj)
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::recoveryFrom(obj);
DOUOBLE_PEAK(_time_consume);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void RespondDefault::saveTo(QJsonObject& obj) const
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_time_consume);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
Get3DBox::Get3DBox()
:AbstractMessage(NAME(Get3DBox)) {
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
Box3DDesc::Box3DDesc()
:AbstractMessage(NAME(Box3DDesc)) {
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void Box3DDesc::recoveryFrom(const QJsonObject& obj)
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::recoveryFrom(obj);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
DOUOBLE_PEAK(this->_d3_data._height_m);
DOUOBLE_PEAK(this->_d3_data._length_m);
DOUOBLE_PEAK(this->_d3_data._width_m);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
DOUOBLE_PEAK(this->_lla_pos._lon_deg);
DOUOBLE_PEAK(this->_lla_pos._lat_deg);
DOUOBLE_PEAK(this->_lla_pos._alt_m);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
DOUOBLE_PEAK(this->_posture_d3._azimuth_deg);
DOUOBLE_PEAK(this->_posture_d3._pitch_deg);
DOUOBLE_PEAK(this->_posture_d3._roll_deg);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void Box3DDesc::saveTo(QJsonObject& obj) const
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::saveTo(obj);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
DOUBLE_SAVE(this->_d3_data._height_m);
DOUBLE_SAVE(this->_d3_data._length_m);
DOUBLE_SAVE(this->_d3_data._width_m);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
DOUBLE_SAVE(this->_lla_pos._lon_deg);
DOUBLE_SAVE(this->_lla_pos._lat_deg);
DOUBLE_SAVE(this->_lla_pos._alt_m);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
DOUBLE_SAVE(this->_posture_d3._azimuth_deg);
DOUBLE_SAVE(this->_posture_d3._pitch_deg);
DOUBLE_SAVE(this->_posture_d3._roll_deg);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
EntityAllocte::EntityAllocte()
:AbstractMessage(NAME(EntityAllocte)) {
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void EntityAllocte::recoveryFrom(const QJsonObject& obj)
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::recoveryFrom(obj);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
STRING_PEAK(_entity_templet);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void EntityAllocte::saveTo(QJsonObject& obj) const
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::saveTo(obj);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
STRING_SAVE(_entity_templet);
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
AbstractMessage::AbstractMessage(const QString& topic) :_topic_string(topic) {}
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
void AbstractMessage::reset(uint64_t from, uint64_t to) {
this->_from_id = from;
this->_to_id = to;
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
// ͨ<><CDA8> WsMessage <20>̳<EFBFBD>
void AbstractMessage::recoveryFrom(const QJsonObject& obj) {
2025-05-25 04:43:37 +00:00
from_to_recovery(_from_id, _to_id, obj);
}
2025-06-07 15:58:50 +00:00
void AbstractMessage::saveTo(QJsonObject& obj) const
2025-05-25 04:43:37 +00:00
{
from_to_save(_from_id, _to_id, obj);
}
2025-06-07 15:58:50 +00:00
QString AbstractMessage::topicString() const
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
return _topic_string;
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
uint64_t AbstractMessage::targetEntity() const
2025-05-25 04:43:37 +00:00
{
return _to_id;
}
2025-06-07 15:58:50 +00:00
uint64_t AbstractMessage::sourceEntity() const
2025-05-25 04:43:37 +00:00
{
return _from_id;
}
2025-06-07 15:58:50 +00:00
EntityTotalGet::EntityTotalGet()
:AbstractMessage(NAME(EntityTotalGet)) {
2025-05-25 04:43:37 +00:00
}
EntityTotalList::EntityTotalList()
:AbstractMessage(NAME(EntityTotalList)) {
}
2025-06-07 15:58:50 +00:00
void EntityTotalList::recoveryFrom(const QJsonObject& obj)
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::recoveryFrom(obj);
2025-05-31 03:57:32 +00:00
2025-06-07 15:58:50 +00:00
QStringList strs;
STRLIST_PEAK(strs);
std::transform(strs.begin(), strs.end(),
std::back_inserter(_entities_list),
[](QString v) { return v.toULongLong(); });
2025-05-25 04:43:37 +00:00
}
2025-06-07 15:58:50 +00:00
void EntityTotalList::saveTo(QJsonObject& obj) const
2025-05-25 04:43:37 +00:00
{
2025-06-07 15:58:50 +00:00
AbstractMessage::saveTo(obj);
2025-05-25 04:43:37 +00:00
2025-06-07 15:58:50 +00:00
QStringList strs;
std::transform(_entities_list.begin(), _entities_list.end(),
std::back_inserter(strs),
[](int v) { return QString(",").arg(v); });
STRLIST_SAVE(strs);
2025-05-25 04:43:37 +00:00
}