space-packet#
Pure OCaml implementation of CCSDS 133.0-B-2 Space Packet Protocol.
Overview#
Space packets are the fundamental data unit in CCSDS (Consultative Committee for Space Data Systems) systems. They carry telemetry, telecommand, and ancillary data between spacecraft and ground systems.
This library provides encoding and decoding of space packets with streaming I/O support via bytesrw.
Features#
- Full CCSDS 133.0-B-2 space packet primary header support
- Telemetry and telecommand packet types
- Sequence flags for packet segmentation
- Application Process Identifier (APID) handling
- Streaming I/O with bytesrw
- Zero-copy decoding where possible
Installation#
Install with opam:
$ opam install space-packet
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 space-packet
Usage#
(* Create a telemetry packet. *)
let pkt =
Space_packet.v_exn ~packet_type:Telemetry ~apid:100
~sequence_flags:Unsegmented ~sequence_count:42 "sensor data payload"
let bytes = Space_packet.encode pkt
let () =
match Space_packet.decode bytes with
| Ok decoded -> assert (Space_packet.apid decoded = 100)
| Error `Truncated -> failwith "truncated"
| Error (`Invalid_version v) -> Fmt.failwith "invalid version: %d" v
Streaming I/O#
let send writer = Space_packet.write writer pkt
let recv reader =
match Space_packet.read reader with
| Ok pkt -> Fmt.pr "APID: %d@." (Space_packet.apid pkt)
| Error _ -> Fmt.epr "decode failed@."
Packet Structure#
+------------------+------------------+
| Primary Header | Packet Data |
| (6 octets) | (1-65536 octets) |
+------------------+------------------+
Primary Header:
+---------+------+-----+------+---------+---------+-------------+
| Version | Type | SHF | APID | SeqFlag | SeqCnt | Data Length |
| 3 bits | 1b | 1b | 11b | 2 bits | 14 bits | 16 bits |
+---------+------+-----+------+---------+---------+-------------+
API#
Space_packet.make- Create a space packet (returns Result)Space_packet.v_exn- Create a space packet (raises on error)Space_packet.encode- Serialize packet to bytesSpace_packet.decode- Parse packet from bytesSpace_packet.write- Write packet to bytesrw writerSpace_packet.read- Read packet from bytesrw readerSpace_packet.apid- Get Application Process IDSpace_packet.packet_type- Get packet type (Telemetry/Telecommand)Space_packet.sequence_count- Get sequence counterSpace_packet.is_idle- Check if packet is an idle packet (APID 2047)
Related Work#
- CCSDS 133.0-B-2 - Space Packet Protocol specification
- ocaml-sle - CCSDS Space Link Extension protocols (uses space packets)
- ocaml-tcf - CCSDS Time Code Formats (often used in secondary headers)
- libcsp - Cubesat Space Protocol (C) - different protocol but similar concepts
- SatCat5 - Satellite communication library (C++/VHDL)
Licence#
ISC License. See LICENSE.md for details.