diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..de09383 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,48 @@ +{ + "configurations": [{ + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "LIN", + "XPLM200", + "XPLM210" + ], + "compilerPath": "/opt/llvm-mingw/bin/clang", + "cStandard": "c11", + "cppStandard": "c++14", + "intelliSenseMode": "linux-clang-x64" + }, { + "name": "Windows", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "IBM", + "XPLM200", + "XPLM210" + ], + "compilerPath": "/opt/llvm-mingw/bin/x86_64-w64-mingw32-clang", + "cStandard": "c11", + "cppStandard": "c++14", + "intelliSenseMode": "windows-clang-x64" + }, + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "APL", + "XPLM200", + "XPLM210" + ], + "compilerPath": "/opt/osxcross/target/bin/o64-clang", + "cStandard": "c11", + "cppStandard": "c++14", + "intelliSenseMode": "macos-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a37b8c..935f4fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,6 @@ option(DEBUG "Debug symbols" OFF) add_subdirectory( ixwebsocket ) -add_subdirectory( - simdata -) add_subdirectory( file ) diff --git a/file/gate.cpp b/file/gate.cpp new file mode 100644 index 0000000..db8d1f3 --- /dev/null +++ b/file/gate.cpp @@ -0,0 +1,26 @@ +#include "simdata/gate.h" + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + Gate::Gate(std::string designator, + struct germanairlinesva::geodata::point center, + std::uint8_t radius) + { + this->designator = designator; + this->center = center; + this->radius = radius; + } + + void Gate::toFile(std::ofstream &out) const + { + writeString(out, this->designator); + write(out, this->center); + write(out, this->radius); + } + } // namespace simdata +} // namespace file +} // namespace germanairlinesva \ No newline at end of file diff --git a/file/include/config/config.hpp b/file/include/config/config.hpp index 2176ed2..93cfbbb 100644 --- a/file/include/config/config.hpp +++ b/file/include/config/config.hpp @@ -25,10 +25,10 @@ namespace file std::string line; while (std::getline(config, line)) { std::vector fields = - germanairlinesva_util::split(line, '='); + germanairlinesva::util::split(line, '='); if (fields.size() >= 2) { - germanairlinesva_util::trim(fields[0]); - germanairlinesva_util::trim(fields[1]); + germanairlinesva::util::trim(fields[0]); + germanairlinesva::util::trim(fields[1]); settings[fields[0]] = fields[1]; } } diff --git a/file/include/recording/recordingEntry.h b/file/include/recording/recordingEntry.h index 165b0f1..a6f64ec 100644 --- a/file/include/recording/recordingEntry.h +++ b/file/include/recording/recordingEntry.h @@ -5,7 +5,7 @@ #include #include -#include "geodata.h" +#include "geodata.hpp" namespace germanairlinesva { @@ -25,7 +25,7 @@ namespace file std::uint32_t time = 0; std::uint16_t altitude = 0; std::uint16_t groundSpeed = 0; - struct germanairlinesva_geodata::point coordinates; + struct germanairlinesva::geodata::point coordinates; std::vector file; public: @@ -33,7 +33,7 @@ namespace file RecordingEntry(std::uint32_t time, std::uint16_t altitude, std::uint16_t groundSpeed, - struct germanairlinesva_geodata::point coordinates); + struct germanairlinesva::geodata::point coordinates); inline const std::uint8_t *getBinaryData() const { return file.data(); } inline std::size_t getBinaryLength() const { return file.size(); } diff --git a/file/include/simdata/gate.h b/file/include/simdata/gate.h new file mode 100644 index 0000000..046cec4 --- /dev/null +++ b/file/include/simdata/gate.h @@ -0,0 +1,67 @@ +#ifndef GERMANAIRLINESVA_FILE_GATE_H +#define GERMANAIRLINESVA_FILE_GATE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "geodata.hpp" +#include "helpers.hpp" + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + /* + * Representation of gate + * Heading in degrees (0...360) + * Radius in metres + * + * Designator must be null terminated + * + * UINT8 | CHAR[] | POINT | UINT8 + * -------+------------+--------+------- + * STRLEN | DESIGNATOR | CENTER | RADIUS + */ + class Gate + { + private: + std::string designator; + struct germanairlinesva::geodata::point center; + std::uint8_t radius; + + public: + Gate(std::string designator, + struct germanairlinesva::geodata::point center, + std::uint8_t radius); + + void toFile(std::ofstream &out) const; + + inline const std::string to_string() const + { + std::ostringstream str; + str << "Gate " << this->designator << " at " << this->center.latitude + << "N " << this->center.longitude << "E, Radius " + << (int)this->radius; + return str.str(); + } + + friend inline std::ostream &operator<<(std::ostream &os, + const Gate &gate) + { + return os << gate.to_string(); + } + }; + } // namespace simdata +} // namespace file +} // namespace germanairlinesva + +#endif \ No newline at end of file diff --git a/file/include/simdata/runway.h b/file/include/simdata/runway.h new file mode 100644 index 0000000..b617d51 --- /dev/null +++ b/file/include/simdata/runway.h @@ -0,0 +1,87 @@ +#ifndef GERMANAIRLINESVA_FILE_RUNWAY_H +#define GERMANAIRLINESVA_FILE_RUNWAY_H + +#include +#include +#include +#include +#include +#include +#include + +#include "geodata.hpp" +#include "helpers.hpp" +#include "util.hpp" + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + /* + * Representation of one runway with supplementary information + * Heading in degrees (0...360) true + * Width and length in meters + * + * Designator must be null terminated + * + * UINT8 | CHAR[] | BOX | UINT8 | UINT16 | UINT16 + * -------+------------+--------+-------+--------+------- + * STRLEN | DESIGNATOR | BOUNDS | WIDTH | LENGTH | TRUHDG + */ + class Runway + { + private: + std::string designator; + struct germanairlinesva::geodata::box bounds; + std::uint8_t width; + std::uint16_t length; + std::uint16_t trueHeading; + std::vector file; + + public: + // From X-Plane or MakeRwys + Runway(std::string designator, + double latitudeStart, + double longitudeStart, + double latitudeEnd, + double longitudeEnd, + double width); + // From database + Runway(std::string designator, + struct germanairlinesva::geodata::box bounds, + std::uint8_t width, + std::uint16_t length, + std::uint16_t trueHeading); + + void toFile(std::ofstream &out) const; + + inline const std::string to_string() const + { + std::ostringstream str; + str << "Runway " << this->designator << " with bounds " + << this->bounds.topLeft.latitude << "N " + << this->bounds.topLeft.longitude << "E, " + << this->bounds.topRight.latitude << "N " + << this->bounds.topRight.longitude << "E, " + << this->bounds.bottomRight.latitude << "N " + << this->bounds.bottomRight.longitude << "E, " + << this->bounds.bottomLeft.latitude << "N " + << this->bounds.bottomLeft.longitude << "E, " + << "Width " << (int)this->width << "m, Length " << this->length + << "m, True Heading " << this->trueHeading << "°"; + return str.str(); + } + + friend inline std::ostream &operator<<(std::ostream &os, + const Runway &runway) + { + return os << runway.to_string(); + } + }; + } // namespace simdata +} // namespace file +} // namespace germanairlinesva + +#endif \ No newline at end of file diff --git a/file/include/simdata/simdataXP.h b/file/include/simdata/simdataXP.h new file mode 100644 index 0000000..fc3fe0f --- /dev/null +++ b/file/include/simdata/simdataXP.h @@ -0,0 +1,41 @@ +#ifndef GERMANAIRLINESVA_FILE_SIMDATAXP_H +#define GERMANAIRLINESVA_FILE_SIMDATAXP_H + +#include +#include +#include + +#include "simdata/gate.h" +#include "simdata/runway.h" +#include "util.hpp" + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + int scan( + const std::string defaultFile, + const std::string sceneryPack, + const std::string logFile, + std::map, std::vector>> + &airports); + + void makeAirport( + const std::string &kind, + std::ifstream &infile, + std::map, std::vector>> + &airports, + std::ofstream &logfile); + void makeGate15(std::vector &gates, + const std::vector &fields); + void makeRunway(std::vector &runways, + const std::vector &fields); + void makeGate1300(std::vector &gates, + const std::vector &fields); + } // namespace simdata +} // namespace file +} // namespace germanairlinesva + +#endif \ No newline at end of file diff --git a/file/include/simdata/simulatorDatabase.hpp b/file/include/simdata/simulatorDatabase.hpp new file mode 100644 index 0000000..86dcc37 --- /dev/null +++ b/file/include/simdata/simulatorDatabase.hpp @@ -0,0 +1,174 @@ +#ifndef GERMANAIRLINESVA_FILE_SIMULATORDATABASE_H +#define GERMANAIRLINESVA_FILE_SIMULATORDATABASE_H + +#include +#include +#include +#include +#include +#include +#include + +#include "simdata/gate.h" +#include "simdata/runway.h" + +/* + * Header + * + * CHAR[5] | UINT8 + * --------+-------- + * VGAS | VERSION + */ +/* + * Airport + * + * UINT8 | CHAR[] | UINT16 | GATE[] | UINT8 | RUNWAY[] + * --------+--------+----------+--------+---------+--------- + * STRLEN | ICAO | NUMGATES | GATES | NUMRWYS | RUNWAYS + */ + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + static inline void toFile( + std::map< + std::string, + std::pair, + std::vector>> + &airports, + const std::string &file) + { + std::uint8_t null = 0; + std::ofstream out(file, std::fstream::binary); + + // File Header, Last member is version + std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1}; + out.write(reinterpret_cast(header), 6); + // Num Airports + std::uint16_t numAirports = airports.size(); + out.write(reinterpret_cast(&numAirports), + sizeof(numAirports)); + // Airport + for (const std::pair< + const std::string, + std::pair, + std::vector>> + &airport : airports) { + std::string icao = airport.first; + std::vector gates = + airport.second.first; + std::vector runways = + airport.second.second; + // ICAO + std::uint8_t icaoLength = icao.length(); + out.write(reinterpret_cast(&icaoLength), + sizeof(icaoLength)); + out.write(icao.c_str(), icaoLength); + out.write(reinterpret_cast(&null), sizeof(null)); + // Gates + std::uint16_t numGates = gates.size(); + out.write(reinterpret_cast(&numGates), sizeof(numGates)); + for (germanairlinesva::file::simdata::Gate &gate : gates) { + gate.toFile(out); + } + // Runways + std::uint8_t numRunways = runways.size(); + out.write(reinterpret_cast(&numRunways), + sizeof(numRunways)); + for (germanairlinesva::file::simdata::Runway &runway : runways) { + runway.toFile(out); + } + } + out.close(); + } + + static inline std::map< + std::string, + std::pair, + std::vector>> + readVersion1(std::ifstream &in) + { + std::map, + std::vector>> + airports; + + std::uint16_t numAirports; + in.read(reinterpret_cast(&numAirports), sizeof(numAirports)); + + for (int i = 0; i < numAirports; i++) { + // ICAO + std::uint8_t icaoLength; + in.read(reinterpret_cast(&icaoLength), sizeof(icaoLength)); + char *icao = static_cast(calloc(icaoLength + 1, sizeof(char))); + in.read(icao, icaoLength + 1); + // Gates + std::uint16_t numGates; + in.read(reinterpret_cast(&numGates), sizeof(numGates)); + for (int j = 0; j < numGates; j++) { + std::string designator = readString(in); + struct germanairlinesva::geodata::point center = + read(in); + std::uint8_t radius = read(in); + + airports[icao].first.emplace_back(designator, center, radius); + } + // Runways + std::uint8_t numRunways; + in.read(reinterpret_cast(&numRunways), sizeof(numRunways)); + for (int j = 0; j < numRunways; j++) { + std::string designator = readString(in); + // Bounds + struct germanairlinesva::geodata::box bounds = + read(in); + std::uint8_t width = read(in); + std::uint16_t length = read(in); + std::uint16_t trueHeading = read(in); + + airports[icao].second.emplace_back(designator, + bounds, + width, + length, + trueHeading); + } + } + + in.close(); + + return airports; + } + + static inline std::map< + std::string, + std::pair, + std::vector>> + fromFile(const std::string &file) + { + std::map, + std::vector>> + airports; + std::ifstream in(file, std::ifstream::binary); + + // File Header + char ident[5]; + in.read(ident, 5); + if (strcmp(ident, "VGAS") != 0) { + throw std::invalid_argument("Wrong file"); + } + std::uint8_t version; + in.read(reinterpret_cast(&version), 1); + + if (version == 1) { + return readVersion1(in); + } + return airports; + } + } // namespace simdata +} // namespace file +} // namespace germanairlinesva + +#endif diff --git a/file/logbook.cpp b/file/logbook.cpp index c9d66c0..9a571b7 100644 --- a/file/logbook.cpp +++ b/file/logbook.cpp @@ -8,7 +8,7 @@ namespace file { Logbook::Logbook() { - if (germanairlinesva_util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) { + if (germanairlinesva::util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) { this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK); } } diff --git a/file/recordingEntry.cpp b/file/recordingEntry.cpp index 35ab58f..39c20ea 100644 --- a/file/recordingEntry.cpp +++ b/file/recordingEntry.cpp @@ -11,7 +11,7 @@ namespace file std::uint32_t time, std::uint16_t altitude, std::uint16_t groundSpeed, - struct germanairlinesva_geodata::point coordinates) + struct germanairlinesva::geodata::point coordinates) { this->time = time; this->altitude = altitude; diff --git a/file/runway.cpp b/file/runway.cpp new file mode 100644 index 0000000..0ccc253 --- /dev/null +++ b/file/runway.cpp @@ -0,0 +1,57 @@ +#include "simdata/runway.h" + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + Runway::Runway(std::string designator, + double latitudeStart, + double longitudeStart, + double latitudeEnd, + double longitudeEnd, + double width) + { + this->designator = designator; + this->width = width; + this->length = germanairlinesva::geodata::distanceEarthD(latitudeStart, + longitudeStart, + latitudeEnd, + longitudeEnd); + this->trueHeading = (std::uint16_t)std::round( + germanairlinesva::geodata::bearingDD(latitudeStart, + longitudeStart, + latitudeEnd, + longitudeEnd)); + this->bounds = germanairlinesva::geodata::calculateBoxDD( + {latitudeStart, longitudeStart}, + {latitudeEnd, longitudeEnd}, + this->trueHeading, + this->width); + } + + Runway::Runway(std::string designator, + germanairlinesva::geodata::box bounds, + std::uint8_t width, + std::uint16_t length, + std::uint16_t trueHeading) + { + this->designator = designator; + this->bounds = bounds; + this->width = width; + this->length = length; + this->trueHeading = trueHeading; + } + + void Runway::toFile(std::ofstream &out) const + { + writeString(out, this->designator); + write(out, this->bounds); + write(out, this->width); + write(out, this->length); + write(out, this->trueHeading); + } + } // namespace simdata +} // namespace file +} // namespace germanairlinesva \ No newline at end of file diff --git a/file/simdataXP.cpp b/file/simdataXP.cpp new file mode 100644 index 0000000..dfdd8d4 --- /dev/null +++ b/file/simdataXP.cpp @@ -0,0 +1,198 @@ +#include "simdata/simdataXP.h" + +namespace germanairlinesva +{ +namespace file +{ + namespace simdata + { + int scan( + const std::string defaultFile, + const std::string sceneryPack, + const std::string logFile, + std::map, std::vector>> + &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::fstream::trunc); + if (!logfile.good()) { + base.close(); + custom.close(); + return 3; + } + + // Default + logfile << " " << defaultFile << std::endl; + makeAirport("DEFAULT", base, airports, logfile); + base.close(); + + std::string line; + size_t pos; + std::vector packs; + while (std::getline(custom, line)) { + if ((pos = line.find("SCENERY_PACK")) != std::string::npos) { + std::string path = + germanairlinesva::util::rtrim_copy(line.substr(pos + 13)) + + "Earth nav data/apt.dat"; + packs.emplace_back(path); + } + } + std::reverse(packs.begin(), packs.end()); + + for (std::string const &path : packs) { + std::ifstream pack(path); + if (pack.good()) { + logfile << " " << path << std::endl; + makeAirport("CUSTOM", pack, airports, logfile); + pack.close(); + } else { + pack.close(); + logfile << "" + << "Could not find " << path << std::endl; + } + } + + logfile << std::endl + << " Total airports: " << airports.size() << std::endl; + + custom.close(); + logfile.close(); + return 0; + } + + void makeAirport( + const std::string &kind, + std::ifstream &infile, + std::map, std::vector>> + &airports, + std::ofstream &logfile) + { + std::string line; + std::string *currentIcao = nullptr; + std::vector tmpGates; + std::vector tmpRunways; + + int apCount = 0; + int validCount = 0; + + while (std::getline(infile, line)) { + std::vector fields = + germanairlinesva::util::split(line, ' '); + fields = germanairlinesva::util::select_T( + 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 " << *currentIcao << " committed" + << std::endl; + } else if (currentIcao != nullptr) { + logfile << "\t " << *currentIcao + << " had no gates or runways" << std::endl; + } + tmpGates = std::vector(); + tmpRunways = std::vector(); + 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 " << 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 " << *currentIcao << " committed" + << std::endl; + } else if (currentIcao != nullptr) { + logfile << "\t " << *currentIcao + << " had no gates or runways" << std::endl; + } + tmpGates = std::vector(); + tmpRunways = std::vector(); + currentIcao = nullptr; + logfile << "\t<" << kind << " SKIPPED> " << line << std::endl; + } else if (currentIcao != nullptr && fields[0] == "100") { + makeRunway(tmpRunways, fields); + logfile << "\t\t " << line << std::endl; + } else if (currentIcao != nullptr && fields[0] == "1300") { + makeGate1300(tmpGates, fields); + logfile << "\t\t " << line << std::endl; + } + } + + if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) { + airports[*currentIcao] = {tmpGates, tmpRunways}; + validCount += 1; + logfile << "\t " << *currentIcao << " committed" << std::endl; + } + logfile << " " << apCount << " airports found, of which " + << validCount << " are valid" << std::endl; + } + + void makeGate15(std::vector &gates, + const std::vector &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"); + struct germanairlinesva::geodata::point pt { + std::stod(fields[1]), std::stod(fields[2]) + }; + gates.emplace_back(gateName, pt, 40); + } + + void makeRunway(std::vector &runways, + const std::vector &fields) + { + runways.emplace_back(fields[8], + std::stod(fields[9]), + std::stod(fields[10]), + std::stod(fields[18]), + std::stod(fields[19]), + std::stod(fields[1])); + runways.emplace_back(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 &gates, + const std::vector &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"); + + struct germanairlinesva::geodata::point pt { + std::stod(fields[1]), std::stod(fields[2]) + }; + gates.emplace_back(gateName, pt, 40); + } + } // namespace simdata +} // namespace file +} // namespace germanairlinesva \ No newline at end of file diff --git a/simdata/CMakeLists.txt b/simdata/CMakeLists.txt deleted file mode 100644 index 53de2d4..0000000 --- a/simdata/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ -file(GLOB simdata CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/simdata/*.cpp) - -add_library(simdata SHARED - ${simdata} -) - -target_include_directories(simdata PRIVATE - ${CMAKE_SOURCE_DIR}/simdata/include - ${CMAKE_SOURCE_DIR}/utilities/include -) - -set_target_properties(simdata PROPERTIES - PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/simdata/include -) -target_compile_options(simdata PRIVATE - -Wall - -Wextra - -pedantic -) -if(DEBUG) - target_compile_options(simdata PRIVATE - -g - ) - target_link_options(simdata PRIVATE - -g - ) -else() - target_compile_options(simdata PRIVATE - -O2 - ) -endif() - -if(APPLE) - message("Building simdata for MacOSX Universal into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}") - - set_target_properties(simdata PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}" - BUILD_WITH_INSTALL_NAME_DIR TRUE - ) - - target_compile_options(simdata PRIVATE - "SHELL:-arch x86_64" - ) - target_link_options(simdata PRIVATE - "SHELL:-arch x86_64" - ) - target_link_libraries(simdata PRIVATE - "-framework Security" - ) -elseif(UNIX) - message("Building simdata for Linux ${BIT} into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}") - - set_target_properties(simdata PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}" - ) - - target_compile_options(simdata PRIVATE - -nodefaultlibs - ) - if() - target_compile_options(simdata PRIVATE - -m32 - ) - target_link_options(simdata PRIVATE - -m32 - ) - endif() -elseif(WIN32) - if (BIT STREQUAL "32") - message("Building simdata for Windows ${BIT} into ${PROJECT_BINARY_DIR}/ESP/${PLUGIN_NAME}") - - set_target_properties(simdata PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/ESP/${PLUGIN_NAME}" - ) - else() - message("Building simdata for Windows ${BIT} into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}") - - set_target_properties(simdata PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}" - ) - endif() - - if(DEBUG) - target_compile_options(simdata PRIVATE - -gcodeview - ) - target_link_options(simdata PRIVATE - -Wl,-pdb= - ) - endif() - target_link_options(simdata PRIVATE - -static-libgcc - -static-libstdc++ - ) -endif() diff --git a/simdata/gate.cpp b/simdata/gate.cpp deleted file mode 100644 index 67fae6a..0000000 --- a/simdata/gate.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "gate.h" - -namespace germanairlinesva_simdata -{ - Gate::Gate(std::string designator, - double latitude, - double longitude, - std::uint8_t radius) - { - this->designator = designator; - this->center = {latitude, longitude}; - this->radius = radius; - - file = std::vector(1 + this->designator.length() + 1 + - sizeof(center) + sizeof(radius), - 0); - std::uint8_t *bufPtr = file.data(); - std::memset(bufPtr, - static_cast(this->designator.length()), - sizeof(std::uint8_t)); - bufPtr++; - std::memcpy(bufPtr, this->designator.c_str(), this->designator.length()); - bufPtr += this->designator.length() + 1; - std::memcpy(bufPtr, &this->center, sizeof(this->center)); - bufPtr += sizeof(this->center); - std::memcpy(bufPtr, &this->radius, sizeof(this->radius)); - } - - // From database - Gate::Gate(std::string designator, - struct germanairlinesva_geodata::point center, - std::uint8_t radius) - { - this->designator = designator; - this->center = center; - this->radius = radius; - - file = std::vector(1 + this->designator.length() + 1 + - sizeof(center) + sizeof(radius), - 0); - std::uint8_t *bufPtr = file.data(); - std::memset(bufPtr, - static_cast(this->designator.length()), - sizeof(std::uint8_t)); - bufPtr++; - std::memcpy(bufPtr, this->designator.c_str(), this->designator.length()); - bufPtr += this->designator.length() + 1; - std::memcpy(bufPtr, &this->center, sizeof(this->center)); - bufPtr += sizeof(this->center); - std::memcpy(bufPtr, &this->radius, sizeof(this->radius)); - } -} // namespace germanairlinesva_simdata \ No newline at end of file diff --git a/simdata/include/gate.h b/simdata/include/gate.h deleted file mode 100644 index 323d9e0..0000000 --- a/simdata/include/gate.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_GATE_H -#define GERMANAIRLINESVA_GACONNECTOR_GATE_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "geodata.h" - -namespace germanairlinesva_simdata -{ - /* - * Representation of gate - * Heading in degrees (0...360) - * Radius in metres - * - * Designator must be null terminated - * - * UINT8 | CHAR[] | POINT | UINT8 - * -------+------------+--------+------- - * STRLEN | DESIGNATOR | CENTER | RADIUS - */ - class Gate - { - private: - std::string designator; - struct germanairlinesva_geodata::point center; - std::uint8_t radius; - std::vector file; - - public: - // From X-Plane or MakeRwys - Gate(std::string designator, - double latitude, - double longitude, - std::uint8_t radius); - // From database - Gate(std::string designator, - struct germanairlinesva_geodata::point center, - std::uint8_t radius); - - inline const std::uint8_t *getBinaryData() const { return file.data(); } - inline std::size_t getBinaryLength() const { return file.size(); } - - inline const std::string to_string() const - { - std::ostringstream str; - str << "Gate " << this->designator << " at " << this->center.latitude - << "N " << this->center.longitude << "E, Radius " - << (int)this->radius; - return str.str(); - } - - friend inline std::ostream &operator<<(std::ostream &os, const Gate &gate) - { - return os << gate.to_string(); - } - }; -} // namespace germanairlinesva_simdata - -#endif \ No newline at end of file diff --git a/simdata/include/runway.h b/simdata/include/runway.h deleted file mode 100644 index fc8aa59..0000000 --- a/simdata/include/runway.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_RUNWAY_H -#define GERMANAIRLINESVA_GACONNECTOR_RUNWAY_H - -#include -#include -#include -#include -#include -#include - -#include "geodata.h" -#include "util.hpp" - -namespace germanairlinesva_simdata -{ - /* - * Representation of one runway with supplementary information - * Heading in degrees (0...360) true - * Width and length in meters - * - * Designator must be null terminated - * - * UINT8 | CHAR[] | BOX | UINT8 | UINT16 | UINT16 - * -------+------------+--------+-------+--------+------- - * STRLEN | DESIGNATOR | BOUNDS | WIDTH | LENGTH | TRUHDG - */ - class Runway - { - private: - std::string designator; - struct germanairlinesva_geodata::box bounds; - std::uint8_t width; - std::uint16_t length; - std::uint16_t trueHeading; - std::vector file; - - public: - // From X-Plane or MakeRwys - Runway(std::string designator, - double latitudeStart, - double longitudeStart, - double latitudeEnd, - double longitudeEnd, - double width); - // From database - Runway(std::string designator, - struct germanairlinesva_geodata::box bounds, - std::uint8_t width, - std::uint16_t length, - std::uint16_t trueHeading); - - inline const std::uint8_t *getBinaryData() const { return file.data(); } - inline std::size_t getBinaryLength() const { return file.size(); } - - inline const std::string to_string() const - { - std::ostringstream str; - str << "Runway " << this->designator << " with bounds " - << this->bounds.topLeft.latitude << "N " - << this->bounds.topLeft.longitude << "E, " - << this->bounds.topRight.latitude << "N " - << this->bounds.topRight.longitude << "E, " - << this->bounds.bottomRight.latitude << "N " - << this->bounds.bottomRight.longitude << "E, " - << this->bounds.bottomLeft.latitude << "N " - << this->bounds.bottomLeft.longitude << "E, " - << "Width " << (int)this->width << "m, Length " << this->length - << "m, True Heading " << this->trueHeading << "°"; - return str.str(); - } - - friend inline std::ostream &operator<<(std::ostream &os, - const Runway &runway) - { - return os << runway.to_string(); - } - }; - - -} // namespace germanairlinesva_simdata - -#endif \ No newline at end of file diff --git a/simdata/include/simdata.h b/simdata/include/simdata.h deleted file mode 100644 index 0db01d3..0000000 --- a/simdata/include/simdata.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_SIMDATA_H -#define GERMANAIRLINESVA_GACONNECTOR_SIMDATA_H - -#include -#include -#include - -#include "gate.h" -#include "runway.h" -#include "util.hpp" - -namespace germanairlinesva_simdata -{ - int scan( - const std::string defaultFile, - const std::string sceneryPack, - const std::string logFile, - std::map, std::vector>> - &airports); - - void makeAirport( - const std::string &kind, - std::ifstream &infile, - std::map, std::vector>> - &airports, - std::ofstream &logfile); - void makeGate15(std::vector &gates, - const std::vector &fields); - void makeRunway(std::vector &runways, - const std::vector &fields); - void makeGate1300(std::vector &gates, - const std::vector &fields); - -} // namespace germanairlinesva_simdata - -#endif \ No newline at end of file diff --git a/simdata/include/simulatorDatabase.hpp b/simdata/include/simulatorDatabase.hpp deleted file mode 100644 index a1faa46..0000000 --- a/simdata/include/simulatorDatabase.hpp +++ /dev/null @@ -1,189 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_SIMULATORDATABASE_H -#define GERMANAIRLINESVA_GACONNECTOR_SIMULATORDATABASE_H - -#include -#include -#include -#include -#include -#include -#include - -#include "gate.h" -#include "runway.h" - -/* - * Header - * - * CHAR[5] | UINT8 - * --------+-------- - * VGAS | VERSION - */ -/* - * Airport - * - * UINT8 | CHAR[] | UINT16 | GATE[] | UINT8 | RUNWAY[] - * --------+--------+----------+--------+---------+--------- - * STRLEN | ICAO | NUMGATES | GATES | NUMRWYS | RUNWAYS - */ - -namespace germanairlinesva_simdata -{ - static inline void - toFile(std::map, - std::vector>> - &airports, - const std::string &file) - { - std::uint8_t null = 0; - std::ofstream out(file, std::fstream::binary); - - // File Header, Last member is version - std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1}; - out.write(reinterpret_cast(header), 6); - // Num Airports - std::uint16_t numAirports = airports.size(); - out.write(reinterpret_cast(&numAirports), - sizeof(numAirports)); - // Airport - for (const std::pair< - const std::string, - std::pair, - std::vector>> - &airport : airports) { - std::string icao = airport.first; - std::vector gates = airport.second.first; - std::vector runways = - airport.second.second; - // ICAO - std::uint8_t icaoLength = icao.length(); - out.write(reinterpret_cast(&icaoLength), - sizeof(icaoLength)); - out.write(icao.c_str(), icaoLength); - out.write(reinterpret_cast(&null), sizeof(null)); - // Gates - std::uint16_t numGates = gates.size(); - out.write(reinterpret_cast(&numGates), sizeof(numGates)); - for (germanairlinesva_simdata::Gate &gate : gates) { - out.write(reinterpret_cast(gate.getBinaryData()), - (std::streamsize)gate.getBinaryLength()); - } - // Runways - std::uint8_t numRunways = runways.size(); - out.write(reinterpret_cast(&numRunways), - sizeof(numRunways)); - for (germanairlinesva_simdata::Runway &runway : runways) { - out.write(reinterpret_cast(runway.getBinaryData()), - (std::streamsize)runway.getBinaryLength()); - } - } - out.close(); - } - - static inline std::map< - std::string, - std::pair, - std::vector>> - readVersion1(std::ifstream &in) - { - std::map, - std::vector>> - airports; - - std::uint16_t numAirports; - in.read(reinterpret_cast(&numAirports), sizeof(numAirports)); - - for (int i = 0; i < numAirports; i++) { - // ICAO - std::uint8_t icaoLength; - in.read(reinterpret_cast(&icaoLength), sizeof(icaoLength)); - char *icao = static_cast(calloc(icaoLength + 1, sizeof(char))); - in.read(icao, icaoLength + 1); - // Gates - std::uint16_t numGates; - in.read(reinterpret_cast(&numGates), sizeof(numGates)); - for (int j = 0; j < numGates; j++) { - // ICAO - std::uint8_t designatorLength; - in.read(reinterpret_cast(&designatorLength), - sizeof(designatorLength)); - char *designator = - static_cast(calloc(designatorLength + 1, sizeof(char))); - in.read(designator, designatorLength + 1); - // Center - struct germanairlinesva_geodata::point center; - in.read(reinterpret_cast(¢er), sizeof(center)); - // Radius - std::uint8_t radius; - in.read(reinterpret_cast(&radius), sizeof(radius)); - - airports[icao].first.emplace_back(designator, center, radius); - } - // Runways - std::uint8_t numRunways; - in.read(reinterpret_cast(&numRunways), sizeof(numRunways)); - for (int j = 0; j < numRunways; j++) { - // ICAO - std::uint8_t designatorLength; - in.read(reinterpret_cast(&designatorLength), - sizeof(designatorLength)); - char *designator = - static_cast(calloc(designatorLength + 1, sizeof(char))); - in.read(designator, designatorLength + 1); - // Bounds - struct germanairlinesva_geodata::box bounds; - in.read(reinterpret_cast(&bounds), sizeof(bounds)); - // Width - std::uint8_t width; - in.read(reinterpret_cast(&width), sizeof(width)); - // Length - std::uint16_t length; - in.read(reinterpret_cast(&length), sizeof(length)); - // True Heading - std::uint16_t trueHeading; - in.read(reinterpret_cast(&trueHeading), sizeof(trueHeading)); - - airports[icao].second.emplace_back(designator, - bounds, - width, - length, - trueHeading); - } - } - - in.close(); - - return airports; - } - - static inline std::map< - std::string, - std::pair, - std::vector>> - fromFile(const std::string &file) - { - std::map, - std::vector>> - airports; - std::ifstream in(file, std::ifstream::binary); - - // File Header - char ident[5]; - in.read(ident, 5); - if (strcmp(ident, "VGAS") != 0) { - throw std::invalid_argument("Wrong file"); - } - std::uint8_t version; - in.read(reinterpret_cast(&version), 1); - - if (version == 1) { - return readVersion1(in); - } - return airports; - } -} // namespace germanairlinesva_simdata - -#endif diff --git a/simdata/runway.cpp b/simdata/runway.cpp deleted file mode 100644 index 50665b0..0000000 --- a/simdata/runway.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "runway.h" -namespace germanairlinesva_simdata -{ - Runway::Runway(std::string designator, - double latitudeStart, - double longitudeStart, - double latitudeEnd, - double longitudeEnd, - double width) - { - this->designator = designator; - this->width = width; - this->length = germanairlinesva_geodata::distanceEarthD(latitudeStart, - longitudeStart, - latitudeEnd, - longitudeEnd); - this->trueHeading = (std::uint16_t)std::round( - germanairlinesva_geodata::bearingDD(latitudeStart, - longitudeStart, - latitudeEnd, - longitudeEnd)); - this->bounds = germanairlinesva_geodata::calculateBoxDD( - {latitudeStart, longitudeStart}, - {latitudeEnd, longitudeEnd}, - this->trueHeading, - this->width); - - file = std::vector( - 1 + this->designator.length() + 1 + sizeof(this->bounds) + - sizeof(this->width) + sizeof(this->length) + - sizeof(this->trueHeading), - 0); - std::uint8_t *bufPtr = file.data(); - std::memset(bufPtr, - static_cast(this->designator.length()), - sizeof(std::uint8_t)); - bufPtr++; - std::memcpy(bufPtr, this->designator.c_str(), this->designator.length()); - bufPtr += this->designator.length() + 1; - std::memcpy(bufPtr, &this->bounds, sizeof(this->bounds)); - bufPtr += sizeof(this->bounds); - std::memcpy(bufPtr, &this->width, sizeof(this->width)); - bufPtr += sizeof(this->width); - std::memcpy(bufPtr, &this->length, sizeof(this->length)); - bufPtr += sizeof(this->length); - std::memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading)); - } - - Runway::Runway(std::string designator, - germanairlinesva_geodata::box bounds, - std::uint8_t width, - std::uint16_t length, - std::uint16_t trueHeading) - { - this->designator = designator; - this->bounds = bounds; - this->width = width; - this->length = length; - this->trueHeading = trueHeading; - - file = std::vector( - 1 + this->designator.length() + 1 + sizeof(this->bounds) + - sizeof(this->width) + sizeof(this->length) + - sizeof(this->trueHeading), - 0); - std::uint8_t *bufPtr = file.data(); - std::memset(bufPtr, - static_cast(this->designator.length()), - sizeof(std::uint8_t)); - bufPtr++; - std::memcpy(bufPtr, this->designator.c_str(), this->designator.length()); - bufPtr += this->designator.length() + 1; - std::memcpy(bufPtr, &this->bounds, sizeof(this->bounds)); - bufPtr += sizeof(this->bounds); - std::memcpy(bufPtr, &this->width, sizeof(this->width)); - bufPtr += sizeof(this->width); - std::memcpy(bufPtr, &this->length, sizeof(this->length)); - bufPtr += sizeof(this->length); - std::memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading)); - } -} // namespace germanairlinesva_simdata \ No newline at end of file diff --git a/simdata/simdata.cpp b/simdata/simdata.cpp deleted file mode 100644 index 7052306..0000000 --- a/simdata/simdata.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include "simdata.h" - -namespace germanairlinesva_simdata -{ - int scan( - const std::string defaultFile, - const std::string sceneryPack, - const std::string logFile, - std::map, std::vector>> - &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::fstream::trunc); - if (!logfile.good()) { - base.close(); - custom.close(); - return 3; - } - - // Default - logfile << " " << defaultFile << std::endl; - makeAirport("DEFAULT", base, airports, logfile); - base.close(); - - std::string line; - size_t pos; - std::vector packs; - while (std::getline(custom, line)) { - if ((pos = line.find("SCENERY_PACK")) != std::string::npos) { - std::string path = - germanairlinesva_util::rtrim_copy(line.substr(pos + 13)) + - "Earth nav data/apt.dat"; - packs.emplace_back(path); - } - } - std::reverse(packs.begin(), packs.end()); - - for (std::string const &path : packs) { - std::ifstream pack(path); - if (pack.good()) { - logfile << " " << path << std::endl; - makeAirport("CUSTOM", pack, airports, logfile); - pack.close(); - } else { - pack.close(); - logfile << "" - << "Could not find " << path << std::endl; - } - } - - logfile << std::endl - << " Total airports: " << airports.size() << std::endl; - - custom.close(); - logfile.close(); - return 0; - } - - void makeAirport( - const std::string &kind, - std::ifstream &infile, - std::map, std::vector>> - &airports, - std::ofstream &logfile) - { - std::string line; - std::string *currentIcao = nullptr; - std::vector tmpGates; - std::vector tmpRunways; - - int apCount = 0; - int validCount = 0; - - while (std::getline(infile, line)) { - std::vector fields = germanairlinesva_util::split(line, ' '); - fields = germanairlinesva_util::select_T( - 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 " << *currentIcao << " committed" << std::endl; - } else if (currentIcao != nullptr) { - logfile << "\t " << *currentIcao << " had no gates or runways" - << std::endl; - } - tmpGates = std::vector(); - tmpRunways = std::vector(); - 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 " << 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 " << *currentIcao << " committed" << std::endl; - } else if (currentIcao != nullptr) { - logfile << "\t " << *currentIcao << " had no gates or runways" - << std::endl; - } - tmpGates = std::vector(); - tmpRunways = std::vector(); - currentIcao = nullptr; - logfile << "\t<" << kind << " SKIPPED> " << line << std::endl; - } else if (currentIcao != nullptr && fields[0] == "100") { - makeRunway(tmpRunways, fields); - logfile << "\t\t " << line << std::endl; - } else if (currentIcao != nullptr && fields[0] == "1300") { - makeGate1300(tmpGates, fields); - logfile << "\t\t " << line << std::endl; - } - } - - if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) { - airports[*currentIcao] = {tmpGates, tmpRunways}; - validCount += 1; - logfile << "\t " << *currentIcao << " committed" << std::endl; - } - logfile << " " << apCount << " airports found, of which " - << validCount << " are valid" << std::endl; - } - - void makeGate15(std::vector &gates, - const std::vector &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"); - - gates.emplace_back(gateName, - std::stod(fields[1]), - std::stod(fields[2]), - 40); - } - - void makeRunway(std::vector &runways, - const std::vector &fields) - { - runways.emplace_back(fields[8], - std::stod(fields[9]), - std::stod(fields[10]), - std::stod(fields[18]), - std::stod(fields[19]), - std::stod(fields[1])); - runways.emplace_back(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 &gates, - const std::vector &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"); - - gates.emplace_back(gateName, - std::stod(fields[1]), - std::stod(fields[2]), - 40); - } -} // namespace germanairlinesva_simdata \ No newline at end of file diff --git a/simdata/include/geodata.h b/utilities/include/geodata.hpp similarity index 98% rename from simdata/include/geodata.h rename to utilities/include/geodata.hpp index 6c7dc29..4787428 100644 --- a/simdata/include/geodata.h +++ b/utilities/include/geodata.hpp @@ -13,7 +13,9 @@ #include -namespace germanairlinesva_geodata +namespace germanairlinesva +{ +namespace geodata { #pragma pack(push) #pragma pack(1) @@ -205,7 +207,7 @@ namespace germanairlinesva_geodata return {primaryTop, secondaryTop, secondaryBottom, primaryBottom}; } - -} // namespace germanairlinesva_geodata +} // namespace geodata +} // namespace germanairlinesva #endif \ No newline at end of file diff --git a/utilities/include/util.hpp b/utilities/include/util.hpp index b5e431b..4ca61e4 100644 --- a/utilities/include/util.hpp +++ b/utilities/include/util.hpp @@ -39,7 +39,9 @@ #include -namespace germanairlinesva_util +namespace germanairlinesva +{ +namespace util { template static inline std::vector @@ -297,7 +299,7 @@ namespace germanairlinesva_util return result; } - -} // namespace germanairlinesva_util +} // namespace util +} // namespace germanairlinesva #endif diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index 102ea55..31a5504 100644 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -2,112 +2,112 @@ namespace germanairlinesva_websocket { - Websocket::Websocket(std::string host, - std::string user, - std::function toLog) - : host(host), user(user), toLog(std::move(toLog)) - { +Websocket::Websocket(std::string host, + std::string user, + std::function toLog) + : host(host), user(user), toLog(std::move(toLog)) +{ #ifdef IBM - // Required on Windows - ix::initNetSystem(); + // Required on Windows + ix::initNetSystem(); #endif - this->webSocket = new ix::WebSocket(); - this->webSocket->enableAutomaticReconnection(); - this->webSocket->setUrl(host); - this->webSocket->setOnMessageCallback( - [this](const ix::WebSocketMessagePtr &msg) { - this->onClientMessageCallback(msg); - }); - this->webSocket->start(); - } + this->webSocket = new ix::WebSocket(); + this->webSocket->enableAutomaticReconnection(); + this->webSocket->setUrl(host); + this->webSocket->setOnMessageCallback( + [this](const ix::WebSocketMessagePtr &msg) { + this->onClientMessageCallback(msg); + }); + this->webSocket->start(); +} - Websocket::~Websocket() - { - this->webSocket->stop(); - this->toLog("WebSocket stopped"); +Websocket::~Websocket() +{ + this->webSocket->stop(); + this->toLog("WebSocket stopped"); #ifdef IBM - // Required on Windows - ix::uninitNetSystem(); + // Required on Windows + ix::uninitNetSystem(); #endif - } +} - void Websocket::onClientMessageCallback(const ix::WebSocketMessagePtr &msg) - { - if (msg->type == ix::WebSocketMessageType::Open) { +void Websocket::onClientMessageCallback(const ix::WebSocketMessagePtr &msg) +{ + if (msg->type == ix::WebSocketMessageType::Open) { + std::stringstream debug_msg; + + debug_msg << std::endl << "New connection" << std::endl; + debug_msg << "Uri: " << msg->openInfo.uri << std::endl; + debug_msg << "Headers:" << std::endl; + for (const auto &it : msg->openInfo.headers) { + debug_msg << it.first << ": " << it.second << std::endl; + } + + this->toLog(debug_msg.str()); + + this->webSocket->send("MASTER:" + user); + this->toLog("Connecting as " + user); + } else if (msg->type == ix::WebSocketMessageType::Close) { + if (msg->closeInfo.reason.compare("DUPLICATE")) { + this->webSocket->disableAutomaticReconnection(); + + this->toLog("Disconnected due to beeing a duplicate simualtor"); + } else { std::stringstream debug_msg; - debug_msg << std::endl << "New connection" << std::endl; - debug_msg << "Uri: " << msg->openInfo.uri << std::endl; - debug_msg << "Headers:" << std::endl; - for (const auto &it : msg->openInfo.headers) { - debug_msg << it.first << ": " << it.second << std::endl; - } + debug_msg << std::endl << "Connection closed" << std::endl; + debug_msg << "Code: " << msg->closeInfo.code << std::endl; + debug_msg << "Reason: " << msg->closeInfo.reason << std::endl; + debug_msg << "Remote: " << msg->closeInfo.remote << std::endl; this->toLog(debug_msg.str()); + } + } else if (msg->type == ix::WebSocketMessageType::Error) { + std::stringstream debug_msg; - this->webSocket->send("MASTER:" + user); - this->toLog("Connecting as " + user); - } else if (msg->type == ix::WebSocketMessageType::Close) { - if (msg->closeInfo.reason.compare("DUPLICATE")) { - this->webSocket->disableAutomaticReconnection(); + debug_msg << std::endl << "Connection error" << std::endl; + debug_msg << "Decompression: " << msg->errorInfo.decompressionError + << std::endl; + debug_msg << "HTTP status: " << msg->errorInfo.http_status << std::endl; + debug_msg << "Reason: " << msg->errorInfo.reason << std::endl; + debug_msg << "Retries: " << msg->errorInfo.retries << std::endl; + debug_msg << "Wait time: " << msg->errorInfo.wait_time << std::endl; - this->toLog("Disconnected due to beeing a duplicate simualtor"); - } else { - std::stringstream debug_msg; + this->toLog(debug_msg.str()); + } else if (msg->type == ix::WebSocketMessageType::Message) { + if (!msg->str.empty()) { + this->toLog(msg->str); + } + } +} - debug_msg << std::endl << "Connection closed" << std::endl; - debug_msg << "Code: " << msg->closeInfo.code << std::endl; - debug_msg << "Reason: " << msg->closeInfo.reason << std::endl; - debug_msg << "Remote: " << msg->closeInfo.remote << std::endl; - - this->toLog(debug_msg.str()); - } - } else if (msg->type == ix::WebSocketMessageType::Error) { - std::stringstream debug_msg; - - debug_msg << std::endl << "Connection error" << std::endl; - debug_msg << "Decompression: " << msg->errorInfo.decompressionError - << std::endl; - debug_msg << "HTTP status: " << msg->errorInfo.http_status << std::endl; - debug_msg << "Reason: " << msg->errorInfo.reason << std::endl; - debug_msg << "Retries: " << msg->errorInfo.retries << std::endl; - debug_msg << "Wait time: " << msg->errorInfo.wait_time << std::endl; - - this->toLog(debug_msg.str()); - } else if (msg->type == ix::WebSocketMessageType::Message) { - if (!msg->str.empty()) { - this->toLog(msg->str); - } +void Websocket::sendData(data &d) +{ + if (strcmp(d.path, this->lastPath) != 0) { + strcpy(this->lastPath, d.path); + if (germanairlinesva::util::generateMD5(d.path, + this->lastHash, + this->toLog)) { + strcpy(this->lastHash, "NOT SET"); } } - void Websocket::sendData(data &d) - { - if (strcmp(d.path, this->lastPath) != 0) { - strcpy(this->lastPath, d.path); - if (germanairlinesva_util::generateMD5(d.path, - this->lastHash, - this->toLog)) { - strcpy(this->lastHash, "NOT SET"); - } - } + nlohmann::json json = { + {"altitude", d.alt}, + {"vs", d.vs}, + {"ias", d.ias}, + {"magHdg", d.magHeading}, + {"truHdg", d.truHdg}, + {"totFuel", d.totFuelKg}, + {"fuelFlow", d.ff}, + {"hash", this->lastHash}, + }; - nlohmann::json json = { - {"altitude", d.alt}, - {"vs", d.vs}, - {"ias", d.ias}, - {"magHdg", d.magHeading}, - {"truHdg", d.truHdg}, - {"totFuel", d.totFuelKg}, - {"fuelFlow", d.ff}, - {"hash", this->lastHash}, - }; - - if (this->webSocket != nullptr) { - std::ostringstream msg; - msg << "SEND:" << user << ":" << json.dump(); - this->webSocket->send(msg.str(), false); - } + if (this->webSocket != nullptr) { + std::ostringstream msg; + msg << "SEND:" << user << ":" << json.dump(); + this->webSocket->send(msg.str(), false); } +} } // namespace germanairlinesva_websocket \ No newline at end of file diff --git a/xplugin/CMakeLists.txt b/xplugin/CMakeLists.txt index 2a0ecbb..e226651 100644 --- a/xplugin/CMakeLists.txt +++ b/xplugin/CMakeLists.txt @@ -117,6 +117,5 @@ elseif(WIN32) endif() target_link_libraries(germanairlinesva_xplugin PRIVATE - simdata ixwebsocket ) diff --git a/xplugin/include/main.h b/xplugin/include/main.h index 4e37b94..a0c01e0 100644 --- a/xplugin/include/main.h +++ b/xplugin/include/main.h @@ -5,8 +5,8 @@ #include "constants.h" #include "logbook/logbook.h" #include "recording/recording.h" -#include "simdata.h" -#include "simulatorDatabase.hpp" +#include "simdata/simdataXP.h" +#include "simdata/simulatorDatabase.hpp" #include "util.hpp" #include "websocket.h" diff --git a/xplugin/main.cpp b/xplugin/main.cpp index f1695c0..526dc1c 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -12,8 +12,8 @@ std::atomic wantsExit; std::map configuration; std::map, - std::vector>> + std::pair, + std::vector>> airports; germanairlinesva_websocket::Websocket *connector; int xplaneVersion; @@ -130,19 +130,20 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) toLog("WebSocket started"); char hash[2 * MD5LEN + 1] = ""; - if (germanairlinesva_util::generateMD5(XPLANE_CUSTOM_SCENERY, hash, toLog) == + if (germanairlinesva::util::generateMD5(XPLANE_CUSTOM_SCENERY, hash, toLog) == 0) { if (strcmp(configuration["scenery"].c_str(), hash) != 0 || - !germanairlinesva_util::fileExists( + !germanairlinesva::util::fileExists( XPLANE_PLUGIN_DIRECTORY SIMDATABASE)) { scan(xplaneVersion < 12000 ? XPLANE11_BASE_SCENERY : XPLANE12_BASE_SCENERY, XPLANE_CUSTOM_SCENERY, XPLANE_PLUGIN_DIRECTORY "log.txt", airports); - germanairlinesva_simdata::toFile(airports, - XPLANE_PLUGIN_DIRECTORY SIMDATABASE); + germanairlinesva::file::simdata::toFile( + airports, + XPLANE_PLUGIN_DIRECTORY SIMDATABASE); configuration["scenery"] = hash; germanairlinesva::file::config::writeConfig( @@ -150,7 +151,7 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) XPLANE_PLUGIN_DIRECTORY CONFIG); toLog("Sim Database updated"); } else { - airports = germanairlinesva_simdata::fromFile( + airports = germanairlinesva::file::simdata::fromFile( XPLANE_PLUGIN_DIRECTORY SIMDATABASE); toLog("Sim Database loaded"); } @@ -279,7 +280,7 @@ float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon) void serverWorker() { - germanairlinesva_util::setThreadName("GAServerWorker"); + germanairlinesva::util::setThreadName("GAServerWorker"); while (!wantsExit) { struct germanairlinesva_websocket::data copy; @@ -297,7 +298,7 @@ void serverWorker() void recordingWorker() { - germanairlinesva_util::setThreadName("GARecordingWorker"); + germanairlinesva::util::setThreadName("GARecordingWorker"); germanairlinesva::file::recording::RecordingEntry lastPath; std::uint32_t segment = 0;