ADSB decoder

This object processes 2MHz wide IQ blocks and extracts ADSB messages.

class ADSB {
    constructor();

    bool process( IQData iq );
    bool hasData();
    Object getData();
} ;

.process

Inject IQ data for processing. Returns true if messages have been processed.

.hasData

Returns true if ADSB messages have been decoded and are available

.getData

Returns a decoded object. Available fields are :

  • icao : the ICAO number of the decoded message
  • update_type : A combination of the following :
    • 0 : new aircraft
    • 1 : position update
    • 2 : direction update
    • 4 : altitude update
    • 8 : Squawk update
    • 16 : Callsign change
    • 99 : aircraft lost, no message received for a while (considered as lost).

For example : update_type = 3 = 1+2 = position AND direction change

  • timestamp : date of update, number of millisecs since 01/01/1970
  • squawk : Squawk codes are four-digit codes ranging from 0000 all the way through to 7777 that are set on an aircraft transponder. These unique identifiers allow air traffic control units to distinguish between different aircraft.
  • aircraft_type:
    • 1 :
    • 2 :
    • 3 :
    • 4 :
  • flight: flight number, if available
  • alt_ft : altitude ASL, in feet
  • speed_kn: speed, in knots
  • track : flying direction, 0 is North
  • pos_valid: true if the position fields (lat,lon) are valid or not

Example:

    {
        "icao":"3949EF",
        "update_type":1,
        "timestamp":1692377456177,
        "squawk":1000,
        "aircraft_type":4,
        "flight":"AFR598",
        "alt_ft":21025,
        "speed_kn":404,
        "track":211,
        "pos_valid":true,
        "lat":48.506593865863344,
        "lon":2.18902587890625
    }

Use case example

const SAMPLE_RATE=2e6;
const ADSB_CENTER=1090;


// RTLSDR native driver
var list = RTLSDR.list();
if( list.length == 0 ) {
    print('no radio found.');
    exit(0);
}
var selection = list[0] ;
print( JSON.stringify( selection ));
var rx = RTLSDR.makeDevice( selection );

// or Soapy driver
//var rx = Soapy.makeDevice({'query' : 'driver=sdrplay' })


rx.setRxSampleRate( SAMPLE_RATE );
rx.setRxCenterFreq( ADSB_CENTER );
rx.setGain( 48 );

rx.dump();

var fifo_from_rx = Queues.create( 'input');

var adsb = new ADSB();
// engage streaming
if( !fifo_from_rx.ReadFromRx( rx ) ) {
    print('Cannot stream from rx');
    exit();
}
var IQBlock = new IQData('iq');
print('starting rx process');
while( fifo_from_rx.isFromRx() ) { 
    if( IQBlock.readFromQueue( fifo_from_rx ) ) {   
       //IQBlock.dump();
       var hasMsg = adsb.process( IQBlock );
       while( hasMsg ) {
        var positionMsg = adsb.getData();
        print( JSON.stringify( positionMsg )); 
        hasMsg = adsb.hasData();
       }
    }
}
Last update: November 21, 2023