@@ -33,8 +33,12 @@ CDelHel::CDelHel() : EuroScopePlugIn::CPlugIn(
33
33
this ->logMinMaxRFL = false ;
34
34
this ->checkMinMaxRFL = false ;
35
35
this ->flashOnMessage = false ;
36
+ this ->topSkyAvailable = false ;
37
+ this ->ccamsAvailable = false ;
38
+ this ->preferTopSkySquawkAssignment = false ;
36
39
37
40
this ->LoadSettings ();
41
+ this ->CheckLoadedPlugins ();
38
42
39
43
this ->ReadAirportConfig ();
40
44
this ->ReadRoutingConfig ();
@@ -55,7 +59,7 @@ bool CDelHel::OnCompileCommand(const char* sCommandLine)
55
59
if (starts_with (args[0 ], " .delhel" )) {
56
60
if (args.size () == 1 ) {
57
61
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 " ;
59
63
60
64
this ->LogMessage (msg.str ());
61
65
@@ -190,6 +194,21 @@ bool CDelHel::OnCompileCommand(const char* sCommandLine)
190
194
191
195
this ->SaveSettings ();
192
196
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
+
193
212
return true ;
194
213
}
195
214
}
@@ -295,7 +314,7 @@ void CDelHel::LoadSettings()
295
314
if (settings) {
296
315
std::vector<std::string> splitSettings = split (settings, SETTINGS_DELIMITER);
297
316
298
- if (splitSettings.size () < 7 ) {
317
+ if (splitSettings.size () < 8 ) {
299
318
this ->LogMessage (" Invalid saved settings found, reverting to default." );
300
319
301
320
this ->SaveSettings ();
@@ -310,6 +329,7 @@ void CDelHel::LoadSettings()
310
329
std::istringstream (splitSettings[4 ]) >> this ->logMinMaxRFL ;
311
330
std::istringstream (splitSettings[5 ]) >> this ->checkMinMaxRFL ;
312
331
std::istringstream (splitSettings[6 ]) >> this ->flashOnMessage ;
332
+ std::istringstream (splitSettings[7 ]) >> this ->preferTopSkySquawkAssignment ;
313
333
314
334
this ->LogDebugMessage (" Successfully loaded settings." );
315
335
}
@@ -327,7 +347,8 @@ void CDelHel::SaveSettings()
327
347
<< this ->warnRFLBelowCFL << SETTINGS_DELIMITER
328
348
<< this ->logMinMaxRFL << SETTINGS_DELIMITER
329
349
<< this ->checkMinMaxRFL << SETTINGS_DELIMITER
330
- << this ->flashOnMessage ;
350
+ << this ->flashOnMessage << SETTINGS_DELIMITER
351
+ << this ->preferTopSkySquawkAssignment ;
331
352
332
353
this ->SaveDataToSettings (PLUGIN_NAME, " DelHel settings" , ss.str ().c_str ());
333
354
}
@@ -557,8 +578,15 @@ validation CDelHel::ProcessFlightPlan(EuroScopePlugIn::CFlightPlan& fp, bool nap
557
578
return res;
558
579
}
559
580
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
+ }
562
590
}
563
591
564
592
this ->LogDebugMessage (" Skipping processing of VFR flightplan route" , cs);
@@ -734,11 +762,24 @@ validation CDelHel::ProcessFlightPlan(EuroScopePlugIn::CFlightPlan& fp, bool nap
734
762
}
735
763
736
764
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);
738
766
}
739
767
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
+ }
742
783
}
743
784
744
785
this ->LogDebugMessage (" Successfully processed flightplan" , cs);
@@ -1030,6 +1071,47 @@ void CDelHel::CheckForUpdate()
1030
1071
this ->latestVersion = std::future<std::string>();
1031
1072
}
1032
1073
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
+
1033
1115
void __declspec (dllexport) EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInstance)
1034
1116
{
1035
1117
*ppPlugInInstance = pPlugin = new CDelHel ();
0 commit comments