-
Notifications
You must be signed in to change notification settings - Fork 25
/
DataRefs.cpp
2777 lines (2445 loc) · 113 KB
/
DataRefs.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
/// @file DataRefs.cpp
/// @brief Access to global data like dataRefs, `doc8643` and `model_typecode` files.
/// @details Implements classes Doc8643, DataRefs, and read access to `model_typecode` file.\n
/// There is exactly one instance of DataRefs, which is the global variable `dataRefs`,
/// in which all globally relevant values are stored, beyond just XP's dataRefs:\n
/// - LiveTraffic's configuration options including reading/writing of the config file\n
/// - readable callbacks for other plugins' access to LiveTraffic's data
/// - LTAPI interface
/// @author Birger Hoppe
/// @copyright (c) 2018-2020 Birger Hoppe
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:\n
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.\n
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
#include "LiveTraffic.h"
#include <fstream>
#include <errno.h>
constexpr int DEFAULT_MODES_ID = 0xFFFF00; ///< used if no modeS id is available for user aircraft while exporting data
//
//MARK: external references
//
// return color into a RGB array as XP likes it
void conv_color (int inCol, float outColor[4])
{
outColor[0] = float((inCol & 0xFF0000) >> 16) / 255.0f; // red
outColor[1] = float((inCol & 0x00FF00) >> 8) / 255.0f; // green
outColor[2] = float((inCol & 0x0000FF) ) / 255.0f; // blue
outColor[3] = 1.0f;
}
//
// MARK: Doc8643
//
// global map, which stores the content of the doc8643 file
std::map<std::string, Doc8643> mapDoc8643;
const Doc8643 DOC8643_EMPTY; // objet returned if Doc8643::get fails
// constructor setting all elements
Doc8643::Doc8643 (std::string&& _manufacturer,
std::string&& _model,
std::string&& _typeDesignator,
std::string&& _classification,
std::string&& _wtc) :
manufacturer (std::move(_manufacturer)),
model (std::move(_model)),
typeDesignator (std::move(_typeDesignator)),
classification (std::move(_classification)),
wtc (std::move(_wtc))
{}
// return the string for FlightModel matching
Doc8643::operator std::string() const
{
return wtc + ';' + classification + ';' + typeDesignator + ';' +
model + ';' + manufacturer;
}
//
// Static functions
//
// reads the Doc8643 file into mapDoc8643
bool Doc8643::ReadDoc8643File ()
{
// clear the map, just in case
mapDoc8643.clear();
// Put together path to Doc8643.txt
std::string path (LTCalcFullPluginPath(PATH_DOC8643_TXT));
// open the file for reading
std::ifstream fIn (path);
if (!fIn) {
// if there is no config file output a warning (we can use defaults)
char sErr[SERR_LEN];
strerror_s(sErr, sizeof(sErr), errno);
SHOW_MSG(logERR, ERR_CFG_FILE_OPEN_IN,
path.c_str(), sErr);
return false;
}
// regular expression to extract individual values, separated by TABs
enum { DOC_MANU=1, DOC_MODEL, DOC_TYPE, DOC_CLASS, DOC_WTC, DOC_EXPECTED };
const std::regex re("^([^\\t]+)\\t" // manufacturer
"([^\\t]+)\\t" // model
"([[:alnum:]]{2,4})\\t" // type designator
"(-|[AGHLST][C1-8][EJPRT])\\t" // classification
"(-|[HLMJ]|L/M)"); // wtc
// loop over lines of the file
std::string text;
int errCnt = 0;
for (int ln=1; fIn && errCnt <= ERR_CFG_FILE_MAXWARN; ln++) {
// read entire line
safeGetline(fIn, text);
if (text.empty()) // skip empty lines silently
continue;
// apply the regex to extract values
std::smatch m;
std::regex_search(text, m, re);
// add to map (if matched)
if (m.size() == DOC_EXPECTED) {
mapDoc8643.emplace(m[DOC_TYPE],
Doc8643(m[DOC_MANU],
m[DOC_MODEL],
m[DOC_TYPE],
m[DOC_CLASS],
m[DOC_WTC]));
} else if (fIn) {
// I/O was good, but line didn't match
SHOW_MSG(logWARN, ERR_CFG_LINE_READ,
path.c_str(), ln, text.c_str());
errCnt++;
} else if (!fIn && !fIn.eof()) {
// I/O error
char sErr[SERR_LEN];
strerror_s(sErr, sizeof(sErr), errno);
SHOW_MSG(logWARN, ERR_CFG_LINE_READ,
path.c_str(), ln, sErr);
errCnt++;
}
}
// close file
fIn.close();
// too many warnings?
if (errCnt > ERR_CFG_FILE_MAXWARN) {
SHOW_MSG(logERR, ERR_CFG_FILE_READ,
path.c_str(), ERR_CFG_FILE_TOOMANY);
return false;
}
// looks like success
return true;
}
// return the matching Doc8643 object from the global map
const Doc8643& Doc8643::get (const std::string& _type)
try
{
return mapDoc8643.at(_type);
}
catch (...)
{
return DOC8643_EMPTY;
}
//
// MARK: ModelIcaoType
//
namespace ModelIcaoType
{
/// Map, which stores the content of the model_typecode.txt file:
/// human-readable model text maps to ICAO type cide
std::map<std::string, std::string> mapModelIcaoType;
/// global empty string returned if nothing is found in map
const std::string gEmptyString;
// Read the `model_typecode.txt` file
bool ReadFile ()
{
// clear the map
mapModelIcaoType.clear();
// Put together path to model_typecode.txt
std::string path (LTCalcFullPluginPath(PATH_MODEL_TYPECODE_TXT));
// open the file for reading
std::ifstream fIn (path);
if (!fIn) {
// if there is no config file output a warning, but otherwise no worries
char sErr[SERR_LEN];
strerror_s(sErr, sizeof(sErr), errno);
SHOW_MSG(logERR, ERR_CFG_FILE_OPEN_IN,
path.c_str(), sErr);
return false;
}
// loop over lines of the file
std::string text;
int errCnt = 0;
for (int ln=1; fIn && errCnt <= ERR_CFG_FILE_MAXWARN; ln++) {
// read entire line
safeGetline(fIn, text);
if (text.empty()) // skip empty lines silently
continue;
// ignore the first line, if it is just the column header
if (ln == 1 && text == "MODEL|TYPECODE")
continue;
// Elements model and type code are separate by pipe.
// Find the last pipe in line (just in case there happens to a pipe in the model name, which is the first field)
const std::string::size_type pos = text.rfind('|');
// not found a pipe?
if (pos == std::string::npos ||
// pipe is first or last character? not good either as either string would be empty then
pos == 0 || pos == text.size()-1) {
// I/O was good, but line has wrong format
SHOW_MSG(logWARN, ERR_CFG_LINE_READ,
path.c_str(), ln, text.c_str());
errCnt++;
}
// everything to the left is mode text
std::string mdl = text.substr(0,pos);
str_toupper(trim(mdl));
// everything to the right is type code, which should exist
// (but if not we use it anyway...)
std::string type = text.substr(pos+1);
str_toupper(trim(type));
#if TEST_MODEL_TYPE_CODES
// quite many invalid codes are in the file, which originates
// in the OpenSky aircraft database...we don't warn about all of them
if (Doc8643::get(type) == DOC8643_EMPTY) {
LOG_MSG(logWARN, ERR_CFG_TYPE_INVALID,
path.c_str(), ln,
type.c_str());
}
#endif
// and just move it to the map:
mapModelIcaoType.emplace(std::move(mdl),
std::move(type));
}
// close file
fIn.close();
// too many warnings?
if (errCnt > ERR_CFG_FILE_MAXWARN) {
SHOW_MSG(logERR, ERR_CFG_FILE_READ,
path.c_str(), ERR_CFG_FILE_TOOMANY);
return false;
}
// looks like success
return true;
}
// Lookup ICAO type designator for human-readable model text, empty if nothing found
const std::string& getIcaoType (const std::string& _model)
{
try {
// lookup a value on the map, throws std::out_of_range if nothing found
return mapModelIcaoType.at(str_toupper_c(_model));
}
catch (...) {
// caught exception -> nothing found in map, return something empty
return gEmptyString;
}
}
}
//
// MARK: WndRect
//
// Write WndRect into config file ("left,top,right.bottom")
std::ostream& operator<< (std::ostream& _stream, const WndRect& _r)
{
return _stream << _r.left() << ',' << _r.top() << ',' << _r.right() << ',' << _r.bottom();
}
// Set from config file string ("left,top,right.bottom")
void WndRect::set (const std::string& _s)
{
std::vector<std::string> tok = str_tokenize(_s, ",");
if (tok.size() == 4) {
left() = std::stoi(tok[0]);
top() = std::stoi(tok[1]);
right() = std::stoi(tok[2]);
bottom() = std::stoi(tok[3]);
} else {
LOG_MSG(logERR, "Window pos expects 4 numbers but got: %s", _s.c_str());
}
}
// Make sure the window is on the visible screen
bool WndRect::keepOnScreen ()
{
bool bChanged = false;
WndRect screen;
XPLMGetScreenBoundsGlobal(&screen.left(), &screen.top(),
&screen.right(), &screen.bottom());
if (right() > screen.right()) {
shift(screen.right() - right(), 0);
bChanged = true;
}
if (left() < screen.left()) {
shift(screen.left() - left(), 0);
bChanged = true;
}
if (bottom() < screen.bottom()) {
shift(0, screen.bottom() - bottom());
bChanged = true;
}
if (top() > screen.top() - WIN_FROM_TOP) {
shift(0, screen.top() - WIN_FROM_TOP - top());
bChanged = true;
}
// Did we change any value?
return bChanged;
}
//MARK: X-Plane Datarefs
const char* DATA_REFS_XP[] = {
"sim/network/misc/network_time_sec", // float n seconds The current elapsed time synched across the network (used as timestamp in Log.txt)
"sim/time/local_time_sec",
"sim/time/local_date_days",
"sim/time/use_system_time",
"sim/time/zulu_time_sec",
"sim/operation/prefs/replay_mode", // int y enum Are we in replay mode?
"sim/graphics/view/view_is_external",
"sim/graphics/view/view_type",
"sim/graphics/view/using_modern_driver", // boolean: Vulkan/Metal in use? (since XP11.50)
"sim/multiplayer/camera/tcas_idx", // Shared data refs filled by LiveTraffic with aircraft under camera
"sim/multiplayer/camera/modeS_id", // Shared data refs filled by LiveTraffic with aircraft under camera
"sim/flightmodel/position/latitude",
"sim/flightmodel/position/longitude",
"sim/flightmodel/position/elevation",
"sim/flightmodel/position/y_agl", // [m] height above ground
"sim/flightmodel/position/true_theta", // pitch
"sim/flightmodel/position/true_phi", // roll
"sim/flightmodel/position/true_psi", // true heading
"sim/flightmodel/position/mag_psi", // magnetic heading
"sim/flightmodel/position/hpath", // track
"sim/flightmodel/position/indicated_airspeed", // KIAS (apparently really in knots)
"sim/flightmodel/position/true_airspeed", // TAS
"sim/flightmodel/position/groundspeed", // GS
"sim/flightmodel/position/vh_ind", // float n meters/second VVI (vertical velocity in meters per second)"
"sim/flightmodel/failures/onground_any",
"sim/aircraft/view/acf_tailnum", // byte[40] y string Tail number
"sim/aircraft/view/acf_modeS_id", // int y integer 24bit (0-16777215 or 0-0xFFFFFF) unique ID of the airframe. This is also known as the ADS-B "hexcode".
"sim/aircraft/view/acf_ICAO", // byte[40] y string ICAO code for aircraft (a string) entered by author
"sim/graphics/VR/enabled",
};
static_assert(sizeof(DATA_REFS_XP) / sizeof(DATA_REFS_XP[0]) == CNT_DATAREFS_XP,
"dataRefsXP and DATA_REFS_XP[] differ in number of elements");
//MARK: X-Plane Command Refs
const char* CMD_REFS_XP[] = {
"sim/general/left",
"sim/general/right",
"sim/general/left_fast",
"sim/general/right_fast",
"sim/general/forward",
"sim/general/backward",
"sim/general/forward_fast",
"sim/general/backward_fast",
"sim/general/hat_switch_left",
"sim/general/hat_switch_right",
"sim/general/hat_switch_up",
"sim/general/hat_switch_down",
"sim/general/hat_switch_up_left",
"sim/general/hat_switch_up_right",
"sim/general/hat_switch_down_left",
"sim/general/hat_switch_down_right",
"sim/general/up",
"sim/general/down",
"sim/general/up_fast",
"sim/general/down_fast",
"sim/general/rot_left",
"sim/general/rot_right",
"sim/general/rot_left_fast",
"sim/general/rot_right_fast",
"sim/general/rot_up",
"sim/general/rot_down",
"sim/general/rot_up_fast",
"sim/general/rot_down_fast",
"sim/general/zoom_in",
"sim/general/zoom_out",
"sim/general/zoom_in_fast",
"sim/general/zoom_out_fast",
"sim/view/free_camera",
"sim/view/forward_with_2d_panel",
"sim/view/forward_with_hud",
"sim/view/forward_with_nothing",
"sim/view/linear_spot",
"sim/view/still_spot",
"sim/view/runway",
"sim/view/circle",
"sim/view/tower",
"sim/view/ridealong",
"sim/view/track_weapon",
"sim/view/chase",
"sim/view/3d_cockpit_cmnd_look",
};
static_assert(sizeof(CMD_REFS_XP) / sizeof(CMD_REFS_XP[0]) == CNT_CMDREFS_XP,
"cmdRefsXP and CMD_REFS_XP[] differ in number of elements");
// For informing dataRe Editor and tool see
// http://www.xsquawkbox.net/xpsdk/mediawiki/DataRefEditor and
// https://github.com/leecbaker/datareftool/blob/master/src/plugin_custom_dataref.cpp
// DataRef editors, which we inform about our dataRefs
#define MSG_ADD_DATAREF 0x01000000
const char* DATA_REF_EDITORS[] = {
"xplanesdk.examples.DataRefEditor",
"com.leecbaker.datareftool"
};
/// Map view types to view commands
struct mapViewTypesTy {
XPViewTypes e = VIEW_UNKNOWN; ///< enum value
cmdRefsXP cr = CR_NO_COMMAND; ///< command ref enum value
};
mapViewTypesTy MAP_VIEW_TYPES[] = {
{ VIEW_FWD_2D, CR_VIEW_FWD_2D },
{ VIEW_EXT_TOWER, CR_VIEW_EXT_TOWER },
{ VIEW_EXT_RNWY, CR_VIEW_EXT_RNWY },
{ VIEW_EXT_CHASE, CR_VIEW_EXT_CHASE },
{ VIEW_EXT_CIRCLE, CR_VIEW_EXT_CIRCLE },
{ VIEW_EXT_STILL, CR_VIEW_EXT_STILL },
{ VIEW_EXT_LINEAR, CR_VIEW_EXT_LINEAR },
{ VIEW_FWD_HUD, CR_VIEW_FWD_HUD },
{ VIEW_FWD_NODISP, CR_VIEW_FWD_NODISP },
{ VIEW_FWD_3D, CR_VIEW_FWD_3D },
{ VIEW_FREE_CAM, CR_VIEW_FREE_CAM },
{ VIEW_EXT_RIDE, CR_VIEW_EXT_RIDE },
};
//
//MARK: DataRefs::dataRefDefinitionT
//
// constant used in dataRefDefinitionT::refCon but denoting to query the address of the respective variable
void* GET_VAR = reinterpret_cast<void*>(INT_MIN);
// list of all datRef definitions offered by LiveTraffic:
DataRefs::dataRefDefinitionT DATA_REFS_LT[CNT_DATAREFS_LT] = {
// a/c information
{"livetraffic/ac/key", DataRefs::LTGetAcInfoI, DataRefs::LTSetAcKey, (void*)DR_AC_KEY, false },
{"livetraffic/ac/num", DataRefs::LTGetAcInfoI, NULL, (void*)DR_AC_NUM, false },
{"livetraffic/ac/on_gnd", DataRefs::LTGetAcInfoI, NULL, (void*)DR_AC_ON_GND, false },
{"livetraffic/ac/phase", DataRefs::LTGetAcInfoI, NULL, (void*)DR_AC_PHASE, false },
{"livetraffic/ac/lat", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_LAT, false },
{"livetraffic/ac/lon", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_LON, false },
{"livetraffic/ac/alt", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_ALT, false },
{"livetraffic/ac/heading", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_HEADING, false },
{"livetraffic/ac/roll", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_ROLL, false },
{"livetraffic/ac/pitch", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_PITCH, false },
{"livetraffic/ac/speed", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_SPEED, false },
{"livetraffic/ac/vsi", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_VSI, false },
{"livetraffic/ac/terrain_alt", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_TERRAIN_ALT, false },
{"livetraffic/ac/height", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_HEIGHT, false },
{"livetraffic/ac/flaps", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_FLAPS, false },
{"livetraffic/ac/gear", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_GEAR, false },
{"livetraffic/ac/lights/beacon", DataRefs::LTGetAcInfoI, NULL, (void*)DR_AC_LIGHTS_BEACON, false },
{"livetraffic/ac/lights/strobe", DataRefs::LTGetAcInfoI, NULL, (void*)DR_AC_LIGHTS_STROBE, false },
{"livetraffic/ac/lights/nav", DataRefs::LTGetAcInfoI, NULL, (void*)DR_AC_LIGHTS_NAV, false },
{"livetraffic/ac/lights/landing", DataRefs::LTGetAcInfoI, NULL, (void*)DR_AC_LIGHTS_LANDING, false },
{"livetraffic/ac/bearing", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_BEARING, false },
{"livetraffic/ac/dist", DataRefs::LTGetAcInfoF, NULL, (void*)DR_AC_DIST, false },
{"livetraffic/bulk/quick", DataRefs::LTGetBulkAc, NULL, (void*)DR_AC_BULK_QUICK, false },
{"livetraffic/bulk/expensive", DataRefs::LTGetBulkAc, NULL, (void*)DR_AC_BULK_EXPENSIVE, false },
{"livetraffic/sim/date", DataRefs::LTGetSimDateTime, NULL, (void*)1, false },
{"livetraffic/sim/time", DataRefs::LTGetSimDateTime, NULL, (void*)2, false },
{"livetraffic/ver/nr", GetLTVerNum, NULL, NULL, false },
{"livetraffic/ver/date", GetLTVerDate, NULL, NULL, false },
// UI information
{"livetraffic/ui/opacity", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/ui/font_scale", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/ui/settings/transparent", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/ui/aci/collapsed", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
// configuration options
{"livetraffic/cfg/aircrafts_displayed", DataRefs::LTGetInt, DataRefs::LTSetAircraftDisplayed, GET_VAR, false },
{"livetraffic/cfg/auto_start", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/volume/master", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/sound/force_fmod_instance", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/cfg/ai_on_request", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/ai_controlled", DataRefs::HaveAIUnderControl, NULL, NULL, false },
{"livetraffic/cfg/ai_not_on_gnd", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/labels", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/label_shown", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/label_max_dist", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/label_visibility_cut_off", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/cfg/label_col_dyn", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/label_color", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/log_level", DataRefs::LTGetInt, DataRefs::LTSetLogLevel, GET_VAR, true },
{"livetraffic/cfg/msg_area_level", DataRefs::LTGetInt, DataRefs::LTSetLogLevel, GET_VAR, true },
{"livetraffic/cfg/log_list_len", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/max_num_ac", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_std_distance", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_snap_taxi_dist", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/fd_refresh_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_long_refresh_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_buf_period", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_reduce_height", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/network_timeout", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/lnd_lights_taxi", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/hide_below_agl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/hide_taxiing", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/hide_parking", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/hide_nearby_gnd", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/hide_nearby_air", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/hide_in_replay", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/cfg/hide_static_twr", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/cfg/copy_obj_files", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/contrail_min_alt", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/contrail_max_alt", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/contrail_life_time", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/contrail_multiple", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/cfg/remote_support", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/external_camera_tool", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/cfg/last_check_new_ver", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
// debug options
{"livetraffic/dbg/ac_filter", DataRefs::LTGetInt, DataRefs::LTSetDebugAcFilter, GET_VAR, false },
{"livetraffic/dbg/ac_pos", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/dbg/log_raw_fd", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, false },
{"livetraffic/dbg/model_matching", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/dbg/export_fd", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, false },
{"livetraffic/dbg/export_user_ac", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, false },
{"livetraffic/dbg/export_normalize_ts", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/dbg/export_format", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
// channel configuration options
{"livetraffic/channel/fscharter/environment", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/channel/open_glider/use_requrepl",DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/channel/real_traffic/listen_port",DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/traffic_port",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/weather_port",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/sim_time_ctrl",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/man_toffset",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/connect_type",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/fore_flight/listen_port", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/fore_flight/send_port", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/fore_flight/user_plane", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/channel/fore_flight/traffic", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/channel/fore_flight/interval", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
// channels, in ascending order of priority
{"livetraffic/channel/futuredatachn/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, false },
{"livetraffic/channel/fore_flight/sender", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/synthetic/intern", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/fscharter/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/open_glider/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/adsbhub/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/open_sky/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/open_sky/ac_masterdata", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/open_sky/ac_masterfile", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/adsb_exchange/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
{"livetraffic/channel/real_traffic/online", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true },
};
// returns the actual address of the variable within DataRefs, which stores the value of interest as per dataRef definition
// (called in case dataRefDefinitionT::refCon == GET_VAR)
void* DataRefs::getVarAddr (dataRefsLT dr)
{
switch (dr) {
// UI information
case DR_UI_OPACITY: return &UIopacity;
case DR_UI_FONT_SCALE: return &UIFontScale;
case DR_UI_SETTINGS_TRANSP: return &SUItransp;
case DR_UI_ACI_COLLAPSED: return &ACIcollapsed;
// configuration options
case DR_CFG_AIRCRAFT_DISPLAYED: return &bShowingAircraft;
case DR_CFG_AUTO_START: return &bAutoStart;
case DR_CFG_MASTER_VOLUME: return &volMaster;
case DR_CFG_SND_FORCE_FMOD_INSTANCE:return &sndForceFmodInstance;
case DR_CFG_AI_ON_REQUEST: return &bAIonRequest;
case DR_CFG_AI_NOT_ON_GND: return &bAINotOnGnd;
case DR_CFG_LABELS: return &labelCfg;
case DR_CFG_LABEL_SHOWN: return &labelShown;
case DR_CFG_LABEL_MAX_DIST: return &labelMaxDist;
case DR_CFG_LABEL_VISIBILITY_CUT_OFF: return &bLabelVisibilityCUtOff;
case DR_CFG_LABEL_COL_DYN: return &bLabelColDynamic;
case DR_CFG_LABEL_COLOR: return &labelColor;
case DR_CFG_LOG_LEVEL: return &iLogLevel;
case DR_CFG_MSG_AREA_LEVEL: return &iMsgAreaLevel;
case DR_CFG_LOG_LIST_LEN: return &logListLen;
case DR_CFG_MAX_NUM_AC: return &maxNumAc;
case DR_CFG_FD_STD_DISTANCE: return &fdStdDistance;
case DR_CFG_FD_SNAP_TAXI_DIST: return &fdSnapTaxiDist;
case DR_CFG_FD_REFRESH_INTVL: return &fdRefreshIntvl;
case DR_CFG_FD_LONG_REFRESH_INTVL: return &fdLongRefrIntvl;
case DR_CFG_FD_BUF_PERIOD: return &fdBufPeriod;
case DR_CFG_FD_REDUCE_HEIGHT: return &fdReduceHeight;
case DR_CFG_MAX_NETW_TIMEOUT: return &netwTimeoutMax;
case DR_CFG_LND_LIGHTS_TAXI: return &bLndLightsTaxi;
case DR_CFG_HIDE_BELOW_AGL: return &hideBelowAGL;
case DR_CFG_HIDE_TAXIING: return &hideTaxiing;
case DR_CFG_HIDE_PARKING: return &hideParking;
case DR_CFG_HIDE_NEARBY_GND: return &hideNearbyGnd;
case DR_CFG_HIDE_NEARBY_AIR: return &hideNearbyAir;
case DR_CFG_HIDE_IN_REPLAY: return &hideInReplay;
case DR_CFG_HIDE_STATIC_TWR: return &hideStaticTwr;
case DR_CFG_COPY_OBJ_FILES: return &cpyObjFiles;
case DR_CFG_CONTRAIL_MIN_ALT: return &contrailAltMin_ft;
case DR_CFG_CONTRAIL_MAX_ALT: return &contrailAltMax_ft;
case DR_CFG_CONTRAIL_LIFE_TIME: return &contrailLifeTime;
case DR_CFG_CONTRAIL_MULTIPLE: return &contrailMulti;
case DR_CFG_REMOTE_SUPPORT: return &remoteSupport;
case DR_CFG_EXTERNAL_CAMERA: return &bUseExternalCamera;
case DR_CFG_LAST_CHECK_NEW_VER: return &lastCheckNewVer;
// debug options
case DR_DBG_AC_FILTER: return &uDebugAcFilter;
case DR_DBG_AC_POS: return &bDebugAcPos;
case DR_DBG_LOG_RAW_FD: return &bDebugLogRawFd;
case DR_DBG_MODEL_MATCHING: return &bDebugModelMatching;
case DR_DBG_EXPORT_FD: return &bDebugExportFd;
case DR_DBG_EXPORT_USER_AC: return &bDebugExportUserAc;
case DR_DBG_EXPORT_NORMALIZE_TS: return &bDebugExportNormTS;
case DR_DBG_EXPORT_FORMAT: return &eDebugExportFdFormat;
// channel configuration options
case DR_CFG_FSC_ENV: return &fscEnv;
case DR_CFG_OGN_USE_REQUREPL: return &ognUseRequRepl;
case DR_CFG_RT_LISTEN_PORT: return &rtListenPort;
case DR_CFG_RT_TRAFFIC_PORT: return &rtTrafficPort;
case DR_CFG_RT_WEATHER_PORT: return &rtWeatherPort;
case DR_CFG_RT_SIM_TIME_CTRL: return &rtSTC;
case DR_CFG_RT_MAN_TOFFSET: return &rtManTOfs;
case DR_CFG_RT_CONNECT_TYPE: return &rtConnType;
case DR_CFG_FF_LISTEN_PORT: return &ffListenPort;
case DR_CFG_FF_SEND_PORT: return &ffSendPort;
case DR_CFG_FF_SEND_USER_PLANE: return &bffUserPlane;
case DR_CFG_FF_SEND_TRAFFIC: return &bffTraffic;
case DR_CFG_FF_SEND_TRAFFIC_INTVL: return &ffSendTrfcIntvl;
default:
// flight channels
if (DR_CHANNEL_FIRST <= dr && dr <= DR_CHANNEL_LAST)
return &bChannel[dr-DR_CHANNEL_FIRST];
// else: must not happen
LOG_ASSERT(NULL);
return NULL;
}
}
//MARK: LiveTraffic Command Refs
struct cmdRefDescrTy {
const char* cmdName;
const char* cmdDescr;
} CMD_REFS_LT[] = {
{"LiveTraffic/Info_Staus_Wnd/Open", "Opens/Closes the Information/Status window"},
{"LiveTraffic/Aircraft_Info_Wnd/Open", "Opens an Aircraft Information Window"},
{"LiveTraffic/Aircraft_Info_Wnd/Open_Popped_Out", "Opens a popped out Aircraft Information Window (separate OS-level window)"},
{"LiveTraffic/Aircraft_Info_Wnd/Hide_Show", "Hides/Shows all Aircraft Information Windows, but does not close"},
{"LiveTraffic/Aircraft_Info_Wnd/Close_All", "Closes all Aircraft Information Windows"},
{"LiveTraffic/Aircrafts/Display", "Starts/Stops display of live aircraft"},
{"LiveTraffic/Aircrafts/TCAS_Control", "TCAS Control toggle: Tries to take control over AI aircraft, or release it"},
{"LiveTraffic/Aircrafts/Toggle_Labels", "Toggle display of labels in current view"},
{"LiveTraffic/Aircrafts/Toggle_Ahead", "Toggle visibility of aircraft ahead"},
{"LiveTraffic/Settings/Open", "Opens/Closes the Settings window"},
};
static_assert(sizeof(CMD_REFS_LT) / sizeof(CMD_REFS_LT[0]) == CNT_CMDREFS_LT,
"cmdRefsLT and CMD_REFS_LT[] differ in number of elements");
// MARK: CSLPathCfgTy
DataRefs::CSLPathCfgTy::CSLPathCfgTy (bool b, const std::string& p) :
bEnabled(b), path(LTRemoveXPSystemPath(p))
{}
// tests path for existence
bool DataRefs::CSLPathCfgTy::exists() const
{
if (bPathExists) // stored result available?
return bPathExists > 0; // 1 = "exists"
// need to test the file system
return LTNumFilesInPath(LTCalcFullPath(path)) > 0;
}
// tests path for existence, saves test result
bool DataRefs::CSLPathCfgTy::existsSave()
{
bPathExists = exists();
return bPathExists > 0;
}
// assign new path
const std::string& DataRefs::CSLPathCfgTy::operator= (const std::string& _p)
{
path = LTRemoveXPSystemPath(_p); // store (shortened) path
existsSave(); // check for existence
return path;
}
//MARK: DataRefs Constructor - just plain variable init, no API calls
/// Mutex guarding updates to cached values
static std::recursive_mutex mutexDrUpdate;
/// Flag to ignore this sharedDataref callback
static bool gbIgnoreItsMe = false;
DataRefs::DataRefs ( logLevelTy initLogLevel ) :
iLogLevel (initLogLevel),
#ifdef DEBUG
bDebugAcPos (true),
#endif
MsgRect(0, 0, WIN_WIDTH, 0),
SUIrect (0, 500, 690, 0), // (left=bottom=0 means: initially centered)
ACIrect (0, 530, 320, 0),
ILWrect (0, 400, 965, 0)
{
// override log level in Beta and DEBUG cases
// (config file is read later, that may reduce the level again)
#ifdef DEBUG
iLogLevel = logDEBUG;
#else
if ( LT_BETA_VER_LIMIT )
iLogLevel = logDEBUG;
#endif
// disable all channels
for ( int& i: bChannel )
i = false;
// enable OpenSky, OGN, and Synthetic by default
bChannel[DR_CHANNEL_OPEN_SKY_ONLINE - DR_CHANNEL_FIRST] = true;
bChannel[DR_CHANNEL_OPEN_SKY_AC_MASTERDATA - DR_CHANNEL_FIRST] = true;
bChannel[DR_CHANNEL_OPEN_SKY_AC_MASTERFILE - DR_CHANNEL_FIRST] = true;
bChannel[DR_CHANNEL_OPEN_GLIDER_NET - DR_CHANNEL_FIRST] = true;
bChannel[DR_CHANNEL_SYNTHETIC - DR_CHANNEL_FIRST] = true;
// Clear the dataRefs arrays
memset ( adrXP, 0, sizeof(adrXP));
memset ( adrLT, 0, sizeof(adrLT));
// X-Plane only knows about day in the year, but not the actual year
// so we assume something:
// if LocalDateDays < today's day of year --> current year
// if LocalDateDays >= today's day of year --> previous year
{
std::tm tm;
time_t now = time(nullptr);
localtime_s(&tm, &now);
dataRefs.iTodaysDayOfYear = tm.tm_yday;
// also compute start of this and last year for sim-time computations
tm.tm_sec = tm.tm_min = tm.tm_hour = 0; // 00:00:00h
tm.tm_mday = 1; // 1st of
tm.tm_mon = 0; // January
tm.tm_isdst = 0; // no DST
tStartThisYear = mktime_utc(tm);
// previous year
tm.tm_year--;
tStartPrevYear = mktime_utc(tm);
}
}
// Find and register dataRefs
bool DataRefs::Init ()
{
// XP System Path
char aszPath[512];
XPLMGetSystemPath ( aszPath );
XPSystemPath = aszPath;
// XP Version
XPLMGetVersions(&xpVer, &xplmVer, nullptr);
snprintf(aszPath, sizeof(aszPath), "X-Plane %d.%02d",
xpVer / 1000,
((xpVer) / 10) % 100);
sXpVer = aszPath;
// Directory Separator provided by XP
DirSeparator = XPLMGetDirectorySeparator();
// my own plugin path
pluginID = XPLMGetMyID();
aszPath[0] = 0;
XPLMGetPluginInfo(pluginID, NULL, aszPath, NULL, NULL);
LTPluginPath = aszPath;
LOG_ASSERT(!LTPluginPath.empty());
// LTPluginPath is now something like "...:Resources:plugins:LiveTraffic:64:mac.xpl"
// we now reduce the path to the beginning of the plugin:
// remove the file name
std::string::size_type pos = LTPluginPath.rfind(DirSeparator);
LOG_ASSERT(pos != std::string::npos);
LTPluginPath.erase(pos);
// remove the 64 subdirectory, but leave the separator at the end
pos = LTPluginPath.rfind(DirSeparator);
LOG_ASSERT(pos != std::string::npos);
LTPluginPath.erase(pos+1);
// Create the two shared dataRefs for aircraft under camera
if (!XPLMShareData(DATA_REFS_XP[DR_CAMERA_TCAS_IDX], xplmType_Int, ClearCameraAc, nullptr) ||
!XPLMShareData(DATA_REFS_XP[DR_CAMERA_AC_ID], xplmType_Int, nullptr, nullptr))
{
LOG_MSG(logERR,ERR_SHARED_DATAREF);
}
// Fetch all XP-provided data refs and verify if OK
for ( int i=0; i < CNT_DATAREFS_XP; i++ )
{
if ( (adrXP[i] = XPLMFindDataRef (DATA_REFS_XP[i])) == NULL )
{
// for XP10 compatibility we accept if we don't find a few,
// all else stays an error
if (i != DR_VR_ENABLED &&
i != DR_MODERN_DRIVER &&
i != DR_CAMERA_TCAS_IDX && // don't insist on publishing the a/c under camera
i != DR_CAMERA_AC_ID &&
i != DR_PLANE_MODES_ID) // Came with XP 11.50 only
{
LOG_MSG(logFATAL,ERR_DATAREF_FIND,DATA_REFS_XP[i]);
return false;
}
}
}
// Fetch all XP-provided cmd refs and verify if OK
for (int i = 0; i < CNT_CMDREFS_XP; i++)
{
if ((cmdXP[i] = XPLMFindCommand(CMD_REFS_XP[i])) == NULL)
{
// Not finding a command is not fatal.
// Just be aware that it could come back zero when using.
LOG_MSG(logWARN, ERR_DATAREF_FIND, CMD_REFS_XP[i]);
}
}
// register all LiveTraffic-provided dataRefs and commands
if (!RegisterDataAccessors() || !RegisterCommands())
return false;
// Using a modern graphics driver? (Metal, Vulkan)
bUsingModernDriver = adrXP[DR_MODERN_DRIVER] ? XPLMGetDatai(adrXP[DR_MODERN_DRIVER]) != 0 : false;
// read Doc8643 file (which we could live without)
Doc8643::ReadDoc8643File();
// read model_typecode file (which we could live without)
ModelIcaoType::ReadFile();
// read configuration file if any
if (!LoadConfigFile())
return false;
// *** Flarm ac type definitions - Defaults ***
OGNFillDefaultFlarmAcTypes();
// *** CSL path defaults ***
// We'll try making this fool-proof but expert-changeable:
// There are two paths under LiveTraffic that in all normal
// installations should be supported, especially on initial setup.
// Experts, however, may want to remove them and keep their CSLs elsewhere
// or just deactivate the standard directories.
// So the logic is:
// 1. Underlying directory _does_ exist and is not empty
// 2. Entry in vCSLPath does _not_ yet exist
// then: add an activated entry
for (std::string stdCSL: { PATH_RESOURCES_CSL, PATH_RESOURCES_SCSL }) {
// 1. Underlying directory _does_ exist and is not empty
const std::string path (LTCalcFullPluginPath(stdCSL));
if (LTNumFilesInPath(path) > 0) {
// 2. Entry in vCSLPath does _not_ yet exist
CSLPathCfgTy cfg (true, LTRemoveXPSystemPath(path));
if (std::find(vCSLPaths.cbegin(), vCSLPaths.cend(), cfg) == vCSLPaths.cend()) {
// insert at beginning
vCSLPaths.emplace(vCSLPaths.cbegin(), std::move(cfg));
}
}
}
// Read initial cached values
UpdateCachedValues();
return true;
}
// tell DRE and DRT our dataRefs
void DataRefs::InformDataRefEditors ()
{
// loop over all available data ref editor signatures
for (const char* szDREditor: DATA_REF_EDITORS) {
// find the plugin by signature
XPLMPluginID PluginID = XPLMFindPluginBySignature(szDREditor);
if (PluginID != XPLM_NO_PLUGIN_ID) {
// send message regarding each dataRef we offer
for ( const DataRefs::dataRefDefinitionT& def: DATA_REFS_LT )
XPLMSendMessageToPlugin(PluginID,
MSG_ADD_DATAREF,
(void*)def.getDataName());
// And then there are 2 shared dataRefs
if (adrXP[DR_CAMERA_TCAS_IDX] && adrXP[DR_CAMERA_AC_ID])
{
XPLMSendMessageToPlugin(PluginID,
MSG_ADD_DATAREF,
(void*)DATA_REFS_XP[DR_CAMERA_TCAS_IDX]);
XPLMSendMessageToPlugin(PluginID,
MSG_ADD_DATAREF,
(void*)DATA_REFS_XP[DR_CAMERA_AC_ID]);
}
}
}
}
// Unregister (destructor would be too late for reasonable API calls)
void DataRefs::Stop ()
{
// Stop all file writing
if (AnyExportData()) {
SetAllExportData(false);
LTFlightData::ExportOpenClose();
}
// unregister our dataRefs
for (XPLMDataRef& dr: adrLT) {
XPLMUnregisterDataAccessor(dr);
dr = NULL;
}
// Unshare shared dataRefs
XPLMUnshareData(DATA_REFS_XP[DR_CAMERA_TCAS_IDX], xplmType_Int, ClearCameraAc, nullptr);
XPLMUnshareData(DATA_REFS_XP[DR_CAMERA_AC_ID], xplmType_Int, nullptr, nullptr);
// save config file
SaveConfigFile();
}
// call XPLMRegisterDataAccessor
bool DataRefs::RegisterDataAccessors ()
{
bool bRet = true;
// loop over all data ref definitions
for (int i=0; i < CNT_DATAREFS_LT; i++)
{
dataRefsLT eDataRef = dataRefsLT(i);
dataRefDefinitionT& def = DATA_REFS_LT[i];
// look up _and update_ refCon first if required
// (can look up variable addresses only when object is known but not at compile time in definition of DATA_REFS_LT)
if (def.getRefCon() == GET_VAR)
def.setRefCon(getVarAddr(eDataRef));
// register data accessor
if ( (adrLT[i] =
XPLMRegisterDataAccessor(def.getDataName(), // inDataName
def.getDataType(), // inDataType
def.isWriteable(), // inIsWritable
def.getDatai_f(), // int
def.setDatai_f(),
def.getDataf_f(), // float
def.setDataf_f(),
NULL,NULL, // double
NULL,NULL, // int array
NULL,NULL, // float array
def.getDatab_f(), // data (read only)
NULL,
def.getRefCon(), // read refCon
def.getRefCon() // write refCon
)) == NULL )
{ LOG_MSG(logERR,ERR_DATAREF_ACCESSOR,def.getDataName()); bRet = false; }
}
return bRet;
}
// call XPLMRegisterDataAccessor
bool DataRefs::RegisterCommands()
{