object

# `ccsds(SecondaryHeaderLength)`

- `SecondaryHeaderLength` - Length in bytes of the secondary header when present (0 for no secondary header parsing, or a positive integer).

CCSDS Space Packet parser following the CCSDS 133.0-B-2 standard. Parses binary packet data including optional secondary headers.

Availability:
`logtalk_load(ccsds(loader))`
Author: Paulo Moura
Version: 0:5:1
Date: 2026-02-04
Compilation flags:
`static, context_switching_calls`
Uses:
list
reader
Remarks:
(none)
Inherited public predicates:
(none)

## Public predicates

### `parse/2`

Parses CCSDS packet(s) from a source into a list of packet terms. The source can be `file(File)`, `stream(Stream)`, or `bytes(Bytes)`.

Compilation flags:
`static`
Template:
`parse(Source,Packets)`
Mode and number of proofs:
`parse(+compound,-list(compound))` - `one_or_error`
Exceptions:
`Source` is a variable:
`instantiation_error`
`Source` is neither a variable nor a valid source:
`domain_error(ccsds_source,Source)`
`Source` is a valid source but the data cannot be parsed as a CCSDS packet:
`domain_error(ccsds_byte_sequence,Bytes)`

### `generate/2`

Generates CCSDS packet bytes to a sink from a list of packet terms. The sink can be `file(File)`, `stream(Stream)`, or `bytes(Bytes)`. For `file(File)` and `stream(Stream)`, writes to the binary file or stream. For `bytes(Bytes)`, unifies Bytes with the generated byte list.

Compilation flags:
`static`
Template:
`generate(Sink,Packets)`
Mode and number of proofs:
`generate(+compound,+list(compound))` - `one_or_error`
Exceptions:
`Sink` is a variable:
`instantiation_error`
`Sink` is neither a variable nor a valid sink:
`domain_error(ccsds_sink,Sink)`
`Packets` is a partial list or a list with an element `Packet` which is a variable:
`instantiation_error`
An element `Packet` of the list `Packets` is neither a variable nor a valid CCSDS packet term:
`domain_error(ccsds_packet_term,Packet)`

### `generate/3`

Generates a list of bytes from a CCSDS packet term with an open tail. Mainly used when generating arbitrary CCSDS packets.

Compilation flags:
`static`
Template:
`generate(Packet,Bytes,Tail)`
Mode and number of proofs:
`generate(+compound,-list(byte),--variable)` - `one_or_error`
Exceptions:
`Packet` is a variable:
`instantiation_error`
`Packet` is neither a variable nor a valid CCSDS packet term:
`domain_error(ccsds_packet_term,Packet)`

### `version/2`

Extracts the version number from a packet (always 0 for CCSDS Space Packets).

Compilation flags:
`static`
Template:
`version(Packet,Version)`
Mode and number of proofs:
`version(+compound,-integer)` - `one`

### `type/2`

Extracts the packet type from a packet. Returns `telemetry` or `telecommand`.

Compilation flags:
`static`
Template:
`type(Packet,Type)`
Mode and number of proofs:
`type(+compound,-atom)` - `one`

### `secondary_header_flag/2`

Extracts the secondary header flag. Returns `absent` or `present`.

Compilation flags:
`static`
Template:
`secondary_header_flag(Packet,Flag)`
Mode and number of proofs:
`secondary_header_flag(+compound,-atom)` - `one`

### `apid/2`

Extracts the Application Process Identifier (APID) from a packet.

Compilation flags:
`static`
Template:
`apid(Packet,APID)`
Mode and number of proofs:
`apid(+compound,-integer)` - `one`

### `sequence_flags/2`

Extracts the sequence flags. Returns `continuation`, `first`, `last`, or `standalone`.

Compilation flags:
`static`
Template:
`sequence_flags(Packet,Flags)`
Mode and number of proofs:
`sequence_flags(+compound,-atom)` - `one`

### `sequence_count/2`

Extracts the packet sequence count (0-16383).

Compilation flags:
`static`
Template:
`sequence_count(Packet,Count)`
Mode and number of proofs:
`sequence_count(+compound,-integer)` - `one`

### `data_length/2`

Extracts the packet data length field value.

Compilation flags:
`static`
Template:
`data_length(Packet,Length)`
Mode and number of proofs:
`data_length(+compound,-integer)` - `one`

### `user_data/2`

Extracts the user data field as a list of bytes.

Compilation flags:
`static`
Template:
`user_data(Packet,Data)`
Mode and number of proofs:
`user_data(+compound,-list(byte))` - `one`

### `secondary_header/2`

Extracts the secondary header. Returns none if not present, or secondary_header(Bytes) with the raw bytes.

Compilation flags:
`static`
Template:
`secondary_header(Packet,SecondaryHeader)`
Mode and number of proofs:
`secondary_header(+compound,-compound)` - `one`

### `secondary_header_time/2`

Extracts time from a secondary header as cuc_time(Coarse, Fine) for CCSDS Unsegmented Time Code. Fails if no secondary header or time cannot be parsed.

Compilation flags:
`static`
Template:
`secondary_header_time(Packet,Time)`
Mode and number of proofs:
`secondary_header_time(+compound,-compound)` - `zero_or_one`

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

(no local declarations; see entity ancestors if any)

## Operators

(none)