Recording now uses new write
This commit is contained in:
parent
94fbc1f558
commit
d6d3c0b4d9
5
TODO.md
5
TODO.md
@ -1,3 +1,6 @@
|
|||||||
- Reverse engineer FSUIPC .NET onRunway Check
|
- Reverse engineer FSUIPC .NET onRunway Check
|
||||||
- Update OSXCross Docker image to SDK 11
|
- 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
|
||||||
@ -18,8 +18,8 @@ namespace file
|
|||||||
void Gate::toFile(std::ofstream &out) const
|
void Gate::toFile(std::ofstream &out) const
|
||||||
{
|
{
|
||||||
writeString(out, this->designator);
|
writeString(out, this->designator);
|
||||||
write<struct germanairlinesva::geodata::point>(out, this->center);
|
write<decltype(this->center)>(out, this->center);
|
||||||
write<std::uint8_t>(out, this->radius);
|
write<decltype(this->radius)>(out, this->radius);
|
||||||
}
|
}
|
||||||
} // namespace simdata
|
} // namespace simdata
|
||||||
} // namespace file
|
} // namespace file
|
||||||
|
|||||||
@ -2,9 +2,10 @@
|
|||||||
#define GERMANAIRLINESVA_FILE_RECORDING_H
|
#define GERMANAIRLINESVA_FILE_RECORDING_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
#include "recordingEntry.h"
|
#include "recordingEntry.h"
|
||||||
|
|
||||||
namespace germanairlinesva
|
namespace germanairlinesva
|
||||||
@ -28,14 +29,14 @@ namespace file
|
|||||||
class Recording
|
class Recording
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::uint64_t count = 0;
|
std::vector<RecordingEntry> entries;
|
||||||
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void addSegment(const RecordingEntry &segment);
|
template <class... Args> inline void addEntry(Args &&...args)
|
||||||
|
{
|
||||||
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
this->entries.emplace_back(std::forward<Args>(args)...);
|
||||||
inline std::size_t getBinaryLength() const { return file.size(); }
|
}
|
||||||
|
void toFile(std::string fileName) const;
|
||||||
};
|
};
|
||||||
} // namespace recording
|
} // namespace recording
|
||||||
} // namespace file
|
} // namespace file
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
#define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H
|
#define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "geodata.hpp"
|
#include "geodata.hpp"
|
||||||
|
#include "helpers.hpp"
|
||||||
|
|
||||||
namespace germanairlinesva
|
namespace germanairlinesva
|
||||||
{
|
{
|
||||||
@ -22,11 +23,10 @@ namespace file
|
|||||||
class RecordingEntry
|
class RecordingEntry
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::uint32_t time = 0;
|
std::uint32_t time;
|
||||||
std::uint16_t altitude = 0;
|
std::uint16_t altitude;
|
||||||
std::uint16_t groundSpeed = 0;
|
std::uint16_t groundSpeed;
|
||||||
struct germanairlinesva::geodata::point coordinates;
|
struct germanairlinesva::geodata::point coordinates;
|
||||||
std::vector<std::uint8_t> file;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RecordingEntry() = default;
|
RecordingEntry() = default;
|
||||||
@ -35,8 +35,7 @@ namespace file
|
|||||||
std::uint16_t groundSpeed,
|
std::uint16_t groundSpeed,
|
||||||
struct germanairlinesva::geodata::point coordinates);
|
struct germanairlinesva::geodata::point coordinates);
|
||||||
|
|
||||||
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
void toFile(std::ofstream &out) const;
|
||||||
inline std::size_t getBinaryLength() const { return file.size(); }
|
|
||||||
|
|
||||||
friend inline bool operator==(const RecordingEntry &lhs,
|
friend inline bool operator==(const RecordingEntry &lhs,
|
||||||
const RecordingEntry &rhs)
|
const RecordingEntry &rhs)
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#define GERMANAIRLINESVA_FILE_GATE_H
|
#define GERMANAIRLINESVA_FILE_GATE_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@ -83,21 +83,21 @@ namespace file
|
|||||||
writeString(out, this->outTime, 5);
|
writeString(out, this->outTime, 5);
|
||||||
writeString(out, this->onTime, 5);
|
writeString(out, this->onTime, 5);
|
||||||
writeString(out, this->onBlockTime, 5);
|
writeString(out, this->onBlockTime, 5);
|
||||||
write<float>(out, this->totalFlightTime);
|
write<decltype(this->totalFlightTime)>(out, this->totalFlightTime);
|
||||||
write<float>(out, this->taxiOutFuel);
|
write<decltype(this->taxiOutFuel)>(out, this->taxiOutFuel);
|
||||||
write<float>(out, this->inFlightFuel);
|
write<decltype(this->inFlightFuel)>(out, this->inFlightFuel);
|
||||||
write<float>(out, this->taxiInFuel);
|
write<decltype(this->taxiInFuel)>(out, this->taxiInFuel);
|
||||||
write<float>(out, this->totalFuel);
|
write<decltype(this->totalFuel)>(out, this->totalFuel);
|
||||||
write<float>(out, this->taxiOutDistance);
|
write<decltype(this->taxiOutDistance)>(out, this->taxiOutDistance);
|
||||||
write<float>(out, this->inFlightDistance);
|
write<decltype(this->inFlightDistance)>(out, this->inFlightDistance);
|
||||||
write<float>(out, this->taxiInDistance);
|
write<decltype(this->taxiInDistance)>(out, this->taxiInDistance);
|
||||||
write<float>(out, this->totalDistance);
|
write<decltype(this->totalDistance)>(out, this->totalDistance);
|
||||||
write<float>(out, this->maxLandingRate);
|
write<decltype(this->maxLandingRate)>(out, this->maxLandingRate);
|
||||||
write<std::uint8_t>(out, this->touchdowns);
|
write<decltype(this->touchdowns)>(out, this->touchdowns);
|
||||||
write<float>(out, this->maxLandingGees);
|
write<decltype(this->maxLandingGees)>(out, this->maxLandingGees);
|
||||||
writeString(out, this->recordingFilename);
|
writeString(out, this->recordingFilename);
|
||||||
write<float>(out, this->points);
|
write<decltype(this->points)>(out, this->points);
|
||||||
write<std::uint8_t>(out, this->flags);
|
write<decltype(this->flags)>(out, this->flags);
|
||||||
}
|
}
|
||||||
} // namespace logbook
|
} // namespace logbook
|
||||||
} // namespace file
|
} // namespace file
|
||||||
|
|||||||
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
require "Recording.php";
|
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());
|
print_r($r->geoJSON());
|
||||||
|
|||||||
@ -6,13 +6,16 @@ namespace file
|
|||||||
{
|
{
|
||||||
namespace recording
|
namespace recording
|
||||||
{
|
{
|
||||||
void Recording::addSegment(const RecordingEntry &segment)
|
void Recording::toFile(std::string fileName) const
|
||||||
{
|
{
|
||||||
file.resize(file.size() + segment.getBinaryLength());
|
std::ofstream out(XPLANE_PLUGIN_DIRECTORY RECORDING_DIRECTORY + fileName,
|
||||||
std::uint8_t *bufPtr =
|
std::fstream::binary);
|
||||||
6 + file.data() + count * segment.getBinaryLength();
|
char header[] = {'V', 'G', 'A', 'R', '\0', 1};
|
||||||
std::memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
|
out.write(header, 6);
|
||||||
count++;
|
for (const RecordingEntry &entry : this->entries) {
|
||||||
|
entry.toFile(out);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
}
|
}
|
||||||
} // namespace recording
|
} // namespace recording
|
||||||
} // namespace file
|
} // namespace file
|
||||||
|
|||||||
@ -17,20 +17,15 @@ namespace file
|
|||||||
this->altitude = altitude;
|
this->altitude = altitude;
|
||||||
this->groundSpeed = groundSpeed;
|
this->groundSpeed = groundSpeed;
|
||||||
this->coordinates = coordinates;
|
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 recording
|
||||||
} // namespace file
|
} // namespace file
|
||||||
} // namespace germanairlinesva
|
} // namespace germanairlinesva
|
||||||
@ -47,10 +47,10 @@ namespace file
|
|||||||
void Runway::toFile(std::ofstream &out) const
|
void Runway::toFile(std::ofstream &out) const
|
||||||
{
|
{
|
||||||
writeString(out, this->designator);
|
writeString(out, this->designator);
|
||||||
write<struct germanairlinesva::geodata::box>(out, this->bounds);
|
write<decltype(this->bounds)>(out, this->bounds);
|
||||||
write<std::uint8_t>(out, this->width);
|
write<decltype(this->width)>(out, this->width);
|
||||||
write<std::uint16_t>(out, this->length);
|
write<decltype(this->length)>(out, this->length);
|
||||||
write<std::uint16_t>(out, this->trueHeading);
|
write<decltype(this->trueHeading)>(out, this->trueHeading);
|
||||||
}
|
}
|
||||||
} // namespace simdata
|
} // namespace simdata
|
||||||
} // namespace file
|
} // namespace file
|
||||||
|
|||||||
@ -217,11 +217,7 @@ PLUGIN_API void XPluginStop(void)
|
|||||||
serverThread.join();
|
serverThread.join();
|
||||||
recordingThread.join();
|
recordingThread.join();
|
||||||
|
|
||||||
std::ofstream out(XPLANE_PLUGIN_DIRECTORY RECORDING_DIRECTORY "flight.rec",
|
p.toFile("flight.rec");
|
||||||
std::fstream::binary);
|
|
||||||
out.write(reinterpret_cast<const char *>(p.getBinaryData()),
|
|
||||||
(std::streamsize)p.getBinaryLength());
|
|
||||||
out.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PLUGIN_API void XPluginDisable(void) {}
|
PLUGIN_API void XPluginDisable(void) {}
|
||||||
@ -318,7 +314,7 @@ void recordingWorker()
|
|||||||
{copy.lat, copy.lon});
|
{copy.lat, copy.lon});
|
||||||
|
|
||||||
if (strcmp(copy.path, "") != 0 && copy.pause && lastPath != currentPath) {
|
if (strcmp(copy.path, "") != 0 && copy.pause && lastPath != currentPath) {
|
||||||
p.addSegment(currentPath);
|
p.addEntry(currentPath);
|
||||||
lastPath = currentPath;
|
lastPath = currentPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user