Refactor SimDatabase
This commit is contained in:
parent
4445f1f12a
commit
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:
|
||||
|
||||
77
file/include/simdata/simDatabase.h
Normal file
77
file/include/simdata/simDatabase.h
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_SIMDATABASE_H
|
||||
#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 "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
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace simdata
|
||||
{
|
||||
class SimDatabase
|
||||
{
|
||||
private:
|
||||
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:
|
||||
SimDatabase(int xPlaneVersion,
|
||||
const char *hash,
|
||||
std::unique_ptr<config::Config> &configuration,
|
||||
std::function<void(const std::string)> toLog);
|
||||
|
||||
void toFile() 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)
|
||||
{
|
||||
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>>();
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace simdata
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
|
||||
#endif
|
||||
@ -19,20 +19,20 @@ namespace file
|
||||
const std::string defaultFile,
|
||||
const std::string sceneryPack,
|
||||
const std::string logFile,
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
std::map<std::string, std::pair<std::vector<const Gate>, std::vector<const Runway>>>
|
||||
&airports);
|
||||
|
||||
void makeAirport(
|
||||
const std::string &kind,
|
||||
std::ifstream &infile,
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
std::map<std::string, std::pair<std::vector<const Gate>, std::vector<const Runway>>>
|
||||
&airports,
|
||||
std::ofstream &logfile);
|
||||
void makeGate15(std::vector<Gate> &gates,
|
||||
void makeGate15(std::vector<const 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,174 +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"
|
||||
|
||||
/*
|
||||
* 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(
|
||||
std::map<
|
||||
std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
&airports,
|
||||
const std::string &file)
|
||||
{
|
||||
std::uint8_t null = 0;
|
||||
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);
|
||||
// Num Airports
|
||||
std::uint16_t numAirports = airports.size();
|
||||
out.write(reinterpret_cast<const char *>(&numAirports),
|
||||
sizeof(numAirports));
|
||||
// Airport
|
||||
for (const std::pair<
|
||||
const std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
&airport : airports) {
|
||||
std::string icao = airport.first;
|
||||
std::vector<germanairlinesva::file::simdata::Gate> gates =
|
||||
airport.second.first;
|
||||
std::vector<germanairlinesva::file::simdata::Runway> runways =
|
||||
airport.second.second;
|
||||
// ICAO
|
||||
std::uint8_t icaoLength = icao.length();
|
||||
out.write(reinterpret_cast<const char *>(&icaoLength),
|
||||
sizeof(icaoLength));
|
||||
out.write(icao.c_str(), icaoLength);
|
||||
out.write(reinterpret_cast<const char *>(&null), sizeof(null));
|
||||
// Gates
|
||||
std::uint16_t numGates = gates.size();
|
||||
out.write(reinterpret_cast<const char *>(&numGates), sizeof(numGates));
|
||||
for (germanairlinesva::file::simdata::Gate &gate : gates) {
|
||||
gate.toFile(out);
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways = runways.size();
|
||||
out.write(reinterpret_cast<const char *>(&numRunways),
|
||||
sizeof(numRunways));
|
||||
for (germanairlinesva::file::simdata::Runway &runway : runways) {
|
||||
runway.toFile(out);
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
|
||||
static inline std::map<
|
||||
std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
readVersion1(std::ifstream &in)
|
||||
{
|
||||
std::map<std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
airports;
|
||||
|
||||
std::uint16_t numAirports;
|
||||
in.read(reinterpret_cast<char *>(&numAirports), sizeof(numAirports));
|
||||
|
||||
for (int i = 0; i < numAirports; i++) {
|
||||
// ICAO
|
||||
std::uint8_t icaoLength;
|
||||
in.read(reinterpret_cast<char *>(&icaoLength), sizeof(icaoLength));
|
||||
char *icao = static_cast<char *>(calloc(icaoLength + 1, sizeof(char)));
|
||||
in.read(icao, icaoLength + 1);
|
||||
// Gates
|
||||
std::uint16_t numGates;
|
||||
in.read(reinterpret_cast<char *>(&numGates), sizeof(numGates));
|
||||
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);
|
||||
|
||||
airports[icao].first.emplace_back(designator, center, radius);
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways;
|
||||
in.read(reinterpret_cast<char *>(&numRunways), sizeof(numRunways));
|
||||
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);
|
||||
|
||||
airports[icao].second.emplace_back(designator,
|
||||
bounds,
|
||||
width,
|
||||
length,
|
||||
trueHeading);
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
return airports;
|
||||
}
|
||||
|
||||
static inline std::map<
|
||||
std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
fromFile(const std::string &file)
|
||||
{
|
||||
std::map<std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
airports;
|
||||
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;
|
||||
in.read(reinterpret_cast<char *>(&version), 1);
|
||||
|
||||
if (version == 1) {
|
||||
return readVersion1(in);
|
||||
}
|
||||
return airports;
|
||||
}
|
||||
} // 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) {
|
||||
|
||||
121
file/simDatabase.cpp
Normal file
121
file/simDatabase.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include "simdata/simDatabase.h"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace simdata
|
||||
{
|
||||
SimDatabase::SimDatabase(int xPlaneVersion,
|
||||
const char *hash,
|
||||
std::unique_ptr<config::Config> &configuration,
|
||||
std::function<void(const std::string)> toLog)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void SimDatabase::fromFile()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
} // namespace germanairlinesva
|
||||
@ -10,7 +10,7 @@ namespace file
|
||||
const std::string defaultFile,
|
||||
const std::string sceneryPack,
|
||||
const std::string logFile,
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
std::map<std::string, std::pair<std::vector<const Gate>, std::vector<const Runway>>>
|
||||
&airports)
|
||||
{
|
||||
std::ifstream base(defaultFile);
|
||||
@ -71,14 +71,14 @@ namespace file
|
||||
void makeAirport(
|
||||
const std::string &kind,
|
||||
std::ifstream &infile,
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
std::map<std::string, std::pair<std::vector<const Gate>, std::vector<const Runway>>>
|
||||
&airports,
|
||||
std::ofstream &logfile)
|
||||
{
|
||||
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;
|
||||
@ -104,8 +104,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;
|
||||
@ -124,8 +124,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") {
|
||||
@ -146,7 +146,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;
|
||||
@ -161,7 +161,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],
|
||||
@ -178,7 +178,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"
|
||||
|
||||
|
||||
@ -10,12 +10,9 @@ std::thread serverThread;
|
||||
std::thread recordingThread;
|
||||
std::atomic<bool> wantsExit;
|
||||
|
||||
germanairlinesva::file::config::Config configuration;
|
||||
std::map<std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
airports;
|
||||
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 */
|
||||
@ -114,52 +111,39 @@ 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) {
|
||||
|
||||
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",
|
||||
airports);
|
||||
germanairlinesva::file::simdata::toFile(
|
||||
airports,
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
|
||||
configuration.updateScenery(hash);
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
airports = germanairlinesva::file::simdata::fromFile(
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
toLog("Sim Database loaded");
|
||||
}
|
||||
database = std::make_unique<germanairlinesva::file::simdata::SimDatabase>(
|
||||
xplaneVersion,
|
||||
hash,
|
||||
configuration,
|
||||
toLog);
|
||||
|
||||
toLog("Readback test of sim database using EDDF");
|
||||
auto ap = airports["EDDF"];
|
||||
auto ap = (*database)["EDDF"];
|
||||
for (const auto &it : ap.first) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
for (const auto &it : ap.second) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
toLog("Readback test of sim database using XXXX");
|
||||
auto ap2 = (*database)["XXXX"];
|
||||
ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR");
|
||||
}
|
||||
|
||||
// Thread for sending data to websocket
|
||||
@ -209,10 +193,13 @@ PLUGIN_API void XPluginStop(void)
|
||||
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
delete connector;
|
||||
serverThread.join();
|
||||
recordingThread.join();
|
||||
|
||||
delete connector.release();
|
||||
delete database.release();
|
||||
delete configuration.release();
|
||||
|
||||
p.toFile("flight.rec");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user