Future proofed file read/write
This commit is contained in:
parent
699e2a4784
commit
2fc2170763
@ -30,7 +30,7 @@ IndentCaseLabels: true
|
||||
IndentFunctionDeclarationAfterType: true
|
||||
IndentWidth: 2
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: All
|
||||
NamespaceIndentation: Inner
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
ObjCBlockIndentWidth: 4
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_CONFIG_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_CONFIG_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace germanairlinesva_config
|
||||
{
|
||||
static inline std::map<std::string, std::string>
|
||||
readConfig(const std::string &file)
|
||||
{
|
||||
std::ifstream config(file);
|
||||
std::map<std::string, std::string> settings;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(config, line)) {
|
||||
std::vector<std::string> fields = germanairlinesva_util::split(line, '=');
|
||||
if (fields.size() >= 2) {
|
||||
germanairlinesva_util::trim(fields[0]);
|
||||
germanairlinesva_util::trim(fields[1]);
|
||||
settings[fields[0]] = fields[1];
|
||||
}
|
||||
}
|
||||
|
||||
config.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
static inline void
|
||||
writeConfig(const std::map<std::string, std::string> &config,
|
||||
const std::string &file)
|
||||
{
|
||||
std::ofstream cfg(file);
|
||||
for (const std::pair<const std::string, std::string> &entry : config) {
|
||||
cfg << entry.first << '=' << entry.second << '\n';
|
||||
}
|
||||
cfg.close();
|
||||
}
|
||||
} // namespace germanairlinesva_config
|
||||
#endif
|
||||
53
file/include/config/config.hpp
Normal file
53
file/include/config/config.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_CONFIG_H
|
||||
#define GERMANAIRLINESVA_FILE_CONFIG_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace config
|
||||
{
|
||||
static inline std::map<std::string, std::string>
|
||||
readConfig(const std::string &file)
|
||||
{
|
||||
std::ifstream config(file);
|
||||
std::map<std::string, std::string> settings;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(config, line)) {
|
||||
std::vector<std::string> fields =
|
||||
germanairlinesva_util::split(line, '=');
|
||||
if (fields.size() >= 2) {
|
||||
germanairlinesva_util::trim(fields[0]);
|
||||
germanairlinesva_util::trim(fields[1]);
|
||||
settings[fields[0]] = fields[1];
|
||||
}
|
||||
}
|
||||
|
||||
config.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
static inline void
|
||||
writeConfig(const std::map<std::string, std::string> &config,
|
||||
const std::string &file)
|
||||
{
|
||||
std::ofstream cfg(file);
|
||||
for (const std::pair<const std::string, std::string> &entry : config) {
|
||||
cfg << entry.first << '=' << entry.second << '\n';
|
||||
}
|
||||
cfg.close();
|
||||
}
|
||||
} // namespace config
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
#endif
|
||||
57
file/include/helpers.hpp
Normal file
57
file/include/helpers.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_HELPERS_H
|
||||
#define GERMANAIRLINESVA_FILE_HELPERS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
static inline const std::string readString(std::ifstream &in,
|
||||
std::uint8_t length)
|
||||
{
|
||||
std::vector<char> value(length + 1);
|
||||
in.read(value.data(), length);
|
||||
return std::string(std::move(value.data()));
|
||||
}
|
||||
|
||||
static inline const std::string readString(std::ifstream &in)
|
||||
{
|
||||
std::uint8_t length;
|
||||
in.read(reinterpret_cast<char *>(&length), 1);
|
||||
std::vector<char> value(length + 1);
|
||||
in.read(value.data(), length);
|
||||
return std::string(std::move(value.data()));
|
||||
}
|
||||
|
||||
template <typename T> static inline const T read(std::ifstream &in)
|
||||
{
|
||||
T value;
|
||||
in.read(reinterpret_cast<char *>(&value), sizeof(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline void writeString(std::ofstream &out, std::string value)
|
||||
{
|
||||
std::uint8_t length = value.length();
|
||||
out.write(reinterpret_cast<char *>(&length), sizeof(length));
|
||||
out.write(value.data(), length);
|
||||
}
|
||||
|
||||
static inline void
|
||||
writeString(std::ofstream &out, std::string value, std::uint8_t length)
|
||||
{
|
||||
out.write(value.data(), length);
|
||||
}
|
||||
|
||||
template <typename T> static inline void write(std::ofstream &out, T value)
|
||||
{
|
||||
out.write(reinterpret_cast<char *>(&value), sizeof(value));
|
||||
}
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
|
||||
#endif
|
||||
@ -1,44 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_LOGBOOK_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_LOGBOOK_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "constants.h"
|
||||
#include "logbookEntry.h"
|
||||
#include "util.hpp"
|
||||
|
||||
namespace germanairlinesva_logbook
|
||||
{
|
||||
/*
|
||||
* Logbook Header (6)
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAL | VERSION
|
||||
*
|
||||
* Logbook Entries (n)
|
||||
* LOGBOOKENTRY[]
|
||||
*/
|
||||
class Logbook
|
||||
{
|
||||
private:
|
||||
std::vector<LogbookEntry> entries;
|
||||
|
||||
void fromFile(const std::string &file);
|
||||
void readVersion1(std::ifstream &in);
|
||||
|
||||
public:
|
||||
Logbook();
|
||||
|
||||
template <class... Args> inline void addEntry(Args &&...args)
|
||||
{
|
||||
this->entries.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
void toFile() const;
|
||||
};
|
||||
} // namespace germanairlinesva_logbook
|
||||
|
||||
#endif
|
||||
51
file/include/logbook/logbook.h
Normal file
51
file/include/logbook/logbook.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_LOGBOOK_H
|
||||
#define GERMANAIRLINESVA_FILE_LOGBOOK_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "constants.h"
|
||||
#include "helpers.hpp"
|
||||
#include "logbookEntry.h"
|
||||
#include "util.hpp"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace logbook
|
||||
{
|
||||
/*
|
||||
* Logbook Header (6)
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAL | VERSION
|
||||
*
|
||||
* Logbook Entries (n)
|
||||
* LOGBOOKENTRY[]
|
||||
*/
|
||||
class Logbook
|
||||
{
|
||||
private:
|
||||
std::vector<LogbookEntry> entries;
|
||||
|
||||
void fromFile(const std::string &file);
|
||||
void readVersion1(std::ifstream &in);
|
||||
|
||||
public:
|
||||
Logbook();
|
||||
|
||||
template <class... Args> inline void addEntry(Args &&...args)
|
||||
{
|
||||
this->entries.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
void toFile() const;
|
||||
};
|
||||
} // namespace logbook
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
#endif
|
||||
158
file/include/logbook/logbookEntry.h
Normal file
158
file/include/logbook/logbookEntry.h
Normal file
@ -0,0 +1,158 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_LOGBOOKENTRY_H
|
||||
#define GERMANAIRLINESVA_FILE_LOGBOOKENTRY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace 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)
|
||||
* FLOAT | 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 arrivalGate;
|
||||
std::string arrivalRunway;
|
||||
std::string offBlockTime;
|
||||
std::string outTime;
|
||||
std::string onTime;
|
||||
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;
|
||||
|
||||
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 arrivalGate,
|
||||
std::string arrivalRunway,
|
||||
std::string offBlockTime,
|
||||
std::string outTime,
|
||||
std::string onTime,
|
||||
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);
|
||||
|
||||
void toFile(std::ofstream &out) const;
|
||||
};
|
||||
} // namespace logbook
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
|
||||
#endif
|
||||
@ -1,153 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_LOGBOOKENTRY_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_LOGBOOKENTRY_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)
|
||||
* FLOAT | 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 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;
|
||||
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 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);
|
||||
|
||||
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
||||
inline std::size_t getBinaryLength() const { return file.size(); }
|
||||
};
|
||||
} // namespace germanairlinesva_logbook
|
||||
|
||||
#endif
|
||||
@ -1,39 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDING_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_RECORDING_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "pathSegment.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
/*
|
||||
* Path Recording (6 + n * 24)
|
||||
* HEADER | SEGMENTS
|
||||
|
||||
* Header (6)
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAR | VERSION
|
||||
|
||||
* Path Segments (n)
|
||||
* PATHSEGMENT[]
|
||||
*/
|
||||
class PathRecording
|
||||
{
|
||||
private:
|
||||
std::uint64_t count = 0;
|
||||
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
|
||||
|
||||
public:
|
||||
void addSegment(const PathSegment &segment);
|
||||
|
||||
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
||||
inline std::size_t getBinaryLength() const { return file.size(); }
|
||||
};
|
||||
|
||||
} // namespace germanairlinesva_recording
|
||||
|
||||
#endif
|
||||
@ -1,53 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "geodata.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
/*
|
||||
* Path Segment (24)
|
||||
* UINT32 | UINT16 | UINT16 | POINT
|
||||
* -------+----------+-------------+------------
|
||||
* TIME | ALTITUDE | GROUNDSPEED | COORDINATES
|
||||
*/
|
||||
class PathSegment
|
||||
{
|
||||
private:
|
||||
std::uint32_t time = 0;
|
||||
std::uint16_t altitude = 0;
|
||||
std::uint16_t groundSpeed = 0;
|
||||
struct germanairlinesva_geodata::point coordinates;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
PathSegment() = default;
|
||||
PathSegment(std::uint32_t time,
|
||||
std::uint16_t altitude,
|
||||
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(); }
|
||||
|
||||
friend inline bool operator==(const PathSegment &lhs,
|
||||
const PathSegment &rhs)
|
||||
{
|
||||
return lhs.altitude == rhs.altitude &&
|
||||
lhs.groundSpeed == rhs.groundSpeed &&
|
||||
lhs.coordinates.latitude == rhs.coordinates.latitude &&
|
||||
lhs.coordinates.longitude == rhs.coordinates.longitude;
|
||||
}
|
||||
friend inline bool operator!=(const PathSegment &lhs,
|
||||
const PathSegment &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
};
|
||||
} // namespace germanairlinesva_recording
|
||||
|
||||
#endif
|
||||
44
file/include/recording/recording.h
Normal file
44
file/include/recording/recording.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_RECORDING_H
|
||||
#define GERMANAIRLINESVA_FILE_RECORDING_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "recordingEntry.h"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace recording
|
||||
{
|
||||
/*
|
||||
* Path Recording (6 + n * 24)
|
||||
* HEADER | SEGMENTS
|
||||
|
||||
* Header (6)
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAR | VERSION
|
||||
|
||||
* Path Segments (n)
|
||||
* PATHSEGMENT[]
|
||||
*/
|
||||
class Recording
|
||||
{
|
||||
private:
|
||||
std::uint64_t count = 0;
|
||||
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
|
||||
|
||||
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(); }
|
||||
};
|
||||
} // namespace recording
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
|
||||
#endif
|
||||
59
file/include/recording/recordingEntry.h
Normal file
59
file/include/recording/recordingEntry.h
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_RECORDINGENTRY_H
|
||||
#define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "geodata.h"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace recording
|
||||
{
|
||||
/*
|
||||
* Path Segment (24)
|
||||
* UINT32 | UINT16 | UINT16 | POINT
|
||||
* -------+----------+-------------+------------
|
||||
* TIME | ALTITUDE | GROUNDSPEED | COORDINATES
|
||||
*/
|
||||
class RecordingEntry
|
||||
{
|
||||
private:
|
||||
std::uint32_t time = 0;
|
||||
std::uint16_t altitude = 0;
|
||||
std::uint16_t groundSpeed = 0;
|
||||
struct germanairlinesva_geodata::point coordinates;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
RecordingEntry() = default;
|
||||
RecordingEntry(std::uint32_t time,
|
||||
std::uint16_t altitude,
|
||||
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(); }
|
||||
|
||||
friend inline bool operator==(const RecordingEntry &lhs,
|
||||
const RecordingEntry &rhs)
|
||||
{
|
||||
return lhs.altitude == rhs.altitude &&
|
||||
lhs.groundSpeed == rhs.groundSpeed &&
|
||||
lhs.coordinates.latitude == rhs.coordinates.latitude &&
|
||||
lhs.coordinates.longitude == rhs.coordinates.longitude;
|
||||
}
|
||||
friend inline bool operator!=(const RecordingEntry &lhs,
|
||||
const RecordingEntry &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
};
|
||||
} // namespace recording
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
|
||||
#endif
|
||||
133
file/logbook.cpp
133
file/logbook.cpp
@ -1,44 +1,111 @@
|
||||
#include "logbook.h"
|
||||
#include "logbook/logbook.h"
|
||||
|
||||
namespace germanairlinesva_logbook
|
||||
namespace germanairlinesva
|
||||
{
|
||||
Logbook::Logbook()
|
||||
namespace file
|
||||
{
|
||||
namespace logbook
|
||||
{
|
||||
if (germanairlinesva_util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
|
||||
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
|
||||
Logbook::Logbook()
|
||||
{
|
||||
if (germanairlinesva_util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
|
||||
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logbook::fromFile(const std::string &file)
|
||||
{
|
||||
std::ifstream in(file, std::ifstream::binary);
|
||||
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");
|
||||
// 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) {
|
||||
while (in.peek() != EOF) {
|
||||
this->readVersion1(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::uint8_t version;
|
||||
in.read(reinterpret_cast<char *>(&version), 1);
|
||||
|
||||
if (version == 1) {
|
||||
return this->readVersion1(in);
|
||||
void Logbook::readVersion1(std::ifstream &in)
|
||||
{
|
||||
std::string date = readString(in, 10);
|
||||
std::string flightNumber = readString(in, 4);
|
||||
std::string aircraftType = readString(in, 4);
|
||||
std::string aircraftRegistration = readString(in, 6);
|
||||
std::string departureAirport = readString(in);
|
||||
std::string departureGate = readString(in);
|
||||
std::string departureRunway = readString(in);
|
||||
std::string arrivalAirport = readString(in);
|
||||
std::string arrivalGate = readString(in);
|
||||
std::string arrivalRunway = readString(in);
|
||||
std::string offBlockTime = readString(in, 5);
|
||||
std::string outTime = readString(in, 5);
|
||||
std::string inTime = readString(in, 5);
|
||||
std::string onBlockTime = readString(in, 5);
|
||||
float totalFlightTime = read<float>(in);
|
||||
float taxiOutFuel = read<float>(in);
|
||||
float inFlightFuel = read<float>(in);
|
||||
float taxiInFuel = read<float>(in);
|
||||
float totalFuel = read<float>(in);
|
||||
float taxiOutDistance = read<float>(in);
|
||||
float inFlightDistance = read<float>(in);
|
||||
float taxiInDistance = read<float>(in);
|
||||
float totalDistance = read<float>(in);
|
||||
float maxLandingRate = read<float>(in);
|
||||
std::uint8_t touchdowns = read<std::uint8_t>(in);
|
||||
float maxLandingGees = read<float>(in);
|
||||
std::string recordingFilename = readString(in);
|
||||
float points = read<float>(in);
|
||||
std::uint8_t flags = read<std::uint8_t>(in);
|
||||
|
||||
this->addEntry(date,
|
||||
flightNumber,
|
||||
aircraftType,
|
||||
aircraftRegistration,
|
||||
departureAirport,
|
||||
departureGate,
|
||||
departureRunway,
|
||||
arrivalAirport,
|
||||
arrivalGate,
|
||||
arrivalRunway,
|
||||
offBlockTime,
|
||||
outTime,
|
||||
inTime,
|
||||
onBlockTime,
|
||||
totalFlightTime,
|
||||
taxiOutFuel,
|
||||
inFlightFuel,
|
||||
taxiInFuel,
|
||||
totalFuel,
|
||||
taxiOutDistance,
|
||||
inFlightDistance,
|
||||
taxiInDistance,
|
||||
totalDistance,
|
||||
maxLandingRate,
|
||||
touchdowns,
|
||||
maxLandingGees,
|
||||
recordingFilename,
|
||||
points,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
|
||||
void Logbook::readVersion1(std::ifstream &in) {}
|
||||
|
||||
|
||||
void Logbook::toFile() const
|
||||
{
|
||||
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::fstream::binary);
|
||||
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
|
||||
out.write(header, 6);
|
||||
for (const LogbookEntry &entry : this->entries) {
|
||||
out.write(reinterpret_cast<const char *>(entry.getBinaryData()),
|
||||
entry.getBinaryLength());
|
||||
void Logbook::toFile() const
|
||||
{
|
||||
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::fstream::binary);
|
||||
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
|
||||
out.write(header, 6);
|
||||
for (const LogbookEntry &entry : this->entries) {
|
||||
entry.toFile(out);
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
} // namespace germanairlinesva_logbook
|
||||
} // namespace logbook
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
@ -1,191 +1,104 @@
|
||||
#include "logbookEntry.h"
|
||||
#include "logbook/logbookEntry.h"
|
||||
|
||||
namespace germanairlinesva_logbook
|
||||
namespace germanairlinesva
|
||||
{
|
||||
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)
|
||||
namespace file
|
||||
{
|
||||
namespace logbook
|
||||
{
|
||||
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;
|
||||
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 onTime,
|
||||
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->onTime = onTime;
|
||||
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
|
||||
void LogbookEntry::toFile(std::ofstream &out) const
|
||||
{
|
||||
writeString(out, this->date, 10);
|
||||
writeString(out, this->flightNumber, 4);
|
||||
writeString(out, this->aircraftType, 4);
|
||||
writeString(out, this->aircraftRegistration, 6);
|
||||
writeString(out, this->departureAirport);
|
||||
writeString(out, this->departureGate);
|
||||
writeString(out, this->departureRunway);
|
||||
writeString(out, this->arrivalAirport);
|
||||
writeString(out, this->arrivalGate);
|
||||
writeString(out, this->arrivalRunway);
|
||||
writeString(out, this->offBlockTime, 5);
|
||||
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);
|
||||
writeString(out, this->recordingFilename);
|
||||
write<float>(out, this->points);
|
||||
write<std::uint8_t>(out, this->flags);
|
||||
}
|
||||
} // namespace logbook
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
@ -1,12 +0,0 @@
|
||||
#include "pathRecording.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
void PathRecording::addSegment(const PathSegment &segment)
|
||||
{
|
||||
file.resize(file.size() + segment.getBinaryLength());
|
||||
std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength();
|
||||
std::memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
|
||||
count++;
|
||||
}
|
||||
} // namespace germanairlinesva_recording
|
||||
@ -1,28 +0,0 @@
|
||||
#include "pathSegment.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
PathSegment::PathSegment(std::uint32_t time,
|
||||
std::uint16_t altitude,
|
||||
std::uint16_t groundSpeed,
|
||||
struct germanairlinesva_geodata::point coordinates)
|
||||
{
|
||||
this->time = time;
|
||||
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));
|
||||
};
|
||||
} // namespace germanairlinesva_recording
|
||||
19
file/recording.cpp
Normal file
19
file/recording.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "recording/recording.h"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace recording
|
||||
{
|
||||
void Recording::addSegment(const RecordingEntry &segment)
|
||||
{
|
||||
file.resize(file.size() + segment.getBinaryLength());
|
||||
std::uint8_t *bufPtr =
|
||||
6 + file.data() + count * segment.getBinaryLength();
|
||||
std::memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
|
||||
count++;
|
||||
}
|
||||
} // namespace recording
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
36
file/recordingEntry.cpp
Normal file
36
file/recordingEntry.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "recording/recordingEntry.h"
|
||||
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace recording
|
||||
{
|
||||
RecordingEntry::RecordingEntry(
|
||||
std::uint32_t time,
|
||||
std::uint16_t altitude,
|
||||
std::uint16_t groundSpeed,
|
||||
struct germanairlinesva_geodata::point coordinates)
|
||||
{
|
||||
this->time = time;
|
||||
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));
|
||||
};
|
||||
} // namespace recording
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
@ -1,10 +1,10 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
||||
|
||||
#include "config.hpp"
|
||||
#include "config/config.hpp"
|
||||
#include "constants.h"
|
||||
#include "logbook.h"
|
||||
#include "pathRecording.h"
|
||||
#include "logbook/logbook.h"
|
||||
#include "recording/recording.h"
|
||||
#include "simdata.h"
|
||||
#include "simulatorDatabase.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
@ -47,7 +47,7 @@ XPLMDataRef roll;
|
||||
XPLMDataRef quaternion;
|
||||
|
||||
struct germanairlinesva_websocket::data toSend;
|
||||
germanairlinesva_recording::PathRecording p;
|
||||
germanairlinesva::file::recording::Recording p;
|
||||
|
||||
/*
|
||||
* Callbacks
|
||||
@ -114,8 +114,8 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
|
||||
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
|
||||
|
||||
configuration =
|
||||
germanairlinesva_config::readConfig(XPLANE_PLUGIN_DIRECTORY CONFIG);
|
||||
configuration = germanairlinesva::file::config::readConfig(
|
||||
XPLANE_PLUGIN_DIRECTORY CONFIG);
|
||||
toLog("Config loaded");
|
||||
|
||||
try {
|
||||
@ -145,8 +145,9 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
|
||||
configuration["scenery"] = hash;
|
||||
germanairlinesva_config::writeConfig(configuration,
|
||||
XPLANE_PLUGIN_DIRECTORY CONFIG);
|
||||
germanairlinesva::file::config::writeConfig(
|
||||
configuration,
|
||||
XPLANE_PLUGIN_DIRECTORY CONFIG);
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
airports = germanairlinesva_simdata::fromFile(
|
||||
@ -170,7 +171,7 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
toLog("Workers started");
|
||||
|
||||
toLog("Logbook Test");
|
||||
germanairlinesva_logbook::Logbook logbook;
|
||||
germanairlinesva::file::logbook::Logbook logbook;
|
||||
logbook.addEntry("08.09.2022",
|
||||
"1000",
|
||||
"L049",
|
||||
@ -298,7 +299,7 @@ void recordingWorker()
|
||||
{
|
||||
germanairlinesva_util::setThreadName("GARecordingWorker");
|
||||
|
||||
germanairlinesva_recording::PathSegment lastPath;
|
||||
germanairlinesva::file::recording::RecordingEntry lastPath;
|
||||
std::uint32_t segment = 0;
|
||||
|
||||
while (!wantsExit) {
|
||||
@ -309,7 +310,7 @@ void recordingWorker()
|
||||
std::memcpy(©, &toSend, sizeof(germanairlinesva_websocket::data));
|
||||
}
|
||||
|
||||
germanairlinesva_recording::PathSegment currentPath(
|
||||
germanairlinesva::file::recording::RecordingEntry currentPath(
|
||||
segment,
|
||||
static_cast<std::uint16_t>(copy.alt),
|
||||
static_cast<std::uint16_t>(copy.gs),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user