mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 11:05:44 +08:00
refs #873, value object light to light states
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1d967b08e8
commit
3090413849
@@ -40,7 +40,6 @@ namespace BlackMisc
|
|||||||
IndexLogo
|
IndexLogo
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//! Default constructor
|
//! Default constructor
|
||||||
CAircraftLights() = default;
|
CAircraftLights() = default;
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Weather;
|
using namespace BlackMisc::Weather;
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CSimConnectUtilities::writeSimConnectCfg(const QString &fileName, const QString &ip, int port)
|
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);
|
QFile file(fileName);
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if ((success = file.open(QIODevice::WriteOnly | QIODevice::Text)))
|
if ((success = file.open(QIODevice::WriteOnly | QIODevice::Text)))
|
||||||
@@ -50,7 +51,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString CSimConnectUtilities::simConnectCfg(const QString &ip, int port)
|
QString CSimConnectUtilities::simConnectCfg(const QString &ip, int port)
|
||||||
{
|
{
|
||||||
QString sc = QString("[SimConnect]\nProtocol=Ipv4\nAddress=%1\nPort=%2\n"
|
const QString sc = QString("[SimConnect]\nProtocol=Ipv4\nAddress=%1\nPort=%2\n"
|
||||||
"MaxReceiveSize=4096\nDisableNagle=0").arg(ip).arg(port);
|
"MaxReceiveSize=4096\nDisableNagle=0").arg(ip).arg(port);
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
@@ -75,6 +76,18 @@ namespace BlackMisc
|
|||||||
return beautify ? sf.replace('_', ' ') : sf;
|
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)
|
QString CSimConnectUtilities::convertToSimConnectMetar(const CGridPoint &gridPoint)
|
||||||
{
|
{
|
||||||
// STATION ID
|
// STATION ID
|
||||||
@@ -114,7 +127,7 @@ namespace BlackMisc
|
|||||||
// Q = specifier for altimeter in millibars
|
// Q = specifier for altimeter in millibars
|
||||||
simconnectMetar += QLatin1String(" Q");
|
simconnectMetar += QLatin1String(" Q");
|
||||||
// NNNN = altimeter in millibars
|
// 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'));
|
simconnectMetar += QStringLiteral("%1").arg(altimeter, 4, 10, QLatin1Char('0'));
|
||||||
|
|
||||||
return simconnectMetar;
|
return simconnectMetar;
|
||||||
@@ -126,7 +139,7 @@ namespace BlackMisc
|
|||||||
qRegisterMetaType<CSimConnectUtilities::SIMCONNECT_SURFACE>();
|
qRegisterMetaType<CSimConnectUtilities::SIMCONNECT_SURFACE>();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CSimConnectUtilities::windsToSimConnectMetar(const BlackMisc::Weather::CWindLayerList &windLayers)
|
QString CSimConnectUtilities::windsToSimConnectMetar(const CWindLayerList &windLayers)
|
||||||
{
|
{
|
||||||
QString simconnectWinds;
|
QString simconnectWinds;
|
||||||
bool surface = true;
|
bool surface = true;
|
||||||
@@ -145,15 +158,15 @@ namespace BlackMisc
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// DDD = Direction (0-360 degrees)
|
// 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'));
|
simconnectWinds += QStringLiteral("%1").arg(direction, 3, 10, QLatin1Char('0'));
|
||||||
|
|
||||||
// SSS = Speed
|
// 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'));
|
simconnectWinds += QStringLiteral("%1").arg(speed, 3, 10, QLatin1Char('0'));
|
||||||
}
|
}
|
||||||
// XX = Gust speed
|
// 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')); }
|
if (gustSpeed) { simconnectWinds += QStringLiteral("G%1").arg(gustSpeed, 2, 10, QLatin1Char('0')); }
|
||||||
|
|
||||||
// UUU = Speed units
|
// UUU = Speed units
|
||||||
@@ -189,7 +202,7 @@ namespace BlackMisc
|
|||||||
return simconnectWinds;
|
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:
|
// There are several format options, we use the meter format:
|
||||||
// NNNND&BXXXX&DYYYY
|
// NNNND&BXXXX&DYYYY
|
||||||
@@ -208,17 +221,17 @@ namespace BlackMisc
|
|||||||
simconnectVisibilities += QLatin1String("NDV");
|
simconnectVisibilities += QLatin1String("NDV");
|
||||||
|
|
||||||
// XXXX = base of visibility layer in meters
|
// 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'));
|
simconnectVisibilities += QStringLiteral("&B%1").arg(base, 4, 10, QLatin1Char('0'));
|
||||||
|
|
||||||
// YYYY = depth of visibility layer in meters
|
// 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'));
|
simconnectVisibilities += QStringLiteral("&D%1").arg(depth, 4, 10, QLatin1Char('0'));
|
||||||
}
|
}
|
||||||
return simconnectVisibilities;
|
return simconnectVisibilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CSimConnectUtilities::cloudsToSimConnectMetar(const BlackMisc::Weather::CCloudLayerList &cloudLayers)
|
QString CSimConnectUtilities::cloudsToSimConnectMetar(const CCloudLayerList &cloudLayers)
|
||||||
{
|
{
|
||||||
// Format:
|
// Format:
|
||||||
// CCCNNN&BXXXX&DYYYY
|
// CCCNNN&BXXXX&DYYYY
|
||||||
@@ -302,7 +315,7 @@ namespace BlackMisc
|
|||||||
return simconnectClouds;
|
return simconnectClouds;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CSimConnectUtilities::temperaturesToSimConnectMetar(const BlackMisc::Weather::CTemperatureLayerList &temperatureLayers)
|
QString CSimConnectUtilities::temperaturesToSimConnectMetar(const CTemperatureLayerList &temperatureLayers)
|
||||||
{
|
{
|
||||||
// Format:
|
// Format:
|
||||||
// TT/DD&ANNNNN
|
// TT/DD&ANNNNN
|
||||||
@@ -326,7 +339,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
return simconnectTemperatures;
|
return simconnectTemperatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#define BLACKMISC_SIMULATION_FSX_SIMCONNECTUTILITIES_H
|
#define BLACKMISC_SIMULATION_FSX_SIMCONNECTUTILITIES_H
|
||||||
|
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
|
#include "blackmisc/aviation/aircraftlights.h"
|
||||||
#include "blackmisc/weather/gridpoint.h"
|
#include "blackmisc/weather/gridpoint.h"
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
@@ -73,7 +74,7 @@ namespace BlackMisc
|
|||||||
static const QString simConnectSurfaceTypeToString(const DWORD type, bool beautify = true);
|
static const QString simConnectSurfaceTypeToString(const DWORD type, bool beautify = true);
|
||||||
|
|
||||||
//! SimConnect surfaces.
|
//! 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
|
enum SIMCONNECT_SURFACE
|
||||||
{
|
{
|
||||||
Concrete,
|
Concrete,
|
||||||
@@ -146,6 +147,25 @@ namespace BlackMisc
|
|||||||
SIMCONNECT_EXCEPTION_OBJECT_SCHEDULE
|
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
|
//! Converts the weather at gridPoint to a SimConnect METAR string
|
||||||
static QString convertToSimConnectMetar(const BlackMisc::Weather::CGridPoint &gridPoint);
|
static QString convertToSimConnectMetar(const BlackMisc::Weather::CGridPoint &gridPoint);
|
||||||
|
|
||||||
@@ -167,7 +187,6 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Hidden constructor
|
//! Hidden constructor
|
||||||
CSimConnectUtilities();
|
CSimConnectUtilities();
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user