Initial Logbook read and write

This commit is contained in:
2022-09-09 02:05:57 +02:00
parent a5e23f4b43
commit b050c23577
19 changed files with 457 additions and 83 deletions
+8 -8
View File
@@ -32,10 +32,10 @@ else()
endif()
if(APPLE)
message("Building file for MacOSX Universal into ${PROJECT_BINARY_DIR}/${PLUGIN_NAME}")
message("Building file for MacOSX Universal into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}")
set_target_properties(file PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}"
BUILD_WITH_INSTALL_NAME_DIR TRUE
)
@@ -49,10 +49,10 @@ if(APPLE)
"-framework Security"
)
elseif(UNIX)
message("Building file for Linux ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
message("Building file for Linux ${BIT} into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}")
set_target_properties(file PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}"
)
target_compile_options(file PRIVATE
@@ -60,16 +60,16 @@ elseif(UNIX)
)
elseif(WIN32)
if (BIT STREQUAL "32")
message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/FSConnect")
message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/ESP/${PLUGIN_NAME}")
set_target_properties(file PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/FSConnect"
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/ESP/${PLUGIN_NAME}"
)
else()
message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}")
set_target_properties(file PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}"
)
endif()
+7 -6
View File
@@ -6,7 +6,9 @@
#include <string>
#include <vector>
#include "constants.h"
#include "logbookEntry.h"
#include "util.hpp"
namespace germanairlinesva_logbook
{
@@ -22,16 +24,15 @@ namespace germanairlinesva_logbook
class Logbook
{
private:
std::ifstream fileStream;
std::vector<std::uint8_t> file{'V', 'G', 'A', 'L', '\0', 1};
std::vector<std::uint8_t> file;
void fromFile();
void readVersion1();
void fromFile(const std::string &file);
void readVersion1(std::ifstream &in);
public:
Logbook(std::ifstream &logbook);
Logbook();
void addEntry(LogbookEntry entry);
void toFile(std::ofstream &logbook);
void toFile();
};
} // namespace germanairlinesva_logbook
+4 -5
View File
@@ -1,5 +1,5 @@
#ifndef GERMANAIRLINESVA_GACONNECTOR_LOGBOOKENTRY_H
#define GERMANAIRLINESVA_GACONNECTOR_LOHBOOKENTRY_H
#define GERMANAIRLINESVA_GACONNECTOR_LOGBOOKENTRY_H
#include <cstdint>
#include <cstring>
@@ -91,7 +91,7 @@ namespace germanairlinesva_logbook
std::string departureGate;
std::string departureRunway;
std::string arrivalAirport;
std::string arrivaleGate;
std::string arrivalGate;
std::string arrivalRunway;
std::string offBlockTime;
std::string outTime;
@@ -123,7 +123,7 @@ namespace germanairlinesva_logbook
std::string departureGate,
std::string departureRunway,
std::string arrivalAirport,
std::string arrivaleGate,
std::string arrivalGate,
std::string arrivalRunway,
std::string offBlockTime,
std::string outTime,
@@ -143,8 +143,7 @@ namespace germanairlinesva_logbook
float maxLandingGees,
std::string recordingFilename,
float points,
std::uint8_t flags,
std::vector<std::uint8_t> file);
std::uint8_t flags);
inline std::uint8_t *getBinaryData() { return file.data(); }
inline std::size_t getBinaryLength() { return file.size(); }
+61
View File
@@ -0,0 +1,61 @@
#include "logbook.h"
namespace germanairlinesva_logbook
{
Logbook::Logbook()
{
if (germanairlinesva_util::fileExists(
XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
} else {
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
this->file.resize(6);
std::memcpy(file.data(), &header, 6);
}
}
void Logbook::fromFile(const std::string &file)
{
std::ifstream in(file, std::ifstream::binary);
// File Header
char ident[5];
in.read(ident, 5);
if (strcmp(ident, "VGAL") != 0) {
throw std::invalid_argument("Wrong file");
}
std::uint8_t version;
in.read(reinterpret_cast<char *>(&version), 1);
if (version == 1) {
return this->readVersion1(in);
}
}
void Logbook::readVersion1(std::ifstream &in)
{
in.seekg(0, std::fstream::end);
std::streampos fileSize = in.tellg();
in.seekg(0, std::ios::beg);
this->file.resize(fileSize);
in.read(reinterpret_cast<char *>(this->file.data()), fileSize);
in.close();
}
void Logbook::addEntry(LogbookEntry entry)
{
std::size_t size = file.size();
file.resize(file.size() + entry.getBinaryLength());
std::uint8_t *bufPtr = file.data() + size;
std::memcpy(bufPtr, entry.getBinaryData(), entry.getBinaryLength());
}
void Logbook::toFile()
{
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK,
std::fstream::binary);
out.write(reinterpret_cast<char *>(this->file.data()), this->file.size());
out.close();
}
} // namespace germanairlinesva_logbook
+191
View File
@@ -0,0 +1,191 @@
#include "logbookEntry.h"
namespace germanairlinesva_logbook
{
LogbookEntry::LogbookEntry(std::string date,
std::string flightNumber,
std::string aircraftType,
std::string aircraftRegistration,
std::string departureAirport,
std::string departureGate,
std::string departureRunway,
std::string arrivalAirport,
std::string arrivalGate,
std::string arrivalRunway,
std::string offBlockTime,
std::string outTime,
std::string inTime,
std::string onBlockTime,
float totalFlightTime,
float taxiOutFuel,
float inFlightFuel,
float taxiInFuel,
float totalFuel,
float taxiOutDistance,
float inFlightDistance,
float taxiInDistance,
float totalDistance,
float maxLandingRate,
std::uint8_t touchdowns,
float maxLandingGees,
std::string recordingFilename,
float points,
std::uint8_t flags)
{
this->date = date;
this->flightNumber = flightNumber;
this->aircraftType = aircraftType;
this->aircraftRegistration = aircraftRegistration;
this->departureAirport = departureAirport;
this->departureGate = departureGate;
this->departureRunway = departureRunway;
this->arrivalAirport = arrivalAirport;
this->arrivalGate = arrivalGate;
this->arrivalRunway = arrivalRunway;
this->offBlockTime = offBlockTime;
this->outTime = outTime;
this->inTime = inTime;
this->onBlockTime = onBlockTime;
this->totalFlightTime = totalFlightTime;
this->taxiOutFuel = taxiOutFuel;
this->inFlightFuel = inFlightFuel;
this->taxiInFuel = taxiInFuel;
this->totalFuel = totalFuel;
this->taxiOutDistance = taxiOutDistance;
this->inFlightDistance = inFlightDistance;
this->taxiInDistance = taxiInDistance;
this->totalDistance = totalDistance;
this->maxLandingRate = maxLandingRate;
this->touchdowns = touchdowns;
this->maxLandingGees = maxLandingGees;
this->recordingFilename = recordingFilename;
this->points = points;
this->flags = flags;
file = std::vector<std::uint8_t>(
this->date.length() + 1 + this->flightNumber.length() + 1 +
this->aircraftType.length() + 1 + this->aircraftRegistration.length() +
1 + 1 + this->departureAirport.length() + 1 + 1 +
this->departureGate.length() + 1 + 1 + this->departureRunway.length() +
1 + 1 + this->arrivalAirport.length() + 1 + 1 +
this->arrivalGate.length() + 1 + 1 + this->arrivalRunway.length() + 1 +
this->offBlockTime.length() + 1 + this->outTime.length() + 1 +
this->inTime.length() + 1 + this->onBlockTime.length() + 1 +
sizeof(this->totalFlightTime) + sizeof(this->taxiOutFuel) +
sizeof(this->inFlightFuel) + sizeof(this->taxiInFuel) +
sizeof(this->totalFuel) + sizeof(this->taxiOutDistance) +
sizeof(this->inFlightDistance) + sizeof(this->taxiInDistance) +
sizeof(this->totalDistance) + sizeof(this->maxLandingRate) +
sizeof(this->touchdowns) + sizeof(this->maxLandingGees) + 1 +
recordingFilename.length() + 1 + sizeof(this->points) +
sizeof(this->flags));
std::uint8_t *bufPtr = file.data();
std::memcpy(bufPtr, this->date.c_str(), this->date.length());
bufPtr += this->date.length() + 1;
std::memcpy(bufPtr,
this->flightNumber.c_str(),
this->flightNumber.length());
bufPtr += this->flightNumber.length() + 1;
std::memcpy(bufPtr,
this->aircraftType.c_str(),
this->aircraftType.length());
bufPtr += this->aircraftType.length() + 1;
std::memcpy(bufPtr,
this->aircraftRegistration.c_str(),
this->aircraftRegistration.length());
bufPtr += this->aircraftRegistration.length() + 1;
std::memset(bufPtr,
static_cast<std::uint8_t>(this->departureAirport.length()),
sizeof(std::uint8_t));
bufPtr++;
std::memcpy(bufPtr,
this->departureAirport.c_str(),
this->departureAirport.length());
bufPtr += this->departureAirport.length() + 1;
std::memset(bufPtr,
static_cast<std::uint8_t>(this->departureGate.length()),
sizeof(std::uint8_t));
bufPtr++;
std::memcpy(bufPtr,
this->departureGate.c_str(),
this->departureGate.length());
bufPtr += this->departureGate.length() + 1;
std::memset(bufPtr,
static_cast<std::uint8_t>(this->departureRunway.length()),
sizeof(std::uint8_t));
bufPtr++;
std::memcpy(bufPtr,
this->departureRunway.c_str(),
this->departureRunway.length());
bufPtr += this->departureRunway.length() + 1;
std::memset(bufPtr,
static_cast<std::uint8_t>(this->arrivalAirport.length()),
sizeof(std::uint8_t));
bufPtr++;
std::memcpy(bufPtr,
this->arrivalAirport.c_str(),
this->arrivalAirport.length());
bufPtr += this->arrivalAirport.length() + 1;
std::memset(bufPtr,
static_cast<std::uint8_t>(this->arrivalGate.length()),
sizeof(std::uint8_t));
bufPtr++;
std::memcpy(bufPtr, this->arrivalGate.c_str(), this->arrivalGate.length());
bufPtr += this->arrivalGate.length() + 1;
std::memset(bufPtr,
static_cast<std::uint8_t>(this->arrivalRunway.length()),
sizeof(std::uint8_t));
bufPtr++;
std::memcpy(bufPtr,
this->arrivalRunway.c_str(),
this->arrivalRunway.length());
bufPtr += this->arrivalRunway.length() + 1;
std::memcpy(bufPtr,
this->offBlockTime.c_str(),
this->offBlockTime.length());
bufPtr += this->offBlockTime.length() + 1;
std::memcpy(bufPtr, this->outTime.c_str(), this->outTime.length());
bufPtr += this->outTime.length() + 1;
std::memcpy(bufPtr, this->inTime.c_str(), this->inTime.length());
bufPtr += this->inTime.length() + 1;
std::memcpy(bufPtr, this->onBlockTime.c_str(), this->onBlockTime.length());
bufPtr += this->onBlockTime.length() + 1;
std::memcpy(bufPtr, &this->totalFlightTime, sizeof(this->totalFlightTime));
bufPtr += sizeof(this->totalFlightTime);
std::memcpy(bufPtr, &this->taxiOutFuel, sizeof(this->taxiOutFuel));
bufPtr += sizeof(this->taxiOutFuel);
std::memcpy(bufPtr, &this->inFlightFuel, sizeof(this->inFlightFuel));
bufPtr += sizeof(this->inFlightFuel);
std::memcpy(bufPtr, &this->taxiInFuel, sizeof(this->taxiInFuel));
bufPtr += sizeof(this->taxiInFuel);
std::memcpy(bufPtr, &this->totalFuel, sizeof(this->totalFuel));
bufPtr += sizeof(this->totalFuel);
std::memcpy(bufPtr, &this->taxiOutDistance, sizeof(this->taxiOutDistance));
bufPtr += sizeof(this->taxiOutDistance);
std::memcpy(bufPtr,
&this->inFlightDistance,
sizeof(this->inFlightDistance));
bufPtr += sizeof(this->inFlightDistance);
std::memcpy(bufPtr, &this->taxiInDistance, sizeof(this->taxiInDistance));
bufPtr += sizeof(this->taxiInDistance);
std::memcpy(bufPtr, &this->totalDistance, sizeof(this->totalDistance));
bufPtr += sizeof(this->totalDistance);
std::memcpy(bufPtr, &this->maxLandingRate, sizeof(this->maxLandingRate));
bufPtr += sizeof(this->maxLandingRate);
std::memcpy(bufPtr, &this->touchdowns, sizeof(this->touchdowns));
bufPtr += sizeof(this->touchdowns);
std::memcpy(bufPtr, &this->maxLandingGees, sizeof(this->maxLandingGees));
bufPtr += sizeof(this->maxLandingGees);
std::memset(bufPtr,
static_cast<std::uint8_t>(this->recordingFilename.length()),
sizeof(std::uint8_t));
bufPtr++;
std::memcpy(bufPtr,
this->recordingFilename.c_str(),
this->recordingFilename.length());
bufPtr += this->recordingFilename.length() + 1;
std::memcpy(bufPtr, &this->points, sizeof(this->points));
bufPtr += sizeof(this->points);
std::memcpy(bufPtr, &this->flags, sizeof(this->flags));
}
} // namespace germanairlinesva_logbook
+1 -1
View File
@@ -2,5 +2,5 @@
require "Recording.php";
$r = new germanairlinesva_recording\Recording("/mnt/f/X-Plane 11/Resources/plugins/GAConnector/flight.rec");
$r = new germanairlinesva_recording\Recording("/mnt/f/X-Plane 12/Resources/plugins/GAConnector/recordings/flight.rec");
print_r($r->geoJSON());