Formating

This commit is contained in:
Kilian Hofmann 2022-10-04 21:59:06 +02:00
parent 3a9db68e74
commit c214d473e2
7 changed files with 206 additions and 84 deletions

View File

@ -57,21 +57,50 @@ struct data {
double gForce; // G FORCE IN G double gForce; // G FORCE IN G
}; };
struct Port { struct port {
double headingTrue; // PLANE HEADING DEGREES TRUE double headingTrue; // PLANE HEADING DEGREES TRUE
double latitude; // PLANE LATITUDE double latitude; // PLANE LATITUDE
double longitude; // PLANE LONGITUDE double longitude; // PLANE LONGITUDE
}; };
struct airport {
double lat;
double lon;
char name[32];
};
struct runway {
double lat;
double lon;
float heading;
float length;
float width;
int pNum;
int pDeg;
int sNum;
int sDeg;
};
struct parking {
int type;
int name;
int suffix;
unsigned int number;
float heading;
float radius;
float x;
float z;
};
#pragma pack(pop) #pragma pack(pop)
enum DEFINITIONS { enum DEFINITIONS {
D_DATA, D_DATA,
D_FACILITY,
D_PORT, D_PORT,
}; };
enum REQUESTS { enum REQUESTS {
R_DATA, R_DATA,
R_FACILITY,
R_ACFT, R_ACFT,
R_DIALOG, R_DIALOG,
R_PORT, R_PORT,

View File

@ -146,7 +146,7 @@ WINBOOL addNotifyIcon(HWND hWnd)
GetSystemMetrics(SM_CYSMICON), GetSystemMetrics(SM_CYSMICON),
LR_SHARED); LR_SHARED);
if (icon == NULL) { if (icon == NULL) {
toLog("error icon " + std::to_string(GetLastError())); toLog("Error icon " + std::to_string(GetLastError()));
} }
niData.cbSize = sizeof(NOTIFYICONDATA); niData.cbSize = sizeof(NOTIFYICONDATA);
niData.uVersion = NOTIFYICON_VERSION_4; niData.uVersion = NOTIFYICON_VERSION_4;
@ -187,6 +187,9 @@ WINBOOL createMenu(HWND hWnd)
version.append(SimConnect::resolveVersion(simConnect->getVersion())); version.append(SimConnect::resolveVersion(simConnect->getVersion()));
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, version.c_str()); AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, version.c_str());
} }
if (!recorder->getSupportedState()) {
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, "Sim unsupported");
}
AppendMenu(hMenu, MF_SEPARATOR, NULL, NULL); AppendMenu(hMenu, MF_SEPARATOR, NULL, NULL);
AppendMenu(hMenu, MF_STRING, IDM_EXIT, "Exit"); AppendMenu(hMenu, MF_STRING, IDM_EXIT, "Exit");

View File

