summaryrefslogtreecommitdiffhomepage
path: root/X-Plane-SDK/Delphi/XPLM/XPLMNavigation.pas
blob: 993ef5826aab6153680b803a82db61dbbdb436c8 (plain)
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
{
   Copyright 2005-2012 Sandy Barbour and Ben Supnik
   
   All rights reserved.  See license.txt for usage.
   
   X-Plane SDK Version: 2.1.1                                                  
}

UNIT XPLMNavigation;
INTERFACE
{
   XPLMNavigation - THEORY OF OPERATION 
   
   The XPLM Navigation APIs give you some access to the navigation databases 
   inside X-Plane.  X-Plane stores all navigation information in RAM, so by 
   using these APIs you can gain access to most information without having to 
   go to disk or parse the files yourself. 
   
   You can also use this API to program the FMS.  You must use the navigation 
   APIs to find the nav-aids you want to program into the FMS, since the FMS 
   is powered internally by x-plane's navigation database.                     
}

USES   XPLMDefs;
   {$A4}
{$IFDEF MSWINDOWS}
   {$DEFINE DELPHI}
{$ENDIF}
{___________________________________________________________________________
 * NAVIGATION DATABASE ACCESS
 ___________________________________________________________________________}
{
                                                                               
}



   {
    XPLMNavType
    
    These enumerations define the different types of navaids.  They are each 
    defined with a separate bit so that they may be bit-wise added together to 
    form sets of nav-aid types. 
    
    NOTE: xplm_Nav_LatLon is a specific lat-lon coordinate entered into the 
    FMS. It will not exist in the database, and cannot be programmed into the 
    FMS. Querying the FMS for navaids will return it.  Use 
    XPLMSetFMSEntryLatLon to set a lat/lon waypoint.                            
   }
TYPE
   XPLMNavType = (
      xplm_Nav_Unknown                         = 0
 
     ,xplm_Nav_Airport                         = 1
 
     ,xplm_Nav_NDB                             = 2
 
     ,xplm_Nav_VOR                             = 4
 
     ,xplm_Nav_ILS                             = 8
 
     ,xplm_Nav_Localizer                       = 16
 
     ,xplm_Nav_GlideSlope                      = 32
 
     ,xplm_Nav_OuterMarker                     = 64
 
     ,xplm_Nav_MiddleMarker                    = 128
 
     ,xplm_Nav_InnerMarker                     = 256
 
     ,xplm_Nav_Fix                             = 512
 
     ,xplm_Nav_DME                             = 1024
 
     ,xplm_Nav_LatLon                          = 2048
 
   );
   PXPLMNavType = ^XPLMNavType;

   {
    XPLMNavRef
    
    XPLMNavRef is an iterator into the navigation database.  The navigation 
    database is essentially an array, but it is not necessarily densely 
    populated. The only assumption you can safely make is that like-typed 
    nav-aids are  grouped together. 
    
    Use XPLMNavRef to refer to a nav-aid. 
    
    XPLM_NAV_NOT_FOUND is returned by functions that return an XPLMNavRef when 
    the iterator must be invalid.                                               
   }
   XPLMNavRef = integer;
   PXPLMNavRef = ^XPLMNavRef;

