Files
pilotclient/src/blackcore/fsd/visualpilotdataperiodic.cpp
2022-02-20 14:33:07 +00:00

91 lines
3.9 KiB
C++

/* Copyright (C) 2019
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
#include "visualpilotdataperiodic.h"
#include "visualpilotdataupdate.h"
#include "pbh.h"
#include "serializer.h"
#include "blackmisc/logmessage.h"
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
namespace BlackCore::Fsd
{
VisualPilotDataPeriodic::VisualPilotDataPeriodic() : MessageBase()
{ }
VisualPilotDataPeriodic::VisualPilotDataPeriodic(const QString &sender, double latitude, double longitude, double altitudeTrue, double heightAgl,
double pitch, double bank, double heading, double xVelocity, double yVelocity, double zVelocity,
double pitchRadPerSec, double bankRadPerSec, double headingRadPerSec, double noseGearAngle)
: MessageBase(sender, {}),
m_latitude(latitude),
m_longitude(longitude),
m_altitudeTrue(altitudeTrue),
m_heightAgl(heightAgl),
m_pitch(pitch),
m_bank(bank),
m_heading(heading),
m_xVelocity(xVelocity),
m_yVelocity(yVelocity),
m_zVelocity(zVelocity),
m_pitchRadPerSec(pitchRadPerSec),
m_bankRadPerSec(bankRadPerSec),
m_headingRadPerSec(headingRadPerSec),
m_noseGearAngle(noseGearAngle)
{ }
QStringList VisualPilotDataPeriodic::toTokens() const
{
std::uint32_t pbh;
packPBH(m_pitch, m_bank, m_heading, false/*! \todo check if needed? */, pbh);
QStringList tokens;
tokens.push_back(m_sender);
tokens.push_back(QString::number(m_latitude, 'f', 7));
tokens.push_back(QString::number(m_longitude, 'f', 7));
tokens.push_back(QString::number(m_altitudeTrue, 'f', 2));
tokens.push_back(QString::number(m_heightAgl, 'f', 2));
tokens.push_back(QString::number(pbh));
tokens.push_back(QString::number(m_xVelocity, 'f', 4));
tokens.push_back(QString::number(m_yVelocity, 'f', 4));
tokens.push_back(QString::number(m_zVelocity, 'f', 4));
tokens.push_back(QString::number(m_pitchRadPerSec, 'f', 4));
tokens.push_back(QString::number(m_headingRadPerSec, 'f', 4));
tokens.push_back(QString::number(m_bankRadPerSec, 'f', 4));
tokens.push_back(QString::number(m_noseGearAngle, 'f', 2));
return tokens;
}
VisualPilotDataPeriodic VisualPilotDataPeriodic::fromTokens(const QStringList &tokens)
{
if (tokens.size() < 12)
{
CLogMessage(static_cast<VisualPilotDataPeriodic *>(nullptr)).debug(u"Wrong number of arguments.");
return {};
}
double pitch = 0.0;
double bank = 0.0;
double heading = 0.0;
bool unused = false; //! \todo check if needed?
unpackPBH(tokens[5].toUInt(), pitch, bank, heading, unused);
return VisualPilotDataPeriodic(tokens[0], tokens[1].toDouble(), tokens[2].toDouble(), tokens[3].toDouble(), tokens[4].toDouble(),
pitch, bank, heading, tokens[6].toDouble(), tokens[7].toDouble(), tokens[8].toDouble(), tokens[9].toDouble(),
tokens[11].toDouble(), tokens[10].toDouble(), tokens.value(12, QStringLiteral("0")).toDouble());
}
VisualPilotDataUpdate VisualPilotDataPeriodic::toUpdate() const
{
return VisualPilotDataUpdate(m_sender, m_latitude, m_longitude, m_altitudeTrue, m_heightAgl, m_pitch, m_bank, m_heading,
m_xVelocity, m_yVelocity, m_zVelocity, m_pitchRadPerSec, m_bankRadPerSec, m_headingRadPerSec, m_noseGearAngle);
}
}