DEV Community

Ashen Chathuranga
Ashen Chathuranga

Posted on

Complete ADS-B Decoder in Rust: Track Aircraft in Real-Time with RTL-SDR

Have you ever wondered how websites like FlightRadar24 track thousands of aircraft in real-time? The answer lies in ADS-B (Automatic Dependent Surveillance-Broadcast) - a technology where aircraft continuously broadcast their position, altitude, speed, and identification. Best part? You can receive these signals yourself with a $20 USB dongle!

I've built a complete ADS-B decoder in Rust that rivals the popular dump1090, adding several improvements and comprehensive protocol documentation. Let me show you what makes this project special.

What Can You Track?

With just an RTL-SDR dongle and a simple antenna, you can:

  • Track aircraft up to 250+ nautical miles away
  • See their callsigns (flight numbers)
  • Monitor altitude, speed, and heading in real-time
  • Calculate distance and bearing from your location
  • Detect emergency squawk codes (7500/7600/7700)
  • Access additional data like IAS, Mach number, and vertical rate from BDS registers
Hex     Flight   Alt    Speed  Lat      Lon       Msgs  Seen  Distance  Bearing
89645A  UAE80T   35000  465kt  5.8912   79.4521   142   0s    245.2km   312°
4D2023  AMC421   22000  385kt  37.074   13.799    87    1s    187.8km   158°
Enter fullscreen mode Exit fullscreen mode

Key Features

Complete Mode S Decoding

This isn't a minimal proof-of-concept - it's a full-featured decoder supporting:

  • All major Downlink Formats: DF0, DF4, DF5, DF11, DF16, DF17, DF20, DF21
  • CPR Position Decoding: Both global and local Compact Position Reporting
  • Error Correction: Single-bit and optional two-bit error correction via CRC syndrome
  • BDS Register Decoding: Extract Comm-B data from DF20/DF21 messages

Smart Aircraft Filtering

Real-world RF environments are noisy. The decoder includes:

  • Ghost aircraft filtering with configurable message thresholds
  • Persistent ICAO tracking with TTL-based cleanup
  • ICAO address validation and recovery from CRC
  • Smart handling of position data across zone boundaries

Emergency Detection

Automatically highlights emergency situations with color-coded alerts:

  • 7500 - Hijacking
  • 7600 - Radio Failure
  • 7700 - General Emergency

Multiple Output Formats

Stream decoded data in various formats:

  • Raw TCP (port 30002) - hex messages
  • SBS/BaseStation (port 30003) - compatible with Virtual Radar Server
  • JSON API (port 8080) - for web applications
  • Interactive terminal - with real-time updates

Getting Started

Hardware You'll Need

  • RTL-SDR dongle ($20-30) or HackRF One ($300+)
  • Antenna - a simple 1090 MHz dipole works great (6.9cm elements)
  • Computer - even a Raspberry Pi works!

Installation

# Install RTL-SDR libraries
# Fedora/RHEL
sudo dnf install rtl-sdr rtl-sdr-devel

# Ubuntu/Debian  
sudo apt install rtl-sdr librtlsdr-dev

# Clone and build
git clone https://github.com/ktauchathuranga/adsb.git
cd adsb
cargo build --release
Enter fullscreen mode Exit fullscreen mode

Running It

# Basic usage with RTL-SDR
./target/release/adsb --interactive

# With HackRF One
./target/release/adsb --hackrf --interactive

# Add your location for distance/bearing calculations
./target/release/adsb --interactive \
  --lat 6.9271 --lon 79.8612

# Enable networking for web access
./target/release/adsb --net --interactive
Enter fullscreen mode Exit fullscreen mode

Then open http://localhost:8080 to see aircraft on a map!

How ADS-B Works

One thing that sets this project apart is its comprehensive protocol documentation. The README includes a complete deep-dive into:

Signal Characteristics

  • Frequency: 1090 MHz
  • Modulation: PPM (Pulse Position Modulation)
  • Data Rate: 1 Mbit/s
  • Message Types: 56-bit (short) and 112-bit (long)

Every message starts with a distinctive preamble:

