Accessing LiveTraffic's Aircraft Data
Ways for plugin developers to access information of LiveTraffic's aircraft
There are a few ways to access LiveTraffic's aircraft data programmatically:
Read Traffic Data
LTAPI
LiveTraffic offers a C++ API to read (nearly) all information of all aircraft that LiveTraffic operates. With a single call, you are provided with a vector of LTAircraft
objects. You can subclass the LTAircraft
class to add your own management functionality. Technically, data is packed and transferred very efficiently in the background and transferred by means of binary dataRefs. Available from X-Plane.org and from GitHub. Includes a sample plugin implementation demonstrating most features.
I am aware of one plugin, which makes already active use of it, which is ABC.
TCAS Targets
As of X-Plane 11.50, X-Plane offers a new approach called TCAS Override to report planes to TCAS systems and to other plugins interested in multiplayer aircraft informaton. New plugins shall definitely follow this new approach. Find implementaton details in Laminar's blog entry.
While LiveTraffic has TCAS control, and only then, LiveTraffic reports the closest up to 63 aircraft as TCAS targets with the following values:
All dataRefs under sim/cockpit2/tcas/targets/position
are filled as expected and documented except for the following, which are not populated:
weight_on_wheels
wing_sweep
yolk_pitch/roll/yaw
[sic!]
Standard Multiplayer DataRefs
The classic 19 sets of multiplayer dataRefs (sim/multiplayer/position/plane*
) are mirrored automatically while providing TCAS target information. So the closest 19 aircraft are also available via this channel while LiveTraffic has TCAS control.
With TCAS Override, XPLMCountAircraft
returns the actual number of reported aircraft independend of how many AI Aircraft the user has configured. So you can rely on this number and don't necessarily need to always monitor all these 19 slots. Still, for backward compatibility, LiveTraffic fills unused slots' _x/y/z
values with > 9999999
. (They are deliberately not set to 0
in this case, because 0/0/0 is a totally valid geographic location.)
Starting with 11.50 Beta 8, X-Plane can return values larger than 20 in XPLMCountAircraft
! If you are dealing with the 19 multiplayer slots only you need to make sure to handle larger values correctly, e.g. by capping at 20.
Shared DataRefs for Textual Information
As a supplement to the standard multiplay dataRefs, textual aircraft and flight information is provided via shared dataRefs of type xplmType_Data
as suggested by FSTramp (LiveTraffic issue #144) with #
being a plane number between 1
and 63
:
sim/multiplayer/position/plane#_tailnum
- Tail number, registrationsim/multiplayer/position/plane#_ICAO
- ICAO Aircraft typesim/multiplayer/position/plane#_manufacturer
- Aircraft manufacturer, human readablesim/multiplayer/position/plane#_model
- Aircraft model, human readablesim/multiplayer/position/plane#_ICAOairline
- ICAO airline/operator codesim/multiplayer/position/plane#_airline
- Airline/operatorsim/multiplayer/position/plane#_flightnum
- Flight numbersim/multiplayer/position/plane#_apt_from
- Origin airportsim/multiplayer/position/plane#_apt_to
- Destination airportsim/multiplayer/position/plane#_cslModel
- CSL model used to render the plane (folder name plus model id)
A plugin wanting to use this data must call XPLMShareData
, can optionally thereby register a notification callback, then calls XPLMFindDataRef
and XPLMGetDatab
as usual. Provide at least a 40 character buffer per dataRef to be on the safe side.
Take Over Camera View of an Aircraft
A LiveTraffic user can activate a camera view on any aircraft. LiveTraffic publishes which aircraft the camera shows and even provides a setting that disables LiveTraffic's internal camera implementation so that a 3rd party camera tool can instead provide the view.
LiveTraffic operates two integer shared dataRefs with global names, ie. not LiveTraffic-specific. In fact, they pick up the naming scheme as used by the shared dataRefs for textual aircraft information. Shared dataRefs have the advantage that a reading plugin can register a notification callback and several plugins can write to them and this way inform both the camera plugin as well as LiveTraffic. See SDK documentation on XPLMShareData.
sim/multiplayer/camera/tcas_idx
is set to the TCAS index (1..63
) of the aircraft being viewed, or to-1
if that aircraft has no TCAS index, or to0
if camera view is turned off.sim/multiplayer/camera/modeS_id
is set to the aircraft key, usually the 24bit ICAO transponder code (like0xAB1234
=11211316
) of the aircraft being viewed, or to0
if camera view is turned off.
A camera plugin
should register a notification on
sim/multiplayer/camera/tcas_idx
because this dataRef is set last. By the time your notification callback triggers bothmodeS_id
andtcas_idx
will be updated.should, in the notification callback, read one or both values and do your camera magic if values are not
0
.can - optionally but welcome - write the dataRef values, too, ie. if your user switches off the camera view then update
modeS_id
andtcas_idx
(in this order) to0
to indicate that no camera view is on an aircraft; or even update them with aircraft info if your user selects another aircraft inside your plugin. (Note that your callbacks get called even if you set the values...weird twist of the SDK implementation.)
Alternatively, a camera plugin can just use LTAPI, which handles all that internally:
Override
LTAPIAircraft::toggleCamera()
, which is called whenever the shared dataRef values change on the current aircraft and even provides you with a pointer to the previous aircraft if any. The LTAPIExample plugin includes an example implementation.LTAPIAircraft::setCameraAc()
andLTAPIConnect::clearCameraInfo()
are available for write operations.
UDP Broadcast in ForeFlight Data Format
You can make use of the data broadcasted on the ForeFlight channel for other purposes than just ForeFlight. The ForeFlight data format is described here and LiveTraffic sticks to it. Example broadcasts (around OMDB) look like this:
User plane's position is broadcasted with 1Hz, its attitude with 5Hz. The repeat interval of traffic data is not defined by ForeFlight and configurable in LiveTraffic.
Output port is 49002 as defined by ForeFlight. There is no GUI setting for it so that nobody can accidently change it. But you'll find it in LiveTraffic's configuration file.
Here's a simplistic Python script, with which I test receiving any broadcasts. It does not interpret the data, but only displays it together with a timestamp. It works for Python 2 and 3 (only the output format slightly differs) and takes just one parameter, the port number:
Called like ./udp_listen.py 49002
, it would output received UDP datagrams continuously like this:
Export Traffic Data
See the Advanced Options to export traffic data to a *.csv
file in a format very similar to what is discussed above. These export files can even be used to re-feed them into LiveTraffic.