- OCaml 65%
- C 21%
- Python 14%
- Shell <1%
ocaml-uslp #
CCSDS space links grew three frame formats over the years: TM frames for
telemetry, TC frames for telecommands and AOS frames for high-rate payload
data. (The payload is the instrument or equipment the mission flies for, such
as a camera or a radar; payload data is what it produces, usually far more than
the spacecraft's own housekeeping telemetry.) The Unified Space Link Protocol
(CCSDS 732.1-B-2) replaces them
with one transfer frame that serves every direction and adds a 16-bit
spacecraft identifier, multiplexer access points and a variable-length frame
counter. ocaml-uslp decodes and encodes USLP transfer frames in OCaml, and
exposes the same layout as wire codecs for zero-copy access to single fields.
Installation #
Install with opam:
$ opam install uslp
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 uslp
Usage #
(* Decode a USLP frame. *)
let decode_frame buf =
match Uslp.decode buf with
| Error e -> Fmt.epr "Error: %a@." Uslp.pp_error e
| Ok frame ->
Fmt.pr "SCID: %d, VCID: %d, MAP: %d@."
(Uslp.int_of_scid frame.header.scid)
(Uslp.int_of_vcid frame.header.vcid)
(Uslp.int_of_map_id frame.header.map_id)
(* Create and encode a USLP frame. *)
let encode_frame () =
let scid = Uslp.scid_exn 1000 in
let vcid = Uslp.vcid_exn 5 in
let map_id = Uslp.map_id_exn 3 in
let frame =
Uslp.v ~scid ~vcid ~map_id ~vcfc:12345 ~vcfc_len:2 "payload"
in
let encoded = Uslp.encode ~fecf:Uslp.Crc16 frame in
Fmt.pr "Encoded: %d bytes@." (String.length encoded)
(* Decode with VCFC and the 16-bit FECF. *)
let decode_with_fecf buf =
match Uslp.decode ~vcfc_len:2 ~expect_fecf:Uslp.Crc16 buf with
| Error e -> Fmt.epr "Error: %a@." Uslp.pp_error e
| Ok frame -> Fmt.pr "VCFC: %d@." frame.header.vcfc
(* The data field of a frame carrying complete Space Packets: a one-octet
TFDF Header, Construction Rule '111' and UPID 0 (732.1-B-2 4.1.4.2). *)
let packets_in frame =
match Uslp.Tfdf.decode frame.Uslp.data with
| Error `Truncated -> None
| Ok tfdf -> Some tfdf.Uslp.Tfdf.zone
Frame Format #
Primary header (7+ bytes):
Byte 0: TFVN(4b) | SCID[15:12](4b)
Byte 1: SCID[11:4](8b)
Byte 2: SCID[3:0](4b) | src_dest(1b) | VCID[5:3](3b)
Byte 3: VCID[2:0](3b) | MAP_ID(4b) | EOFPH(1b)
Byte 4-5: Frame Length - 1 (16b)
Byte 6: Bypass(1b) | PCC(1b) | Rsvd(2b) | OCF(1b) | VCFC_len(3b)
Byte 7+: VCFC (0-7 bytes based on vcfc_len)
Optional insert zone (variable)
Data field (variable)
Optional OCF (4 bytes) - Contains CLCW
Optional FECF (2 bytes) - CRC-16-CCITT, CCSDS 732.1-B-2 annex B
TFVN is the transfer frame version number, 12 for USLP (binary 1100). EOFPH (end of frame primary header) set means the header stops after its first four octets, a truncated frame for very short links. The bypass flag marks a frame that skips the receiver's sequence check, and PCC (protocol control command) marks a frame that carries a control command rather than user data. The insert zone is a fixed-size area, the same length on every frame of a physical channel, for isochronous data such as voice (CCSDS 732.1-B-2, sections 4.1.2 and 4.1.3).
Features #
- a virtual channel frame count (VCFC) of 0 to 7 bytes;
- a 16-bit spacecraft identifier, where AOS has 8 bits and TM 10;
- MAP identifiers, which multiplex several access points on one virtual channel;
- the source-or-destination indicator;
- no FECF, or the 16-bit FECF of 4.1.6.2 (CRC-16-CCITT, annex B).
On a Proximity-1 link the frame travels in a PLTU, whose CRC-32 (CCSDS
211.2-B-3 annex C) protects it in place of the FECF (annex C6); the
proximity1 package builds it with Proximity1.Pltu.encode.
Licence #
ISC