.. index:: single: ccsds_tc_services
.. _ccsds_tc_services/0:

.. rst-class:: right

**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:0
| **Date:** 2026-05-08

| **Compilation flags:**
|    ``static, context_switching_calls``


| **Uses:**
|    :ref:`list <list/0>`
|    :ref:`type <type/0>`

| **Remarks:**
|    (none)

| **Inherited public predicates:**
|    (none)

.. contents::
   :local:
   :backlinks: top

Public predicates
-----------------

.. index:: valid_segment/1
.. _ccsds_tc_services/0::valid_segment/1:

``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``


------------

.. index:: sequence_flags/2
.. _ccsds_tc_services/0::sequence_flags/2:

``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``


------------

.. index:: map_id/2
.. _ccsds_tc_services/0::map_id/2:

``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``


------------

.. index:: valid_map_dispatch/1
.. _ccsds_tc_services/0::valid_map_dispatch/1:

``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``


------------

.. index:: dispatch_map_id/2
.. _ccsds_tc_services/0::dispatch_map_id/2:

``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``


------------

.. index:: dispatch_service_units/2
.. _ccsds_tc_services/0::dispatch_service_units/2:

``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``


------------

.. index:: segment_header_suffix/2
.. _ccsds_tc_services/0::segment_header_suffix/2:

``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``


------------

.. index:: valid_reassembled_segment/1
.. _ccsds_tc_services/0::valid_reassembled_segment/1:

``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``


------------

.. index:: segment_header_suffixes/2
.. _ccsds_tc_services/0::segment_header_suffixes/2:

``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``


------------

.. index:: segment_data/2
.. _ccsds_tc_services/0::segment_data/2:

``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``


------------

.. index:: valid_reassembly_state/1
.. _ccsds_tc_services/0::valid_reassembly_state/1:

``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``


------------

.. index:: initial_reassembly_state/1
.. _ccsds_tc_services/0::initial_reassembly_state/1:

``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``


------------

.. index:: pending_fragments/2
.. _ccsds_tc_services/0::pending_fragments/2:

``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``


------------

.. index:: valid_discontinuity_policy/1
.. _ccsds_tc_services/0::valid_discontinuity_policy/1:

``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``


------------

.. index:: extract_tc_segment/2
.. _ccsds_tc_services/0::extract_tc_segment/2:

``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``


------------

.. index:: insert_tc_segment/3
.. _ccsds_tc_services/0::insert_tc_segment/3:

``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``


------------

.. index:: reassemble_tc_frame/4
.. _ccsds_tc_services/0::reassemble_tc_frame/4:

``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``


------------

.. index:: reassemble_tc_frame/5
.. _ccsds_tc_services/0::reassemble_tc_frame/5:

``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``


------------

.. index:: reassemble_tc_frame/6
.. _ccsds_tc_services/0::reassemble_tc_frame/6:

``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``


------------

.. index:: reassemble_tc_frames/4
.. _ccsds_tc_services/0::reassemble_tc_frames/4:

``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``


------------

.. index:: reassemble_tc_frames/5
.. _ccsds_tc_services/0::reassemble_tc_frames/5:

``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``


------------

.. index:: reassemble_tc_frames/6
.. _ccsds_tc_services/0::reassemble_tc_frames/6:

``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``


------------

.. index:: reassemble_tc_frame_with_provenance/5
.. _ccsds_tc_services/0::reassemble_tc_frame_with_provenance/5:

``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``


------------

.. index:: reassemble_tc_frame_with_provenance/6
.. _ccsds_tc_services/0::reassemble_tc_frame_with_provenance/6:

``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``


------------

.. index:: reassemble_tc_frames_with_provenance/5
.. _ccsds_tc_services/0::reassemble_tc_frames_with_provenance/5:

``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``


------------

.. index:: reassemble_tc_frames_with_provenance/6
.. _ccsds_tc_services/0::reassemble_tc_frames_with_provenance/6:

``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``


------------

.. index:: dispatch_service_units_by_map/2
.. _ccsds_tc_services/0::dispatch_service_units_by_map/2:

``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``


------------

.. index:: dispatch_service_units_by_map/3
.. _ccsds_tc_services/0::dispatch_service_units_by_map/3:

``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``


------------

Protected predicates
--------------------

(no local declarations; see entity ancestors if any)

Private predicates
------------------

(no local declarations; see entity ancestors if any)

Operators
---------

(none)

