Something went wrong. Try again.
A port of FlightAware's dump1090, a Mode S and ADS-B decoder for software defined radios, to Zig 0.16.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792// SPDX-FileCopyrightText: © 2012 Salvatore Sanfilippo <antirez@gmail.com>// SPDX-FileCopyrightText: © 2014-2016 Oliver Jowett <oliver@mutability.co.uk>// SPDX-FileCopyrightText: © 2021 FlightAware LLC// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: GPL-2.0-or-later
//! One decoded downlink message, and the vocabulary it is described in.//!//! This is the boundary between the two halves of the program. Below it, the//! demodulator and the decoders care about bits, parity and pulse shapes;//! above it, the tracker and the output formats care about aircraft. A//! `Message` is the only thing that crosses, and everything it can say is//! declared here.//!//! Almost every field is optional, and that is the point rather than an//! inconvenience. A Mode S frame carries 56 or 112 bits, so any one message//! says a very little about an aircraft — an altitude but no position, a//! callsign but no altitude — and the tracker's whole job is assembling those//! fragments. Upstream carries a parallel `_valid` bit for each field; here//! the absence is in the type, so a field cannot be read without the question//! of whether it was present having been answered.
const std = @import("std");
const cpr = @import("cpr.zig");const modes = @import("modes.zig");
/// Where a piece of data came from, worst to best.////// The tracker keeps the best source it has seen for each field and refuses/// to overwrite it with a worse one, so that a position from an unverifiable/// Mode S reply cannot displace one from an extended squitter whose CRC/// checked out. The order of this enum *is* that ranking.pub const Source = enum { /// No data at all. Ranks below everything. invalid, /// A Mode A/C reply, which is twelve pulses and no error detection. mode_ac, /// Multilateration: computed from arrival times at several receivers /// rather than stated by the aircraft. mlat, /// A Mode S message whose CRC could not be checked, because the format /// overlays the address on the parity field. mode_s, /// A Mode S message whose CRC was checked in full. mode_s_checked, /// A TIS-B extended squitter: ground radar rebroadcasting what it sees. tisb, /// An ADS-R extended squitter: a rebroadcast of an ADS-B message that /// arrived over a different data link. adsr, /// An ADS-B extended squitter, straight from the aircraft. adsb,};
/// What kind of address a message carries, and who sent it. Earlier values/// are higher priority, which is how the tracker decides that a direct ADS-B/// report should win over the ground's rebroadcast of the same aircraft.pub const AddressType = enum { /// Mode S or ADS-B, an ICAO address, from a transponder. adsb_icao, /// ADS-B, an ICAO address, from something that is not a transponder. adsb_icao_nt, /// ADS-R, an ICAO address. adsr_icao, /// TIS-B, an ICAO address. tisb_icao,
/// ADS-B, some other address format. adsb_other, /// ADS-R, some other address format. adsr_other, /// TIS-B, a Mode A code and a track file number rather than an address. tisb_trackfile, /// TIS-B, some other address format. tisb_other,
/// A Mode A reply, whose "address" is fabricated from the squawk. mode_a,
/// Something whose addressing scheme was not recognised. unknown,};
/// The unit an altitude is quoted in. Mode S can encode metres, but no/// transponder in service does.pub const AltitudeUnit = enum { feet, meters };
/// An altitude and the unit it was reported in.pub const Altitude = struct { value: i32, unit: AltitudeUnit,};
/// Whether the aircraft says it is on the ground.pub const AirGround = enum { /// Nothing said either way. invalid, /// On the ground. ground, /// Airborne, stated as such. airborne, /// Probably airborne: the message rules out the ground state but does not /// assert the airborne one. uncertain,};
/// How the Source Integrity Level should be read.pub const SilType = enum { /// No SIL was reported. invalid, /// A SIL was reported but not what it is per. unknown, /// The probability is per sample. per_sample, /// The probability is per flight hour. per_hour,};
/// Which CPR grid a position was encoded against.pub const CprType = enum { /// The quarter-scale grid used on the ground. surface, /// The full-globe grid used in the air. airborne, /// The reduced-precision grid TIS-B uses for coarse position reports. coarse,
/// The CPR grid this corresponds to. Coarse positions use the airborne /// grid with fewer bits, so they solve the same way. pub fn kind(self: CprType) cpr.Kind { return switch (self) { .surface => .surface, .airborne, .coarse => .airborne, }; }};
/// What a reported direction means. Aircraft report several different things/// through the same field, and two of these are not answers but instructions/// to look elsewhere in the aircraft's own operational status for the answer.pub const HeadingType = enum { /// Not set. invalid, /// Direction of travel over the ground, degrees clockwise from true north. ground_track, /// Where the nose points, degrees clockwise from true north. true_heading, /// Where the nose points, degrees clockwise from magnetic north. magnetic_heading, /// Magnetic or true, according to the HRD bit of the aircraft's /// operational status message. magnetic_or_true, /// Ground track, magnetic or true, according to the TAH bit of the /// aircraft's operational status message. track_or_heading,};
/// A direction, and what kind of direction it is.pub const Heading = struct { degrees: f32, type: HeadingType,};
/// What a Comm-B reply turned out to contain.////// A Comm-B reply carries no field saying which register it answers with, so/// the format has to be inferred from whether the contents are plausible./// Sometimes more than one interpretation is, and `ambiguous` is the honest/// answer.pub const CommBFormat = enum { /// Not looked at. unknown, /// More than one register decoded plausibly, so none was chosen. ambiguous, /// Nothing decoded plausibly. not_decoded, /// All zeros: the transponder had nothing to say. empty_response, /// BDS1,0 data link capability. datalink_caps, /// BDS1,7 common usage GICB capability. gicb_caps, /// BDS2,0 aircraft identification. aircraft_ident, /// BDS3,0 ACAS resolution advisory. acas_ra, /// BDS4,0 selected vertical intention. vertical_intent, /// BDS5,0 track and turn report. track_turn, /// BDS6,0 heading and speed report. heading_speed, /// BDS4,4 meteorological routine air report. mrar, /// BDS0,5 extended squitter airborne position. airborne_position,};
/// Which autopilot modes an aircraft says are engaged.pub const NavModes = packed struct(u8) { autopilot: bool = false, vnav: bool = false, alt_hold: bool = false, approach: bool = false, lnav: bool = false, tcas: bool = false, _: u2 = 0,
pub const none: NavModes = .{};
/// Whether any mode at all is engaged. pub fn any(self: NavModes) bool { return @as(u8, @bitCast(self)) != 0; }};
/// The emergency and priority status codes, numbered as the type 28/// subfield encodes them.pub const Emergency = enum(u3) { none = 0, general = 1, lifeguard = 2, min_fuel = 3, no_comms = 4, unlawful_interference = 5, downed = 6, reserved = 7,};
/// Which box in the cockpit an altitude the aircraft is flying towards came/// from.pub const NavAltitudeSource = enum { invalid, unknown, /// Set on the aircraft itself. aircraft, /// The mode control panel / flight control unit: what the pilot dialled. mcp, /// The flight management system: what the flight plan says. fms,};
/// Where a BDS4,4 meteorological report got its wind data.pub const MrarSource = enum(u3) { invalid = 0, /// Inertial navigation. ins = 1, /// Satellite navigation. gnss = 2, dme_dme = 3, vor_dme = 4, reserved = 5,};
/// The severity scale BDS4,4 and BDS4,5 hazard reports use.pub const Hazard = enum(u2) { nil = 0, light = 1, moderate = 2, severe = 3 };
/// Which downlink format a message is, or that it is not Mode S at all.pub const Format = union(enum) { /// A Mode S downlink format, 0 to 31. mode_s: u5, /// A Mode A or Mode C reply, which has no format field: twelve pulses /// that mean a squawk or an altitude depending on what was asked. mode_ac,
/// Whether this is a particular Mode S downlink format. pub fn is(self: Format, df: u5) bool { return switch (self) { .mode_s => |actual| actual == df, .mode_ac => false, }; }
/// Whether this is any of the given Mode S downlink formats. pub fn isAny(self: Format, formats: []const u5) bool { return switch (self) { .mode_s => |actual| std.mem.indexOfScalar(u5, formats, actual) != null, .mode_ac => false, }; }
/// The human-readable name of the format, as `--verbose` prints it. pub fn name(self: Format) []const u8 { return switch (self) { .mode_ac => "Mode A/C Reply", .mode_s => |df| switch (df) { 0 => "Short Air-Air Surveillance", 4 => "Survelliance, Altitude Reply", 5 => "Survelliance, Identity Reply", 11 => "All Call Reply", 16 => "Long Air-Air ACAS", 17 => "Extended Squitter", 18 => "Extended Squitter (Non-Transponder)", 19 => "Extended Squitter (Military)", 20 => "Comm-B, Altitude Reply", 21 => "Comm-B, Identity Reply", 22 => "Military Use", 24...31 => "Comm-D Extended Length Message", else => "reserved", }, }; }};
/// Bit 24 of an address, set to mark that the value is not a real ICAO/// address — an anonymous ADS-B identifier, a ground vehicle, or a TIS-B/// track file number. ICAO addresses are 24 bits, so the bit is free.pub const non_icao_address: u32 = 1 << 24;
/// The timestamp a multilateration server puts on a synthetic message to say/// that the position was computed rather than received. It is not a time.pub const mlat_timestamp: u64 = 0xff004d4c4154;
/// How accurately the aircraft says it knows where it is.////// These are all reported separately from the position itself and mean/// nothing without it, which is why they are gathered here rather than mixed/// in among the fields they qualify.pub const Accuracy = struct { /// Navigation Integrity Category supplement A. nic_a: ?u1 = null, /// Navigation Integrity Category supplement B. nic_b: ?u1 = null, /// Navigation Integrity Category supplement C. nic_c: ?u1 = null, /// Barometric altitude integrity. nic_baro: ?u1 = null, /// Navigation Accuracy Category for position. nac_p: ?u4 = null, /// Navigation Accuracy Category for velocity. nac_v: ?u3 = null, /// Source Integrity Level, meaningless unless `sil_type` says what it is /// per. sil: u2 = 0, sil_type: SilType = .invalid, /// Geometric Vertical Accuracy. gva: ?u2 = null, /// System Design Assurance. sda: ?u2 = null,};
/// What an aircraft's operational status message said about its equipment.pub const OpStatus = struct { /// Which version of the ADS-B standard the aircraft implements. The /// meaning of several other fields depends on it. version: u3 = 0,
/// Operational mode: an ACAS resolution advisory is active. om_acas_ra: bool = false, /// Operational mode: the ident switch has been pressed. om_ident: bool = false, /// Operational mode: under air traffic control. om_atc: bool = false, /// Operational mode: single antenna flag. om_saf: bool = false,
/// Capability: ACAS is fitted and operating. cc_acas: bool = false, /// Capability: cockpit display of traffic information. cc_cdti: bool = false, /// Capability: 1090 MHz ADS-B receiver. cc_1090_in: bool = false, /// Capability: air-referenced velocity reports. cc_arv: bool = false, /// Capability: target state reports. cc_ts: bool = false, /// Capability: trajectory change reports. cc_tc: u2 = 0, /// Capability: UAT receiver. cc_uat_in: bool = false, /// Capability: position offset applied. cc_poa: bool = false, /// Capability: class B2 transmitter below 70 watts. cc_b2_low: bool = false, /// Aircraft length and width category, if reported. cc_lw: ?u4 = null, /// GPS antenna offset from the aircraft's nose. cc_antenna_offset: u8 = 0,
/// How to read a surface movement report's direction field. tah: HeadingType = .invalid, /// Which north the aircraft's headings are referenced to. hrd: HeadingType = .invalid,};
/// Where the aircraft has been told to go: the autopilot's targets, from/// either an ADS-B target state message or a Comm-B BDS4,0 reply.pub const Nav = struct { /// The heading the autopilot is steering to. heading: ?Heading = null, /// The altitude the flight management system is flying to, in feet. fms_altitude: ?i32 = null, /// The altitude dialled into the mode control panel, in feet. mcp_altitude: ?i32 = null, /// The altimeter setting, in millibars. qnh: ?f32 = null, /// Which of the above the aircraft is actually using. altitude_source: NavAltitudeSource = .invalid, /// The autopilot modes engaged, or null if the message did not say. modes: ?NavModes = null,};
/// A BDS4,4 meteorological routine air report: what the aircraft's own/// sensors say about the air it is flying through.pub const Meteorology = struct { /// Where the wind figures came from. source: ?MrarSource = null, /// Wind speed in knots and direction in degrees. wind: ?struct { speed: f32, direction: f32 } = null, /// Static air temperature, degrees Celsius. temperature: ?f32 = null, /// Average static pressure, hPa. pressure: ?f32 = null, turbulence: ?Hazard = null, /// Relative humidity, 0-100 per cent. humidity: ?f32 = null,};
/// Ground speed, which surface movement reports encode differently in ADS-B/// version 0 and version 2.////// Both readings are decoded, because a message does not say which version/// encoded it; the tracker fills in `selected` once it has heard the/// aircraft's operational status and knows which to believe.pub const GroundSpeed = struct { /// Read as an ADS-B version 0 message. v0: f32, /// Read as an ADS-B version 2 message. v2: f32, /// Whichever of the two applies. Equal to `v0` until the tracker knows /// better. selected: f32,
/// A speed that both versions agree on, as every airborne velocity /// message produces. pub fn exact(speed: f32) GroundSpeed { return .{ .v0 = speed, .v2 = speed, .selected = speed }; }};
/// A position as the message carried it: the two CPR fragments, unresolved.pub const CprPosition = struct { /// Which of the two interleaved grids this was encoded against. frame: cpr.Frame, /// The grid itself. type: CprType, /// The raw latitude and longitude fragments. encoded: cpr.Encoded,};
/// A position the decoder resolved, along with what the resolution says about/// its precision.pub const DecodedPosition = struct { position: cpr.Position, /// Navigation Integrity Category. nic: u8, /// Radius of containment, in metres. rc: u32, /// Whether it was solved against a reference rather than from a pair of /// messages. relative: bool,};
/// The raw Annex 4 fields, named as the standard names them.////// Only the fields a message's downlink format defines are meaningful; the/// rest are zero. They are kept because the Beast and AVR output formats/// forward the message rather than the decode, and because `--verbose` prints/// them for anyone comparing against the standard.pub const Raw = struct { /// Interrogator identifier, recovered from a DF11's parity. iid: u32 = 0, /// Address announced. aa: u32 = 0, /// Altitude code. ac: u32 = 0, /// Capability. ca: u32 = 0, /// Cross-link capability. cc: u32 = 0, /// Control field. cf: u32 = 0, /// Downlink request. dr: u32 = 0, /// Flight status. fs: u32 = 0, /// Identity, the Gillham-coded squawk. id: u32 = 0, /// Control, for extended length messages. ke: u32 = 0, /// Number of the D-segment, for extended length messages. nd: u32 = 0, /// Reply information. ri: u32 = 0, /// Sensitivity level. sl: u32 = 0, /// Utility message. um: u32 = 0, /// Vertical status. vs: u32 = 0, /// Comm-B message field. mb: [7]u8 = @splat(0), /// Comm-D message field. md: [10]u8 = @splat(0), /// Extended squitter message field. me: [7]u8 = @splat(0), /// ACAS message field. mv: [7]u8 = @splat(0),};
/// One decoded downlink message.pub const Message = struct { // ---- The frame itself ----
/// The frame, after any error correction was applied. msg: [modes.max_message_bytes]u8 = @splat(0), /// The frame exactly as received, before correction. This is what gets /// forwarded to other receivers, so that they can make their own decision /// about whether to trust the correction. verbatim: [modes.max_message_bytes]u8 = @splat(0), /// How many bytes of `msg` are meaningful: 2 for a Mode A/C reply, 7 or /// 14 for Mode S. len: u8 = 0, /// Which downlink format this is. format: Format = .{ .mode_s = 0 }, /// The CRC syndrome. Zero means the frame checked out; for the formats /// that overlay the address on the parity field it *is* the address. crc: u24 = 0, /// How many bit errors were corrected to get here. Anything above zero /// means the frame is a guess, however good a one. corrected_bits: u8 = 0, /// Whether this frame can be trusted without corroboration: an /// uncorrected DF11, DF17 or DF18. reliable: bool = false, /// How plausible the frame looked, or null if it has not been scored — /// which is how a message arriving over the network starts out. score: ?ScoreRank = null,
// ---- Where it came from ----
/// The aircraft's address, with `non_icao_address` set if it is not a /// real ICAO address. address: u32 = 0, address_type: AddressType = .adsb_icao, /// Overall trustworthiness of everything in this message. source: Source = .invalid, /// The receiver's 12 MHz clock when the frame arrived. timestamp_12mhz: u64 = 0, /// Wall-clock milliseconds when the frame arrived. system_timestamp_ms: u64 = 0, /// Whether the frame arrived over the network rather than from a radio. remote: bool = false, /// Received signal power, as a fraction of full scale. signal_level: f64 = 0,
// ---- Raw fields ----
raw: Raw = .{}, /// Extended squitter message type, the first five bits of ME. metype: u5 = 0, /// Extended squitter message subtype. mesub: u3 = 0, /// What a Comm-B reply was taken to be. commb_format: CommBFormat = .unknown,
// ---- What was decoded ----
/// Pressure altitude. altitude_baro: ?Altitude = null, /// Altitude from satellite navigation. altitude_geom: ?Altitude = null, /// Geometric minus barometric altitude, in feet. geom_delta: ?i32 = null, /// Direction of travel or of the nose. heading: ?Heading = null, /// Rate of change of track, degrees per second. track_rate: ?f32 = null, /// Roll angle in degrees; negative is a left roll. roll: ?f32 = null, /// Speed over the ground, in knots. gs: ?GroundSpeed = null, /// Indicated airspeed, knots. ias: ?u32 = null, /// True airspeed, knots. tas: ?u32 = null, /// Mach number. mach: ?f64 = null, /// Rate of change of barometric altitude, feet per minute. baro_rate: ?i32 = null, /// Rate of change of geometric altitude, feet per minute. geom_rate: ?i32 = null, /// The squawk, four octal digits packed one per hex nibble. squawk: ?u16 = null, /// The eight-character callsign, space padded. callsign: ?[ais_callsign_len]u8 = null, /// Wake turbulence and emitter category, A0 to D7 as one hex byte. category: ?u8 = null, /// Emergency or priority status. emergency: ?Emergency = null, /// Whether the aircraft says it is on the ground. airground: AirGround = .invalid,
/// Special position identification: the pilot pressed the ident button. spi: ?bool = null, /// The alert bit, set when the squawk has just been changed. alert: ?bool = null,
/// The unresolved position, if the message carried one. cpr: ?CprPosition = null, /// The resolved position, if the decoder could work one out. decoded_position: ?DecodedPosition = null,
accuracy: Accuracy = .{}, /// The aircraft's operational status, if this message was one. opstatus: ?OpStatus = null, nav: Nav = .{}, meteorology: Meteorology = .{},
/// The length of a callsign; see `ais.callsign_len`. const ais_callsign_len = 8;
/// A message with nothing decoded. pub const empty: Message = .{};
/// The meaningful bytes of the frame after correction. pub fn bytes(self: *const Message) []const u8 { return self.msg[0..self.len]; }
/// The meaningful bytes of the frame as received. pub fn verbatimBytes(self: *const Message) []const u8 { return self.verbatim[0..self.len]; }
/// The ICAO address without the non-ICAO marker. pub fn icaoAddress(self: *const Message) u24 { return @truncate(self.address); }
/// Whether the address is a real ICAO one. pub fn addressIsIcao(self: *const Message) bool { return self.address & non_icao_address == 0; }
/// How plausible a Mode S frame looked, worst to best. /// /// A receiver hears the same transmission more than once — a strong /// signal correlates at several sample offsets, and the same aircraft is /// heard by several network peers — and something has to choose between /// the copies. This is that ranking, and it is a total order rather than /// a number because what it encodes is a series of judgements that are /// not really commensurable: is a DF17 with one corrected bit from a /// known aircraft better evidence than a clean DF11 from an unknown one? /// Upstream decided yes, and the order below is that decision. /// /// Two members are cutoffs rather than outcomes: anything below /// `unknown_threshold` is discarded outright, and anything below /// `accept_threshold` is kept only for statistics. pub const ScoreRank = enum { /// A frame of nothing but zero bits. Technically a valid DF0, but no /// transponder sends one and noise produces them constantly. all_zeros, /// A downlink format nothing knows how to read. unknown_df, /// The CRC failed and no correction could rescue it. uncorrectable,
/// Cutoff: below this the frame is thrown away. unknown_threshold,
/// An address-overlaid format naming an aircraft never heard from. unreliable_unknown,
df11_iid_1error_unknown, df11_acq_1error_unknown, df11_iid_unknown,
df18_2error_unknown, df17_2error_unknown,
/// Cutoff: below this the frame is counted but not acted on. accept_threshold,
/// An address-overlaid format naming a known aircraft. Still the /// weakest thing worth acting on, because the "address" is just the /// CRC and could be anything. unreliable_known,
// Two-bit correction is a guess even when the address is known, so it // ranks below a clean frame from an aircraft nobody has heard of. df18_2error_known, df17_2error_known,
df18_1error_unknown, df17_1error_unknown,
/// A clean acquisition squitter from an unknown aircraft. Ranked /// above the corrected frames deliberately: without accepting one /// non-squitter format from an unknown aircraft, a Mode S-only /// aircraft would never be picked up at all. df11_acq_unknown,
df11_iid_1error_known, df11_acq_1error_known, df11_iid_known,
df18_1error_known, df17_1error_known,
df11_acq_known,
df18_unknown, df17_unknown, df18_known, df17_known,
/// Whether the frame is worth keeping at all. pub fn isPlausible(self: ScoreRank) bool { return @intFromEnum(self) >= @intFromEnum(ScoreRank.unknown_threshold); }
/// Whether the frame is worth acting on. pub fn isAcceptable(self: ScoreRank) bool { return @intFromEnum(self) >= @intFromEnum(ScoreRank.accept_threshold); } };
/// Whether this message was synthesised by a multilateration server /// rather than received. pub fn isMlat(self: *const Message) bool { return self.remote and self.timestamp_12mhz == mlat_timestamp; }};
const testing = std.testing;
test "an empty message decodes nothing" { const message: Message = .empty; try testing.expectEqual(@as(?Altitude, null), message.altitude_baro); try testing.expectEqual(@as(?[8]u8, null), message.callsign); try testing.expectEqual(AirGround.invalid, message.airground); try testing.expectEqual(@as(usize, 0), message.bytes().len);}
test "sources rank worst to best" { try testing.expect(@intFromEnum(Source.invalid) < @intFromEnum(Source.mode_ac)); try testing.expect(@intFromEnum(Source.mode_s) < @intFromEnum(Source.mode_s_checked)); try testing.expect(@intFromEnum(Source.tisb) < @intFromEnum(Source.adsb));}
test "address types rank best to worst" { try testing.expect(@intFromEnum(AddressType.adsb_icao) < @intFromEnum(AddressType.tisb_icao)); try testing.expect(@intFromEnum(AddressType.tisb_icao) < @intFromEnum(AddressType.adsb_other)); try testing.expect(@intFromEnum(AddressType.mode_a) < @intFromEnum(AddressType.unknown));}
test "the non-ICAO marker is outside the address" { var message: Message = .empty; message.address = 0x4840d6; try testing.expect(message.addressIsIcao()); try testing.expectEqual(@as(u24, 0x4840d6), message.icaoAddress());
message.address |= non_icao_address; try testing.expect(!message.addressIsIcao()); try testing.expectEqual(@as(u24, 0x4840d6), message.icaoAddress());}
test "format names" { try testing.expectEqualStrings("Extended Squitter", (Format{ .mode_s = 17 }).name()); try testing.expectEqualStrings("Comm-D Extended Length Message", (Format{ .mode_s = 27 }).name()); try testing.expectEqualStrings("reserved", (Format{ .mode_s = 3 }).name()); try testing.expectEqualStrings("Mode A/C Reply", @as(Format, .mode_ac).name());
try testing.expect((Format{ .mode_s = 17 }).is(17)); try testing.expect(!@as(Format, .mode_ac).is(17)); try testing.expect((Format{ .mode_s = 21 }).isAny(&.{ 20, 21 })); try testing.expect(!(Format{ .mode_s = 19 }).isAny(&.{ 20, 21 }));}
test "nav modes pack into a byte" { try testing.expect(!NavModes.none.any()); const modes_engaged: NavModes = .{ .autopilot = true, .lnav = true }; try testing.expect(modes_engaged.any()); try testing.expectEqual(@as(u8, 0b0001_0001), @as(u8, @bitCast(modes_engaged)));}
test "coarse TIS-B positions solve on the airborne grid" { try testing.expectEqual(cpr.Kind.airborne, CprType.coarse.kind()); try testing.expectEqual(cpr.Kind.surface, CprType.surface.kind());}