Remove ixWebSocket

This commit is contained in:
2022-09-04 00:50:49 +02:00
parent fbee417594
commit a820f7456a
123 changed files with 998 additions and 12947 deletions
+6 -17
View File
@@ -1,23 +1,15 @@
#For TLS
#target_compile_definitions(WebSocketServerXPlane PUBLIC
#IXWEBSOCKET_USE_TLS
#IXWEBSOCKET_USE_OPEN_SSL
#)
#Link to ssl(requires OpenSLL for macOS and Windows)
file(GLOB websocket CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/websocket/*.cpp)
file(GLOB socket CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/socket/*.cpp)
file(GLOB file CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/file/*.cpp)
add_library(germanairlinesva_xplugin SHARED
${websocket}
${socket}
${file}
makeRwysXP.cpp
main.cpp
)
target_include_directories(germanairlinesva_xplugin PRIVATE
${CMAKE_SOURCE_DIR}/ixwebsocket/include
${CMAKE_SOURCE_DIR}/websocket/include
${CMAKE_SOURCE_DIR}/socket/include
${CMAKE_SOURCE_DIR}/XPSDK/CHeaders
${CMAKE_SOURCE_DIR}/nlohmann
${CMAKE_SOURCE_DIR}/file
@@ -64,16 +56,16 @@ if(APPLE)
APL
)
target_compile_options(germanairlinesva_xplugin PRIVATE
#"SHELL:-arch i386"
"SHELL:-arch i386"
"SHELL:-arch x86_64"
)
target_link_options(germanairlinesva_xplugin PRIVATE
#"SHELL:-arch i386"
"SHELL:-arch i386"
"SHELL:-arch x86_64"
)
target_link_libraries(germanairlinesva_xplugin PRIVATE
${CMAKE_SOURCE_DIR}/XPSDK/Libraries/Mac/XPLM.framework/XPLM
ixwebsocket
"-framework Security"
)
elseif(UNIX)
message("Building for Linux ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
@@ -101,7 +93,6 @@ elseif(UNIX)
target_link_libraries(germanairlinesva_xplugin PRIVATE
crypto
pthread
ixwebsocket
)
elseif(WIN32)
message("Building for Windows ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
@@ -123,13 +114,11 @@ elseif(WIN32)
)
endif()
target_link_options(germanairlinesva_xplugin PRIVATE
-static
-static-libgcc
-static-libstdc++
)
target_link_libraries(germanairlinesva_xplugin PRIVATE
ws2_32.lib
ixwebsocket
)
if(BIT STREQUAL "32")
target_link_libraries(germanairlinesva_xplugin PRIVATE
+1 -1
View File
@@ -5,7 +5,7 @@
#include "makeRwysXP.h"
#include "recordingPath.hpp"
#include "simulatorDatabase.hpp"
#include "websocket.h"
#include "socket.h"
#include "XPLM/XPLMDataAccess.h"
#include "XPLM/XPLMGraphics.h"
+167 -169
View File
@@ -3,8 +3,8 @@
std::mutex mutex;
std::queue<std::function<void()>> &messageQueue()
{
static std::queue<std::function<void()>> _messageQueue;
return _messageQueue;
static std::queue<std::function<void()>> _messageQueue;
return _messageQueue;
}
std::thread serverThread;
std::thread recordingThread;
@@ -12,7 +12,7 @@ std::atomic<bool> wantsExit;
std::map<std::string, std::string> configuration;
Websocket *connector;
Socket *connector;
/* Datarefs */
XPLMDataRef pauseIndicator;
@@ -51,124 +51,123 @@ Path p;
PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
{
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1);
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1);
wantsExit.store(false);
wantsExit.store(false);
/* First we must fill in the passed-in buffers to describe our
* plugin to the plugin-system. */
/* First we must fill in the passed-in buffers to describe our
* plugin to the plugin-system. */
strcpy(outName, "GAConnector");
strcpy(outSig, "de.german-airlines.GAConnector");
strcpy(outDesc, "GAConnector");
strcpy(outName, "GAConnector");
strcpy(outSig, "de.german-airlines.GAConnector");
strcpy(outDesc, "GAConnector");
/* Flight Loop */
XPLMRegisterFlightLoopCallback(flightLoop, -1, nullptr);
/* Flight Loop */
XPLMRegisterFlightLoopCallback(flightLoop, -1, nullptr);
/* Setup DataRefs */
pauseIndicator = XPLMFindDataRef(
"sim/time/sim_speed"); // INT 0=paused, doubles as setting pause(1)
parkingBrake =
XPLMFindDataRef("sim/flightmodel/controls/parkbrake"); // FLOAT 1=max
acftOnGrnd =
XPLMFindDataRef("sim/flightmodel/failures/onground_any"); // INT 1=true
totalFuelKgs =
XPLMFindDataRef("sim/flightmodel/weight/m_fuel_total"); // FLOAT
trueHeading = XPLMFindDataRef(
"sim/flightmodel/position/true_psi"); // FLOAT degrees north
acftAlt =
XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE meters
acftGS = XPLMFindDataRef(
"sim/flightmodel/position/groundspeed"); // FLOAT meters/second
acftIAS = XPLMFindDataRef(
"sim/flightmodel/position/indicated_airspeed"); // FLOAT kias
acftVS = XPLMFindDataRef(
"sim/flightmodel/position/vh_ind_fpm"); // FLOAT feet/minute
acftLatitude =
XPLMFindDataRef("sim/flightmodel/position/latitude"); // DOUBLE degrees
acftLongitude =
XPLMFindDataRef("sim/flightmodel/position/longitude"); // DOUBLE degrees
fuelFlow = XPLMFindDataRef(
"sim/flightmodel/engine/ENGN_FF_"); // FLOAT[8] kg/second
maxSpeed = XPLMFindDataRef("sim/aircraft/view/acf_Vne"); // FLOAT kias
uptime =
XPLMFindDataRef("sim/time/total_running_time_sec"); // FLOAT seconds
magHeading = XPLMFindDataRef(
"sim/flightmodel/position/mag_psi"); // FLOAT degrees north
timeZulu = XPLMFindDataRef(
"sim/time/zulu_time_sec"); // FLOAT seconds since midnight
payloadKgs = XPLMFindDataRef("sim/flightmodel/weight/m_fixed"); // FLOAT
totalWeightKgs = XPLMFindDataRef("sim/flightmodel/weight/m_total"); // FLOAT
/* Setup DataRefs */
pauseIndicator = XPLMFindDataRef(
"sim/time/sim_speed"); // INT 0=paused, doubles as setting pause(1)
parkingBrake =
XPLMFindDataRef("sim/flightmodel/controls/parkbrake"); // FLOAT 1=max
acftOnGrnd =
XPLMFindDataRef("sim/flightmodel/failures/onground_any"); // INT 1=true
totalFuelKgs =
XPLMFindDataRef("sim/flightmodel/weight/m_fuel_total"); // FLOAT
trueHeading = XPLMFindDataRef(
"sim/flightmodel/position/true_psi"); // FLOAT degrees north
acftAlt =
XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE meters
acftGS = XPLMFindDataRef(
"sim/flightmodel/position/groundspeed"); // FLOAT meters/second
acftIAS = XPLMFindDataRef(
"sim/flightmodel/position/indicated_airspeed"); // FLOAT kias
acftVS = XPLMFindDataRef(
"sim/flightmodel/position/vh_ind_fpm"); // FLOAT feet/minute
acftLatitude =
XPLMFindDataRef("sim/flightmodel/position/latitude"); // DOUBLE degrees
acftLongitude =
XPLMFindDataRef("sim/flightmodel/position/longitude"); // DOUBLE degrees
fuelFlow =
XPLMFindDataRef("sim/flightmodel/engine/ENGN_FF_"); // FLOAT[8] kg/second
maxSpeed = XPLMFindDataRef("sim/aircraft/view/acf_Vne"); // FLOAT kias
uptime = XPLMFindDataRef("sim/time/total_running_time_sec"); // FLOAT seconds
magHeading = XPLMFindDataRef(
"sim/flightmodel/position/mag_psi"); // FLOAT degrees north
timeZulu =
XPLMFindDataRef("sim/time/zulu_time_sec"); // FLOAT seconds since midnight
payloadKgs = XPLMFindDataRef("sim/flightmodel/weight/m_fixed"); // FLOAT
totalWeightKgs = XPLMFindDataRef("sim/flightmodel/weight/m_total"); // FLOAT
localX = XPLMFindDataRef("sim/flightmodel/position/local_x"); // DOUBLE
localY = XPLMFindDataRef("sim/flightmodel/position/local_y"); // DOUBLE
localZ = XPLMFindDataRef("sim/flightmodel/position/local_z"); // DOUBLE
elevation = XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE
pitch = XPLMFindDataRef("sim/flightmodel/position/theta"); // FLOAT
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
localX = XPLMFindDataRef("sim/flightmodel/position/local_x"); // DOUBLE
localY = XPLMFindDataRef("sim/flightmodel/position/local_y"); // DOUBLE
localZ = XPLMFindDataRef("sim/flightmodel/position/local_z"); // DOUBLE
elevation = XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE
pitch = XPLMFindDataRef("sim/flightmodel/position/theta"); // FLOAT
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
// Initialize connector
try {
connector = new Websocket(toLog);
} catch (const std::invalid_argument &e) {
toLog(e.what());
return 0;
// Initialize connector
try {
connector =
new Socket("https://wsecho.hofmannnet.myhome-server.de/client", toLog);
} catch (const std::invalid_argument &e) {
toLog(e.what());
return 0;
}
toLog("WebSocket started");
configuration =
config::readConfig("Resources/plugins/GAConnector/config.cfg");
toLog("Config loaded");
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>>>
airports;
if (strcmp(configuration["scenery"].c_str(), hash) != 0) {
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");
configuration["scenery"] = hash;
config::writeConfig(configuration,
"Resources/plugins/GAConnector/config.cfg");
toLog("Sim Database updated");
} else {
airports =
simulatorDatabase::fromFile("Resources/plugins/GAConnector/sim.bin");
toLog("Sim Database loaded");
}
toLog("WebSocket started");
}
configuration =
config::readConfig("Resources/plugins/GAConnector/config.cfg");
toLog("Config loaded");
// Thread for sending data to web socket
serverThread = std::thread(&serverWorker);
recordingThread = std::thread(&recordingWorker);
toLog("Workers 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>>>
airports;
if (strcmp(configuration["scenery"].c_str(), hash) != 0) {
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");
configuration["scenery"] = hash;
config::writeConfig(configuration,
"Resources/plugins/GAConnector/config.cfg");
toLog("Sim Database updated");
} else {
airports = simulatorDatabase::fromFile(
"Resources/plugins/GAConnector/sim.bin");
toLog("Sim Database loaded");
}
}
// Thread for sending data to web socket
serverThread = std::thread(&serverWorker);
recordingThread = std::thread(&recordingWorker);
toLog("Workers started");
return 1;
return 1;
}
PLUGIN_API void XPluginStop(void)
{
/* Flight Loop */
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
/* End threads */
wantsExit = true;
delete connector;
serverThread.join();
recordingThread.join();
/* Flight Loop */
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
/* End threads */
wantsExit = true;
delete connector;
serverThread.join();
recordingThread.join();
std::ofstream out("Resources/plugins/GAConnector/flight.rec");
out.write(reinterpret_cast<const char *>(p.getBinaryData()),
(std::streamsize)p.getBinaryLength());
out.close();
std::ofstream out("Resources/plugins/GAConnector/flight.rec");
out.write(reinterpret_cast<const char *>(p.getBinaryData()),
(std::streamsize)p.getBinaryLength());
out.close();
}
PLUGIN_API void XPluginDisable(void) {}
@@ -187,94 +186,93 @@ PLUGIN_API void
#pragma clang diagnostic ignored "-Wunused-parameter"
float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon)
{
const std::lock_guard<std::mutex> lock(mutex);
const std::lock_guard<std::mutex> lock(mutex);
memset(&toSend, 0, sizeof(data));
memset(&toSend, 0, sizeof(data));
toSend.pause = XPLMGetDatai(pauseIndicator);
toSend.pBrake = XPLMGetDataf(parkingBrake);
toSend.onGrnd = XPLMGetDatai(acftOnGrnd);
toSend.totFuelKg = XPLMGetDataf(totalFuelKgs);
toSend.truHdg = XPLMGetDataf(trueHeading);
toSend.alt = XPLMGetDatad(acftAlt);
toSend.gs = XPLMGetDataf(acftGS);
toSend.ias = XPLMGetDataf(acftIAS);
toSend.vs = XPLMGetDataf(acftVS);
toSend.lat = XPLMGetDatad(acftLatitude);
toSend.lon = XPLMGetDatad(acftLongitude);
XPLMGetDatavf(fuelFlow, toSend.ff, 0, 8);
toSend.maxSpd = XPLMGetDataf(maxSpeed);
toSend.pause = XPLMGetDatai(pauseIndicator);
toSend.pBrake = XPLMGetDataf(parkingBrake);
toSend.onGrnd = XPLMGetDatai(acftOnGrnd);
toSend.totFuelKg = XPLMGetDataf(totalFuelKgs);
toSend.truHdg = XPLMGetDataf(trueHeading);
toSend.alt = XPLMGetDatad(acftAlt);
toSend.gs = XPLMGetDataf(acftGS);
toSend.ias = XPLMGetDataf(acftIAS);
toSend.vs = XPLMGetDataf(acftVS);
toSend.lat = XPLMGetDatad(acftLatitude);
toSend.lon = XPLMGetDatad(acftLongitude);
XPLMGetDatavf(fuelFlow, toSend.ff, 0, 8);
toSend.maxSpd = XPLMGetDataf(maxSpeed);
char *name = (char *)calloc(256, sizeof(char));
XPLMGetNthAircraftModel(0, name, toSend.path);
free(name);
char *name = (char *)calloc(256, sizeof(char));
XPLMGetNthAircraftModel(0, name, toSend.path);
free(name);
toSend.uptime = XPLMGetDataf(uptime);
toSend.magHeading = XPLMGetDataf(magHeading);
toSend.uptime = XPLMGetDataf(uptime);
toSend.magHeading = XPLMGetDataf(magHeading);
toSend.payloadKg = XPLMGetDataf(payloadKgs);
toSend.totalWeightKg = XPLMGetDataf(totalWeightKgs);
toSend.payloadKg = XPLMGetDataf(payloadKgs);
toSend.totalWeightKg = XPLMGetDataf(totalWeightKgs);
if (!messageQueue().empty()) {
auto op = std::move(messageQueue().front());
messageQueue().pop();
op();
}
if (!messageQueue().empty()) {
auto op = std::move(messageQueue().front());
messageQueue().pop();
op();
}
return -1;
return -1;
}
#pragma clang diagnostic pop
void serverWorker()
{
util::setThreadName("GAServerWorker");
util::setThreadName("GAServerWorker");
while (!wantsExit) {
data copy;
{
const std::lock_guard<std::mutex> lock(mutex);
while (!wantsExit) {
data copy;
{
const std::lock_guard<std::mutex> lock(mutex);
memcpy(&copy, &toSend, sizeof(data));
}
connector->sendData(copy);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
memcpy(&copy, &toSend, sizeof(data));
}
connector->sendData(copy);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}
void recordingWorker()
{
util::setThreadName("GARecordingWorker");
util::setThreadName("GARecordingWorker");
PathSegment lastPath;
PathSegment lastPath;
while (!wantsExit) {
data copy;
{
const std::lock_guard<std::mutex> lock(mutex);
while (!wantsExit) {
data copy;
{
const std::lock_guard<std::mutex> lock(mutex);
memcpy(&copy, &toSend, sizeof(data));
}
PathSegment currentPath(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.addSegment(currentPath);
lastPath = currentPath;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
memcpy(&copy, &toSend, sizeof(data));
}
PathSegment currentPath(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.addSegment(currentPath);
lastPath = currentPath;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
void toLog(const std::string &message)
{
std::stringstream msg;
msg << "German Airlines VA: " << message << std::endl;
XPLMDebugString(msg.str().c_str());
std::stringstream msg;
msg << "German Airlines VA: " << message << std::endl;
XPLMDebugString(msg.str().c_str());
}
+133 -139
View File
@@ -6,58 +6,58 @@ int scan(const char *defaultFile,
std::map<std::string,
std::pair<std::vector<Gate>, std::vector<Runway>>> &airports)
{
std::ifstream base(defaultFile);
if (!base.good()) {
return 1;
}
std::ifstream custom(sceneryPack);
if (!custom.good()) {
base.close();
return 2;
}
std::ofstream logfile(logFile, std::ios::out | std::ios::trunc);
if (!logfile.good()) {
base.close();
custom.close();
return 3;
}
// Default
logfile << "<FILE> " << defaultFile << std::endl;
makeAirport("DEFAULT", &base, &airports, &logfile);
std::ifstream base(defaultFile);
if (!base.good()) {
return 1;
}
std::ifstream custom(sceneryPack);
if (!custom.good()) {
base.close();
return 2;
}
std::ofstream logfile(logFile, std::ios::out | std::ios::trunc);
if (!logfile.good()) {
base.close();
std::string line;
size_t pos;
std::vector<std::string> packs;
while (std::getline(custom, line)) {
if ((pos = line.find("SCENERY_PACK")) != std::string::npos) {
std::string path =
rtrim_copy(line.substr(pos + 13)) + "Earth nav data/apt.dat";
packs.push_back(path);
}
}
std::reverse(packs.begin(), packs.end());
for (std::string const &path : packs) {
std::ifstream pack(path);
if (pack.good()) {
logfile << "<FILE> " << path << std::endl;
makeAirport("CUSTOM", &pack, &airports, &logfile);
pack.close();
} else {
pack.close();
logfile << "<STATUS>"
<< "Could not find " << path << std::endl;
}
}
logfile << std::endl
<< "<STATUS> Total airports: " << airports.size() << std::endl;
custom.close();
logfile.close();
return 0;
return 3;
}
// Default
logfile << "<FILE> " << defaultFile << std::endl;
makeAirport("DEFAULT", &base, &airports, &logfile);
base.close();
std::string line;
size_t pos;
std::vector<std::string> packs;
while (std::getline(custom, line)) {
if ((pos = line.find("SCENERY_PACK")) != std::string::npos) {
std::string path =
rtrim_copy(line.substr(pos + 13)) + "Earth nav data/apt.dat";
packs.push_back(path);
}
}
std::reverse(packs.begin(), packs.end());
for (std::string const &path : packs) {
std::ifstream pack(path);
if (pack.good()) {
logfile << "<FILE> " << path << std::endl;
makeAirport("CUSTOM", &pack, &airports, &logfile);
pack.close();
} else {
pack.close();
logfile << "<STATUS>"
<< "Could not find " << path << std::endl;
}
}
logfile << std::endl
<< "<STATUS> Total airports: " << airports.size() << std::endl;
custom.close();
logfile.close();
return 0;
}
void makeAirport(
@@ -67,114 +67,108 @@ void makeAirport(
*airports,
std::ofstream *logfile)
{
std::string line;
std::string *currentIcao = nullptr;
std::vector<Gate> tmpGates;
std::vector<Runway> tmpRunways;
std::string line;
std::string *currentIcao = nullptr;
std::vector<Gate> tmpGates;
std::vector<Runway> tmpRunways;
int apCount = 0;
int validCount = 0;
int apCount = 0;
int validCount = 0;
while (std::getline(*infile, line)) {
std::vector<std::string> fields = split(line, ' ');
fields = util::select_T<std::string>(fields, [](const std::string &s) {
return s.length() > 0;
});
while (std::getline(*infile, line)) {
std::vector<std::string> fields = split(line, ' ');
fields = util::select_T<std::string>(fields, [](const std::string &s) {
return s.length() > 0;
});
if (fields.empty())
continue;
if (fields[0] == "1") {
// Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() &&
!tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed"
<< std::endl;
} else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao
<< " had no gates or runways" << std::endl;
}
tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>();
currentIcao = new std::string(fields[4]);
apCount += 1;
*logfile << "\t<" << kind << "> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "15") {
makeGate15(&tmpGates, fields);
*logfile << "\t\t<GATE OLD> " << line << std::endl;
} else if (fields[0] == "16" || fields[0] == "17") {
// Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() &&
!tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed"
<< std::endl;
} else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao
<< " had no gates or runways" << std::endl;
}
tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>();
currentIcao = nullptr;
*logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "100") {
makeRunway(&tmpRunways, fields);
*logfile << "\t\t<RUNWAY> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "1300") {
makeGate1300(&tmpGates, fields);
*logfile << "\t\t<GATE> " << line << std::endl;
}
}
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
if (fields.empty())
continue;
if (fields[0] == "1") {
// Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
} else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
<< std::endl;
}
tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>();
currentIcao = new std::string(fields[4]);
apCount += 1;
*logfile << "\t<" << kind << "> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "15") {
makeGate15(&tmpGates, fields);
*logfile << "\t\t<GATE OLD> " << line << std::endl;
} else if (fields[0] == "16" || fields[0] == "17") {
// Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
} else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
<< std::endl;
}
tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>();
currentIcao = nullptr;
*logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "100") {
makeRunway(&tmpRunways, fields);
*logfile << "\t\t<RUNWAY> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "1300") {
makeGate1300(&tmpGates, fields);
*logfile << "\t\t<GATE> " << line << std::endl;
}
*logfile << "<STATUS> " << apCount << " airports found, of which "
<< validCount << " are valid" << std::endl;
}
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
}
*logfile << "<STATUS> " << apCount << " airports found, of which "
<< validCount << " are valid" << std::endl;
}
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields)
{
std::string gateName;
for (size_t j = 4; j < fields.size() - 1; j++) {
gateName += fields[j] + " ";
}
gateName += fields.back();
gateName = std::regex_replace(gateName, std::regex{","}, "0");
std::string gateName;
for (size_t j = 4; j < fields.size() - 1; j++) {
gateName += fields[j] + " ";
}
gateName += fields.back();
gateName = std::regex_replace(gateName, std::regex{","}, "0");
gates->push_back(
Gate{gateName, std::stod(fields[1]), std::stod(fields[2])});
gates->push_back(Gate{gateName, std::stod(fields[1]), std::stod(fields[2])});
}
void makeRunway(std::vector<Runway> *runways, std::vector<std::string> fields)
{
runways->push_back(Runway{fields[8],
std::stod(fields[9]),
std::stod(fields[10]),
std::stod(fields[18]),
std::stod(fields[19]),
std::stod(fields[1])});
runways->push_back(Runway{fields[17],
std::stod(fields[18]),
std::stod(fields[19]),
std::stod(fields[9]),
std::stod(fields[10]),
std::stod(fields[1])});
runways->push_back(Runway{fields[8],
std::stod(fields[9]),
std::stod(fields[10]),
std::stod(fields[18]),
std::stod(fields[19]),
std::stod(fields[1])});
runways->push_back(Runway{fields[17],
std::stod(fields[18]),
std::stod(fields[19]),
std::stod(fields[9]),
std::stod(fields[10]),
std::stod(fields[1])});
}
void makeGate1300(std::vector<Gate> *gates, std::vector<std::string> fields)
{
std::string gateName;
for (size_t j = 6; j < fields.size() - 1; j++) {
gateName += fields[j] + " ";
}
gateName += fields.back();
gateName = std::regex_replace(gateName, std::regex{","}, "0");
std::string gateName;
for (size_t j = 6; j < fields.size() - 1; j++) {
gateName += fields[j] + " ";
}
gateName += fields.back();
gateName = std::regex_replace(gateName, std::regex{","}, "0");
gates->push_back(
Gate{gateName, std::stod(fields[1]), std::stod(fields[2])});
gates->push_back(Gate{gateName, std::stod(fields[1]), std::stod(fields[2])});
}
+9 -9
View File
@@ -5,13 +5,13 @@ BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
default:
break;
}
return TRUE;
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
default:
break;
}
return TRUE;
}