Namespacing and Lib for files
This commit is contained in:
parent
2510f4968c
commit
3559b124a7
@ -19,6 +19,9 @@ add_subdirectory(
|
||||
add_subdirectory(
|
||||
simdata
|
||||
)
|
||||
add_subdirectory(
|
||||
file
|
||||
)
|
||||
add_subdirectory(
|
||||
xplugin
|
||||
)
|
||||
|
||||
90
file/CMakeLists.txt
Normal file
90
file/CMakeLists.txt
Normal file
@ -0,0 +1,90 @@
|
||||
file(GLOB file CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/file/*.cpp)
|
||||
|
||||
add_library(file SHARED
|
||||
${file}
|
||||
)
|
||||
|
||||
target_include_directories(file PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/file/include
|
||||
${CMAKE_SOURCE_DIR}/simdata/include
|
||||
${CMAKE_SOURCE_DIR}/utilities/include
|
||||
)
|
||||
|
||||
set_target_properties(file PROPERTIES
|
||||
PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/file/include
|
||||
)
|
||||
target_compile_options(file PRIVATE
|
||||
-Wall
|
||||
-Wextra
|
||||
-pedantic
|
||||
)
|
||||
if(DEBUG)
|
||||
target_compile_options(file PRIVATE
|
||||
-g
|
||||
)
|
||||
target_link_options(file PRIVATE
|
||||
-g
|
||||
)
|
||||
else()
|
||||
target_compile_options(file PRIVATE
|
||||
-O2
|
||||
)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
message("Building file for MacOSX Universal into ${PROJECT_BINARY_DIR}/${PLUGIN_NAME}")
|
||||
|
||||
set_target_properties(file PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}"
|
||||
BUILD_WITH_INSTALL_NAME_DIR TRUE
|
||||
)
|
||||
|
||||
target_compile_options(file PRIVATE
|
||||
"SHELL:-arch i386"
|
||||
"SHELL:-arch x86_64"
|
||||
)
|
||||
target_link_options(file PRIVATE
|
||||
"SHELL:-arch i386"
|
||||
"SHELL:-arch x86_64"
|
||||
)
|
||||
target_link_libraries(file PRIVATE
|
||||
"-framework Security"
|
||||
)
|
||||
elseif(UNIX)
|
||||
message("Building file for Linux ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
|
||||
|
||||
set_target_properties(file PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
|
||||
)
|
||||
|
||||
target_compile_options(file PRIVATE
|
||||
-nodefaultlibs
|
||||
)
|
||||
if(BIT STREQUAL "32")
|
||||
target_compile_options(file PRIVATE
|
||||
-m32
|
||||
)
|
||||
target_link_options(file PRIVATE
|
||||
-m32
|
||||
)
|
||||
endif()
|
||||
elseif(WIN32)
|
||||
message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
|
||||
|
||||
set_target_properties(file PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
|
||||
)
|
||||
|
||||
if(DEBUG)
|
||||
target_compile_options(file PRIVATE
|
||||
-gcodeview
|
||||
)
|
||||
target_link_options(file PRIVATE
|
||||
-Wl,-pdb=
|
||||
)
|
||||
endif()
|
||||
target_link_options(file PRIVATE
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
)
|
||||
endif()
|
||||
43
file/include/pathRecording.h
Normal file
43
file/include/pathRecording.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDING_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_RECORDING_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "pathSegment.h"
|
||||
|
||||
#define CURRENT_VERSION 1
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
/*
|
||||
* Header
|
||||
*
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAR | VERSION
|
||||
*/
|
||||
/*
|
||||
* Path Recording
|
||||
*
|
||||
* PATHSEGMENT[]
|
||||
* -------------
|
||||
* SEGMENTS
|
||||
*/
|
||||
class PathRecording
|
||||
{
|
||||
private:
|
||||
std::uint64_t count = 0;
|
||||
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', 0, CURRENT_VERSION};
|
||||
|
||||
public:
|
||||
void addSegment(PathSegment segment);
|
||||
|
||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
||||
inline std::size_t getBinaryLength() { return file.size(); }
|
||||
};
|
||||
|
||||
} // namespace germanairlinesva_recording
|
||||
|
||||
#endif
|
||||
52
file/include/pathSegment.h
Normal file
52
file/include/pathSegment.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "geodata.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
/*
|
||||
* UINT32 | UINT16 | UINT16 | COORDINATES
|
||||
* -------+----------+-------------+------------
|
||||
* TIME | ALTITUDE | GROUNDSPEED | POINT
|
||||
*/
|
||||
class PathSegment
|
||||
{
|
||||
private:
|
||||
std::uint32_t time = 0;
|
||||
std::uint16_t altitude = 0;
|
||||
std::uint16_t groundSpeed = 0;
|
||||
struct germanairlinesva_geodata::point coordinates;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
PathSegment() = default;
|
||||
PathSegment(std::uint32_t time,
|
||||
std::uint16_t altitude,
|
||||
std::uint16_t groundSpeed,
|
||||
struct germanairlinesva_geodata::point coordinates);
|
||||
|
||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
||||
inline std::size_t getBinaryLength() { 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
|
||||
12
file/pathRecording.cpp
Normal file
12
file/pathRecording.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "pathRecording.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
void PathRecording::addSegment(PathSegment segment)
|
||||
{
|
||||
file.resize(file.size() + segment.getBinaryLength());
|
||||
std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength();
|
||||
memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
|
||||
count++;
|
||||
}
|
||||
} // namespace germanairlinesva_recording
|
||||
28
file/pathSegment.cpp
Normal file
28
file/pathSegment.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "pathSegment.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
PathSegment::PathSegment(std::uint32_t time,
|
||||
std::uint16_t altitude,
|
||||
std::uint16_t groundSpeed,
|
||||
struct germanairlinesva_geodata::point coordinates)
|
||||
{
|
||||
this->time = time;
|
||||
this->altitude = altitude;
|
||||
this->groundSpeed = groundSpeed;
|
||||
this->coordinates = coordinates;
|
||||
|
||||
file = std::vector<std::uint8_t>(
|
||||
sizeof(this->time) + sizeof(this->altitude) +
|
||||
sizeof(this->groundSpeed) + sizeof(this->coordinates),
|
||||
0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memcpy(bufPtr, &this->time, sizeof(this->time));
|
||||
bufPtr += sizeof(this->time);
|
||||
memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
|
||||
bufPtr += sizeof(this->altitude);
|
||||
memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
|
||||
bufPtr += sizeof(this->groundSpeed);
|
||||
memcpy(bufPtr, &this->coordinates, sizeof(this->coordinates));
|
||||
};
|
||||
} // namespace germanairlinesva_recording
|
||||
@ -1,62 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* Length in bytes: 20
|
||||
*
|
||||
* UINT16 | UINT16 | DOUBLE | DOUBLE |
|
||||
* ---------+-------------+----------+-----------+
|
||||
* ALTITUDE | GROUNDSPEED | LATITUDE | LONGITUDE |
|
||||
*/
|
||||
class PathSegment
|
||||
{
|
||||
private:
|
||||
std::uint16_t altitude = 0;
|
||||
std::uint16_t groundSpeed = 0;
|
||||
double latitude = 0;
|
||||
double longitude = 0;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
PathSegment() = default;
|
||||
PathSegment(std::uint16_t altitude,
|
||||
std::uint16_t groundSpeed,
|
||||
double latitude,
|
||||
double longitude)
|
||||
{
|
||||
this->altitude = altitude;
|
||||
this->groundSpeed = groundSpeed;
|
||||
this->latitude = latitude;
|
||||
this->longitude = longitude;
|
||||
|
||||
file = std::vector<std::uint8_t>(20, 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
|
||||
bufPtr += sizeof(this->altitude);
|
||||
memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
|
||||
bufPtr += sizeof(this->groundSpeed);
|
||||
memcpy(bufPtr, &this->latitude, sizeof(this->latitude));
|
||||
bufPtr += sizeof(this->latitude);
|
||||
memcpy(bufPtr, &this->longitude, sizeof(this->longitude));
|
||||
}
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
|
||||
friend bool operator==(const PathSegment &lhs, const PathSegment &rhs)
|
||||
{
|
||||
return lhs.altitude == rhs.altitude &&
|
||||
lhs.groundSpeed == rhs.groundSpeed &&
|
||||
lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude;
|
||||
}
|
||||
friend bool operator!=(const PathSegment &lhs, const PathSegment &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,29 +0,0 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDINGPATH_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_RECORDINGPATH_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "pathSegment.hpp"
|
||||
|
||||
class Path
|
||||
{
|
||||
private:
|
||||
std::uint64_t count = 0;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
void addSegment(PathSegment segment)
|
||||
{
|
||||
file.resize(file.size() + segment.getBinaryLength());
|
||||
std::uint8_t *bufPtr = file.data() + count * segment.getBinaryLength();
|
||||
memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
|
||||
count++;
|
||||
}
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -12,9 +12,6 @@ target_include_directories(simdata PRIVATE
|
||||
set_target_properties(simdata PROPERTIES
|
||||
PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/simdata/include
|
||||
)
|
||||
target_compile_definitions(simdata PRIVATE
|
||||
_USE_MATH_DEFINES
|
||||
)
|
||||
target_compile_options(simdata PRIVATE
|
||||
-Wall
|
||||
-Wextra
|
||||
|
||||
@ -44,8 +44,8 @@ namespace germanairlinesva_simdata
|
||||
germanairlinesva_geodata::point center,
|
||||
std::uint8_t radius);
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
||||
inline std::size_t getBinaryLength() { return file.size(); }
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_GEODATA_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_GEODATA_H
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#ifdef IBM
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
@ -49,8 +49,8 @@ namespace germanairlinesva_simdata
|
||||
std::uint16_t length,
|
||||
std::uint16_t trueHeading);
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
||||
inline std::size_t getBinaryLength() { return file.size(); }
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_SIMULATORDATABASE_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_SIMULATORDATABASE_H
|
||||
|
||||
#include "gate.h"
|
||||
#include "runway.h"
|
||||
|
||||
#define CURRENT_VERSION 1
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@ -14,6 +9,11 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gate.h"
|
||||
#include "runway.h"
|
||||
|
||||
#define CURRENT_VERSION 1
|
||||
|
||||
/*
|
||||
* Header
|
||||
*
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
|
||||
@ -32,7 +32,7 @@ namespace germanairlinesva_websocket
|
||||
std::function<void(std::string)> toLog;
|
||||
|
||||
public:
|
||||
explicit Websocket(std::string host,
|
||||
Websocket(std::string host,
|
||||
std::string user,
|
||||
std::function<void(const std::string)> toLog);
|
||||
~Websocket();
|
||||
|
||||
@ -36,7 +36,7 @@ namespace germanairlinesva_websocket
|
||||
if (msg->type == ix::WebSocketMessageType::Open) {
|
||||
std::stringstream debug_msg;
|
||||
|
||||
debug_msg << "New connection" << std::endl;
|
||||
debug_msg << std::endl << "New connection" << std::endl;
|
||||
debug_msg << "Uri: " << msg->openInfo.uri << std::endl;
|
||||
debug_msg << "Headers:" << std::endl;
|
||||
for (const auto &it : msg->openInfo.headers) {
|
||||
@ -55,7 +55,7 @@ namespace germanairlinesva_websocket
|
||||
} else {
|
||||
std::stringstream debug_msg;
|
||||
|
||||
debug_msg << "Connection closed" << std::endl;
|
||||
debug_msg << std::endl << "Connection closed" << std::endl;
|
||||
debug_msg << "Code: " << msg->closeInfo.code << std::endl;
|
||||
debug_msg << "Reason: " << msg->closeInfo.reason << std::endl;
|
||||
debug_msg << "Remote: " << msg->closeInfo.remote << std::endl;
|
||||
@ -65,7 +65,7 @@ namespace germanairlinesva_websocket
|
||||
} else if (msg->type == ix::WebSocketMessageType::Error) {
|
||||
std::stringstream debug_msg;
|
||||
|
||||
debug_msg << "Connection error" << std::endl;
|
||||
debug_msg << std::endl << "Connection error" << std::endl;
|
||||
debug_msg << "Decompression: " << msg->errorInfo.decompressionError
|
||||
<< std::endl;
|
||||
debug_msg << "HTTP status: " << msg->errorInfo.http_status << std::endl;
|
||||
|
||||
@ -8,13 +8,13 @@ add_library(germanairlinesva_xplugin SHARED
|
||||
)
|
||||
|
||||
target_include_directories(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/ixwebsocket/include
|
||||
${CMAKE_SOURCE_DIR}/file/include
|
||||
${CMAKE_SOURCE_DIR}/simdata/include
|
||||
${CMAKE_SOURCE_DIR}/websocket/include
|
||||
${CMAKE_SOURCE_DIR}/utilities/include
|
||||
${CMAKE_SOURCE_DIR}/ixwebsocket/include
|
||||
${CMAKE_SOURCE_DIR}/nlohmann/include
|
||||
${CMAKE_SOURCE_DIR}/XPSDK/CHeaders
|
||||
${CMAKE_SOURCE_DIR}/file
|
||||
)
|
||||
|
||||
set_target_properties(germanairlinesva_xplugin PROPERTIES
|
||||
@ -24,7 +24,6 @@ set_target_properties(germanairlinesva_xplugin PROPERTIES
|
||||
target_compile_definitions(germanairlinesva_xplugin PRIVATE
|
||||
XPLM200
|
||||
XPLM210
|
||||
_USE_MATH_DEFINES
|
||||
)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-Wall
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAIN_H
|
||||
|
||||
#include "config.hpp"
|
||||
#include "recordingPath.hpp"
|
||||
#include "pathRecording.h"
|
||||
#include "simdata.h"
|
||||
#include "simulatorDatabase.hpp"
|
||||
#include "websocket.h"
|
||||
@ -17,6 +17,8 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <sstream>
|
||||
|
||||
@ -47,7 +47,7 @@ XPLMDataRef roll;
|
||||
XPLMDataRef quaternion;
|
||||
|
||||
germanairlinesva_websocket::data toSend;
|
||||
Path p;
|
||||
germanairlinesva_recording::PathRecording p;
|
||||
|
||||
/*
|
||||
* Callbacks
|
||||
@ -266,7 +266,8 @@ void recordingWorker()
|
||||
{
|
||||
germanairlinesva_util::setThreadName("GARecordingWorker");
|
||||
|
||||
PathSegment lastPath;
|
||||
germanairlinesva_recording::PathSegment lastPath;
|
||||
std::uint32_t segment = 0;
|
||||
|
||||
while (!wantsExit) {
|
||||
germanairlinesva_websocket::data copy;
|
||||
@ -276,23 +277,29 @@ void recordingWorker()
|
||||
memcpy(©, &toSend, sizeof(germanairlinesva_websocket::data));
|
||||
}
|
||||
|
||||
PathSegment currentPath(static_cast<std::uint16_t>(copy.alt),
|
||||
static_cast<std::uint16_t>(copy.gs),
|
||||
copy.lat,
|
||||
copy.lon);
|
||||
germanairlinesva_recording::PathSegment currentPath(
|
||||
segment,
|
||||
static_cast<std::uint16_t>(copy.alt),
|
||||
static_cast<std::uint16_t>(copy.gs),
|
||||
{copy.lat, copy.lon});
|
||||
|
||||
if (strcmp(copy.path, "") != 0 && copy.pause && lastPath != currentPath) {
|
||||
p.addSegment(currentPath);
|
||||
lastPath = currentPath;
|
||||
}
|
||||
|
||||
segment++;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void toLog(const std::string &message)
|
||||
{
|
||||
std::time_t utc = std::time(nullptr);
|
||||
std::tm *time = std::gmtime(&utc);
|
||||
std::stringstream msg;
|
||||
msg << "German Airlines VA: " << message << std::endl;
|
||||
msg << std::put_time(time, "%Y-%m-%d %H:%M:%S UTC ")
|
||||
<< "German Airlines VA: " << message << std::endl;
|
||||
XPLMDebugString(msg.str().c_str());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user