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:
- Unarmours the payload into
Bits, a fixed-capacity buffer read by bit offset and width as in the standard’s tables. - Reassembles multi-sentence messages in an
Assemblerwith fixed slots and a timeout, so a lost fragment costs one message, not a slot. - Decodes into a
Messagewith kernel field types:Position,Speed,TrueCourse,TargetIdfor the MMSI,Distancefor draught,InlineStrfor names. “Not available” isNone, 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
| Message | Decoded as |
|---|---|
| 1, 2, 3 — class A position report | PositionReport |
| 5 — class A static and voyage data | StaticAndVoyageData |
| 18 — class B position report | PositionReport |
| 19 — class B extended position report | PositionReport, with name, type and dimensions |
| 21 — aid to navigation | AidToNavigation |
| 24 — class B static data report, part A or B | StaticDataReport |
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— forno_stdtargets:--no-default-features --features libm.serde— serialisation of the messages.
Structs§
- AidTo
Navigation - Aid-to-navigation report.
- Assembler
- Fragment assembler with
Nslots. - Bits
- Message bits in a fixed-capacity buffer.
- ClassB
Static Data - 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.
- Inline
Str - Short inline string.
- Position
Report - Position report.
- Ship
Type - Ship and cargo type, as the standard’s two-digit code.
- Static
AndVoyage Data - Class A static and voyage data: message 5.
- Static
Data Report - 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.
- Hazard
Category - Cargo hazard category (A most hazardous, D least).
- Mark
- IALA mark type of a beacon or buoy.
- Message
- Decoded AIS message.
- Navigation
Status - Class A navigational status.
- Position
Fixing Device - Position fixing device type.
- Quadrant
- Cardinal quadrant: the side of the danger where safe water lies.
- Ship
Category - Ship categories.
- Static
Data Part - Parts of a class B static data report.
- Station
Class - 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.