Start on SimConnect
This commit is contained in:
parent
997586b8aa
commit
23db85c2a5
17
.vscode/c_cpp_properties.json
vendored
17
.vscode/c_cpp_properties.json
vendored
@ -32,7 +32,7 @@
|
|||||||
"intelliSenseMode": "windows-clang-x64"
|
"intelliSenseMode": "windows-clang-x64"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Windows ESP",
|
"name": "Windows ESP 32",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/**"
|
||||||
],
|
],
|
||||||
@ -45,6 +45,21 @@
|
|||||||
"cppStandard": "c++14",
|
"cppStandard": "c++14",
|
||||||
"intelliSenseMode": "windows-clang-x64"
|
"intelliSenseMode": "windows-clang-x64"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Windows ESP 64",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"defines": [
|
||||||
|
"BIT=\"64\"",
|
||||||
|
"IBM",
|
||||||
|
"MSFS"
|
||||||
|
],
|
||||||
|
"compilerPath": "/opt/llvm-mingw/bin/x86_64-w64-mingw32-clang",
|
||||||
|
"cStandard": "c11",
|
||||||
|
"cppStandard": "c++14",
|
||||||
|
"intelliSenseMode": "windows-clang-x64"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Mac",
|
"name": "Mac",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
|
|||||||
24
.vscode/settings.json
vendored
24
.vscode/settings.json
vendored
@ -64,6 +64,28 @@
|
|||||||
"cinttypes": "cpp",
|
"cinttypes": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"valarray": "cpp",
|
"valarray": "cpp",
|
||||||
"__threading_support": "cpp"
|
"__threading_support": "cpp",
|
||||||
|
"__config": "cpp",
|
||||||
|
"__undef_macros": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"__bit_reference": "cpp",
|
||||||
|
"__bits": "cpp",
|
||||||
|
"__debug": "cpp",
|
||||||
|
"__errc": "cpp",
|
||||||
|
"__hash_table": "cpp",
|
||||||
|
"__locale": "cpp",
|
||||||
|
"__mutex_base": "cpp",
|
||||||
|
"__node_handle": "cpp",
|
||||||
|
"__nullptr": "cpp",
|
||||||
|
"__split_buffer": "cpp",
|
||||||
|
"__string": "cpp",
|
||||||
|
"__tree": "cpp",
|
||||||
|
"__tuple": "cpp",
|
||||||
|
"compare": "cpp",
|
||||||
|
"concepts": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"queue": "cpp",
|
||||||
|
"stack": "cpp",
|
||||||
|
"variant": "cpp"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -14,6 +14,7 @@ set(PLUGIN_NAME GAConnector)
|
|||||||
option(DEBUG "Debug symbols" OFF)
|
option(DEBUG "Debug symbols" OFF)
|
||||||
option(XP "X-Plane" OFF)
|
option(XP "X-Plane" OFF)
|
||||||
option(BIT "Bitnes" 64)
|
option(BIT "Bitnes" 64)
|
||||||
|
option(MSFS "MSFS" OFF)
|
||||||
|
|
||||||
add_subdirectory(
|
add_subdirectory(
|
||||||
ixwebsocket
|
ixwebsocket
|
||||||
|
|||||||
13
TODO.md
13
TODO.md
@ -1,8 +1,9 @@
|
|||||||
- SimConnect DATA class
|
|
||||||
- SimDatabase
|
- SimDatabase
|
||||||
- MakeRwys (or equiv BGL lib) for 32Bit
|
- Call to MakeRwys
|
||||||
- New Facillity API for 64Bit
|
- New Facillity API for 64Bit
|
||||||
- Readback test
|
|
||||||
- Websocket dummy
|
- Recording Class
|
||||||
- Recording file dummy
|
- Bundle all threads, databse, config, websocket
|
||||||
- Logbook file dummy
|
|
||||||
|
- Websocket
|
||||||
|
- Increase sent data
|
||||||
2
build.sh
2
build.sh
@ -24,7 +24,7 @@ case $1 in
|
|||||||
\cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libunwind.dll X-Plane/GAConnector/64
|
\cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libunwind.dll X-Plane/GAConnector/64
|
||||||
;;
|
;;
|
||||||
"win64-ESP")
|
"win64-ESP")
|
||||||
cmake -DDEBUG=$DEBUG -DBIT=64 -DCMAKE_TOOLCHAIN_FILE=../toolchain-win-64.cmake ..
|
cmake -DDEBUG=$DEBUG -DBIT=64 -DMSFS=ON -DCMAKE_TOOLCHAIN_FILE=../toolchain-win-64.cmake ..
|
||||||
\cp -rf ../openSSL/win64/*.dll ESP/64/GAConnector/
|
\cp -rf ../openSSL/win64/*.dll ESP/64/GAConnector/
|
||||||
\cp -rf ../SimConnect/64/*.dll ESP/64/GAConnector/
|
\cp -rf ../SimConnect/64/*.dll ESP/64/GAConnector/
|
||||||
\cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libc++.dll ESP/64/GAConnector/
|
\cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libc++.dll ESP/64/GAConnector/
|
||||||
|
|||||||
@ -6,6 +6,7 @@ enable_language(RC)
|
|||||||
add_executable(germanairlinesva_esp WIN32
|
add_executable(germanairlinesva_esp WIN32
|
||||||
${socket}
|
${socket}
|
||||||
resources/resources-${BIT}.rc
|
resources/resources-${BIT}.rc
|
||||||
|
simconnect.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +24,11 @@ target_compile_definitions(germanairlinesva_esp PRIVATE
|
|||||||
BIT="${BIT}"
|
BIT="${BIT}"
|
||||||
IBM
|
IBM
|
||||||
)
|
)
|
||||||
|
if (MSFS)
|
||||||
|
target_compile_definitions(germanairlinesva_esp PRIVATE
|
||||||
|
MSFS
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_compile_options(germanairlinesva_esp PRIVATE
|
target_compile_options(germanairlinesva_esp PRIVATE
|
||||||
-Wall
|
-Wall
|
||||||
|
|||||||
@ -1,20 +1,34 @@
|
|||||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_ESP_MAIN_H
|
#ifndef GERMANAIRLINESVA_GACONNECTOR_ESP_MAIN_H
|
||||||
#define GERMANAIRLINESVA_GACONNECTOR_ESP_MAIN_H
|
#define GERMANAIRLINESVA_GACONNECTOR_ESP_MAIN_H
|
||||||
|
|
||||||
#include "constants.h"
|
#include <atomic>
|
||||||
|
|
||||||
#include "windows.h"
|
|
||||||
|
|
||||||
#include "SimConnect.h"
|
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
|
|
||||||
|
#include <shlobj.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include "config/config.hpp"
|
||||||
|
#include "constants.h"
|
||||||
|
#include "logbook/logbook.hpp"
|
||||||
|
#include "recording/recording.hpp"
|
||||||
|
#include "simconnect.h"
|
||||||
|
#include "simdata/simDatabase.hpp"
|
||||||
|
|
||||||
WINBOOL addNotifyIcon(HWND hWnd);
|
WINBOOL addNotifyIcon(HWND hWnd);
|
||||||
WINBOOL removeNotifyIcon(HWND hWnd);
|
WINBOOL removeNotifyIcon(HWND hWnd);
|
||||||
|
WINBOOL createMenu(HWND hWnd);
|
||||||
|
void end(HWND hwnd);
|
||||||
|
void serverWorker();
|
||||||
|
void recordingWorker();
|
||||||
void toLog(const std::string &message);
|
void toLog(const std::string &message);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
125
esp/include/simconnect.h
Normal file
125
esp/include/simconnect.h
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
#ifndef GERMANAIRLINESVA_GACONNECTOR_ESP_SIMCONNECT_H
|
||||||
|
#define GERMANAIRLINESVA_GACONNECTOR_ESP_SIMCONNECT_H
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include "SimConnect.h"
|
||||||
|
|
||||||
|
#include "config/config.hpp"
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
|
#pragma pack(push)
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
struct data {
|
||||||
|
double parkingBrake; // BRAKE PARKING INDICATOR
|
||||||
|
double onGround; // SIM ON GROUND
|
||||||
|
|
||||||
|
double emptyWeight; // EMPTY WEIGHT
|
||||||
|
double currentWeight; // TOTAL WEIGHT
|
||||||
|
|
||||||
|
double fuel; // FUEL TOTAL QUANTITY WEIGHT
|
||||||
|
|
||||||
|
double headingTrue; // PLANE HEADING DEGREES TRUE
|
||||||
|
double headingMagnetic; // PLANE HEADING DEGREES Magnetic
|
||||||
|
|
||||||
|
double groundSpeed; // GROUND VELOCITY
|
||||||
|
double indicatedAirspeed; // AIRSPEED INDICATED
|
||||||
|
double barberPoleSpeed; // AIRSPEED BARBER POLE
|
||||||
|
|
||||||
|
double verticalVelocity; // VELOCITY WORLD Y
|
||||||
|
double verticalSpeed; // VERTICAL SPEED
|
||||||
|
double altitude; // PLANE ALTITUDE
|
||||||
|
double altitudeAGL; // PLANE ALT ABOVE GROUND
|
||||||
|
|
||||||
|
double latitude; // PLANE LATITUDE
|
||||||
|
double longitude; // PLANE LONGITUDE
|
||||||
|
|
||||||
|
double elapsedTime; // ABSOLUTE TIME
|
||||||
|
|
||||||
|
double fuelFlowEng1; // ENG FUEL FLOW PPH:1
|
||||||
|
double fuelFlowEng2; // ENG FUEL FLOW PPH:2
|
||||||
|
double fuelFlowEng3; // ENG FUEL FLOW PPH:3
|
||||||
|
double fuelFlowEng4; // ENG FUEL FLOW PPH:4
|
||||||
|
|
||||||
|
int brakePos;
|
||||||
|
int brakeParkPos;
|
||||||
|
int brakeLeftPos;
|
||||||
|
|
||||||
|
double timeZulu; // ZULU TIME IN SECONDS
|
||||||
|
|
||||||
|
double gForce; // G FORCE IN G
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Port {
|
||||||
|
double headingTrue; // PLANE HEADING DEGREES TRUE
|
||||||
|
double latitude; // PLANE LATITUDE
|
||||||
|
double longitude; // PLANE LONGITUDE
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
enum DEFINITIONS {
|
||||||
|
D_DATA,
|
||||||
|
D_PORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum REQUESTS {
|
||||||
|
R_DATA,
|
||||||
|
R_ACFT,
|
||||||
|
R_DIALOG,
|
||||||
|
R_PORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum EVENTS {
|
||||||
|
E_PAUSE,
|
||||||
|
E_STATUS,
|
||||||
|
E_TEXT,
|
||||||
|
E_TIMEMIN,
|
||||||
|
E_TIMEHRS,
|
||||||
|
E_TIMESEC,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum GROUPS {
|
||||||
|
G_TIME,
|
||||||
|
};
|
||||||
|
|
||||||
|
class SimConnect
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
HANDLE simConnect;
|
||||||
|
bool connectedToSim;
|
||||||
|
char version;
|
||||||
|
std::string aircraftPath;
|
||||||
|
bool pausedMenu;
|
||||||
|
bool paused;
|
||||||
|
std::mutex mutex;
|
||||||
|
struct germanairlinesva::websocket::data simData;
|
||||||
|
std::shared_ptr<germanairlinesva::file::config::Config> configuration;
|
||||||
|
std::function<void(const std::string)> toLog;
|
||||||
|
|
||||||
|
void handleOpen(SIMCONNECT_RECV_OPEN *data);
|
||||||
|
void handleSystemEvent(SIMCONNECT_RECV_SYSTEM_STATE *state);
|
||||||
|
void handleEvent(SIMCONNECT_RECV_EVENT *event);
|
||||||
|
void handleData(SIMCONNECT_RECV_SIMOBJECT_DATA *data);
|
||||||
|
|
||||||
|
public:
|
||||||
|
SimConnect(
|
||||||
|
HWND hWnd,
|
||||||
|
std::function<void(const std::string)> toLog,
|
||||||
|
std::shared_ptr<germanairlinesva::file::config::Config> &configuration);
|
||||||
|
~SimConnect();
|
||||||
|
bool isConnected() const;
|
||||||
|
const std::string getVersion() const;
|
||||||
|
void getData(struct germanairlinesva::websocket::data *data);
|
||||||
|
void getStates() const;
|
||||||
|
void handleMessage();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
285
esp/main.cpp
285
esp/main.cpp
@ -1,6 +1,22 @@
|
|||||||
#include "include/main.h"
|
#include "include/main.h"
|
||||||
|
|
||||||
bool connectedToSim = false;
|
std::mutex mutex;
|
||||||
|
std::queue<std::function<void()>> &messageQueue()
|
||||||
|
{
|
||||||
|
static std::queue<std::function<void()>> _messageQueue;
|
||||||
|
return _messageQueue;
|
||||||
|
}
|
||||||
|
std::thread serverThread;
|
||||||
|
std::thread recordingThread;
|
||||||
|
std::atomic<bool> wantsExit;
|
||||||
|
|
||||||
|
std::shared_ptr<germanairlinesva::file::config::Config> configuration;
|
||||||
|
std::unique_ptr<germanairlinesva::file::simdata::SimDatabase> database;
|
||||||
|
std::unique_ptr<germanairlinesva::websocket::Websocket> connector;
|
||||||
|
std::unique_ptr<SimConnect> simConnect;
|
||||||
|
|
||||||
|
struct germanairlinesva::websocket::data toSend;
|
||||||
|
germanairlinesva::file::recording::Recording p;
|
||||||
|
|
||||||
// The Window Procedure
|
// The Window Procedure
|
||||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
@ -8,58 +24,34 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
static UINT s_uTaskbarRestart;
|
static UINT s_uTaskbarRestart;
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_CREATE:
|
case WM_CREATE: {
|
||||||
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
|
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case WM_CLOSE: {
|
case WM_CLOSE: {
|
||||||
toLog("Close");
|
|
||||||
DestroyWindow(hWnd);
|
DestroyWindow(hWnd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_DESTROY: {
|
case WM_DESTROY: {
|
||||||
toLog("Destroy");
|
end(hWnd);
|
||||||
removeNotifyIcon(hWnd);
|
|
||||||
UnregisterClass(WINDOW_CLASS, GetModuleHandle(NULL));
|
|
||||||
PostQuitMessage(0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TRAY_MESSAGE: {
|
case TRAY_MESSAGE: {
|
||||||
switch (lParam) {
|
switch (lParam) {
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
case WM_CONTEXTMENU: {
|
case WM_CONTEXTMENU: {
|
||||||
const int IDM_EXIT = 100;
|
createMenu(hWnd);
|
||||||
POINT pt;
|
|
||||||
GetCursorPos(&pt);
|
|
||||||
|
|
||||||
HMENU hMenu = CreatePopupMenu();
|
|
||||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, "Version: " BIT);
|
|
||||||
if (connectedToSim) {
|
|
||||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, "Connected to Sim");
|
|
||||||
}
|
|
||||||
AppendMenu(hMenu, MF_SEPARATOR, NULL, NULL);
|
|
||||||
AppendMenu(hMenu, MF_STRING, IDM_EXIT, "Exit");
|
|
||||||
|
|
||||||
SetForegroundWindow(hWnd);
|
|
||||||
|
|
||||||
WINBOOL cmd = TrackPopupMenu(hMenu,
|
|
||||||
TPM_LEFTALIGN | TPM_LEFTBUTTON |
|
|
||||||
TPM_BOTTOMALIGN | TPM_RETURNCMD,
|
|
||||||
pt.x,
|
|
||||||
pt.y,
|
|
||||||
0,
|
|
||||||
hWnd,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (cmd == IDM_EXIT) {
|
|
||||||
PostMessage(hWnd, WM_CLOSE, 0, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
DestroyMenu(hMenu);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SIMCONNECT_MESSAGE: {
|
||||||
|
if (simConnect != nullptr && simConnect->isConnected()) {
|
||||||
|
simConnect->handleMessage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
if (msg == s_uTaskbarRestart) {
|
if (msg == s_uTaskbarRestart) {
|
||||||
addNotifyIcon(hWnd);
|
addNotifyIcon(hWnd);
|
||||||
@ -77,13 +69,13 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
|||||||
LPSTR lpCmdLine,
|
LPSTR lpCmdLine,
|
||||||
int nCmdShow)
|
int nCmdShow)
|
||||||
{
|
{
|
||||||
HANDLE simConnect;
|
|
||||||
HRESULT hr;
|
|
||||||
WNDCLASS wc;
|
WNDCLASS wc;
|
||||||
ZeroMemory(&wc, sizeof(WNDCLASS));
|
ZeroMemory(&wc, sizeof(WNDCLASS));
|
||||||
HWND hWnd;
|
HWND hWnd;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
|
wantsExit.store(false);
|
||||||
|
|
||||||
// Exit if already running
|
// Exit if already running
|
||||||
hWnd = FindWindow(WINDOW_CLASS, WINDOW_CLASS);
|
hWnd = FindWindow(WINDOW_CLASS, WINDOW_CLASS);
|
||||||
if (hWnd != NULL) {
|
if (hWnd != NULL) {
|
||||||
@ -132,13 +124,99 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
|||||||
// Never show window
|
// Never show window
|
||||||
// ShowWindow(hWnd, SHOW_OPENWINDOW);
|
// ShowWindow(hWnd, SHOW_OPENWINDOW);
|
||||||
|
|
||||||
hr = SimConnect_Open(&simConnect, "GAConnector", hWnd, NULL, NULL, NULL);
|
configuration = std::make_unique<germanairlinesva::file::config::Config>();
|
||||||
if (hr == E_FAIL) {
|
toLog("Config loaded");
|
||||||
toLog("SimConnect_Open failed");
|
|
||||||
} else {
|
connector = std::make_unique<germanairlinesva::websocket::Websocket>(
|
||||||
connectedToSim = true;
|
"wss://ws.hofmannnet.myhome-server.de:8000",
|
||||||
|
configuration->getUser(),
|
||||||
|
toLog);
|
||||||
|
toLog("WebSocket started");
|
||||||
|
|
||||||
|
#ifndef MSFS
|
||||||
|
PWSTR folder;
|
||||||
|
HRESULT result = SHGetKnownFolderPath(FOLDERID_RoamingAppData,
|
||||||
|
KF_FLAG_DEFAULT,
|
||||||
|
NULL,
|
||||||
|
&folder);
|
||||||
|
if (SUCCEEDED(result)) {
|
||||||
|
size_t origsize = wcslen(folder) + 1;
|
||||||
|
size_t convertedChars = 0;
|
||||||
|
char *nstring = new char[origsize * 2];
|
||||||
|
wcstombs_s(&convertedChars, nstring, origsize * 2, folder, _TRUNCATE);
|
||||||
|
|
||||||
|
std::string path(nstring);
|
||||||
|
path.append("\\Microsoft\\FSX\\scenery.cfg");
|
||||||
|
toLog(path);
|
||||||
|
|
||||||
|
delete[] nstring;
|
||||||
|
CoTaskMemFree(folder);
|
||||||
|
|
||||||
|
char hash[2 * MD5LEN + 1] = "";
|
||||||
|
if (germanairlinesva::util::generateMD5(path.c_str(), hash, toLog) == 0) {
|
||||||
|
database = std::make_unique<germanairlinesva::file::simdata::SimDatabase>(
|
||||||
|
FSX_VERSION,
|
||||||
|
hash,
|
||||||
|
configuration,
|
||||||
|
toLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toLog("Readback test of sim database using EDDF");
|
||||||
|
auto ap = (*database)["EDDF"];
|
||||||
|
for (const auto &it : ap.first) {
|
||||||
|
toLog(" " + it.to_string());
|
||||||
|
}
|
||||||
|
for (const auto &it : ap.second) {
|
||||||
|
toLog(" " + it.to_string());
|
||||||
|
}
|
||||||
|
toLog("Readback test of sim database using XXXX");
|
||||||
|
auto ap2 = (*database)["XXXX"];
|
||||||
|
ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
toLog("Logbook Test");
|
||||||
|
germanairlinesva::file::logbook::Logbook logbook;
|
||||||
|
logbook.addEntry("08.09.2022",
|
||||||
|
"F",
|
||||||
|
"1000",
|
||||||
|
"L049",
|
||||||
|
"D-ALFA",
|
||||||
|
"John F. Kennedy International Aiport / EDDF",
|
||||||
|
"A1",
|
||||||
|
"14L",
|
||||||
|
"Gander International Airport / CYQX",
|
||||||
|
"10",
|
||||||
|
"03",
|
||||||
|
"10:00",
|
||||||
|
"10:20",
|
||||||
|
"13:20",
|
||||||
|
"13:30",
|
||||||
|
210.5,
|
||||||
|
20.1,
|
||||||
|
5012.4156,
|
||||||
|
8.87,
|
||||||
|
5041.3856,
|
||||||
|
7.1,
|
||||||
|
971.14,
|
||||||
|
2.41,
|
||||||
|
980.65,
|
||||||
|
-165.23,
|
||||||
|
1,
|
||||||
|
1.2012,
|
||||||
|
"2022-09-08_VGA1000",
|
||||||
|
5.5,
|
||||||
|
1);
|
||||||
|
logbook.toFile();
|
||||||
|
|
||||||
|
// Open SimConnect
|
||||||
|
simConnect = std::make_unique<SimConnect>(hWnd, toLog, configuration);
|
||||||
|
|
||||||
|
// Thread for sending data to websocket
|
||||||
|
serverThread = std::thread(&serverWorker);
|
||||||
|
recordingThread = std::thread(&recordingWorker);
|
||||||
|
toLog("Workers started");
|
||||||
|
|
||||||
// The Message Loop
|
// The Message Loop
|
||||||
while (GetMessage(&msg, NULL, 0, 0) > 0) {
|
while (GetMessage(&msg, NULL, 0, 0) > 0) {
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
@ -146,8 +224,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exit
|
// Exit
|
||||||
SimConnect_Close(&simConnect);
|
toLog("Connector stopped");
|
||||||
toLog("Bye");
|
|
||||||
return msg.wParam;
|
return msg.wParam;
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
@ -193,6 +270,126 @@ WINBOOL removeNotifyIcon(HWND hWnd)
|
|||||||
return Shell_NotifyIcon(NIM_DELETE, &niData);
|
return Shell_NotifyIcon(NIM_DELETE, &niData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WINBOOL createMenu(HWND hWnd)
|
||||||
|
{
|
||||||
|
const int IDM_EXIT = 100;
|
||||||
|
POINT pt;
|
||||||
|
GetCursorPos(&pt);
|
||||||
|
|
||||||
|
HMENU hMenu = CreatePopupMenu();
|
||||||
|
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, "Version: " BIT " Bit");
|
||||||
|
if (simConnect->isConnected()) {
|
||||||
|
std::string version("Connected to Sim: ");
|
||||||
|
version.append(simConnect->getVersion());
|
||||||
|
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, version.c_str());
|
||||||
|
}
|
||||||
|
AppendMenu(hMenu, MF_SEPARATOR, NULL, NULL);
|
||||||
|
AppendMenu(hMenu, MF_STRING, IDM_EXIT, "Exit");
|
||||||
|
|
||||||
|
SetForegroundWindow(hWnd);
|
||||||
|
|
||||||
|
WINBOOL cmd = TrackPopupMenu(hMenu,
|
||||||
|
TPM_LEFTALIGN | TPM_LEFTBUTTON |
|
||||||
|
TPM_BOTTOMALIGN | TPM_RETURNCMD,
|
||||||
|
pt.x,
|
||||||
|
pt.y,
|
||||||
|
0,
|
||||||
|
hWnd,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (cmd == IDM_EXIT) {
|
||||||
|
PostMessage(hWnd, WM_CLOSE, 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DestroyMenu(hMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
void end(HWND hWnd)
|
||||||
|
{
|
||||||
|
removeNotifyIcon(hWnd);
|
||||||
|
UnregisterClass(WINDOW_CLASS, GetModuleHandle(NULL));
|
||||||
|
|
||||||
|
/* End threads */
|
||||||
|
wantsExit = true;
|
||||||
|
serverThread.join();
|
||||||
|
recordingThread.join();
|
||||||
|
|
||||||
|
p.toFile("flight.rec");
|
||||||
|
|
||||||
|
// End SimConnect
|
||||||
|
delete simConnect.release();
|
||||||
|
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void serverWorker()
|
||||||
|
{
|
||||||
|
germanairlinesva::util::setThreadName("GAServerWorker");
|
||||||
|
|
||||||
|
while (!wantsExit) {
|
||||||
|
simConnect->getStates();
|
||||||
|
|
||||||
|
struct germanairlinesva::websocket::data *copy =
|
||||||
|
new germanairlinesva::websocket::data();
|
||||||
|
{
|
||||||
|
const std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
|
||||||
|
simConnect->getData(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
connector->sendData(*copy);
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||||
|
}
|
||||||
|
|
||||||
|
toLog("Server thread stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
void recordingWorker()
|
||||||
|
{
|
||||||
|
germanairlinesva::util::setThreadName("GARecordingWorker");
|
||||||
|
|
||||||
|
germanairlinesva::file::recording::RecordingEntry lastPath;
|
||||||
|
std::uint32_t segment = 0;
|
||||||
|
|
||||||
|
auto ap = (*database)["EDDF"];
|
||||||
|
auto rwys = ap.second;
|
||||||
|
|
||||||
|
while (!wantsExit) {
|
||||||
|
struct germanairlinesva::websocket::data *copy =
|
||||||
|
new germanairlinesva::websocket::data();
|
||||||
|
{
|
||||||
|
const std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
|
||||||
|
simConnect->getData(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
germanairlinesva::file::recording::RecordingEntry currentPath(
|
||||||
|
segment,
|
||||||
|
static_cast<std::uint16_t>(copy->alt),
|
||||||
|
static_cast<std::uint16_t>(copy->gs),
|
||||||
|
{copy->lat, copy->lon});
|
||||||
|
|
||||||
|
if (strcmp(copy->path, "") != 0 && !copy->pause &&
|
||||||
|
lastPath != currentPath) {
|
||||||
|
p.addEntry(currentPath);
|
||||||
|
lastPath = currentPath;
|
||||||
|
|
||||||
|
for (const auto &it : rwys) {
|
||||||
|
if (it.containsPoint({copy->lat, copy->lon})) {
|
||||||
|
toLog("On Runway: " + it.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
segment++;
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
toLog("Recording thread stopped");
|
||||||
|
}
|
||||||
|
|
||||||
void toLog(const std::string &message)
|
void toLog(const std::string &message)
|
||||||
{
|
{
|
||||||
std::time_t utc = std::time(nullptr);
|
std::time_t utc = std::time(nullptr);
|
||||||
|
|||||||
459
esp/simconnect.cpp
Normal file
459
esp/simconnect.cpp
Normal file
@ -0,0 +1,459 @@
|
|||||||
|
#include "include/simconnect.h"
|
||||||
|
|
||||||
|
SimConnect::SimConnect(
|
||||||
|
HWND hWnd,
|
||||||
|
std::function<void(const std::string)> toLog,
|
||||||
|
std::shared_ptr<germanairlinesva::file::config::Config> &configuration)
|
||||||
|
: configuration(configuration), toLog(std::move(toLog))
|
||||||
|
{
|
||||||
|
HRESULT hr = SimConnect_Open(&this->simConnect,
|
||||||
|
"GAConnector",
|
||||||
|
hWnd,
|
||||||
|
SIMCONNECT_MESSAGE,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (!SUCCEEDED(hr)) {
|
||||||
|
this->toLog("SimConnect_Open: Failed");
|
||||||
|
} else {
|
||||||
|
this->connectedToSim = true;
|
||||||
|
this->toLog("SimConnect_Close: Connection opened");
|
||||||
|
|
||||||
|
// Setup SimConnect
|
||||||
|
SimConnect_SubscribeToSystemEvent(simConnect, EVENTS::E_PAUSE, "Pause");
|
||||||
|
SimConnect_SubscribeToSystemEvent(simConnect, EVENTS::E_STATUS, "Sim");
|
||||||
|
|
||||||
|
SimConnect_MapClientEventToSimEvent(simConnect,
|
||||||
|
EVENTS::E_TIMESEC,
|
||||||
|
"CLOCK_SECONDS_ZERO");
|
||||||
|
SimConnect_AddClientEventToNotificationGroup(simConnect,
|
||||||
|
GROUPS::G_TIME,
|
||||||
|
EVENTS::E_TIMESEC,
|
||||||
|
false);
|
||||||
|
SimConnect_SetNotificationGroupPriority(simConnect,
|
||||||
|
GROUPS::G_TIME,
|
||||||
|
SIMCONNECT_GROUP_PRIORITY_HIGHEST);
|
||||||
|
SimConnect_MapClientEventToSimEvent(simConnect,
|
||||||
|
EVENTS::E_TIMEMIN,
|
||||||
|
"ZULU_MINUTES_SET");
|
||||||
|
SimConnect_AddClientEventToNotificationGroup(simConnect,
|
||||||
|
GROUPS::G_TIME,
|
||||||
|
EVENTS::E_TIMEMIN,
|
||||||
|
false);
|
||||||
|
SimConnect_SetNotificationGroupPriority(simConnect,
|
||||||
|
GROUPS::G_TIME,
|
||||||
|
SIMCONNECT_GROUP_PRIORITY_HIGHEST);
|
||||||
|
SimConnect_MapClientEventToSimEvent(simConnect,
|
||||||
|
EVENTS::E_TIMEHRS,
|
||||||
|
"ZULU_HOURS_SET");
|
||||||
|
SimConnect_AddClientEventToNotificationGroup(simConnect,
|
||||||
|
GROUPS::G_TIME,
|
||||||
|
EVENTS::E_TIMEHRS,
|
||||||
|
false);
|
||||||
|
SimConnect_SetNotificationGroupPriority(simConnect,
|
||||||
|
GROUPS::G_TIME,
|
||||||
|
SIMCONNECT_GROUP_PRIORITY_HIGHEST);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"BRAKE PARKING INDICATOR",
|
||||||
|
"BOOL",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"SIM ON GROUND",
|
||||||
|
"BOOL",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"EMPTY WEIGHT",
|
||||||
|
"KILOGRAMS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"TOTAL WEIGHT",
|
||||||
|
"KILOGRAMS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"FUEL TOTAL QUANTITY WEIGHT",
|
||||||
|
"KILOGRAMS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"PLANE HEADING DEGREES TRUE",
|
||||||
|
"DEGREES",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"PLANE HEADING DEGREES MAGNETIC",
|
||||||
|
"DEGREES",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"GROUND VELOCITY",
|
||||||
|
"KNOTS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"AIRSPEED INDICATED",
|
||||||
|
"KNOTS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"AIRSPEED BARBER POLE",
|
||||||
|
"KNOTS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"VELOCITY WORLD Y",
|
||||||
|
"FEET/MINUTE",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"VERTICAL SPEED",
|
||||||
|
"FEET/MINUTE",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"PLANE ALTITUDE",
|
||||||
|
"FEET",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"PLANE ALT ABOVE GROUND",
|
||||||
|
"FEET",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"PLANE LATITUDE",
|
||||||
|
"DEGREES",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"PLANE LONGITUDE",
|
||||||
|
"DEGREES",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"ABSOLUTE TIME",
|
||||||
|
"SECONDS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"ENG FUEL FLOW PPH:1",
|
||||||
|
"KILOGRAMS PER SECOND",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"ENG FUEL FLOW PPH:2",
|
||||||
|
"KILOGRAMS PER SECOND",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"ENG FUEL FLOW PPH:3",
|
||||||
|
"KILOGRAMS PER SECOND",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"ENG FUEL FLOW PPH:4",
|
||||||
|
"KILOGRAMS PER SECOND",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"BRAKE INDICATOR",
|
||||||
|
"POSITION",
|
||||||
|
SIMCONNECT_DATATYPE_INT32,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"BRAKE PARKING POSITION",
|
||||||
|
"POSITION",
|
||||||
|
SIMCONNECT_DATATYPE_INT32,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"BRAKE LEFT POSITION",
|
||||||
|
"POSITION",
|
||||||
|
SIMCONNECT_DATATYPE_INT32,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"ZULU TIME",
|
||||||
|
"SECONDS",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
"G FORCE",
|
||||||
|
"GForce",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_PORT,
|
||||||
|
"PLANE HEADING DEGREES TRUE",
|
||||||
|
"DEGREES",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_PORT,
|
||||||
|
"PLANE LATITUDE",
|
||||||
|
"DEGREES",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
SimConnect_AddToDataDefinition(simConnect,
|
||||||
|
DEFINITIONS::D_PORT,
|
||||||
|
"PLANE LONGITUDE",
|
||||||
|
"DEGREES",
|
||||||
|
SIMCONNECT_DATATYPE_FLOAT64,
|
||||||
|
0,
|
||||||
|
SIMCONNECT_UNUSED);
|
||||||
|
|
||||||
|
SimConnect_RequestDataOnSimObject(simConnect,
|
||||||
|
REQUESTS::R_DATA,
|
||||||
|
DEFINITIONS::D_DATA,
|
||||||
|
SIMCONNECT_OBJECT_ID_USER,
|
||||||
|
SIMCONNECT_PERIOD_SIM_FRAME,
|
||||||
|
SIMCONNECT_DATA_REQUEST_FLAG_DEFAULT,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SimConnect::~SimConnect()
|
||||||
|
{
|
||||||
|
if (this->connectedToSim) {
|
||||||
|
HRESULT hr = SimConnect_Close(this->simConnect);
|
||||||
|
if (!SUCCEEDED(hr)) {
|
||||||
|
this->toLog("SimConnect_Close: Failed");
|
||||||
|
} else {
|
||||||
|
this->connectedToSim = true;
|
||||||
|
this->toLog("SimConnect_Close: Connection closed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimConnect::getStates() const
|
||||||
|
{
|
||||||
|
SimConnect_RequestSystemState(this->simConnect,
|
||||||
|
REQUESTS::R_ACFT,
|
||||||
|
"AircraftLoaded");
|
||||||
|
SimConnect_RequestSystemState(this->simConnect, REQUESTS::R_DIALOG, "DIALOG");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SimConnect::isConnected() const { return this->connectedToSim; }
|
||||||
|
|
||||||
|
const std::string SimConnect::getVersion() const
|
||||||
|
{
|
||||||
|
switch (this->version) {
|
||||||
|
case MSFS_VERSION:
|
||||||
|
return "MSFS";
|
||||||
|
case FSX_VERSION:
|
||||||
|
return "FSX";
|
||||||
|
case P3D5_VERSION:
|
||||||
|
return "P3D5";
|
||||||
|
case P3D4_VERSION:
|
||||||
|
return "P3D4";
|
||||||
|
break;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
return "P3D3";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimConnect::getData(struct germanairlinesva::websocket::data *data)
|
||||||
|
{
|
||||||
|
const std::lock_guard<std::mutex> lock(this->mutex);
|
||||||
|
memcpy(data, &this->simData, sizeof(this->simData));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimConnect::handleMessage()
|
||||||
|
{
|
||||||
|
SIMCONNECT_RECV *pData;
|
||||||
|
DWORD cbData;
|
||||||
|
|
||||||
|
HRESULT hr = SimConnect_GetNextDispatch(this->simConnect, &pData, &cbData);
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
switch (pData->dwID) {
|
||||||
|
case SIMCONNECT_RECV_ID_OPEN: {
|
||||||
|
this->handleOpen((SIMCONNECT_RECV_OPEN *)pData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SIMCONNECT_RECV_ID_EVENT: {
|
||||||
|
this->handleEvent((SIMCONNECT_RECV_EVENT *)pData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SIMCONNECT_RECV_ID_SYSTEM_STATE: {
|
||||||
|
this->handleSystemEvent((SIMCONNECT_RECV_SYSTEM_STATE *)pData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: {
|
||||||
|
this->handleData((SIMCONNECT_RECV_SIMOBJECT_DATA *)pData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimConnect::handleOpen(SIMCONNECT_RECV_OPEN *data)
|
||||||
|
{
|
||||||
|
switch (data->dwSimConnectVersionMajor) {
|
||||||
|
case MSFS_VERSION:
|
||||||
|
this->version = MSFS_VERSION;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case FSX_VERSION:
|
||||||
|
switch (data->dwSimConnectBuildMajor) {
|
||||||
|
case FSXRTM_SUBVERSION:
|
||||||
|
case FSSXSP1_SUBVERRSION:
|
||||||
|
break;
|
||||||
|
case FSXSP2_SUBVERSION:
|
||||||
|
case FSXACC_SUBVERSION:
|
||||||
|
case FSXGOLD_SUBVERSION:
|
||||||
|
this->version = FSX_VERSION;
|
||||||
|
break;
|
||||||
|
case FSXSE_SUBVERSION:
|
||||||
|
if (configuration->getFSXSEPath().length() > 0) {
|
||||||
|
this->version = FSXSE_VERSION;
|
||||||
|
} else {
|
||||||
|
this->version = FSX_VERSION;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
this->version = P3D5_VERSION;
|
||||||
|
break;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
this->version = P3D4_VERSION;
|
||||||
|
break;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
this->version = P3D3_VERSION;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimConnect::handleSystemEvent(SIMCONNECT_RECV_SYSTEM_STATE *state)
|
||||||
|
{
|
||||||
|
switch (state->dwRequestID) {
|
||||||
|
case REQUESTS::R_ACFT:
|
||||||
|
this->aircraftPath = state->szString;
|
||||||
|
break;
|
||||||
|
case REQUESTS::R_DIALOG:
|
||||||
|
this->pausedMenu = state->dwInteger != 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimConnect::handleEvent(SIMCONNECT_RECV_EVENT *event)
|
||||||
|
{
|
||||||
|
switch (event->uEventID) {
|
||||||
|
case EVENTS::E_PAUSE:
|
||||||
|
this->paused = event->dwData != 0;
|
||||||
|
break;
|
||||||
|
case EVENTS::E_STATUS:
|
||||||
|
this->toLog("SimConnect Status " + std::to_string(event->dwData));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimConnect::handleData(SIMCONNECT_RECV_SIMOBJECT_DATA *data)
|
||||||
|
{
|
||||||
|
switch (data->dwRequestID) {
|
||||||
|
case REQUESTS::R_DATA: {
|
||||||
|
const std::lock_guard<std::mutex> lock(this->mutex);
|
||||||
|
|
||||||
|
struct data *_data = (struct data *)&data->dwData;
|
||||||
|
this->simData.pause = this->paused || this->pausedMenu;
|
||||||
|
this->simData.pBrake = _data->parkingBrake != 0 || _data->brakePos;
|
||||||
|
this->simData.onGrnd = _data->onGround != 0;
|
||||||
|
this->simData.totFuelKg = _data->fuel;
|
||||||
|
this->simData.truHdg = _data->headingTrue;
|
||||||
|
this->simData.alt = _data->altitude;
|
||||||
|
this->simData.gs = _data->groundSpeed;
|
||||||
|
this->simData.ias = _data->indicatedAirspeed;
|
||||||
|
this->simData.vs =
|
||||||
|
abs(_data->verticalVelocity - _data->verticalSpeed) > 200
|
||||||
|
? _data->verticalSpeed
|
||||||
|
: _data->verticalVelocity;
|
||||||
|
this->simData.lat = _data->latitude;
|
||||||
|
this->simData.lon = _data->longitude;
|
||||||
|
this->simData.ff[0] = _data->fuelFlowEng1;
|
||||||
|
this->simData.ff[1] = _data->fuelFlowEng2;
|
||||||
|
this->simData.ff[2] = _data->fuelFlowEng3;
|
||||||
|
this->simData.ff[3] = _data->fuelFlowEng4;
|
||||||
|
this->simData.maxSpd = _data->barberPoleSpeed;
|
||||||
|
strcpy(this->simData.path, this->aircraftPath.c_str());
|
||||||
|
this->simData.uptime = _data->elapsedTime;
|
||||||
|
this->simData.magHeading = _data->headingMagnetic;
|
||||||
|
this->simData.payloadKg =
|
||||||
|
_data->currentWeight - _data->emptyWeight - _data->fuel;
|
||||||
|
this->simData.totalWeightKg = _data->currentWeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,6 +23,12 @@ namespace file
|
|||||||
std::string user;
|
std::string user;
|
||||||
std::string scenery;
|
std::string scenery;
|
||||||
std::string token;
|
std::string token;
|
||||||
|
std::string FSXPath;
|
||||||
|
std::string FSXSEPath;
|
||||||
|
std::string P3D3Path;
|
||||||
|
std::string P3D4Path;
|
||||||
|
std::string P3D5Path;
|
||||||
|
std::string MSFSPath;
|
||||||
|
|
||||||
inline void writeFile() const
|
inline void writeFile() const
|
||||||
{
|
{
|
||||||
@ -30,6 +36,12 @@ namespace file
|
|||||||
out << "scenery=" << this->scenery << "\n";
|
out << "scenery=" << this->scenery << "\n";
|
||||||
out << "user=" << this->user << "\n";
|
out << "user=" << this->user << "\n";
|
||||||
out << "token=" << this->token << "\n";
|
out << "token=" << this->token << "\n";
|
||||||
|
out << "fsxPath=" << this->FSXPath << "\n";
|
||||||
|
out << "fsxSEPath=" << this->FSXSEPath << "\n";
|
||||||
|
out << "p3d3Path=" << this->P3D3Path << "\n";
|
||||||
|
out << "p3d4Path=" << this->P3D4Path << "\n";
|
||||||
|
out << "p3d5Path=" << this->P3D5Path << "\n";
|
||||||
|
out << "msfsPath=" << this->MSFSPath << "\n";
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +61,18 @@ namespace file
|
|||||||
this->user = fields[1];
|
this->user = fields[1];
|
||||||
} else if (fields[0] == "token") {
|
} else if (fields[0] == "token") {
|
||||||
this->token = fields[1];
|
this->token = fields[1];
|
||||||
|
} else if (fields[0] == "fsxPath") {
|
||||||
|
this->FSXPath = fields[1];
|
||||||
|
} else if (fields[0] == "fsxSEPath") {
|
||||||
|
this->FSXSEPath = fields[1];
|
||||||
|
} else if (fields[0] == "p3d3Path") {
|
||||||
|
this->P3D3Path = fields[1];
|
||||||
|
} else if (fields[0] == "p3d4Paht") {
|
||||||
|
this->P3D4Path = fields[1];
|
||||||
|
} else if (fields[0] == "p3d5Path") {
|
||||||
|
this->P3D5Path = fields[1];
|
||||||
|
} else if (fields[0] == "msfsPath") {
|
||||||
|
this->MSFSPath = fields[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,6 +89,15 @@ namespace file
|
|||||||
inline const std::string getUser() const { return this->user; }
|
inline const std::string getUser() const { return this->user; }
|
||||||
inline const std::string getScenery() const { return this->scenery; }
|
inline const std::string getScenery() const { return this->scenery; }
|
||||||
inline const std::string getToken() const { return this->token; }
|
inline const std::string getToken() const { return this->token; }
|
||||||
|
inline const std::string getFSXPath() const { return this->FSXPath; }
|
||||||
|
inline const std::string getFSXSEPath() const
|
||||||
|
{
|
||||||
|
return this->FSXSEPath;
|
||||||
|
}
|
||||||
|
inline const std::string getP3D3Path() const { return this->P3D3Path; }
|
||||||
|
inline const std::string getP3D4Path() const { return this->P3D4Path; }
|
||||||
|
inline const std::string getP3D5Path() const { return this->P3D5Path; }
|
||||||
|
inline const std::string getMSFSPath() const { return this->MSFSPath; }
|
||||||
};
|
};
|
||||||
} // namespace config
|
} // namespace config
|
||||||
} // namespace file
|
} // namespace file
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace file
|
|||||||
double trueHeading;
|
double trueHeading;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// From X-Plane or MakeRwys
|
// From X-Plane
|
||||||
inline Runway(std::string designator,
|
inline Runway(std::string designator,
|
||||||
double latitudeStart,
|
double latitudeStart,
|
||||||
double longitudeStart,
|
double longitudeStart,
|
||||||
@ -63,6 +63,21 @@ namespace file
|
|||||||
this->trueHeading,
|
this->trueHeading,
|
||||||
this->width);
|
this->width);
|
||||||
};
|
};
|
||||||
|
// From MakeRwys
|
||||||
|
inline Runway(std::string designator,
|
||||||
|
struct geodata::point start,
|
||||||
|
double width,
|
||||||
|
double length,
|
||||||
|
double trueHeading)
|
||||||
|
: designator(designator), width(width), length(length),
|
||||||
|
trueHeading(trueHeading)
|
||||||
|
{
|
||||||
|
geodata::point end =
|
||||||
|
geodata::calculatePointDD(start, trueHeading, length);
|
||||||
|
|
||||||
|
this->bounds =
|
||||||
|
geodata::calculateBoxDD(start, end, trueHeading, width);
|
||||||
|
};
|
||||||
// From database
|
// From database
|
||||||
inline Runway(std::string designator,
|
inline Runway(std::string designator,
|
||||||
struct geodata::box bounds,
|
struct geodata::box bounds,
|
||||||
|
|||||||
@ -16,7 +16,12 @@
|
|||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "simdata/gate.hpp"
|
#include "simdata/gate.hpp"
|
||||||
#include "simdata/runway.hpp"
|
#include "simdata/runway.hpp"
|
||||||
|
#ifdef XP
|
||||||
#include "simdata/simdataXP.hpp"
|
#include "simdata/simdataXP.hpp"
|
||||||
|
#endif
|
||||||
|
#ifndef MSFS
|
||||||
|
#include "simdata/simdataESP.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Header
|
* Header
|
||||||
@ -84,9 +89,11 @@ namespace file
|
|||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void fromFile()
|
inline void fromFile(const char *file)
|
||||||
{
|
{
|
||||||
std::ifstream in(BASE_DIRECTORY SIMDATABASE, std::ifstream::binary);
|
std::string path(BASE_DIRECTORY);
|
||||||
|
path.append(file);
|
||||||
|
std::ifstream in(path, std::ifstream::binary);
|
||||||
|
|
||||||
std::string ident = readString(in, 4);
|
std::string ident = readString(in, 4);
|
||||||
if (ident.compare(SIMDATABASE_HEADER) != 0) {
|
if (ident.compare(SIMDATABASE_HEADER) != 0) {
|
||||||
@ -100,37 +107,82 @@ namespace file
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline SimDatabase(int xPlaneVersion,
|
inline SimDatabase(int simVersion,
|
||||||
const char *hash,
|
const char *hash,
|
||||||
std::unique_ptr<config::Config> &configuration,
|
std::shared_ptr<config::Config> &configuration,
|
||||||
std::function<void(const std::string)> toLog)
|
std::function<void(const std::string)> toLog)
|
||||||
{
|
{
|
||||||
if (strcmp(configuration->getScenery().c_str(), hash) != 0 ||
|
if (strcmp(configuration->getScenery().c_str(), hash) != 0 ||
|
||||||
!util::fileExists(BASE_DIRECTORY SIMDATABASE)) {
|
!util::fileExists(BASE_DIRECTORY SIMDATABASE)) {
|
||||||
#ifdef XP
|
#ifdef XP
|
||||||
scan(xPlaneVersion < 12000 ? XPLANE11_BASE_SCENERY
|
scan(simVersion < 12000 ? XPLANE11_BASE_SCENERY
|
||||||
: XPLANE12_BASE_SCENERY,
|
: XPLANE12_BASE_SCENERY,
|
||||||
XPLANE_CUSTOM_SCENERY,
|
XPLANE_CUSTOM_SCENERY,
|
||||||
BASE_DIRECTORY "log.txt",
|
BASE_DIRECTORY "log.txt",
|
||||||
airports);
|
airports);
|
||||||
#else
|
|
||||||
toLog("ESP SCAN WILL BE HERE");
|
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef MSFS
|
||||||
|
scan(BASE_DIRECTORY MAKERWYS_R5,
|
||||||
|
BASE_DIRECTORY MAKERWYS_G5,
|
||||||
|
BASE_DIRECTORY "db_log.txt",
|
||||||
|
airports);
|
||||||
|
#endif
|
||||||
configuration->updateScenery(hash);
|
configuration->updateScenery(hash);
|
||||||
this->toFile();
|
#ifdef XP
|
||||||
|
this->toFile(SIMDATABASE);
|
||||||
|
#endif
|
||||||
|
#ifndef MSFS
|
||||||
|
switch (simVersion) {
|
||||||
|
case FSX_VERSION:
|
||||||
|
this->toFile(FSX_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case FSXSE_VERSION:
|
||||||
|
this->toFile(FSXSE_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
this->toFile(P3D3_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
this->toFile(P3D4_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
this->toFile(P3D5_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
toLog("Sim Database updated");
|
toLog("Sim Database updated");
|
||||||
} else {
|
} else {
|
||||||
this->fromFile();
|
#ifdef XP
|
||||||
|
this->fromFile(SIMDATABASE);
|
||||||
|
#endif
|
||||||
|
#ifndef MSFS
|
||||||
|
switch (simVersion) {
|
||||||
|
case FSX_VERSION:
|
||||||
|
this->fromFile(FSX_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case FSXSE_VERSION:
|
||||||
|
this->fromFile(FSXSE_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
this->fromFile(P3D3_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
this->fromFile(P3D4_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
this->fromFile(P3D5_PREFIX SIMDATABASE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
toLog("Sim Database loaded");
|
toLog("Sim Database loaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void toFile() const
|
inline void toFile(const char *file) const
|
||||||
{
|
{
|
||||||
std::ofstream out(BASE_DIRECTORY SIMDATABASE, std::fstream::binary);
|
std::string path(BASE_DIRECTORY);
|
||||||
|
path.append(file);
|
||||||
|
std::ofstream out(path, std::fstream::binary);
|
||||||
|
|
||||||
// File Header
|
// File Header
|
||||||
out.write(SIMDATABASE_HEADER, 4);
|
out.write(SIMDATABASE_HEADER, 4);
|
||||||
|
|||||||
141
file/include/simdata/simdataESP.hpp
Normal file
141
file/include/simdata/simdataESP.hpp
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#ifndef GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H
|
||||||
|
#define GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "geodata.hpp"
|
||||||
|
#include "simdata/gate.hpp"
|
||||||
|
#include "simdata/runway.hpp"
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
namespace germanairlinesva
|
||||||
|
{
|
||||||
|
namespace file
|
||||||
|
{
|
||||||
|
namespace simdata
|
||||||
|
{
|
||||||
|
inline int scan(
|
||||||
|
const std::string runwaysFile,
|
||||||
|
const std::string gatesFile,
|
||||||
|
const std::string logFile,
|
||||||
|
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||||
|
&airports)
|
||||||
|
{
|
||||||
|
std::ifstream runways(runwaysFile);
|
||||||
|
if (!runways.good()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::ifstream gates(gatesFile);
|
||||||
|
if (!gates.good()) {
|
||||||
|
runways.close();
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
std::ofstream log(logFile, std::fstream::trunc);
|
||||||
|
if (!log.good()) {
|
||||||
|
runways.close();
|
||||||
|
gates.close();
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
std::string *currentIcao = nullptr;
|
||||||
|
std::map<std::string, std::vector<Gate>> tmpAirportGates;
|
||||||
|
std::map<std::string, std::vector<Runway>> tmpAirportRunways;
|
||||||
|
std::vector<Gate> tmpGates;
|
||||||
|
std::vector<Runway> tmpRunways;
|
||||||
|
|
||||||
|
int apCount = 0;
|
||||||
|
int validCount = 0;
|
||||||
|
|
||||||
|
log << "<FILE> " << runwaysFile << std::endl;
|
||||||
|
|
||||||
|
while (std::getline(runways, line)) {
|
||||||
|
std::vector<std::string> fields = util::split(line, ',');
|
||||||
|
// New ICAO
|
||||||
|
if (currentIcao != nullptr && *currentIcao != fields[0]) {
|
||||||
|
tmpAirportRunways[*currentIcao] = tmpRunways;
|
||||||
|
tmpRunways = std::vector<Runway>();
|
||||||
|
apCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentIcao = new std::string(fields[0]);
|
||||||
|
|
||||||
|
int desig = std::stoi(fields[1]);
|
||||||
|
std::string designator;
|
||||||
|
switch (desig % 10) {
|
||||||
|
case 0:
|
||||||
|
designator = std::to_string(desig / 10);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
designator = std::to_string(desig / 10) + " L";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
designator = std::to_string(desig / 10) + " R";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
designator = std::to_string(desig / 10) + " C";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (desig < 100) {
|
||||||
|
designator = "0" + designator;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct geodata::point start = {std::stod(fields[2]),
|
||||||
|
std::stod(fields[3])};
|
||||||
|
tmpRunways.emplace_back(designator,
|
||||||
|
start,
|
||||||
|
geodata::toMetre(std::stod(fields[8])),
|
||||||
|
geodata::toMetre(std::stod(fields[6])),
|
||||||
|
std::stod(fields[5]) + std::stod(fields[9]));
|
||||||
|
|
||||||
|
log << "\t<RUNWAY> " << line << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentIcao = nullptr;
|
||||||
|
while (std::getline(gates, line)) {
|
||||||
|
std::vector<std::string> fields = util::split(line, ',');
|
||||||
|
// New ICAO
|
||||||
|
if (currentIcao != nullptr && *currentIcao != fields[0]) {
|
||||||
|
tmpAirportGates[*currentIcao] = tmpGates;
|
||||||
|
tmpGates = std::vector<Gate>();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentIcao = new std::string(fields[0]);
|
||||||
|
|
||||||
|
double width = std::stod(fields[5]);
|
||||||
|
tmpGates.emplace_back(fields[1] + fields[2],
|
||||||
|
std::stod(fields[3]),
|
||||||
|
std::stod(fields[4]),
|
||||||
|
width > 0 ? width : 20);
|
||||||
|
|
||||||
|
log << "\t<GATE> " << line << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &pair : tmpAirportRunways) {
|
||||||
|
std::string icao = pair.first;
|
||||||
|
|
||||||
|
if (!tmpAirportGates[icao].empty() && !pair.second.empty()) {
|
||||||
|
airports[icao] = {tmpAirportGates[icao], pair.second};
|
||||||
|
log << "\t<STATUS> " << icao << " committed" << std::endl;
|
||||||
|
validCount++;
|
||||||
|
} else {
|
||||||
|
log << "\t<STATUS> " << icao << " had no gates or runways"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log << "<STATUS> " << apCount << " airports found, of which "
|
||||||
|
<< validCount << " are valid" << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace simdata
|
||||||
|
} // namespace file
|
||||||
|
} // namespace germanairlinesva
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -60,7 +60,7 @@ namespace file
|
|||||||
gates.emplace_back(gateName,
|
gates.emplace_back(gateName,
|
||||||
std::stod(fields[1]),
|
std::stod(fields[1]),
|
||||||
std::stod(fields[2]),
|
std::stod(fields[2]),
|
||||||
40);
|
20);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void makeAirport(
|
inline void makeAirport(
|
||||||
|
|||||||
@ -8,10 +8,6 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <basetsd.h>
|
#include <basetsd.h>
|
||||||
|
|||||||
@ -6,10 +6,11 @@
|
|||||||
#else
|
#else
|
||||||
#define BASE_DIRECTORY "./"
|
#define BASE_DIRECTORY "./"
|
||||||
|
|
||||||
#define APP_ICON 100
|
#define APP_ICON 1
|
||||||
#define TRAY_ICON_ID 0xAFFE
|
#define TRAY_ICON_ID 0xAFFE
|
||||||
#define TRAY_MESSAGE 0xAFFE
|
#define TRAY_MESSAGE 0xAFFE
|
||||||
#define WINDOW_CLASS "GermanAirlinesVA_GAConnector"
|
#define WINDOW_CLASS "GermanAirlinesVA_GAConnector"
|
||||||
|
#define SIMCONNECT_MESSAGE 0xAFFF
|
||||||
|
|
||||||
#define VER_FILEVERSION 1, 0, 0, 15
|
#define VER_FILEVERSION 1, 0, 0, 15
|
||||||
#define VER_FILEVERSION_STR "1.0.0.15\0"
|
#define VER_FILEVERSION_STR "1.0.0.15\0"
|
||||||
@ -35,6 +36,9 @@
|
|||||||
#define XPLANE12_BASE_SCENERY \
|
#define XPLANE12_BASE_SCENERY \
|
||||||
"Global Scenery/Global Airports/Earth nav data/apt.dat"
|
"Global Scenery/Global Airports/Earth nav data/apt.dat"
|
||||||
|
|
||||||
|
#define MAKERWYS_R5 "r5.csv"
|
||||||
|
#define MAKERWYS_G5 "g5.csv"
|
||||||
|
|
||||||
#define RECORDING_DIRECTORY "recordings/"
|
#define RECORDING_DIRECTORY "recordings/"
|
||||||
|
|
||||||
#define CONFIG "config.cfg"
|
#define CONFIG "config.cfg"
|
||||||
@ -45,4 +49,28 @@
|
|||||||
#define RECORDING_HEADER "VGAR"
|
#define RECORDING_HEADER "VGAR"
|
||||||
#define SIMDATABASE_HEADER "VGAS"
|
#define SIMDATABASE_HEADER "VGAS"
|
||||||
|
|
||||||
|
#define FSX_PREFIX "fsx_"
|
||||||
|
#define FSXSE_PREFIX "fsxse_"
|
||||||
|
#define P3D3_PREFIX "p3d3_"
|
||||||
|
#define P3D4_PREFIX "p3d4_"
|
||||||
|
#define P3D5_PREFIX "p3d5_"
|
||||||
|
#define MSFS_PREFIX "msfs_"
|
||||||
|
|
||||||
|
#define FSX_VERSION 10
|
||||||
|
#define FSXSE_VERSION 101
|
||||||
|
#define P3D3_VERSION 3
|
||||||
|
#define P3D4_VERSION 4
|
||||||
|
#define P3D5_VERSION 5
|
||||||
|
#define MSFS_VERSION 11
|
||||||
|
|
||||||
|
// Not supported
|
||||||
|
#define FSXRTM_SUBVERSION 60905
|
||||||
|
#define FSSXSP1_SUBVERRSION 61242
|
||||||
|
// Supported
|
||||||
|
#define FSXSP2_SUBVERSION 61259
|
||||||
|
#define FSXACC_SUBVERSION 61472
|
||||||
|
#define FSXGOLD_SUBVERSION 61637
|
||||||
|
// Must be differentiated due to SxS Install
|
||||||
|
#define FSXSE_SUBVERSION 62615
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1,12 +1,7 @@
|
|||||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_GEODATA_H
|
#ifndef GERMANAIRLINESVA_GACONNECTOR_GEODATA_H
|
||||||
#define GERMANAIRLINESVA_GACONNECTOR_GEODATA_H
|
#define GERMANAIRLINESVA_GACONNECTOR_GEODATA_H
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES
|
#define M_PI 3.14159265358979323846
|
||||||
|
|
||||||
#ifdef IBM
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
#define MD5LEN 16
|
#define MD5LEN 16
|
||||||
#define EARTH_M 6371000
|
#define EARTH_M 6371000
|
||||||
@ -35,6 +30,8 @@ namespace geodata
|
|||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
static inline double toMetre(double value) { return value * 0.3048; }
|
||||||
|
|
||||||
static inline double toFeet(double value) { return value * 3.280839895; }
|
static inline double toFeet(double value) { return value * 3.280839895; }
|
||||||
|
|
||||||
static inline double toDegrees(double value) { return value * 180 / M_PI; }
|
static inline double toDegrees(double value) { return value * 180 / M_PI; }
|
||||||
@ -240,6 +237,7 @@ namespace geodata
|
|||||||
|
|
||||||
return {primaryTop, secondaryTop, secondaryBottom, primaryBottom};
|
return {primaryTop, secondaryTop, secondaryBottom, primaryBottom};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace geodata
|
} // namespace geodata
|
||||||
} // namespace germanairlinesva
|
} // namespace germanairlinesva
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_UTIL_H
|
#ifndef GERMANAIRLINESVA_GACONNECTOR_UTIL_H
|
||||||
#define GERMANAIRLINESVA_GACONNECTOR_UTIL_H
|
#define GERMANAIRLINESVA_GACONNECTOR_UTIL_H
|
||||||
|
|
||||||
#ifdef IBM
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
#define MD5LEN 16
|
#define MD5LEN 16
|
||||||
#define EARTH_M 6371000
|
#define EARTH_M 6371000
|
||||||
@ -38,7 +34,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace germanairlinesva
|
namespace germanairlinesva
|
||||||
{
|
{
|
||||||
namespace util
|
namespace util
|
||||||
|
|||||||
@ -30,7 +30,7 @@ namespace websocket
|
|||||||
ix::WebSocket *webSocket = nullptr;
|
ix::WebSocket *webSocket = nullptr;
|
||||||
std::string host;
|
std::string host;
|
||||||
std::string user;
|
std::string user;
|
||||||
std::function<void(std::string)> toLog;
|
std::function<void(const std::string)> toLog;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Websocket(std::string host,
|
Websocket(std::string host,
|
||||||
|
|||||||
@ -1,21 +1,5 @@
|
|||||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
#ifndef GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
||||||
#define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
#define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
||||||
|
|
||||||
#include "config/config.hpp"
|
|
||||||
#include "constants.h"
|
|
||||||
#include "logbook/logbook.hpp"
|
|
||||||
#include "recording/recording.hpp"
|
|
||||||
#include "simdata/simDatabase.hpp"
|
|
||||||
#include "util.hpp"
|
|
||||||
#include "websocket.h"
|
|
||||||
|
|
||||||
#include "XPLM/XPLMDataAccess.h"
|
|
||||||
#include "XPLM/XPLMGraphics.h"
|
|
||||||
#include "XPLM/XPLMPlanes.h"
|
|
||||||
#include "XPLM/XPLMPlugin.h"
|
|
||||||
#include "XPLM/XPLMProcessing.h"
|
|
||||||
#include "XPLM/XPLMUtilities.h"
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -27,6 +11,22 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include "websocket.h"
|
||||||
|
|
||||||
|
#include "config/config.hpp"
|
||||||
|
#include "constants.h"
|
||||||
|
#include "logbook/logbook.hpp"
|
||||||
|
#include "recording/recording.hpp"
|
||||||
|
#include "simdata/simDatabase.hpp"
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
#include "XPLM/XPLMDataAccess.h"
|
||||||
|
#include "XPLM/XPLMGraphics.h"
|
||||||
|
#include "XPLM/XPLMPlanes.h"
|
||||||
|
#include "XPLM/XPLMPlugin.h"
|
||||||
|
#include "XPLM/XPLMProcessing.h"
|
||||||
|
#include "XPLM/XPLMUtilities.h"
|
||||||
|
|
||||||
float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon);
|
float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon);
|
||||||
void serverWorker();
|
void serverWorker();
|
||||||
void recordingWorker();
|
void recordingWorker();
|
||||||
|
|||||||
@ -10,7 +10,7 @@ std::thread serverThread;
|
|||||||
std::thread recordingThread;
|
std::thread recordingThread;
|
||||||
std::atomic<bool> wantsExit;
|
std::atomic<bool> wantsExit;
|
||||||
|
|
||||||
std::unique_ptr<germanairlinesva::file::config::Config> configuration;
|
std::shared_ptr<germanairlinesva::file::config::Config> configuration;
|
||||||
std::unique_ptr<germanairlinesva::file::simdata::SimDatabase> database;
|
std::unique_ptr<germanairlinesva::file::simdata::SimDatabase> database;
|
||||||
std::unique_ptr<germanairlinesva::websocket::Websocket> connector;
|
std::unique_ptr<germanairlinesva::websocket::Websocket> connector;
|
||||||
int xplaneVersion;
|
int xplaneVersion;
|
||||||
@ -142,7 +142,6 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
|||||||
auto ap2 = (*database)["XXXX"];
|
auto ap2 = (*database)["XXXX"];
|
||||||
ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR");
|
ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR");
|
||||||
|
|
||||||
|
|
||||||
// Thread for sending data to websocket
|
// Thread for sending data to websocket
|
||||||
serverThread = std::thread(&serverWorker);
|
serverThread = std::thread(&serverWorker);
|
||||||
recordingThread = std::thread(&recordingWorker);
|
recordingThread = std::thread(&recordingWorker);
|
||||||
@ -194,10 +193,6 @@ PLUGIN_API void XPluginStop(void)
|
|||||||
serverThread.join();
|
serverThread.join();
|
||||||
recordingThread.join();
|
recordingThread.join();
|
||||||
|
|
||||||
delete connector.release();
|
|
||||||
delete database.release();
|
|
||||||
delete configuration.release();
|
|
||||||
|
|
||||||
p.toFile("flight.rec");
|
p.toFile("flight.rec");
|
||||||
|
|
||||||
toLog("Plugin stopped");
|
toLog("Plugin stopped");
|
||||||
@ -288,7 +283,7 @@ void recordingWorker()
|
|||||||
auto rwys = ap.second;
|
auto rwys = ap.second;
|
||||||
|
|
||||||
while (!wantsExit) {
|
while (!wantsExit) {
|
||||||
germanairlinesva::websocket::data copy;
|
struct germanairlinesva::websocket::data copy;
|
||||||
{
|
{
|
||||||
const std::lock_guard<std::mutex> lock(mutex);
|
const std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user