Skip to content

Commit 81fb427

Browse files
authored
Merge pull request #23 from MorpheusXAUT/ccams-squawk-assignment
CCAMS squawk assignment
2 parents 3522be8 + 1617c57 commit 81fb427

File tree

6 files changed

+171
-64
lines changed

6 files changed

+171
-64
lines changed

DelHel/CDelHel.cpp

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ CDelHel::CDelHel() : EuroScopePlugIn::CPlugIn(
3333
this->logMinMaxRFL = false;
3434
this->checkMinMaxRFL = false;
3535
this->flashOnMessage = false;
36+
this->topSkyAvailable = false;
37+
this->ccamsAvailable = false;
38+
this->preferTopSkySquawkAssignment = false;
3639

3740
this->LoadSettings();
41+
this->CheckLoadedPlugins();
3842

3943
this->ReadAirportConfig();
4044
this->ReadRoutingConfig();
@@ -55,7 +59,7 @@ bool CDelHel::OnCompileCommand(const char* sCommandLine)
5559
if (starts_with(args[0], ".delhel")) {
5660
if (args.size() == 1) {
5761
std::ostringstream msg;
58-
msg << "Version " << PLUGIN_VERSION << " loaded. Available commands: auto, debug, nap, reload, reset, update, rflblw, logminmaxrfl, minmaxrfl, flash";
62+
msg << "Version " << PLUGIN_VERSION << " loaded. Available commands: auto, debug, nap, reload, reset, update, rflblw, logminmaxrfl, minmaxrfl, flash, ccams";
5963

6064
this->LogMessage(msg.str());
6165

@@ -190,6 +194,21 @@ bool CDelHel::OnCompileCommand(const char* sCommandLine)
190194

191195
this->SaveSettings();
192196

197+
return true;
198+
}
199+
else if (args[1] == "prefertopsky") {
200+
if (this->preferTopSkySquawkAssignment) {
201+
this->LogMessage("No longer preferring TopSky squawk assignment, will use CCAMS if loaded", "Config");
202+
}
203+
else {
204+
this->LogMessage("Preferring TopSky squawk assignment, even if CCAMS is loaded", "Config");
205+
}
206+
207+
this->preferTopSkySquawkAssignment = !this->preferTopSkySquawkAssignment;
208+
209+
this->SaveSettings();
210+
this->CheckLoadedPlugins();
211+
193212
return true;
194213
}
195214
}
@@ -295,7 +314,7 @@ void CDelHel::LoadSettings()
295314
if (settings) {
296315
std::vector<std::string> splitSettings = split(settings, SETTINGS_DELIMITER);
297316

298-
if (splitSettings.size() < 7) {
317+
if (splitSettings.size() < 8) {
299318
this->LogMessage("Invalid saved settings found, reverting to default.");
300319

301320
this->SaveSettings();
@@ -310,6 +329,7 @@ void CDelHel::LoadSettings()
310329
std::istringstream(splitSettings[4]) >> this->logMinMaxRFL;
311330
std::istringstream(splitSettings[5]) >> this->checkMinMaxRFL;
312331
std::istringstream(splitSettings[6]) >> this->flashOnMessage;
332+
std::istringstream(splitSettings[7]) >> this->preferTopSkySquawkAssignment;
313333

314334
this->LogDebugMessage("Successfully loaded settings.");
315335
}
@@ -327,7 +347,8 @@ void CDelHel::SaveSettings()
327347
<< this->warnRFLBelowCFL << SETTINGS_DELIMITER
328348
<< this->logMinMaxRFL << SETTINGS_DELIMITER
329349
<< this->checkMinMaxRFL << SETTINGS_DELIMITER
330-
<< this->flashOnMessage;
350+
<< this->flashOnMessage << SETTINGS_DELIMITER
351+
<< this->preferTopSkySquawkAssignment;
331352

332353
this->SaveDataToSettings(PLUGIN_NAME, "DelHel settings", ss.str().c_str());
333354
}
@@ -557,8 +578,15 @@ validation CDelHel::ProcessFlightPlan(EuroScopePlugIn::CFlightPlan& fp, bool nap
557578
return res;
558579
}
559580

560-
if (!cad.SetSquawk(VFR_SQUAWK)) {
561-
this->LogDebugMessage("Failed to set VFR squawk", cs);
581+
if (this->radarScreen != nullptr && this->ccamsAvailable && !this->preferTopSkySquawkAssignment) {
582+
this->radarScreen->StartTagFunction(cs.c_str(), nullptr, 0, cs.c_str(), CCAMS_PLUGIN_NAME, CCAMS_TAG_FUNC_ASSIGN_SQUAWK_VFR, POINT(), RECT());
583+
this->LogDebugMessage("Triggered automatic VFR squawk assignment via CCAMS", cs);
584+
}
585+
else {
586+
// TopSky doesn't have a dedicated VFR squawk assignment function. Force hardcoded VFR squawk assignment
587+
if (!cad.SetSquawk(VFR_SQUAWK)) {
588+
this->LogDebugMessage("Failed to set VFR squawk", cs);
589+
}
562590
}
563591

564592
this->LogDebugMessage("Skipping processing of VFR flightplan route", cs);
@@ -734,11 +762,24 @@ validation CDelHel::ProcessFlightPlan(EuroScopePlugIn::CFlightPlan& fp, bool nap
734762
}
735763

736764
if (this->radarScreen == nullptr) {
737-
this->LogDebugMessage("Radar screen not initialised, cannot trigger automatic squawk assignment via TopSky", cs);
765+
this->LogDebugMessage("Radar screen not initialised, cannot trigger automatic squawk assignment via TopSky or CCAMS", cs);
738766
}
739767
else {
740-
this->radarScreen->StartTagFunction(cs.c_str(), nullptr, 0, cs.c_str(), TOPSKY_PLUGIN_NAME, TOPSKY_TAG_FUNC_ASSIGN_SQUAWK, POINT(), RECT());
741-
this->LogDebugMessage("Triggered automatic squawk assignment via TopSky", cs);
768+
if (this->preferTopSkySquawkAssignment && this->topSkyAvailable) {
769+
this->radarScreen->StartTagFunction(cs.c_str(), nullptr, 0, cs.c_str(), TOPSKY_PLUGIN_NAME, TOPSKY_TAG_FUNC_ASSIGN_SQUAWK, POINT(), RECT());
770+
this->LogDebugMessage("Triggered automatic squawk assignment via TopSky", cs);
771+
}
772+
else if (this->ccamsAvailable) {
773+
this->radarScreen->StartTagFunction(cs.c_str(), nullptr, 0, cs.c_str(), CCAMS_PLUGIN_NAME, CCAMS_TAG_FUNC_ASSIGN_SQUAWK_AUTO, POINT(), RECT());
774+
this->LogDebugMessage("Triggered automatic squawk assignment via CCAMS", cs);
775+
}
776+
else if (this->topSkyAvailable) {
777+
this->radarScreen->StartTagFunction(cs.c_str(), nullptr, 0, cs.c_str(), TOPSKY_PLUGIN_NAME, TOPSKY_TAG_FUNC_ASSIGN_SQUAWK, POINT(), RECT());
778+
this->LogDebugMessage("Triggered automatic squawk assignment via TopSky", cs);
779+
}
780+
else {
781+
this->LogDebugMessage("Neither TopSky nor CCAMS are loaded, cannot trigger automatic squawk assignment", cs);
782+
}
742783
}
743784

744785
this->LogDebugMessage("Successfully processed flightplan", cs);
@@ -1030,6 +1071,47 @@ void CDelHel::CheckForUpdate()
10301071
this->latestVersion = std::future<std::string>();
10311072
}
10321073

1074+
void CDelHel::CheckLoadedPlugins()
1075+
{
1076+
this->topSkyAvailable = false;
1077+
this->ccamsAvailable = false;
1078+
1079+
HMODULE hMods[1024];
1080+
HANDLE hProcess;
1081+
DWORD cbNeeded;
1082+
unsigned int i;
1083+
1084+
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId());
1085+
if (hProcess == NULL) {
1086+
this->LogDebugMessage("Failed to check loaded plugins");
1087+
return;
1088+
}
1089+
1090+
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) {
1091+
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) {
1092+
TCHAR szModName[MAX_PATH];
1093+
if (GetModuleFileNameEx(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) {
1094+
std::string moduleName = szModName;
1095+
size_t pos = moduleName.find_last_of("\\");
1096+
if (pos != std::string::npos) {
1097+
moduleName = moduleName.substr(pos + 1);
1098+
}
1099+
1100+
if (moduleName == TOPSKY_DLL_NAME) {
1101+
this->topSkyAvailable = true;
1102+
this->LogDebugMessage("Found TopSky plugin", "Config");
1103+
}
1104+
else if (moduleName == CCAMS_DLL_NAME) {
1105+
this->ccamsAvailable = true;
1106+
this->LogDebugMessage("Found CCAMS plugin", "Config");
1107+
}
1108+
}
1109+
}
1110+
}
1111+
1112+
CloseHandle(hProcess);
1113+
}
1114+
10331115
void __declspec (dllexport) EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInstance)
10341116
{
10351117
*ppPlugInInstance = pPlugin = new CDelHel();

DelHel/CDelHel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <fstream>
99
#include <filesystem>
1010
#include <algorithm>
11+
#include <psapi.h>
1112

1213
#include "EuroScope/EuroScopePlugIn.h"
1314
#include "semver/semver.hpp"
@@ -47,6 +48,9 @@ class CDelHel : public EuroScopePlugIn::CPlugIn
4748
bool logMinMaxRFL;
4849
bool checkMinMaxRFL;
4950
bool flashOnMessage;
51+
bool topSkyAvailable;
52+
bool ccamsAvailable;
53+
bool preferTopSkySquawkAssignment;
5054
std::future<std::string> latestVersion;
5155
std::map<std::string, airport> airports;
5256
std::vector<std::string> processed;
@@ -69,5 +73,6 @@ class CDelHel : public EuroScopePlugIn::CPlugIn
6973
void LogDebugMessage(std::string message, std::string type);
7074

7175
void CheckForUpdate();
76+
void CheckLoadedPlugins();
7277
};
7378

