diff --git a/file/gate.hpp b/file/gate.hpp index ed53ed8..9182544 100644 --- a/file/gate.hpp +++ b/file/gate.hpp @@ -49,8 +49,8 @@ public: memcpy(bufPtr, &this->longitude, sizeof(this->longitude)); } - std::uint8_t *getBinaryData() { return this->file.data(); } - std::size_t getBinaryLength() { return this->file.size(); } + std::uint8_t *getBinaryData() { return file.data(); } + std::size_t getBinaryLength() { return file.size(); } }; #endif \ No newline at end of file diff --git a/file/pathSegment.hpp b/file/pathSegment.hpp index fb884c9..100db9e 100644 --- a/file/pathSegment.hpp +++ b/file/pathSegment.hpp @@ -12,20 +12,23 @@ class PathSegment { private: - std::uint16_t altitude; - std::uint16_t groundSpeed; - double latitude; - double longitude; + 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(); @@ -37,4 +40,18 @@ public: 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); + } }; diff --git a/file/recordingPath.hpp b/file/recordingPath.hpp index 5fe4828..2e3d173 100644 --- a/file/recordingPath.hpp +++ b/file/recordingPath.hpp @@ -1,4 +1,5 @@ #include +#include #include #include "pathSegment.hpp" @@ -6,8 +7,18 @@ class Path { private: - std::vector segments; + std::uint64_t count = 0; + std::vector file; public: - void addSegment(PathSegment segment) { segments.push_back(segment); } + 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(); } }; \ No newline at end of file diff --git a/file/runway.hpp b/file/runway.hpp index ee94b32..ec34bb8 100644 --- a/file/runway.hpp +++ b/file/runway.hpp @@ -107,8 +107,8 @@ public: memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading)); } - std::uint8_t *getBinaryData() { return this->file.data(); } - std::size_t getBinaryLength() { return this->file.size(); } + std::uint8_t *getBinaryData() { return file.data(); } + std::size_t getBinaryLength() { return file.size(); } }; #endif \ No newline at end of file diff --git a/xplugin/main.cpp b/xplugin/main.cpp index 6588cf6..1a74ef8 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -43,6 +43,7 @@ XPLMDataRef roll; XPLMDataRef quaternion; data toSend; +Path p; /* * Callbacks @@ -162,6 +163,12 @@ PLUGIN_API void XPluginStop(void) wantsExit = true; delete connector; serverThread.join(); + recordingThread.join(); + + std::ofstream out("Resources/plugins/GAConnector/flight.rec"); + out.write(reinterpret_cast(p.getBinaryData()), + (std::streamsize)p.getBinaryLength()); + out.close(); } PLUGIN_API void XPluginDisable(void) {} @@ -240,7 +247,7 @@ void recordingWorker() { util::setThreadName("GARecordingWorker"); - Path p; + PathSegment lastPath; while (!wantsExit) { data copy; @@ -250,10 +257,16 @@ void recordingWorker() memcpy(©, &toSend, sizeof(data)); } - p.addSegment({static_cast(copy.alt), - static_cast(copy.gs), - copy.lat, - copy.lon}); + PathSegment currentPath(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; + } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); }