@ -19,48 +19,52 @@ SimConnect::SimConnect(
this->toLog("SimConnect_Close: Connection opened"); this->toLog("SimConnect_Close: Connection opened");
// Setup SimConnect // Setup SimConnect
SimConnect_SubscribeToSystemEvent(simConnect, EVENTS::E_PAUSE, "Pause"); SimConnect_SubscribeToSystemEvent(this->simConnect,
SimConnect_SubscribeToSystemEvent(simConnect, EVENTS::E_STATUS, "Sim"); EVENTS::E_PAUSE,
"Pause");
SimConnect_SubscribeToSystemEvent(this->simConnect,
EVENTS::E_STATUS,
"Sim");
SimConnect_MapClientEventToSimEvent(simConnect, SimConnect_MapClientEventToSimEvent(this->simConnect,
EVENTS::E_TIMESEC, EVENTS::E_TIMESEC,
"CLOCK_SECONDS_ZERO"); "CLOCK_SECONDS_ZERO");
SimConnect_AddClientEventToNotificationGroup(simConnect, SimConnect_AddClientEventToNotificationGroup(this->simConnect,
GROUPS::G_TIME, GROUPS::G_TIME,
EVENTS::E_TIMESEC, EVENTS::E_TIMESEC,
false); false);
SimConnect_SetNotificationGroupPriority(simConnect, SimConnect_SetNotificationGroupPriority(this->simConnect,
GROUPS::G_TIME, GROUPS::G_TIME,
SIMCONNECT_GROUP_PRIORITY_HIGHEST); SIMCONNECT_GROUP_PRIORITY_HIGHEST);
SimConnect_MapClientEventToSimEvent(simConnect, SimConnect_MapClientEventToSimEvent(this->simConnect,
EVENTS::E_TIMEMIN, EVENTS::E_TIMEMIN,
"ZULU_MINUTES_SET"); "ZULU_MINUTES_SET");
SimConnect_AddClientEventToNotificationGroup(simConnect, SimConnect_AddClientEventToNotificationGroup(this->simConnect,
GROUPS::G_TIME, GROUPS::G_TIME,
EVENTS::E_TIMEMIN, EVENTS::E_TIMEMIN,
false); false);
SimConnect_SetNotificationGroupPriority(simConnect, SimConnect_SetNotificationGroupPriority(this->simConnect,
GROUPS::G_TIME, GROUPS::G_TIME,
SIMCONNECT_GROUP_PRIORITY_HIGHEST); SIMCONNECT_GROUP_PRIORITY_HIGHEST);
SimConnect_MapClientEventToSimEvent(simConnect, SimConnect_MapClientEventToSimEvent(this->simConnect,
EVENTS::E_TIMEHRS, EVENTS::E_TIMEHRS,
"ZULU_HOURS_SET"); "ZULU_HOURS_SET");
SimConnect_AddClientEventToNotificationGroup(simConnect, SimConnect_AddClientEventToNotificationGroup(this->simConnect,
GROUPS::G_TIME, GROUPS::G_TIME,
EVENTS::E_TIMEHRS, EVENTS::E_TIMEHRS,
false); false);
SimConnect_SetNotificationGroupPriority(simConnect, SimConnect_SetNotificationGroupPriority(this->simConnect,
GROUPS::G_TIME, GROUPS::G_TIME,
SIMCONNECT_GROUP_PRIORITY_HIGHEST); SIMCONNECT_GROUP_PRIORITY_HIGHEST);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"BRAKE PARKING INDICATOR", "BRAKE PARKING INDICATOR",
"BOOL", "BOOL",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"SIM ON GROUND", "SIM ON GROUND",
"BOOL", "BOOL",
@ -68,14 +72,14 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"EMPTY WEIGHT", "EMPTY WEIGHT",
"KILOGRAMS", "KILOGRAMS",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"TOTAL WEIGHT", "TOTAL WEIGHT",
"KILOGRAMS", "KILOGRAMS",
@ -83,7 +87,7 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"FUEL TOTAL QUANTITY WEIGHT", "FUEL TOTAL QUANTITY WEIGHT",
"KILOGRAMS", "KILOGRAMS",
@ -91,14 +95,14 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"PLANE HEADING DEGREES TRUE", "PLANE HEADING DEGREES TRUE",
"DEGREES", "DEGREES",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"PLANE HEADING DEGREES MAGNETIC", "PLANE HEADING DEGREES MAGNETIC",
"DEGREES", "DEGREES",
@ -106,21 +110,21 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"GROUND VELOCITY", "GROUND VELOCITY",
"KNOTS", "KNOTS",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"AIRSPEED INDICATED", "AIRSPEED INDICATED",
"KNOTS", "KNOTS",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"AIRSPEED BARBER POLE", "AIRSPEED BARBER POLE",
"KNOTS", "KNOTS",
@ -128,28 +132,28 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"VELOCITY WORLD Y", "VELOCITY WORLD Y",
"FEET/MINUTE", "FEET/MINUTE",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"VERTICAL SPEED", "VERTICAL SPEED",
"FEET/MINUTE", "FEET/MINUTE",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"PLANE ALTITUDE", "PLANE ALTITUDE",
"FEET", "FEET",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"PLANE ALT ABOVE GROUND", "PLANE ALT ABOVE GROUND",
"FEET", "FEET",
@ -157,14 +161,14 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"PLANE LATITUDE", "PLANE LATITUDE",
"DEGREES", "DEGREES",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"PLANE LONGITUDE", "PLANE LONGITUDE",
"DEGREES", "DEGREES",
@ -172,7 +176,7 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"ABSOLUTE TIME", "ABSOLUTE TIME",
"SECONDS", "SECONDS",
@ -180,28 +184,28 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"ENG FUEL FLOW PPH:1", "ENG FUEL FLOW PPH:1",
"KILOGRAMS PER SECOND", "KILOGRAMS PER SECOND",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"ENG FUEL FLOW PPH:2", "ENG FUEL FLOW PPH:2",
"KILOGRAMS PER SECOND", "KILOGRAMS PER SECOND",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"ENG FUEL FLOW PPH:3", "ENG FUEL FLOW PPH:3",
"KILOGRAMS PER SECOND", "KILOGRAMS PER SECOND",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"ENG FUEL FLOW PPH:4", "ENG FUEL FLOW PPH:4",
"KILOGRAMS PER SECOND", "KILOGRAMS PER SECOND",
@ -209,21 +213,21 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"BRAKE INDICATOR", "BRAKE INDICATOR",
"POSITION", "POSITION",
SIMCONNECT_DATATYPE_INT32, SIMCONNECT_DATATYPE_INT32,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"BRAKE PARKING POSITION", "BRAKE PARKING POSITION",
"POSITION", "POSITION",
SIMCONNECT_DATATYPE_INT32, SIMCONNECT_DATATYPE_INT32,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"BRAKE LEFT POSITION", "BRAKE LEFT POSITION",
"POSITION", "POSITION",
@ -231,7 +235,7 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"ZULU TIME", "ZULU TIME",
"SECONDS", "SECONDS",
@ -239,7 +243,7 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
"G FORCE", "G FORCE",
"GForce", "GForce",
@ -247,21 +251,21 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_PORT, DEFINITIONS::D_PORT,
"PLANE HEADING DEGREES TRUE", "PLANE HEADING DEGREES TRUE",
"DEGREES", "DEGREES",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_PORT, DEFINITIONS::D_PORT,
"PLANE LATITUDE", "PLANE LATITUDE",
"DEGREES", "DEGREES",
SIMCONNECT_DATATYPE_FLOAT64, SIMCONNECT_DATATYPE_FLOAT64,
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_AddToDataDefinition(simConnect, SimConnect_AddToDataDefinition(this->simConnect,
DEFINITIONS::D_PORT, DEFINITIONS::D_PORT,
"PLANE LONGITUDE", "PLANE LONGITUDE",
"DEGREES", "DEGREES",
@ -269,7 +273,67 @@ SimConnect::SimConnect(
0, 0,
SIMCONNECT_UNUSED); SIMCONNECT_UNUSED);
SimConnect_RequestDataOnSimObject(simConnect, #ifdef MSFS
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"OPEN AIRPORT");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"LATITUDE");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"LONGITUDE");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "NAME");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"OPEN RUNWAY");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"LATITUDE");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"LONGITUDE");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "HEADING");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "LENGTH");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "WIDTH");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"PRIMARY_NUMBER");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"PRIMARY_DESIGNATOR");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"SECONDARY_NUMBER");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"SECONDARY_DESIGNATOR");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"CLOSE RUNWAY");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"OPEN TAXI_PARKING");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "TYPE");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "NAME");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "SUFFIX");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "NUMBER");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "HEADING");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "RADIUS");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "BIAS_X");
SimConnect_AddToFacilityDefinition(this->simConnect, D_FACILITY, "BIAS_Z");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"CLOSE TAXI_PARKING");
SimConnect_AddToFacilityDefinition(this->simConnect,
D_FACILITY,
"CLOSE AIRPORT");
#endif
SimConnect_RequestDataOnSimObject(this->simConnect,
REQUESTS::R_DATA, REQUESTS::R_DATA,
DEFINITIONS::D_DATA, DEFINITIONS::D_DATA,
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_OBJECT_ID_USER,
@ -340,6 +404,11 @@ void SimConnect::handleMessage(std::function<void(int)> callbackOpen,
callbackData(); callbackData();
break; break;
} }
#ifdef MSFS
case SIMCONNECT_RECV_ID_FACILITY_DATA: {
this->toLog("NavData API MSFS Message received");
}
#endif
default: default:
break; break;
} }

