object

# `ccsds_packetization`

Helpers for packetizing CCSDS space packets into TM and AOS service-data regions with cross-frame carryover and idle fill generation.

Availability:
`logtalk_load(ccsds_packetization(loader))`
Author: Paulo Moura
Version: 1:0:2
Date: 2026-06-16
Compilation flags:
`static, context_switching_calls`
Uses:
ccsds_packets(SecondaryHeaderLength)
list
type
Remarks:
(none)
Inherited public predicates:
(none)

## Public predicates

### `initial_state/1`

Returns the initial packetizer state.

Compilation flags:
`static`
Template:
`initial_state(State)`
Mode and number of proofs:
`initial_state(-compound)` - `one`

### `pending_packets/2`

Extracts the non-empty queued packets and pending trailing packet bytes buffered per frame type, spacecraft identifier, and virtual channel identifier.

Compilation flags:
`static`
Template:
`pending_packets(State,PendingPackets)`
Mode and number of proofs:
`pending_packets(+compound,-list(compound))` - `one_or_error`
Exceptions:
`State` is a variable:
`instantiation_error`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`

### `packetize_tm_packets/6`

Packetizes packets into the packet service region of a TM transfer frame, preserving any still-pending trailing packet bytes and queuing packets that do not fully fit.

Compilation flags:
`static`
Template:
`packetize_tm_packets(Frame,SecondaryHeaderLength,State,Packets,UpdatedFrame,UpdatedState)`
Mode and number of proofs:
`packetize_tm_packets(+compound,+integer,+compound,+list(compound),-compound,-compound)` - `one_or_error`
Exceptions:
`Frame`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid TM transfer frame term:
`domain_error(ccsds_tm_transfer_frame_term,Frame)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `packetize_tm_packets/7`

Packetizes packets into the packet service region of a TM transfer frame and also returns explicit packetization events.

Compilation flags:
`static`
Template:
`packetize_tm_packets(Frame,SecondaryHeaderLength,State,Packets,UpdatedFrame,UpdatedState,Events)`
Mode and number of proofs:
`packetize_tm_packets(+compound,+integer,+compound,+list(compound),-compound,-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frame`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid TM transfer frame term:
`domain_error(ccsds_tm_transfer_frame_term,Frame)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `packetize_aos_packets/6`

Packetizes packets into the packet service region of an AOS transfer frame, preserving any still-pending trailing packet bytes and queuing packets that do not fully fit.

Compilation flags:
`static`
Template:
`packetize_aos_packets(Frame,SecondaryHeaderLength,State,Packets,UpdatedFrame,UpdatedState)`
Mode and number of proofs:
`packetize_aos_packets(+compound,+integer,+compound,+list(compound),-compound,-compound)` - `one_or_error`
Exceptions:
`Frame`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid AOS transfer frame term:
`domain_error(ccsds_aos_transfer_frame_term,Frame)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `packetize_aos_packets/7`

Packetizes packets into the packet service region of an AOS transfer frame and also returns explicit packetization events.

Compilation flags:
`static`
Template:
`packetize_aos_packets(Frame,SecondaryHeaderLength,State,Packets,UpdatedFrame,UpdatedState,Events)`
Mode and number of proofs:
`packetize_aos_packets(+compound,+integer,+compound,+list(compound),-compound,-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frame`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid AOS transfer frame term:
`domain_error(ccsds_aos_transfer_frame_term,Frame)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `packetize_tm_frames/7`

Packetizes packets across a sequence of TM transfer frames. Packets that remain queued for the first frame channel are also returned.

Compilation flags:
`static`
Template:
`packetize_tm_frames(Frames,SecondaryHeaderLength,State,Packets,UpdatedFrames,RemainingPackets,UpdatedState)`
Mode and number of proofs:
`packetize_tm_frames(+list(compound),+integer,+compound,+list(compound),-list(compound),-list(compound),-compound)` - `one_or_error`
Exceptions:
`Frames`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frames` is neither a variable nor a valid list of TM transfer frame terms:
`domain_error(ccsds_tm_transfer_frame_terms,Frames)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `packetize_tm_frames/8`

Packetizes packets across a sequence of TM transfer frames and also returns explicit packetization events in frame order.

Compilation flags:
`static`
Template:
`packetize_tm_frames(Frames,SecondaryHeaderLength,State,Packets,UpdatedFrames,RemainingPackets,UpdatedState,Events)`
Mode and number of proofs:
`packetize_tm_frames(+list(compound),+integer,+compound,+list(compound),-list(compound),-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frames`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frames` is neither a variable nor a valid list of TM transfer frame terms:
`domain_error(ccsds_tm_transfer_frame_terms,Frames)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `packetize_aos_frames/7`

Packetizes packets across a sequence of AOS transfer frames. Packets that remain queued for the first frame channel are also returned.

Compilation flags:
`static`
Template:
`packetize_aos_frames(Frames,SecondaryHeaderLength,State,Packets,UpdatedFrames,RemainingPackets,UpdatedState)`
Mode and number of proofs:
`packetize_aos_frames(+list(compound),+integer,+compound,+list(compound),-list(compound),-list(compound),-compound)` - `one_or_error`
Exceptions:
`Frames`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frames` is neither a variable nor a valid list of AOS transfer frame terms:
`domain_error(ccsds_aos_transfer_frame_terms,Frames)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `packetize_aos_frames/8`

Packetizes packets across a sequence of AOS transfer frames and also returns explicit packetization events in frame order.

Compilation flags:
`static`
Template:
`packetize_aos_frames(Frames,SecondaryHeaderLength,State,Packets,UpdatedFrames,RemainingPackets,UpdatedState,Events)`
Mode and number of proofs:
`packetize_aos_frames(+list(compound),+integer,+compound,+list(compound),-list(compound),-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frames`, `SecondaryHeaderLength`, `State`, or `Packets` is a variable:
`instantiation_error`
`Frames` is neither a variable nor a valid list of AOS transfer frame terms:
`domain_error(ccsds_aos_transfer_frame_terms,Frames)`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`State` is neither a variable nor a valid packetizer state term:
`domain_error(ccsds_packetizer_state,State)`
`Packets` is neither a variable nor a valid list of CCSDS packet terms:
`domain_error(ccsds_packet_terms,Packets)`

### `generate_idle_packet/4`

Generates a telemetry idle packet using APID 2047, the given packet secondary header length, sequence count, and user-data length.

Compilation flags:
`static`
Template:
`generate_idle_packet(SecondaryHeaderLength,SequenceCount,UserDataLength,Packet)`
Mode and number of proofs:
`generate_idle_packet(+integer,+integer,+integer,-compound)` - `one_or_error`
Exceptions:
`SecondaryHeaderLength`, `SequenceCount`, or `UserDataLength` is a variable:
`instantiation_error`
`SecondaryHeaderLength` is neither a variable nor a valid CCSDS packet secondary header length:
`domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)`
`SequenceCount` is neither a variable nor a valid CCSDS packet sequence count:
`domain_error(ccsds_packet_sequence_count,SequenceCount)`
`UserDataLength` is neither a variable nor a valid idle-packet user-data length:
`domain_error(ccsds_idle_user_data_length,UserDataLength)`

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

(no local declarations; see entity ancestors if any)

## Operators

(none)