diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..2378106 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/opt/llvm-mingw/bin/clang++", + "cStandard": "c17", + "intelliSenseMode": "windows-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0999cd5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "clang++-10 - Build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "lldb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: clang++-10 build active file", + "miDebuggerPath": "/usr/bin/lldb-mi-10" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cd358a6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,67 @@ +{ + "files.associations": { + "thread": "cpp", + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "shared_mutex": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "valarray": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..2fc6150 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: clang++-10 build active file", + "command": "/usr/bin/clang++-10", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/file/pathSegment.hpp b/file/pathSegment.hpp new file mode 100644 index 0000000..fb884c9 --- /dev/null +++ b/file/pathSegment.hpp @@ -0,0 +1,40 @@ +#include +#include +#include + +/* + * Length in bytes: 20 + * + * UINT16 | UINT16 | DOUBLE | DOUBLE | + * ---------+-------------+----------+-----------+ + * ALTITUDE | GROUNDSPEED | LATITUDE | LONGITUDE | + */ +class PathSegment +{ +private: + std::uint16_t altitude; + std::uint16_t groundSpeed; + double latitude; + double longitude; + std::vector file; + +public: + PathSegment(std::uint16_t altitude, + std::uint16_t groundSpeed, + double latitude, + double longitude) + { + this->altitude = altitude; + + + 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)); + } +}; diff --git a/file/recordingPath.hpp b/file/recordingPath.hpp new file mode 100644 index 0000000..5fe4828 --- /dev/null +++ b/file/recordingPath.hpp @@ -0,0 +1,13 @@ +#include +#include + +#include "pathSegment.hpp" + +class Path +{ +private: + std::vector segments; + +public: + void addSegment(PathSegment segment) { segments.push_back(segment); } +}; \ No newline at end of file diff --git a/websocket/include/websocket.h b/websocket/include/websocket.h index 6a6fe29..ed96f9a 100644 --- a/websocket/include/websocket.h +++ b/websocket/include/websocket.h @@ -19,7 +19,7 @@ #include #include -class websocket +class Websocket { private: char lastPath[513] = ""; @@ -30,8 +30,8 @@ private: std::function toLog; public: - explicit websocket(std::function toLog); - ~websocket(); + explicit Websocket(std::function toLog); + ~Websocket(); void onClientMessageCallback( std::shared_ptr &connectionState, ix::WebSocket &ws, diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index 7576219..155ce61 100644 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -1,6 +1,6 @@ #include "include/websocket.h" -websocket::websocket(std::function toLog) +Websocket::Websocket(std::function toLog) : toLog(std::move(toLog)) { #ifdef IBM @@ -27,7 +27,7 @@ websocket::websocket(std::function toLog) server->start(); } -websocket::~websocket() +Websocket::~Websocket() { server->stop(); @@ -37,7 +37,7 @@ websocket::~websocket() #endif } -void websocket::onClientMessageCallback( +void Websocket::onClientMessageCallback( std::shared_ptr &connectionState, ix::WebSocket &ws, const ix::WebSocketMessagePtr &msg) @@ -95,7 +95,7 @@ void websocket::onClientMessageCallback( } } -void websocket::sendData(data d) +void Websocket::sendData(data d) { if (strcmp(d.path, lastPath) != 0) { strcpy(lastPath, d.path); diff --git a/xplugin/include/main.h b/xplugin/include/main.h index a380305..820e824 100644 --- a/xplugin/include/main.h +++ b/xplugin/include/main.h @@ -3,6 +3,7 @@ #include "config.hpp" #include "makeRwysXP.h" +#include "recordingPath.hpp" #include "simulatorDatabase.hpp" #include "websocket.h" @@ -23,6 +24,7 @@ float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon); void serverWorker(); +void recordingWorker(); void toLog(const std::string &message); #endif diff --git a/xplugin/main.cpp b/xplugin/main.cpp index 6d5dab1..6588cf6 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -7,11 +7,12 @@ std::queue> &messageQueue() return _messageQueue; } std::thread serverThread; +std::thread recordingThread; std::atomic wantsExit; std::map configuration; -websocket *connector; +Websocket *connector; /* Datarefs */ XPLMDataRef pauseIndicator; @@ -108,7 +109,7 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) // Initialize connector try { - connector = new websocket(toLog); + connector = new Websocket(toLog); } catch (const std::invalid_argument &e) { toLog(e.what()); return 0; @@ -147,7 +148,8 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) // Thread for sending data to web socket serverThread = std::thread(&serverWorker); - toLog("Worker started"); + recordingThread = std::thread(&recordingWorker); + toLog("Workers started"); return 1; } @@ -218,7 +220,7 @@ float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon) void serverWorker() { - util::setThreadName("GAWorker"); + util::setThreadName("GAServerWorker"); while (!wantsExit) { data copy; @@ -234,6 +236,29 @@ void serverWorker() } } +void recordingWorker() +{ + util::setThreadName("GARecordingWorker"); + + Path p; + + while (!wantsExit) { + data copy; + { + const std::lock_guard lock(mutex); + + memcpy(©, &toSend, sizeof(data)); + } + + p.addSegment({static_cast(copy.alt), + static_cast(copy.gs), + copy.lat, + copy.lon}); + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } +} + void toLog(const std::string &message) { std::stringstream msg;