- OCaml 100%
kvn #
CCSDS Key-Value Notation parser.
Space agencies exchange orbits, attitudes and tracking data as CCSDS navigation
data messages: the Orbit Ephemeris and Orbit Parameter Messages (OEM and OPM,
CCSDS 502.0-B-3) and the OCM, which carries both kinds of orbit data with
manoeuvres and covariance in one message, the Tracking Data Message (TDM,
503.0-B), the Attitude Data Messages (ADM, 504.0-B), the Conjunction Data
Message (CDM, 508.0-B), which warns of a close approach between two objects, and
others. Most of them are written in Key-Value Notation (KVN): KEY = VALUE
lines, data lines, comments and START/STOP blocks, defined in CCSDS
502.0-B-3 Annex A. kvn is the layer every such message parser shares. It
classifies lines, parses CCSDS epochs, walks a document line by line and
iterates over a delimited block, and the message parsers build on it.
Installation #
Install with opam:
$ opam install kvn
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install kvn
Usage #
let kvn_data =
"CCSDS_OEM_VERS = 2.0\n\
META_START\n\
OBJECT_NAME = ISS\n\
META_STOP\n"
(* Parse a KVN file line by line *)
let scan () =
let st = Kvn.of_string kvn_data in
while not (Kvn.eof st) do
(match Kvn.next st with
| Some (_n, line) ->
(match Kvn.classify line with
| Kvn.Keyword (k, v) -> Printf.printf "%s = %s\n" k v
| Kvn.Data d -> Printf.printf "data: %s\n" d
| Kvn.Comment c -> Printf.printf "# %s\n" c
| Kvn.Blank -> ())
| None -> ())
done
(* Iterate over a metadata block *)
let iter () =
let st = Kvn.of_string kvn_data in
Kvn.iter_block ~start:"META_START" ~stop:"META_STOP" st
~on_keyword:(fun k v -> Printf.printf "%s = %s\n" k v)
~on_data:(fun _n _d -> ())
API Overview #
lineis a classified line:Keyword,Data,CommentorBlank, andclassifycomputes it.parse_epochreads both CCSDS epoch forms, calendar and day-of-year, as aPtime.t.stateis a mutable cursor over the numbered lines of a document, built withof_stringorof_channeland moved withpeek,next,advance,skip_blanksandeof.iter_blockiterates over a delimited block such asMETA_START/META_STOP.parse_pairsreads everyKEY = VALUEpair with its line number, units such as[km]stripped bystrip_unit.parse_floatandsplit_dataread values.erroris the parse error type the message parsers share.
License #
ISC