mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
415 lines
16 KiB
C++
415 lines
16 KiB
C++
// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
|
|
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
|
|
|
//! \file
|
|
|
|
#ifndef SWIFT_SIMPLUGIN_MSFS2024COMMON_SIMCONNECT_DATADEFINITION_H
|
|
#define SWIFT_SIMPLUGIN_MSFS2024COMMON_SIMCONNECT_DATADEFINITION_H
|
|
|
|
#include <algorithm>
|
|
|
|
#include <QString>
|
|
#include <QtGlobal>
|
|
|
|
#include "misc/aviation/aircraftlights.h"
|
|
#include "misc/simulation/simulatorinfo.h"
|
|
#include "plugins/simulator/msfs2024/msfs2024export.h"
|
|
#include "plugins/simulator/msfs2024/simconnectsymbolsmsfs2024.h"
|
|
#include "plugins/simulator/msfs2024/simconnectwindowsmsfs2024.h"
|
|
|
|
namespace swift::misc::aviation
|
|
{
|
|
class CAircraftParts;
|
|
}
|
|
namespace swift::simplugin::msfs2024common
|
|
{
|
|
//! Data struct of our own aircraft
|
|
//! \sa SimConnect variables http://msdn.microsoft.com/en-us/library/cc526981.aspx
|
|
//! \sa SimConnect events http://msdn.microsoft.com/en-us/library/cc526980.aspx
|
|
struct DataDefinitionOwnAircraft
|
|
{
|
|
double latitudeDeg; //!< Latitude (deg)
|
|
double longitudeDeg; //!< Longitude (deg)
|
|
double altitudeFt; //!< Altitude (ft)
|
|
double altitudeAGLFt; //!< Altitude above ground (ft)
|
|
double pressureAltitudeM; //!< Pressure altitude (m)
|
|
double cgToGroundFt; //!< Static CG to ground (ft)
|
|
double trueHeadingDeg; //!< True heading (deg)
|
|
double pitchDeg; //!< Pitch (deg)
|
|
double bankDeg; //!< Bank (deg)
|
|
double velocity; //!< Ground velocity
|
|
double elevationFt; //!< Elevation (ft)
|
|
double simOnGround; //!< Is aircraft on ground?
|
|
// 12
|
|
double lightStrobe; //!< Is strobe light on?
|
|
double lightLanding; //!< Is landing light on?
|
|
double lightTaxi; //!< Is taxi light on?
|
|
double lightBeacon; //!< Is beacon light on?
|
|
double lightNav; //!< Is nav light on?
|
|
double lightLogo; //!< Is logo light on?
|
|
double lightRecognition;
|
|
double lightCabin; //!< Is cabin light on?
|
|
double lightWing; //!< Is wing light on?
|
|
// 21
|
|
double transponderCode; //!< Transponder Code
|
|
double com1ActiveMHz; //!< COM1 active frequency
|
|
double com2ActiveMHz; //!< COM2 active frequency
|
|
double com1StandbyMHz; //!< COM1 standby frequency
|
|
double com2StandbyMHz; //!< COM2 standby frequency
|
|
double comTransmit1; //!< COM1 transmit, means also receiving
|
|
double comTransmit2; //!< COM2 transmit, means also receiving
|
|
double comReceiveAll; //!< all COMs receiving, or COM:x transmitting or receiving
|
|
double comTest1; //!< COM1 test
|
|
double comTest2; //!< COM2 test
|
|
double comStatus1; //!< COM1 status
|
|
double comStatus2; //!< COM2 status
|
|
// 33
|
|
double flapsHandlePosition; //!< Flaps handle position in percent
|
|
double spoilersHandlePosition; //!< Spoilers out? (flag)
|
|
double gearHandlePosition; //!< Gear handle position (flag)
|
|
// 36
|
|
double numberOfEngines; //!< Number of engines
|
|
double engineType; //!< Engine type
|
|
double engine1Combustion; //!< Engine 1 combustion flag
|
|
double engine2Combustion; //!< Engine 2 combustion flag
|
|
double engine3Combustion; //!< Engine 3 combustion flag
|
|
double engine4Combustion; //!< Engine 4 combustion flag
|
|
double engine5Combustion; //!< Engine 5 combustion flag
|
|
double engine6Combustion; //!< Engine 6 combustion flag
|
|
double engine7Combustion; //!< Engine 7 combustion flag
|
|
double engine8Combustion; //!< Engine 8 combustion flag
|
|
// 46
|
|
double engine1Power; //!< Engine 1 power
|
|
double engine2Power; //!< Engine 2 power
|
|
double engine3Power; //!< Engine 3 power
|
|
double engine4Power; //!< Engine 4 power
|
|
double engine5Power; //!< Engine 5 power
|
|
double engine6Power; //!< Engine 6 power
|
|
double engine7Power; //!< Engine 7 power
|
|
double engine8Power; //!< Engine 8 power
|
|
// 54
|
|
double velocityWorldX; //!< Velocity World X
|
|
double velocityWorldY; //!< Velocity World Y
|
|
double velocityWorldZ; //!< Velocity World Z
|
|
double rotationVelocityBodyX; //!< Rotation Velocity Body X
|
|
double rotationVelocityBodyY; //!< Rotation Velocity Body Y
|
|
double rotationVelocityBodyZ; //!< Rotation Velocity Body Z
|
|
// 60
|
|
double altitudeCalibratedFt; //!< Altitude without temperature effect (ft, FS2020)
|
|
// 61
|
|
};
|
|
|
|
//! Data struct of aircraft position
|
|
struct DataDefinitionOwnAircraftModel
|
|
{
|
|
char title[256]; //!< Aircraft model string
|
|
char livery[256]; //!< Aircraft livery string msfs2024
|
|
};
|
|
|
|
//! Data struct of aircraft model data
|
|
|
|
// struct DataDefinitionOwnAircraftLivery
|
|
//{
|
|
// char livery[256]; //!< Aircraft model string
|
|
// };
|
|
|
|
////! Data struct of aircraft model livery
|
|
|
|
struct DataDefinitionRemoteAircraftModel
|
|
{
|
|
double cgToGroundFt; //!< Static CG to ground (ft)
|
|
char atcType[32]; //!< type
|
|
char atcModel[32]; //!< model
|
|
char atcId[32]; //!< id
|
|
char atcAirlineNumber[64]; //!< airline number
|
|
char atcFlightNumber[8]; //!< flight number (168)
|
|
char title[256]; //!< Aircraft model string
|
|
char livery[256]; //!< Aircraft livery string msfs2024
|
|
};
|
|
|
|
//! Data struct of aircraft data (setable)
|
|
struct DataDefinitionRemoteAtc
|
|
{
|
|
// length here is from SimConnect_AddToDataDefinition
|
|
char atcId[32]; //!< ID used by ATC
|
|
char atcAirline[64]; //!< Airline used by ATC
|
|
char atcFlightNumber[8]; //!< Flight Number used by ATC
|
|
|
|
//! @{
|
|
//! Copy the strings, length from docu
|
|
void copyAtcId(const char *c)
|
|
{
|
|
strncpy_s(atcId, c, 10);
|
|
atcId[9] = 0;
|
|
}
|
|
void copyAtcAirline(const char *c)
|
|
{
|
|
strncpy_s(atcAirline, c, 50);
|
|
atcAirline[49] = 0;
|
|
}
|
|
void copyFlightNumber(const char *c)
|
|
{
|
|
strncpy_s(atcFlightNumber, c, 6);
|
|
atcFlightNumber[5] = 0;
|
|
}
|
|
//! @}
|
|
|
|
//! Set default values
|
|
void setDefaultValues()
|
|
{
|
|
std::fill(atcId, atcId + 10, static_cast<byte>(0));
|
|
std::fill(atcAirline, atcAirline + 50, static_cast<byte>(0));
|
|
std::fill(atcFlightNumber, atcFlightNumber + 6, static_cast<byte>(0));
|
|
}
|
|
};
|
|
|
|
//! Data struct of remote aircraft parts
|
|
struct MSFS2024_EXPORT DataDefinitionRemoteAircraftPartsWithoutLights
|
|
{
|
|
double flapsLeadingEdgeLeftPercent; //!< Leading edge left in percent 0..1
|
|
double flapsLeadingEdgeRightPercent; //!< Leading edge right in percent 0..1
|
|
double flapsTrailingEdgeLeftPercent; //!< Trailing edge left in percent 0..1
|
|
double flapsTrailingEdgeRightPercent; //!< Trailing edge right in percent 0..1
|
|
double gearHandlePosition; //!< Gear handle position
|
|
double spoilersHandlePosition; //!< Spoilers out?
|
|
double engine1Combustion; //!< Engine 1 combustion flag
|
|
double engine2Combustion; //!< Engine 2 combustion flag
|
|
double engine3Combustion; //!< Engine 3 combustion flag
|
|
double engine4Combustion; //!< Engine 4 combustion flag
|
|
double engine5Combustion; //!< Engine 5 combustion flag
|
|
double engine6Combustion; //!< Engine 6 combustion flag
|
|
double engine7Combustion; //!< Engine 7 combustion flag
|
|
double engine8Combustion; //!< Engine 8 combustion flag
|
|
double engine1Power; //!< Engine 1 power
|
|
double engine2Power; //!< Engine 2 power
|
|
double engine3Power; //!< Engine 3 power
|
|
double engine4Power; //!< Engine 4 power
|
|
double engine5Power; //!< Engine 5 power
|
|
double engine6Power; //!< Engine 6 power
|
|
double engine7Power; //!< Engine 7 power
|
|
double engine8Power; //!< Engine 8 power
|
|
|
|
//! Ctor
|
|
DataDefinitionRemoteAircraftPartsWithoutLights();
|
|
|
|
//! Ctor
|
|
DataDefinitionRemoteAircraftPartsWithoutLights(const swift::misc::aviation::CAircraftParts &parts);
|
|
|
|
//! Equal to other parts
|
|
bool operator==(const DataDefinitionRemoteAircraftPartsWithoutLights &rhs) const;
|
|
|
|
//! All engines on/off
|
|
void setAllEngines(bool on, double power);
|
|
|
|
//! Set given engine
|
|
void setEngine(int number1based, bool on, double power);
|
|
|
|
//! Reset all flaps
|
|
void resetAllFlaps();
|
|
|
|
//! Reset spoilers
|
|
void resetSpoilers();
|
|
|
|
//! Reset to invalid values
|
|
void resetToInvalid();
|
|
|
|
//! Init from parts
|
|
void initFromParts(const swift::misc::aviation::CAircraftParts &parts);
|
|
};
|
|
|
|
//! Data for aircraft lighs
|
|
struct MSFS2024_EXPORT DataDefinitionRemoteAircraftLights
|
|
{
|
|
double lightStrobe; //!< Is strobe light on?
|
|
double lightLanding; //!< Is landing light on?
|
|
double lightTaxi; //!< Is taxi light on?
|
|
double lightBeacon; //!< Is beacon light on?
|
|
double lightNav; //!< Is nav light on?
|
|
double lightLogo; //!< Is logo light on?
|
|
double lightRecognition; //!< Is recognition light on
|
|
double lightCabin; //!< Is cabin light on
|
|
double lightWing; //!< Is cabin light on
|
|
//! Convert to lights
|
|
swift::misc::aviation::CAircraftLights toLights() const;
|
|
};
|
|
|
|
//! Data for AI object and probe sent back from simulator
|
|
struct DataDefinitionPosData
|
|
{
|
|
double latitudeDeg; //!< Latitude (deg)
|
|
double longitudeDeg; //!< Longitude (deg)
|
|
double altitudeFt; //!< Altitude (ft)
|
|
double elevationFt; //!< Elevation (ft)
|
|
double cgToGroundFt; //!< Static CG to ground (ft)
|
|
|
|
//! Above ground ft
|
|
double aboveGroundFt() const { return altitudeFt - elevationFt; }
|
|
|
|
//! Above ground ft
|
|
bool isOnGround() const { return this->aboveGroundFt() < 1.0; }
|
|
};
|
|
|
|
//! The whole SB data area
|
|
//! \remark vPilot SB area https://forums.vatsim.net/viewtopic.php?p=519580
|
|
//! \remark SB offsets http://www.squawkbox.ca/doc/sdk/fsuipc.php
|
|
struct DataDefinitionClientAreaSb
|
|
{
|
|
byte data[128] {}; //!< 128 bytes of data, offsets
|
|
|
|
//! Standby = 1, else 0
|
|
byte getTransponderMode() const { return data[17]; }
|
|
|
|
//! Ident = 1, else 0
|
|
byte getIdent() const { return data[19]; }
|
|
|
|
//! Ident?
|
|
bool isIdent() const { return getIdent() != 0; }
|
|
|
|
//! Standby
|
|
bool isStandby() const { return getTransponderMode() != 0; }
|
|
|
|
//! SB is running
|
|
void setRunning(bool running) { data[0] = running ? 1 : 0; }
|
|
|
|
//! Mark as connected with network
|
|
void setConnected(bool connected) { data[1] = connected ? 1 : 0; }
|
|
|
|
//! Set default values
|
|
void setDefaultValues()
|
|
{
|
|
std::fill(data, data + 128, static_cast<byte>(0));
|
|
data[0] = 1; // SB running, indicates the client is running as external app, 0..not running, 1..external
|
|
// app, 2..FS module
|
|
data[1] = 0; // SB connected to FSD, 0..not connected, 1..connected
|
|
data[17] = 1; // 1..standby, 0..mode C
|
|
data[19] = 0; // no ident
|
|
}
|
|
|
|
//! Values
|
|
QString toQString() const;
|
|
};
|
|
|
|
//! Data structure for MSFS transponder mode information
|
|
struct DataDefinitionMSFSTransponderMode
|
|
{
|
|
double transponderMode = 1; //!< transponder state simvar
|
|
double ident = 0; //!< ident
|
|
};
|
|
|
|
//! Client areas
|
|
enum ClientAreaId
|
|
{
|
|
ClientAreaSquawkBox
|
|
};
|
|
|
|
//! Handles SimConnect data definitions for MSFS2024
|
|
class MSFS2024_EXPORT CSimConnectDefinitions
|
|
{
|
|
public:
|
|
//! SimConnect definiton IDs
|
|
enum DataDefiniton
|
|
{
|
|
DataOwnAircraft,
|
|
DataOwnAircraftTitle,
|
|
DataRemoteAircraftLights,
|
|
DataRemoteAircraftPartsWithoutLights,
|
|
DataRemoteAircraftSetPosition, //!< the position which will be set
|
|
DataRemoteAircraftGetPosition, //!< get position to evaluate altitude / AGL
|
|
DataRemoteAircraftModelData, //!< model data eventually used and reported back from simulator
|
|
DataRemoteAircraftSetData, //!< set model data such as airline
|
|
DataSimEnvironment,
|
|
DataTransponderModeMSFS,
|
|
DataClientAreaSb, //!< whole SB area, see http://squawkbox.ca/doc/sdk/fsuipc.php
|
|
DataClientAreaSbIdent, //!< SB ident single value 0x7b93/19
|
|
DataClientAreaSbStandby, //!< SB standby 0x7b91/17
|
|
DataClientAreaSbConnected, //!< SB connected with network 0x7b81/1
|
|
DataClientAreaSbRunning //!< SB running 0x7b80/0
|
|
};
|
|
|
|
//! SimConnect request IDs
|
|
enum Request
|
|
{
|
|
RequestOwnAircraft,
|
|
RequestOwnAircraftTitle,
|
|
RequestOwnAircraftLivery,
|
|
RequestSimEnvironment,
|
|
RequestSbData, //!< SB client area / XPDR mode
|
|
RequestMSFSTransponder, //!< MSFS XPDR mode/ident
|
|
RequestFacility,
|
|
RequestEndMarker, //!< free request ids can start here
|
|
|
|
};
|
|
|
|
//! SimObject requests used for AI aircraft and probes
|
|
enum SimObjectRequest
|
|
{
|
|
SimObjectBaseId, //!< base id without specific request
|
|
SimObjectAdd,
|
|
SimObjectRemove,
|
|
SimObjectPositionData,
|
|
SimObjectLights,
|
|
SimObjectModel,
|
|
SimObjectMisc,
|
|
SimObjectEndMarker //!< end marker, do NOT remove, also means invalid
|
|
};
|
|
|
|
enum REQUEST_ID
|
|
{
|
|
REQUEST_NONE = 0,
|
|
REQUEST_POSITION_USER = 50,
|
|
REQUEST_CREATE = 100,
|
|
REQUEST_ALL = 1000,
|
|
REQUEST_USER,
|
|
REQUEST_AIRPLANE,
|
|
REQUEST_HELICOPTER,
|
|
REQUEST_GROUND,
|
|
REQUEST_ANIMAL,
|
|
REQUEST_HOT_AIR,
|
|
REQUEST_BOAT,
|
|
};
|
|
|
|
//! Request to string
|
|
static const QString &requestToString(Request request);
|
|
|
|
//! Request to string
|
|
static const QString &simObjectRequestToString(SimObjectRequest simObjectRequest);
|
|
|
|
//! Constructor
|
|
CSimConnectDefinitions();
|
|
|
|
//! Initialize all data definitions
|
|
static HRESULT initDataDefinitionsWhenConnected(const HANDLE hSimConnect,
|
|
const swift::misc::simulation::CSimulatorInfo &simInfo);
|
|
|
|
//! Initialize data retrieval for model list
|
|
static HRESULT initOwnAircraftList(const HANDLE hSimConnect);
|
|
|
|
private:
|
|
//! Initialize data definition for our own aircraft
|
|
static HRESULT initOwnAircraft(const HANDLE hSimConnect);
|
|
|
|
//! Initialize data definition for remote aircraft
|
|
static HRESULT initRemoteAircraft(const HANDLE hSimConnect);
|
|
|
|
//! Initialize data for setting remote aircraft airline etc.
|
|
static HRESULT initRemoteAircraftSimData(const HANDLE hSimConnect);
|
|
|
|
//! Initialize data for remote aircraft queried from simulator
|
|
static HRESULT initRemoteAircraftSimDataSet(const HANDLE hSimConnect);
|
|
|
|
//! Initialize data definition for Simulator environment
|
|
static HRESULT initSimulatorEnvironment(const HANDLE hSimConnect);
|
|
|
|
//! Initialize the SB data are
|
|
static HRESULT initSbDataArea(const HANDLE hSimConnect);
|
|
|
|
//! Initialize data definition for MSFS transponder
|
|
// static HRESULT initMSFSTransponder(const HANDLE hSimConnect);
|
|
|
|
//! Initialize data definition for MSFS transponder
|
|
static HRESULT initMSFS2024Transponder(const HANDLE hSimConnect);
|
|
};
|
|
} // namespace swift::simplugin::msfs2024common
|
|
|
|
#endif // SWIFT_SIMPLUGIN_MSFS2024COMMON_SIMCONNECT_DATADEFINITION_H
|