Compare commits
2 Commits
161941ac1b
...
6027095c38
| Author | SHA1 | Date | |
|---|---|---|---|
| 6027095c38 | |||
| 2cf03d2933 |
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -63,6 +63,7 @@
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"valarray": "cpp"
|
||||
"valarray": "cpp",
|
||||
"__threading_support": "cpp"
|
||||
},
|
||||
}
|
||||
6
build.sh
6
build.sh
@ -17,11 +17,15 @@ case $1 in
|
||||
;;
|
||||
"win32")
|
||||
cmake -DDEBUG=$DEBUG -DBIT=32 -DCMAKE_TOOLCHAIN_FILE=../toolchain-win-32.cmake ..
|
||||
\cp -rf ../openSSL/win32/*.dll ESP/GAConnector/
|
||||
\cp -rf /opt/llvm-mingw/i686-w64-mingw32/bin/libc++.dll ESP/GAConnector/
|
||||
\cp -rf /opt/llvm-mingw/i686-w64-mingw32/bin/libunwind.dll ESP/GAConnector/
|
||||
;;
|
||||
"win64")
|
||||
cmake -DDEBUG=$DEBUG -DBIT=64 -DCMAKE_TOOLCHAIN_FILE=../toolchain-win-64.cmake ..
|
||||
\cp -rf ../openSSL/win64/*.dll X-Plane/GAConnector/64/
|
||||
\cp -rf ../openSSL/win64/*.dll ESP/GAConnector/
|
||||
\cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libc++.dll X-Plane/GAConnector/64
|
||||
\cp -rf /opt/llvm-mingw/x86_64-w64-mingw32/bin/libunwind.dll X-Plane/GAConnector/64
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@ -81,8 +81,4 @@ elseif(WIN32)
|
||||
-Wl,-pdb=
|
||||
)
|
||||
endif()
|
||||
target_link_options(file PRIVATE
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
#define GERMANAIRLINESVA_FILE_LOGBOOK_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -33,7 +32,7 @@ namespace file
|
||||
private:
|
||||
std::vector<LogbookEntry> entries;
|
||||
|
||||
void fromFile(const std::string &file);
|
||||
void fromFile();
|
||||
void readVersion1(std::ifstream &in);
|
||||
|
||||
public:
|
||||
|
||||
@ -2,15 +2,36 @@
|
||||
#define GERMANAIRLINESVA_FILE_SIMDATABASE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "geodata.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "config/config.h"
|
||||
#include "constants.h"
|
||||
#include "simdata/gate.h"
|
||||
#include "simdata/runway.h"
|
||||
#include "simdata/simdataXP.h"
|
||||
|
||||
/*
|
||||
* Header
|
||||
*
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAS | VERSION
|
||||
*/
|
||||
/*
|
||||
* Airport
|
||||
*
|
||||
* UINT8 | CHAR[] | UINT16 | GATE[] | UINT8 | RUNWAY[]
|
||||
* --------+--------+----------+--------+---------+---------
|
||||
* STRLEN | ICAO | NUMGATES | GATES | NUMRWYS | RUNWAYS
|
||||
*/
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
@ -21,37 +42,32 @@ namespace file
|
||||
class SimDatabase
|
||||
{
|
||||
private:
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
std::map<
|
||||
std::string,
|
||||
std::pair<std::vector<const germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<const germanairlinesva::file::simdata::Runway>>>
|
||||
airports;
|
||||
|
||||
void fromFile();
|
||||
void readVersion1(std::ifstream &in);
|
||||
|
||||
public:
|
||||
void toFile(std::ofstream &out) const;
|
||||
SimDatabase(int xPlaneVersion,
|
||||
const char *hash,
|
||||
std::unique_ptr<config::Config> &configuration,
|
||||
std::function<void(const std::string)> toLog);
|
||||
|
||||
const Gate *checkGate(
|
||||
const std::string icao,
|
||||
const struct germanairlinesva::geodata::point coordinates) const;
|
||||
void toFile() const;
|
||||
|
||||
inline std::size_t numAirports() const { return this->airports.size(); }
|
||||
inline const std::pair<std::vector<Gate>, std::vector<Runway>> &
|
||||
getAirport(std::string icao) const
|
||||
inline std::size_t getCount() const { return this->airports.size(); }
|
||||
inline const std::pair<const std::vector<const Gate>, const std::vector<const Runway>>
|
||||
operator[](std::string key)
|
||||
{
|
||||
return this->airports.at(icao);
|
||||
try {
|
||||
return this->airports.at(key);
|
||||
} catch (std::out_of_range &ex) {
|
||||
return std::pair<const std::vector<const Gate>, const std::vector<const Runway>>();
|
||||
}
|
||||
inline void addAirport(std::string icao,
|
||||
std::vector<Gate> &gates,
|
||||
std::vector<Runway> &runways)
|
||||
{
|
||||
this->airports[icao] = std::make_pair(gates, runways);
|
||||
}
|
||||
template <class... Args>
|
||||
inline void addGate(std::string icao, Args &&...args)
|
||||
{
|
||||
this->airports[icao].first.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
template <class... Args>
|
||||
inline void addRunway(std::string icao, Args &&...args)
|
||||
{
|
||||
this->airports[icao].second.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
} // namespace simdata
|
||||
|
||||
@ -27,9 +27,9 @@ namespace file
|
||||
std::ofstream &logfile);
|
||||
void makeGate15(std::vector<Gate> &gates,
|
||||
const std::vector<std::string> &fields);
|
||||
void makeRunway(std::vector<Runway> &runways,
|
||||
void makeRunway(std::vector<const Runway> &runways,
|
||||
const std::vector<std::string> &fields);
|
||||
void makeGate1300(std::vector<Gate> &gates,
|
||||
void makeGate1300(std::vector<const Gate> &gates,
|
||||
const std::vector<std::string> &fields);
|
||||
} // namespace simdata
|
||||
} // namespace file
|
||||
|
||||
@ -1,114 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_SIMULATORDATABASE_H
|
||||
#define GERMANAIRLINESVA_FILE_SIMULATORDATABASE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "simdata/gate.h"
|
||||
#include "simdata/runway.h"
|
||||
#include "simdata/simDatabase.h"
|
||||
|
||||
/*
|
||||
* Header
|
||||
*
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAS | VERSION
|
||||
*/
|
||||
/*
|
||||
* Airport
|
||||
*
|
||||
* UINT8 | CHAR[] | UINT16 | GATE[] | UINT8 | RUNWAY[]
|
||||
* --------+--------+----------+--------+---------+---------
|
||||
* STRLEN | ICAO | NUMGATES | GATES | NUMRWYS | RUNWAYS
|
||||
*/
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace simdata
|
||||
{
|
||||
static inline void toFile(const SimDatabase &database,
|
||||
const std::string &file)
|
||||
{
|
||||
std::ofstream out(file, std::fstream::binary);
|
||||
|
||||
// File Header, Last member is version
|
||||
std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1};
|
||||
out.write(reinterpret_cast<const char *>(header), 6);
|
||||
|
||||
database.toFile(out);
|
||||
|
||||
out.close();
|
||||
}
|
||||
|
||||
static inline const SimDatabase readVersion1(std::ifstream &in)
|
||||
{
|
||||
SimDatabase database;
|
||||
|
||||
std::uint16_t numAirports = read<std::uint16_t>(in);
|
||||
|
||||
for (int i = 0; i < numAirports; i++) {
|
||||
// ICAO
|
||||
std::string icao = readString(in);
|
||||
// Gates
|
||||
std::uint16_t numGates = read<std::uint16_t>(in);
|
||||
for (int j = 0; j < numGates; j++) {
|
||||
std::string designator = readString(in);
|
||||
struct germanairlinesva::geodata::point center =
|
||||
read<struct germanairlinesva::geodata::point>(in);
|
||||
std::uint8_t radius = read<std::uint8_t>(in);
|
||||
|
||||
database.addGate(icao, designator, center, radius);
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways = read<std::uint8_t>(in);
|
||||
for (int j = 0; j < numRunways; j++) {
|
||||
std::string designator = readString(in);
|
||||
// Bounds
|
||||
struct germanairlinesva::geodata::box bounds =
|
||||
read<struct germanairlinesva::geodata::box>(in);
|
||||
std::uint8_t width = read<std::uint8_t>(in);
|
||||
std::uint16_t length = read<std::uint16_t>(in);
|
||||
std::uint16_t trueHeading = read<std::uint16_t>(in);
|
||||
|
||||
database
|
||||
.addRunway(icao, designator, bounds, width, length, trueHeading);
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
static inline const SimDatabase fromFile(const std::string &file)
|
||||
{
|
||||
std::ifstream in(file, std::ifstream::binary);
|
||||
|
||||
// File Header
|
||||
char ident[5];
|
||||
in.read(ident, 5);
|
||||
if (strcmp(ident, "VGAS") != 0) {
|
||||
throw std::invalid_argument("Wrong file");
|
||||
}
|
||||
std::uint8_t version = read<std::uint8_t>(in);
|
||||
|
||||
if (version == 1) {
|
||||
return readVersion1(in);
|
||||
}
|
||||
|
||||
in.close();
|
||||
return SimDatabase();
|
||||
}
|
||||
} // namespace simdata
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
|
||||
#endif
|
||||
@ -9,22 +9,20 @@ namespace file
|
||||
Logbook::Logbook()
|
||||
{
|
||||
if (germanairlinesva::util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
|
||||
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
|
||||
this->fromFile();
|
||||
}
|
||||
}
|
||||
|
||||
void Logbook::fromFile(const std::string &file)
|
||||
void Logbook::fromFile()
|
||||
{
|
||||
std::ifstream in(file, std::ifstream::binary);
|
||||
std::ifstream in(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::ifstream::binary);
|
||||
|
||||
// File Header
|
||||
char ident[5];
|
||||
in.read(ident, 5);
|
||||
if (strcmp(ident, "VGAL") != 0) {
|
||||
std::string ident = readString(in, 5);
|
||||
if (ident.compare("VGAL") != 0) {
|
||||
throw std::invalid_argument("Wrong file");
|
||||
}
|
||||
std::uint8_t version;
|
||||
in.read(reinterpret_cast<char *>(&version), 1);
|
||||
std::uint8_t version = read<std::uint8_t>(in);
|
||||
|
||||
if (version == 1) {
|
||||
while (in.peek() != EOF) {
|
||||
|
||||
@ -6,33 +6,115 @@ namespace file
|
||||
{
|
||||
namespace simdata
|
||||
{
|
||||
void SimDatabase::toFile(std::ofstream &out) const
|
||||
SimDatabase::SimDatabase(int xPlaneVersion,
|
||||
const char *hash,
|
||||
std::unique_ptr<config::Config> &configuration,
|
||||
std::function<void(const std::string)> toLog)
|
||||
{
|
||||
write<std::uint16_t>(out, this->airports.size());
|
||||
for (const auto &airport : this->airports) {
|
||||
writeString(out, airport.first);
|
||||
write<std::uint16_t>(out, airport.second.first.size());
|
||||
for (const Gate &gate : airport.second.first) {
|
||||
gate.toFile(out);
|
||||
}
|
||||
write<std::uint8_t>(out, airport.second.second.size());
|
||||
for (const Runway &runway : airport.second.second) {
|
||||
runway.toFile(out);
|
||||
}
|
||||
if (strcmp(configuration->getScenery().c_str(), hash) != 0 ||
|
||||
!util::fileExists(XPLANE_PLUGIN_DIRECTORY SIMDATABASE)) {
|
||||
scan(xPlaneVersion < 12000 ? XPLANE11_BASE_SCENERY
|
||||
: XPLANE12_BASE_SCENERY,
|
||||
XPLANE_CUSTOM_SCENERY,
|
||||
XPLANE_PLUGIN_DIRECTORY "log.txt",
|
||||
airports);
|
||||
|
||||
configuration->updateScenery(hash);
|
||||
this->toFile();
|
||||
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
this->fromFile();
|
||||
}
|
||||
}
|
||||
|
||||
const Gate *SimDatabase::checkGate(
|
||||
const std::string icao,
|
||||
const struct germanairlinesva::geodata::point coordinates) const
|
||||
void SimDatabase::fromFile()
|
||||
{
|
||||
auto airport = this->getAirport(icao);
|
||||
for (const Gate &gate : airport.first) {
|
||||
if (gate.contains(coordinates)) {
|
||||
return &gate;
|
||||
std::ifstream in(XPLANE_PLUGIN_DIRECTORY SIMDATABASE,
|
||||
std::ifstream::binary);
|
||||
|
||||
// File Header
|
||||
std::string ident = readString(in, 5);
|
||||
if (ident.compare("VGAS") != 0) {
|
||||
throw std::invalid_argument("Wrong file");
|
||||
}
|
||||
std::uint8_t version = read<std::uint8_t>(in);
|
||||
|
||||
if (version == 1) {
|
||||
this->readVersion1(in);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
void SimDatabase::readVersion1(std::ifstream &in)
|
||||
{
|
||||
std::uint16_t numAirports = read<std::uint16_t>(in);
|
||||
|
||||
for (int i = 0; i < numAirports; i++) {
|
||||
// ICAO
|
||||
std::string icao = readString(in);
|
||||
// Gates
|
||||
std::uint16_t numGates = read<std::uint16_t>(in);
|
||||
for (int j = 0; j < numGates; j++) {
|
||||
std::string designator = readString(in);
|
||||
struct germanairlinesva::geodata::point center =
|
||||
read<struct germanairlinesva::geodata::point>(in);
|
||||
std::uint8_t radius = read<std::uint8_t>(in);
|
||||
|
||||
this->airports[icao].first.emplace_back(designator, center, radius);
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways = read<std::uint8_t>(in);
|
||||
for (int j = 0; j < numRunways; j++) {
|
||||
std::string designator = readString(in);
|
||||
// Bounds
|
||||
struct germanairlinesva::geodata::box bounds =
|
||||
read<struct germanairlinesva::geodata::box>(in);
|
||||
std::uint8_t width = read<std::uint8_t>(in);
|
||||
std::uint16_t length = read<std::uint16_t>(in);
|
||||
std::uint16_t trueHeading = read<std::uint16_t>(in);
|
||||
|
||||
this->airports[icao].second.emplace_back(designator,
|
||||
bounds,
|
||||
width,
|
||||
length,
|
||||
trueHeading);
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
|
||||
void SimDatabase::toFile() const
|
||||
{
|
||||
std::ofstream out(XPLANE_PLUGIN_DIRECTORY SIMDATABASE,
|
||||
std::fstream::binary);
|
||||
|
||||
// File Header, Last member is version
|
||||
std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1};
|
||||
out.write(reinterpret_cast<const char *>(header), 6);
|
||||
// Num Airports
|
||||
write<std::uint16_t>(out, airports.size());
|
||||
// Airport
|
||||
for (const std::pair<const std::string,
|
||||
std::pair<std::vector<const Gate>, std::vector<const Runway>>>
|
||||
&airport : airports) {
|
||||
std::string icao = airport.first;
|
||||
const std::vector<const Gate> gates = airport.second.first;
|
||||
const std::vector<const Runway> runways = airport.second.second;
|
||||
// ICAO
|
||||
writeString(out, icao);
|
||||
// Gates
|
||||
write<std::uint16_t>(out, gates.size());
|
||||
for (const Gate &gate : gates) {
|
||||
gate.toFile(out);
|
||||
}
|
||||
// Runways
|
||||
write<std::uint8_t>(out, runways.size());
|
||||
for (const Runway &runway : runways) {
|
||||
runway.toFile(out);
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
} // namespace simdata
|
||||
} // namespace file
|
||||
|
||||
@ -74,8 +74,8 @@ namespace file
|
||||
{
|
||||
std::string line;
|
||||
std::string *currentIcao = nullptr;
|
||||
std::vector<Gate> tmpGates;
|
||||
std::vector<Runway> tmpRunways;
|
||||
std::vector<const Gate> tmpGates;
|
||||
std::vector<const Runway> tmpRunways;
|
||||
|
||||
int apCount = 0;
|
||||
int validCount = 0;
|
||||
@ -101,8 +101,8 @@ namespace file
|
||||
logfile << "\t<STATUS> " << *currentIcao
|
||||
<< " had no gates or runways" << std::endl;
|
||||
}
|
||||
tmpGates = std::vector<Gate>();
|
||||
tmpRunways = std::vector<Runway>();
|
||||
tmpGates = std::vector<const Gate>();
|
||||
tmpRunways = std::vector<const Runway>();
|
||||
currentIcao = new std::string(fields[4]);
|
||||
apCount += 1;
|
||||
logfile << "\t<" << kind << "> " << line << std::endl;
|
||||
@ -121,8 +121,8 @@ namespace file
|
||||
logfile << "\t<STATUS> " << *currentIcao
|
||||
<< " had no gates or runways" << std::endl;
|
||||
}
|
||||
tmpGates = std::vector<Gate>();
|
||||
tmpRunways = std::vector<Runway>();
|
||||
tmpGates = std::vector<const Gate>();
|
||||
tmpRunways = std::vector<const Runway>();
|
||||
currentIcao = nullptr;
|
||||
logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
|
||||
} else if (currentIcao != nullptr && fields[0] == "100") {
|
||||
@ -143,7 +143,7 @@ namespace file
|
||||
<< validCount << " are valid" << std::endl;
|
||||
}
|
||||
|
||||
void makeGate15(std::vector<Gate> &gates,
|
||||
void makeGate15(std::vector<const Gate> &gates,
|
||||
const std::vector<std::string> &fields)
|
||||
{
|
||||
std::string gateName;
|
||||
@ -158,7 +158,7 @@ namespace file
|
||||
gates.emplace_back(gateName, pt, 40);
|
||||
}
|
||||
|
||||
void makeRunway(std::vector<Runway> &runways,
|
||||
void makeRunway(std::vector<const Runway> &runways,
|
||||
const std::vector<std::string> &fields)
|
||||
{
|
||||
runways.emplace_back(fields[8],
|
||||
@ -175,7 +175,7 @@ namespace file
|
||||
std::stod(fields[1]));
|
||||
}
|
||||
|
||||
void makeGate1300(std::vector<Gate> &gates,
|
||||
void makeGate1300(std::vector<const Gate> &gates,
|
||||
const std::vector<std::string> &fields)
|
||||
{
|
||||
std::string gateName;
|
||||
|
||||
@ -78,7 +78,6 @@ elseif(UNIX)
|
||||
)
|
||||
target_link_libraries(ixwebsocket PRIVATE
|
||||
${OPENSSL_LIBRARIES}
|
||||
pthread
|
||||
)
|
||||
elseif(WIN32)
|
||||
if (BIT STREQUAL "32")
|
||||
@ -107,10 +106,6 @@ elseif(WIN32)
|
||||
-Wl,-pdb=
|
||||
)
|
||||
endif()
|
||||
target_link_options(ixwebsocket PRIVATE
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
)
|
||||
target_include_directories(ixwebsocket PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/openSSL/win${BIT}/include
|
||||
)
|
||||
@ -124,4 +119,8 @@ elseif(WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(ixwebsocket PRIVATE
|
||||
pthread
|
||||
)
|
||||
|
||||
add_library(ixwebsocket::ixwebsocket ALIAS ixwebsocket)
|
||||
@ -170,7 +170,7 @@ namespace util
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *lastHash,
|
||||
const std::function<void(const std::string)> &toLog)
|
||||
const std::function<void(const std::string)> toLog)
|
||||
{
|
||||
int file_descript;
|
||||
unsigned long file_size;
|
||||
@ -205,7 +205,7 @@ namespace util
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *buffer,
|
||||
const std::function<void(const std::string)> &toLog)
|
||||
const std::function<void(const std::string)> toLog)
|
||||
{
|
||||
int file_descriptor;
|
||||
unsigned long file_size;
|
||||
|
||||
@ -80,9 +80,6 @@ elseif(UNIX)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-nodefaultlibs
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
pthread
|
||||
)
|
||||
elseif(WIN32)
|
||||
message("Building for Windows ${BIT} into ${PROJECT_BINARY_DIR}/X-Plane/${PLUGIN_NAME}/${BIT}")
|
||||
|
||||
@ -102,12 +99,6 @@ elseif(WIN32)
|
||||
-Wl,-pdb=
|
||||
)
|
||||
endif()
|
||||
target_link_options(germanairlinesva_xplugin PRIVATE
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/XPSDK/Libraries/Win/XPLM_64.lib
|
||||
)
|
||||
@ -118,4 +109,5 @@ endif()
|
||||
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
ixwebsocket
|
||||
pthread
|
||||
)
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
#include "constants.h"
|
||||
#include "logbook/logbook.h"
|
||||
#include "recording/recording.h"
|
||||
#include "simdata/simDatabase.h"
|
||||
#include "simdata/simdataXP.h"
|
||||
#include "simdata/simulatorDatabase.hpp"
|
||||
#include "util.hpp"
|
||||
#include "websocket.h"
|
||||
|
||||
|
||||
108
xplugin/main.cpp
108
xplugin/main.cpp
@ -10,9 +10,9 @@ std::thread serverThread;
|
||||
std::thread recordingThread;
|
||||
std::atomic<bool> wantsExit;
|
||||
|
||||
germanairlinesva::file::config::Config configuration;
|
||||
germanairlinesva::file::simdata::SimDatabase database;
|
||||
germanairlinesva_websocket::Websocket *connector;
|
||||
std::unique_ptr<germanairlinesva::file::config::Config> configuration;
|
||||
std::unique_ptr<germanairlinesva::file::simdata::SimDatabase> database;
|
||||
std::unique_ptr<germanairlinesva_websocket::Websocket> connector;
|
||||
int xplaneVersion;
|
||||
|
||||
/* Datarefs */
|
||||
@ -111,49 +111,30 @@ 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::file::config::Config();
|
||||
configuration = std::make_unique<germanairlinesva::file::config::Config>();
|
||||
toLog("Config loaded");
|
||||
/*
|
||||
|
||||
try {
|
||||
connector = new germanairlinesva_websocket::Websocket(
|
||||
connector = std::make_unique<germanairlinesva_websocket::Websocket>(
|
||||
"wss://ws.hofmannnet.myhome-server.de:8000",
|
||||
configuration.getUser(),
|
||||
configuration->getUser(),
|
||||
toLog);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
toLog(e.what());
|
||||
return 0;
|
||||
}
|
||||
toLog("WebSocket started");
|
||||
*/
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (germanairlinesva::util::generateMD5(XPLANE_CUSTOM_SCENERY, hash, toLog) ==
|
||||
0) {
|
||||
database = std::make_unique<germanairlinesva::file::simdata::SimDatabase>(
|
||||
xplaneVersion,
|
||||
hash,
|
||||
configuration,
|
||||
toLog);
|
||||
|
||||
if (strcmp(configuration.getScenery().c_str(), hash) != 0 ||
|
||||
!germanairlinesva::util::fileExists(
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE)) {
|
||||
scan(xplaneVersion < 12000 ? XPLANE11_BASE_SCENERY
|
||||
: XPLANE12_BASE_SCENERY,
|
||||
XPLANE_CUSTOM_SCENERY,
|
||||
XPLANE_PLUGIN_DIRECTORY "log.txt",
|
||||
database);
|
||||
germanairlinesva::file::simdata::toFile(
|
||||
database,
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
|
||||
configuration.updateScenery(hash);
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
database = germanairlinesva::file::simdata::fromFile(
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
toLog("Sim Database loaded");
|
||||
}
|
||||
|
||||
toLog("Binary readback test");
|
||||
germanairlinesva::file::simdata::toFile(database,
|
||||
XPLANE_PLUGIN_DIRECTORY "sim2.bin");
|
||||
toLog("Readback test of sim database using EDDF");
|
||||
auto ap = database.getAirport("EDDF");
|
||||
auto ap = (*database)["EDDF"];
|
||||
for (const auto &it : ap.first) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
@ -161,64 +142,17 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
toLog("Readback test of sim database using XXXX");
|
||||
try {
|
||||
ap = database.getAirport("XXXX");
|
||||
toLog(" Return was non null ! ERROR");
|
||||
} catch (std::out_of_range) {
|
||||
toLog(" Return was null");
|
||||
}
|
||||
auto ap2 = (*database)["XXXX"];
|
||||
ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR");
|
||||
}
|
||||
|
||||
// Thread for sending data to websocket
|
||||
// serverThread = std::thread(&serverWorker);
|
||||
// recordingThread = std::thread(&recordingWorker);
|
||||
toLog("Workers started");
|
||||
delete connector.release();
|
||||
delete database.release();
|
||||
delete configuration.release();
|
||||
|
||||
toLog("Logbook Test");
|
||||
germanairlinesva::file::logbook::Logbook logbook;
|
||||
logbook.addEntry("08.09.2022",
|
||||
"1000",
|
||||
"L049",
|
||||
"D-ALFA",
|
||||
"John F. Kennedy International Aiport / EDDF",
|
||||
"A1",
|
||||
"14L",
|
||||
"Gander International Airport / CYQX",
|
||||
"10",
|
||||
"03",
|
||||
"10:00",
|
||||
"10:20",
|
||||
"13:20",
|
||||
"13:30",
|
||||
210.5,
|
||||
20.1,
|
||||
5012.4156,
|
||||
8.87,
|
||||
5041.3856,
|
||||
7.1,
|
||||
971.14,
|
||||
2.41,
|
||||
980.65,
|
||||
-165.23,
|
||||
1,
|
||||
1.2012,
|
||||
"2022-09-08_VGA1000",
|
||||
5.5,
|
||||
1);
|
||||
logbook.toFile();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
PLUGIN_API void XPluginStop(void)
|
||||
{
|
||||
/* Flight Loop */
|
||||
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
// serverThread.join();
|
||||
// recordingThread.join();
|
||||
// delete connector;
|
||||
delete connector.release();
|
||||
delete database.release();
|
||||
delete configuration.release();
|
||||
|
||||
p.toFile("flight.rec");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user