Recording now uses new write

This commit is contained in:
Kilian Hofmann 2022-09-10 02:05:38 +02:00
parent 94fbc1f558
commit d6d3c0b4d9
11 changed files with 58 additions and 62 deletions

View File

@ -1,3 +1,6 @@
- Reverse engineer FSUIPC .NET onRunway Check
- Update OSXCross Docker image to SDK 11
- Implement ARM64 arch for Plugin
- Implement ARM64 arch for Plugin
- Refactor SimDatabase to be a class
- Requires new Airport class
- Refactor Config to be a class

View File

@ -18,8 +18,8 @@ namespace file
void Gate::toFile(std::ofstream &out) const
{
writeString(out, this->designator);
write<struct germanairlinesva::geodata::point>(out, this->center);
write<std::uint8_t>(out, this->radius);
write<decltype(this->center)>(out, this->center);
write<decltype(this->radius)>(out, this->radius);
}
} // namespace simdata
} // namespace file

View File

@ -2,9 +2,10 @@
#define GERMANAIRLINESVA_FILE_RECORDING_H
#include <cstdint>
#include <cstring>
#include <fstream>
#include <vector>
#include "constants.h"
#include "recordingEntry.h"
namespace germanairlinesva
@ -28,14 +29,14 @@ namespace file
class Recording
{
private:
std::uint64_t count = 0;
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
std::vector<RecordingEntry> entries;
public:
void addSegment(const RecordingEntry &segment);
inline const std::uint8_t *getBinaryData() const { return file.data(); }
inline std::size_t getBinaryLength() const { return file.size(); }
template <class... Args> inline void addEntry(Args &&...args)
{
this->entries.emplace_back(std::forward<Args>(args)...);
}
void toFile(std::string fileName) const;
};
} // namespace recording
} // namespace file

View File

@ -2,10 +2,11 @@
#define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H
#include <cstdint>
#include <cstring>
#include <fstream>
#include <vector>
#include "geodata.hpp"
#include "helpers.hpp"
namespace germanairlinesva
{
@ -22,11 +23,10 @@ namespace file
class RecordingEntry
{
private:
std::uint32_t time = 0;
std::uint16_t altitude = 0;
std::uint16_t groundSpeed = 0;
std::uint32_t time;
std::uint16_t altitude;
std::uint16_t groundSpeed;
struct germanairlinesva::geodata::point coordinates;
std::vector<std::uint8_t> file;
public:
RecordingEntry() = default;
@ -35,8 +35,7 @@ namespace file
std::uint16_t groundSpeed,
struct germanairlinesva::geodata::point coordinates);
inline const std::uint8_t *getBinaryData() const { return file.data(); }
inline std::size_t getBinaryLength() const { return file.size(); }
void toFile(std::ofstream &out) const;
friend inline bool operator==(const RecordingEntry &lhs,
const RecordingEntry &rhs)

View File

@ -2,7 +2,6 @@
#define GERMANAIRLINESVA_FILE_GATE_H
#include <cstdint>
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>

View File

@ -83,21 +83,21 @@ namespace file
writeString(out, this->outTime, 5);
writeString(out, this->onTime, 5);
writeString(out, this->onBlockTime, 5);
write<float>(out, this->totalFlightTime);
write<float>(out, this->taxiOutFuel);
write<float>(out, this->inFlightFuel);
write<float>(out, this->taxiInFuel);
write<float>(out, this->totalFuel);
write<float>(out, this->taxiOutDistance);
write<float>(out, this->inFlightDistance);
write<float>(out, this->taxiInDistance);
write<float>(out, this->totalDistance);
write<float>(out, this->maxLandingRate);
write<std::uint8_t>(out, this->touchdowns);
write<float>(out, this->maxLandingGees);
write<decltype(this->totalFlightTime)>(out, this->totalFlightTime);
write<decltype(this->taxiOutFuel)>(out, this->taxiOutFuel);
write<decltype(this->inFlightFuel)>(out, this->inFlightFuel);
write<decltype(this->taxiInFuel)>(out, this->taxiInFuel);
write<decltype(this->totalFuel)>(out, this->totalFuel);
write<decltype(this->taxiOutDistance)>(out, this->taxiOutDistance);
write<decltype(this->inFlightDistance)>(out, this->inFlightDistance);
write<decltype(this->taxiInDistance)>(out, this->taxiInDistance);
write<decltype(this->totalDistance)>(out, this->totalDistance);
write<decltype(this->maxLandingRate)>(out, this->maxLandingRate);
write<decltype(this->touchdowns)>(out, this->touchdowns);
write<decltype(this->maxLandingGees)>(out, this->maxLandingGees);
writeString(out, this->recordingFilename);
write<float>(out, this->points);
write<std::uint8_t>(out, this->flags);
write<decltype(this->points)>(out, this->points);
write<decltype(this->flags)>(out, this->flags);
}
} // namespace logbook
} // namespace file

