tm#
CCSDS TM (Telemetry) Transfer Frames for OCaml.
Overview#
This library implements parsing and encoding of CCSDS TM Transfer Frames as specified in CCSDS 132.0-B-3. TM frames are the fundamental data unit for transporting telemetry from spacecraft to ground stations.
Features#
- TM frame primary header (6 bytes) encoding/decoding
- Operational Control Field (OCF) with CLCW support
- Frame Error Control Field (FECF) using CRC-16-CCITT
- Command Link Control Word (CLCW) for COP-1 protocol
- Typed spacecraft ID (SCID) and virtual channel ID (VCID)
- Security-hardened parsing with bounds checking
Installation#
opam install tm
Usage#
(* Create a TM frame *)
let scid = Tm.scid_exn 100 in
let vcid = Tm.vcid_exn 2 in
let data = String.make 1103 '\x00' in
let frame = Tm.make ~scid ~vcid ~mcfc:1 ~vcfc:2 data in
(* Encode to bytes *)
let bytes = Tm.encode frame in
(* Decode from bytes *)
match Tm.decode bytes with
| Ok frame -> Printf.printf "SCID: %d\n" (Tm.scid_to_int frame.header.scid)
| Error e -> Format.printf "Error: %a\n" Tm.pp_error e
Working with CLCW#
(* Extract CLCW from frame OCF *)
match Tm.get_clcw frame with
| Ok clcw ->
Printf.printf "Report value (N(R)): %d\n" clcw.report_value;
if clcw.flags.lockout then print_endline "FARM-1 in lockout!"
| Error `No_ocf -> print_endline "No OCF present"
| Error (`Invalid_vcid _) -> print_endline "Invalid VCID in CLCW"
(* Create a CLCW *)
let clcw = Tm.make_clcw ~vcid ~report_value:42 ~lockout:false () in
let ocf_word = Tm.encode_clcw clcw in
Frame Structure#
+----------------+-------------+------+------+
| Primary Header | Data Field | OCF | FECF |
| (6 bytes) | (variable) | (4B) | (2B) |
+----------------+-------------+------+------+
Standard CCSDS frame length is 1115 bytes (configurable).
API#
Types#
Tm.scid- Spacecraft ID (10 bits, 0-1023)Tm.vcid- Virtual Channel ID (3 bits, 0-7)Tm.header- TM frame primary headerTm.clcw- Command Link Control WordTm.t- Complete TM frame
Functions#
Tm.decode- Parse TM frame from bytesTm.encode- Serialize TM frame to bytesTm.compute_fecf- Calculate CRC-16-CCITTTm.get_clcw- Extract CLCW from frame OCF
References#
- CCSDS 132.0-B-3 - TM Space Data Link Protocol specification
- CCSDS 232.1-B-2 - Communications Operation Procedure-1 (COP-1)
Licence#
MIT License. See LICENSE.md for details.