Expand description
NMEA 2000 parameter groups from CAN frames to the KINAVIS types.
Every NMEA 2000 device (GNSS, compass, sounder, AIS) sends parameter groups: fixed layouts of little-endian fields, carried in one 8-byte frame or, as a fast packet, in up to 32. Starting from frames delivered by the bus interface, this crate:
- Parses the identifier —
CanId— into thePgnand source address. - Reassembles fast packets in an
Assemblerwith fixed slots and a timeout, so a lost frame costs one group, not a slot. - Decodes the group into a
Messagewith kernel field types (Position,Speed,TrueCourse,Distance,Instant). “Not available” isNone, not the raw all-ones value.
No allocation, no panics on any input; builds for bare-metal targets and CI checks the strict-profile build for panic paths. The bus (CAN controller, driver, address claim) is the caller’s.
use kinavis_nmea2000::{Assembler, CanId, Frame, Message, Pgn};
use kinavis_kernel::{Instant, Utc};
let mut assembler = Assembler::new();
let now = Instant::<Utc>::from_unix_seconds(1_789_000_000);
// Position, rapid update, from address 35: 50.755°N 1.333°W in 1e-7°.
let id = CanId::new(0x09F8_0123)?;
assert_eq!(id.pgn(), Pgn::POSITION_RAPID_UPDATE);
let frame = Frame::new(id, &[0x30, 0x99, 0x40, 0x1E, 0xB0, 0x99, 0x34, 0xFF])?;
let Some(payload) = assembler.push(&frame, now)? else { panic!("in frames") };
let Message::PositionRapidUpdate(update) = Message::decode(&payload)? else {
panic!("not a position");
};
assert_eq!(format!("{:.3}", update.position.unwrap()), "50°45.300'N 001°19.980'W");§Supported PGNs
| Group | Decoded as |
|---|---|
| 129025 — position, rapid update | PositionRapidUpdate |
| 129026 — COG and SOG, rapid update | CourseAndSpeed |
| 129029 — GNSS position data | GnssPosition, and a kernel GnssFix from it |
| 127250 — vessel heading | VesselHeading |
| 128267 — water depth | WaterDepth |
| 129038 — AIS class A position report | AisPositionReport |
| 129039 — AIS class B position report | AisPositionReport |
Other PGNs pass the assembler only with an explicit transport
(Assembler::push_as) and decode as Message::Unsupported with the PGN
and the raw Payload.
§Feature flags
std(default) — standard library maths in the kernel.libm— forno_stdtargets:--no-default-features --features libm.serde— serialisation of the messages.
Structs§
- AisPosition
Report - AIS position report, class A or B.
- Assembler
- Fast-packet assembler with
Nslots. - CanId
- 29-bit extended CAN identifier, J1939 layout.
- Course
AndSpeed - Course and speed over ground, rapid update: PGN 129026.
- Frame
- CAN frame: identifier and up to 8 data bytes.
- Gnss
Position - GNSS position data, PGN 129029.
- Payload
- Complete PGN payload (single frame or reassembled fast packet), fixed capacity.
- Pgn
- Parameter group number.
- Position
Rapid Update - Position, rapid update: PGN 129025.
- Vessel
Heading - Vessel heading: PGN 127250.
- Water
Depth - Water depth: PGN 128267.
Enums§
- Gnss
System - Satellite system(s) of a fix.
- Integrity
- Receiver integrity monitoring status.
- Message
- Decoded parameter group.
- Nmea2000
Error - Why a frame could not be accepted, reassembled or decoded.
- Referenced
- Direction with its reference: true or magnetic north.
- Station
Class - Station class.
- Transport
- PGN transport on the bus.
Constants§
- DEFAULT_
TIMEOUT - Default timeout for an incomplete packet. Frames of one packet follow within milliseconds; the standard specifies 750 ms.
- MAX_
ASSEMBLIES - Default number of concurrent fast-packet assemblies.
- MAX_
PAYLOAD_ BYTES - Maximum fast-packet payload: 6 bytes in the first frame + 7 in each of up to 31 more.