mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #873, value object light to light states
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1d967b08e8
commit
3090413849
@@ -18,6 +18,7 @@
|
||||
#include <QMetaObject>
|
||||
#include <QTextStream>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Weather;
|
||||
|
||||
@@ -36,7 +37,7 @@ namespace BlackMisc
|
||||
|
||||
bool CSimConnectUtilities::writeSimConnectCfg(const QString &fileName, const QString &ip, int port)
|
||||
{
|
||||
QString sc = CSimConnectUtilities::simConnectCfg(ip, port);
|
||||
const QString sc = CSimConnectUtilities::simConnectCfg(ip, port);
|
||||
QFile file(fileName);
|
||||
bool success = false;
|
||||
if ((success = file.open(QIODevice::WriteOnly | QIODevice::Text)))
|
||||
@@ -50,8 +51,8 @@ namespace BlackMisc
|
||||
|
||||
QString CSimConnectUtilities::simConnectCfg(const QString &ip, int port)
|
||||
{
|
||||
QString sc = QString("[SimConnect]\nProtocol=Ipv4\nAddress=%1\nPort=%2\n"
|
||||
"MaxReceiveSize=4096\nDisableNagle=0").arg(ip).arg(port);
|
||||
const QString sc = QString("[SimConnect]\nProtocol=Ipv4\nAddress=%1\nPort=%2\n"
|
||||
"MaxReceiveSize=4096\nDisableNagle=0").arg(ip).arg(port);
|
||||
return sc;
|
||||
}
|
||||
|
||||
@@ -75,6 +76,18 @@ namespace BlackMisc
|
||||
return beautify ? sf.replace('_', ' ') : sf;
|
||||
}
|
||||
|
||||
int CSimConnectUtilities::lightsToLightStates(const CAircraftLights &lights)
|
||||
{
|
||||
int lightMask = 0;
|
||||
if (lights.isBeaconOn()) { lightMask |= Beacon; }
|
||||
if (lights.isLandingOn()) { lightMask |= Landing; }
|
||||
if (lights.isLogoOn()) { lightMask |= Logo; }
|
||||
if (lights.isNavOn()) { lightMask |= Nav; }
|
||||
if (lights.isStrobeOn()) { lightMask |= Strobe; }
|
||||
if (lights.isTaxiOn()) { lightMask |= Taxi; }
|
||||
return lightMask;
|
||||
}
|
||||
|
||||
QString CSimConnectUtilities::convertToSimConnectMetar(const CGridPoint &gridPoint)
|
||||
{
|
||||
// STATION ID
|
||||
@@ -114,7 +127,7 @@ namespace BlackMisc
|
||||
// Q = specifier for altimeter in millibars
|
||||
simconnectMetar += QLatin1String(" Q");
|
||||
// NNNN = altimeter in millibars
|
||||
auto altimeter = gridPoint.getSurfacePressure().valueInteger(CPressureUnit::mbar());
|
||||
const auto altimeter = gridPoint.getSurfacePressure().valueInteger(CPressureUnit::mbar());
|
||||
simconnectMetar += QStringLiteral("%1").arg(altimeter, 4, 10, QLatin1Char('0'));
|
||||
|
||||
return simconnectMetar;
|
||||
@@ -126,7 +139,7 @@ namespace BlackMisc
|
||||
qRegisterMetaType<CSimConnectUtilities::SIMCONNECT_SURFACE>();
|
||||
}
|
||||
|
||||
QString CSimConnectUtilities::windsToSimConnectMetar(const BlackMisc::Weather::CWindLayerList &windLayers)
|
||||
QString CSimConnectUtilities::windsToSimConnectMetar(const CWindLayerList &windLayers)
|
||||
{
|
||||
QString simconnectWinds;
|
||||
bool surface = true;
|
||||
@@ -145,15 +158,15 @@ namespace BlackMisc
|
||||
else
|
||||
{
|
||||
// DDD = Direction (0-360 degrees)
|
||||
auto direction = windLayer.getDirection().valueInteger(CAngleUnit::deg());
|
||||
const auto direction = windLayer.getDirection().valueInteger(CAngleUnit::deg());
|
||||
simconnectWinds += QStringLiteral("%1").arg(direction, 3, 10, QLatin1Char('0'));
|
||||
|
||||
// SSS = Speed
|
||||
auto speed = windLayer.getSpeed().valueInteger(CSpeedUnit::kts());
|
||||
const auto speed = windLayer.getSpeed().valueInteger(CSpeedUnit::kts());
|
||||
simconnectWinds += QStringLiteral("%1").arg(speed, 3, 10, QLatin1Char('0'));
|
||||
}
|
||||
// XX = Gust speed
|
||||
auto gustSpeed = windLayer.getGustSpeed().valueInteger(CSpeedUnit::kts());
|
||||
const auto gustSpeed = windLayer.getGustSpeed().valueInteger(CSpeedUnit::kts());
|
||||
if (gustSpeed) { simconnectWinds += QStringLiteral("G%1").arg(gustSpeed, 2, 10, QLatin1Char('0')); }
|
||||
|
||||
// UUU = Speed units
|
||||
@@ -189,7 +202,7 @@ namespace BlackMisc
|
||||
return simconnectWinds;
|
||||
}
|
||||
|
||||
QString CSimConnectUtilities::visibilitiesToSimConnectMetar(const BlackMisc::Weather::CVisibilityLayerList &visibilityLayers)
|
||||
QString CSimConnectUtilities::visibilitiesToSimConnectMetar(const CVisibilityLayerList &visibilityLayers)
|
||||
{
|
||||
// There are several format options, we use the meter format:
|
||||
// NNNND&BXXXX&DYYYY
|
||||
@@ -208,17 +221,17 @@ namespace BlackMisc
|
||||
simconnectVisibilities += QLatin1String("NDV");
|
||||
|
||||
// XXXX = base of visibility layer in meters
|
||||
auto base = visibilityLayer.getBase().valueInteger(CLengthUnit::m());
|
||||
const auto base = visibilityLayer.getBase().valueInteger(CLengthUnit::m());
|
||||
simconnectVisibilities += QStringLiteral("&B%1").arg(base, 4, 10, QLatin1Char('0'));
|
||||
|
||||
// YYYY = depth of visibility layer in meters
|
||||
auto depth = visibilityLayer.getTop().valueInteger(CLengthUnit::m());
|
||||
const auto depth = visibilityLayer.getTop().valueInteger(CLengthUnit::m());
|
||||
simconnectVisibilities += QStringLiteral("&D%1").arg(depth, 4, 10, QLatin1Char('0'));
|
||||
}
|
||||
return simconnectVisibilities;
|
||||
}
|
||||
|
||||
QString CSimConnectUtilities::cloudsToSimConnectMetar(const BlackMisc::Weather::CCloudLayerList &cloudLayers)
|
||||
QString CSimConnectUtilities::cloudsToSimConnectMetar(const CCloudLayerList &cloudLayers)
|
||||
{
|
||||
// Format:
|
||||
// CCCNNN&BXXXX&DYYYY
|
||||
@@ -273,15 +286,15 @@ namespace BlackMisc
|
||||
// http://wiki.sandaysoft.com/a/Rain_measurement#Rain_Rate
|
||||
auto precipitationRate = cloudLayer.getPrecipitationRate();
|
||||
// Very light rain: precipitation rate is < 0.25 mm/hour
|
||||
if(precipitationRate < 0.25) { simconnectClouds += QLatin1Char('V'); }
|
||||
if (precipitationRate < 0.25) { simconnectClouds += QLatin1Char('V'); }
|
||||
// Light rain: precipitation rate is between 0.25mm/hour and 1.0mm/hour
|
||||
else if(precipitationRate >= 0.25 && precipitationRate < 1.0) { simconnectClouds += QLatin1Char('L'); }
|
||||
else if (precipitationRate >= 0.25 && precipitationRate < 1.0) { simconnectClouds += QLatin1Char('L'); }
|
||||
// Moderate rain: precipitation rate is between 1.0 mm/hour and 4.0 mm/hour
|
||||
else if(precipitationRate >= 1.0 && precipitationRate < 4.0) { simconnectClouds += QLatin1Char('M'); }
|
||||
else if (precipitationRate >= 1.0 && precipitationRate < 4.0) { simconnectClouds += QLatin1Char('M'); }
|
||||
// Heavy rain: recipitation rate is between 4.0 mm/hour and 16.0 mm/hour
|
||||
else if(precipitationRate >= 4.0 && precipitationRate < 16.0) { simconnectClouds += QLatin1Char('H'); }
|
||||
else if (precipitationRate >= 4.0 && precipitationRate < 16.0) { simconnectClouds += QLatin1Char('H'); }
|
||||
// Very heavy rain: precipitation rate is > 16.0 mm/hour
|
||||
else if(precipitationRate >= 16.0) { simconnectClouds += QLatin1Char('D'); }
|
||||
else if (precipitationRate >= 16.0) { simconnectClouds += QLatin1Char('D'); }
|
||||
|
||||
// Q = Type of precipitation
|
||||
switch (cloudLayer.getPrecipitation())
|
||||
@@ -302,7 +315,7 @@ namespace BlackMisc
|
||||
return simconnectClouds;
|
||||
}
|
||||
|
||||
QString CSimConnectUtilities::temperaturesToSimConnectMetar(const BlackMisc::Weather::CTemperatureLayerList &temperatureLayers)
|
||||
QString CSimConnectUtilities::temperaturesToSimConnectMetar(const CTemperatureLayerList &temperatureLayers)
|
||||
{
|
||||
// Format:
|
||||
// TT/DD&ANNNNN
|
||||
@@ -326,7 +339,6 @@ namespace BlackMisc
|
||||
}
|
||||
return simconnectTemperatures;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKMISC_SIMULATION_FSX_SIMCONNECTUTILITIES_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/aviation/aircraftlights.h"
|
||||
#include "blackmisc/weather/gridpoint.h"
|
||||
|
||||
#include <QMetaType>
|
||||
@@ -23,10 +24,10 @@
|
||||
// though it does not make sense to be used on non WIN machines.
|
||||
// But it allows such parts to compile on all platforms.
|
||||
#ifdef Q_OS_WIN
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
# include <Windows.h>
|
||||
#else
|
||||
using DWORD = unsigned long; //!< Fake Windows DWORD
|
||||
#endif
|
||||
@@ -73,7 +74,7 @@ namespace BlackMisc
|
||||
static const QString simConnectSurfaceTypeToString(const DWORD type, bool beautify = true);
|
||||
|
||||
//! SimConnect surfaces.
|
||||
// http://msdn.microsoft.com/en-us/library/cc526981.aspx#AircraftFlightInstrumentationData
|
||||
//! \sa http://msdn.microsoft.com/en-us/library/cc526981.aspx#AircraftFlightInstrumentationData
|
||||
enum SIMCONNECT_SURFACE
|
||||
{
|
||||
Concrete,
|
||||
@@ -146,6 +147,25 @@ namespace BlackMisc
|
||||
SIMCONNECT_EXCEPTION_OBJECT_SCHEDULE
|
||||
};
|
||||
|
||||
//! Lights for FSX/P3D "LIGHT ON STATES"
|
||||
//! \sa http://www.prepar3d.com/SDKv2/LearningCenter/utilities/variables/simulation_variables.html
|
||||
enum LIGHT_STATES
|
||||
{
|
||||
Nav = 0x0001,
|
||||
Beacon = 0x0002,
|
||||
Landing = 0x0004,
|
||||
Taxi = 0x0008,
|
||||
Strobe = 0x0010,
|
||||
Panel = 0x0020,
|
||||
Recognition = 0x0040,
|
||||
Wing = 0x0080,
|
||||
Logo = 0x0100,
|
||||
Cabin = 0x0200
|
||||
};
|
||||
|
||||
//! Lights to states
|
||||
static int lightsToLightStates(const BlackMisc::Aviation::CAircraftLights &lights);
|
||||
|
||||
//! Converts the weather at gridPoint to a SimConnect METAR string
|
||||
static QString convertToSimConnectMetar(const BlackMisc::Weather::CGridPoint &gridPoint);
|
||||
|
||||
@@ -167,7 +187,6 @@ namespace BlackMisc
|
||||
|
||||
//! Hidden constructor
|
||||
CSimConnectUtilities();
|
||||
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user