How To Receive Aircraft Transmissions |
Virtual Radar Server can listen to several different formats of aircraft message data. In the code they are referred to as:
Sbs3 - Kinetic's format for transmitting the Mode-S / ADS-B bytes received from the aircraft via an SBS-3 receiver.
Port30003 - Kinetic's de-facto standard for transmitting aircraft data from BaseStation. Many other programs can output this format.
Beast - this format encompasses the three AVR text-based message formats for Mode-S / ADS-B bytes (one each for with parity, without parity and with MLAT timestamps) and the Beast's binary format.
At the time of writing it can listen to feeds over a network connection or a serial port connection.
The interface for the object that receives these messages is IListener. In principle there could be many listeners running simultaneously but in practise the application only creates one. The single listener is created by the singleton object IAutoConfigListener. This object creates a listener and then applies configuration settings to it. When the user changes the configuration the object automatically applies the new settings to the listener.
The listener does not have any code to listen to a data feed, nor does it have any code to extract messages out of the feed. It is given classes that can do these jobs. IListenerProviders can read bytes from a connection to the feed (ITcpListenerProvider listens to network connections, ISerialListenerProvider listens to serial port connections) and IMessageBytesExtractors can extract raw (i.e. Mode-S) or Port30003 messages from the bytes received from the feed (ISbs3MessageBytesExtractor decodes SBS-3 format feeds, IPort30003MessageBytesExtractor decodes Port30003 format feeds and IBeastMessageBytesExtractor decodes the AVR and Beast binary format feeds).
The listener has a number of events that it can raise once a message is received. All of these events are raised on a background thread so that a slow message handler cannot cause delays in the listener. The same background thread is used for all background events so the events are guaranteed to be received in the same order for all messages.
Virtual Radar Server creates an IAutoConfigListener when the application starts up and the IBaseStationAircraftList listens to it for information about the aircraft that it is tracking. Your plugin can use the same listener to pick up aircraft messages at any stage in the message processing pipeline, from raw bytes to cooked BaseStationMessage.
IAutoConfigListener is a singleton object. You can get a reference to it by calling the Interface Factory. The listener that it is controlling is exposed via its Listener property:
public void Startup(PluginStartupParameters parameters) { var listener = Factory.Singleton.Resolve<IAutoConfigListener>().Singleton.Listener; }
The listener can raise one of four events when a message is received ( RawBytesReceived, ModeSBytesReceived, ModeSMessageReceived and Port30003MessageReceived ).
public void Startup(PluginStartupParameters parameters) { // See above for instructions on initialising the listener variable listener.Port30003MessageReceived += Listener_Port30003MessageReceived; }
Now all you need is the event handler. When you do your work bear in mind that you are always running on a non-GUI thread. You cannot make any GUI calls when a message is received.
private void Listener_Port30003MessageReceived(object sender, BaseStationMessageEventArgs args) { BaseStationMessage message = args.Message; // Do something with the message from the aircraft... }