CCSDS Key-Value Notation parser
README.md

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 #

  • line is a classified line: Keyword, Data, Comment or Blank, and classify computes it.
  • parse_epoch reads both CCSDS epoch forms, calendar and day-of-year, as a Ptime.t.
  • state is a mutable cursor over the numbered lines of a document, built with of_string or of_channel and moved with peek, next, advance, skip_blanks and eof.
  • iter_block iterates over a delimited block such as META_START/META_STOP.
  • parse_pairs reads every KEY = VALUE pair with its line number, units such as [km] stripped by strip_unit.
  • parse_float and split_data read values.
  • error is the parse error type the message parsers share.

License #

ISC