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() = default;
16 
17  EuroscopeSimData::EuroscopeSimData(const QString &sender, const QString &model, const QString &livery,
18  quint64 timestamp, double latitude, double longitude, double altitude,
19  double heading, int bank, int pitch, int groundSpeed, bool onGround,
20  double gearPercent, double thrustPercent,
22  : MessageBase(sender, {}), m_model(model), m_livery(livery), m_timestamp(timestamp), m_latitude(latitude),
23  m_longitude(longitude), m_altitude(altitude), m_heading(heading), m_bank(bank), m_pitch(pitch),
24  m_groundSpeed(groundSpeed), m_onGround(onGround), m_gearPercent(gearPercent), m_thrustPercent(thrustPercent),
25  m_lights(lights)
26  {}
27 
28  QStringList EuroscopeSimData::toTokens() const
29  {
30  static constexpr auto toFlags = [](const CAircraftLights &lights) {
31  int n = 0;
32  if (lights.isBeaconOn()) { n |= 0x002; }
33  if (lights.isCabinOn()) { n |= 0x400; }
34  if (lights.isLandingOn()) { n |= 0x020; }
35  if (lights.isLogoOn()) { n |= 0x200; }
36  if (lights.isNavOn()) { n |= 0x008; }
37  if (lights.isRecognitionOn()) { n |= 0x080; }
38  if (lights.isStrobeOn()) { n |= 0x004; }
39  if (lights.isTaxiOn()) { n |= 0x040; }
40  return n;
41  };
42 
43  QStringList tokens;
44  tokens.push_back({}); // first token is empty
45  tokens.push_back(m_sender);
46  tokens.push_back(m_model);
47  tokens.push_back(m_livery);
48  tokens.push_back(QString::number(m_timestamp));
49  tokens.push_back(QString::number(m_latitude, 'f', 7));
50  tokens.push_back(QString::number(m_longitude, 'f', 7));
51  tokens.push_back(QString::number(m_altitude, 'f', 1));
52  tokens.push_back(QString::number(m_heading, 'f', 2));
53  tokens.push_back(QString::number(m_bank));
54  tokens.push_back(QString::number(m_pitch));
55  tokens.push_back(QString::number(m_groundSpeed));
56  tokens.push_back(m_onGround ? QStringLiteral("1") : QStringLiteral("0"));
57  tokens.push_back(QString::number(m_gearPercent));
58  tokens.push_back(QString::number(m_thrustPercent));
59  tokens.push_back(QStringLiteral("0")); // emergency flags
60  tokens.push_back(QStringLiteral("0.0")); // airport altitude
61  tokens.push_back(QString::number(toFlags(m_lights)));
62  return tokens;
63  }
64 
66  {
67  if (tokens.size() < 18)
68  {
69  CLogMessage(static_cast<EuroscopeSimData *>(nullptr)).debug(u"Wrong number of arguments.");
70  return {};
71  }
72 
73  static constexpr auto fromFlags = [](int n) {
74  return CAircraftLights(n & 0x4, n & 0x20, n & 0x40, n & 0x2, n & 0x8, n & 0x200, n & 0x80, n & 0x400);
75  };
76 
77  // token[0,15,16] are not used
78  return EuroscopeSimData(tokens[1], tokens[2], tokens[3], tokens[4].toULongLong(), tokens[5].toDouble(),
79  tokens[6].toDouble(), tokens[7].toDouble(), tokens[8].toDouble(), tokens[9].toInt(),
80  tokens[10].toInt(), tokens[11].toInt(), tokens[12].toInt(), tokens[13].toDouble(),
81  tokens[14].toDouble(), fromFlags(tokens[17].toInt()));
82  }
83 } // 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.