Expand description
§CCSDS NDM
A high-performance, type-safe library for parsing and generating CCSDS Navigation Data Messages (NDM) in both KVN (Key-Value Notation) and XML formats.
This crate is designed for mission-critical space applications where correctness, performance, and adherence to standards are paramount.
§Key Features
- Comprehensive Support: Full support for OPM, OMM, OEM, OCM, CDM, TDM, RDM, AEM, APM, and ACM messages.
- Format Agnostic: Seamlessly convert between KVN and XML formats.
- Type Safety: Strictly typed units (e.g.,
km,deg,s) prevent physical unit errors. - High Performance Parsing: Utilizes
winnowandquick-xmlfor efficient, low-allocation parsing. - Ergonomic Construction: Uses the builder pattern (via the
boncrate) for safe and easy message creation. - Standard Compliant: Validates messages against CCSDS 502.0-B-3 and related standards.
§Architecture
The library is organized around a few core concepts:
NdmTrait: The unifying interface for all message types. It defines the standardto_kvn,from_kvn,to_xml, andfrom_xmlmethods.MessageTypeEnum: A container that holds any valid NDM. This is the primary return type when parsing files with unknown contents (auto-detection).- Strong Typing: All physical quantities (Distance, Velocity, Mass, etc.) are wrapped in the
UnitValuestruct, ensuring that units are always tracked and validated.
§Quick Start
§1. Parse any NDM file (auto-detection)
The library automatically detects whether the input is KVN or XML and what message type it contains.
use ccsds_ndm::{from_file, MessageType};
let ndm = from_file("example.opm").unwrap();
match ndm {
MessageType::Opm(opm) => {
println!("Object: {}", opm.body.segment.metadata.object_name);
}
MessageType::Oem(oem) => {
println!("Ephemeris points: {}", oem.body.segment[0].data.state_vector.len());
}
_ => println!("Other message type"),
}§2. Parse a specific message type
If you know the message type in advance, you can parse it directly:
use ccsds_ndm::messages::opm::Opm;
use ccsds_ndm::traits::Ndm;
// Parses strict KVN for OPM
let opm = Opm::from_kvn("CCSDS_OPM_VERS = 3.0\n...").unwrap();§3. Generate a message using the Builder Pattern
Creating messages from scratch is safe and verbose-free using the builder() methods.
use ccsds_ndm::messages::opm::{Opm, OpmBody, OpmSegment, OpmMetadata, OpmData};
use ccsds_ndm::common::{OdmHeader, StateVector};
use ccsds_ndm::types::{Epoch, Position, Velocity};
use ccsds_ndm::traits::Ndm;
let opm = Opm::builder()
.version("3.0")
.header(OdmHeader::builder()
.creation_date("2024-01-01T00:00:00".parse().unwrap())
.originator("EXAMPLE")
.build())
.body(OpmBody::builder()
.segment(OpmSegment::builder()
.metadata(OpmMetadata::builder()
.object_name("SATELLITE")
.object_id("2024-001A")
.center_name("EARTH")
.ref_frame("GCRF")
.time_system("UTC")
.build())
.data(OpmData::builder()
.state_vector(StateVector::builder()
.epoch("2024-01-01T12:00:00".parse().unwrap())
.x(Position::new(7000.0, None))
.y(Position::new(0.0, None))
.z(Position::new(0.0, None))
.x_dot(Velocity::new(0.0, None))
.y_dot(Velocity::new(7.5, None))
.z_dot(Velocity::new(0.0, None))
.build())
.build())
.build())
.build())
.build();
// Convert to KVN string
println!("{}", opm.to_kvn().unwrap());§4. Serialize to KVN or XML
use ccsds_ndm::{from_file, MessageType};
let ndm = from_file("example.opm").unwrap();
// Serialize to string
let kvn_string = ndm.to_kvn().unwrap();
let xml_string = ndm.to_xml().unwrap();
// Write to file
ndm.to_xml_file("output.xml").unwrap();§Modules
Re-exports§
pub use validation::take_warnings as take_validation_warnings;pub use validation::ValidationMode;
Modules§
- common
- Contains Rust definitions for common structures
from
ndmxml-4.0.0-common-4.0.xsdused by OEM. - detect
- error
- kvn
- Key-Value Notation (KVN) support.
- messages
- Supported CCSDS Navigation Data Message (NDM) types.
- traits
- Core traits for CCSDS NDM message handling.
- types
- utils
- Utility functions and serialization helpers for CCSDS NDM.
- validation
- versioning
- Centralized version policy for CCSDS message roots.
- xml
- XML format support.
Macros§
- parse_
block - Macro for declarative KVN block parsing.
Enums§
- Message
Type - A generic container for any parsed NDM message.
Functions§
- from_
file - Parse an NDM from a file path, auto-detecting the message format (KVN or XML) and type.
- from_
file_ with_ mode - Parse an NDM from a file with explicit validation mode.
- from_
str - Parse an NDM from a string, auto-detecting the message format (KVN or XML) and type.
- from_
str_ with_ mode - Parse an NDM from a string with explicit validation mode.