object

# `ccsds_tc_services`

Helpers for CCSDS telecommand segment extraction, insertion, and cross-frame TC service reassembly.

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

## Public predicates

### `valid_segment/1`

True if the argument is a valid CCSDS telecommand segment term.

Compilation flags:
`static`
Template:
`valid_segment(Segment)`
Mode and number of proofs:
`valid_segment(@compound)` - `zero_or_one`

### `sequence_flags/2`

Extracts the telecommand segment sequence flags.

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

### `map_id/2`

Extracts the telecommand service-unit MAP identifier from either a telecommand segment term or a provenance-aware reassembled telecommand service-unit term.

Compilation flags:
`static`
Template:
`map_id(ServiceUnit,MapId)`
Mode and number of proofs:
`map_id(+compound,-integer)` - `one`

### `valid_map_dispatch/1`

True if the argument is a valid MAP-aware dispatch term grouping complete telecommand service units for a single MAP identifier.

Compilation flags:
`static`
Template:
`valid_map_dispatch(Dispatch)`
Mode and number of proofs:
`valid_map_dispatch(@compound)` - `zero_or_one`

### `dispatch_map_id/2`

Extracts the MAP identifier from a MAP-aware dispatch term.

Compilation flags:
`static`
Template:
`dispatch_map_id(Dispatch,MapId)`
Mode and number of proofs:
`dispatch_map_id(+compound,-integer)` - `one`

### `dispatch_service_units/2`

Extracts the complete telecommand service units from a MAP-aware dispatch term.

Compilation flags:
`static`
Template:
`dispatch_service_units(Dispatch,ServiceUnits)`
Mode and number of proofs:
`dispatch_service_units(+compound,-list(compound))` - `one`

### `segment_header_suffix/2`

Extracts the mission-specific segment-header suffix bytes. Returns the empty list when the segment has no mission-specific suffix.

Compilation flags:
`static`
Template:
`segment_header_suffix(Segment,HeaderSuffix)`
Mode and number of proofs:
`segment_header_suffix(+compound,-list(byte))` - `one`

### `valid_reassembled_segment/1`

True if the argument is a valid provenance-aware reassembled telecommand service-unit term.

Compilation flags:
`static`
Template:
`valid_reassembled_segment(ReassembledSegment)`
Mode and number of proofs:
`valid_reassembled_segment(@compound)` - `zero_or_one`

### `segment_header_suffixes/2`

Extracts the ordered list of per-frame mission-specific segment-header suffixes that contributed to a provenance-aware reassembled telecommand service-unit term.

Compilation flags:
`static`
Template:
`segment_header_suffixes(ReassembledSegment,HeaderSuffixes)`
Mode and number of proofs:
`segment_header_suffixes(+compound,-list(list(byte)))` - `one`

### `segment_data/2`

Extracts the telecommand segment data bytes.

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

### `valid_reassembly_state/1`

True if the argument is a valid telecommand segment reassembly state term.

Compilation flags:
`static`
Template:
`valid_reassembly_state(State)`
Mode and number of proofs:
`valid_reassembly_state(@compound)` - `zero_or_one`

### `initial_reassembly_state/1`

Returns the initial telecommand segment reassembly state.

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

### `pending_fragments/2`

Extracts the pending segmented telecommand data fragments keyed by spacecraft, virtual channel, and MAP identifier.

Compilation flags:
`static`
Template:
`pending_fragments(State,PendingFragments)`
Mode and number of proofs:
`pending_fragments(+compound,-list(compound))` - `one`

### `valid_discontinuity_policy/1`

True if the argument is a valid discontinuity recovery policy atom. Valid values are `throw`, `drop`, and `resynchronize`.

Compilation flags:
`static`
Template:
`valid_discontinuity_policy(Policy)`
Mode and number of proofs:
`valid_discontinuity_policy(@atom)` - `zero_or_one`

### `extract_tc_segment/2`

Extracts a telecommand segment from a telecommand transfer frame using the representation `tc_segment(SequenceFlags, MapId, HeaderSuffix, Data)`. When mission-specific segment headers use multiple octets, only the first octet is interpreted for the standard MAP and sequence semantics and the remaining octets are returned as `HeaderSuffix`.

