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(const QString &sender, double latitude, double longitude,
18  double altitudeTrue, double heightAgl, double pitch, double bank,
19  double heading, double noseGearAngle)
20  : MessageBase(sender, {}), m_latitude(latitude), m_longitude(longitude), m_altitudeTrue(altitudeTrue),
21  m_heightAgl(heightAgl), m_pitch(pitch), m_bank(bank), m_heading(heading), m_noseGearAngle(noseGearAngle)
22  {}
23 
25  {
26  std::uint32_t pbh {};
27  packPBH(m_pitch, m_bank, m_heading, false , pbh);
28 
29  QStringList tokens;
30  tokens.push_back(m_sender);
31  tokens.push_back(QString::number(m_latitude, 'f', 7));
32  tokens.push_back(QString::number(m_longitude, 'f', 7));
33  tokens.push_back(QString::number(m_altitudeTrue, 'f', 2));
34  tokens.push_back(QString::number(m_heightAgl, 'f', 2));
35  tokens.push_back(QString::number(pbh));
36  tokens.push_back(QString::number(m_noseGearAngle, 'f', 2));
37  return tokens;
38  }
39 
41  {
42  if (tokens.size() < 6)
43  {
44  CLogMessage(static_cast<VisualPilotDataStopped *>(nullptr)).debug(u"Wrong number of arguments.");
45  return {};
46  }
47 
48  double pitch = 0.0;
49  double bank = 0.0;
50  double heading = 0.0;
51  bool unused = false;
52  unpackPBH(tokens[5].toUInt(), pitch, bank, heading, unused);
53 
54  return { tokens[0],
55  tokens[1].toDouble(),
56  tokens[2].toDouble(),
57  tokens[3].toDouble(),
58  tokens[4].toDouble(),
59  pitch,
60  bank,
61  heading,
62  tokens.value(12, QStringLiteral("0")).toDouble() };
63  }
64 
66  {
68  0, 0, 0, m_noseGearAngle };
69  }
70 } // 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
void push_back(QList< T >::parameter_type value)
qsizetype size() const const
T value(qsizetype i) const const
QString number(double n, char format, int precision)