Convert ESP to Recorder
This commit is contained in:
parent
0a150391b8
commit
3a9db68e74
@ -1,17 +1,21 @@
|
|||||||
file(GLOB socket CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/websocket/*.cpp)
|
file(GLOB socket CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/websocket/*.cpp)
|
||||||
|
file(GLOB recorder CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/recorder/*.cpp)
|
||||||
|
|
||||||
enable_language(RC)
|
enable_language(RC)
|
||||||
|
|
||||||
# Add WIN32 to hide console window
|
# Add WIN32 to hide console window
|
||||||
add_executable(germanairlinesva_esp WIN32
|
add_executable(germanairlinesva_esp WIN32
|
||||||
${socket}
|
${socket}
|
||||||
|
${recorder}
|
||||||
resources/resources-${BIT}.rc
|
resources/resources-${BIT}.rc
|
||||||
simconnect.cpp
|
simconnect.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(germanairlinesva_esp PRIVATE
|
target_include_directories(germanairlinesva_esp PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/esp/include
|
||||||
${CMAKE_SOURCE_DIR}/file/include
|
${CMAKE_SOURCE_DIR}/file/include
|
||||||
|
${CMAKE_SOURCE_DIR}/recorder/include
|
||||||
${CMAKE_SOURCE_DIR}/simdata/include
|
${CMAKE_SOURCE_DIR}/simdata/include
|
||||||
${CMAKE_SOURCE_DIR}/websocket/include
|
${CMAKE_SOURCE_DIR}/websocket/include
|
||||||
${CMAKE_SOURCE_DIR}/utilities/include
|
${CMAKE_SOURCE_DIR}/utilities/include
|
||||||
|
|||||||
@ -113,13 +113,17 @@ class SimConnect
|
|||||||
SimConnect(
|
SimConnect(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
std::function<void(const std::string)> toLog,
|
std::function<void(const std::string)> toLog,
|
||||||
std::shared_ptr<germanairlinesva::file::config::Config> &configuration);
|
std::shared_ptr<germanairlinesva::file::config::Config> configuration);
|
||||||
~SimConnect();
|
~SimConnect();
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
const std::string getVersion() const;
|
char getVersion() const;
|
||||||
void getData(struct germanairlinesva::gaconnector::websocket::data *data);
|
void getData(struct germanairlinesva::gaconnector::websocket::data *data);
|
||||||
void getStates() const;
|
void getStates() const;
|
||||||
void handleMessage();
|
void handleMessage(std::function<void(int)> callbackOpen,
|
||||||
|
std::function<void()> callbackData);
|
||||||
|
|
||||||
|
static const std::string resolveVersion(char version);
|
||||||
|
static const std::string resolveScenery(char version);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -10,25 +10,19 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
#include "websocket.h"
|
#include "websocket.h"
|
||||||
|
|
||||||
#include <shlobj.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include "_simconnect.h"
|
#include "_simconnect.h"
|
||||||
#include "config/config.hpp"
|
#include "recorder.h"
|
||||||
#include "constants.h"
|
|
||||||
#include "logbook/logbook.hpp"
|
|
||||||
#include "recording/recording.hpp"
|
|
||||||
#include "simdata/simDatabase.hpp"
|
|
||||||
|
|
||||||
WINBOOL addNotifyIcon(HWND hWnd);
|
WINBOOL addNotifyIcon(HWND hWnd);
|
||||||
WINBOOL removeNotifyIcon(HWND hWnd);
|
WINBOOL removeNotifyIcon(HWND hWnd);
|
||||||
WINBOOL createMenu(HWND hWnd);
|
WINBOOL createMenu(HWND hWnd);
|
||||||
void end(HWND hwnd);
|
void end(HWND hwnd);
|
||||||
void serverWorker();
|
|
||||||
void recordingWorker();
|
|
||||||
void toLog(const std::string &message);
|
void toLog(const std::string &message);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
198
esp/main.cpp
198
esp/main.cpp
@ -1,22 +1,8 @@
|
|||||||
#include "include/main.h"
|
#include "include/main.h"
|
||||||
|
|
||||||
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::gaconnector::websocket::Websocket> connector;
|
|
||||||
std::unique_ptr<SimConnect> simConnect;
|
std::unique_ptr<SimConnect> simConnect;
|
||||||
|
|
||||||
struct germanairlinesva::gaconnector::websocket::data toSend;
|
struct germanairlinesva::gaconnector::websocket::data toSend;
|
||||||
germanairlinesva::file::recording::Recording p;
|
germanairlinesva::gaconnector::recorder::Recorder *recorder;
|
||||||
|
|
||||||
// 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)
|
||||||
@ -48,7 +34,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
case SIMCONNECT_MESSAGE: {
|
case SIMCONNECT_MESSAGE: {
|
||||||
if (simConnect != nullptr && simConnect->isConnected()) {
|
if (simConnect != nullptr && simConnect->isConnected()) {
|
||||||
simConnect->handleMessage();
|
simConnect->handleMessage(
|
||||||
|
[](int version) { recorder->loadDatabase(version); },
|
||||||
|
[]() {
|
||||||
|
germanairlinesva::gaconnector::websocket::data d;
|
||||||
|
simConnect->getStates();
|
||||||
|
simConnect->getData(&d);
|
||||||
|
recorder->setData(d);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -74,8 +67,6 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
|||||||
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) {
|
||||||
@ -124,100 +115,11 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
|||||||
// Never show window
|
// Never show window
|
||||||
// ShowWindow(hWnd, SHOW_OPENWINDOW);
|
// ShowWindow(hWnd, SHOW_OPENWINDOW);
|
||||||
|
|
||||||
configuration = std::make_unique<germanairlinesva::file::config::Config>();
|
recorder = new germanairlinesva::gaconnector::recorder::Recorder(0, toLog);
|
||||||
toLog("Config loaded");
|
|
||||||
|
|
||||||
connector =
|
|
||||||
std::make_unique<germanairlinesva::gaconnector::websocket::Websocket>(
|
|
||||||
"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::utilities::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
|
// Open SimConnect
|
||||||
simConnect = std::make_unique<SimConnect>(hWnd, toLog, configuration);
|
simConnect =
|
||||||
|
std::make_unique<SimConnect>(hWnd, toLog, recorder->getConfiguration());
|
||||||
// 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) {
|
||||||
@ -282,7 +184,7 @@ WINBOOL createMenu(HWND hWnd)
|
|||||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, "Version: " BIT " Bit");
|
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, "Version: " BIT " Bit");
|
||||||
if (simConnect->isConnected()) {
|
if (simConnect->isConnected()) {
|
||||||
std::string version("Connected to Sim: ");
|
std::string version("Connected to Sim: ");
|
||||||
version.append(simConnect->getVersion());
|
version.append(SimConnect::resolveVersion(simConnect->getVersion()));
|
||||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, version.c_str());
|
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, version.c_str());
|
||||||
}
|
}
|
||||||
AppendMenu(hMenu, MF_SEPARATOR, NULL, NULL);
|
AppendMenu(hMenu, MF_SEPARATOR, NULL, NULL);
|
||||||
@ -312,11 +214,7 @@ void end(HWND hWnd)
|
|||||||
UnregisterClass(WINDOW_CLASS, GetModuleHandle(NULL));
|
UnregisterClass(WINDOW_CLASS, GetModuleHandle(NULL));
|
||||||
|
|
||||||
/* End threads */
|
/* End threads */
|
||||||
wantsExit = true;
|
recorder->~Recorder();
|
||||||
serverThread.join();
|
|
||||||
recordingThread.join();
|
|
||||||
|
|
||||||
p.toFile("flight.rec");
|
|
||||||
|
|
||||||
// End SimConnect
|
// End SimConnect
|
||||||
delete simConnect.release();
|
delete simConnect.release();
|
||||||
@ -324,74 +222,6 @@ void end(HWND hWnd)
|
|||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serverWorker()
|
|
||||||
{
|
|
||||||
germanairlinesva::utilities::setThreadName("GAServerWorker");
|
|
||||||
|
|
||||||
while (!wantsExit) {
|
|
||||||
simConnect->getStates();
|
|
||||||
|
|
||||||
struct germanairlinesva::gaconnector::websocket::data *copy =
|
|
||||||
new germanairlinesva::gaconnector::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::utilities::setThreadName("GARecordingWorker");
|
|
||||||
|
|
||||||
germanairlinesva::file::recording::RecordingEntry lastPath;
|
|
||||||
std::uint32_t segment = 0;
|
|
||||||
|
|
||||||
auto ap = (*database)["EDDF"];
|
|
||||||
auto rwys = ap.second;
|
|
||||||
|
|
||||||
while (!wantsExit) {
|
|
||||||
struct germanairlinesva::gaconnector::websocket::data *copy =
|
|
||||||
new germanairlinesva::gaconnector::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);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
SimConnect::SimConnect(
|
SimConnect::SimConnect(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
std::function<void(const std::string)> toLog,
|
std::function<void(const std::string)> toLog,
|
||||||
std::shared_ptr<germanairlinesva::file::config::Config> &configuration)
|
std::shared_ptr<germanairlinesva::file::config::Config> configuration)
|
||||||
: configuration(configuration), toLog(std::move(toLog))
|
: configuration(configuration), toLog(std::move(toLog))
|
||||||
{
|
{
|
||||||
HRESULT hr = SimConnect_Open(&this->simConnect,
|
HRESULT hr = SimConnect_Open(&this->simConnect,
|
||||||
@ -304,24 +304,7 @@ void SimConnect::getStates() const
|
|||||||
|
|
||||||
bool SimConnect::isConnected() const { return this->connectedToSim; }
|
bool SimConnect::isConnected() const { return this->connectedToSim; }
|
||||||
|
|
||||||
const std::string SimConnect::getVersion() const
|
char SimConnect::getVersion() const { return this->version; }
|
||||||
{
|
|
||||||
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(
|
void SimConnect::getData(
|
||||||
struct germanairlinesva::gaconnector::websocket::data *data)
|
struct germanairlinesva::gaconnector::websocket::data *data)
|
||||||
@ -330,7 +313,8 @@ void SimConnect::getData(
|
|||||||
memcpy(data, &this->simData, sizeof(this->simData));
|
memcpy(data, &this->simData, sizeof(this->simData));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimConnect::handleMessage()
|
void SimConnect::handleMessage(std::function<void(int)> callbackOpen,
|
||||||
|
std::function<void()> callbackData)
|
||||||
{
|
{
|
||||||
SIMCONNECT_RECV *pData;
|
SIMCONNECT_RECV *pData;
|
||||||
DWORD cbData;
|
DWORD cbData;
|
||||||
@ -340,6 +324,7 @@ void SimConnect::handleMessage()
|
|||||||
switch (pData->dwID) {
|
switch (pData->dwID) {
|
||||||
case SIMCONNECT_RECV_ID_OPEN: {
|
case SIMCONNECT_RECV_ID_OPEN: {
|
||||||
this->handleOpen((SIMCONNECT_RECV_OPEN *)pData);
|
this->handleOpen((SIMCONNECT_RECV_OPEN *)pData);
|
||||||
|
callbackOpen(this->version);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SIMCONNECT_RECV_ID_EVENT: {
|
case SIMCONNECT_RECV_ID_EVENT: {
|
||||||
@ -352,6 +337,7 @@ void SimConnect::handleMessage()
|
|||||||
}
|
}
|
||||||
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: {
|
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: {
|
||||||
this->handleData((SIMCONNECT_RECV_SIMOBJECT_DATA *)pData);
|
this->handleData((SIMCONNECT_RECV_SIMOBJECT_DATA *)pData);
|
||||||
|
callbackData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -379,7 +365,7 @@ void SimConnect::handleOpen(SIMCONNECT_RECV_OPEN *data)
|
|||||||
this->version = FSX_VERSION;
|
this->version = FSX_VERSION;
|
||||||
break;
|
break;
|
||||||
case FSXSE_SUBVERSION:
|
case FSXSE_SUBVERSION:
|
||||||
if (configuration->getFSXSEPath().length() > 0) {
|
if (configuration->getPath(FSXSE_VERSION).length() > 0) {
|
||||||
this->version = FSXSE_VERSION;
|
this->version = FSXSE_VERSION;
|
||||||
} else {
|
} else {
|
||||||
this->version = FSX_VERSION;
|
this->version = FSX_VERSION;
|
||||||
@ -458,3 +444,41 @@ void SimConnect::handleData(SIMCONNECT_RECV_SIMOBJECT_DATA *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string SimConnect::resolveVersion(char version)
|
||||||
|
{
|
||||||
|
switch (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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string SimConnect::resolveScenery(char version)
|
||||||
|
{
|
||||||
|
switch (version) {
|
||||||
|
case FSX_VERSION:
|
||||||
|
return FSX_SCENERY;
|
||||||
|
case FSXSE_VERSION:
|
||||||
|
return FSXSE_SCENERY;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
return P3D5_SCENREY;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
return P3D4_SCENREY;
|
||||||
|
break;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
return P3D3_SCENREY;
|
||||||
|
default:
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,7 +21,13 @@ namespace file
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string user;
|
std::string user;
|
||||||
std::string scenery;
|
std::string XP11Scenery;
|
||||||
|
std::string XP12Scenery;
|
||||||
|
std::string FSXScenery;
|
||||||
|
std::string FSXSEScenery;
|
||||||
|
std::string P3D3Scenery;
|
||||||
|
std::string P3D4Scenery;
|
||||||
|
std::string P3D5Scenery;
|
||||||
std::string token;
|
std::string token;
|
||||||
std::string FSXPath;
|
std::string FSXPath;
|
||||||
std::string FSXSEPath;
|
std::string FSXSEPath;
|
||||||
@ -33,7 +39,13 @@ namespace file
|
|||||||
inline void writeFile() const
|
inline void writeFile() const
|
||||||
{
|
{
|
||||||
std::ofstream out(BASE_DIRECTORY CONFIG);
|
std::ofstream out(BASE_DIRECTORY CONFIG);
|
||||||
out << "scenery=" << this->scenery << "\n";
|
out << "xp11Scenery=" << this->XP11Scenery << "\n";
|
||||||
|
out << "xp12Scenery=" << this->XP12Scenery << "\n";
|
||||||
|
out << "fsxScenery=" << this->FSXScenery << "\n";
|
||||||
|
out << "fsxSEScenery=" << this->FSXSEScenery << "\n";
|
||||||
|
out << "p3d3Scenery=" << this->P3D3Scenery << "\n";
|
||||||
|
out << "p3d4Scenery=" << this->P3D4Scenery << "\n";
|
||||||
|
out << "p3d5Scenery=" << this->P3D5Scenery << "\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 << "fsxPath=" << this->FSXPath << "\n";
|
||||||
@ -55,8 +67,20 @@ namespace file
|
|||||||
if (fields.size() >= 2) {
|
if (fields.size() >= 2) {
|
||||||
utilities::trim(fields[0]);
|
utilities::trim(fields[0]);
|
||||||
utilities::trim(fields[1]);
|
utilities::trim(fields[1]);
|
||||||
if (fields[0] == "scenery") {
|
if (fields[0] == "xp11Scenery") {
|
||||||
this->scenery = fields[1];
|
this->XP11Scenery = fields[1];
|
||||||
|
} else if (fields[0] == "xp12Scenery") {
|
||||||
|
this->XP12Scenery = fields[1];
|
||||||
|
} else if (fields[0] == "fsxScenery") {
|
||||||
|
this->FSXScenery = fields[1];
|
||||||
|
} else if (fields[0] == "fsxSEScenery") {
|
||||||
|
this->FSXSEScenery = fields[1];
|
||||||
|
} else if (fields[0] == "p3d3Scenery") {
|
||||||
|
this->P3D3Scenery = fields[1];
|
||||||
|
} else if (fields[0] == "p3d4Scenery") {
|
||||||
|
this->P3D4Scenery = fields[1];
|
||||||
|
} else if (fields[0] == "p3d5Scenery") {
|
||||||
|
this->P3D5Scenery = fields[1];
|
||||||
} else if (fields[0] == "user") {
|
} else if (fields[0] == "user") {
|
||||||
this->user = fields[1];
|
this->user = fields[1];
|
||||||
} else if (fields[0] == "token") {
|
} else if (fields[0] == "token") {
|
||||||
@ -79,25 +103,78 @@ namespace file
|
|||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void updateScenery(std::string scenery)
|
inline void updateScenery(int simVersion, std::string scenery)
|
||||||
{
|
{
|
||||||
this->scenery = scenery;
|
switch (simVersion) {
|
||||||
|
case FSX_VERSION:
|
||||||
|
this->FSXScenery = scenery;
|
||||||
|
break;
|
||||||
|
case FSXSE_VERSION:
|
||||||
|
this->FSXSEScenery = scenery;
|
||||||
|
break;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
this->P3D3Scenery = scenery;
|
||||||
|
break;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
this->P3D4Scenery = scenery;
|
||||||
|
break;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
this->P3D5Scenery = scenery;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (simVersion < 12000) {
|
||||||
|
this->XP11Scenery = scenery;
|
||||||
|
} else {
|
||||||
|
this->XP12Scenery = scenery;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
this->writeFile();
|
this->writeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
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(int simVersion) const
|
||||||
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;
|
switch (simVersion) {
|
||||||
|
case FSX_VERSION:
|
||||||
|
return this->FSXScenery;
|
||||||
|
case FSXSE_VERSION:
|
||||||
|
return this->FSXSEScenery;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
return this->P3D3Scenery;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
return this->P3D4Scenery;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
return this->P3D5Scenery;
|
||||||
|
default:
|
||||||
|
if (simVersion < 12000) {
|
||||||
|
return this->XP11Scenery;
|
||||||
|
} else {
|
||||||
|
return this->XP12Scenery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline const std::string getToken() const { return this->token; }
|
||||||
|
inline const std::string getPath(int simVersion) const
|
||||||
|
{
|
||||||
|
switch (simVersion) {
|
||||||
|
case FSX_VERSION:
|
||||||
|
return this->FSXPath;
|
||||||
|
case FSXSE_VERSION:
|
||||||
|
return this->FSXSEPath;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
return this->P3D3Path;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
return this->P3D4Path;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
return this->P3D5Path;
|
||||||
|
case MSFS_VERSION:
|
||||||
|
return this->MSFSPath;
|
||||||
|
default:
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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
|
||||||
|
|||||||
@ -108,14 +108,35 @@ namespace file
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const char *resolveFilename(int simVersion) const
|
||||||
|
{
|
||||||
|
switch (simVersion) {
|
||||||
|
case FSX_VERSION:
|
||||||
|
return BASE_DIRECTORY FSX_PREFIX SIMDATABASE;
|
||||||
|
case FSXSE_VERSION:
|
||||||
|
return BASE_DIRECTORY FSXSE_PREFIX SIMDATABASE;
|
||||||
|
case P3D3_VERSION:
|
||||||
|
return BASE_DIRECTORY P3D3_PREFIX SIMDATABASE;
|
||||||
|
case P3D4_VERSION:
|
||||||
|
return BASE_DIRECTORY P3D4_PREFIX SIMDATABASE;
|
||||||
|
case P3D5_VERSION:
|
||||||
|
return BASE_DIRECTORY P3D5_PREFIX SIMDATABASE;
|
||||||
|
case MSFS_VERSION:
|
||||||
|
return "NONE";
|
||||||
|
default:
|
||||||
|
return BASE_DIRECTORY SIMDATABASE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline SimDatabase(int simVersion,
|
inline SimDatabase(int simVersion,
|
||||||
const char *hash,
|
const char *hash,
|
||||||
std::shared_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(simVersion).c_str(), hash) !=
|
||||||
!utilities::fileExists(BASE_DIRECTORY SIMDATABASE)) {
|
0 ||
|
||||||
|
!utilities::fileExists(resolveFilename(simVersion))) {
|
||||||
#ifdef XP
|
#ifdef XP
|
||||||
scan(simVersion < 12000 ? XPLANE11_BASE_SCENERY
|
scan(simVersion < 12000 ? XPLANE11_BASE_SCENERY
|
||||||
: XPLANE12_BASE_SCENERY,
|
: XPLANE12_BASE_SCENERY,
|
||||||
@ -129,52 +150,16 @@ namespace file
|
|||||||
BASE_DIRECTORY "db_log.txt",
|
BASE_DIRECTORY "db_log.txt",
|
||||||
airports);
|
airports);
|
||||||
#endif
|
#endif
|
||||||
configuration->updateScenery(hash);
|
configuration->updateScenery(simVersion, hash);
|
||||||
#ifdef XP
|
|
||||||
this->toFile(SIMDATABASE);
|
|
||||||
#endif
|
|
||||||
#ifndef MSFS
|
#ifndef MSFS
|
||||||
switch (simVersion) {
|
this->toFile(resolveFilename(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
|
#endif
|
||||||
toLog("Sim Database updated");
|
toLog("Sim Database updated");
|
||||||
} else {
|
} else {
|
||||||
#ifdef XP
|
|
||||||
this->fromFile(SIMDATABASE);
|
|
||||||
#endif
|
|
||||||
#ifndef MSFS
|
#ifndef MSFS
|
||||||
switch (simVersion) {
|
this->fromFile(resolveFilename(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
|
#endif
|
||||||
toLog("Sim Database loaded");
|
toLog("Sim Database loaded");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,18 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
#include "websocket.h"
|
#include "websocket.h"
|
||||||
|
|
||||||
|
#if defined(IBM) && not defined(XP)
|
||||||
|
#include "_simconnect.h"
|
||||||
|
|
||||||
|
#include <shlobj.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "config/config.hpp"
|
#include "config/config.hpp"
|
||||||
#include "logbook/logbook.hpp"
|
#include "logbook/logbook.hpp"
|
||||||
#include "recording/recording.hpp"
|
#include "recording/recording.hpp"
|
||||||
@ -45,6 +55,7 @@ namespace gaconnector
|
|||||||
void serverWorker();
|
void serverWorker();
|
||||||
void recordingWorker();
|
void recordingWorker();
|
||||||
|
|
||||||
|
|
||||||
// For Testing
|
// For Testing
|
||||||
void test() const;
|
void test() const;
|
||||||
|
|
||||||
@ -54,6 +65,8 @@ namespace gaconnector
|
|||||||
|
|
||||||
void setData(websocket::data &data);
|
void setData(websocket::data &data);
|
||||||
void handleMessages();
|
void handleMessages();
|
||||||
|
std::shared_ptr<file::config::Config> getConfiguration() const;
|
||||||
|
void loadDatabase(int simVersion);
|
||||||
};
|
};
|
||||||
} // namespace recorder
|
} // namespace recorder
|
||||||
} // namespace gaconnector
|
} // namespace gaconnector
|
||||||
|
|||||||
@ -25,19 +25,19 @@ namespace gaconnector
|
|||||||
this->configuration,
|
this->configuration,
|
||||||
this->toLog);
|
this->toLog);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#ifndef MSFS
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// WebSocket
|
// WebSocket
|
||||||
this->connector = std::make_unique<websocket::Websocket>(
|
this->connector =
|
||||||
"wss://ws.hofmannnet.myhome-server.de:8000",
|
std::make_unique<websocket::Websocket>(WEBSOCKET_ADDRESS,
|
||||||
this->configuration->getUser(),
|
this->configuration->getUser(),
|
||||||
this->toLog);
|
this->toLog);
|
||||||
this->toLog("WebSocket started");
|
this->toLog("WebSocket started");
|
||||||
|
|
||||||
// For Testing
|
// For Testing
|
||||||
|
#ifdef XP
|
||||||
this->test();
|
this->test();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Thread for sending data to websocket
|
// Thread for sending data to websocket
|
||||||
this->serverThread = std::thread(&Recorder::serverWorker, this);
|
this->serverThread = std::thread(&Recorder::serverWorker, this);
|
||||||
@ -70,6 +70,53 @@ namespace gaconnector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<file::config::Config> Recorder::getConfiguration() const
|
||||||
|
{
|
||||||
|
return this->configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Recorder::loadDatabase(int simVersion)
|
||||||
|
{
|
||||||
|
if (simVersion == MSFS_VERSION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(IBM) && not defined(XP)
|
||||||
|
this->toLog("Loading database for " +
|
||||||
|
SimConnect::resolveVersion(simVersion));
|
||||||
|
|
||||||
|
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(SimConnect::resolveScenery(simVersion));
|
||||||
|
this->toLog(path);
|
||||||
|
|
||||||
|
delete[] nstring;
|
||||||
|
CoTaskMemFree(folder);
|
||||||
|
|
||||||
|
char hash[2 * MD5LEN + 1] = "";
|
||||||
|
if (utilities::generateMD5(path.c_str(), hash, toLog) == 0) {
|
||||||
|
database =
|
||||||
|
std::make_unique<file::simdata::SimDatabase>(simVersion,
|
||||||
|
hash,
|
||||||
|
this->configuration,
|
||||||
|
this->toLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->test();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Recorder::serverWorker()
|
void Recorder::serverWorker()
|
||||||
{
|
{
|
||||||
utilities::setThreadName("GAServerWorker");
|
utilities::setThreadName("GAServerWorker");
|
||||||
@ -112,7 +159,7 @@ namespace gaconnector
|
|||||||
static_cast<std::uint16_t>(copy.gs),
|
static_cast<std::uint16_t>(copy.gs),
|
||||||
{copy.lat, copy.lon});
|
{copy.lat, copy.lon});
|
||||||
|
|
||||||
if (strcmp(copy.path, "") != 0 && copy.pause &&
|
if (strcmp(copy.path, "") != 0 && !copy.pause &&
|
||||||
lastPath != currentPath) {
|
lastPath != currentPath) {
|
||||||
path.addEntry(currentPath);
|
path.addEntry(currentPath);
|
||||||
lastPath = currentPath;
|
lastPath = currentPath;
|
||||||
@ -142,39 +189,6 @@ namespace gaconnector
|
|||||||
auto ap2 = (*database)["XXXX"];
|
auto ap2 = (*database)["XXXX"];
|
||||||
ap2.first.size() == 0 ? this->toLog(" SUCCESS") : this->toLog(" ERROR");
|
ap2.first.size() == 0 ? this->toLog(" SUCCESS") : this->toLog(" ERROR");
|
||||||
#endif
|
#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();
|
|
||||||
}
|
}
|
||||||
} // namespace recorder
|
} // namespace recorder
|
||||||
} // namespace gaconnector
|
} // namespace gaconnector
|
||||||
|
|||||||
@ -63,6 +63,12 @@
|
|||||||
#define P3D5_VERSION 5
|
#define P3D5_VERSION 5
|
||||||
#define MSFS_VERSION 11
|
#define MSFS_VERSION 11
|
||||||
|
|
||||||
|
#define FSX_SCENERY "\\Microsoft\\FSX\\scenery.cfg"
|
||||||
|
#define FSXSE_SCENERY "\\Microsoft\\FSX-SE\\scenery.cfg"
|
||||||
|
#define P3D3_SCENREY "\\Lockheed Martin\\Prepar3D V3\\scenery.cfg"
|
||||||
|
#define P3D4_SCENREY "\\Lockheed Martin\\Prepar3D V4\\scenery.cfg"
|
||||||
|
#define P3D5_SCENREY "\\Lockheed Martin\\Prepar3D V5\\scenery.cfg"
|
||||||
|
|
||||||
// Not supported
|
// Not supported
|
||||||
#define FSXRTM_SUBVERSION 60905
|
#define FSXRTM_SUBVERSION 60905
|
||||||
#define FSSXSP1_SUBVERRSION 61242
|
#define FSSXSP1_SUBVERRSION 61242
|
||||||
@ -73,4 +79,6 @@
|
|||||||
// Must be differentiated due to SxS Install
|
// Must be differentiated due to SxS Install
|
||||||
#define FSXSE_SUBVERSION 62615
|
#define FSXSE_SUBVERSION 62615
|
||||||
|
|
||||||
|
#define WEBSOCKET_ADDRESS "wss://ws.hofmannnet.myhome-server.de:8000"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -103,6 +103,7 @@ namespace gaconnector
|
|||||||
{"truHdg", d.truHdg},
|
{"truHdg", d.truHdg},
|
||||||
{"totFuel", d.totFuelKg},
|
{"totFuel", d.totFuelKg},
|
||||||
{"fuelFlow", d.ff},
|
{"fuelFlow", d.ff},
|
||||||
|
{"path", d.path},
|
||||||
{"hash", this->lastHash},
|
{"hash", this->lastHash},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ add_library(germanairlinesva_xplugin SHARED
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(germanairlinesva_xplugin PRIVATE
|
target_include_directories(germanairlinesva_xplugin PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/xplugin/include
|
||||||
${CMAKE_SOURCE_DIR}/file/include
|
${CMAKE_SOURCE_DIR}/file/include
|
||||||
${CMAKE_SOURCE_DIR}/recorder/include
|
${CMAKE_SOURCE_DIR}/recorder/include
|
||||||
${CMAKE_SOURCE_DIR}/simdata/include
|
${CMAKE_SOURCE_DIR}/simdata/include
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user