diff --git a/.clang-format b/.clang-format index 9173886..35594a3 100644 --- a/.clang-format +++ b/.clang-format @@ -30,7 +30,7 @@ IndentCaseLabels: true IndentFunctionDeclarationAfterType: true IndentWidth: 2 MaxEmptyLinesToKeep: 2 -NamespaceIndentation: All +NamespaceIndentation: Inner ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true ObjCBlockIndentWidth: 4 diff --git a/file/include/config.hpp b/file/include/config.hpp deleted file mode 100644 index 40740dc..0000000 --- a/file/include/config.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_CONFIG_H -#define GERMANAIRLINESVA_GACONNECTOR_CONFIG_H - -#include - -#include -#include -#include -#include - -#include "util.hpp" - -namespace germanairlinesva_config -{ - static inline std::map - readConfig(const std::string &file) - { - std::ifstream config(file); - std::map settings; - - std::string line; - while (std::getline(config, line)) { - std::vector 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 &config, - const std::string &file) - { - std::ofstream cfg(file); - for (const std::pair &entry : config) { - cfg << entry.first << '=' << entry.second << '\n'; - } - cfg.close(); - } -} // namespace germanairlinesva_config -#endif diff --git a/file/include/config/config.hpp b/file/include/config/config.hpp new file mode 100644 index 0000000..2176ed2 --- /dev/null +++ b/file/include/config/config.hpp @@ -0,0 +1,53 @@ +#ifndef GERMANAIRLINESVA_FILE_CONFIG_H +#define GERMANAIRLINESVA_FILE_CONFIG_H + +#include + +#include +#include +#include +#include + +#include "util.hpp" + +namespace germanairlinesva +{ +namespace file +{ + namespace config + { + static inline std::map + readConfig(const std::string &file) + { + std::ifstream config(file); + std::map settings; + + std::string line; + while (std::getline(config, line)) { + std::vector 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 &config, + const std::string &file) + { + std::ofstream cfg(file); + for (const std::pair &entry : config) { + cfg << entry.first << '=' << entry.second << '\n'; + } + cfg.close(); + } + } // namespace config +} // namespace file +} // namespace germanairlinesva +#endif diff --git a/file/include/helpers.hpp b/file/include/helpers.hpp new file mode 100644 index 0000000..e6a3e55 --- /dev/null +++ b/file/include/helpers.hpp @@ -0,0 +1,57 @@ +#ifndef GERMANAIRLINESVA_FILE_HELPERS_H +#define GERMANAIRLINESVA_FILE_HELPERS_H + +#include +#include +#include +#include + +namespace germanairlinesva +{ +namespace file +{ + static inline const std::string readString(std::ifstream &in, + std::uint8_t length) + { + std::vector 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(&length), 1); + std::vector value(length + 1); + in.read(value.data(), length); + return std::string(std::move(value.data())); + } + + template static inline const T read(std::ifstream &in) + { + T value; + in.read(reinterpret_cast(&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(&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 static inline void write(std::ofstream &out, T value) + { + out.write(reinterpret_cast(&value), sizeof(value)); + } +} // namespace file +} // namespace germanairlinesva + +#endif \ No newline at end of file diff --git a/file/include/logbook.h b/file/include/logbook.h deleted file mode 100644 index 290acf0..0000000 --- a/file/include/logbook.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_LOGBOOK_H -#define GERMANAIRLINESVA_GACONNECTOR_LOGBOOK_H - -#include -#include -#include -#include -#include - -#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 entries; - - void fromFile(const std::string &file); - void readVersion1(std::ifstream &in); - - public: - Logbook(); - - template inline void addEntry(Args &&...args) - { - this->entries.emplace_back(std::forward(args)...); - } - void toFile() const; - }; -} // namespace germanairlinesva_logbook - -#endif \ No newline at end of file diff --git a/file/include/logbook/logbook.h b/file/include/logbook/logbook.h new file mode 100644 index 0000000..7178c20 --- /dev/null +++ b/file/include/logbook/logbook.h @@ -0,0 +1,51 @@ +#ifndef GERMANAIRLINESVA_FILE_LOGBOOK_H +#define GERMANAIRLINESVA_FILE_LOGBOOK_H + +#include +#include +#include +#include +#include +#include + +#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 entries; + + void fromFile(const std::string &file); + void readVersion1(std::ifstream &in); + + public: + Logbook(); + + template inline void addEntry(Args &&...args) + { + this->entries.emplace_back(std::forward(args)...); + } + void toFile() const; + }; + } // namespace logbook +} // namespace file +} // namespace germanairlinesva +#endif \ No newline at end of file diff --git a/file/include/logbook/logbookEntry.h b/file/include/logbook/logbookEntry.h new file mode 100644 index 0000000..36e23ea --- /dev/null +++ b/file/include/logbook/logbookEntry.h @@ -0,0 +1,158 @@ +#ifndef GERMANAIRLINESVA_FILE_LOGBOOKENTRY_H +#define GERMANAIRLINESVA_FILE_LOGBOOKENTRY_H + +#include +#include +#include +#include + +#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 \ No newline at end of file diff --git a/file/include/logbookEntry.h b/file/include/logbookEntry.h deleted file mode 100644 index 219a1b3..0000000 --- a/file/include/logbookEntry.h +++ /dev/null @@ -1,153 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_LOGBOOKENTRY_H -#define GERMANAIRLINESVA_GACONNECTOR_LOGBOOKENTRY_H - -#include -#include -#include -#include -#include - -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 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 \ No newline at end of file diff --git a/file/include/pathRecording.h b/file/include/pathRecording.h deleted file mode 100644 index 5243d33..0000000 --- a/file/include/pathRecording.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDING_H -#define GERMANAIRLINESVA_GACONNECTOR_RECORDING_H - -#include -#include -#include - -#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 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 \ No newline at end of file diff --git a/file/include/pathSegment.h b/file/include/pathSegment.h deleted file mode 100644 index be07ec7..0000000 --- a/file/include/pathSegment.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H -#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H - -#include -#include -#include - -#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 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 diff --git a/file/include/recording/recording.h b/file/include/recording/recording.h new file mode 100644 index 0000000..06e4a79 --- /dev/null +++ b/file/include/recording/recording.h @@ -0,0 +1,44 @@ +#ifndef GERMANAIRLINESVA_FILE_RECORDING_H +#define GERMANAIRLINESVA_FILE_RECORDING_H + +#include +#include +#include + +#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 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 \ No newline at end of file diff --git a/file/include/recording/recordingEntry.h b/file/include/recording/recordingEntry.h new file mode 100644 index 0000000..165b0f1 --- /dev/null +++ b/file/include/recording/recordingEntry.h @@ -0,0 +1,59 @@ +#ifndef GERMANAIRLINESVA_FILE_RECORDINGENTRY_H +#define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H + +#include +#include +#include + +#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 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 diff --git a/file/logbook.cpp b/file/logbook.cpp index b6b8132..c9d66c0 100644 --- a/file/logbook.cpp +++ b/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(&version), 1); + + if (version == 1) { + while (in.peek() != EOF) { + this->readVersion1(in); + } + } } - std::uint8_t version; - in.read(reinterpret_cast(&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(in); + float taxiOutFuel = read(in); + float inFlightFuel = read(in); + float taxiInFuel = read(in); + float totalFuel = read(in); + float taxiOutDistance = read(in); + float inFlightDistance = read(in); + float taxiInDistance = read(in); + float totalDistance = read(in); + float maxLandingRate = read(in); + std::uint8_t touchdowns = read(in); + float maxLandingGees = read(in); + std::string recordingFilename = readString(in); + float points = read(in); + std::uint8_t flags = read(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(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 \ No newline at end of file + } // namespace logbook +} // namespace file +} // namespace germanairlinesva \ No newline at end of file diff --git a/file/logbookEntry.cpp b/file/logbookEntry.cpp index 9446f28..ae91c0f 100644 --- a/file/logbookEntry.cpp +++ b/file/logbookEntry.cpp @@ -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( - 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(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(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(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(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(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(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(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 \ No newline at end of file + 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(out, this->totalFlightTime); + write(out, this->taxiOutFuel); + write(out, this->inFlightFuel); + write(out, this->taxiInFuel); + write(out, this->totalFuel); + write(out, this->taxiOutDistance); + write(out, this->inFlightDistance); + write(out, this->taxiInDistance); + write(out, this->totalDistance); + write(out, this->maxLandingRate); + write(out, this->touchdowns); + write(out, this->maxLandingGees); + writeString(out, this->recordingFilename); + write(out, this->points); + write(out, this->flags); + } + } // namespace logbook +} // namespace file +} // namespace germanairlinesva \ No newline at end of file diff --git a/file/pathRecording.cpp b/file/pathRecording.cpp deleted file mode 100644 index 7de4d0e..0000000 --- a/file/pathRecording.cpp +++ /dev/null @@ -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 \ No newline at end of file diff --git a/file/pathSegment.cpp b/file/pathSegment.cpp deleted file mode 100644 index 47214ef..0000000 --- a/file/pathSegment.cpp +++ /dev/null @@ -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( - 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 \ No newline at end of file diff --git a/file/recording.cpp b/file/recording.cpp new file mode 100644 index 0000000..973c21d --- /dev/null +++ b/file/recording.cpp @@ -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 \ No newline at end of file diff --git a/file/recordingEntry.cpp b/file/recordingEntry.cpp new file mode 100644 index 0000000..35ab58f --- /dev/null +++ b/file/recordingEntry.cpp @@ -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( + 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 \ No newline at end of file diff --git a/xplugin/include/main.h b/xplugin/include/main.h index 0d1256e..4e37b94 100644 --- a/xplugin/include/main.h +++ b/xplugin/include/main.h @@ -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" diff --git a/xplugin/main.cpp b/xplugin/main.cpp index 722ec18..f1695c0 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -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(copy.alt), static_cast(copy.gs),