Files
qt5-legatus-legacy/Lts/Services/EffectShowManagement/esm_convert_to_tab.cpp
T
2026-08-13 18:33:10 +02:00

144 lines
4.2 KiB
C++
Executable File

/**
* @RDE_HEADER@
* MeteoDataManagement - Static Meteo Data Edit Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-10-17
*/
#include "esm_convert_to_tab.h"
#include <LtsUtilsCore/qbytearray_byteaccess.h>
#include <LtsUtilsCore/dds_vector.h>
#include <QByteArray>
namespace EffectShowManagement
{
namespace ConvertToTab
{
//=============================================================================
std::vector<uint8_t> convertEffectShowOrder(const EffectShowOrder_t &effectShowOrder)
{
QByteArray ba;
ba.reserve(48);
LtsUtils::set1Byte(150, ba);
LtsUtils::set2Byte(effectShowOrder.idEffectShow, ba);
LtsUtils::set4Byte(effectShowOrder.startTime, ba);
LtsUtils::set8Byte(effectShowOrder.centerPosition.lon(), ba);
LtsUtils::set8Byte(effectShowOrder.centerPosition.lat(), ba);
// 50m squares
LtsUtils::set1Byte(effectShowOrder.areaWidth / 50, ba);
LtsUtils::set1Byte(effectShowOrder.areaDepth / 50, ba);
double rotation = fmod(effectShowOrder.rotation, 360.0);
if (rotation < 0.0)
rotation += 360.0;
LtsUtils::set2Byte(qRound(rotation * 100), ba);
LtsUtils::set8Byte(effectShowOrder.lowerLeftPosition.lon(), ba);
LtsUtils::set8Byte(effectShowOrder.lowerLeftPosition.lat(), ba);
LtsUtils::set1Byte(effectShowOrder.numOfVolley, ba);
LtsUtils::set1Byte(effectShowOrder.shotsPerVolley, ba);
LtsUtils::set1Byte(effectShowOrder.typeOfAmmunition, ba);
LtsUtils::set2Byte(static_cast<quint16>(effectShowOrder.duration), ba);
const QByteArray text = effectShowOrder.name.toUtf8().simplified();
for (auto c : text)
LtsUtils::set1Byte(c, ba);
return LtsUtils::convert<std::vector<uint8_t>>(ba);
}
//=============================================================================
std::vector<uint8_t> convertRelocationOrder(const RelocationOrder_t &relocationOrder)
{
QByteArray ba;
ba.reserve(63);
LtsUtils::set1Byte(155, ba);
LtsUtils::set2Byte(relocationOrder.idRelocation, ba);
LtsUtils::set4Byte(relocationOrder.executionTime, ba);
LtsUtils::set8Byte(relocationOrder.centerPosition.lon(), ba);
LtsUtils::set8Byte(relocationOrder.centerPosition.lat(), ba);
const QByteArray text = relocationOrder.infoText.toUtf8().simplified();
for (auto c : text)
LtsUtils::set1Byte(c, ba);
return LtsUtils::convert<std::vector<uint8_t>>(ba);
}
//======================================================================
std::vector<uint8_t> convertEffectShowStop(const qint16 &idEffectShow)
{
QByteArray ba;
ba.reserve(3);
LtsUtils::set1Byte(152, ba);
LtsUtils::set2Byte(idEffectShow, ba);
return LtsUtils::convert<std::vector<uint8_t>>(ba);
}
//======================================================================
std::vector<uint8_t> convertEffectShowContinue(const EffectShowContinue_t &effectShowContinue)
{
QByteArray ba;
ba.reserve(7);
LtsUtils::set1Byte(151, ba);
LtsUtils::set2Byte(effectShowContinue.idEffectShow, ba);
LtsUtils::set4Byte(effectShowContinue.executionTime, ba);
return LtsUtils::convert<std::vector<uint8_t>>(ba);
}
//======================================================================
std::vector<uint8_t> convertOrderRetract(const RetractOrder_t &retractOrder)
{
QByteArray ba;
ba.reserve(4);
LtsUtils::set1Byte(153, ba);
LtsUtils::set1Byte(retractOrder.orderType, ba);
LtsUtils::set2Byte(retractOrder.id, ba);
return LtsUtils::convert<std::vector<uint8_t>>(ba);
}
//=====================================================================
std::vector<uint8_t> convertStatusRequest()
{
std::vector<uint8_t> tele;
tele.resize(1, 154);
return tele;
}
//======================================================================
std::vector<uint8_t> convertMeteoData(const MeteoDataManagement::MeteoData &meteoData)
{
QByteArray ba;
ba.reserve(11);
LtsUtils::set1Byte(156, ba);
LtsUtils::set2Byte(qRound(meteoData.temperature() * 10.0), ba);
LtsUtils::set2Byte(qRound(meteoData.humidity()), ba);
LtsUtils::set2Byte(qRound(meteoData.pressure()), ba);
double dir = fmod(meteoData.windDirection(), 360.0);
if (dir < 0.0)
dir += 360.0;
LtsUtils::set2Byte(qRound(dir * 100), ba);
LtsUtils::set2Byte(qRound(meteoData.windSpeed()), ba);
return LtsUtils::convert<std::vector<uint8_t>>(ba);
}
} // namespace ConvertToTab
} // namespace EffectShowManagement