Packet Utilisation Standard (ECSS-E-ST-70-41C)
README.md

pus #

Packet Utilisation Standard (ECSS-E-ST-70-41C) codecs in OCaml.

A spacecraft and its ground segment exchange telecommands and telemetry as CCSDS Space Packets (CCSDS 133.0-B-2). The Space Packet header names the application process a packet belongs to and says nothing about what the packet asks for or reports. ESA missions settle that with the Packet Utilisation Standard (PUS). PUS adds a secondary header holding a service type, a subtype and source or destination identifiers, and after it the service's own data, such as a housekeeping report or a schedule of time-tagged commands. pus encodes and decodes the secondary header and the data of every service type in the standard.

An application process is a piece of on-board software that sends and receives packets. Each Space Packet names one by its 11-bit Application Process Identifier (APID). Housekeeping is the telemetry a spacecraft sends about its own health, such as temperatures, voltages and modes, as sets of parameters sampled at a fixed interval.

Supported Services #

Service Name Subtypes
ST[1] Request Verification TM[1,1-8] acceptance/start/progress/completion, TM[1,10] routing failure
ST[2] Device Access On/off, register load and dump, CPDU, physical and logical device commands (TC[2,1-2,4-5,7-8,10-11], TM[2,6,9,12])
ST[3] Housekeeping Housekeeping, diagnostic and parameter functional reporting subservices (TC[3,1-9,11,27-34,37-40,42-44], TM[3,10,12,25,26,35,36,41])
ST[4] Parameter Statistics Reporting Statistics reporting and definition management (TC[4,1,3-8], TM[4,2,9])
ST[5] Event Reporting TM[5,1-4] info/low/medium/high severity, TC[5,5-7] enable/disable/report, TM[5,8] disabled-events report
ST[6] Memory Management Load, dump, check, scrubbing and write protection, raw and object memory (TC[6,1-3,5,7,9,11-17,19-22], TM[6,4,6,8,10,18])
ST[8] Function Management TC[8,1] perform a function, its application data carried verbatim. A deprecated backward-compatibility service (§6.8.1.1)
ST[9] Time Management TC[9,1] set the time report generation rate. TM[9,2] and TM[9,3] carry no PUS secondary header, so they are time_reports rather than services
ST[11] Time-Based Scheduling Schedule execution, insertion, deletion, time shift, sub-schedules and groups (TC[11,1-9,11-12,14-18,20-26], TM[11,10,13,19,27])
ST[12] On-Board Monitoring Parameter monitoring and functional monitoring subservices (TC[12,1-8,10,13,15-25,27], TM[12,9,11,12,14,26,28])
ST[13] Large Packet Transfer TM[13,1-3] downlink parts, TC[13,9-11] uplink parts, TM[13,16] uplink abortion report
ST[14] Real-Time Forwarding Control Forward-control configuration for application processes, housekeeping, diagnostics and events (TC[14,1-3,5-7,9-11,13-15], TM[14,4,8,12,16])
ST[15] On-Board Storage and Retrieval Packet store storage selection, retrieval and store management (TC[15,1-5,9,11-12,14-18,20-22,24-35,37,39], TM[15,6,13,19,23,36,38,40])
ST[17] Test TC[17,1] ping, TM[17,2] pong, TC[17,3] connection test, TM[17,4] connection test report
ST[18] On-Board Control Procedure OBCP load, activate, stop, suspend, resume, abort and engine control (TC[18,1-8,12-17,19-22], TM[18,9,18])
ST[19] Event-Action Event-action definition management and status reporting (TC[19,1-6,8-10], TM[19,7,11])
ST[20] Parameter Management Report and set parameter values, parameter definition management (TC[20,1,3-6], TM[20,2,7])
ST[21] Request Sequencing Sequence load, activate, abort, checksum and content reporting (TC[21,1-6,8-9,11,13], TM[21,7,10,12,14])
ST[22] Position-Based Scheduling The ST[11] shape against orbit position, plus TC[22,28] set orbit number (TC[22,1-9,11-12,14-18,20-26,28], TM[22,10,13,19,27])
ST[23] File Management File and directory handling, plus the file copy subservice (TC[23,1-3,5-7,9-12,14-22,24], TM[23,4,8,13,23])

