forked from pierr3/ModeS
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CCAMS.cpp
1170 lines (1066 loc) · 46.2 KB
/
CCAMS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include "CCAMS.h"
#include <fstream>
CCAMS::CCAMS(const EquipmentCodes&& ec, const SquawkCodes&& sc) : CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE,
MY_PLUGIN_NAME,
MY_PLUGIN_VERSION,
MY_PLUGIN_DEVELOPER,
MY_PLUGIN_COPYRIGHT),
EquipmentCodesFAA(ec.FAA),
EquipmentCodesICAO(ec.ICAO_MODE_S),
EquipmentCodesICAOEHS(ec.ICAO_EHS),
ModeSAirports(MODE_S_AIRPORTS),
squawkModeS(sc.MODE_S),
squawkVFR(sc.VFR)
{
string DisplayMsg { "Version " + string { MY_PLUGIN_VERSION } + " loaded" };
#ifdef _DEBUG
DisplayUserMessage(MY_PLUGIN_NAME, "Initialisation", ("DEBUG " + DisplayMsg).c_str(), true, false, false, false, false);
#else
DisplayUserMessage(MY_PLUGIN_NAME, "Initialisation", DisplayMsg.c_str(), true, false, false, false, false);
#endif
RegisterTagItemType("Transponder Type", ItemCodes::TAG_ITEM_ISMODES);
RegisterTagItemType("EHS Heading", ItemCodes::TAG_ITEM_EHS_HDG);
RegisterTagItemType("EHS Roll Angle", ItemCodes::TAG_ITEM_EHS_ROLL);
RegisterTagItemType("EHS GS", ItemCodes::TAG_ITEM_EHS_GS);
RegisterTagItemType("Mode S squawk error", ItemCodes::TAG_ITEM_ERROR_MODES_USE);
RegisterTagItemType("Assigned squawk", ItemCodes::TAG_ITEM_SQUAWK);
RegisterTagItemFunction("Auto assign squawk", ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_AUTO);
RegisterTagItemFunction("Open SQUAWK assign popup", ItemCodes::TAG_FUNC_SQUAWK_POPUP);
FpListEHS = RegisterFpList("Mode S EHS");
if (FpListEHS.GetColumnNumber() == 0)
{
FpListEHS.AddColumnDefinition("C/S", 8, false, NULL, TAG_ITEM_TYPE_CALLSIGN, NULL, TAG_ITEM_FUNCTION_OPEN_FP_DIALOG, NULL, NULL);
FpListEHS.AddColumnDefinition("HDG", 5, true, MY_PLUGIN_NAME, ItemCodes::TAG_ITEM_EHS_HDG, NULL, NULL, NULL, NULL);
FpListEHS.AddColumnDefinition("Roll", 5, true, MY_PLUGIN_NAME, ItemCodes::TAG_ITEM_EHS_ROLL, NULL, NULL, NULL, NULL);
FpListEHS.AddColumnDefinition("GS", 4, true, MY_PLUGIN_NAME, ItemCodes::TAG_ITEM_EHS_GS, NULL, NULL, NULL, NULL);
}
// Start new thread to get the version file from the server
fUpdateString = async(LoadUpdateString);
// Set default setting values
ConnectionStatus = 0;
pluginVersionCheck = false;
acceptEquipmentICAO = true;
acceptEquipmentFAA = true;
#ifdef _DEBUG
autoAssign = true;
#else
autoAssign = true;
#endif
APTcodeMaxGS = 50;
APTcodeMaxDist = 3;
ReadSettings();
}
CCAMS::~CCAMS()
{}
bool CCAMS::OnCompileCommand(const char* command)
{
string commandString(command);
cmatch matches;
if (_stricmp(command, ".help") == 0)
{
DisplayUserMessage("HELP", "HELP", ".HELP CCAMS | Centralised code assignment and management system Help", true, true, true, true, false);
return NULL;
}
else if (_stricmp(command, ".help ccams") == 0)
{
// Display HELP
DisplayUserMessage("HELP", MY_PLUGIN_NAME, ".CCAMS EHSLIST | Displays the flight plan list with EHS values of the currently selected aircraft.", true, true, true, true, false);
DisplayUserMessage("HELP", MY_PLUGIN_NAME, ".CCAMS AUTO | Activates or deactivates automatic code assignment.", true, true, true, true, false);
DisplayUserMessage("HELP", MY_PLUGIN_NAME, ".CCAMS TRACKING | Activates or deactivates transponder code validation when starting to track a flight.", true, true, true, true, false);
DisplayUserMessage("HELP", MY_PLUGIN_NAME, ".CCAMS RELOAD | Force load of local and remote settings.", true, true, true, true, false);
#ifdef _DEBUG
DisplayUserMessage("HELP", MY_PLUGIN_NAME, ".CCAMS RESET | Clears the list of flight plans which have been determined no longer applicable for automatic code assignment.", true, true, true, true, false);
DisplayUserMessage("HELP", MY_PLUGIN_NAME, ".CCAMS [CALL SIGN] | Displays tracking and controller information for a specific flight (to support debugging of automatic code assignment).", true, true, true, true, false);
#endif
return true;
}
else if (regex_search(command, matches, regex("^\\.ccams\\s+(\\w+)", regex::icase)))
{
return PluginCommands(matches[1].str().c_str());
}
return false;
}
bool CCAMS::PluginCommands(const char* Command)
{
//string sCommand(Command);
if (_stricmp(Command, "ehslist") == 0)
{
FpListEHS.ShowFpList(true);
return true;
}
else if (_stricmp(Command, "auto") == 0)
{
if (!pluginVersionCheck)
{
DisplayUserMessage(MY_PLUGIN_NAME, "Error", "Your plugin version is not up-to-date and the automatic code assignment therefore not available.", true, true, false, false, false);
}
else if (autoAssign)
{
autoAssign = false;
SaveDataToSettings("AutoAssign", "Automatic assignment of squawk codes", "0");
DisplayUserMessage(MY_PLUGIN_NAME, "Setting changed", "Automatic code assignment disabled", true, true, false, false, false);
}
else
{
autoAssign = true;
SaveDataToSettings("AutoAssign", "Automatic assignment of squawk codes", "1");
DisplayUserMessage(MY_PLUGIN_NAME, "Setting changed", "Automatic code assignment enabled", true, true, false, false, false);
}
return true;
}
else if (_stricmp(Command, "tracking") == 0)
{
if (updateOnStartTracking)
{
updateOnStartTracking = false;
SaveDataToSettings("updateOnStartTracking", "Validating squawk when starting to track an aircraft", "0");
DisplayUserMessage(MY_PLUGIN_NAME, "Setting changed", "Validating squawk when starting to track an aircraft disabled", true, true, false, false, false);
}
else
{
updateOnStartTracking = true;
SaveDataToSettings("updateOnStartTracking", "Validating squawk when starting to track an aircraft", "1");
DisplayUserMessage(MY_PLUGIN_NAME, "Setting changed", "Validating squawk when starting to track an aircraft enabled", true, true, false, false, false);
}
return true;
}
else if (_stricmp(Command, "reload") == 0)
{
fUpdateString = async(LoadUpdateString);
ReadSettings();
return true;
}
#ifdef _DEBUG
else if (_stricmp(Command, "reset") == 0)
{
ProcessedFlightPlans.clear();
return true;
}
else if (_stricmp(Command, "list") == 0)
{
string DisplayMsg;
for (auto& pfp : ProcessedFlightPlans)
{
if (DisplayMsg.length() == 0)
DisplayMsg = "Processed Flight Plans: " + pfp;
else
DisplayMsg += ", " + pfp;
}
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
return true;
}
else if (_stricmp(Command, "sqlist") == 0)
{
for (CRadarTarget RadarTarget = RadarTargetSelectFirst(); RadarTarget.IsValid();
RadarTarget = RadarTargetSelectNext(RadarTarget))
{
string DisplayMsg = "Status " + string{ (RadarTarget.GetCorrelatedFlightPlan().GetSimulated() ? "simulated" : "not sim") } +
", FP Type '" + RadarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetPlanType() + "'" +
", AC info '" + RadarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetAircraftInfo() + "' / '" + to_string(RadarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetCapibilities()) + "'" +
", " + to_string(RadarTarget.GetCorrelatedFlightPlan().GetSectorEntryMinutes()) + " Minutes to Sector Entry, " +
(HasValidSquawk(RadarTarget.GetCorrelatedFlightPlan()) ? "has valid squawk" : "has NO valid squawk") +
", ASSIGNED '" + RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk() + "', SET " + RadarTarget.GetPosition().GetSquawk();
DisplayUserMessage("CCAMS Squawk List Dump", RadarTarget.GetCallsign(), DisplayMsg.c_str(), true, false, false, false, false);
}
return true;
}
else
{
for (CFlightPlan FlightPlan = FlightPlanSelectFirst(); FlightPlan.IsValid();
FlightPlan = FlightPlanSelectNext(FlightPlan))
{
if (_stricmp(Command, FlightPlan.GetCallsign()) == 0)
{
string DisplayMsg = "Status " + string{FlightPlan.GetCallsign()} + ": " + (FlightPlan.GetSimulated() ? "simulated" : "not sim") +
", FP Type '" + FlightPlan.GetFlightPlanData().GetPlanType() + "'" +
", AC info '" + FlightPlan.GetFlightPlanData().GetAircraftInfo() + "' / '" + FlightPlan.GetFlightPlanData().GetCapibilities() + "'" +
", " + to_string(FlightPlan.GetSectorEntryMinutes()) + " Minutes to Sector Entry, " +
(HasValidSquawk(FlightPlan) ? "has valid squawk" : "has NO valid squawk") +
", ASSIGNED '" + FlightPlan.GetControllerAssignedData().GetSquawk() + "', SET " + FlightPlan.GetCorrelatedRadarTarget().GetPosition().GetSquawk();
DisplayUserMessage("CCAMS FP Status", "Debug", DisplayMsg.c_str(), true, false, false, false, false);
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController() || (ControllerMyself().GetFacility() > 1 && ControllerMyself().GetFacility() < 5))
DisplayUserMessage("CCAMS FP Status", "Debug", "This controller is not allowed to automatically assign squawks", true, false, false, false, false);
if (find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end())
DisplayUserMessage("CCAMS FP Status", "Debug", "This flight plan has already been processed", true, false, false, false, false);
for (CRadarTarget RadarTarget = RadarTargetSelectFirst(); RadarTarget.IsValid();
RadarTarget = RadarTargetSelectNext(RadarTarget))
{
if (_stricmp(RadarTarget.GetCallsign(), FlightPlan.GetCallsign()) == 0)
continue;
else if (_stricmp(RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk(), FlightPlan.GetControllerAssignedData().GetSquawk()) == 0 && _stricmp(RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk(),squawkModeS) != 0)
{
DisplayMsg = "ASSR also used for " + string{ RadarTarget.GetCallsign() } + ", " + (RadarTarget.GetCorrelatedFlightPlan().GetSimulated() ? "simulated" : "not sim") +
", FP Type '" + RadarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetPlanType() + "', " + to_string(RadarTarget.GetCorrelatedFlightPlan().GetSectorEntryMinutes()) +
" Minutes to Sector Entry, " + (HasValidSquawk(RadarTarget.GetCorrelatedFlightPlan()) ? "has valid squawk" : "has NO valid squawk") +
", ASSIGNED '" + RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk() + "', SET " + RadarTarget.GetPosition().GetSquawk();
DisplayUserMessage("CCAMS FP Status", RadarTarget.GetCallsign(), DisplayMsg.c_str(), true, false, false, false, false);
}
else if (_stricmp(RadarTarget.GetPosition().GetSquawk(), FlightPlan.GetControllerAssignedData().GetSquawk()) == 0 && _stricmp(RadarTarget.GetPosition().GetSquawk(), squawkModeS) != 0)
{
DisplayMsg = "PSSR also used for " + string{ RadarTarget.GetCallsign() } + ", " + (RadarTarget.GetCorrelatedFlightPlan().GetSimulated() ? "simulated" : "not sim") +
", FP Type '" + RadarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetPlanType() + "', " + to_string(RadarTarget.GetCorrelatedFlightPlan().GetSectorEntryMinutes()) +
" Minutes to Sector Entry, " + (HasValidSquawk(RadarTarget.GetCorrelatedFlightPlan()) ? "has valid squawk" : "has NO valid squawk") +
", ASSIGNED '" + RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk() + "', SET " + RadarTarget.GetPosition().GetSquawk();
DisplayUserMessage("CCAMS FP Status", RadarTarget.GetCallsign(), DisplayMsg.c_str(), true, false, false, false, false);
}
}
return true;
}
}
}
#endif
return false;
}
void CCAMS::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget, int ItemCode, int TagData, char sItemString[16], int * pColorCode, COLORREF * pRGB, double * pFontSize)
{
if (!FlightPlan.IsValid())
return;
if (ItemCode == ItemCodes::TAG_ITEM_ISMODES)
{
if (IsAcModeS(FlightPlan))
strcpy_s(sItemString, 16, "S");
else
strcpy_s(sItemString, 16, "A");
}
else
{
if (!RadarTarget.IsValid())
return;
if (ItemCode == ItemCodes::TAG_ITEM_EHS_HDG)
{
if (IsEHS(FlightPlan))
{
//strncpy(sItemString, to_string(RadarTarget.GetPosition().GetReportedHeading()).c_str(), 16);
sprintf_s(sItemString, 16, "%03i°", RadarTarget.GetPosition().GetReportedHeading() % 360);
#ifdef _DEBUG
string DisplayMsg{ to_string(RadarTarget.GetPosition().GetReportedHeading()) };
//DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
else
{
strcpy_s(sItemString, 16, "N/A");
}
}
else if (ItemCode == ItemCodes::TAG_ITEM_EHS_ROLL)
{
if (IsEHS(FlightPlan))
{
auto rollb = RadarTarget.GetPosition().GetReportedBank();
if (rollb == 0)
{
sprintf_s(sItemString, 16, "%i", abs(rollb));
}
else
{
sprintf_s(sItemString, 16, "%c%i°", rollb > 0 ? 'R' : 'L', abs(rollb));
}
#ifdef _DEBUG
string DisplayMsg{ to_string(abs(rollb)) };
//DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
else
{
strcpy_s(sItemString, 16, "N/A");
}
}
else if (ItemCode == ItemCodes::TAG_ITEM_EHS_GS)
{
if (IsEHS(FlightPlan) && FlightPlan.GetCorrelatedRadarTarget().IsValid())
{
snprintf(sItemString, 16, "%03i", RadarTarget.GetPosition().GetReportedGS());
#ifdef _DEBUG
string DisplayMsg{ to_string(RadarTarget.GetPosition().GetReportedGS()) };
//DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
else
{
strcpy_s(sItemString, 16, "N/A");
}
}
else if (ItemCode == ItemCodes::TAG_ITEM_ERROR_MODES_USE)
{
if (IsEligibleSquawkModeS(FlightPlan)) return;
auto assr = RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk();
auto pssr = RadarTarget.GetPosition().GetSquawk();
if (strcmp(assr, squawkModeS) != 0 &&
strcmp(pssr, squawkModeS) != 0)
return;
*pColorCode = EuroScopePlugIn::TAG_COLOR_INFORMATION;
strcpy_s(sItemString, 16, "MSSQ");
}
else if (ItemCode == ItemCodes::TAG_ITEM_SQUAWK)
{
auto assr = RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk();
auto pssr = RadarTarget.GetPosition().GetSquawk();
if (!IsEligibleSquawkModeS(FlightPlan) && (strcmp(assr, squawkModeS) == 0 || (strcmp(pssr, squawkModeS) == 0 && strlen(assr) == 0)))
{
// mode S code assigned, but not eligible
*pColorCode = EuroScopePlugIn::TAG_COLOR_REDUNDANT;
}
else if(strcmp(assr, pssr) != 0)
{
// assigned squawk is not set
*pColorCode = EuroScopePlugIn::TAG_COLOR_INFORMATION;
}
strcpy_s(sItemString, 16, assr);
}
}
}
void CCAMS::OnFlightPlanDisconnect(CFlightPlan FlightPlan)
{
ProcessedFlightPlans.erase(remove(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()),
ProcessedFlightPlans.end());
FpListEHS.RemoveFpFromTheList(FlightPlan);
}
void CCAMS::OnFlightPlanFlightPlanDataUpdate(CFlightPlan FlightPlan)
{
string DisplayMsg;
#ifdef _DEBUG
stringstream log;
#endif
if (!HasValidSquawk(FlightPlan))
{
if (std::find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end() && updateOnStartTracking)
{
ProcessedFlightPlans.erase(remove(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()), ProcessedFlightPlans.end());
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP removed from processed list:no valid squawk assigned";
writeLogFile(log);
DisplayMsg = string{ FlightPlan.GetCallsign() } + " removed from processed list because it has no valid squawk assigned";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}
else if (FlightPlan.GetTrackingControllerIsMe())
{
if (autoAssign && pluginVersionCheck && ConnectionStatus > 10)
{
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP processed for automatic squawk assignment:flight plan update and controller is tracking";
writeLogFile(log);
string DisplayMsg = string{ FlightPlan.GetCallsign() } + " is processed for automatic squawk assignment (due to flight plan update and controller is tracking)";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, true, false, false, false);
#endif
AssignAutoSquawk(FlightPlan);
}
}
}
void CCAMS::OnFlightPlanFlightStripPushed(CFlightPlan FlightPlan, const char* sSenderController, const char* sTargetController)
{
#ifdef _DEBUG
stringstream log;
#endif
if (strcmp(sTargetController, FlightPlan.GetCallsign()) == 0)
{
// shouldn't be required that often anymore (if at all) since call signs are not added to the list that generously
auto it = find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign());
if (it != ProcessedFlightPlans.end()) {
//ProcessedFlightPlans.erase(it);
ProcessedFlightPlans.erase(remove(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()), ProcessedFlightPlans.end());
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP removed from processed list:strip push received";
writeLogFile(log);
string DisplayMsg = string{ FlightPlan.GetCallsign() } + " removed from processed list because a strip push has been received";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}
}
void CCAMS::OnRefreshFpListContent(CFlightPlanList AcList)
{
if (ControllerMyself().IsValid() && RadarTargetSelectASEL().IsValid())
{
#ifdef _DEBUG
string DisplayMsg{ "The following call sign was identified to be added to the EHS Mode S list: " + string { FlightPlanSelectASEL().GetCallsign() } };
//DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
for (CFlightPlan FP = FlightPlanSelectFirst(); FP.IsValid(); FP = FlightPlanSelectNext(FP))
{
FpListEHS.RemoveFpFromTheList(FP);
}
FpListEHS.AddFpToTheList(FlightPlanSelectASEL());
}
}
void CCAMS::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area)
{
CFlightPlan FlightPlan = FlightPlanSelectASEL();
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
return;
if (!FlightPlan.IsValid() || FlightPlan.GetSimulated())
return;
if (!FlightPlan.GetTrackingControllerIsMe() && strlen(FlightPlan.GetTrackingControllerCallsign())>0)
return;
switch (FunctionId)
{
case ItemCodes::TAG_FUNC_SQUAWK_POPUP:
OpenPopupList(Area, "Squawk", 1);
AddPopupListElement("Auto assign", "", ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_AUTO);
AddPopupListElement("Manual set", "", ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_MANUAL);
AddPopupListElement("Discrete", "", ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_DISCRETE);
AddPopupListElement("VFR", "", ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_VFR);
break;
case ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_MANUAL:
OpenPopupEdit(Area, ItemCodes::TAG_FUNC_ASSIGN_SQUAWK, "");
break;
case ItemCodes::TAG_FUNC_ASSIGN_SQUAWK:
FlightPlan.GetControllerAssignedData().SetSquawk(sItemString);
break;
case ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_AUTO:
if (IsEligibleSquawkModeS(FlightPlan))
{
FlightPlan.GetControllerAssignedData().SetSquawk(squawkModeS);
return;
}
// continue with discrete assignment if Mode S squawk is not applicable
case ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_DISCRETE:
try
{
if (PendingSquawks.find(FlightPlan.GetCallsign()) == PendingSquawks.end())
{
PendingSquawks.insert(std::make_pair(FlightPlan.GetCallsign(), std::async(LoadWebSquawk,
FlightPlan, ControllerMyself(), collectUsedCodes(FlightPlan), IsADEPvicinity(FlightPlan), GetConnectionType())));
#ifdef _DEBUG
if (GetConnectionType() > 2)
{
string DisplayMsg{ "A request for a simulated aircraft has been detected: " + string { FlightPlan.GetCallsign() } };
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
}
#endif
}
}
catch (std::runtime_error const& e)
{
DisplayUserMessage(MY_PLUGIN_NAME, "Error", e.what(), true, true, false, false, false);
}
catch (...)
{
DisplayUserMessage(MY_PLUGIN_NAME, "Error", std::to_string(GetLastError()).c_str(), true, true, false, false, false);
}
break;
case ItemCodes::TAG_FUNC_ASSIGN_SQUAWK_VFR:
FlightPlan.GetControllerAssignedData().SetSquawk(squawkVFR);
break;
default:
break;
}
}
void CCAMS::OnTimer(int Counter)
{
if (fUpdateString.valid() && fUpdateString.wait_for(0ms) == future_status::ready)
DoInitialLoad(fUpdateString);
if (GetConnectionType() > 0)
ConnectionStatus++;
else if (GetConnectionType() != ConnectionStatus)
{
ConnectionStatus = 0;
if (ProcessedFlightPlans.size() > 0)
{
ProcessedFlightPlans.clear();
#ifdef _DEBUG
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", "Connection Status 0 detected, all processed flight plans are removed from the list", true, false, false, false, false);
#endif
}
}
#ifdef _DEBUG
if (ConnectionStatus == 10)
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", "Active connection established, automatic squawk assignment enabled", true, false, false, false, false);
#endif
if (ControllerMyself().IsValid() && ControllerMyself().IsController())
{
AssignPendingSquawks();
if (!(Counter % 3) && autoAssign && pluginVersionCheck && ConnectionStatus > 10)
{
#ifdef _DEBUG
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", "Starting timer-based auto-assignments", true, false, false, false, false);
#endif // _DEBUG
for (CRadarTarget RadarTarget = RadarTargetSelectFirst(); RadarTarget.IsValid();
RadarTarget = RadarTargetSelectNext(RadarTarget))
{
AssignAutoSquawk(RadarTarget.GetCorrelatedFlightPlan());
}
}
}
}
void CCAMS::AssignAutoSquawk(CFlightPlan& FlightPlan)
{
string DisplayMsg;
#ifdef _DEBUG
stringstream log;
#endif
const char* assr = FlightPlan.GetControllerAssignedData().GetSquawk();
const char* pssr = FlightPlan.GetCorrelatedRadarTarget().GetPosition().GetSquawk();
// check controller class validity and qualification, restrict to APP/CTR/FSS controller types and respect a minimum connection duration (time)
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController() || ControllerMyself().GetRating() < 2 || (ControllerMyself().GetFacility() > 1 && ControllerMyself().GetFacility() < 5))
return;
// // check for exclusion arguments from automatic squawk assignment
// if (find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end())
// {
// // this flight was already processed
// if (FlightPlan.GetSimulated() || strcmp(FlightPlan.GetFlightPlanData().GetPlanType(), "V") == 0)
// return;
// else if (FlightPlan.GetFlightPlanData().IsReceived() && FlightPlan.GetSectorEntryMinutes() < 0)
// return;
// else if (HasValidSquawk(FlightPlan))
// return;
//
// // The flight was already processed, but the assigned code has become invalid again
// // This is probably due to a duplicate, where the code assigned earlier was assigned to a second aircraft by another controller
// else if (FlightPlan.GetTrackingControllerIsMe())
// {
// // attempting to change to squawk of the other aircraft
// for (CRadarTarget RadarTarget = RadarTargetSelectFirst(); RadarTarget.IsValid();
// RadarTarget = RadarTargetSelectNext(RadarTarget))
// {
// if (_stricmp(RadarTarget.GetCallsign(), FlightPlan.GetCallsign()) == 0)
// continue;
// else if (_stricmp(RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk(), FlightPlan.GetControllerAssignedData().GetSquawk()) == 0
// && RadarTarget.GetCorrelatedFlightPlan().GetTrackingControllerCallsign() > 0)
// {
// PendingSquawks.insert(std::make_pair(RadarTarget.GetCallsign(), std::async(LoadWebSquawk,
// RadarTarget.GetCorrelatedFlightPlan(), ControllerMyself(), collectUsedCodes(RadarTarget.GetCorrelatedFlightPlan()), IsADEPvicinity(RadarTarget.GetCorrelatedFlightPlan()), GetConnectionType())));
//#ifdef _DEBUG
// log << RadarTarget.GetCallsign() << ":duplicate assigned code:unique code AUTO assigned:" << FlightPlan.GetCallsign() << " already tracked by " << FlightPlan.GetTrackingControllerCallsign();
// writeLogFile(log);
// DisplayMsg = string{ RadarTarget.GetCallsign() } + ", unique code AUTO assigned due to a detected duplicate with " + FlightPlan.GetCallsign();
// DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
//#endif
// }
// }
// return;
// }
//
// // removing the call sign from the processed flight plan list to initiate a new assignment
// ProcessedFlightPlans.erase(remove(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()), ProcessedFlightPlans.end());
//#ifdef _DEBUG
// log << FlightPlan.GetCallsign() << ":duplicate assigned code:FP removed from processed list";
// writeLogFile(log);
// string DisplayMsg = string{ FlightPlan.GetCallsign() } + " removed from processed list because the assigned code is no longer valid";
// DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
//#endif
// }
if (FlightPlan.GetSimulated() || strcmp(FlightPlan.GetFlightPlanData().GetPlanType(), "V") == 0)
{
// disregard simulated flight plans (out of the controllers range)
// disregard flight with flight rule VFR
if (find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end())
{
ProcessedFlightPlans.push_back(FlightPlan.GetCallsign());
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP processed:Simulated/FP Type";
writeLogFile(log);
DisplayMsg = string{ FlightPlan.GetCallsign() } + " processed due to Simulation Flag / Flight Plan Type";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
return;
}
else if (FlightPlan.GetFlightPlanData().IsReceived() && FlightPlan.GetSectorEntryMinutes() < 0)
{
// the flight will never enter the sector of the current controller
if (find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end())
{
ProcessedFlightPlans.push_back(FlightPlan.GetCallsign());
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP processed:Sector Entry Time:" << FlightPlan.GetSectorEntryMinutes();
writeLogFile(log);
DisplayMsg = string{ FlightPlan.GetCallsign() } + " processed because it will not enter the controllers sector";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
return;
}
else if (HasValidSquawk(FlightPlan))
{
// this flight has already assigned a valid unique code
if (FlightPlan.GetTrackingControllerIsMe())
{
{
if (find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end())
ProcessedFlightPlans.push_back(FlightPlan.GetCallsign());
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP processed:has already a valid squawk:" << assr << ":" << pssr;
writeLogFile(log);
DisplayMsg = string{ FlightPlan.GetCallsign() } + " processed because it has already a valid squawk (ASSIGNED '" + assr + "', SET " + pssr + ")";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}
// if this flight is not tracked by the current controller yet, it is kept for revalidation in the next round
return;
}
else if (find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end())
{
// The flight was already processed, but the assigned code has become invalid again
// This is probably due to a duplicate, where the code assigned earlier was assigned to a second aircraft by another controller
if (FlightPlan.GetTrackingControllerIsMe())
{
// attempting to change to squawk of the other aircraft
for (CRadarTarget RadarTarget = RadarTargetSelectFirst(); RadarTarget.IsValid();
RadarTarget = RadarTargetSelectNext(RadarTarget))
{
if (_stricmp(RadarTarget.GetCallsign(), FlightPlan.GetCallsign()) == 0)
continue;
else if (_stricmp(RadarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetSquawk(), FlightPlan.GetControllerAssignedData().GetSquawk()) == 0
&& RadarTarget.GetCorrelatedFlightPlan().GetTrackingControllerCallsign() > 0)
{
PendingSquawks.insert(std::make_pair(RadarTarget.GetCallsign(), std::async(LoadWebSquawk,
RadarTarget.GetCorrelatedFlightPlan(), ControllerMyself(), collectUsedCodes(RadarTarget.GetCorrelatedFlightPlan()), IsADEPvicinity(RadarTarget.GetCorrelatedFlightPlan()), GetConnectionType())));
#ifdef _DEBUG
log << RadarTarget.GetCallsign() << ":duplicate assigned code:unique code AUTO assigned:" << FlightPlan.GetCallsign() << " already tracked by " << FlightPlan.GetTrackingControllerCallsign();
writeLogFile(log);
DisplayMsg = string{ RadarTarget.GetCallsign() } + ", unique code AUTO assigned due to a detected duplicate with " + FlightPlan.GetCallsign();
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}
return;
}
// removing the call sign from the processed flight plan list to initiate a new assignment
ProcessedFlightPlans.erase(remove(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()), ProcessedFlightPlans.end());
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":duplicate assigned code:FP removed from processed list";
writeLogFile(log);
string DisplayMsg = string{ FlightPlan.GetCallsign() } + " removed from processed list because the assigned code is no longer valid";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
else
{
#ifdef _DEBUG
DisplayMsg = string{ FlightPlan.GetCallsign() } + " has NOT a valid squawk code (ASSIGNED '" + assr + "', SET " + pssr + "), continue checks if eligible for automatic squawk assignment";
//DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
// disregard if no flight plan received (= no ADES/ADEP), or low speed (considered not flying yet)
if (strlen(FlightPlan.GetFlightPlanData().GetOrigin()) < 4 || strlen(FlightPlan.GetFlightPlanData().GetDestination()) < 4 || FlightPlan.GetCorrelatedRadarTarget().GetGS() < APTcodeMaxGS)
return;
// disregard if the flight is assumed in the vicinity of the departure or arrival airport
if (IsADEPvicinity(FlightPlan) || FlightPlan.GetDistanceToDestination() < APTcodeMaxDist)
return;
#ifdef _DEBUG
DisplayMsg = string{ FlightPlan.GetCallsign() } + ": Tracking Controller Len '" + to_string(strlen(FlightPlan.GetTrackingControllerCallsign())) + "', CoordNextC '" + string{ FlightPlan.GetCoordinatedNextController() } + "', Minutes to entry " + to_string(FlightPlan.GetSectorEntryMinutes()) + ", TrackingMe: " + to_string(FlightPlan.GetTrackingControllerIsMe());
//DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
if (!FlightPlan.GetTrackingControllerIsMe())
{
// the current controller is not tracking the flight plan
CFlightPlanPositionPredictions Pos = FlightPlan.GetPositionPredictions();
int min;
for (min = 0; min < Pos.GetPointsNumber(); min++)
{
if (min <= 15 && _stricmp(FlightPlan.GetPositionPredictions().GetControllerId(min), "--") != 0)
{
break;
}
}
if (strlen(FlightPlan.GetTrackingControllerCallsign()) > 0)
{
// another controller is currently tracking the flight
return;
}
else if (_stricmp(ControllerMyself().GetPositionId(), FlightPlan.GetPositionPredictions().GetControllerId(min)) != 0)
{
// the current controller is not the next controller of this flight
return;
}
else if (FlightPlan.GetSectorEntryMinutes() > 15)
{
// the flight is still too far away from the current controllers sector
return;
}
else
{
#ifdef _DEBUG
// The current controller is not tracking the flight, but automatic squawk assignment is applicable
DisplayMsg = string{ FlightPlan.GetCallsign() } + " IS eligible for automatic squawk assignment. ASSIGNED '" + assr + "', SET " + pssr + ", Sector entry in " + to_string(FlightPlan.GetSectorEntryMinutes()) + " MIN";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
}
// if the function has not been ended, the flight is subject to automatic squawk assignment
#ifdef _DEBUG
DisplayMsg = string{ FlightPlan.GetCallsign() } + ", AC info '" + FlightPlan.GetFlightPlanData().GetAircraftInfo() + "' / '" + to_string(FlightPlan.GetFlightPlanData().GetCapibilities()) + "'";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
if (IsEligibleSquawkModeS(FlightPlan))
{
FlightPlan.GetControllerAssignedData().SetSquawk(squawkModeS);
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP processed:Mode S code AUTO assigned";
writeLogFile(log);
DisplayMsg = string{ FlightPlan.GetCallsign() } + ", code 1000 AUTO assigned";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
else
{
PendingSquawks.insert(std::make_pair(FlightPlan.GetCallsign(), std::async(LoadWebSquawk,
FlightPlan, ControllerMyself(), collectUsedCodes(FlightPlan), IsADEPvicinity(FlightPlan), GetConnectionType())));
#ifdef _DEBUG
log << FlightPlan.GetCallsign() << ":FP processed:unique code AUTO assigned";
writeLogFile(log);
DisplayMsg = string{ FlightPlan.GetCallsign() } + ", unique code AUTO assigned";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
}
ProcessedFlightPlans.push_back(FlightPlan.GetCallsign());
}
void CCAMS::AssignSquawk(CFlightPlan& FlightPlan)
{
future<string> webSquawk = std::async(LoadWebSquawk, FlightPlan, ControllerMyself(), collectUsedCodes(FlightPlan), IsADEPvicinity(FlightPlan), GetConnectionType());
if (webSquawk.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)
{
string squawk = webSquawk.get();
if (!FlightPlanSelect(FlightPlan.GetCallsign()).GetControllerAssignedData().SetSquawk(squawk.c_str()))
{
PendingSquawks.insert(std::make_pair(FlightPlan.GetCallsign(), std::async(LoadWebSquawk,
FlightPlan, ControllerMyself(), collectUsedCodes(FlightPlan), IsADEPvicinity(FlightPlan), GetConnectionType())));
}
}
}
void CCAMS::AssignPendingSquawks()
{
for (auto it = PendingSquawks.begin(), next_it = it; it != PendingSquawks.end(); it = next_it)
{
bool must_delete = false;
if (it->second.valid() && it->second.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
std::string squawk = it->second.get();
//if (squawk is an error number)
#ifdef _DEBUG
string DisplayMsg = string{ it->first } + ", code " + squawk + " assigned";
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
if (!FlightPlanSelect(it->first).GetControllerAssignedData().SetSquawk(squawk.c_str()))
{
if (squawk == "E404")
{
DisplayUserMessage(MY_PLUGIN_NAME, "Error 404", "The internet connection cannot be initiated", true, true, false, false, false);
}
else if (squawk == "E406")
{
DisplayUserMessage(MY_PLUGIN_NAME, "Error 406", "No answer received from the CCAMS server", true, true, false, false, false);
}
else
{
string DisplayMsg{ "Your request for a squawk from the centralised code server failed. Check your plugin version, try again or revert to the ES built-in functionalities for assigning a squawk (F9)." };
DisplayUserMessage(MY_PLUGIN_NAME, "Error", DisplayMsg.c_str(), true, true, false, false, false);
DisplayUserMessage(MY_PLUGIN_NAME, "Error", ("For troubleshooting, report code '" + squawk + "'").c_str(), true, true, false, false, false);
}
}
must_delete = true;
}
++next_it;
if (must_delete)
{
PendingSquawks.erase(it);
}
}
}
void CCAMS::DoInitialLoad(future<string> & fmessage)
{
try
{
string message = fmessage.get();
smatch match;
#ifdef _DEBUG
string DisplayMsg = "Update string downloaded: " + message;
DisplayUserMessage(MY_PLUGIN_NAME, "Debug", DisplayMsg.c_str(), true, false, false, false, false);
#endif
if (regex_match(message, match, regex("(\\d+)[:](\\d+)[:]([A-Z,]+)[:]([^:]+)", regex::icase)))
{
if (stoi(match[2].str(), nullptr, 0) > MY_PLUGIN_VERSIONCODE)
throw error{ "Your " + string { MY_PLUGIN_NAME } + " plugin (version " + MY_PLUGIN_VERSION + ") is outdated and the automatic code assignment therefore not available. Please change to the latest version.\n\nVisit https://github.com/kusterjs/CCAMS/releases" };
else
pluginVersionCheck = true;
if (stoi(match[1].str(), nullptr, 0) > MY_PLUGIN_VERSIONCODE)
{
DisplayUserMessage(MY_PLUGIN_NAME, "Update", "An update for the CCAMS plugin is available. Please visit https://github.com/kusterjs/CCAMS/releases and download the latest version.", true, true, false, true, false);
}
EquipmentCodesFAA = match[3].str();
ModeSAirports = regex(match[4].str(), regex::icase);
}
else
{
throw error{ string { MY_PLUGIN_NAME } + " plugin couldn't parse the server configuration and version data. Automatic code assignment therefore not available." };
}
}
catch (modesexception & e)
{
e.whatMessageBox();
}
catch (exception & e)
{
MessageBox(NULL, e.what(), MY_PLUGIN_NAME, MB_OK | MB_ICONERROR);
}
fmessage = future<string>();
}
void CCAMS::ReadSettings()
{
// Overwrite setting values by plugin settings, if available
try
{
const char* cstrSetting = GetDataFromSettings("codeVFR");
if (cstrSetting != NULL)
{
if (regex_match(cstrSetting, std::regex("[0-7]{4}")))
{
squawkVFR = cstrSetting;
}
}
cstrSetting = GetDataFromSettings("acceptFPLformatICAO");
if (cstrSetting != NULL)
{
if (strcmp(cstrSetting, "0") == 0)
{
acceptEquipmentICAO = false;
}
}
cstrSetting = GetDataFromSettings("acceptFPLformatFAA");
if (cstrSetting != NULL)
{
if (strcmp(cstrSetting, "0") == 0)
{
acceptEquipmentFAA = false;
}
}
cstrSetting = GetDataFromSettings("updateOnStartTracking");
if (cstrSetting != NULL)
{
if (strcmp(cstrSetting, "0") == 0)
{
updateOnStartTracking = false;
}
}
cstrSetting = GetDataFromSettings("AutoAssign");
if (cstrSetting != NULL)
{
if (strcmp(cstrSetting, "0") == 0)
{
autoAssign = false;
}
else if (strcmp(cstrSetting, "1") == 0)
{
autoAssign = true;
}
}
}
catch (std::runtime_error const& e)
{
DisplayUserMessage(MY_PLUGIN_NAME, "Plugin Error", (string("Error: ") + e.what()).c_str(), true, true, true, true, true);
}
catch (...)
{
DisplayUserMessage(MY_PLUGIN_NAME, "Plugin Error", ("Unexpected error: " + std::to_string(GetLastError())).c_str(), true, true, true, true, true);
}
}
inline bool CCAMS::IsFlightPlanProcessed(CFlightPlan& FlightPlan)
{
//if (find(ProcessedFlightPlans.begin(), ProcessedFlightPlans.end(), FlightPlan.GetCallsign()) != ProcessedFlightPlans.end())
// return true;
//return false;
string callsign { FlightPlan.GetCallsign() };
for (auto &pfp : ProcessedFlightPlans)
if (pfp.compare(callsign) == 0)
return true;
return false;
}
bool CCAMS::IsAcModeS(const CFlightPlan& FlightPlan) const
{
return HasEquipment(FlightPlan, acceptEquipmentFAA, acceptEquipmentICAO, EquipmentCodesICAO);
}
double CCAMS::GetDistanceFromOrigin(const CFlightPlan& FlightPlan) const
{
if (FlightPlan.GetExtractedRoute().GetPointsNumber() > 1)
return FlightPlan.GetFPTrackPosition().GetPosition().DistanceTo(FlightPlan.GetExtractedRoute().GetPointPosition(0));
for (EuroScopePlugIn::CSectorElement SectorElement = SectorFileElementSelectFirst(SECTOR_ELEMENT_AIRPORT); SectorElement.IsValid();
SectorElement = SectorFileElementSelectNext(SectorElement, SECTOR_ELEMENT_AIRPORT))
{
if (strncmp(SectorElement.GetName(), FlightPlan.GetFlightPlanData().GetOrigin(), 4) == 0)
{
CPosition AirportPosition;
if (SectorElement.GetPosition(&AirportPosition, 0))
return FlightPlan.GetFPTrackPosition().GetPosition().DistanceTo(AirportPosition);
break;
}
}
return 0;
}
bool CCAMS::IsADEPvicinity(const CFlightPlan& FlightPlan) const
{
if (FlightPlan.GetCorrelatedRadarTarget().GetGS() < APTcodeMaxGS &&
GetDistanceFromOrigin(FlightPlan) < APTcodeMaxDist)
return true;
return false;
}
bool CCAMS::IsApModeS(const string& icao) const
{
if (regex_search(icao, ModeSAirports))
return true;
return false;
}
bool CCAMS::IsEHS(const CFlightPlan& FlightPlan) const
{
return HasEquipment(FlightPlan, acceptEquipmentFAA, true, EquipmentCodesICAOEHS);
}
bool CCAMS::HasEquipment(const CFlightPlan& FlightPlan, bool acceptEquipmentFAA, bool acceptEquipmentICAO, string CodesICAO) const
{
//check for ICAO suffix
if (acceptEquipmentICAO)
{
cmatch acdata;
if (regex_match(FlightPlan.GetFlightPlanData().GetAircraftInfo(), acdata, regex("(\\w{2,4})\\/([LMHJ])-(\\w+)\\/(\\w*?[" + CodesICAO + "]\\w*)", std::regex::icase)))