CONST
   XPLM_NAV_NOT_FOUND   = -1;

   {
    XPLMGetFirstNavAid
    
    This returns the very first navaid in the database.  Use this to traverse 
    the entire database.  Returns XPLM_NAV_NOT_FOUND if the nav database is 
    empty.                                                                      
   }
   FUNCTION XPLMGetFirstNavAid: XPLMNavRef;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetNextNavAid
    
    Given a nav aid ref, this routine returns the next navaid.  It returns 
    XPLM_NAV_NOT_FOUND if the nav aid passed in was invalid or if the navaid 
    passed in was the last one in the database.  Use this routine to iterate 
    across all like-typed navaids or the entire database. 
    
    WARNING: due to a bug in the SDK, when fix loading is disabled in the 
    rendering settings screen, calling this routine with the last airport 
    returns a bogus nav aid.  Using this nav aid can crash x-plane.             
   }
   FUNCTION XPLMGetNextNavAid(
                                        inNavAidRef         : XPLMNavRef) : XPLMNavRef;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMFindFirstNavAidOfType
    
    This routine returns the ref of the first navaid of the given type in the 
    database or XPLM_NAV_NOT_FOUND if there are no navaids of that type in the 
    database.  You must pass exactly one nav aid type to this routine. 
    
    WARNING: due to a bug in the SDK, when fix loading is disabled in the 
    rendering settings screen, calling this routine with fixes returns a bogus 
    nav aid.  Using this nav aid can crash x-plane.				                         
   }
   FUNCTION XPLMFindFirstNavAidOfType(
                                        inType              : XPLMNavType) : XPLMNavRef;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMFindLastNavAidOfType
    
    This routine returns the ref of the last navaid of the given type in the 
    database or XPLM_NAV_NOT_FOUND if there are no navaids of that type in the 
    database.  You must pass exactly one nav aid type to this routine. 
    
    WARNING: due to a bug in the SDK, when fix loading is disabled in the 
    rendering settings screen, calling this routine with fixes returns a bogus 
    nav aid.  Using this nav aid can crash x-plane.								                     
   }
   FUNCTION XPLMFindLastNavAidOfType(
                                        inType              : XPLMNavType) : XPLMNavRef;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMFindNavAid
    
    This routine provides a number of searching capabilities for the nav 
    database. XPLMFindNavAid will search through every nav aid whose type is 
    within inType (multiple types may be added together) and return any 
    nav-aids found based  on the following rules: 
    
    If inLat and inLon are not NULL, the navaid nearest to that lat/lon will be 
    returned, otherwise the last navaid found will be returned. 
    
    If inFrequency is not NULL, then any navaids considered must match this  
    frequency.  Note that this will screen out radio beacons that do not have 
    frequency data published (like inner markers) but not fixes and airports. 
    
    If inNameFragment is not NULL, only navaids that contain the fragment in 
    their name will be returned. 
    
    If inIDFragment is not NULL, only navaids that contain the fragment in 
    their IDs will be returned. 
    
    This routine provides a simple way to do a number of useful searches: 
    
    Find the nearest navaid on this frequency. Find the nearest airport. Find 
    the VOR whose ID is "KBOS". Find the nearest airport whose name contains 
    "Chicago".                                                                  
   }
   FUNCTION XPLMFindNavAid(
                                        inNameFragment      : Pchar;    { Can be nil }
                                        inIDFragment        : Pchar;    { Can be nil }
                                        inLat               : Psingle;    { Can be nil }
                                        inLon               : Psingle;    { Can be nil }
                                        inFrequency         : Pinteger;    { Can be nil }
                                        inType              : XPLMNavType) : XPLMNavRef;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetNavAidInfo
    
    This routine returns information about a navaid.  Any non-null field is 
    filled out with information if it is available. 
    
    Frequencies are in the nav.dat convention as described in the X-Plane nav 
    database FAQ: NDB frequencies are exact, all others are multiplied by 100. 
    
    The buffer for IDs should be at least 6 chars and the buffer for names 
    should be at least 41 chars, but since these values are likely to go up, I 
    recommend passing at least 32 chars for IDs and 256 chars for names when 
    possible. 
    
    The outReg parameter tells if the navaid is within the local "region" of 
    loaded DSFs.  (This information may not be particularly useful to plugins.) 
    The parameter is a single byte value 1 for true or 0 for false, not a C 
    string.                                                                     
   }
   PROCEDURE XPLMGetNavAidInfo(
                                        inRef               : XPLMNavRef;    
                                        outType             : PXPLMNavType;    { Can be nil }
                                        outLatitude         : Psingle;    { Can be nil }
                                        outLongitude        : Psingle;    { Can be nil }
                                        outHeight           : Psingle;    { Can be nil }
                                        outFrequency        : Pinteger;    { Can be nil }
                                        outHeading          : Psingle;    { Can be nil }
                                        outID               : Pchar;    { Can be nil }
                                        outName             : Pchar;    { Can be nil }
                                        outReg              : Pchar);    { Can be nil }
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