View File

@ -2,5 +2,5 @@
require "Recording.php";
$r = new germanairlinesva_recording\Recording("/mnt/f/X-Plane 12/Resources/plugins/GAConnector/recordings/flight.rec");
$r = new germanairlinesva_recording\Recording("/mnt/f/X-Plane 11/Resources/plugins/GAConnector/recordings/flight.rec");
print_r($r->geoJSON());

View File

@ -6,13 +6,16 @@ namespace file
{
namespace recording
{
void Recording::addSegment(const RecordingEntry &segment)
void Recording::toFile(std::string fileName) const
{
file.resize(file.size() + segment.getBinaryLength());
std::uint8_t *bufPtr =
6 + file.data() + count * segment.getBinaryLength();
std::memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
count++;
std::ofstream out(XPLANE_PLUGIN_DIRECTORY RECORDING_DIRECTORY + fileName,
std::fstream::binary);
char header[] = {'V', 'G', 'A', 'R', '\0', 1};
out.write(header, 6);
for (const RecordingEntry &entry : this->entries) {
entry.toFile(out);
}
out.close();
}
} // namespace recording
} // namespace file

View File

@ -17,20 +17,15 @@ namespace file
this->altitude = altitude;
this->groundSpeed = groundSpeed;
this->coordinates = coordinates;
file = std::vector<std::uint8_t>(
sizeof(this->time) + sizeof(this->altitude) +
sizeof(this->groundSpeed) + sizeof(this->coordinates),
0);
std::uint8_t *bufPtr = file.data();
std::memcpy(bufPtr, &this->time, sizeof(this->time));
bufPtr += sizeof(this->time);
std::memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
bufPtr += sizeof(this->altitude);
std::memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
bufPtr += sizeof(this->groundSpeed);
std::memcpy(bufPtr, &this->coordinates, sizeof(this->coordinates));
};
void RecordingEntry::toFile(std::ofstream &out) const
{
write<decltype(this->time)>(out, this->time);
write<decltype(this->altitude)>(out, this->altitude);
write<decltype(this->groundSpeed)>(out, this->groundSpeed);
write<decltype(this->coordinates)>(out, this->coordinates);
}
} // namespace recording
} // namespace file
} // namespace germanairlinesva

View File

@ -47,10 +47,10 @@ namespace file
void Runway::toFile(std::ofstream &out) const
{
writeString(out, this->designator);
write<struct germanairlinesva::geodata::box>(out, this->bounds);
write<std::uint8_t>(out, this->width);
write<std::uint16_t>(out, this->length);
write<std::uint16_t>(out, this->trueHeading);
write<decltype(this->bounds)>(out, this->bounds);
write<decltype(this->width)>(out, this->width);
write<decltype(this->length)>(out, this->length);
write<decltype(this->trueHeading)>(out, this->trueHeading);
}
} // namespace simdata
} // namespace file

View File

@ -217,11 +217,7 @@ PLUGIN_API void XPluginStop(void)
serverThread.join();
recordingThread.join();
std::ofstream out(XPLANE_PLUGIN_DIRECTORY RECORDING_DIRECTORY "flight.rec",
std::fstream::binary);
out.write(reinterpret_cast<const char *>(p.getBinaryData()),
(std::streamsize)p.getBinaryLength());
out.close();
p.toFile("flight.rec");
}
PLUGIN_API void XPluginDisable(void) {}
@ -318,7 +314,7 @@ void recordingWorker()
{copy.lat, copy.lon});
if (strcmp(copy.path, "") != 0 && copy.pause && lastPath != currentPath) {
p.addSegment(currentPath);
p.addEntry(currentPath);
lastPath = currentPath;
}