Convert ESP to Recorder

This commit is contained in:
2022-10-04 17:47:45 +02:00
parent 0a150391b8
commit 3a9db68e74
12 changed files with 271 additions and 316 deletions
+13
View File
@@ -7,8 +7,18 @@
#include <queue>
#include <thread>
#include "constants.h"
#include "websocket.h"
#if defined(IBM) && not defined(XP)
#include "_simconnect.h"
#include <shlobj.h>
#include <stdlib.h>
#include <windows.h>
#endif
#include "config/config.hpp"
#include "logbook/logbook.hpp"
#include "recording/recording.hpp"
@@ -45,6 +55,7 @@ namespace gaconnector
void serverWorker();
void recordingWorker();
// For Testing
void test() const;
@@ -54,6 +65,8 @@ namespace gaconnector
void setData(websocket::data &data);
void handleMessages();
std::shared_ptr<file::config::Config> getConfiguration() const;
void loadDatabase(int simVersion);
};
} // namespace recorder
} // namespace gaconnector
+55 -41
View File
@@ -25,19 +25,19 @@ namespace gaconnector
this->configuration,
this->toLog);
}
#endif
#ifndef MSFS
#endif
// WebSocket
this->connector = std::make_unique<websocket::Websocket>(
"wss://ws.hofmannnet.myhome-server.de:8000",
this->configuration->getUser(),
this->toLog);
this->connector =
std::make_unique<websocket::Websocket>(WEBSOCKET_ADDRESS,
this->configuration->getUser(),
this->toLog);
this->toLog("WebSocket started");
// For Testing
// For Testing
#ifdef XP
this->test();
#endif
// Thread for sending data to websocket
this->serverThread = std::thread(&Recorder::serverWorker, this);
@@ -70,6 +70,53 @@ namespace gaconnector
}
}
std::shared_ptr<file::config::Config> Recorder::getConfiguration() const
{
return this->configuration;
}
void Recorder::loadDatabase(int simVersion)
{
if (simVersion == MSFS_VERSION) {
return;
}
#if defined(IBM) && not defined(XP)
this->toLog("Loading database for " +
SimConnect::resolveVersion(simVersion));
PWSTR folder;
HRESULT result = SHGetKnownFolderPath(FOLDERID_RoamingAppData,
KF_FLAG_DEFAULT,
NULL,
&folder);
if (SUCCEEDED(result)) {
size_t origsize = wcslen(folder) + 1;
size_t convertedChars = 0;
char *nstring = new char[origsize * 2];
wcstombs_s(&convertedChars, nstring, origsize * 2, folder, _TRUNCATE);
std::string path(nstring);
path.append(SimConnect::resolveScenery(simVersion));
this->toLog(path);
delete[] nstring;
CoTaskMemFree(folder);
char hash[2 * MD5LEN + 1] = "";
if (utilities::generateMD5(path.c_str(), hash, toLog) == 0) {
database =
std::make_unique<file::simdata::SimDatabase>(simVersion,
hash,
this->configuration,
this->toLog);
}
this->test();
}
#endif
}
void Recorder::serverWorker()
{
utilities::setThreadName("GAServerWorker");
@@ -112,7 +159,7 @@ namespace gaconnector
static_cast<std::uint16_t>(copy.gs),
{copy.lat, copy.lon});
if (strcmp(copy.path, "") != 0 && copy.pause &&
if (strcmp(copy.path, "") != 0 && !copy.pause &&
lastPath != currentPath) {
path.addEntry(currentPath);
lastPath = currentPath;
@@ -142,39 +189,6 @@ namespace gaconnector
auto ap2 = (*database)["XXXX"];
ap2.first.size() == 0 ? this->toLog(" SUCCESS") : this->toLog(" ERROR");
#endif
toLog("Logbook Test");
germanairlinesva::file::logbook::Logbook logbook;
logbook.addEntry("08.09.2022",
"F",
"1000",
"L049",
"D-ALFA",
"John F. Kennedy International Aiport / EDDF",
"A1",
"14L",
"Gander International Airport / CYQX",
"10",
"03",
"10:00",
"10:20",
"13:20",
"13:30",
210.5,
20.1,
5012.4156,
8.87,
5041.3856,
7.1,
971.14,
2.41,
980.65,
-165.23,
1,
1.2012,
"2022-09-08_VGA1000",
5.5,
1);
logbook.toFile();
}
} // namespace recorder
} // namespace gaconnector