diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d25527..7c893cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,9 @@ add_subdirectory( add_subdirectory( simdata ) +add_subdirectory( + file +) add_subdirectory( xplugin ) diff --git a/file/CMakeLists.txt b/file/CMakeLists.txt new file mode 100644 index 0000000..4abd863 --- /dev/null +++ b/file/CMakeLists.txt @@ -0,0 +1,90 @@ +file(GLOB file CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/file/*.cpp) + +add_library(file SHARED + ${file} +) + +target_include_directories(file PRIVATE + ${CMAKE_SOURCE_DIR}/file/include + ${CMAKE_SOURCE_DIR}/simdata/include + ${CMAKE_SOURCE_DIR}/utilities/include +) + +set_target_properties(file PROPERTIES + PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/file/include +) +target_compile_options(file PRIVATE + -Wall + -Wextra + -pedantic +) +if(DEBUG) + target_compile_options(file PRIVATE + -g + ) + target_link_options(file PRIVATE + -g + ) +else() + target_compile_options(file PRIVATE + -O2 + ) +endif() + +if(APPLE) + message("Building file for MacOSX Universal into ${PROJECT_BINARY_DIR}/${PLUGIN_NAME}") + + set_target_properties(file PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}" + BUILD_WITH_INSTALL_NAME_DIR TRUE + ) + + target_compile_options(file PRIVATE + "SHELL:-arch i386" + "SHELL:-arch x86_64" + ) + target_link_options(file PRIVATE + "SHELL:-arch i386" + "SHELL:-arch x86_64" + ) + target_link_libraries(file PRIVATE + "-framework Security" + ) +elseif(UNIX) + message("Building file for Linux ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}") + + set_target_properties(file PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}" + ) + + target_compile_options(file PRIVATE + -nodefaultlibs + ) + if(BIT STREQUAL "32") + target_compile_options(file PRIVATE + -m32 + ) + target_link_options(file PRIVATE + -m32 + ) + endif() +elseif(WIN32) + message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}") + + set_target_properties(file PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}" + ) + + if(DEBUG) + target_compile_options(file PRIVATE + -gcodeview + ) + target_link_options(file PRIVATE + -Wl,-pdb= + ) + endif() + target_link_options(file PRIVATE + -static-libgcc + -static-libstdc++ + ) +endif() diff --git a/file/config.hpp b/file/include/config.hpp similarity index 100% rename from file/config.hpp rename to file/include/config.hpp diff --git a/file/include/pathRecording.h b/file/include/pathRecording.h new file mode 100644 index 0000000..278e4ac --- /dev/null +++ b/file/include/pathRecording.h @@ -0,0 +1,43 @@ +#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDING_H +#define GERMANAIRLINESVA_GACONNECTOR_RECORDING_H + +#include +#include +#include + +#include "pathSegment.h" + +#define CURRENT_VERSION 1 + +namespace germanairlinesva_recording +{ + /* + * Header + * + * CHAR[5] | UINT8 + * --------+-------- + * VGAR | VERSION + */ + /* + * Path Recording + * + * PATHSEGMENT[] + * ------------- + * SEGMENTS + */ + class PathRecording + { + private: + std::uint64_t count = 0; + std::vector file{'V', 'G', 'A', 'R', 0, CURRENT_VERSION}; + + public: + void addSegment(PathSegment segment); + + inline std::uint8_t *getBinaryData() { return file.data(); } + inline std::size_t getBinaryLength() { return file.size(); } + }; + +} // namespace germanairlinesva_recording + +#endif \ No newline at end of file diff --git a/file/include/pathSegment.h b/file/include/pathSegment.h new file mode 100644 index 0000000..bafde0b --- /dev/null +++ b/file/include/pathSegment.h @@ -0,0 +1,52 @@ +#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H +#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H + +#include +#include +#include + +#include "geodata.h" + +namespace germanairlinesva_recording +{ + /* + * UINT32 | UINT16 | UINT16 | COORDINATES + * -------+----------+-------------+------------ + * TIME | ALTITUDE | GROUNDSPEED | POINT + */ + class PathSegment + { + private: + std::uint32_t time = 0; + std::uint16_t altitude = 0; + std::uint16_t groundSpeed = 0; + struct germanairlinesva_geodata::point coordinates; + std::vector file; + + public: + PathSegment() = default; + PathSegment(std::uint32_t time, + std::uint16_t altitude, + std::uint16_t groundSpeed, + struct germanairlinesva_geodata::point coordinates); + + inline std::uint8_t *getBinaryData() { return file.data(); } + inline std::size_t getBinaryLength() { return file.size(); } + + friend inline bool operator==(const PathSegment &lhs, + const PathSegment &rhs) + { + return lhs.altitude == rhs.altitude && + lhs.groundSpeed == rhs.groundSpeed && + lhs.coordinates.latitude == rhs.coordinates.latitude && + lhs.coordinates.longitude == rhs.coordinates.longitude; + } + friend inline bool operator!=(const PathSegment &lhs, + const PathSegment &rhs) + { + return !(lhs == rhs); + } + }; +} // namespace germanairlinesva_recording + +#endif diff --git a/file/pathRecording.cpp b/file/pathRecording.cpp new file mode 100644 index 0000000..ad49764 --- /dev/null +++ b/file/pathRecording.cpp @@ -0,0 +1,12 @@ +#include "pathRecording.h" + +namespace germanairlinesva_recording +{ + void PathRecording::addSegment(PathSegment segment) + { + file.resize(file.size() + segment.getBinaryLength()); + std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength(); + memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength()); + count++; + } +} // namespace germanairlinesva_recording \ No newline at end of file diff --git a/file/pathSegment.cpp b/file/pathSegment.cpp new file mode 100644 index 0000000..e4aaf79 --- /dev/null +++ b/file/pathSegment.cpp @@ -0,0 +1,28 @@ +#include "pathSegment.h" + +namespace germanairlinesva_recording +{ + PathSegment::PathSegment(std::uint32_t time, + std::uint16_t altitude, + std::uint16_t groundSpeed, + struct germanairlinesva_geodata::point coordinates) + { + this->time = time; + this->altitude = altitude; + this->groundSpeed = groundSpeed; + this->coordinates = coordinates; + + file = std::vector( + sizeof(this->time) + sizeof(this->altitude) + + sizeof(this->groundSpeed) + sizeof(this->coordinates), + 0); + std::uint8_t *bufPtr = file.data(); + memcpy(bufPtr, &this->time, sizeof(this->time)); + bufPtr += sizeof(this->time); + memcpy(bufPtr, &this->altitude, sizeof(this->altitude)); + bufPtr += sizeof(this->altitude); + memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed)); + bufPtr += sizeof(this->groundSpeed); + memcpy(bufPtr, &this->coordinates, sizeof(this->coordinates)); + }; +} // namespace germanairlinesva_recording \ No newline at end of file diff --git a/file/pathSegment.hpp b/file/pathSegment.hpp deleted file mode 100644 index 823911b..0000000 --- a/file/pathSegment.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H -#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H - -#include -#include -#include - -/* - * Length in bytes: 20 - * - * UINT16 | UINT16 | DOUBLE | DOUBLE | - * ---------+-------------+----------+-----------+ - * ALTITUDE | GROUNDSPEED | LATITUDE | LONGITUDE | - */ -class PathSegment -{ - private: - std::uint16_t altitude = 0; - std::uint16_t groundSpeed = 0; - double latitude = 0; - double longitude = 0; - std::vector file; - - public: - PathSegment() = default; - PathSegment(std::uint16_t altitude, - std::uint16_t groundSpeed, - double latitude, - double longitude) - { - this->altitude = altitude; - this->groundSpeed = groundSpeed; - this->latitude = latitude; - this->longitude = longitude; - - file = std::vector(20, 0); - std::uint8_t *bufPtr = file.data(); - memcpy(bufPtr, &this->altitude, sizeof(this->altitude)); - bufPtr += sizeof(this->altitude); - memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed)); - bufPtr += sizeof(this->groundSpeed); - memcpy(bufPtr, &this->latitude, sizeof(this->latitude)); - bufPtr += sizeof(this->latitude); - memcpy(bufPtr, &this->longitude, sizeof(this->longitude)); - } - - std::uint8_t *getBinaryData() { return file.data(); } - std::size_t getBinaryLength() { return file.size(); } - - friend bool operator==(const PathSegment &lhs, const PathSegment &rhs) - { - return lhs.altitude == rhs.altitude && - lhs.groundSpeed == rhs.groundSpeed && - lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude; - } - friend bool operator!=(const PathSegment &lhs, const PathSegment &rhs) - { - return !(lhs == rhs); - } -}; - -#endif diff --git a/file/recordingPath.hpp b/file/recordingPath.hpp deleted file mode 100644 index 70da501..0000000 --- a/file/recordingPath.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDINGPATH_H -#define GERMANAIRLINESVA_GACONNECTOR_RECORDINGPATH_H - -#include -#include -#include - -#include "pathSegment.hpp" - -class Path -{ - private: - std::uint64_t count = 0; - std::vector file; - - public: - void addSegment(PathSegment segment) - { - file.resize(file.size() + segment.getBinaryLength()); - std::uint8_t *bufPtr = file.data() + count * segment.getBinaryLength(); - memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength()); - count++; - } - - std::uint8_t *getBinaryData() { return file.data(); } - std::size_t getBinaryLength() { return file.size(); } -}; - -#endif \ No newline at end of file diff --git a/simdata/CMakeLists.txt b/simdata/CMakeLists.txt index 79ebe7e..1da3a59 100644 --- a/simdata/CMakeLists.txt +++ b/simdata/CMakeLists.txt @@ -12,9 +12,6 @@ target_include_directories(simdata PRIVATE set_target_properties(simdata PROPERTIES PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/simdata/include ) -target_compile_definitions(simdata PRIVATE - _USE_MATH_DEFINES -) target_compile_options(simdata PRIVATE -Wall -Wextra diff --git a/simdata/include/gate.h b/simdata/include/gate.h index a7535a4..8e08f31 100644 --- a/simdata/include/gate.h +++ b/simdata/include/gate.h @@ -44,8 +44,8 @@ namespace germanairlinesva_simdata germanairlinesva_geodata::point center, std::uint8_t radius); - std::uint8_t *getBinaryData() { return file.data(); } - std::size_t getBinaryLength() { return file.size(); } + inline std::uint8_t *getBinaryData() { return file.data(); } + inline std::size_t getBinaryLength() { return file.size(); } std::string to_string() const { diff --git a/simdata/include/geodata.h b/simdata/include/geodata.h index 37c2395..c9863b1 100644 --- a/simdata/include/geodata.h +++ b/simdata/include/geodata.h @@ -1,6 +1,8 @@ #ifndef GERMANAIRLINESVA_GACONNECTOR_GEODATA_H #define GERMANAIRLINESVA_GACONNECTOR_GEODATA_H +#define _USE_MATH_DEFINES + #ifdef IBM #define WIN32_LEAN_AND_MEAN #endif diff --git a/simdata/include/runway.h b/simdata/include/runway.h index 91f32f5..664eccb 100644 --- a/simdata/include/runway.h +++ b/simdata/include/runway.h @@ -49,8 +49,8 @@ namespace germanairlinesva_simdata std::uint16_t length, std::uint16_t trueHeading); - std::uint8_t *getBinaryData() { return file.data(); } - std::size_t getBinaryLength() { return file.size(); } + inline std::uint8_t *getBinaryData() { return file.data(); } + inline std::size_t getBinaryLength() { return file.size(); } std::string to_string() const { diff --git a/simdata/include/simulatorDatabase.hpp b/simdata/include/simulatorDatabase.hpp index fe90bff..a8fc785 100644 --- a/simdata/include/simulatorDatabase.hpp +++ b/simdata/include/simulatorDatabase.hpp @@ -1,11 +1,6 @@ #ifndef GERMANAIRLINESVA_GACONNECTOR_SIMULATORDATABASE_H #define GERMANAIRLINESVA_GACONNECTOR_SIMULATORDATABASE_H -#include "gate.h" -#include "runway.h" - -#define CURRENT_VERSION 1 - #include #include #include @@ -14,6 +9,11 @@ #include #include +#include "gate.h" +#include "runway.h" + +#define CURRENT_VERSION 1 + /* * Header * diff --git a/utilities/include/util.hpp b/utilities/include/util.hpp index 0e80534..c7791ed 100644 --- a/utilities/include/util.hpp +++ b/utilities/include/util.hpp @@ -31,7 +31,6 @@ #endif #include -#include #include #include #include diff --git a/websocket/include/websocket.h b/websocket/include/websocket.h index 3497365..124828f 100644 --- a/websocket/include/websocket.h +++ b/websocket/include/websocket.h @@ -32,7 +32,7 @@ namespace germanairlinesva_websocket std::function toLog; public: - explicit Websocket(std::string host, + Websocket(std::string host, std::string user, std::function toLog); ~Websocket(); diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index 473c04a..b3bac49 100644 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -36,7 +36,7 @@ namespace germanairlinesva_websocket if (msg->type == ix::WebSocketMessageType::Open) { std::stringstream debug_msg; - debug_msg << "New connection" << 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) { @@ -55,7 +55,7 @@ namespace germanairlinesva_websocket } else { std::stringstream debug_msg; - debug_msg << "Connection closed" << 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; @@ -65,7 +65,7 @@ namespace germanairlinesva_websocket } else if (msg->type == ix::WebSocketMessageType::Error) { std::stringstream debug_msg; - debug_msg << "Connection error" << std::endl; + 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; diff --git a/xplugin/CMakeLists.txt b/xplugin/CMakeLists.txt index b6fa6e9..41d295c 100644 --- a/xplugin/CMakeLists.txt +++ b/xplugin/CMakeLists.txt @@ -8,13 +8,13 @@ add_library(germanairlinesva_xplugin SHARED ) target_include_directories(germanairlinesva_xplugin PRIVATE - ${CMAKE_SOURCE_DIR}/ixwebsocket/include + ${CMAKE_SOURCE_DIR}/file/include ${CMAKE_SOURCE_DIR}/simdata/include ${CMAKE_SOURCE_DIR}/websocket/include ${CMAKE_SOURCE_DIR}/utilities/include + ${CMAKE_SOURCE_DIR}/ixwebsocket/include ${CMAKE_SOURCE_DIR}/nlohmann/include ${CMAKE_SOURCE_DIR}/XPSDK/CHeaders - ${CMAKE_SOURCE_DIR}/file ) set_target_properties(germanairlinesva_xplugin PROPERTIES @@ -24,7 +24,6 @@ set_target_properties(germanairlinesva_xplugin PROPERTIES target_compile_definitions(germanairlinesva_xplugin PRIVATE XPLM200 XPLM210 - _USE_MATH_DEFINES ) target_compile_options(germanairlinesva_xplugin PRIVATE -Wall diff --git a/xplugin/include/main.h b/xplugin/include/main.h index 857825b..e7e2505 100644 --- a/xplugin/include/main.h +++ b/xplugin/include/main.h @@ -2,7 +2,7 @@ #define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H #include "config.hpp" -#include "recordingPath.hpp" +#include "pathRecording.h" #include "simdata.h" #include "simulatorDatabase.hpp" #include "websocket.h" @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/xplugin/main.cpp b/xplugin/main.cpp index 8f5446e..5c535c8 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -47,7 +47,7 @@ XPLMDataRef roll; XPLMDataRef quaternion; germanairlinesva_websocket::data toSend; -Path p; +germanairlinesva_recording::PathRecording p; /* * Callbacks @@ -266,7 +266,8 @@ void recordingWorker() { germanairlinesva_util::setThreadName("GARecordingWorker"); - PathSegment lastPath; + germanairlinesva_recording::PathSegment lastPath; + std::uint32_t segment = 0; while (!wantsExit) { germanairlinesva_websocket::data copy; @@ -276,23 +277,29 @@ void recordingWorker() memcpy(©, &toSend, sizeof(germanairlinesva_websocket::data)); } - PathSegment currentPath(static_cast(copy.alt), - static_cast(copy.gs), - copy.lat, - copy.lon); + germanairlinesva_recording::PathSegment currentPath( + segment, + static_cast(copy.alt), + static_cast(copy.gs), + {copy.lat, copy.lon}); if (strcmp(copy.path, "") != 0 && copy.pause && lastPath != currentPath) { p.addSegment(currentPath); lastPath = currentPath; } + segment++; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } } void toLog(const std::string &message) { + std::time_t utc = std::time(nullptr); + std::tm *time = std::gmtime(&utc); std::stringstream msg; - msg << "German Airlines VA: " << message << std::endl; + msg << std::put_time(time, "%Y-%m-%d %H:%M:%S UTC ") + << "German Airlines VA: " << message << std::endl; XPLMDebugString(msg.str().c_str()); }