Begin path recording trials

This commit is contained in:
Kilian Hofmann 2022-01-03 18:18:00 +01:00
parent 107ae2d6c9
commit 3ec41a1a19
10 changed files with 235 additions and 11 deletions

15
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/opt/llvm-mingw/bin/clang++",
"cStandard": "c17",
"intelliSenseMode": "windows-clang-x64"
}
],
"version": 4
}

34
.vscode/launch.json vendored Normal file
View File

@ -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"
}
]
}

67
.vscode/settings.json vendored Normal file
View File

@ -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"
}
}

28
.vscode/tasks.json vendored Normal file
View File

@ -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"
}

40
file/pathSegment.hpp Normal file
View File

@ -0,0 +1,40 @@
#include <cstdint>
#include <cstring>
#include <vector>
/*
* 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<std::uint8_t> file;
public:
PathSegment(std::uint16_t altitude,
std::uint16_t groundSpeed,
double latitude,
double longitude)
{
this->altitude = altitude;
file = std::vector<std::uint8_t>(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));
}
};

13
file/recordingPath.hpp Normal file
View File

@ -0,0 +1,13 @@
#include <cstdint>
#include <vector>
#include "pathSegment.hpp"
class Path
{
private:
std::vector<PathSegment> segments;
public:
void addSegment(PathSegment segment) { segments.push_back(segment); }
};

View File

@ -19,7 +19,7 @@
#include <string>
#include <utility>
class websocket
class Websocket
{
private:
char lastPath[513] = "";
@ -30,8 +30,8 @@ private:
std::function<void(std::string)> toLog;
public:
explicit websocket(std::function<void(const std::string)> toLog);
~websocket();
explicit Websocket(std::function<void(const std::string)> toLog);
~Websocket();
void onClientMessageCallback(
std::shared_ptr<ix::ConnectionState> &connectionState,
ix::WebSocket &ws,

View File

@ -1,6 +1,6 @@
#include "include/websocket.h"
websocket::websocket(std::function<void(const std::string)> toLog)
Websocket::Websocket(std::function<void(const std::string)> toLog)
: toLog(std::move(toLog))
{
#ifdef IBM
@ -27,7 +27,7 @@ websocket::websocket(std::function<void(const std::string)> 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<ix::ConnectionState> &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);

View File

@ -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

View File

@ -7,11 +7,12 @@ std::queue<std::function<void()>> &messageQueue()
return _messageQueue;
}
std::thread serverThread;
std::thread recordingThread;
std::atomic<bool> wantsExit;
std::map<std::string, std::string> 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<std::mutex> lock(mutex);
memcpy(&copy, &toSend, sizeof(data));
}
p.addSegment({static_cast<std::uint16_t>(copy.alt),
static_cast<std::uint16_t>(copy.gs),
copy.lat,
copy.lon});
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
void toLog(const std::string &message)
{
std::stringstream msg;