Compilation flags:
`static`
Template:
`extract_tc_segment(Frame,Segment)`
Mode and number of proofs:
`extract_tc_segment(+compound,-compound)` - `one_or_error`
Exceptions:
`Frame` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`

### `insert_tc_segment/3`

Updates a telecommand transfer frame from a telecommand segment term by encoding the standard MAP and sequence semantics in the first segment-header octet and preserving any remaining mission-specific segment-header octets.

Compilation flags:
`static`
Template:
`insert_tc_segment(Segment,Frame,UpdatedFrame)`
Mode and number of proofs:
`insert_tc_segment(+compound,+compound,-compound)` - `one_or_error`
Exceptions:
`Segment` or `Frame` is a variable:
`instantiation_error`
`Segment` is neither a variable nor a valid telecommand segment term:
`domain_error(ccsds_tc_segment,Segment)`
`Frame` has an invalid telecommand segment header suffix encoding:
`domain_error(ccsds_tc_segment_header,SegmentHeader)`

### `reassemble_tc_frame/4`

Reassembles complete telecommand service units from a single telecommand transfer frame using the default `throw` discontinuity recovery policy.

Compilation flags:
`static`
Template:
`reassemble_tc_frame(Frame,State,Segments,UpdatedState)`
Mode and number of proofs:
`reassemble_tc_frame(+compound,+compound,-list(compound),-compound)` - `one_or_error`
Exceptions:
`Frame` or `State` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
The telecommand frame sequence is discontinuous:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frame/5`

Reassembles complete telecommand service units from a single telecommand transfer frame using the selected discontinuity recovery policy.

Compilation flags:
`static`
Template:
`reassemble_tc_frame(Frame,Policy,State,Segments,UpdatedState)`
Mode and number of proofs:
`reassemble_tc_frame(+compound,+atom,+compound,-list(compound),-compound)` - `one_or_error`
Exceptions:
`Frame`, `Policy`, or `State` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
`Policy` is neither a variable nor a valid telecommand discontinuity recovery policy:
`domain_error(ccsds_tc_discontinuity_policy,Policy)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
The telecommand frame sequence is discontinuous under the `throw` recovery policy:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frame/6`

Reassembles complete telecommand service units from a single telecommand transfer frame using the selected discontinuity recovery policy and returns any recovery events.

Compilation flags:
`static`
Template:
`reassemble_tc_frame(Frame,Policy,State,Segments,UpdatedState,Events)`
Mode and number of proofs:
`reassemble_tc_frame(+compound,+atom,+compound,-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frame`, `Policy`, or `State` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
`Policy` is neither a variable nor a valid telecommand discontinuity recovery policy:
`domain_error(ccsds_tc_discontinuity_policy,Policy)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
The telecommand frame sequence is discontinuous under the `throw` recovery policy:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frames/4`

Reassembles complete telecommand service units across a sequence of telecommand transfer frames using the default `throw` discontinuity recovery policy.