Preamble (8 µs):
 ▲
1│    █   █         █   █
 │    █   █         █   █
0└──────────────────────────────────►
      0   1   2   3   4   5   6   7 µs
Enter fullscreen mode Exit fullscreen mode

Position Encoding Magic

Aircraft positions are encoded using CPR (Compact Position Reporting) - an ingenious algorithm that represents global coordinates in just 17 bits each for latitude and longitude (vs. ~55 bits normally).

The README includes the complete CPR decoding algorithm with:

  • Zone calculations
  • Latitude/longitude recovery
  • NL (Number of Longitude zones) lookup tables
  • Even/odd frame pairing logic

Message Structure

Detailed breakdowns of every message type:

  • DF11: All-Call Reply (ICAO address announcement)
  • DF17: Extended Squitter (ADS-B position/velocity/ID)
  • DF4/DF5: Altitude and Identity Replies
  • DF20/DF21: Comm-B messages with BDS data

CRC & Error Correction

The decoder implements proper CRC-24 checking with:

  • Single-bit error correction (default)
  • Two-bit error correction (aggressive mode)
  • ICAO address recovery from XORed parity fields

Architecture

The codebase is clean and modular:

┌─────────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   RTL-SDR   │────►│ Demodulator │────►│   Decoder   │────►│  Aircraft   │
│   Input     │     │             │     │             │     │   Tracker   │
│             │     │ • Preamble  │     │ • CRC Check │     │             │
│ • 2 MHz IQ  │     │ • PPM Decode│     │ • DF Parse  │     │ • Position  │
│ • 8-bit     │     │ • Magnitude │     │ • CPR Decode│     │ • History   │
└─────────────┘     └─────────────┘     └─────────────┘     └─────────────┘
Enter fullscreen mode Exit fullscreen mode

Key modules:

  • demodulator.rs - Preamble detection and PPM decoding
  • decoder.rs - Message parsing and field extraction
  • crc.rs - Error detection and correction
  • aircraft.rs - Position tracking and CPR decoding
  • network.rs - TCP/HTTP servers

Educational Value

While this is a production-ready tool, it's also an excellent learning resource:

  1. Protocol Documentation: 60KB+ of detailed explanations, diagrams, and examples
  2. Clean Rust Code: Idiomatic async Rust with tokio
  3. Real-World DSP: Signal processing, demodulation, error correction
  4. Network Programming: Concurrent TCP servers and HTTP APIs
  5. Aviation Technology: Deep dive into Mode S/ADS-B standards

The README includes:

  • ASCII art diagrams of signal structures
  • Bit-level message breakdowns
  • Decoding algorithms with pseudocode
  • Lookup tables and encoding schemes
  • Examples with real messages

Future Enhancements

Some ideas I'm exploring:

  • Mode A/C decoding (older transponders)
  • MLAT (Multilateration) support
  • Database integration for aircraft info
  • Advanced filtering and alerting
  • Performance optimizations for embedded systems

Contributing

The project is open source and welcomes contributions! Whether it's:

  • Bug fixes
  • Performance improvements
  • Additional message types
  • Documentation enhancements
  • Testing on new hardware

Check out the repo: github.com/ktauchathuranga/adsb

References

The implementation follows official specifications:

  • ICAO Annex 10 (Aeronautical Telecommunications)
  • DO-260B (MOPS for 1090 MHz ADS-B)
  • Mode S specifications
  • Various research papers on CPR decoding

Final Thoughts

Building this decoder taught me so much about:

  • Radio protocols and signal processing
  • The elegance of well-designed encoding schemes (CPR is brilliant!)
  • Real-time systems and performance optimization
  • The fascinating world of aviation technology

If you're interested in SDR, aviation, or just want to see what's flying overhead, give it a try! The hardware is cheap, the software is free, and watching aircraft appear on your screen in real-time is genuinely exciting.


Have questions? Drop them in the comments! I'd love to hear about your ADS-B setups or help troubleshoot any issues.

Like this? Consider giving the repo a star on GitHub!

rust #sdr #aviation #opensource #flightracking

Top comments (0)