Namespaces
Better File handling
This commit is contained in:
@@ -9,7 +9,7 @@ add_library(germanairlinesva_xplugin SHARED
|
||||
|
||||
target_include_directories(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/ixwebsocket/include
|
||||
${CMAKE_SOURCE_DIR}/makerwysxp/include
|
||||
${CMAKE_SOURCE_DIR}/simdata/include
|
||||
${CMAKE_SOURCE_DIR}/websocket/include
|
||||
${CMAKE_SOURCE_DIR}/utilities/include
|
||||
${CMAKE_SOURCE_DIR}/nlohmann/include
|
||||
@@ -134,6 +134,6 @@ elseif(WIN32)
|
||||
endif()
|
||||
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
makerwysxp
|
||||
simdata
|
||||
ixwebsocket
|
||||
)
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
||||
|
||||
#include "config.hpp"
|
||||
#include "makeRwysXP.h"
|
||||
#include "recordingPath.hpp"
|
||||
#include "simdata.h"
|
||||
#include "simulatorDatabase.hpp"
|
||||
#include "websocket.h"
|
||||
|
||||
|
||||
+40
-23
@@ -12,7 +12,7 @@ std::atomic<bool> wantsExit;
|
||||
|
||||
std::map<std::string, std::string> configuration;
|
||||
|
||||
Websocket *connector;
|
||||
germanairlinesva_websocket::Websocket *connector;
|
||||
|
||||
/* Datarefs */
|
||||
XPLMDataRef pauseIndicator;
|
||||
@@ -42,7 +42,7 @@ XPLMDataRef pitch;
|
||||
XPLMDataRef roll;
|
||||
XPLMDataRef quaternion;
|
||||
|
||||
data toSend;
|
||||
germanairlinesva_websocket::data toSend;
|
||||
Path p;
|
||||
|
||||
/*
|
||||
@@ -107,14 +107,15 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
|
||||
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
|
||||
|
||||
configuration =
|
||||
config::readConfig("Resources/plugins/GAConnector/config.cfg");
|
||||
configuration = germanairlinesva_config::readConfig(
|
||||
"Resources/plugins/GAConnector/config.cfg");
|
||||
toLog("Config loaded");
|
||||
|
||||
try {
|
||||
connector = new Websocket("wss://ws.hofmannnet.myhome-server.de:8000",
|
||||
configuration["user"],
|
||||
toLog);
|
||||
connector = new germanairlinesva_websocket::Websocket(
|
||||
"wss://ws.hofmannnet.myhome-server.de:8000",
|
||||
configuration["user"],
|
||||
toLog);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
toLog(e.what());
|
||||
return 0;
|
||||
@@ -122,28 +123,44 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
toLog("WebSocket started");
|
||||
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (util::generateMD5("Custom Scenery/scenery_packs.ini", hash, toLog) == 0) {
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
if (germanairlinesva_util::generateMD5("Custom Scenery/scenery_packs.ini",
|
||||
hash,
|
||||
toLog) == 0) {
|
||||
std::map<std::string,
|
||||
std::pair<std::vector<germanairlinesva_simdata::Gate>,
|
||||
std::vector<germanairlinesva_simdata::Runway>>>
|
||||
airports;
|
||||
|
||||
if (strcmp(configuration["scenery"].c_str(), hash) != 0) {
|
||||
if (strcmp(configuration["scenery"].c_str(), hash) != 0 ||
|
||||
!germanairlinesva_util::fileExists(
|
||||
"Resources/plugins/GAConnector/sim.bin")) {
|
||||
scan("Resources/default scenery/default apt dat/Earth nav "
|
||||
"data/apt.dat",
|
||||
"Custom Scenery/scenery_packs.ini",
|
||||
"Resources/plugins/GAConnector/log.txt",
|
||||
airports);
|
||||
simulatorDatabase::toFile(airports,
|
||||
"Resources/plugins/GAConnector/sim.bin");
|
||||
germanairlinesva_simdata::toFile(airports,
|
||||
"Resources/plugins/GAConnector/sim.bin");
|
||||
|
||||
configuration["scenery"] = hash;
|
||||
config::writeConfig(configuration,
|
||||
"Resources/plugins/GAConnector/config.cfg");
|
||||
germanairlinesva_config::writeConfig(
|
||||
configuration,
|
||||
"Resources/plugins/GAConnector/config.cfg");
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
airports =
|
||||
simulatorDatabase::fromFile("Resources/plugins/GAConnector/sim.bin");
|
||||
airports = germanairlinesva_simdata::fromFile(
|
||||
"Resources/plugins/GAConnector/sim.bin");
|
||||
toLog("Sim Database loaded");
|
||||
}
|
||||
|
||||
toLog("Readback test of sim database using EDDF");
|
||||
auto ap = airports["EDDF"];
|
||||
for (const auto &it : ap.first) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
for (const auto &it : ap.second) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// Thread for sending data to web socket
|
||||
@@ -188,7 +205,7 @@ float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
memset(&toSend, 0, sizeof(data));
|
||||
memset(&toSend, 0, sizeof(germanairlinesva_websocket::data));
|
||||
|
||||
toSend.pause = XPLMGetDatai(pauseIndicator);
|
||||
toSend.pBrake = XPLMGetDataf(parkingBrake);
|
||||
@@ -226,14 +243,14 @@ float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon)
|
||||
|
||||
void serverWorker()
|
||||
{
|
||||
util::setThreadName("GAServerWorker");
|
||||
germanairlinesva_util::setThreadName("GAServerWorker");
|
||||
|
||||
while (!wantsExit) {
|
||||
data copy;
|
||||
germanairlinesva_websocket::data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
memcpy(©, &toSend, sizeof(data));
|
||||
memcpy(©, &toSend, sizeof(germanairlinesva_websocket::data));
|
||||
}
|
||||
|
||||
connector->sendData(copy);
|
||||
@@ -244,16 +261,16 @@ void serverWorker()
|
||||
|
||||
void recordingWorker()
|
||||
{
|
||||
util::setThreadName("GARecordingWorker");
|
||||
germanairlinesva_util::setThreadName("GARecordingWorker");
|
||||
|
||||
PathSegment lastPath;
|
||||
|
||||
while (!wantsExit) {
|
||||
data copy;
|
||||
germanairlinesva_websocket::data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
memcpy(©, &toSend, sizeof(data));
|
||||
memcpy(©, &toSend, sizeof(germanairlinesva_websocket::data));
|
||||
}
|
||||
|
||||
PathSegment currentPath(static_cast<std::uint16_t>(copy.alt),
|
||||
|
||||
Reference in New Issue
Block a user