{___________________________________________________________________________
 * FLIGHT MANAGEMENT COMPUTER
 ___________________________________________________________________________}
{
   Note: the FMS works based on an array of entries.  Indices into the array 
   are zero-based.  Each entry is a nav-aid plus an altitude.  The FMS tracks 
   the currently displayed entry and the entry that it is flying to. 
   
   The FMS must be programmed with contiguous entries, so clearing an entry at 
   the end shortens the effective flight plan.  There is a max of 100 
   waypoints in the flight plan.                                               
}



   {
    XPLMCountFMSEntries
    
    This routine returns the number of entries in the FMS.                      
   }
   FUNCTION XPLMCountFMSEntries: integer;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetDisplayedFMSEntry
    
    This routine returns the index of the entry the pilot is viewing.           
   }
   FUNCTION XPLMGetDisplayedFMSEntry: integer;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetDestinationFMSEntry
    
    This routine returns the index of the entry the FMS is flying to.           
   }
   FUNCTION XPLMGetDestinationFMSEntry: integer;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMSetDisplayedFMSEntry
    
    This routine changes which entry the FMS is showing to the index specified. 
       }
   PROCEDURE XPLMSetDisplayedFMSEntry(
                                        inIndex             : integer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMSetDestinationFMSEntry
    
    This routine changes which entry the FMS is flying the aircraft toward.     
   }
   PROCEDURE XPLMSetDestinationFMSEntry(
                                        inIndex             : integer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetFMSEntryInfo
    
    This routine returns information about a given FMS entry.  A reference to a 
    navaid can be returned allowing you to find additional information (such as 
    a frequency, ILS heading, name, etc.).  Some information is available 
    immediately.  For a lat/lon entry, the lat/lon is returned by this routine 
    but the navaid cannot be looked up (and the reference will be 
    XPLM_NAV_NOT_FOUND. FMS name entry buffers should be at least 256 chars in 
    length.                                                                     
   }
   PROCEDURE XPLMGetFMSEntryInfo(
                                        inIndex             : integer;    
                                        outType             : PXPLMNavType;    { Can be nil }
                                        outID               : Pchar;    { Can be nil }
                                        outRef              : PXPLMNavRef;    { Can be nil }
                                        outAltitude         : Pinteger;    { Can be nil }
                                        outLat              : Psingle;    { Can be nil }
                                        outLon              : Psingle);    { Can be nil }
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMSetFMSEntryInfo
    
    This routine changes an entry in the FMS to have the destination navaid 
    passed in and the altitude specified.  Use this only for airports, fixes, 
    and radio-beacon navaids.  Currently of radio beacons, the FMS can only 
    support VORs and NDBs. Use the routines below to clear or fly to a lat/lon. 
   }
   PROCEDURE XPLMSetFMSEntryInfo(
                                        inIndex             : integer;    
                                        inRef               : XPLMNavRef;    
                                        inAltitude          : integer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMSetFMSEntryLatLon
    
    This routine changes the entry in the FMS to a lat/lon entry with the given 
    coordinates.                                                                
   }
   PROCEDURE XPLMSetFMSEntryLatLon(
                                        inIndex             : integer;    
                                        inLat               : single;    
                                        inLon               : single;    
                                        inAltitude          : integer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMClearFMSEntry
    
    This routine clears the given entry, potentially shortening the flight 
    plan.                                                                       
   }
   PROCEDURE XPLMClearFMSEntry(
                                        inIndex             : integer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

{___________________________________________________________________________
 * GPS RECEIVER
 ___________________________________________________________________________}
{
   These APIs let you read data from the GPS unit.                             
}



   {
    XPLMGetGPSDestinationType
    
    This routine returns the type of the currently selected GPS destination, 
    one of fix, airport, VOR or NDB.                                            
   }
   FUNCTION XPLMGetGPSDestinationType: XPLMNavType;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetGPSDestination
    
    This routine returns the current GPS destination.                           
   }
   FUNCTION XPLMGetGPSDestination: XPLMNavRef;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

IMPLEMENTATION
END.