More recording

This commit is contained in:
Kilian Hofmann 2022-01-03 21:37:00 +01:00
parent 3ec41a1a19
commit d7b765fba5
5 changed files with 57 additions and 16 deletions

View File

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

View File

@ -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<std::uint8_t> 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<std::uint8_t>(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);
}
};

View File

@ -1,4 +1,5 @@
#include <cstdint>
#include <cstring>
#include <vector>
#include "pathSegment.hpp"
@ -6,8 +7,18 @@
class Path
{
private:
std::vector<PathSegment> segments;
std::uint64_t count = 0;
std::vector<std::uint8_t> 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(); }
};

View File

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

View File

@ -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<const char *>(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(&copy, &toSend, sizeof(data));
}
p.addSegment({static_cast<std::uint16_t>(copy.alt),
static_cast<std::uint16_t>(copy.gs),
copy.lat,
copy.lon});
PathSegment currentPath(static_cast<std::uint16_t>(copy.alt),
static_cast<std::uint16_t>(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));
}