diff --git a/esp/include/_simconnect.h b/esp/include/_simconnect.h index 52cbdb5..8d9dff2 100644 --- a/esp/include/_simconnect.h +++ b/esp/include/_simconnect.h @@ -100,7 +100,7 @@ class SimConnect bool pausedMenu; bool paused; std::mutex mutex; - struct germanairlinesva::websocket::data simData; + struct germanairlinesva::gaconnector::websocket::data simData; std::shared_ptr configuration; std::function toLog; @@ -117,7 +117,7 @@ class SimConnect ~SimConnect(); bool isConnected() const; const std::string getVersion() const; - void getData(struct germanairlinesva::websocket::data *data); + void getData(struct germanairlinesva::gaconnector::websocket::data *data); void getStates() const; void handleMessage(); }; diff --git a/esp/include/main.h b/esp/include/main.h index b9629d0..3c2bc07 100644 --- a/esp/include/main.h +++ b/esp/include/main.h @@ -16,11 +16,11 @@ #include #include +#include "_simconnect.h" #include "config/config.hpp" #include "constants.h" #include "logbook/logbook.hpp" #include "recording/recording.hpp" -#include "_simconnect.h" #include "simdata/simDatabase.hpp" WINBOOL addNotifyIcon(HWND hWnd); diff --git a/esp/main.cpp b/esp/main.cpp index 20b1dff..1c4e3ee 100644 --- a/esp/main.cpp +++ b/esp/main.cpp @@ -12,10 +12,10 @@ std::atomic wantsExit; std::shared_ptr configuration; std::unique_ptr database; -std::unique_ptr connector; +std::unique_ptr connector; std::unique_ptr simConnect; -struct germanairlinesva::websocket::data toSend; +struct germanairlinesva::gaconnector::websocket::data toSend; germanairlinesva::file::recording::Recording p; // The Window Procedure @@ -127,10 +127,11 @@ int WINAPI WinMain(HINSTANCE hInstance, configuration = std::make_unique(); toLog("Config loaded"); - connector = std::make_unique( - "wss://ws.hofmannnet.myhome-server.de:8000", - configuration->getUser(), - toLog); + connector = + std::make_unique( + "wss://ws.hofmannnet.myhome-server.de:8000", + configuration->getUser(), + toLog); toLog("WebSocket started"); #ifndef MSFS @@ -153,7 +154,8 @@ int WINAPI WinMain(HINSTANCE hInstance, CoTaskMemFree(folder); char hash[2 * MD5LEN + 1] = ""; - if (germanairlinesva::util::generateMD5(path.c_str(), hash, toLog) == 0) { + if (germanairlinesva::utilities::generateMD5(path.c_str(), hash, toLog) == + 0) { database = std::make_unique( FSX_VERSION, hash, @@ -324,13 +326,13 @@ void end(HWND hWnd) void serverWorker() { - germanairlinesva::util::setThreadName("GAServerWorker"); + germanairlinesva::utilities::setThreadName("GAServerWorker"); while (!wantsExit) { simConnect->getStates(); - struct germanairlinesva::websocket::data *copy = - new germanairlinesva::websocket::data(); + struct germanairlinesva::gaconnector::websocket::data *copy = + new germanairlinesva::gaconnector::websocket::data(); { const std::lock_guard lock(mutex); @@ -347,7 +349,7 @@ void serverWorker() void recordingWorker() { - germanairlinesva::util::setThreadName("GARecordingWorker"); + germanairlinesva::utilities::setThreadName("GARecordingWorker"); germanairlinesva::file::recording::RecordingEntry lastPath; std::uint32_t segment = 0; @@ -356,8 +358,8 @@ void recordingWorker() auto rwys = ap.second; while (!wantsExit) { - struct germanairlinesva::websocket::data *copy = - new germanairlinesva::websocket::data(); + struct germanairlinesva::gaconnector::websocket::data *copy = + new germanairlinesva::gaconnector::websocket::data(); { const std::lock_guard lock(mutex); diff --git a/esp/simconnect.cpp b/esp/simconnect.cpp index 20ec718..b6244a0 100644 --- a/esp/simconnect.cpp +++ b/esp/simconnect.cpp @@ -323,7 +323,8 @@ const std::string SimConnect::getVersion() const } } -void SimConnect::getData(struct germanairlinesva::websocket::data *data) +void SimConnect::getData( + struct germanairlinesva::gaconnector::websocket::data *data) { const std::lock_guard lock(this->mutex); memcpy(data, &this->simData, sizeof(this->simData)); diff --git a/file/include/config/config.hpp b/file/include/config/config.hpp index 2e22fed..9b52c32 100644 --- a/file/include/config/config.hpp +++ b/file/include/config/config.hpp @@ -51,10 +51,10 @@ namespace file std::ifstream in(BASE_DIRECTORY CONFIG); std::string line; while (std::getline(in, line)) { - std::vector fields = util::split(line, '='); + std::vector fields = utilities::split(line, '='); if (fields.size() >= 2) { - util::trim(fields[0]); - util::trim(fields[1]); + utilities::trim(fields[0]); + utilities::trim(fields[1]); if (fields[0] == "scenery") { this->scenery = fields[1]; } else if (fields[0] == "user") { diff --git a/file/include/logbook/logbook.hpp b/file/include/logbook/logbook.hpp index d4cf131..ef57e07 100644 --- a/file/include/logbook/logbook.hpp +++ b/file/include/logbook/logbook.hpp @@ -117,7 +117,7 @@ namespace file public: inline Logbook() { - if (util::fileExists(BASE_DIRECTORY LOGBOOK)) { + if (utilities::fileExists(BASE_DIRECTORY LOGBOOK)) { this->fromFile(); } } diff --git a/file/include/recording/recordingEntry.hpp b/file/include/recording/recordingEntry.hpp index e3567c6..56bebe7 100644 --- a/file/include/recording/recordingEntry.hpp +++ b/file/include/recording/recordingEntry.hpp @@ -1,5 +1,5 @@ -#ifndef GERMANAIRLINESVA_FILE_RECORDINGENTRY_H -#define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H +#ifndef GERMANAIRLINESVA_FILE_RECORDING_RECORDINGENTRY_H +#define GERMANAIRLINESVA_FILE_RECORDING_RECORDINGENTRY_H #include #include @@ -26,14 +26,14 @@ namespace file std::uint32_t time; std::uint16_t altitude = 0; std::uint16_t groundSpeed = 0; - struct geodata::point coordinates = {NAN, NAN}; + struct utilities::geodata::point coordinates = {NAN, NAN}; public: inline RecordingEntry() = default; inline RecordingEntry(std::uint32_t time, std::uint16_t altitude, std::uint16_t groundSpeed, - struct geodata::point coordinates) + struct utilities::geodata::point coordinates) : time(time), altitude(altitude), groundSpeed(groundSpeed), coordinates(coordinates) { diff --git a/file/include/simdata/gate.hpp b/file/include/simdata/gate.hpp index 0c8eb34..2ca8069 100644 --- a/file/include/simdata/gate.hpp +++ b/file/include/simdata/gate.hpp @@ -32,7 +32,7 @@ namespace file { private: std::string designator; - struct geodata::point center; + struct utilities::geodata::point center; std::uint8_t radius; public: @@ -45,7 +45,7 @@ namespace file radius(radius){}; // From Database inline Gate(std::string designator, - struct geodata::point center, + struct utilities::geodata::point center, std::uint8_t radius) : designator(designator), center(center), radius(radius){}; @@ -56,9 +56,9 @@ namespace file writeradius)>(out, this->radius); } - inline bool contains(geodata::point coordinates) const + inline bool contains(utilities::geodata::point coordinates) const { - return geodata::distanceEarthP(this->center, coordinates); + return utilities::geodata::distanceEarthP(this->center, coordinates); } inline const std::string to_string() const diff --git a/file/include/simdata/runway.hpp b/file/include/simdata/runway.hpp index 944c7dc..a01fde6 100644 --- a/file/include/simdata/runway.hpp +++ b/file/include/simdata/runway.hpp @@ -34,7 +34,7 @@ namespace file { private: std::string designator; - struct geodata::box bounds; + struct utilities::geodata::box bounds; std::uint8_t width; std::uint16_t length; double trueHeading; @@ -49,52 +49,54 @@ namespace file double width) : designator(designator), width(width) { - this->length = geodata::distanceEarthD(latitudeStart, - longitudeStart, - latitudeEnd, - longitudeEnd); - this->trueHeading = geodata::bearingDD(latitudeStart, - longitudeStart, - latitudeEnd, - longitudeEnd); - this->bounds = - geodata::calculateBoxDD({latitudeStart, longitudeStart}, - {latitudeEnd, longitudeEnd}, - this->trueHeading, - this->width); + this->length = utilities::geodata::distanceEarthD(latitudeStart, + longitudeStart, + latitudeEnd, + longitudeEnd); + this->trueHeading = utilities::geodata::bearingDD(latitudeStart, + longitudeStart, + latitudeEnd, + longitudeEnd); + this->bounds = utilities::geodata::calculateBoxDD( + {latitudeStart, longitudeStart}, + {latitudeEnd, longitudeEnd}, + this->trueHeading, + this->width); }; // From MakeRwys inline Runway(std::string designator, - struct geodata::point start, + struct utilities::geodata::point start, double width, double length, double trueHeading) : designator(designator), width(width), length(length), trueHeading(trueHeading) { - geodata::point end = - geodata::calculatePointDD(start, trueHeading, length); + utilities::geodata::point end = + utilities::geodata::calculatePointDD(start, trueHeading, length); - this->bounds = - geodata::calculateBoxDD(start, end, trueHeading, width); + this->bounds = utilities::geodata::calculateBoxDD(start, + end, + trueHeading, + width); }; // From database inline Runway(std::string designator, - struct geodata::box bounds, + struct utilities::geodata::box bounds, std::uint8_t width, std::uint16_t length, double trueHeading) : designator(designator), bounds(bounds), width(width), length(length), trueHeading(trueHeading){}; - inline bool containsPoint(const geodata::point point) const + inline bool containsPoint(const utilities::geodata::point point) const { size_t j = 3; bool c = false; - std::vector poly{this->bounds.topLeft, - this->bounds.topRight, - this->bounds.bottomRight, - this->bounds.bottomLeft}; + std::vector poly{this->bounds.topLeft, + this->bounds.topRight, + this->bounds.bottomRight, + this->bounds.bottomLeft}; for (size_t i = 0; i < poly.size(); i++) { if ((point.latitude == poly[i].latitude) && diff --git a/file/include/simdata/simDatabase.hpp b/file/include/simdata/simDatabase.hpp index 8f5ad7c..8874984 100644 --- a/file/include/simdata/simDatabase.hpp +++ b/file/include/simdata/simDatabase.hpp @@ -19,7 +19,7 @@ #ifdef XP #include "simdata/simdataXP.hpp" #endif -#ifndef MSFS +#if not defined(XP) && not defined(MSFS) #include "simdata/simdataESP.hpp" #endif @@ -61,7 +61,8 @@ namespace file std::uint16_t numGates = read(in); for (int j = 0; j < numGates; j++) { std::string designator = readString(in); - struct geodata::point center = read(in); + struct utilities::geodata::point center = + read(in); std::uint8_t radius = read(in); this->airports[icao].first.emplace_back(designator, @@ -73,7 +74,8 @@ namespace file for (int j = 0; j < numRunways; j++) { std::string designator = readString(in); // Center - struct geodata::box bounds = read(in); + struct utilities::geodata::box bounds = + read(in); std::uint8_t width = read(in); std::uint16_t length = read(in); double trueHeading = read(in); @@ -113,7 +115,7 @@ namespace file std::function toLog) { if (strcmp(configuration->getScenery().c_str(), hash) != 0 || - !util::fileExists(BASE_DIRECTORY SIMDATABASE)) { + !utilities::fileExists(BASE_DIRECTORY SIMDATABASE)) { #ifdef XP scan(simVersion < 12000 ? XPLANE11_BASE_SCENERY : XPLANE12_BASE_SCENERY, diff --git a/file/include/simdata/simdataESP.hpp b/file/include/simdata/simdataESP.hpp index 0d0a31c..6f36649 100644 --- a/file/include/simdata/simdataESP.hpp +++ b/file/include/simdata/simdataESP.hpp @@ -1,5 +1,5 @@ -#ifndef GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H -#define GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H +#ifndef GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAESP_H +#define GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAESP_H #include #include @@ -55,7 +55,7 @@ namespace file log << " " << runwaysFile << std::endl; while (std::getline(runways, line)) { - std::vector fields = util::split(line, ','); + std::vector fields = utilities::split(line, ','); // New ICAO if (currentIcao != nullptr && *currentIcao != fields[0]) { tmpAirportRunways[*currentIcao] = tmpRunways; @@ -85,20 +85,21 @@ namespace file designator = "0" + designator; } - struct geodata::point start = {std::stod(fields[2]), - std::stod(fields[3])}; - tmpRunways.emplace_back(designator, - start, - geodata::toMetre(std::stod(fields[8])), - geodata::toMetre(std::stod(fields[6])), - std::stod(fields[5]) + std::stod(fields[9])); + struct utilities::geodata::point start = {std::stod(fields[2]), + std::stod(fields[3])}; + tmpRunways.emplace_back( + designator, + start, + utilities::geodata::toMetre(std::stod(fields[8])), + utilities::geodata::toMetre(std::stod(fields[6])), + std::stod(fields[5]) + std::stod(fields[9])); log << "\t " << line << std::endl; } currentIcao = nullptr; while (std::getline(gates, line)) { - std::vector fields = util::split(line, ','); + std::vector fields = utilities::split(line, ','); // New ICAO if (currentIcao != nullptr && *currentIcao != fields[0]) { tmpAirportGates[*currentIcao] = tmpGates; diff --git a/file/include/simdata/simdataXP.hpp b/file/include/simdata/simdataXP.hpp index 9066c6e..16daf4b 100644 --- a/file/include/simdata/simdataXP.hpp +++ b/file/include/simdata/simdataXP.hpp @@ -79,10 +79,11 @@ namespace file int validCount = 0; while (std::getline(infile, line)) { - std::vector fields = util::split(line, ' '); - fields = util::select_T(fields, [](const std::string &s) { - return s.length() > 0; - }); + std::vector fields = utilities::split(line, ' '); + fields = + utilities::select_T(fields, [](const std::string &s) { + return s.length() > 0; + }); if (fields.empty()) continue; @@ -173,7 +174,7 @@ namespace file std::vector packs; while (std::getline(custom, line)) { if ((pos = line.find("SCENERY_PACK")) != std::string::npos) { - std::string path = util::rtrim_copy(line.substr(pos + 13)) + + std::string path = utilities::rtrim_copy(line.substr(pos + 13)) + "Earth nav data/apt.dat"; packs.emplace_back(path); } diff --git a/format.sh b/format.sh index d80c918..83c8d90 100755 --- a/format.sh +++ b/format.sh @@ -2,7 +2,7 @@ shopt -s globstar -GLOBIGNORE='**/XPLM/**:XPLM/**:**/XPLM:**/ixwebsocket/**:ixwebsocket/**:**/ixwebsocket:**/nlohmann/**:nlohmann/**:**/nlohmann:**/XPSDK/**:XPSDK/**:**/XPSDK:**/build*/**:build*/**:**/build*:**/openSSL/**:openSSL/**:**/openSSL' +GLOBIGNORE='**/XPLM/**:XPLM/**:**/XPLM:**/ixwebsocket/**:ixwebsocket/**:**/ixwebsocket:**/nlohmann/**:nlohmann/**:**/nlohmann:**/XPSDK/**:XPSDK/**:**/XPSDK:**/build*/**:build*/**:**/build*:**/openSSL/**:openSSL/**:**/openSSL:**/SimConnect/**:SimConnect/**:**/SimConnect' clang-format -verbose -i **/*.cpp clang-format -verbose -i **/*.h diff --git a/recorder/include/recorder.h b/recorder/include/recorder.h new file mode 100644 index 0000000..38fbdf8 --- /dev/null +++ b/recorder/include/recorder.h @@ -0,0 +1,17 @@ +#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDER_RECORDER_H +#define GERMANAIRLINESVA_GACONNECTOR_RECORDER_RECORDER_H + +namespace germanairlinesva +{ +namespace gaconnector +{ + namespace recorder + { + class Recorder + { + }; + } // namespace recorder +} // namespace gaconnector +} // namespace germanairlinesva + +#endif \ No newline at end of file diff --git a/utilities/include/constants.h b/utilities/include/constants.h index ab28ffd..5cedd80 100644 --- a/utilities/include/constants.h +++ b/utilities/include/constants.h @@ -1,5 +1,5 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_CONSTANTS_H -#define GERMANAIRLINESVA_GACONNECTOR_CONSTANTS_H +#ifndef GERMANAIRLINESVA_UTILITIES_CONSTANTS_H +#define GERMANAIRLINESVA_UTILITIES_CONSTANTS_H #ifdef XP #define BASE_DIRECTORY "Resources/plugins/GAConnector/" diff --git a/utilities/include/geodata.hpp b/utilities/include/geodata.hpp index 3d8c60d..a7fd8c8 100644 --- a/utilities/include/geodata.hpp +++ b/utilities/include/geodata.hpp @@ -1,5 +1,5 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_GEODATA_H -#define GERMANAIRLINESVA_GACONNECTOR_GEODATA_H +#ifndef GERMANAIRLINESVA_UTILITIES_GEODATA_H +#define GERMANAIRLINESVA_UTILITIES_GEODATA_H #define M_PI 3.14159265358979323846 #define BUFSIZE 1024 @@ -10,235 +10,242 @@ namespace germanairlinesva { -namespace geodata +namespace utilities { + namespace geodata + { #pragma pack(push) #pragma pack(1) - struct point { - double latitude; - double longitude; - }; + struct point { + double latitude; + double longitude; + }; #pragma pack(pop) #pragma pack(push) #pragma pack(1) - struct box { - struct point topLeft; - struct point topRight; - struct point bottomRight; - struct point bottomLeft; - }; + struct box { + struct point topLeft; + struct point topRight; + struct point bottomRight; + struct point bottomLeft; + }; #pragma pack(pop) - static inline double toMetre(double value) { return value * 0.3048; } + static inline double toMetre(double value) { return value * 0.3048; } - static inline double toFeet(double value) { return value * 3.280839895; } + static inline double toFeet(double value) { return value * 3.280839895; } - static inline double toDegrees(double value) { return value * 180 / M_PI; } + static inline double toDegrees(double value) { return value * 180 / M_PI; } - static inline double toRadians(double value) { return value * M_PI / 180; } + static inline double toRadians(double value) { return value * M_PI / 180; } - static inline double normalizeD(double value) - { - return fmod(value + 360, 360); - } + static inline double normalizeD(double value) + { + return fmod(value + 360, 360); + } - static inline double normalizeR(double value) - { - return value < 0 ? 2 * M_PI + value : value; - } + static inline double normalizeR(double value) + { + return value < 0 ? 2 * M_PI + value : value; + } - // Input and Output in degrees - static inline double bearingDD(double fromLatitude, - double fromLongitude, - double toLatitude, - double toLongitude) - { - double y = sin(toRadians(toLongitude) - toRadians(fromLongitude)) * - cos(toRadians(toLatitude)); - double x = cos(toRadians(fromLatitude)) * sin(toRadians(toLatitude)) - - sin(toRadians(fromLatitude)) * cos(toRadians(toLatitude)) * - cos(toRadians(toLongitude) - toRadians(fromLongitude)); + // Input and Output in degrees + static inline double bearingDD(double fromLatitude, + double fromLongitude, + double toLatitude, + double toLongitude) + { + double y = sin(toRadians(toLongitude) - toRadians(fromLongitude)) * + cos(toRadians(toLatitude)); + double x = cos(toRadians(fromLatitude)) * sin(toRadians(toLatitude)) - + sin(toRadians(fromLatitude)) * cos(toRadians(toLatitude)) * + cos(toRadians(toLongitude) - toRadians(fromLongitude)); - return normalizeD(toDegrees(atan2(y, x))); - } + return normalizeD(toDegrees(atan2(y, x))); + } - // Input in degrees, Output in radians - static inline double bearingDR(double fromLatitude, - double fromLongitude, - double toLatitude, - double toLongitude) - { - double y = sin(toRadians(toLongitude) - toRadians(fromLongitude)) * - cos(toRadians(toLatitude)); - double x = cos(toRadians(fromLatitude)) * sin(toRadians(toLatitude)) - - sin(toRadians(fromLatitude)) * cos(toRadians(toLatitude)) * - cos(toRadians(toLongitude) - toRadians(fromLongitude)); + // Input in degrees, Output in radians + static inline double bearingDR(double fromLatitude, + double fromLongitude, + double toLatitude, + double toLongitude) + { + double y = sin(toRadians(toLongitude) - toRadians(fromLongitude)) * + cos(toRadians(toLatitude)); + double x = cos(toRadians(fromLatitude)) * sin(toRadians(toLatitude)) - + sin(toRadians(fromLatitude)) * cos(toRadians(toLatitude)) * + cos(toRadians(toLongitude) - toRadians(fromLongitude)); - return normalizeR(atan2(y, x)); - } + return normalizeR(atan2(y, x)); + } - // Input in degrees, Output in metres - static inline double distanceEarthD(double fromLatitude, - double fromLongitude, - double toLatitude, - double toLongitude) - { - double lat1r, lon1r, lat2r, lon2r, u, v; - lat1r = toRadians(fromLatitude); - lon1r = toRadians(fromLongitude); - lat2r = toRadians(toLatitude); - lon2r = toRadians(toLongitude); - u = sin((lat2r - lat1r) / 2); - v = sin((lon2r - lon1r) / 2); - return 2.0 * EARTH_M * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v)); - } + // Input in degrees, Output in metres + static inline double distanceEarthD(double fromLatitude, + double fromLongitude, + double toLatitude, + double toLongitude) + { + double lat1r, lon1r, lat2r, lon2r, u, v; + lat1r = toRadians(fromLatitude); + lon1r = toRadians(fromLongitude); + lat2r = toRadians(toLatitude); + lon2r = toRadians(toLongitude); + u = sin((lat2r - lat1r) / 2); + v = sin((lon2r - lon1r) / 2); + return 2.0 * EARTH_M * + asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v)); + } - // Input in degrees, Output in metres - static inline double distanceEarthP(point from, point to) - { - double lat1r, lon1r, lat2r, lon2r, u, v; - lat1r = toRadians(from.latitude); - lon1r = toRadians(from.longitude); - lat2r = toRadians(to.latitude); - lon2r = toRadians(to.longitude); - u = sin((lat2r - lat1r) / 2); - v = sin((lon2r - lon1r) / 2); - return 2.0 * EARTH_M * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v)); - } + // Input in degrees, Output in metres + static inline double distanceEarthP(point from, point to) + { + double lat1r, lon1r, lat2r, lon2r, u, v; + lat1r = toRadians(from.latitude); + lon1r = toRadians(from.longitude); + lat2r = toRadians(to.latitude); + lon2r = toRadians(to.longitude); + u = sin((lat2r - lat1r) / 2); + v = sin((lon2r - lon1r) / 2); + return 2.0 * EARTH_M * + asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v)); + } - // Input and Output in degrees - static inline struct point calculatePointDD(struct point coordinates, - double bearing, - double distance) - { - double r_latitude = toRadians(coordinates.latitude); - double r_longitude = toRadians(coordinates.longitude); - double r_bearing = toRadians(bearing); + // Input and Output in degrees + static inline struct point calculatePointDD(struct point coordinates, + double bearing, + double distance) + { + double r_latitude = toRadians(coordinates.latitude); + double r_longitude = toRadians(coordinates.longitude); + double r_bearing = toRadians(bearing); - double newLatitude = - std::asin(std::sin(r_latitude) * std::cos(distance / EARTH_M) + - std::cos(r_latitude) * std::sin(distance / EARTH_M) * - std::cos(r_bearing)); - double newLongitude = - r_longitude + - std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * - std::cos(r_latitude), - std::cos(distance / EARTH_M) - - std::sin(r_latitude) * std::sin(newLatitude)); + double newLatitude = + std::asin(std::sin(r_latitude) * std::cos(distance / EARTH_M) + + std::cos(r_latitude) * std::sin(distance / EARTH_M) * + std::cos(r_bearing)); + double newLongitude = + r_longitude + + std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * + std::cos(r_latitude), + std::cos(distance / EARTH_M) - + std::sin(r_latitude) * std::sin(newLatitude)); - return {toDegrees(newLatitude), toDegrees(newLongitude)}; - } + return {toDegrees(newLatitude), toDegrees(newLongitude)}; + } - // Input in degrees, Output in radians - static inline struct point calculatePointDR(struct point coordinates, - double bearing, - double distance) - { - double r_latitude = toRadians(coordinates.latitude); - double r_longitude = toRadians(coordinates.longitude); - double r_bearing = toRadians(bearing); + // Input in degrees, Output in radians + static inline struct point calculatePointDR(struct point coordinates, + double bearing, + double distance) + { + double r_latitude = toRadians(coordinates.latitude); + double r_longitude = toRadians(coordinates.longitude); + double r_bearing = toRadians(bearing); - double newLatitude = - std::asin(std::sin(r_latitude) * std::cos(distance / EARTH_M) + - std::cos(r_latitude) * std::sin(distance / EARTH_M) * - std::cos(r_bearing)); - double newLongitude = - r_longitude + - std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * - std::cos(r_latitude), - std::cos(distance / EARTH_M) - - std::sin(r_latitude) * std::sin(newLatitude)); + double newLatitude = + std::asin(std::sin(r_latitude) * std::cos(distance / EARTH_M) + + std::cos(r_latitude) * std::sin(distance / EARTH_M) * + std::cos(r_bearing)); + double newLongitude = + r_longitude + + std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * + std::cos(r_latitude), + std::cos(distance / EARTH_M) - + std::sin(r_latitude) * std::sin(newLatitude)); - return {newLatitude, newLongitude}; - } + return {newLatitude, newLongitude}; + } - // LAT/LON in radians, BEARING/Output in degrees - static inline struct point calculatePointRD(struct point coordinates, - double bearing, - double distance) - { - double r_bearing = toRadians(bearing); + // LAT/LON in radians, BEARING/Output in degrees + static inline struct point calculatePointRD(struct point coordinates, + double bearing, + double distance) + { + double r_bearing = toRadians(bearing); - double newLatitude = std::asin( - std::sin(coordinates.latitude) * std::cos(distance / EARTH_M) + - std::cos(coordinates.latitude) * std::sin(distance / EARTH_M) * - std::cos(r_bearing)); - double newLongitude = - coordinates.longitude + - std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * - std::cos(coordinates.latitude), - std::cos(distance / EARTH_M) - - std::sin(coordinates.latitude) * std::sin(newLatitude)); + double newLatitude = std::asin( + std::sin(coordinates.latitude) * std::cos(distance / EARTH_M) + + std::cos(coordinates.latitude) * std::sin(distance / EARTH_M) * + std::cos(r_bearing)); + double newLongitude = + coordinates.longitude + + std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * + std::cos(coordinates.latitude), + std::cos(distance / EARTH_M) - + std::sin(coordinates.latitude) * + std::sin(newLatitude)); - return {toDegrees(newLatitude), toDegrees(newLongitude)}; - } + return {toDegrees(newLatitude), toDegrees(newLongitude)}; + } - // LAT/LON/Output in radians, BEARING in degrees - static inline struct point calculatePointRR(struct point coordinates, - double bearing, - double distance) - { - double r_bearing = toRadians(bearing); + // LAT/LON/Output in radians, BEARING in degrees + static inline struct point calculatePointRR(struct point coordinates, + double bearing, + double distance) + { + double r_bearing = toRadians(bearing); - double newLatitude = std::asin( - std::sin(coordinates.latitude) * std::cos(distance / EARTH_M) + - std::cos(coordinates.latitude) * std::sin(distance / EARTH_M) * - std::cos(r_bearing)); - double newLongitude = - coordinates.longitude + - std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * - std::cos(coordinates.latitude), - std::cos(distance / EARTH_M) - - std::sin(coordinates.latitude) * std::sin(newLatitude)); + double newLatitude = std::asin( + std::sin(coordinates.latitude) * std::cos(distance / EARTH_M) + + std::cos(coordinates.latitude) * std::sin(distance / EARTH_M) * + std::cos(r_bearing)); + double newLongitude = + coordinates.longitude + + std::atan2(std::sin(r_bearing) * std::sin(distance / EARTH_M) * + std::cos(coordinates.latitude), + std::cos(distance / EARTH_M) - + std::sin(coordinates.latitude) * + std::sin(newLatitude)); - return {newLatitude, newLongitude}; - } + return {newLatitude, newLongitude}; + } - // Input in degrees, calculate from center - static inline box calculateBoxDD(struct point center, - double bearing, - double length, - double width) - { - struct point primaryCenter = calculatePointDR(center, bearing, -length / 2); - struct point secondaryCenter = - calculatePointDR(center, bearing, length / 2); - double offsetHeadingNorth = - bearing - 90 > 0 ? bearing - 90 : bearing - 90 + 360; - struct point primaryTop = - calculatePointRD(primaryCenter, offsetHeadingNorth, width / 2); - struct point primaryBottom = - calculatePointRD(primaryCenter, offsetHeadingNorth, -width / 2); - struct point secondaryTop = - calculatePointRD(secondaryCenter, offsetHeadingNorth, width / 2); - struct point secondaryBottom = - calculatePointRD(secondaryCenter, offsetHeadingNorth, -width / 2); + // Input in degrees, calculate from center + static inline box calculateBoxDD(struct point center, + double bearing, + double length, + double width) + { + struct point primaryCenter = + calculatePointDR(center, bearing, -length / 2); + struct point secondaryCenter = + calculatePointDR(center, bearing, length / 2); + double offsetHeadingNorth = + bearing - 90 > 0 ? bearing - 90 : bearing - 90 + 360; + struct point primaryTop = + calculatePointRD(primaryCenter, offsetHeadingNorth, width / 2); + struct point primaryBottom = + calculatePointRD(primaryCenter, offsetHeadingNorth, -width / 2); + struct point secondaryTop = + calculatePointRD(secondaryCenter, offsetHeadingNorth, width / 2); + struct point secondaryBottom = + calculatePointRD(secondaryCenter, offsetHeadingNorth, -width / 2); - return {primaryTop, secondaryTop, secondaryBottom, primaryBottom}; - } + return {primaryTop, secondaryTop, secondaryBottom, primaryBottom}; + } - // Input in degrees, calculate from start end - static inline box calculateBoxDD(struct point start, - struct point end, - double bearing, - double width) - { - double offsetHeadingNorth = - bearing - 90 > 0 ? bearing - 90 : bearing - 90 + 360; - struct point primaryTop = - calculatePointDD(start, offsetHeadingNorth, width / 2); - struct point primaryBottom = - calculatePointDD(start, offsetHeadingNorth, -width / 2); - struct point secondaryTop = - calculatePointDD(end, offsetHeadingNorth, width / 2); - struct point secondaryBottom = - calculatePointDD(end, offsetHeadingNorth, -width / 2); + // Input in degrees, calculate from start end + static inline box calculateBoxDD(struct point start, + struct point end, + double bearing, + double width) + { + double offsetHeadingNorth = + bearing - 90 > 0 ? bearing - 90 : bearing - 90 + 360; + struct point primaryTop = + calculatePointDD(start, offsetHeadingNorth, width / 2); + struct point primaryBottom = + calculatePointDD(start, offsetHeadingNorth, -width / 2); + struct point secondaryTop = + calculatePointDD(end, offsetHeadingNorth, width / 2); + struct point secondaryBottom = + calculatePointDD(end, offsetHeadingNorth, -width / 2); - return {primaryTop, secondaryTop, secondaryBottom, primaryBottom}; - } - -} // namespace geodata + return {primaryTop, secondaryTop, secondaryBottom, primaryBottom}; + } + } // namespace geodata +} // namespace utilities } // namespace germanairlinesva #endif \ No newline at end of file diff --git a/utilities/include/util.hpp b/utilities/include/util.hpp index 6c7d265..6335222 100644 --- a/utilities/include/util.hpp +++ b/utilities/include/util.hpp @@ -1,5 +1,5 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_UTIL_H -#define GERMANAIRLINESVA_GACONNECTOR_UTIL_H +#ifndef GERMANAIRLINESVA_UTILITIES_UTIL_H +#define GERMANAIRLINESVA_UTILITIES_UTIL_H #define BUFSIZE 1024 #define MD5LEN 16 @@ -36,7 +36,7 @@ namespace germanairlinesva { -namespace util +namespace utilities { template static inline std::vector @@ -294,7 +294,7 @@ namespace util return result; } -} // namespace util +} // namespace utilities } // namespace germanairlinesva #endif diff --git a/websocket/include/types.h b/websocket/include/types.h index 8ce775f..11dc85b 100644 --- a/websocket/include/types.h +++ b/websocket/include/types.h @@ -1,51 +1,64 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_SOCKET_TYPES_H -#define GERMANAIRLINESVA_GACONNECTOR_SOCKET_TYPES_H +#ifndef GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_TYPES_H +#define GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_TYPES_H #include namespace germanairlinesva { -namespace websocket +namespace gaconnector { + namespace websocket + { #pragma pack(push) /* push current alignment to stack */ #pragma pack(1) /* set alignment to 1 byte boundary */ - /* Structures and enums */ - struct data { - std::int32_t pause = 0; - float pBrake = 0; - std::int32_t onGrnd = 0; - float totFuelKg = 0; - float truHdg = 0; - double alt = 0; - float gs = 0; - float ias = 0; - float vs = 0; - double lat = 0; - double lon = 0; - float ff[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - float maxSpd = 0; - char path[513] = ""; - float uptime = 0; - float magHeading = 0; - float payloadKg = 0; - float totalWeightKg = 0; - }; + /* Structures and enums */ + struct data { + std::int32_t pause = 0; + float pBrake = 0; + std::int32_t onGrnd = 0; + float totFuelKg = 0; + float truHdg = 0; + double alt = 0; + float gs = 0; + float ias = 0; + float vs = 0; + double lat = 0; + double lon = 0; + float ff[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + float maxSpd = 0; + char path[513] = ""; + float uptime = 0; + float magHeading = 0; + float payloadKg = 0; + float totalWeightKg = 0; + }; - enum commands { PROCESS, SAVE, LOAD, TEXT, TIME, UNPAUSE, PAUSE, PORT, END }; + enum commands { + PROCESS, + SAVE, + LOAD, + TEXT, + TIME, + UNPAUSE, + PAUSE, + PORT, + END + }; - struct command_base { - enum commands type; - }; + struct command_base { + enum commands type; + }; - struct command_port { - double latitude; - double longitude; - float trueHeading; - }; + struct command_port { + double latitude; + double longitude; + float trueHeading; + }; #pragma pack(pop) /* restore original alignment from stack */ -} // namespace websocket + } // namespace websocket +} // namespace gaconnector } // namespace germanairlinesva #endif diff --git a/websocket/include/websocket.h b/websocket/include/websocket.h index 7b6ef39..b9b170e 100644 --- a/websocket/include/websocket.h +++ b/websocket/include/websocket.h @@ -1,5 +1,5 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_H -#define GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_H +#ifndef GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_WEBSOCKET_H +#define GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_WEBSOCKET_H #define BUFSIZE 1024 #define MD5LEN 16 @@ -20,27 +20,30 @@ namespace germanairlinesva { -namespace websocket +namespace gaconnector { - class Websocket + namespace websocket { - private: - char lastPath[513] = ""; - char lastHash[2 * MD5LEN + 1] = ""; - ix::WebSocket *webSocket = nullptr; - std::string host; - std::string user; - std::function toLog; + class Websocket + { + private: + char lastPath[513] = ""; + char lastHash[2 * MD5LEN + 1] = ""; + ix::WebSocket *webSocket = nullptr; + std::string host; + std::string user; + std::function toLog; - public: - Websocket(std::string host, - std::string user, - std::function toLog); - ~Websocket(); - void onClientMessageCallback(const ix::WebSocketMessagePtr &msg); - void sendData(data &d); - }; -} // namespace websocket + public: + Websocket(std::string host, + std::string user, + std::function toLog); + ~Websocket(); + void onClientMessageCallback(const ix::WebSocketMessagePtr &msg); + void sendData(data &d); + }; + } // namespace websocket +} // namespace gaconnector } // namespace germanairlinesva #endif \ No newline at end of file diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index f62a4c2..6349fe9 100644 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -2,113 +2,116 @@ namespace germanairlinesva { -namespace websocket +namespace gaconnector { - Websocket::Websocket(std::string host, - std::string user, - std::function toLog) - : host(host), user(user), toLog(std::move(toLog)) + namespace websocket { + 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) { - 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") == 0) { - this->webSocket->disableAutomaticReconnection(); - - this->toLog("Disconnected due to beeing a duplicate simualtor"); - } else { + void Websocket::onClientMessageCallback(const ix::WebSocketMessagePtr &msg) + { + if (msg->type == ix::WebSocketMessageType::Open) { std::stringstream debug_msg; - 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; + 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()); - } - } 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->webSocket->send("MASTER:" + user); + this->toLog("Connecting as " + user); + } else if (msg->type == ix::WebSocketMessageType::Close) { + if (msg->closeInfo.reason.compare("DUPLICATE") == 0) { + this->webSocket->disableAutomaticReconnection(); - this->toLog(debug_msg.str()); - } else if (msg->type == ix::WebSocketMessageType::Message) { - if (!msg->str.empty()) { - this->toLog(msg->str); - } - } - } + this->toLog("Disconnected due to beeing a duplicate simualtor"); + } else { + std::stringstream debug_msg; - void Websocket::sendData(data &d) - { - if (strcmp(d.path, this->lastPath) != 0) { - strcpy(this->lastPath, d.path); - if (util::generateMD5(d.path, this->lastHash, this->toLog)) { - strcpy(this->lastHash, "NOT SET"); + 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); + } } } - 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}, - }; + void Websocket::sendData(data &d) + { + if (strcmp(d.path, this->lastPath) != 0) { + strcpy(this->lastPath, d.path); + if (utilities::generateMD5(d.path, this->lastHash, this->toLog)) { + strcpy(this->lastHash, "NOT SET"); + } + } - if (this->webSocket != nullptr) { - std::ostringstream msg; - msg << "SEND:" << user << ":" << json.dump(); - this->webSocket->send(msg.str(), false); + 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); + } } - } -} // namespace websocket + } // namespace websocket +} // namespace gaconnector } // namespace germanairlinesva \ No newline at end of file diff --git a/xplugin/main.cpp b/xplugin/main.cpp index ef1689f..1ac1a9d 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -12,7 +12,7 @@ std::atomic wantsExit; std::shared_ptr configuration; std::unique_ptr database; -std::unique_ptr connector; +std::unique_ptr connector; int xplaneVersion; /* Datarefs */ @@ -43,7 +43,7 @@ XPLMDataRef pitch; XPLMDataRef roll; XPLMDataRef quaternion; -struct germanairlinesva::websocket::data toSend; +struct germanairlinesva::gaconnector::websocket::data toSend; germanairlinesva::file::recording::Recording p; /* @@ -114,15 +114,17 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) configuration = std::make_unique(); toLog("Config loaded"); - connector = std::make_unique( - "wss://ws.hofmannnet.myhome-server.de:8000", - configuration->getUser(), - toLog); + connector = + std::make_unique( + "wss://ws.hofmannnet.myhome-server.de:8000", + configuration->getUser(), + toLog); toLog("WebSocket started"); char hash[2 * MD5LEN + 1] = ""; - if (germanairlinesva::util::generateMD5(XPLANE_CUSTOM_SCENERY, hash, toLog) == - 0) { + if (germanairlinesva::utilities::generateMD5(XPLANE_CUSTOM_SCENERY, + hash, + toLog) == 0) { database = std::make_unique( xplaneVersion, hash, @@ -216,7 +218,9 @@ float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon) { const std::lock_guard lock(mutex); - std::memset(&toSend, 0, sizeof(germanairlinesva::websocket::data)); + std::memset(&toSend, + 0, + sizeof(germanairlinesva::gaconnector::websocket::data)); toSend.pause = XPLMGetDatai(pauseIndicator); toSend.pBrake = XPLMGetDataf(parkingBrake); @@ -254,14 +258,16 @@ float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon) void serverWorker() { - germanairlinesva::util::setThreadName("GAServerWorker"); + germanairlinesva::utilities::setThreadName("GAServerWorker"); while (!wantsExit) { - struct germanairlinesva::websocket::data copy; + struct germanairlinesva::gaconnector::websocket::data copy; { const std::lock_guard lock(mutex); - std::memcpy(©, &toSend, sizeof(germanairlinesva::websocket::data)); + std::memcpy(©, + &toSend, + sizeof(germanairlinesva::gaconnector::websocket::data)); } connector->sendData(copy); @@ -274,7 +280,7 @@ void serverWorker() void recordingWorker() { - germanairlinesva::util::setThreadName("GARecordingWorker"); + germanairlinesva::utilities::setThreadName("GARecordingWorker"); germanairlinesva::file::recording::RecordingEntry lastPath; std::uint32_t segment = 0; @@ -283,11 +289,13 @@ void recordingWorker() auto rwys = ap.second; while (!wantsExit) { - struct germanairlinesva::websocket::data copy; + struct germanairlinesva::gaconnector::websocket::data copy; { const std::lock_guard lock(mutex); - std::memcpy(©, &toSend, sizeof(germanairlinesva::websocket::data)); + std::memcpy(©, + &toSend, + sizeof(germanairlinesva::gaconnector::websocket::data)); } germanairlinesva::file::recording::RecordingEntry currentPath(