.. index:: single: ccsds_frames
.. _ccsds_frames/0:

.. rst-class:: right

**object**

``ccsds_frames``
================

Helpers for introspecting CCSDS transfer frame terms.

| **Availability:** 
|    ``logtalk_load(ccsds_frames(loader))``

| **Author:** Paulo Moura
| **Version:** 1:0:0
| **Date:** 2026-05-09

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


| **Uses:**
|    :ref:`ccsds_packets(SecondaryHeaderLength) <ccsds_packets/1>`
|    :ref:`list <list/0>`
|    :ref:`type <type/0>`

| **Remarks:**
|    (none)

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

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

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

.. index:: valid/1
.. _ccsds_frames/0::valid/1:

``valid/1``
^^^^^^^^^^^

True if the argument is a known CCSDS transfer frame term.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``valid(Frame)``
| **Mode and number of proofs:**
|    ``valid(@compound)`` - ``zero_or_one``


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

.. index:: frame_type/2
.. _ccsds_frames/0::frame_type/2:

``frame_type/2``
^^^^^^^^^^^^^^^^

Returns the CCSDS transfer frame type for a known frame term.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``frame_type(Frame,Type)``
| **Mode and number of proofs:**
|    ``frame_type(+compound,-atom)`` - ``one``


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

.. index:: version/2
.. _ccsds_frames/0::version/2:

``version/2``
^^^^^^^^^^^^^

Extracts the transfer frame version number from a known frame term.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``version(Frame,Version)``
| **Mode and number of proofs:**
|    ``version(+compound,-integer)`` - ``one``


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

.. index:: spacecraft_id/2
.. _ccsds_frames/0::spacecraft_id/2:

``spacecraft_id/2``
^^^^^^^^^^^^^^^^^^^

Extracts the spacecraft identifier from a known frame term.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``spacecraft_id(Frame,SpacecraftId)``
| **Mode and number of proofs:**
|    ``spacecraft_id(+compound,-integer)`` - ``one``


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

.. index:: virtual_channel_id/2
.. _ccsds_frames/0::virtual_channel_id/2:

``virtual_channel_id/2``
^^^^^^^^^^^^^^^^^^^^^^^^

Extracts the virtual channel identifier from a known frame term.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``virtual_channel_id(Frame,VirtualChannelId)``
| **Mode and number of proofs:**
|    ``virtual_channel_id(+compound,-integer)`` - ``one``


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

.. index:: data_field/2
.. _ccsds_frames/0::data_field/2:

``data_field/2``
^^^^^^^^^^^^^^^^

Extracts the raw data field bytes from a known frame term.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``data_field(Frame,DataField)``
| **Mode and number of proofs:**
|    ``data_field(+compound,-list(byte))`` - ``one``


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

.. index:: ocf/2
.. _ccsds_frames/0::ocf/2:

``ocf/2``
^^^^^^^^^

Extracts the operational control field. Returns ``none`` when absent.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``ocf(Frame,OCF)``
| **Mode and number of proofs:**
|    ``ocf(+compound,-compound)`` - ``one``


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

.. index:: fecf/2
.. _ccsds_frames/0::fecf/2:

``fecf/2``
^^^^^^^^^^

Extracts the frame error control field. Returns ``none`` when absent.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``fecf(Frame,FECF)``
| **Mode and number of proofs:**
|    ``fecf(+compound,-compound)`` - ``one``


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

.. index:: update_fecf/2
.. _ccsds_frames/0::update_fecf/2:

``update_fecf/2``
^^^^^^^^^^^^^^^^^

Refreshes a present frame error control field from the remaining frame fields while leaving frames without an FECF unchanged.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``update_fecf(Frame,UpdatedFrame)``
| **Mode and number of proofs:**
|    ``update_fecf(+compound,-compound)`` - ``one_or_error``

| **Exceptions:**
|    ``Frame`` is a variable:
|        ``instantiation_error``
|    ``Frame`` is not a valid CCSDS transfer frame term:
|        ``domain_error(ccsds_frame_term,Frame)``


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

.. index:: verify_fecf/1
.. _ccsds_frames/0::verify_fecf/1:

``verify_fecf/1``
^^^^^^^^^^^^^^^^^

True if a present frame error control field matches the remaining frame fields. Frames without an FECF succeed.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``verify_fecf(Frame)``
| **Mode and number of proofs:**
|    ``verify_fecf(@compound)`` - ``zero_or_one``


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

.. index:: extract_packets/3
.. _ccsds_frames/0::extract_packets/3:

``extract_packets/3``
^^^^^^^^^^^^^^^^^^^^^

Parses the raw frame data field as CCSDS space packet bytes using the given packet secondary header length.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``extract_packets(Frame,SecondaryHeaderLength,Packets)``
| **Mode and number of proofs:**
|    ``extract_packets(+compound,+integer,-list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Frame`` is a variable:
|        ``instantiation_error``
|    ``SecondaryHeaderLength`` is a variable:
|        ``instantiation_error``
|    ``Frame`` is neither a variable nor a valid CCSDS transfer frame term:
|        ``domain_error(ccsds_frame_term,Frame)``
|    ``SecondaryHeaderLength`` is neither a variable nor a valid CCSDS packet secondary header length:
|        ``domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)``
|    The frame data field is not a valid CCSDS packet byte sequence:
|        ``domain_error(ccsds_byte_sequence,Bytes)``


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

.. index:: insert_packets/4
.. _ccsds_frames/0::insert_packets/4:

``insert_packets/4``
^^^^^^^^^^^^^^^^^^^^

Generates CCSDS packet bytes and replaces the raw data field of a frame term, preserving the remaining header fields unchanged.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``insert_packets(Packets,SecondaryHeaderLength,Frame,UpdatedFrame)``
| **Mode and number of proofs:**
|    ``insert_packets(+list(compound),+integer,+compound,-compound)`` - ``one_or_error``

| **Exceptions:**
|    ``Packets`` is a variable:
|        ``instantiation_error``
|    ``SecondaryHeaderLength`` is a variable:
|        ``instantiation_error``
|    ``Frame`` is a variable:
|        ``instantiation_error``
|    ``Frame`` is neither a variable nor a valid CCSDS transfer frame term:
|        ``domain_error(ccsds_frame_term,Frame)``
|    ``SecondaryHeaderLength`` is neither a variable nor a valid CCSDS packet secondary header length:
|        ``domain_error(ccsds_secondary_header_length,SecondaryHeaderLength)``
|    An element ``Packet`` of ``Packets`` is a variable or ``Packets`` is a partial list:
|        ``instantiation_error``
|    An element ``Packet`` of ``Packets`` is neither a variable nor a valid CCSDS packet term:
|        ``domain_error(ccsds_packet_term,Packet)``


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

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

(no local declarations; see entity ancestors if any)

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

(no local declarations; see entity ancestors if any)

Operators
---------

(none)

