Convert ESP to Recorder
This commit is contained in:
1 parent
0a150391b8
commit
3a9db68e74
12 files changed
+271
-316
No files matched your search
+14
-184
@@ -1,22 +1,8 @@
|
||||
#include "include/main.h"
|
||||
|
||||
std::mutex mutex;
|
||||
std::queue<std::function<void()>> &messageQueue()
|
||||
{
|
||||
static std::queue<std::function<void()>> _messageQueue;
|
||||
return _messageQueue;
|
||||
}
|
||||
std::thread serverThread;
|
||||
std::thread recordingThread;
|
||||
std::atomic<bool> wantsExit;
|
||||
|
||||
std::shared_ptr<germanairlinesva::file::config::Config> configuration;
|
||||
std::unique_ptr<germanairlinesva::file::simdata::SimDatabase> database;
|
||||
std::unique_ptr<germanairlinesva::gaconnector::websocket::Websocket> connector;
|
||||
std::unique_ptr<SimConnect> simConnect;
|
||||
|
||||
struct germanairlinesva::gaconnector::websocket::data toSend;
|
||||
germanairlinesva::file::recording::Recording p;
|
||||
germanairlinesva::gaconnector::recorder::Recorder *recorder;
|
||||
|
||||
// The Window Procedure
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
@@ -48,7 +34,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
case SIMCONNECT_MESSAGE: {
|
||||
if (simConnect != nullptr && simConnect->isConnected()) {
|
||||
simConnect->handleMessage();
|
||||
simConnect->handleMessage(
|
||||
[](int version) { recorder->loadDatabase(version); },
|
||||
[]() {
|
||||
germanairlinesva::gaconnector::websocket::data d;
|
||||
simConnect->getStates();
|
||||
simConnect->getData(&d);
|
||||
recorder->setData(d);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -74,8 +67,6 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
||||
HWND hWnd;
|
||||
MSG msg;
|
||||
|
||||
wantsExit.store(false);
|
||||
|
||||
// Exit if already running
|
||||
hWnd = FindWindow(WINDOW_CLASS, WINDOW_CLASS);
|
||||
if (hWnd != NULL) {
|
||||
@@ -124,100 +115,11 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
||||
// Never show window
|
||||
// ShowWindow(hWnd, SHOW_OPENWINDOW);
|
||||
|
||||
configuration = std::make_unique<germanairlinesva::file::config::Config>();
|
||||
toLog("Config loaded");
|
||||
|
||||
connector =
|
||||
std::make_unique<germanairlinesva::gaconnector::websocket::Websocket>(
|
||||
"wss://ws.hofmannnet.myhome-server.de:8000",
|
||||
configuration->getUser(),
|
||||
toLog);
|
||||
toLog("WebSocket started");
|
||||
|
||||
#ifndef MSFS
|
||||
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("\\Microsoft\\FSX\\scenery.cfg");
|
||||
toLog(path);
|
||||
|
||||
delete[] nstring;
|
||||
CoTaskMemFree(folder);
|
||||
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (germanairlinesva::utilities::generateMD5(path.c_str(), hash, toLog) ==
|
||||
0) {
|
||||
database = std::make_unique<germanairlinesva::file::simdata::SimDatabase>(
|
||||
FSX_VERSION,
|
||||
hash,
|
||||
configuration,
|
||||
toLog);
|
||||
}
|
||||
|
||||
toLog("Readback test of sim database using 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");
|
||||
}
|
||||
#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();
|
||||
recorder = new germanairlinesva::gaconnector::recorder::Recorder(0, toLog);
|
||||
|
||||
// Open SimConnect
|
||||
simConnect = std::make_unique<SimConnect>(hWnd, toLog, configuration);
|
||||
|
||||
// Thread for sending data to websocket
|
||||
serverThread = std::thread(&serverWorker);
|
||||
recordingThread = std::thread(&recordingWorker);
|
||||
toLog("Workers started");
|
||||
simConnect =
|
||||
std::make_unique<SimConnect>(hWnd, toLog, recorder->getConfiguration());
|
||||
|
||||
// The Message Loop
|
||||
while (GetMessage(&msg, NULL, 0, 0) > 0) {
|
||||
@@ -282,7 +184,7 @@ WINBOOL createMenu(HWND hWnd)
|
||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, "Version: " BIT " Bit");
|
||||
if (simConnect->isConnected()) {
|
||||
std::string version("Connected to Sim: ");
|
||||
version.append(simConnect->getVersion());
|
||||
version.append(SimConnect::resolveVersion(simConnect->getVersion()));
|
||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, NULL, version.c_str());
|
||||
}
|
||||
AppendMenu(hMenu, MF_SEPARATOR, NULL, NULL);
|
||||
@@ -312,11 +214,7 @@ void end(HWND hWnd)
|
||||
UnregisterClass(WINDOW_CLASS, GetModuleHandle(NULL));
|
||||
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
serverThread.join();
|
||||
recordingThread.join();
|
||||
|
||||
p.toFile("flight.rec");
|
||||
recorder->~Recorder();
|
||||
|
||||
// End SimConnect
|
||||
delete simConnect.release();
|
||||
@@ -324,74 +222,6 @@ void end(HWND hWnd)
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
void serverWorker()
|
||||
{
|
||||
germanairlinesva::utilities::setThreadName("GAServerWorker");
|
||||
|
||||
while (!wantsExit) {
|
||||
simConnect->getStates();
|
||||
|
||||
struct germanairlinesva::gaconnector::websocket::data *copy =
|
||||
new germanairlinesva::gaconnector::websocket::data();
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
simConnect->getData(copy);
|
||||
}
|
||||
|
||||
connector->sendData(*copy);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||
}
|
||||
|
||||
toLog("Server thread stopped");
|
||||
}
|
||||
|
||||
void recordingWorker()
|
||||
{
|
||||
germanairlinesva::utilities::setThreadName("GARecordingWorker");
|
||||
|
||||
germanairlinesva::file::recording::RecordingEntry lastPath;
|
||||
std::uint32_t segment = 0;
|
||||
|
||||
auto ap = (*database)["EDDF"];
|
||||
auto rwys = ap.second;
|
||||
|
||||
while (!wantsExit) {
|
||||
struct germanairlinesva::gaconnector::websocket::data *copy =
|
||||
new germanairlinesva::gaconnector::websocket::data();
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
simConnect->getData(copy);
|
||||
}
|
||||
|
||||
germanairlinesva::file::recording::RecordingEntry 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.addEntry(currentPath);
|
||||
lastPath = currentPath;
|
||||
|
||||
for (const auto &it : rwys) {
|
||||
if (it.containsPoint({copy->lat, copy->lon})) {
|
||||
toLog("On Runway: " + it.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
segment++;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
toLog("Recording thread stopped");
|
||||
}
|
||||
|
||||
void toLog(const std::string &message)
|
||||
{
|
||||
std::time_t utc = std::time(nullptr);
|
||||
|
||||
Reference in new issue
Block a user