swift
visualpilotdatastopped.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "pbh.h"
7 #include "serializer.h"
9 
10 #include "misc/logmessage.h"
11 
12 using namespace swift::misc;
13 using namespace swift::misc::aviation;
14 
15 namespace swift::core::fsd
16 {
17  VisualPilotDataStopped::VisualPilotDataStopped() : MessageBase() {}
18 
19  VisualPilotDataStopped::VisualPilotDataStopped(const QString &sender, double latitude, double longitude,
20  double altitudeTrue, double heightAgl, double pitch, double bank,
21  double heading, double noseGearAngle)
22  : MessageBase(sender, {}), m_latitude(latitude), m_longitude(longitude), m_altitudeTrue(altitudeTrue),
23  m_heightAgl(heightAgl), m_pitch(pitch), m_bank(bank), m_heading(heading), m_noseGearAngle(noseGearAngle)
24  {}
25 
27  {
28  std::uint32_t pbh;
29  packPBH(m_pitch, m_bank, m_heading, false , pbh);
30 
31  QStringList tokens;
32  tokens.push_back(m_sender);
33  tokens.push_back(QString::number(m_latitude, 'f', 7));
34  tokens.push_back(QString::number(m_longitude, 'f', 7));
35  tokens.push_back(QString::number(m_altitudeTrue, 'f', 2));
36  tokens.push_back(QString::number(m_heightAgl, 'f', 2));
37  tokens.push_back(QString::number(pbh));
38  tokens.push_back(QString::number(m_noseGearAngle, 'f', 2));
39  return tokens;
40  }
41 
43  {
44  if (tokens.size() < 6)
45  {
46  CLogMessage(static_cast<VisualPilotDataStopped *>(nullptr)).debug(u"Wrong number of arguments.");
47  return {};
48  }
49 
50  double pitch = 0.0;
51  double bank = 0.0;
52  double heading = 0.0;
53  bool unused = false;
54  unpackPBH(tokens[5].toUInt(), pitch, bank, heading, unused);
55 
56  return VisualPilotDataStopped(tokens[0], tokens[1].toDouble(), tokens[2].toDouble(), tokens[3].toDouble(),
57  tokens[4].toDouble(), pitch, bank, heading,
58  tokens.value(12, QStringLiteral("0")).toDouble());
59  }
60 
62  {
64  m_heading, 0, 0, 0, 0, 0, 0, m_noseGearAngle);
65  }
66 } // namespace swift::core::fsd
FSD message base class.
Definition: messagebase.h:58
QString m_sender
message sender
Definition: messagebase.h:88
VisualPilotDataUpdate with velocity assumed to be zero.
VisualPilotDataUpdate toUpdate() const
Return a regular visual update with the same values.
QStringList toTokens() const
Message converted to tokens.
static VisualPilotDataStopped fromTokens(const QStringList &tokens)
Construct from tokens.
Pilot data update broadcasted to pilots in range every 0.2 seconds.
Class for emitting a log message.
Definition: logmessage.h:27
Derived & debug()
Set the severity to debug.
Free functions in swift::misc.
void unpackPBH(quint32 pbh, double &pitch, double &bank, double &heading, bool &onGround)
Unpack pitch, bank, heading and onGround from 32 bit integer.
Definition: pbh.h:57
void packPBH(double pitch, double bank, double heading, bool onGround, quint32 &pbh)
Pack pitch, bank, heading and onGround into 32 bit integer.
Definition: pbh.h:38