swift
visualpilotdataperiodic.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  VisualPilotDataPeriodic::VisualPilotDataPeriodic() : MessageBase() {}
18 
19  VisualPilotDataPeriodic::VisualPilotDataPeriodic(const QString &sender, double latitude, double longitude,
20  double altitudeTrue, double heightAgl, double pitch, double bank,
21  double heading, double xVelocity, double yVelocity,
22  double zVelocity, double pitchRadPerSec, double bankRadPerSec,
23  double headingRadPerSec, double noseGearAngle)
24  : MessageBase(sender, {}), m_latitude(latitude), m_longitude(longitude), m_altitudeTrue(altitudeTrue),
25  m_heightAgl(heightAgl), m_pitch(pitch), m_bank(bank), m_heading(heading), m_xVelocity(xVelocity),
26  m_yVelocity(yVelocity), m_zVelocity(zVelocity), m_pitchRadPerSec(pitchRadPerSec),
27  m_bankRadPerSec(bankRadPerSec), m_headingRadPerSec(headingRadPerSec), m_noseGearAngle(noseGearAngle)
28  {}
29 
31  {
32  std::uint32_t pbh;
33  packPBH(m_pitch, m_bank, m_heading, false , pbh);
34 
35  QStringList tokens;
36  tokens.push_back(m_sender);
37  tokens.push_back(QString::number(m_latitude, 'f', 7));
38  tokens.push_back(QString::number(m_longitude, 'f', 7));
39  tokens.push_back(QString::number(m_altitudeTrue, 'f', 2));
40  tokens.push_back(QString::number(m_heightAgl, 'f', 2));
41  tokens.push_back(QString::number(pbh));
42  tokens.push_back(QString::number(m_xVelocity, 'f', 4));
43  tokens.push_back(QString::number(m_yVelocity, 'f', 4));
44  tokens.push_back(QString::number(m_zVelocity, 'f', 4));
45  tokens.push_back(QString::number(m_pitchRadPerSec, 'f', 4));
46  tokens.push_back(QString::number(m_headingRadPerSec, 'f', 4));
47  tokens.push_back(QString::number(m_bankRadPerSec, 'f', 4));
48  tokens.push_back(QString::number(m_noseGearAngle, 'f', 2));
49  return tokens;
50  }
51 
53  {
54  if (tokens.size() < 12)
55  {
56  CLogMessage(static_cast<VisualPilotDataPeriodic *>(nullptr)).debug(u"Wrong number of arguments.");
57  return {};
58  }
59 
60  double pitch = 0.0;
61  double bank = 0.0;
62  double heading = 0.0;
63  bool unused = false;
64  unpackPBH(tokens[5].toUInt(), pitch, bank, heading, unused);
65 
67  tokens[0], tokens[1].toDouble(), tokens[2].toDouble(), tokens[3].toDouble(), tokens[4].toDouble(), pitch,
68  bank, heading, tokens[6].toDouble(), tokens[7].toDouble(), tokens[8].toDouble(), tokens[9].toDouble(),
69  tokens[11].toDouble(), tokens[10].toDouble(), tokens.value(12, QStringLiteral("0")).toDouble());
70  }
71 
73  {
77  }
78 } // namespace swift::core::fsd
FSD message base class.
Definition: messagebase.h:58
QString m_sender
message sender
Definition: messagebase.h:88
Every 25th VisualPilotDataUpdate is actually one of these ("slowfast").
QStringList toTokens() const
Message converted to tokens.
static VisualPilotDataPeriodic fromTokens(const QStringList &tokens)
Construct from tokens.
VisualPilotDataUpdate toUpdate() const
Return a regular visual update with the same values.
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