DelHel/DelHel.rc

0 Bytes
Binary file not shown.

DelHel/constants.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <regex>
44

55
#define PLUGIN_NAME "DelHel"
6-
#define PLUGIN_VERSION "0.1.0"
6+
#define PLUGIN_VERSION "0.2.0"
77
#define PLUGIN_AUTHOR "Nick Mueller"
8-
#define PLUGIN_LICENSE "(c) 2020-2022, MIT License"
8+
#define PLUGIN_LICENSE "(c) 2020-2023, MIT License"
99
#define PLUGIN_LATEST_VERSION_URL "https://raw.githubusercontent.com/MorpheusXAUT/DelHel/master/version.txt"
1010
#define PLUGIN_LATEST_DOWNLOAD_URL "https://github.com/MorpheusXAUT/DelHel/releases/latest"
1111

@@ -19,8 +19,14 @@ const int TAG_FUNC_PROCESS_FP_NAP = 102;
1919
const int TAG_FUNC_PROCESS_FP_NON_NAP = 103;
2020

2121
constexpr auto TOPSKY_PLUGIN_NAME = "TopSky plugin";
22+
constexpr auto TOPSKY_DLL_NAME = "TopSky.dll";
2223
const int TOPSKY_TAG_FUNC_ASSIGN_SQUAWK = 667;
2324

25+
constexpr auto CCAMS_PLUGIN_NAME = "CCAMS";
26+
constexpr auto CCAMS_DLL_NAME = "CCAMS.dll";
27+
const int CCAMS_TAG_FUNC_ASSIGN_SQUAWK_AUTO = 871;
28+
const int CCAMS_TAG_FUNC_ASSIGN_SQUAWK_VFR = 873;
29+
2430
const COLORREF TAG_COLOR_NONE = 0;
2531
const COLORREF TAG_COLOR_RED = RGB(200, 0, 0);
2632
const COLORREF TAG_COLOR_ORANGE = RGB(255, 165, 0);

0 commit comments

Comments
 (0)