CCSDS 133.0-B Space Packet Protocol for OCaml
OCaml 60.9%
C 29.7%
PHP 1.8%
Dune 1.6%
Roff 0.6%
Other 5.4%
35 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-space-packet https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-space-packet
git@git.recoil.org:gazagnaire.org/ocaml-space-packet git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-space-packet

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

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 bytes
  • Space_packet.decode - Parse packet from bytes
  • Space_packet.write - Write packet to bytesrw writer
  • Space_packet.read - Read packet from bytesrw reader
  • Space_packet.apid - Get Application Process ID
  • Space_packet.packet_type - Get packet type (Telemetry/Telecommand)
  • Space_packet.sequence_count - Get sequence counter
  • Space_packet.is_idle - Check if packet is an idle packet (APID 2047)
  • 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.