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#
opam install space-packet
Usage#
(* Create a telemetry packet *)
let pkt =
Space_packet.make_exn
~packet_type:Telemetry
~apid:100
~sequence_flags:Unsegmented
~sequence_count:42
"sensor data payload"
(* Encode to bytes *)
let bytes = Space_packet.encode pkt
(* Decode from bytes *)
match Space_packet.decode bytes with
| Ok decoded -> Printf.printf "APID: %d\n" (Space_packet.apid decoded)
| Error `Truncated -> Printf.printf "Packet truncated\n"
| Error (`Invalid_version v) -> Printf.printf "Invalid version: %d\n" v
Streaming I/O#
(* Write to a bytesrw writer *)
Space_packet.write writer pkt
(* Read from a bytesrw reader *)
match Space_packet.read reader with
| Ok pkt -> (* process packet *)
| Error _ -> (* handle error *)
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.make_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.