swift
euroscopesimdata.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2021 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
7 
8 #include "misc/logmessage.h"
9 
10 using namespace swift::misc;
11 using namespace swift::misc::aviation;
12 
13 namespace swift::core::fsd
14 {
15  EuroscopeSimData::EuroscopeSimData(const QString &sender, const QString &model, const QString &livery,
16  quint64 timestamp, double latitude, double longitude, double altitude,
17  double heading, int bank, int pitch, int groundSpeed, bool onGround,
18  double gearPercent, double thrustPercent,
20  : MessageBase(sender, {}), m_model(model), m_livery(livery), m_timestamp(timestamp), m_latitude(latitude),
21  m_longitude(longitude), m_altitude(altitude), m_heading(heading), m_bank(bank), m_pitch(pitch),
22  m_groundSpeed(groundSpeed), m_onGround(onGround), m_gearPercent(gearPercent), m_thrustPercent(thrustPercent),
23  m_lights(lights)
24  {}
25 
27  {
28  static constexpr auto toFlags = [](const CAircraftLights &lights) {
29  int n = 0;
30  if (lights.isBeaconOn()) { n |= 0x002; }
31  if (lights.isCabinOn()) { n |= 0x400; }
32  if (lights.isLandingOn()) { n |= 0x020; }
33  if (lights.isLogoOn()) { n |= 0x200; }
34  if (lights.isNavOn()) { n |= 0x008; }
35  if (lights.isRecognitionOn()) { n |= 0x080; }
36  if (lights.isStrobeOn()) { n |= 0x004; }
37  if (lights.isTaxiOn()) { n |= 0x040; }
38  return n;
39  };
40 
41  QStringList tokens;
42  tokens.push_back({}); // first token is empty
43  tokens.push_back(m_sender);
44  tokens.push_back(m_model);
45  tokens.push_back(m_livery);
47  tokens.push_back(QString::number(m_latitude, 'f', 7));
48  tokens.push_back(QString::number(m_longitude, 'f', 7));
49  tokens.push_back(QString::number(m_altitude, 'f', 1));
50  tokens.push_back(QString::number(m_heading, 'f', 2));
54  tokens.push_back(m_onGround ? QStringLiteral("1") : QStringLiteral("0"));
57  tokens.push_back(QStringLiteral("0")); // emergency flags
58  tokens.push_back(QStringLiteral("0.0")); // airport altitude
59  tokens.push_back(QString::number(toFlags(m_lights)));
60  return tokens;
61  }
62 
64  {
65  if (tokens.size() < 18)
66  {
67  CLogMessage(static_cast<EuroscopeSimData *>(nullptr)).debug(u"Wrong number of arguments.");
68  return {};
69  }
70 
71  static constexpr auto fromFlags = [](int n) {
72  return CAircraftLights(n & 0x4, n & 0x20, n & 0x40, n & 0x2, n & 0x8, n & 0x200, n & 0x80, n & 0x400);
73  };
74 
75  // token[0,15,16] are not used
76  return { tokens[1],
77  tokens[2],
78  tokens[3],
79  tokens[4].toULongLong(),
80  tokens[5].toDouble(),
81  tokens[6].toDouble(),
82  tokens[7].toDouble(),
83  tokens[8].toDouble(),
84  tokens[9].toInt(),
85  tokens[10].toInt(),
86  tokens[11].toInt(),
87  static_cast<bool>(tokens[12].toInt()),
88  tokens[13].toDouble(),
89  tokens[14].toDouble(),
90  fromFlags(tokens[17].toInt()) };
91  }
92 } // namespace swift::core::fsd
Pilot data update broadcast by Euroscope Simulator every second.
QStringList toTokens() const
Message converted to tokens.
static EuroscopeSimData fromTokens(const QStringList &tokens)
Construct from tokens.
swift::misc::aviation::CAircraftLights m_lights
Properties.
FSD message base class.
Definition: messagebase.h:58
QString m_sender
message sender
Definition: messagebase.h:88
Class for emitting a log message.
Definition: logmessage.h:27
Derived & debug()
Set the severity to debug.
Value object encapsulating information about aircraft's lights.
Free functions in swift::misc.
void push_back(QList< T >::parameter_type value)
qsizetype size() const const
QString number(double n, char format, int precision)