Consts and references
This commit is contained in:
parent
b050c23577
commit
699e2a4784
@ -4,6 +4,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
@ -24,15 +25,19 @@ namespace germanairlinesva_logbook
|
|||||||
class Logbook
|
class Logbook
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<std::uint8_t> file;
|
std::vector<LogbookEntry> entries;
|
||||||
|
|
||||||
void fromFile(const std::string &file);
|
void fromFile(const std::string &file);
|
||||||
void readVersion1(std::ifstream &in);
|
void readVersion1(std::ifstream &in);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Logbook();
|
Logbook();
|
||||||
void addEntry(LogbookEntry entry);
|
|
||||||
void toFile();
|
template <class... Args> inline void addEntry(Args &&...args)
|
||||||
|
{
|
||||||
|
this->entries.emplace_back(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
void toFile() const;
|
||||||
};
|
};
|
||||||
} // namespace germanairlinesva_logbook
|
} // namespace germanairlinesva_logbook
|
||||||
|
|
||||||
|
|||||||
@ -71,14 +71,14 @@ namespace germanairlinesva_logbook
|
|||||||
* STRLEN | STRING
|
* STRLEN | STRING
|
||||||
|
|
||||||
* Postamble (5)
|
* Postamble (5)
|
||||||
* FLOAT32 | BITFIELD
|
* FLOAT | BITFIELD
|
||||||
* --------------+---
|
* -------+---------
|
||||||
* POINTS | FLAGS
|
* POINTS | FLAGS
|
||||||
|
|
||||||
* Flags Bitfield
|
* Flags Bitfield
|
||||||
* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
|
* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
|
||||||
* ---+---+---+---+---+---+---+-----
|
* ----+-----+-----+-----+-----+-----+-----+------
|
||||||
* NIL|NIL|NIL|NIL|NIL|NIL|NIL|FILED
|
* NIL | NIL | NIL | NIL | NIL | NIL | NIL | FILED
|
||||||
*/
|
*/
|
||||||
class LogbookEntry
|
class LogbookEntry
|
||||||
{
|
{
|
||||||
@ -145,21 +145,8 @@ namespace germanairlinesva_logbook
|
|||||||
float points,
|
float points,
|
||||||
std::uint8_t flags);
|
std::uint8_t flags);
|
||||||
|
|
||||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
||||||
inline std::size_t getBinaryLength() { return file.size(); }
|
inline std::size_t getBinaryLength() const { return file.size(); }
|
||||||
|
|
||||||
std::string to_string() const
|
|
||||||
{
|
|
||||||
std::ostringstream str;
|
|
||||||
// TO STR
|
|
||||||
return str.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline std::ostream &operator<<(std::ostream &os,
|
|
||||||
const LogbookEntry &gate)
|
|
||||||
{
|
|
||||||
return os << gate.to_string();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} // namespace germanairlinesva_logbook
|
} // namespace germanairlinesva_logbook
|
||||||
|
|
||||||
|
|||||||
@ -28,10 +28,10 @@ namespace germanairlinesva_recording
|
|||||||
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
|
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void addSegment(PathSegment segment);
|
void addSegment(const PathSegment &segment);
|
||||||
|
|
||||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
||||||
inline std::size_t getBinaryLength() { return file.size(); }
|
inline std::size_t getBinaryLength() const { return file.size(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace germanairlinesva_recording
|
} // namespace germanairlinesva_recording
|
||||||
|
|||||||
@ -31,8 +31,8 @@ namespace germanairlinesva_recording
|
|||||||
std::uint16_t groundSpeed,
|
std::uint16_t groundSpeed,
|
||||||
struct germanairlinesva_geodata::point coordinates);
|
struct germanairlinesva_geodata::point coordinates);
|
||||||
|
|
||||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
||||||
inline std::size_t getBinaryLength() { return file.size(); }
|
inline std::size_t getBinaryLength() const { return file.size(); }
|
||||||
|
|
||||||
friend inline bool operator==(const PathSegment &lhs,
|
friend inline bool operator==(const PathSegment &lhs,
|
||||||
const PathSegment &rhs)
|
const PathSegment &rhs)
|
||||||
|
|||||||
@ -4,13 +4,8 @@ namespace germanairlinesva_logbook
|
|||||||
{
|
{
|
||||||
Logbook::Logbook()
|
Logbook::Logbook()
|
||||||
{
|
{
|
||||||
if (germanairlinesva_util::fileExists(
|
if (germanairlinesva_util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
|
||||||
XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
|
|
||||||
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
|
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
|
||||||
} else {
|
|
||||||
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
|
|
||||||
this->file.resize(6);
|
|
||||||
std::memcpy(file.data(), &header, 6);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,30 +27,18 @@ namespace germanairlinesva_logbook
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logbook::readVersion1(std::ifstream &in)
|
void Logbook::readVersion1(std::ifstream &in) {}
|
||||||
{
|
|
||||||
in.seekg(0, std::fstream::end);
|
|
||||||
std::streampos fileSize = in.tellg();
|
|
||||||
in.seekg(0, std::ios::beg);
|
|
||||||
|
|
||||||
this->file.resize(fileSize);
|
|
||||||
in.read(reinterpret_cast<char *>(this->file.data()), fileSize);
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Logbook::addEntry(LogbookEntry entry)
|
void Logbook::toFile() const
|
||||||
{
|
{
|
||||||
std::size_t size = file.size();
|
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::fstream::binary);
|
||||||
file.resize(file.size() + entry.getBinaryLength());
|
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
|
||||||
std::uint8_t *bufPtr = file.data() + size;
|
out.write(header, 6);
|
||||||
std::memcpy(bufPtr, entry.getBinaryData(), entry.getBinaryLength());
|
for (const LogbookEntry &entry : this->entries) {
|
||||||
}
|
out.write(reinterpret_cast<const char *>(entry.getBinaryData()),
|
||||||
|
entry.getBinaryLength());
|
||||||
void Logbook::toFile()
|
}
|
||||||
{
|
|
||||||
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK,
|
|
||||||
std::fstream::binary);
|
|
||||||
out.write(reinterpret_cast<char *>(this->file.data()), this->file.size());
|
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
} // namespace germanairlinesva_logbook
|
} // namespace germanairlinesva_logbook
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace germanairlinesva_recording
|
namespace germanairlinesva_recording
|
||||||
{
|
{
|
||||||
void PathRecording::addSegment(PathSegment segment)
|
void PathRecording::addSegment(const PathSegment &segment)
|
||||||
{
|
{
|
||||||
file.resize(file.size() + segment.getBinaryLength());
|
file.resize(file.size() + segment.getBinaryLength());
|
||||||
std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength();
|
std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength();
|
||||||
|
|||||||
@ -28,7 +28,7 @@ namespace germanairlinesva_simdata
|
|||||||
|
|
||||||
// From database
|
// From database
|
||||||
Gate::Gate(std::string designator,
|
Gate::Gate(std::string designator,
|
||||||
germanairlinesva_geodata::point center,
|
struct germanairlinesva_geodata::point center,
|
||||||
std::uint8_t radius)
|
std::uint8_t radius)
|
||||||
{
|
{
|
||||||
this->designator = designator;
|
this->designator = designator;
|
||||||
|
|||||||
@ -29,7 +29,7 @@ namespace germanairlinesva_simdata
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string designator;
|
std::string designator;
|
||||||
germanairlinesva_geodata::point center;
|
struct germanairlinesva_geodata::point center;
|
||||||
std::uint8_t radius;
|
std::uint8_t radius;
|
||||||
std::vector<std::uint8_t> file;
|
std::vector<std::uint8_t> file;
|
||||||
|
|
||||||
@ -41,13 +41,13 @@ namespace germanairlinesva_simdata
|
|||||||
std::uint8_t radius);
|
std::uint8_t radius);
|
||||||
// From database
|
// From database
|
||||||
Gate(std::string designator,
|
Gate(std::string designator,
|
||||||
germanairlinesva_geodata::point center,
|
struct germanairlinesva_geodata::point center,
|
||||||
std::uint8_t radius);
|
std::uint8_t radius);
|
||||||
|
|
||||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
||||||
inline std::size_t getBinaryLength() { return file.size(); }
|
inline std::size_t getBinaryLength() const { return file.size(); }
|
||||||
|
|
||||||
std::string to_string() const
|
inline const std::string to_string() const
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
str << "Gate " << this->designator << " at " << this->center.latitude
|
str << "Gate " << this->designator << " at " << this->center.latitude
|
||||||
|
|||||||
@ -49,10 +49,10 @@ namespace germanairlinesva_simdata
|
|||||||
std::uint16_t length,
|
std::uint16_t length,
|
||||||
std::uint16_t trueHeading);
|
std::uint16_t trueHeading);
|
||||||
|
|
||||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
inline const std::uint8_t *getBinaryData() const { return file.data(); }
|
||||||
inline std::size_t getBinaryLength() { return file.size(); }
|
inline std::size_t getBinaryLength() const { return file.size(); }
|
||||||
|
|
||||||
std::string to_string() const
|
inline const std::string to_string() const
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
str << "Runway " << this->designator << " with bounds "
|
str << "Runway " << this->designator << " with bounds "
|
||||||
|
|||||||
@ -12,9 +12,9 @@
|
|||||||
namespace germanairlinesva_simdata
|
namespace germanairlinesva_simdata
|
||||||
{
|
{
|
||||||
int scan(
|
int scan(
|
||||||
const char *defaultFile,
|
const std::string defaultFile,
|
||||||
const char *sceneryPack,
|
const std::string sceneryPack,
|
||||||
const char *logFile,
|
const std::string logFile,
|
||||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||||
&airports);
|
&airports);
|
||||||
|
|
||||||
@ -24,10 +24,12 @@ namespace germanairlinesva_simdata
|
|||||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||||
&airports,
|
&airports,
|
||||||
std::ofstream &logfile);
|
std::ofstream &logfile);
|
||||||
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields);
|
void makeGate15(std::vector<Gate> &gates,
|
||||||
void makeRunway(std::vector<Runway> *runways,
|
const std::vector<std::string> &fields);
|
||||||
std::vector<std::string> fields);
|
void makeRunway(std::vector<Runway> &runways,
|
||||||
void makeGate1300(std::vector<Gate> *gates, std::vector<std::string> fields);
|
const std::vector<std::string> &fields);
|
||||||
|
void makeGate1300(std::vector<Gate> &gates,
|
||||||
|
const std::vector<std::string> &fields);
|
||||||
|
|
||||||
} // namespace germanairlinesva_simdata
|
} // namespace germanairlinesva_simdata
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,7 @@ namespace germanairlinesva_simdata
|
|||||||
static_cast<char *>(calloc(designatorLength + 1, sizeof(char)));
|
static_cast<char *>(calloc(designatorLength + 1, sizeof(char)));
|
||||||
in.read(designator, designatorLength + 1);
|
in.read(designator, designatorLength + 1);
|
||||||
// Center
|
// Center
|
||||||
germanairlinesva_geodata::point center;
|
struct germanairlinesva_geodata::point center;
|
||||||
in.read(reinterpret_cast<char *>(¢er), sizeof(center));
|
in.read(reinterpret_cast<char *>(¢er), sizeof(center));
|
||||||
// Radius
|
// Radius
|
||||||
std::uint8_t radius;
|
std::uint8_t radius;
|
||||||
@ -133,7 +133,7 @@ namespace germanairlinesva_simdata
|
|||||||
static_cast<char *>(calloc(designatorLength + 1, sizeof(char)));
|
static_cast<char *>(calloc(designatorLength + 1, sizeof(char)));
|
||||||
in.read(designator, designatorLength + 1);
|
in.read(designator, designatorLength + 1);
|
||||||
// Bounds
|
// Bounds
|
||||||
germanairlinesva_geodata::box bounds;
|
struct germanairlinesva_geodata::box bounds;
|
||||||
in.read(reinterpret_cast<char *>(&bounds), sizeof(bounds));
|
in.read(reinterpret_cast<char *>(&bounds), sizeof(bounds));
|
||||||
// Width
|
// Width
|
||||||
std::uint8_t width;
|
std::uint8_t width;
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
namespace germanairlinesva_simdata
|
namespace germanairlinesva_simdata
|
||||||
{
|
{
|
||||||
int scan(
|
int scan(
|
||||||
const char *defaultFile,
|
const std::string defaultFile,
|
||||||
const char *sceneryPack,
|
const std::string sceneryPack,
|
||||||
const char *logFile,
|
const std::string logFile,
|
||||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||||
&airports)
|
&airports)
|
||||||
{
|
{
|
||||||
@ -38,7 +38,7 @@ namespace germanairlinesva_simdata
|
|||||||
std::string path =
|
std::string path =
|
||||||
germanairlinesva_util::rtrim_copy(line.substr(pos + 13)) +
|
germanairlinesva_util::rtrim_copy(line.substr(pos + 13)) +
|
||||||
"Earth nav data/apt.dat";
|
"Earth nav data/apt.dat";
|
||||||
packs.push_back(path);
|
packs.emplace_back(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::reverse(packs.begin(), packs.end());
|
std::reverse(packs.begin(), packs.end());
|
||||||
@ -104,7 +104,7 @@ namespace germanairlinesva_simdata
|
|||||||
apCount += 1;
|
apCount += 1;
|
||||||
logfile << "\t<" << kind << "> " << line << std::endl;
|
logfile << "\t<" << kind << "> " << line << std::endl;
|
||||||
} else if (currentIcao != nullptr && fields[0] == "15") {
|
} else if (currentIcao != nullptr && fields[0] == "15") {
|
||||||
makeGate15(&tmpGates, fields);
|
makeGate15(tmpGates, fields);
|
||||||
logfile << "\t\t<GATE OLD> " << line << std::endl;
|
logfile << "\t\t<GATE OLD> " << line << std::endl;
|
||||||
} else if (fields[0] == "16" || fields[0] == "17") {
|
} else if (fields[0] == "16" || fields[0] == "17") {
|
||||||
// Write to file if ICAO is valid, and we have gates and runways
|
// Write to file if ICAO is valid, and we have gates and runways
|
||||||
@ -122,10 +122,10 @@ namespace germanairlinesva_simdata
|
|||||||
currentIcao = nullptr;
|
currentIcao = nullptr;
|
||||||
logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
|
logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
|
||||||
} else if (currentIcao != nullptr && fields[0] == "100") {
|
} else if (currentIcao != nullptr && fields[0] == "100") {
|
||||||
makeRunway(&tmpRunways, fields);
|
makeRunway(tmpRunways, fields);
|
||||||
logfile << "\t\t<RUNWAY> " << line << std::endl;
|
logfile << "\t\t<RUNWAY> " << line << std::endl;
|
||||||
} else if (currentIcao != nullptr && fields[0] == "1300") {
|
} else if (currentIcao != nullptr && fields[0] == "1300") {
|
||||||
makeGate1300(&tmpGates, fields);
|
makeGate1300(tmpGates, fields);
|
||||||
logfile << "\t\t<GATE> " << line << std::endl;
|
logfile << "\t\t<GATE> " << line << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,7 +139,8 @@ namespace germanairlinesva_simdata
|
|||||||
<< validCount << " are valid" << std::endl;
|
<< validCount << " are valid" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields)
|
void makeGate15(std::vector<Gate> &gates,
|
||||||
|
const std::vector<std::string> &fields)
|
||||||
{
|
{
|
||||||
std::string gateName;
|
std::string gateName;
|
||||||
for (size_t j = 4; j < fields.size() - 1; j++) {
|
for (size_t j = 4; j < fields.size() - 1; j++) {
|
||||||
@ -148,27 +149,31 @@ namespace germanairlinesva_simdata
|
|||||||
gateName += fields.back();
|
gateName += fields.back();
|
||||||
gateName = std::regex_replace(gateName, std::regex{","}, "0");
|
gateName = std::regex_replace(gateName, std::regex{","}, "0");
|
||||||
|
|
||||||
gates->push_back(
|
gates.emplace_back(gateName,
|
||||||
Gate{gateName, std::stod(fields[1]), std::stod(fields[2]), 40});
|
std::stod(fields[1]),
|
||||||
|
std::stod(fields[2]),
|
||||||
|
40);
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeRunway(std::vector<Runway> *runways, std::vector<std::string> fields)
|
void makeRunway(std::vector<Runway> &runways,
|
||||||
|
const std::vector<std::string> &fields)
|
||||||
{
|
{
|
||||||
runways->push_back(Runway{fields[8],
|
runways.emplace_back(fields[8],
|
||||||
std::stod(fields[9]),
|
std::stod(fields[9]),
|
||||||
std::stod(fields[10]),
|
std::stod(fields[10]),
|
||||||
std::stod(fields[18]),
|
std::stod(fields[18]),
|
||||||
std::stod(fields[19]),
|
std::stod(fields[19]),
|
||||||
std::stod(fields[1])});
|
std::stod(fields[1]));
|
||||||
runways->push_back(Runway{fields[17],
|
runways.emplace_back(fields[17],
|
||||||
std::stod(fields[18]),
|
std::stod(fields[18]),
|
||||||
std::stod(fields[19]),
|
std::stod(fields[19]),
|
||||||
std::stod(fields[9]),
|
std::stod(fields[9]),
|
||||||
std::stod(fields[10]),
|
std::stod(fields[10]),
|
||||||
std::stod(fields[1])});
|
std::stod(fields[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeGate1300(std::vector<Gate> *gates, std::vector<std::string> fields)
|
void makeGate1300(std::vector<Gate> &gates,
|
||||||
|
const std::vector<std::string> &fields)
|
||||||
{
|
{
|
||||||
std::string gateName;
|
std::string gateName;
|
||||||
for (size_t j = 6; j < fields.size() - 1; j++) {
|
for (size_t j = 6; j < fields.size() - 1; j++) {
|
||||||
@ -177,7 +182,9 @@ namespace germanairlinesva_simdata
|
|||||||
gateName += fields.back();
|
gateName += fields.back();
|
||||||
gateName = std::regex_replace(gateName, std::regex{","}, "0");
|
gateName = std::regex_replace(gateName, std::regex{","}, "0");
|
||||||
|
|
||||||
gates->push_back(
|
gates.emplace_back(gateName,
|
||||||
Gate{gateName, std::stod(fields[1]), std::stod(fields[2]), 40});
|
std::stod(fields[1]),
|
||||||
|
std::stod(fields[2]),
|
||||||
|
40);
|
||||||
}
|
}
|
||||||
} // namespace germanairlinesva_simdata
|
} // namespace germanairlinesva_simdata
|
||||||
@ -39,7 +39,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace germanairlinesva_util
|
namespace germanairlinesva_util
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -293,7 +292,7 @@ namespace germanairlinesva_util
|
|||||||
std::string item;
|
std::string item;
|
||||||
|
|
||||||
while (getline(ss, item, delim)) {
|
while (getline(ss, item, delim)) {
|
||||||
result.push_back(item);
|
result.emplace_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -3,12 +3,14 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#pragma pack(push) /* push current alignment to stack */
|
|
||||||
#pragma pack(1) /* set alignment to 1 byte boundary */
|
|
||||||
namespace germanairlinesva_websocket
|
namespace germanairlinesva_websocket
|
||||||
{
|
{
|
||||||
|
#pragma pack(push) /* push current alignment to stack */
|
||||||
|
#pragma pack(1) /* set alignment to 1 byte boundary */
|
||||||
|
|
||||||
/* Structures and enums */
|
/* Structures and enums */
|
||||||
typedef struct data {
|
struct data {
|
||||||
std::int32_t pause = 0;
|
std::int32_t pause = 0;
|
||||||
float pBrake = 0;
|
float pBrake = 0;
|
||||||
std::int32_t onGrnd = 0;
|
std::int32_t onGrnd = 0;
|
||||||
@ -27,30 +29,19 @@ namespace germanairlinesva_websocket
|
|||||||
float magHeading = 0;
|
float magHeading = 0;
|
||||||
float payloadKg = 0;
|
float payloadKg = 0;
|
||||||
float totalWeightKg = 0;
|
float totalWeightKg = 0;
|
||||||
} data;
|
};
|
||||||
|
|
||||||
typedef enum commands {
|
enum commands { PROCESS, SAVE, LOAD, TEXT, TIME, UNPAUSE, PAUSE, PORT, END };
|
||||||
PROCESS,
|
|
||||||
SAVE,
|
|
||||||
LOAD,
|
|
||||||
TEXT,
|
|
||||||
TIME,
|
|
||||||
UNPAUSE,
|
|
||||||
PAUSE,
|
|
||||||
PORT,
|
|
||||||
END
|
|
||||||
} commands;
|
|
||||||
|
|
||||||
typedef struct command_base {
|
struct command_base {
|
||||||
commands type;
|
enum commands type;
|
||||||
} command_base;
|
};
|
||||||
|
|
||||||
|
struct command_port {
|
||||||
typedef struct command_port {
|
|
||||||
double latitude;
|
double latitude;
|
||||||
double longitude;
|
double longitude;
|
||||||
float trueHeading;
|
float trueHeading;
|
||||||
} command_port;
|
};
|
||||||
|
|
||||||
#pragma pack(pop) /* restore original alignment from stack */
|
#pragma pack(pop) /* restore original alignment from stack */
|
||||||
} // namespace germanairlinesva_websocket
|
} // namespace germanairlinesva_websocket
|
||||||
|
|||||||
@ -12,19 +12,20 @@ namespace germanairlinesva_websocket
|
|||||||
ix::initNetSystem();
|
ix::initNetSystem();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
webSocket = new ix::WebSocket();
|
this->webSocket = new ix::WebSocket();
|
||||||
webSocket->enableAutomaticReconnection();
|
this->webSocket->enableAutomaticReconnection();
|
||||||
webSocket->setUrl(host);
|
this->webSocket->setUrl(host);
|
||||||
webSocket->setOnMessageCallback([this](const ix::WebSocketMessagePtr &msg) {
|
this->webSocket->setOnMessageCallback(
|
||||||
this->onClientMessageCallback(msg);
|
[this](const ix::WebSocketMessagePtr &msg) {
|
||||||
});
|
this->onClientMessageCallback(msg);
|
||||||
webSocket->start();
|
});
|
||||||
|
this->webSocket->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Websocket::~Websocket()
|
Websocket::~Websocket()
|
||||||
{
|
{
|
||||||
webSocket->stop();
|
this->webSocket->stop();
|
||||||
toLog("WebSocket stopped");
|
this->toLog("WebSocket stopped");
|
||||||
#ifdef IBM
|
#ifdef IBM
|
||||||
// Required on Windows
|
// Required on Windows
|
||||||
ix::uninitNetSystem();
|
ix::uninitNetSystem();
|
||||||
@ -43,15 +44,15 @@ namespace germanairlinesva_websocket
|
|||||||
debug_msg << it.first << ": " << it.second << std::endl;
|
debug_msg << it.first << ": " << it.second << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
toLog(debug_msg.str());
|
this->toLog(debug_msg.str());
|
||||||
|
|
||||||
webSocket->send("MASTER:" + user);
|
this->webSocket->send("MASTER:" + user);
|
||||||
toLog("Connecting as " + user);
|
this->toLog("Connecting as " + user);
|
||||||
} else if (msg->type == ix::WebSocketMessageType::Close) {
|
} else if (msg->type == ix::WebSocketMessageType::Close) {
|
||||||
if (msg->closeInfo.reason.compare("DUPLICATE")) {
|
if (msg->closeInfo.reason.compare("DUPLICATE")) {
|
||||||
webSocket->disableAutomaticReconnection();
|
this->webSocket->disableAutomaticReconnection();
|
||||||
|
|
||||||
toLog("Disconnected due to beeing a duplicate simualtor");
|
this->toLog("Disconnected due to beeing a duplicate simualtor");
|
||||||
} else {
|
} else {
|
||||||
std::stringstream debug_msg;
|
std::stringstream debug_msg;
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ namespace germanairlinesva_websocket
|
|||||||
debug_msg << "Reason: " << msg->closeInfo.reason << std::endl;
|
debug_msg << "Reason: " << msg->closeInfo.reason << std::endl;
|
||||||
debug_msg << "Remote: " << msg->closeInfo.remote << std::endl;
|
debug_msg << "Remote: " << msg->closeInfo.remote << std::endl;
|
||||||
|
|
||||||
toLog(debug_msg.str());
|
this->toLog(debug_msg.str());
|
||||||
}
|
}
|
||||||
} else if (msg->type == ix::WebSocketMessageType::Error) {
|
} else if (msg->type == ix::WebSocketMessageType::Error) {
|
||||||
std::stringstream debug_msg;
|
std::stringstream debug_msg;
|
||||||
@ -73,20 +74,22 @@ namespace germanairlinesva_websocket
|
|||||||
debug_msg << "Retries: " << msg->errorInfo.retries << std::endl;
|
debug_msg << "Retries: " << msg->errorInfo.retries << std::endl;
|
||||||
debug_msg << "Wait time: " << msg->errorInfo.wait_time << std::endl;
|
debug_msg << "Wait time: " << msg->errorInfo.wait_time << std::endl;
|
||||||
|
|
||||||
toLog(debug_msg.str());
|
this->toLog(debug_msg.str());
|
||||||
} else if (msg->type == ix::WebSocketMessageType::Message) {
|
} else if (msg->type == ix::WebSocketMessageType::Message) {
|
||||||
if (!msg->str.empty()) {
|
if (!msg->str.empty()) {
|
||||||
toLog(msg->str);
|
this->toLog(msg->str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Websocket::sendData(data &d)
|
void Websocket::sendData(data &d)
|
||||||
{
|
{
|
||||||
if (strcmp(d.path, lastPath) != 0) {
|
if (strcmp(d.path, this->lastPath) != 0) {
|
||||||
strcpy(lastPath, d.path);
|
strcpy(this->lastPath, d.path);
|
||||||
if (germanairlinesva_util::generateMD5(d.path, lastHash, toLog)) {
|
if (germanairlinesva_util::generateMD5(d.path,
|
||||||
strcpy(lastHash, "NOT SET");
|
this->lastHash,
|
||||||
|
this->toLog)) {
|
||||||
|
strcpy(this->lastHash, "NOT SET");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,13 +101,13 @@ namespace germanairlinesva_websocket
|
|||||||
{"truHdg", d.truHdg},
|
{"truHdg", d.truHdg},
|
||||||
{"totFuel", d.totFuelKg},
|
{"totFuel", d.totFuelKg},
|
||||||
{"fuelFlow", d.ff},
|
{"fuelFlow", d.ff},
|
||||||
{"hash", lastHash},
|
{"hash", this->lastHash},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (webSocket != nullptr) {
|
if (this->webSocket != nullptr) {
|
||||||
std::ostringstream msg;
|
std::ostringstream msg;
|
||||||
msg << "SEND:" << user << ":" << json.dump();
|
msg << "SEND:" << user << ":" << json.dump();
|
||||||
webSocket->send(msg.str(), false);
|
this->webSocket->send(msg.str(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace germanairlinesva_websocket
|
} // namespace germanairlinesva_websocket
|
||||||
@ -46,7 +46,7 @@ XPLMDataRef pitch;
|
|||||||
XPLMDataRef roll;
|
XPLMDataRef roll;
|
||||||
XPLMDataRef quaternion;
|
XPLMDataRef quaternion;
|
||||||
|
|
||||||
germanairlinesva_websocket::data toSend;
|
struct germanairlinesva_websocket::data toSend;
|
||||||
germanairlinesva_recording::PathRecording p;
|
germanairlinesva_recording::PathRecording p;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -171,35 +171,35 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
|||||||
|
|
||||||
toLog("Logbook Test");
|
toLog("Logbook Test");
|
||||||
germanairlinesva_logbook::Logbook logbook;
|
germanairlinesva_logbook::Logbook logbook;
|
||||||
logbook.addEntry({"08.09.2022",
|
logbook.addEntry("08.09.2022",
|
||||||
"1000",
|
"1000",
|
||||||
"L049",
|
"L049",
|
||||||
"D-ALFA",
|
"D-ALFA",
|
||||||
"John F. Kennedy International Aiport / EDDF",
|
"John F. Kennedy International Aiport / EDDF",
|
||||||
"A1",
|
"A1",
|
||||||
"14L",
|
"14L",
|
||||||
"Gander International Airport / CYQX",
|
"Gander International Airport / CYQX",
|
||||||
"10",
|
"10",
|
||||||
"03",
|
"03",
|
||||||
"10:00",
|
"10:00",
|
||||||
"10:20",
|
"10:20",
|
||||||
"13:20",
|
"13:20",
|
||||||
"13:30",
|
"13:30",
|
||||||
210.5,
|
210.5,
|
||||||
20.1,
|
20.1,
|
||||||
5012.4156,
|
5012.4156,
|
||||||
8.87,
|
8.87,
|
||||||
5041.3856,
|
5041.3856,
|
||||||
7.1,
|
7.1,
|
||||||
971.14,
|
971.14,
|
||||||
2.41,
|
2.41,
|
||||||
980.65,
|
980.65,
|
||||||
-165.23,
|
-165.23,
|
||||||
1,
|
1,
|
||||||
1.2012,
|
1.2012,
|
||||||
"2022-09-08_VGA1000",
|
"2022-09-08_VGA1000",
|
||||||
5.5,
|
5.5,
|
||||||
1});
|
1);
|
||||||
logbook.toFile();
|
logbook.toFile();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -281,7 +281,7 @@ void serverWorker()
|
|||||||
germanairlinesva_util::setThreadName("GAServerWorker");
|
germanairlinesva_util::setThreadName("GAServerWorker");
|
||||||
|
|
||||||
while (!wantsExit) {
|
while (!wantsExit) {
|
||||||
germanairlinesva_websocket::data copy;
|
struct germanairlinesva_websocket::data copy;
|
||||||
{
|
{
|
||||||
const std::lock_guard<std::mutex> lock(mutex);
|
const std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user