Parse and encode CCSDS Conjunction Data Messages (CDM).
Supports both the KVN (Keyword=Value Notation) and XML formats per CCSDS 508.0-B-1. CDMs describe a predicted close approach between two space objects, including states, covariances, and collision probability.
parse/1 auto-detects the format based on the first non-whitespace
character: a leading < is treated as XML, anything else as KVN.
Every item of CCSDS 508.0-B-1 tables 3-1 to 3-4 and every comment is kept:
the header, the relative metadata/data (relative state, screening period
and volume), and for each object its metadata, OD parameters, additional
parameters, state and the RTN covariance through rows 7 to 9. A KVN comment
belongs to the block of the keyword after it. The covariance is held as
stated, without a positive-semidefinite check; CDM.ObjectData documents the
row groups.
Examples
{:ok, cdm} = Sidereon.CCSDS.CDM.parse(kvn_string)
cdm.tca # ~U[2010-03-13 22:37:52.618Z]
cdm.miss_distance_m # 715.0
cdm.collision_probability # 4.835e-05
# KVN output (default)
{:ok, kvn} = Sidereon.CCSDS.CDM.encode(cdm)
# XML output
{:ok, xml} = Sidereon.CCSDS.CDM.encode(cdm, format: :xml)
# Round-trip through XML
{:ok, cdm2} = Sidereon.CCSDS.CDM.parse(xml)
Summary
Types
An RTN triple whose components are each nil when not stated.
A CCSDS CDM. ccsds_cdm_vers is the version the message states, or nil;
the writers state it only when present. comments are the header comments
and relative_comments those of the relative metadata/data. The screening
period and entry and exit times are kept as written; screen_volume_m holds
the three screening-volume sizes.
Functions
Encode a CDM.
Encode a CDM to KVN format explicitly. Returns {:ok, text} or
{:error, reason}.
Encode a CDM to XML format explicitly.
Parse a CDM in either KVN or XML format.
Parse a CDM in KVN format explicitly. Skips format auto-detection.
Parse a CDM in XML format explicitly. Skips format auto-detection.
Convert a parsed CDM to inputs for Sidereon.Collision.probability/1.
Types
An RTN triple whose components are each nil when not stated.
@type t() :: %Sidereon.CCSDS.CDM{ ccsds_cdm_vers: String.t() | nil, collision_probability: float() | nil, collision_probability_method: String.t() | nil, comments: [String.t()], creation_date: DateTime.t() | nil, hard_body_radius_m: float() | nil, message_for: String.t() | nil, message_id: String.t() | nil, miss_distance_m: float() | nil, object1: Sidereon.CCSDS.CDM.ObjectData.t() | nil, object2: Sidereon.CCSDS.CDM.ObjectData.t() | nil, originator: String.t() | nil, relative_comments: [String.t()], relative_position_rtn_m: optional_triple(), relative_speed_m_s: float() | nil, relative_velocity_rtn_m_s: optional_triple(), screen_entry_time: String.t() | nil, screen_exit_time: String.t() | nil, screen_volume_frame: String.t() | nil, screen_volume_m: optional_triple(), screen_volume_shape: String.t() | nil, start_screen_period: String.t() | nil, stop_screen_period: String.t() | nil, tca: DateTime.t() | nil }
A CCSDS CDM. ccsds_cdm_vers is the version the message states, or nil;
the writers state it only when present. comments are the header comments
and relative_comments those of the relative metadata/data. The screening
period and entry and exit times are kept as written; screen_volume_m holds
the three screening-volume sizes.
Functions
@spec encode( t(), keyword() ) :: {:ok, String.t()} | {:error, Sidereon.CCSDS.Error.cdm()}
Encode a CDM.
Returns {:ok, text}, or {:error, reason} for a message the writer cannot
write so that its reader returns it unchanged (such as text with a line break
in KVN, or a retained comment that would read back as a hard-body radius the
message does not hold) or a covariance row group of the wrong length.
Options
:format-:kvn(default) or:xml
@spec encode_kvn(t()) :: {:ok, String.t()} | {:error, Sidereon.CCSDS.Error.cdm()}
Encode a CDM to KVN format explicitly. Returns {:ok, text} or
{:error, reason}.
@spec encode_xml(t()) :: {:ok, String.t()} | {:error, Sidereon.CCSDS.Error.cdm()}
Encode a CDM to XML format explicitly.
Produces a document matching the CCSDS 508.0-B-1 CDM XML schema's
top-level shape (cdm > header/body > segment > metadata/data). This
is the canonical XML form used for inter-system exchange alongside KVN.
Returns {:ok, text} or {:error, reason}.
@spec parse(String.t()) :: {:ok, t()} | {:error, Sidereon.CCSDS.Error.cdm()}
Parse a CDM in either KVN or XML format.
Format is auto-detected from the first non-whitespace character: <
routes to the XML parser, anything else to the KVN parser.
Returns {:ok, %CDM{}} or {:error, reason}.
@spec parse_kvn(String.t()) :: {:ok, t()} | {:error, Sidereon.CCSDS.Error.cdm()}
Parse a CDM in KVN format explicitly. Skips format auto-detection.
@spec parse_xml(String.t()) :: {:ok, t()} | {:error, Sidereon.CCSDS.Error.cdm()}
Parse a CDM in XML format explicitly. Skips format auto-detection.
Convert a parsed CDM to inputs for Sidereon.Collision.probability/1.