Start on Logbook

This commit is contained in:
2022-09-08 02:02:09 +02:00
parent 2bda541bce
commit 8b9f5d0406
15 changed files with 453 additions and 226 deletions
+38
View File
@@ -0,0 +1,38 @@
#ifndef GERMANAIRLINESVA_GACONNECTOR_LOGBOOK_H
#define GERMANAIRLINESVA_GACONNECTOR_LOGBOOK_H
#include <cstdint>
#include <fstream>
#include <string>
#include <vector>
#include "logbookEntry.h"
namespace germanairlinesva_logbook
{
/*
* Logbook Header (6)
* CHAR[5] | UINT8
* --------+--------
* VGAL | VERSION
*
* Logbook Entries (n)
* LOGBOOKENTRY[]
*/
class Logbook
{
private:
std::ifstream fileStream;
std::vector<std::uint8_t> file{'V', 'G', 'A', 'L', '\0', 1};
void fromFile();
void readVersion1();
public:
Logbook(std::ifstream &logbook);
void addEntry(LogbookEntry entry);
void toFile(std::ofstream &logbook);
};
} // namespace germanairlinesva_logbook
#endif
+167
View File
@@ -0,0 +1,167 @@
#ifndef GERMANAIRLINESVA_GACONNECTOR_LOGBOOKENTRY_H
#define GERMANAIRLINESVA_GACONNECTOR_LOHBOOKENTRY_H
#include <cstdint>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
namespace germanairlinesva_logbook
{
/*
* Preamble (24)
* CHAR[10] | CHAR[4] | CHAR[4] | CHAR[6]
* ---------+---------------+----------+-------------
* DATE | FLIGHT NUMBER | AIRCRAFT | REGISTRATION
* Departure Airport Name (2...256)
* UINT8 | CHAR[]
* -------+-------
* STRLEN | STRING
* Departure Gate Name (2...256)
* UINT8 | CHAR[]
* -------+-------
* STRLEN | STRING
* Departure Runway Name (2...256)
* UINT8 | CHAR[]
* -------+-------
* STRLEN | STRING
* Arrival Airport Name (2...256)
* UINT8 | CHAR[]
* -------+-------
* STRLEN | STRING
* Arrival Gate Name (2...256)
* UINT8 | CHAR[]
* -------+-------
* STRLEN | STRING
* Arrival Runway Name (2...256)
* UINT8 | CHAR[]
* -------+-------
* STRLEN | STRING
* Times (24)
* CHAR[5] | CHAR[5] | CHAR[5] | CHAR[4] | FLOAT
* ----------+---------------+--------------+---------------+------
* OFF BLOCK | TAKEOFF (OUT) | LANDING (ON) | ON BLOCK (IN) | TOTAL
* Fuels (16)
* FLOAT | FLOAT | FLOAT | FLOAT
* ---------+-----------+---------+------
* TAXI OUT | IN FLIGHT | TAXI IN | TOTAL
* Distances (16)
* FLOAT | FLOAT | FLOAT |FLOAT
* ---------+-----------+---------+-----
* TAXI OUT | IN FLIGHT | TAXI IN |TOTAL
* Landing (9)
* FLOAT | CHAR | FLOAT
* ---------+---------- +------------
* MAX RATE | TOUCHDOWNS | MAX G-FORCE
* Recording Filename (2...256)
* UINT8 | CHAR[]
* -------+-------
* STRLEN | STRING
* Postamble (5)
* FLOAT32 | BITFIELD
* --------------+---
* POINTS | FLAGS
* Flags Bitfield
* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* ---+---+---+---+---+---+---+-----
* NIL|NIL|NIL|NIL|NIL|NIL|NIL|FILED
*/
class LogbookEntry
{
private:
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 arrivaleGate;
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;
std::vector<std::uint8_t> file;
public:
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 arrivaleGate,
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,
std::vector<std::uint8_t> file);
inline std::uint8_t *getBinaryData() { return file.data(); }
inline std::size_t getBinaryLength() { return file.size(); }
std::string to_string() const
{
std::ostringstream str;
// TO STR
return str.str();
}
friend inline std::ostream &operator<<(std::ostream &os,
const LogbookEntry &gate)
{
return os << gate.to_string();
}
};
} // namespace germanairlinesva_logbook
#endif
+7 -11
View File
@@ -7,29 +7,25 @@
#include "pathSegment.h"
#define CURRENT_VERSION 1
namespace germanairlinesva_recording
{
/*
* Header
*
* Path Recording (6 + n * 24)
* HEADER | SEGMENTS
* Header (6)
* CHAR[5] | UINT8
* --------+--------
* VGAR | VERSION
*/
/*
* Path Recording
*
* Path Segments (n)
* PATHSEGMENT[]
* -------------
* SEGMENTS
*/
class PathRecording
{
private:
std::uint64_t count = 0;
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', 0, CURRENT_VERSION};
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
public:
void addSegment(PathSegment segment);
+1
View File
@@ -10,6 +10,7 @@
namespace germanairlinesva_recording
{
/*
* Path Segment (24)
* UINT32 | UINT16 | UINT16 | POINT
* -------+----------+-------------+------------
* TIME | ALTITUDE | GROUNDSPEED | COORDINATES
+1 -1
View File
@@ -6,7 +6,7 @@ namespace germanairlinesva_recording
{
file.resize(file.size() + segment.getBinaryLength());
std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength();
memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
std::memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
count++;
}
} // namespace germanairlinesva_recording
+4 -4
View File
@@ -17,12 +17,12 @@ namespace germanairlinesva_recording
sizeof(this->groundSpeed) + sizeof(this->coordinates),
0);
std::uint8_t *bufPtr = file.data();
memcpy(bufPtr, &this->time, sizeof(this->time));
std::memcpy(bufPtr, &this->time, sizeof(this->time));
bufPtr += sizeof(this->time);
memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
std::memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
bufPtr += sizeof(this->altitude);
memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
std::memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
bufPtr += sizeof(this->groundSpeed);
memcpy(bufPtr, &this->coordinates, sizeof(this->coordinates));
std::memcpy(bufPtr, &this->coordinates, sizeof(this->coordinates));
};
} // namespace germanairlinesva_recording