Compilation flags:
`static`
Template:
`reassemble_tc_frames(Frames,State,Segments,UpdatedState)`
Mode and number of proofs:
`reassemble_tc_frames(+list(compound),+compound,-list(compound),-compound)` - `one_or_error`
Exceptions:
`Frames` or `State` is a variable:
`instantiation_error`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
An element `Frame` of `Frames` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
The telecommand frame sequence is discontinuous:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frames/5`

Reassembles complete telecommand service units across a sequence of telecommand transfer frames using the selected discontinuity recovery policy.

Compilation flags:
`static`
Template:
`reassemble_tc_frames(Frames,Policy,State,Segments,UpdatedState)`
Mode and number of proofs:
`reassemble_tc_frames(+list(compound),+atom,+compound,-list(compound),-compound)` - `one_or_error`
Exceptions:
`Frames`, `Policy`, or `State` is a variable:
`instantiation_error`
`Policy` is neither a variable nor a valid telecommand discontinuity recovery policy:
`domain_error(ccsds_tc_discontinuity_policy,Policy)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
An element `Frame` of `Frames` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
The telecommand frame sequence is discontinuous under the `throw` recovery policy:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frames/6`

Reassembles complete telecommand service units across a sequence of telecommand transfer frames using the selected discontinuity recovery policy and returns any recovery events in frame order.

Compilation flags:
`static`
Template:
`reassemble_tc_frames(Frames,Policy,State,Segments,UpdatedState,Events)`
Mode and number of proofs:
`reassemble_tc_frames(+list(compound),+atom,+compound,-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frames`, `Policy`, or `State` is a variable:
`instantiation_error`
`Policy` is neither a variable nor a valid telecommand discontinuity recovery policy:
`domain_error(ccsds_tc_discontinuity_policy,Policy)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
An element `Frame` of `Frames` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
The telecommand frame sequence is discontinuous under the `throw` recovery policy:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frame_with_provenance/5`

Reassembles complete telecommand service units from a single telecommand transfer frame using the default `throw` discontinuity recovery policy and returns provenance-aware reassembled service-unit terms.

Compilation flags:
`static`
Template:
`reassemble_tc_frame_with_provenance(Frame,State,ReassembledSegments,UpdatedState,Events)`
Mode and number of proofs:
`reassemble_tc_frame_with_provenance(+compound,+compound,-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frame` or `State` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
The telecommand frame sequence is discontinuous:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frame_with_provenance/6`

Reassembles complete telecommand service units from a single telecommand transfer frame using the selected discontinuity recovery policy and returns provenance-aware reassembled service-unit terms plus any recovery events.

Compilation flags:
`static`
Template:
`reassemble_tc_frame_with_provenance(Frame,Policy,State,ReassembledSegments,UpdatedState,Events)`
Mode and number of proofs:
`reassemble_tc_frame_with_provenance(+compound,+atom,+compound,-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frame`, `Policy`, or `State` is a variable:
`instantiation_error`
`Frame` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
`Policy` is neither a variable nor a valid telecommand discontinuity recovery policy:
`domain_error(ccsds_tc_discontinuity_policy,Policy)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
The telecommand frame sequence is discontinuous under the `throw` recovery policy:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frames_with_provenance/5`

Reassembles complete telecommand service units across a sequence of telecommand transfer frames using the default `throw` discontinuity recovery policy and returns provenance-aware reassembled service-unit terms.

Compilation flags:
`static`
Template:
`reassemble_tc_frames_with_provenance(Frames,State,ReassembledSegments,UpdatedState,Events)`
Mode and number of proofs:
`reassemble_tc_frames_with_provenance(+list(compound),+compound,-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frames` or `State` is a variable:
`instantiation_error`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
An element `Frame` of `Frames` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
The telecommand frame sequence is discontinuous:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `reassemble_tc_frames_with_provenance/6`

Reassembles complete telecommand service units across a sequence of telecommand transfer frames using the selected discontinuity recovery policy and returns provenance-aware reassembled service-unit terms plus any recovery events in frame order.

Compilation flags:
`static`
Template:
`reassemble_tc_frames_with_provenance(Frames,Policy,State,ReassembledSegments,UpdatedState,Events)`
Mode and number of proofs:
`reassemble_tc_frames_with_provenance(+list(compound),+atom,+compound,-list(compound),-compound,-list(compound))` - `one_or_error`
Exceptions:
`Frames`, `Policy`, or `State` is a variable:
`instantiation_error`
`Policy` is neither a variable nor a valid telecommand discontinuity recovery policy:
`domain_error(ccsds_tc_discontinuity_policy,Policy)`
`State` is neither a variable nor a valid telecommand reassembly state term:
`domain_error(ccsds_tc_reassembly_state,State)`
An element `Frame` of `Frames` is neither a variable nor a valid telecommand transfer frame term:
`domain_error(ccsds_tc_transfer_frame_term,Frame)`
The telecommand frame sequence is discontinuous under the `throw` recovery policy:
`domain_error(ccsds_tc_transfer_frame_sequence,tc_transfer_frame_sequence(SpacecraftId,VirtualChannelId,ExpectedSequenceNumber,SequenceNumber))`
A telecommand segment starts a new reassembly while a previous segment for the same MAP is still pending:
`domain_error(ccsds_tc_segment_reassembly,existing_pending_segment(MapId))`
A telecommand continuation or last segment is missing its first segment:
`domain_error(ccsds_tc_segment_reassembly,missing_first_segment(MapId))`

### `dispatch_service_units_by_map/2`

Groups complete telecommand service-unit terms by MAP identifier, preserving the original service-unit order within each MAP bucket and the first-seen order of MAP buckets. Accepts both telecommand segment terms and provenance-aware reassembled telecommand service-unit terms.

Compilation flags:
`static`
Template:
`dispatch_service_units_by_map(ServiceUnits,Dispatches)`
Mode and number of proofs:
`dispatch_service_units_by_map(+list(compound),-list(compound))` - `one_or_error`
Exceptions:
`ServiceUnits` is a variable:
`instantiation_error`
`ServiceUnits` is neither a variable nor a valid list of telecommand service units:
`domain_error(ccsds_tc_service_units,ServiceUnits)`

### `dispatch_service_units_by_map/3`

Extracts the complete telecommand service units for a specific MAP identifier from a list of complete telecommand service-unit terms.

Compilation flags:
`static`
Template:
`dispatch_service_units_by_map(ServiceUnits,MapId,DispatchedServiceUnits)`
Mode and number of proofs:
`dispatch_service_units_by_map(+list(compound),+integer,-list(compound))` - `one_or_error`
Exceptions:
`ServiceUnits` or `MapId` is a variable:
`instantiation_error`
`ServiceUnits` is neither a variable nor a valid list of telecommand service units:
`domain_error(ccsds_tc_service_units,ServiceUnits)`
`MapId` is neither a variable nor a valid telecommand MAP identifier:
`domain_error(ccsds_tc_map_id,MapId)`

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

(no local declarations; see entity ancestors if any)

## Operators

(none)