The table lists every service type ECSS-E-ST-70-41C defines. The standard gives no service to type numbers 7, 10 and 16, and mission-specific services start at ST[128]. A packet with a service type outside the table is kept as raw bytes so it can be passed on unchanged.

The library does not keep the TM message type counter (§7.4.3.1, Figure 7-7), which is state held per application process. It always encodes the counter as 0 (requirement 7.4.3.1h) and ignores it on decode.

Installation #

Install with opam:

$ opam install pus

If opam cannot find the package, it has probably not reached the public opam-repository yet. Add the overlay repository and install from there:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install pus

Usage #

(* Send a ping (are-you-alive test). *)
let ping = Pus.v_tc (ST17 Test)
let data = Pus.encode TC ping

(* Wrap in a CCSDS space packet. *)
let sent =
  match Pus.to_space_packet ~apid:100 TC ping with
  | Ok sp -> Space_packet.encode sp
  | Error _ -> failwith "invalid parameters"

(* Decode a received telemetry packet. The width of the time field in its
   secondary header is the mission's own declaration (ECSS-E-ST-70-41C
   7.4.3.1 j) and is nowhere on the wire, so it is passed in: here a mission
   declaring PFC 1, a 6-octet CDS time. *)
let tm_time_size =
  match Pus.time_size_of_pfc 1 with Ok n -> Some n | Error _ -> None

let report received_sp =
  match Pus.of_space_packet ~tm_time_size received_sp with
  | Ok pus ->
      Fmt.pr "Service %d,%d@." (Pus.service_type pus)
        (Pus.service_subtype pus)
  | Error `Not_pus -> Fmt.pr "Not a PUS packet@."
  | Error `Undeclared_tm_time_size ->
      Fmt.pr "Telemetry needs the mission's time field width@."
  | Error _ -> Fmt.pr "Decode error@."

The PFC is the Parameter Format Code of the absolute-time parameter type. PFC 1 is the CCSDS Day Segmented time code (CDS, CCSDS 301.0-B-4 section 3.3) without a sub-millisecond field. It takes 6 octets, a 2-octet day count followed by a 4-octet millisecond of the day. PFC 2 adds 2 octets of microseconds for 8 octets in all. PFC 3 to 46 are CCSDS Unsegmented time codes of other widths, and Pus.time_size_of_pfc gives each width.

Event Reporting #

(* Report a high-severity event *)
let evt =
  Pus.v_tm ~destination_id:0
    (ST5 (Event { severity = High; event_id = 42; data = "\x01\x02" }))

Housekeeping #

(* Generate a housekeeping parameter report *)
let hk =
  Pus.v_tm
    (ST3 (Hk_report {
      sid = 1;
      params = [
        { param_id = 10; value = "\x00\x2A" };
        { param_id = 11; value = "\xFF" };
      ]
    }))

(* Create a housekeeping parameter report structure with one super
   commutated group *)
let create_structure =
  Pus.v_tc
    (ST3 (Create_hk_structure {
      sid = 1;
      collection_interval = 4;
      parameters = {
        simple = [ 10; 11 ];
        super_commutated = [ { repetition_count = 2; parameters = [ 20; 21 ] } ];
      };
    }))

A super-commutated group is sampled more than once per collection interval. With repetition_count = 2, parameters 20 and 21 appear twice in each report, so they are sampled twice as often as the simple parameters 10 and 11 (ECSS-E-ST-70-41C section 6.3.3.3).

PUS Data-Field Header #

Telecommand (TC):

+----------+---------+---------+---------+-------+
| Version  | Ack     | Service | Subtype | Src   |
| 4 bits   | 4 bits  | 8 bits  | 8 bits  | 16b   |
+----------+---------+---------+---------+-------+

Telemetry (TM):

+----------+----------+---------+---------+-------+------+
| Version  | SC Time  | Service | Subtype | Dest  | Time |
| 4 bits   | Ref Sts  | 8 bits  | 8 bits  | 16b   | var  |
|          | 4 bits   |         |         |       |      |
+----------+----------+---------+---------+-------+------+

Licence #

ISC. See LICENSE.md.