kvn#
CCSDS Key-Value Notation parser.
Typed parser for CCSDS Key-Value Notation (KVN), the text format used by OEM, OCM, TDM, ADM, CDM, and other CCSDS navigation data messages. Provides line classification, epoch parsing, block iteration, and low-level parsing primitives.
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#
type line--Keyword of string * string,Data of string,Comment of string,Blankclassify-- Classify a raw KVN lineparse_epoch-- Parse CCSDS epoch string toPtime.ttype state-- Mutable line-by-line parser stateof_string,of_channel-- Create parser from string or channelpeek,next,advance,skip_blanks,eof-- Parser navigationiter_block-- Iterate over a delimited block (e.g.,META_START/META_STOP)expect_keyword-- Check and consume a specific keywordparse_float,parse_int,parse_floats,split_data-- Value parsing
License#
ISC