View File

@ -45,6 +45,7 @@ namespace gaconnector
std::unique_ptr<websocket::Websocket> connector; std::unique_ptr<websocket::Websocket> connector;
websocket::data toSend; websocket::data toSend;
bool simSupported = false;
std::queue<std::function<void()>> &messageQueue() std::queue<std::function<void()>> &messageQueue()
{ {
@ -67,6 +68,7 @@ namespace gaconnector
void handleMessages(); void handleMessages();
std::shared_ptr<file::config::Config> getConfiguration() const; std::shared_ptr<file::config::Config> getConfiguration() const;
void loadDatabase(int simVersion); void loadDatabase(int simVersion);
bool getSupportedState() const;
}; };
} // namespace recorder } // namespace recorder
} // namespace gaconnector } // namespace gaconnector

View File

@ -6,6 +6,8 @@ namespace gaconnector
{ {
namespace recorder namespace recorder
{ {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
Recorder::Recorder(int simVersion, Recorder::Recorder(int simVersion,
std::function<void(const std::string)> toLog) std::function<void(const std::string)> toLog)
: toLog(std::move(toLog)) : toLog(std::move(toLog))
@ -16,15 +18,7 @@ namespace gaconnector
// Database // Database
#ifdef XP #ifdef XP
char hash[2 * MD5LEN + 1] = ""; this->loadDatabase(simVersion);
if (utilities::generateMD5(XPLANE_CUSTOM_SCENERY, hash, this->toLog) ==
0) {
this->database =
std::make_unique<file::simdata::SimDatabase>(simVersion,
hash,
this->configuration,
this->toLog);
}
#endif #endif
// WebSocket // WebSocket
@ -44,28 +38,29 @@ namespace gaconnector
this->recordingThread = std::thread(&Recorder::recordingWorker, this); this->recordingThread = std::thread(&Recorder::recordingWorker, this);
this->toLog("Workers started"); this->toLog("Workers started");
} }
#pragma clang diagnostic pop
Recorder::~Recorder() Recorder::~Recorder()
{ {
wantsExit = true; this->wantsExit.store(true);
serverThread.join(); this->serverThread.join();
recordingThread.join(); this->recordingThread.join();
} }
void Recorder::setData(websocket::data &data) void Recorder::setData(websocket::data &data)
{ {
const std::lock_guard<std::mutex> lock(mutex); const std::lock_guard<std::mutex> lock(this->mutex);
std::memcpy(&this->toSend, &data, sizeof(websocket::data)); std::memcpy(&this->toSend, &data, sizeof(websocket::data));
} }
void Recorder::handleMessages() void Recorder::handleMessages()
{ {
const std::lock_guard<std::mutex> lock(mutex); const std::lock_guard<std::mutex> lock(this->mutex);
if (!messageQueue().empty()) { if (!this->messageQueue().empty()) {
auto op = std::move(messageQueue().front()); auto op = std::move(this->messageQueue().front());
messageQueue().pop(); this->messageQueue().pop();
op(); op();
} }
} }
@ -77,11 +72,24 @@ namespace gaconnector
void Recorder::loadDatabase(int simVersion) void Recorder::loadDatabase(int simVersion)
{ {
#ifdef XP
char hash[2 * MD5LEN + 1] = "";
if (utilities::generateMD5(XPLANE_CUSTOM_SCENERY, hash, this->toLog) ==
0) {
this->database =
std::make_unique<file::simdata::SimDatabase>(simVersion,
hash,
this->configuration,
this->toLog);
}
#endif
#if defined(IBM) && not defined(XP)
if (simVersion == MSFS_VERSION) { if (simVersion == MSFS_VERSION) {
this->simSupported = strcmp(BIT, "64") == 0;
return; return;
} }
#if defined(IBM) && not defined(XP)
this->toLog("Loading database for " + this->toLog("Loading database for " +
SimConnect::resolveVersion(simVersion)); SimConnect::resolveVersion(simVersion));
@ -98,14 +106,14 @@ namespace gaconnector
std::string path(nstring); std::string path(nstring);
path.append(SimConnect::resolveScenery(simVersion)); path.append(SimConnect::resolveScenery(simVersion));
this->toLog(path); this->toLog("Scenery path: " + path);
delete[] nstring; delete[] nstring;
CoTaskMemFree(folder); CoTaskMemFree(folder);
char hash[2 * MD5LEN + 1] = ""; char hash[2 * MD5LEN + 1] = "";
if (utilities::generateMD5(path.c_str(), hash, toLog) == 0) { if (utilities::generateMD5(path.c_str(), hash, toLog) == 0) {
database = this->database =
std::make_unique<file::simdata::SimDatabase>(simVersion, std::make_unique<file::simdata::SimDatabase>(simVersion,
hash, hash,
this->configuration, this->configuration,
@ -115,8 +123,13 @@ namespace gaconnector
this->test(); this->test();
} }
#endif #endif
// Only here can we be sure to have a supported sim
this->simSupported = true;
} }
bool Recorder::getSupportedState() const { return this->simSupported; }
void Recorder::serverWorker() void Recorder::serverWorker()
{ {
utilities::setThreadName("GAServerWorker"); utilities::setThreadName("GAServerWorker");
@ -124,17 +137,17 @@ namespace gaconnector
while (!wantsExit) { while (!wantsExit) {
struct websocket::data copy; struct websocket::data copy;
{ {
const std::lock_guard<std::mutex> lock(mutex); const std::lock_guard<std::mutex> lock(this->mutex);
std::memcpy(&copy, &toSend, sizeof(websocket::data)); std::memcpy(&copy, &this->toSend, sizeof(websocket::data));
} }
connector->sendData(copy); this->connector->sendData(copy);
std::this_thread::sleep_for(std::chrono::milliseconds(250)); std::this_thread::sleep_for(std::chrono::milliseconds(250));
} }
toLog("Server thread stopped"); this->toLog("Server thread stopped");
} }
void Recorder::recordingWorker() void Recorder::recordingWorker()
@ -148,9 +161,9 @@ namespace gaconnector
while (!wantsExit) { while (!wantsExit) {
struct websocket::data copy; struct websocket::data copy;
{ {
const std::lock_guard<std::mutex> lock(mutex); const std::lock_guard<std::mutex> lock(this->mutex);
std::memcpy(&copy, &toSend, sizeof(websocket::data)); std::memcpy(&copy, &this->toSend, sizeof(websocket::data));
} }
file::recording::RecordingEntry currentPath( file::recording::RecordingEntry currentPath(
@ -171,7 +184,7 @@ namespace gaconnector
} }
path.toFile("flight.rec"); path.toFile("flight.rec");
toLog("Recording thread stopped"); this->toLog("Recording thread stopped");
} }
void Recorder::test() const void Recorder::test() const

View File

@ -27,6 +27,7 @@ namespace gaconnector
class Websocket class Websocket
{ {
private: private:
bool isLoggedIn = false;
char lastPath[513] = ""; char lastPath[513] = "";
char lastHash[2 * MD5LEN + 1] = ""; char lastHash[2 * MD5LEN + 1] = "";
ix::WebSocket *webSocket = nullptr; ix::WebSocket *webSocket = nullptr;

View File

@ -41,44 +41,49 @@ namespace gaconnector
if (msg->type == ix::WebSocketMessageType::Open) { if (msg->type == ix::WebSocketMessageType::Open) {
std::stringstream debug_msg; std::stringstream debug_msg;
debug_msg << std::endl << "New connection" << std::endl; debug_msg << "New connection" << std::endl;
debug_msg << "Uri: " << msg->openInfo.uri << std::endl; debug_msg << "\tUri: " << msg->openInfo.uri << std::endl;
debug_msg << "Headers:" << std::endl; debug_msg << "\tHeaders:" << std::endl;
for (const auto &it : msg->openInfo.headers) { for (const auto &it : msg->openInfo.headers) {
debug_msg << it.first << ": " << it.second << std::endl; debug_msg << "\t\t" << it.first << ": " << it.second << std::endl;
} }
this->toLog(debug_msg.str()); this->toLog(debug_msg.str());
this->webSocket->send("MASTER:" + user); this->webSocket->send("MASTER:" + user);
this->toLog("Connecting as " + user); this->toLog("Connecting as " + user);
this->isLoggedIn = true;
} else if (msg->type == ix::WebSocketMessageType::Close) { } else if (msg->type == ix::WebSocketMessageType::Close) {
if (msg->closeInfo.reason.compare("DUPLICATE") == 0) { if (msg->closeInfo.reason.compare("DUPLICATE") == 0) {
this->webSocket->disableAutomaticReconnection(); this->webSocket->disableAutomaticReconnection();
this->toLog("Disconnected due to beeing a duplicate simualtor"); this->toLog("Disconnected due to beeing a duplicate simualtor");
this->isLoggedIn = false;
} else { } else {
std::stringstream debug_msg; std::stringstream debug_msg;
debug_msg << std::endl << "Connection closed" << std::endl; debug_msg << "Connection closed" << std::endl;
debug_msg << "Code: " << msg->closeInfo.code << std::endl; debug_msg << "\tCode: " << msg->closeInfo.code << std::endl;
debug_msg << "Reason: " << msg->closeInfo.reason << std::endl; debug_msg << "\tReason: " << msg->closeInfo.reason << std::endl;
debug_msg << "Remote: " << msg->closeInfo.remote << std::endl; debug_msg << "\tRemote: " << msg->closeInfo.remote << std::endl;
this->toLog(debug_msg.str()); this->toLog(debug_msg.str());
this->isLoggedIn = false;
} }
} else if (msg->type == ix::WebSocketMessageType::Error) { } else if (msg->type == ix::WebSocketMessageType::Error) {
std::stringstream debug_msg; std::stringstream debug_msg;
debug_msg << std::endl << "Connection error" << std::endl; debug_msg << "Connection error" << std::endl;
debug_msg << "Decompression: " << msg->errorInfo.decompressionError debug_msg << "\tDecompression: " << msg->errorInfo.decompressionError
<< std::endl; << std::endl;
debug_msg << "HTTP status: " << msg->errorInfo.http_status << std::endl; debug_msg << "\tHTTP status: " << msg->errorInfo.http_status
debug_msg << "Reason: " << msg->errorInfo.reason << std::endl; << std::endl;
debug_msg << "Retries: " << msg->errorInfo.retries << std::endl; debug_msg << "\tReason: " << msg->errorInfo.reason << std::endl;
debug_msg << "Wait time: " << msg->errorInfo.wait_time << std::endl; debug_msg << "\tRetries: " << msg->errorInfo.retries << std::endl;
debug_msg << "\tWait time: " << msg->errorInfo.wait_time << std::endl;
this->toLog(debug_msg.str()); this->toLog(debug_msg.str());
this->isLoggedIn = false;
} else if (msg->type == ix::WebSocketMessageType::Message) { } else if (msg->type == ix::WebSocketMessageType::Message) {
if (!msg->str.empty()) { if (!msg->str.empty()) {
this->toLog(msg->str); this->toLog(msg->str);