-
Notifications
You must be signed in to change notification settings - Fork 5
/
CoFrancePlugIn.cpp
949 lines (746 loc) · 36.3 KB
/
CoFrancePlugIn.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
#include "pch.h"
#include "CoFrancePlugIn.h"
#include "RadarScreen.h"
CoFrancePlugIn::CoFrancePlugIn(void):CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE, MY_PLUGIN_NAME, MY_PLUGIN_VERSION, MY_PLUGIN_DEVELOPER, MY_PLUGIN_COPYRIGHT)
{
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
char DllPathFile[_MAX_PATH];
GetModuleFileNameA(HINSTANCE(&__ImageBase), DllPathFile, sizeof(DllPathFile));
DllPath = DllPathFile;
DllPath.resize(DllPath.size() - strlen("CoFrance.dll"));
LoadConfigFile();
Stca = new CSTCA(CoFranceConfig);
// Register tag items
RegisterTagItemType("Two number ground speed", CoFranceTags::GS);
RegisterTagItemType("Vertical Indicator", CoFranceTags::VZ_INDICATOR);
RegisterTagItemType("Dynamic Coordinated Point (reduced)", CoFranceTags::COPXN_POINT_REDUCED);
RegisterTagItemType("Dynamic Coordinated Level (reduced)", CoFranceTags::COPXN_ALT_REDUCED);
RegisterTagItemType("Dynamic Coordinated Level (full)", CoFranceTags::COPXN_ALT_FULL);
RegisterTagItemType("Dummy item", CoFranceTags::DUMMY);
RegisterTagItemType("Dummy item (tagged)", CoFranceTags::DUMMY_TAGGED);
RegisterTagItemType("Scratchpad Indicator (Detail)", CoFranceTags::SCRATCHPAD_INDIC);
RegisterTagItemType("Conflict group (Detail)", CoFranceTags::CONFLICT_GROUP_DETAIL);
RegisterTagItemType("Conflict group (Tagged)", CoFranceTags::CONFLICT_GROUP_TAGGED);
RegisterTagItemType("RFL", CoFranceTags::RFL);
RegisterTagItemType("CFL", CoFranceTags::CFL);
RegisterTagItemType("CFL (Detail)", CoFranceTags::CFL_DETAILED);
RegisterTagItemType("Approach Intention Code", CoFranceTags::APP_INTENTION);
RegisterTagItemType("Vertical Speed", CoFranceTags::VZ);
RegisterTagItemType("STCA Indicator", CoFranceTags::STCA);
RegisterTagItemType("CPDLC Flag", CoFranceTags::CPDLC_STATUS);
RegisterTagItemType("OCL Flag", CoFranceTags::OCL_FLAG);
RegisterTagItemType("Assigned Speed", CoFranceTags::ASSIGNED_SPEED);
RegisterTagItemFunction("Assign Conflict Group", CoFranceTags::FUNCTION_CONFLICT_POPUP);
//RegisterTagItemFunction("Show OCL", CoFranceTags::FUNCTION_OCL_TP);
RegisterTagItemFunction("Open ASP Popup", CoFranceTags::FUNCTION_OPEN_ASP);
RegisterTagItemType("Stand", CoFranceTags::STAND);
RegisterTagItemFunction("Stand popup", CoFranceTags::FUNCTION_STAND_MENU);
DisplayUserMessage("Message", "CoFrance PlugIn", string("Version " + string(MY_PLUGIN_VERSION) + " loaded.").c_str(), false, false, false, false, false);
}
CoFrancePlugIn::~CoFrancePlugIn()
{
GdiplusShutdown(gdiplusToken);
}
CRadarScreen* CoFrancePlugIn::OnRadarScreenCreated(const char* sDisplayName, bool NeedRadarContent, bool GeoReferenced, bool CanBeSaved, bool CanBeCreated)
{
if (CanLoadRadarScreen)
return new RadarScreen(this);
else
return NULL;
}
bool CoFrancePlugIn::OnCompileCommand(const char* sCommandLine)
{
if (strcmp(sCommandLine, ".cofrance reload") == 0) {
LoadConfigFile();
return true;
}
if (strcmp(sCommandLine, ".cofrance reload-local") == 0 || strcmp(sCommandLine, ".cofrl") == 0) {
LoadConfigFile(false);
return true;
}
if (strcmp(sCommandLine, ".cofrance perf") == 0) {
performanceMode = true;
return true;
}
if (strcmp(sCommandLine, ".cofrance debug") == 0) {
Debug = !Debug;
if (Debug) {
DisplayUserMessage("CoFrance", "Debug", "Debug enabled", true, true, false, true, false);
}
else {
DisplayUserMessage("CoFrance", "Debug", "Debug disabled", true, true, false, true, false);
}
return true;
}
if (strcmp(sCommandLine, ".cofrance stand") == 0) {
StandAssignerEnabled = !StandAssignerEnabled;
if (StandAssignerEnabled) {
DisplayUserMessage("CoFrance", "Stand", "Auto assigner enabled", true, true, false, true, false);
}
else {
DisplayUserMessage("CoFrance", "Stand", "Auto assigner disabled", true, true, false, true, false);
}
return true;
}
return false;
}
void CoFrancePlugIn::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget, int ItemCode, int TagData, char sItemString[16], int* pColorCode, COLORREF* pRGB, double* pFontSize)
{
if (ItemCode == CoFranceTags::GS) {
if (!RadarTarget.IsValid())
return;
int gs = roundUp(RadarTarget.GetPosition().GetReportedGS(), 10);
string gs_s = padWithZeros(3, gs);
strcpy_s(sItemString, 16, gs_s.substr(0, 2).c_str());
}
if (ItemCode == CoFranceTags::SCRATCHPAD_INDIC) {
string txt = CoFranceCharacters::Pen;
if (strlen(FlightPlan.GetControllerAssignedData().GetScratchPadString()) > 0)
txt = FlightPlan.GetControllerAssignedData().GetScratchPadString();
strcpy_s(sItemString, 16, txt.substr(0, 15).c_str());
}
if (ItemCode == CoFranceTags::CONFLICT_GROUP_DETAIL) {
if (ConflictGroups.find(FlightPlan.GetCallsign()) != ConflictGroups.end()) {
strcpy_s(sItemString, 16, ConflictGroups[FlightPlan.GetCallsign()].c_str());
*pColorCode = TAG_COLOR_RGB_DEFINED;
*pRGB = GetConflictGroupColor(this->CoFranceConfig, ConflictGroups[FlightPlan.GetCallsign()].c_str());
}
else {
strcpy_s(sItemString, 16, CoFranceCharacters::Moon.c_str());
}
}
if (ItemCode == CoFranceTags::CONFLICT_GROUP_TAGGED) {
if (ConflictGroups.find(FlightPlan.GetCallsign()) != ConflictGroups.end()) {
strcpy_s(sItemString, 16, ConflictGroups[FlightPlan.GetCallsign()].c_str());
*pColorCode = TAG_COLOR_RGB_DEFINED;
*pRGB = GetConflictGroupColor(this->CoFranceConfig, ConflictGroups[FlightPlan.GetCallsign()].c_str());
}
else {
strcpy_s(sItemString, 16, "");
}
}
if (ItemCode == CoFranceTags::DUMMY) {
DetailedAircraft = RadarTarget.GetCallsign();
strcpy_s(sItemString, 16, "");
}
if (ItemCode == CoFranceTags::ASSIGNED_SPEED) {
string aspeed = "";
if (FlightPlan.GetControllerAssignedData().GetAssignedMach() != 0) {
aspeed = "m";
aspeed += "." + to_string(FlightPlan.GetControllerAssignedData().GetAssignedMach());
if (string(FlightPlan.GetControllerAssignedData().GetFlightStripAnnotation(CoFranceTags::ANNOTATION_SPEED_SIGN)) == string("+"))
aspeed += "+";
if (string(FlightPlan.GetControllerAssignedData().GetFlightStripAnnotation(CoFranceTags::ANNOTATION_SPEED_SIGN)) == string("-"))
aspeed += "-";
} else if (FlightPlan.GetControllerAssignedData().GetAssignedSpeed() != 0) {
aspeed = "k";
if (FlightPlan.GetControllerAssignedData().GetAssignedSpeed() % 10 == 1)
aspeed += to_string((FlightPlan.GetControllerAssignedData().GetAssignedSpeed() - 1)/10) + "+";
else if (FlightPlan.GetControllerAssignedData().GetAssignedSpeed() % 10 == 9)
aspeed += to_string((FlightPlan.GetControllerAssignedData().GetAssignedSpeed() + 1)/10) + "-";
else
aspeed += to_string(FlightPlan.GetControllerAssignedData().GetAssignedSpeed()/10);
}
strcpy_s(sItemString, 16, aspeed.c_str());
}
if (ItemCode == CoFranceTags::DUMMY_TAGGED) {
if (DetailedAircraft == RadarTarget.GetCallsign())
DetailedAircraft = "";
strcpy_s(sItemString, 16, "");
}
if (ItemCode == CoFranceTags::RFL) {
string rfl = "RFL";
if (FlightPlan.IsValid()) {
if (FlightPlan.GetFinalAltitude() > 0) {
rfl = padWithZeros(2, FlightPlan.GetFinalAltitude() / 1000);
// VFRs can be cleared up to 500 feet interval so we have to display more
if (FlightPlan.GetFlightPlanData().GetPlanType() == "V")
rfl = padWithZeros(3, FlightPlan.GetFinalAltitude() / 100);
if (FlightPlan.GetFinalAltitude() <= GetTransitionAltitude())
rfl = "A" + rfl;
}
}
strcpy_s(sItemString, 16, rfl.c_str());
}
if (ItemCode == CoFranceTags::CFL || ItemCode == CoFranceTags::CFL_DETAILED) {
string cfl = "";
if (ItemCode == CoFranceTags::CFL_DETAILED)
cfl = "CFL";
if (FlightPlan.IsValid()) {
if (FlightPlan.GetClearedAltitude() > 0) {
cfl = padWithZeros(2, FlightPlan.GetClearedAltitude() / 1000);
// VFRs can be cleared up to 500 feet interval so we have to display more
if (FlightPlan.GetFlightPlanData().GetPlanType() == "V")
cfl = padWithZeros(3, FlightPlan.GetClearedAltitude() / 100);
if (FlightPlan.GetClearedAltitude() <= GetTransitionAltitude())
cfl = "A" + cfl;
}
if (FlightPlan.GetControllerAssignedData().GetClearedAltitude() == 1)
cfl = CoFranceCharacters::ClearedAPPIndicator.c_str();;
if (FlightPlan.GetControllerAssignedData().GetClearedAltitude() == 2)
cfl = CoFranceCharacters::ClearedVisualIndicator.c_str();
// If not detailed and reached alt, then nothing to show
if (ItemCode == CoFranceTags::CFL && abs(RadarTarget.GetPosition().GetFlightLevel() - FlightPlan.GetClearedAltitude()) < 100)
cfl = "";
}
strcpy_s(sItemString, 16, cfl.c_str());
}
if (ItemCode == CoFranceTags::VZ_INDICATOR) {
if (!RadarTarget.IsValid())
return;
string tendency = "-";
int delta_fl = RadarTarget.GetPosition().GetFlightLevel() -
RadarTarget.GetPreviousPosition(RadarTarget.GetPosition()).GetFlightLevel();
if (abs(delta_fl) >= 10)
tendency = delta_fl < 0 ? "|" : "^";
strcpy_s(sItemString, 16, tendency.c_str());
}
if (ItemCode == CoFranceTags::APP_INTENTION) {
// Three types of codes:
// 1. VFR
// 2. Arrival (Assigned Runway with different colours)
// 3. Departure (Abbreviated SID)
if (FlightPlan.IsValid()) {
if (FlightPlan.GetFlightPlanData().GetPlanType()[0] == 'V') {
// We have a VFR flight
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_vfr");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, "VFR");
}
else {
// We have a departure
if (FlightPlan.GetDistanceFromOrigin() <= 50) {
string abbr_sid = "";
if (strlen(FlightPlan.GetFlightPlanData().GetSidName()) > 0) {
abbr_sid = FlightPlan.GetFlightPlanData().GetSidName();
abbr_sid = abbr_sid.substr(0, 3);
}
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_departure");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, abbr_sid.c_str());
}
else {
// We have an arrival
string arr_rwy = "";
if (strlen(FlightPlan.GetFlightPlanData().GetArrivalRwy()) > 0) {
arr_rwy = FlightPlan.GetFlightPlanData().GetArrivalRwy();
arr_rwy = arr_rwy.substr(0, 3);
}
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_arrival");
if (startsWith("LFPG", FlightPlan.GetFlightPlanData().GetDestination()) &&
(startsWith("26", FlightPlan.GetFlightPlanData().GetArrivalRwy()) || startsWith("08", FlightPlan.GetFlightPlanData().GetArrivalRwy()))) {
// South arrival at LFPG, different colour
element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_lfpg_arr_south");
}
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, arr_rwy.c_str());
}
}
}
}
if (ItemCode == CoFranceTags::VZ) {
if (!RadarTarget.IsValid())
return;
string VerticalRate = "00";
CRadarTargetPositionData pos = RadarTarget.GetPosition();
CRadarTargetPositionData oldpos = RadarTarget.GetPreviousPosition(pos);
int mathVerticalRate = 0;
if (pos.IsValid() && oldpos.IsValid()) {
int deltaalt = pos.GetFlightLevel() - oldpos.GetFlightLevel();
int deltaT = oldpos.GetReceivedTime() - pos.GetReceivedTime();
if (deltaT > 0) {
float vz = abs(deltaalt) * (60.0f / deltaT);
mathVerticalRate = (int)vz;
// If the rate is too much
if ((int)abs(vz) >= 9999) {
VerticalRate = "++";
if (deltaalt < 0)
VerticalRate = "--";
}
else if (abs(vz) >= 100 && abs(deltaalt) >= 20) {
string rate = padWithZeros(2, (int)abs(vz / 100));
VerticalRate = "+" + rate;
if (deltaalt < 0)
VerticalRate = "-" + rate;
}
}
}
strcpy_s(sItemString, 16, VerticalRate.c_str());
}
if (ItemCode == CoFranceTags::COPXN_POINT_REDUCED) {
if (!FlightPlan.IsValid())
return;
string copx = "";
if (FlightPlan.GetTrackingControllerIsMe()) {
if (strlen(FlightPlan.GetExitCoordinationPointName()) > 0) {
copx = FlightPlan.GetExitCoordinationPointName();
*pColorCode = GetCoordinationTagColour(FlightPlan.GetExitCoordinationNameState());
}
}
else {
if (strlen(FlightPlan.GetEntryCoordinationPointName()) > 0) {
copx = FlightPlan.GetEntryCoordinationPointName();
*pColorCode = GetCoordinationTagColour(FlightPlan.GetEntryCoordinationPointState());
}
}
if (string(FlightPlan.GetControllerAssignedData().GetDirectToPointName()) == copx) {\
// If direct to COPX has been given, no need to display it
copx = "";
}
strcpy_s(sItemString, 16, copx.substr(0, 15).c_str());
}
if (ItemCode == CoFranceTags::COPXN_ALT_REDUCED || ItemCode == CoFranceTags::COPXN_ALT_FULL) {
if (!FlightPlan.IsValid())
return;
string copx_alt = "";
if (FlightPlan.GetTrackingControllerIsMe()) {
if (FlightPlan.GetExitCoordinationAltitude() > 0) {
copx_alt = string("x") + padWithZeros(2, FlightPlan.GetExitCoordinationAltitude() / 1000);
*pColorCode = GetCoordinationTagColour(FlightPlan.GetExitCoordinationAltitudeState());
}
}
else if (FlightPlan.GetEntryCoordinationAltitude() > 0) {
copx_alt = string("e") + padWithZeros(2, FlightPlan.GetEntryCoordinationAltitude() / 1000);
*pColorCode = GetCoordinationTagColour(FlightPlan.GetEntryCoordinationAltitudeState());
}
if (ItemCode == CoFranceTags::COPXN_ALT_FULL && copx_alt.size() == 0) {
if (FlightPlan.GetTrackingControllerIsMe())
copx_alt = "x...";
else
copx_alt = "e...";
}
strcpy_s(sItemString, 16, copx_alt.substr(0, 15).c_str());
}
if (ItemCode == CoFranceTags::STCA) {
if (Stca->IsSTCA(RadarTarget.GetCallsign())) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "sep_warning");
if (Blink)
element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "stca_warning");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, "STCA");
}
else {
strcpy_s(sItemString, 16, "");
}
}
if (ItemCode == CoFranceTags::OCL_FLAG) {
if (!FlightPlan.IsValid())
return;
string test = FlightPlan.GetFlightPlanData().GetRoute();
const char* destination = FlightPlan.GetFlightPlanData().GetDestination();
// if is OCL revelant
if (StringContainsArray(test, Brest_Oceanic_Points)) {
// Display OCL flag
if (HasOCL(FlightPlan.GetCallsign())) {
// Check if level change required
int ocl_level = GetOCLLevel(FlightPlan.GetCallsign());
int cfl = FlightPlan.GetControllerAssignedData().GetClearedAltitude();
if (cfl == 0)
cfl = FlightPlan.GetControllerAssignedData().GetFinalAltitude();
if (cfl != ocl_level && ocl_level != 0) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_departure");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
string item = "LCHG";
item += std::to_string(ocl_level / 1000);
strcpy_s(sItemString, 16, item.c_str());
}
}
// If there is no OCL and exit of sector is within 45mins and the flight is headed to the Americas (ICAOs starting with KCPSTMN, and SPEM) we display an alert
else if (startsWith("K", destination) || startsWith("C", destination) ||
startsWith("P", destination) || startsWith("T", destination) ||
startsWith("S", destination) || startsWith("M", destination) ||
startsWith("N", destination) || startsWith("LFVP", destination) || startsWith("LFVM", destination)) {
int minutes = 99;
for (int i = FlightPlan.GetExtractedRoute().GetPointsCalculatedIndex(); i < FlightPlan.GetExtractedRoute().GetPointsNumber(); i++) {
if (StringContainsArray(FlightPlan.GetExtractedRoute().GetPointName(i), Brest_Oceanic_Points)) {
minutes = FlightPlan.GetExtractedRoute().GetPointDistanceInMinutes(i);
break;
}
}
if (minutes <= 30) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_departure");
if (minutes < 15)
element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "sep_warning");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, "OCL");
}
}
}
else {
strcpy_s(sItemString, 16, "");
}
}
if (ItemCode == CoFranceTags::CPDLC_STATUS) {
if (!FlightPlan.IsValid())
return;
if (CPDLCStatusTagMap.find(FlightPlan.GetCallsign()) != CPDLCStatusTagMap.end())
{
// Status is response pending
if (CPDLCStatusTagMap[FlightPlan.GetCallsign()] == 1) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_departure");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
}
// Status is response negative
if (CPDLCStatusTagMap[FlightPlan.GetCallsign()] == 2) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "conflict_group_losange");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
}
strcpy_s(sItemString, 16, CoFranceCharacters::DatalinkIndicator.c_str());
}
else {
strcpy_s(sItemString, 16, "");
}
}
if (ItemCode == CoFranceTags::STAND) {
if (!FlightPlan.IsValid())
return;
string Stand = FlightPlan.GetControllerAssignedData().GetFlightStripAnnotation(CoFranceTags::ANNOTATION_STAND);
strcpy_s(sItemString, 16, Stand.c_str());
}
}
void CoFrancePlugIn::OnTimer(int Counter)
{
for (auto it = PendingStands.begin(), next_it = it; it != PendingStands.end(); it = next_it)
{
bool must_delete = false;
if (it->second.valid() && it->second.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
string stand = it->second.get();
FlightPlanSelect(it->first.c_str()).GetControllerAssignedData().SetFlightStripAnnotation(CoFranceTags::ANNOTATION_STAND, stand.c_str());
if (AssignedStandTime.find(it->first.c_str()) != AssignedStandTime.end()) {
AssignedStandTime[it->first.c_str()] = std::chrono::system_clock::now();
}
else {
AssignedStandTime.insert(make_pair(it->first.c_str(), std::chrono::system_clock::now()));
}
if (Debug) {
DisplayUserMessage("CoFrance", "Stand", string("Recieved stand " + stand + " for " + it->first.c_str()).c_str(), true, false, false, false, false);
}
must_delete = true;
}
++next_it;
if (must_delete)
{
PendingStands.erase(it);
}
}
if (CPDLCAPiData.valid() && CPDLCAPiData.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
string d = CPDLCAPiData.get();
CPDLCStatusTagMap.clear();
std::vector<std::string> row = split(d, '|');
for (auto r : row) {
std::vector<std::string> column = split(r, ',');
if (column.size() >= 2) {
try {
CPDLCStatusTagMap.insert(make_pair(column[0], stoi(column[1])));
}
catch (const std::exception& exc) {
}
}
}
}
if (RawOCLData.valid() && RawOCLData.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
string d = RawOCLData.get();
try {
SharedData::OCLData = nlohmann::json::parse(d);
}
catch (std::exception &exc) {
}
}
Blink = !Blink;
// STCA gets refreshed every 3 seconds
if (Counter % 3 == 0 && !performanceMode)
Stca->OnRefresh(this);
// Every 5 seconds send CPDLC data and poll OCL data
if (Counter % 5 == 0) {
if (ControllerMyself().IsValid() && ControllerMyself().IsController()) {
string message = "";
for (CFlightPlan fp = FlightPlanSelectFirst(); fp.IsValid(); fp = FlightPlanSelectNext(fp)) {
if (fp.GetState() == EuroScopePlugIn::FLIGHT_PLAN_STATE_NON_CONCERNED)
continue;
message += fp.GetCallsign();
message += ",";
message += fp.GetTrackingControllerIsMe() ? "1" : "0";
message += ",";
message += fp.GetFlightPlanData().GetOrigin();
message += ",";
message += fp.GetFlightPlanData().GetDestination();
message += ",";
for (int k = fp.GetExtractedRoute().GetPointsCalculatedIndex(); k < fp.GetExtractedRoute().GetPointsNumber(); k++) {
message += fp.GetExtractedRoute().GetPointName(k);
if (k+1 != fp.GetExtractedRoute().GetPointsNumber())
message += "-";
}
message += ",";
CController NextController = ControllerSelect(fp.GetCoordinatedNextController());
if (NextController.IsValid()) {
message += std::to_string(NextController.GetPrimaryFrequency());
message += ",";
message += NextController.GetCallsign();
message += ",";
}
else {
message += ",";
message += ",";
}
message += "|";
}
CPDLCAPiData = async(&CoFrancePlugIn::SendCPDLCActiveAircrafts, this, string(ControllerMyself().GetCallsign()), message);
//
// Polling OCL
//
if (SharedData::OCLEnabled) {
RawOCLData = async(&CoFrancePlugIn::LoadOCLData, this);
}
}
}
}
void CoFrancePlugIn::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area)
{
if (FunctionId == CoFranceTags::FUNCTION_CONFLICT_POPUP) {
SetASELAircraft(FlightPlanSelect(sItemString));
OpenPopupList(Area, "Conflict Group", 1);
AddPopupListElement(CoFranceCharacters::Moon.c_str(), "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP);
AddPopupListElement(CoFranceCharacters::Star.c_str(), "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP);
AddPopupListElement(CoFranceCharacters::Losange.c_str(), "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP);
AddPopupListElement("Remove", "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP, false, 2, false, true);
}
if (FunctionId == CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP) {
if (ConflictGroups.find(FlightPlanSelectASEL().GetCallsign()) != ConflictGroups.end() && strcmp(sItemString, "Remove") == 0)
ConflictGroups.erase(FlightPlanSelectASEL().GetCallsign());
else if (strcmp(sItemString, "Remove") != 0)
ConflictGroups[FlightPlanSelectASEL().GetCallsign()] = sItemString;
}
if (FunctionId == CoFranceTags::FUNCTION_OCL_TP) {
CFlightPlan fp = FlightPlanSelectASEL();
auto t = fp.GetCallsign();
if (!fp.IsValid())
return;
SharedData::OCL_Tooltip_timer = std::chrono::system_clock::now();
if (HasOCL(fp.GetCallsign())) {
SharedData::OCL_Tooltip_string = GetFullOCL(fp.GetCallsign());
SharedData::OCL_Tooltip_pt = Pt;
}
}
if (FunctionId == CoFranceTags::FUNCTION_STAND_MENU) {
OpenPopupList(Area, "Stand", 1);
AddPopupListElement("Clear", "", CoFranceTags::FUNCTION_STAND_CLEAR, false, POPUP_ELEMENT_NO_CHECKBOX, false);
}
if (FunctionId == CoFranceTags::FUNCTION_STAND_CLEAR) {
FlightPlanSelectASEL().GetControllerAssignedData().SetFlightStripAnnotation(CoFranceTags::ANNOTATION_STAND, "");
}
}
void CoFrancePlugIn::OnFlightPlanControllerAssignedDataUpdate(CFlightPlan FlightPlan, int DataType)
{
// Send CPDLC events
if (!FlightPlan.IsValid() || !FlightPlan.GetTrackingControllerIsMe())
return;
// FlightPlan is CPDLC enabled
if (CPDLCStatusTagMap.find(FlightPlan.GetCallsign()) == CPDLCStatusTagMap.end())
return;
string message = "";
if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_TEMPORARY_ALTITUDE && FlightPlan.GetControllerAssignedData().GetClearedAltitude() >= 100)
message = std::to_string(FlightPlan.GetControllerAssignedData().GetClearedAltitude() / 100);
if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_DIRECT_TO)
message = FlightPlan.GetControllerAssignedData().GetDirectToPointName();
if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_HEADING && FlightPlan.GetControllerAssignedData().GetAssignedHeading() != 0)
message = std::to_string(FlightPlan.GetControllerAssignedData().GetAssignedHeading());
if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_SQUAWK)
message = FlightPlan.GetControllerAssignedData().GetSquawk();
if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_SPEED)
message = std::to_string(FlightPlan.GetControllerAssignedData().GetAssignedSpeed());
if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_MACH)
message = std::to_string(FlightPlan.GetControllerAssignedData().GetAssignedMach());
// Send out the event
async(&CoFrancePlugIn::SendCPDLCEvent, this, string(FlightPlan.GetCallsign()), DataType, message);
}
void CoFrancePlugIn::OnRadarTargetPositionUpdate(CRadarTarget RadarTarget)
{
if (StandAssignerEnabled) {
CFlightPlan CorrFp = RadarTarget.GetCorrelatedFlightPlan();
bool toRefresh = false;
if (!CorrFp.IsValid() || !ControllerMyself().IsController())
return;
string stand = string(CorrFp.GetControllerAssignedData().GetFlightStripAnnotation(CoFranceTags::ANNOTATION_STAND));
// Check if we need to refresh the previouly assigned stand
if (AssignedStandTime.find(string(CorrFp.GetCallsign())) != AssignedStandTime.end()) {
std::chrono::duration<double> elapsed_seconds = std::chrono::system_clock::now() - AssignedStandTime[string(CorrFp.GetCallsign())];
if (elapsed_seconds.count() > StandAssignmentRefresh) {
toRefresh = true;
}
}
// There is already an assigned stand
if (!stand.empty() && !toRefresh)
return;
if (std::find(StandApiAvailableFor.begin(), StandApiAvailableFor.end(), string(CorrFp.GetFlightPlanData().GetDestination())) != StandApiAvailableFor.end()) {
if (CorrFp.GetDistanceToDestination() < 10) {
if (PendingStands.find(string(CorrFp.GetCallsign())) == PendingStands.end()) {
if (Debug) {
DisplayUserMessage("CoFrance", "Stand", string("Requesting stand for " + string(CorrFp.GetCallsign())).c_str(), true, false, false, false, false);
}
PendingStands.insert(std::make_pair(string(CorrFp.GetCallsign()),
async(&CoFrancePlugIn::LoadRemoteStandAssignment, this, string(CorrFp.GetCallsign()), string(CorrFp.GetFlightPlanData().GetOrigin()),
string(CorrFp.GetFlightPlanData().GetDestination()),
string(string("") + CorrFp.GetFlightPlanData().GetAircraftWtc()))));
}
}
}
}
}
void CoFrancePlugIn::OnFlightPlanDisconnect(CFlightPlan FlightPlan)
{
auto it = AssignedStandTime.find(string(FlightPlan.GetCallsign()));
if (it != AssignedStandTime.end()) {
AssignedStandTime.erase(it);
}
}
void CoFrancePlugIn::LoadConfigFile(bool fromWeb)
{
DisplayUserMessage("Message", "CoFrance PlugIn", "Reading config file...", false, false, false, false, false);
try {
if (fromWeb) {
httplib::Client cli(CONFIG_ONLINE_URL_BASE);
if (auto res = cli.Get(CONFIG_ONLINE_URL_PATH)) {
if (res->status == 200) {
std::istringstream is(res->body, std::ios_base::binary | std::ios_base::in);
CoFranceConfig = toml::parse(is, "std::string");
}
else
fromWeb = false;
}
else
fromWeb = false;
cli.stop();
if (!fromWeb)
DisplayUserMessage("Message", "CoFrance PlugIn", "Error loading web config, reverting to local file!", false, false, false, false, false);
}
if (!fromWeb)
CoFranceConfig = toml::parse(DllPath + "\\CoFrance.toml");
CanLoadRadarScreen = true;
DisplayUserMessage("Message", "CoFrance PlugIn", "Config file loaded!", false, false, false, false, false);
}
catch (const std::exception& exc) {
CanLoadRadarScreen = false;
DisplayUserMessage("Message", "CoFrance PlugIn", string("Error reading config file " + string(exc.what())).c_str(), false, false, false, false, false);
}
DisplayUserMessage("Message", "CoFrance PlugIn", "Reading stand API config...", false, false, false, false, false);
try {
if (fromWeb) {
httplib::Client cli(API_URL_BASE);
if (auto res = cli.Get(CONFIG_ONLINE_STAND_API_URL_PATH)) {
if (res->status == 200) {
std::istringstream is(res->body, std::ios_base::binary | std::ios_base::in);
toml::value StandApiConfig = toml::parse(is, "std::string");
StandApiAvailableFor = toml::find<vector<string>>(StandApiConfig, "data", "icaos");
DisplayUserMessage("Message", "CoFrance PlugIn", string("Stand API available for: " + join_vector(StandApiAvailableFor)).c_str(), false, false, false, false, false);
}
}
cli.stop();
}
}
catch (const std::exception& exc) {
DisplayUserMessage("Message", "CoFrance PlugIn", string("Error reading stand api file " + string(exc.what())).c_str(), false, false, false, false, false);
}
}
string CoFrancePlugIn::SendCPDLCActiveAircrafts(string my_callsign, string message)
{
string r = "null";
try {
httplib::Client cli("http://127.0.0.1:9596");
cli.set_connection_timeout(0, 500000);
httplib::Params params;
params.emplace("my_callsign", my_callsign);
params.emplace("data", message);
if (auto res = cli.Post("/api/ping", params)) {
if (res->status == 200) {
cli.stop();
return res->body;
}
else {
r = "null";
}
}
cli.stop();
}
catch (const std::exception& exc) {
}
return r;
}
string CoFrancePlugIn::SendCPDLCEvent(string ac_callsign, int event_type, string value)
{
try {
httplib::Client cli("http://127.0.0.1:9596");
cli.set_connection_timeout(0, 500000);
httplib::Params params;
params.emplace("callsign", ac_callsign);
params.emplace("event", std::to_string(event_type));
params.emplace("value", value);
if (auto res = cli.Post("/api/event", params)) {
if (res->status == 200) {
cli.stop();
return "ok";
}
}
cli.stop();
}
catch (const std::exception& exc) {
}
return "null";
}
string CoFrancePlugIn::LoadRemoteStandAssignment(string callsign, string origin, string destination, string wtc)
{
try {
httplib::Client cli(API_URL_BASE);
httplib::Params params;
params.emplace("callsign", callsign);
params.emplace("dep", origin);
params.emplace("arr", destination);
params.emplace("wtc", wtc);
if (auto res = cli.Post(CONFIG_ONLINE_STAND_API_QUERY_URL_PATH, params)) {
if (res->status == 200) {
std::istringstream is(res->body, std::ios_base::binary | std::ios_base::in);
toml::value StandData = toml::parse(is, "std::string");
cli.stop();
return toml::find<string>(StandData, "data", "stand");
}
else {
cli.stop();
return "NoGate";
}
}
cli.stop();
}
catch (const std::exception& exc) {
}
return "NoGate";
}
string CoFrancePlugIn::LoadOCLData()
{
try {
httplib::Client cli("https://nattrak.vatsim.net");
cli.set_connection_timeout(0, 500000);
if (auto res = cli.Get("/api/plugins")) {
if (res->status == 200) {
cli.stop();
return res->body;
}
else {
cli.stop();
return "[]";
}
}
cli.stop();
}
catch (const std::exception& exc) {
return "[]";
}
return "[]";
//return "[ { \"callsign\": \"BER1PE\", \"status\": \"CLEARED\", \"nat\": \"A\", \"fix\": \"MALOT\", \"level\": \"320\", \"mach\": \"0.89\", \"estimating_time\": \"1921\", \"clearance_issued\": \"2021-03-26 00:21:19\", \"extra_info\": \"CROSS MALOT NOT BEFORE 1925\" }, { \"callsign\":\"ADB3908\", \"status\":\"PENDING\", \"nat\":\"RR\", \"fix\":\"PORTI\", \"level\": \"350\", \"mach\": \"0.82\", \"estimating_time\":\"18:41\", \"clearance_issued\":null, \"extra_info\":null } ]";
}