Skip to main content

Crate kinavis_ais

Crate kinavis_ais 

Source
Expand description

AIS messages from their NMEA sentences to the KINAVIS types.

A receiver delivers an AIS message as one or more !AIVDM sentences, 6 bits per character. kinavis-nmea0183 validates each sentence and yields a Vdm with the payload still armoured; this crate:

  1. Unarmours the payload into Bits, a fixed-capacity buffer read by bit offset and width as in the standard’s tables.
  2. Reassembles multi-sentence messages in an Assembler with fixed slots and a timeout, so a lost fragment costs one message, not a slot.
  3. Decodes into a Message with kernel field types: Position, Speed, TrueCourse, TargetId for the MMSI, Distance for draught, InlineStr for names. “Not available” is None, never a zero or a string of @.

No allocation, no panics on any input; builds for bare-metal targets and CI checks the strict-profile build for panic paths.

use kinavis_ais::{Assembler, Message};
use kinavis_kernel::{Instant, Utc};
use kinavis_nmea0183::{parse, Sentence};

let mut assembler = Assembler::new();
let now = Instant::<Utc>::from_unix_seconds(1_789_000_000);

let line = b"!AIVDM,1,1,,A,13aEOK?P00PD2wVMdLDRhgvL289?,0*26\r\n";
let Sentence::Vdm(vdm) = parse(line)? else { panic!("not an AIS sentence") };
let Some(bits) = assembler.push(&vdm, now)? else { panic!("in fragments") };
let Message::PositionReport(report) = Message::decode(&bits)? else { panic!("not a position") };

assert_eq!(report.mmsi.number(), 244_670_316);
assert_eq!(format!("{:.3}", report.position.unwrap()), "51°53.685'N 004°22.757'E");
assert_eq!(report.course.map(|c| c.degrees()), Some(70.6));
assert_eq!(report.speed.map(|s| s.knots()), Some(0.0));
assert_eq!(report.heading, None, "not available, not north");

The caller builds the TargetObservation for the traffic picture from these fields; this crate depends only on the kernel and the sentence crate.

§Supported messages

MessageDecoded as
1, 2, 3 — class A position reportPositionReport
5 — class A static and voyage dataStaticAndVoyageData
18 — class B position reportPositionReport
19 — class B extended position reportPositionReport, with name, type and dimensions
21 — aid to navigationAidToNavigation
24 — class B static data report, part A or BStaticDataReport

Other well-formed messages decode as Message::Unsupported with the message type and the raw Bits.

§Feature flags

  • std (default) — standard library maths in the kernel.
  • libm — for no_std targets: --no-default-features --features libm.
  • serde — serialisation of the messages.

Structs§

AidToNavigation
Aid-to-navigation report.
Assembler
Fragment assembler with N slots.
Bits
Message bits in a fixed-capacity buffer.
ClassBStaticData
Class B static data, part B.
Dimensions
Dimensions from the reported position to bow, stern, port and starboard.
Eta
ETA, UTC, as far as given.
InlineStr
Short inline string.
PositionReport
Position report.
ShipType
Ship and cargo type, as the standard’s two-digit code.
StaticAndVoyageData
Class A static and voyage data: message 5.
StaticDataReport
Class B static data report: message 24, sent as two parts.
Vdm
AIS message or one fragment of it.

Enums§

AidType
Aid-to-navigation type.
AisError
Why a payload could not be unarmoured, reassembled or decoded.
Channel
AIS radio channel.
HazardCategory
Cargo hazard category (A most hazardous, D least).
Mark
IALA mark type of a beacon or buoy.
Message
Decoded AIS message.
NavigationStatus
Class A navigational status.
PositionFixingDevice
Position fixing device type.
Quadrant
Cardinal quadrant: the side of the danger where safe water lies.
ShipCategory
Ship categories.
StaticDataPart
Parts of a class B static data report.
StationClass
Station class.
Turn
Class A rate of turn.

Constants§

DEFAULT_TIMEOUT
Default timeout for an incomplete message.
MAX_ASSEMBLIES
Default number of concurrent assemblies.
MAX_MESSAGE_BITS
Maximum message length in bits.