.. index:: single: ccsds_frame_protocol
.. _ccsds_frame_protocol/0:

.. rst-class:: right

**protocol**

``ccsds_frame_protocol``
========================

CCSDS transfer frame parser and generator protocol.

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

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

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


| **Dependencies:**
|   (none)


| **Remarks:**
|    (none)

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

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

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

.. index:: parse/2
.. _ccsds_frame_protocol/0::parse/2:

``parse/2``
^^^^^^^^^^^

Parses CCSDS transfer frame(s) from a source. Supported source terms are ``file(File)``, ``stream(Stream)``, and ``bytes(Bytes)``.

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

| **Template:**
|    ``parse(Source,Frames)``
| **Mode and number of proofs:**
|    ``parse(+compound,-list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Source`` is a variable:
|        ``instantiation_error``
|    ``Source`` is not a valid CCSDS frame source term:
|        ``domain_error(ccsds_frame_source,Source)``
|    ``Source`` bytes are not a valid CCSDS frame byte sequence for the selected frame type:
|        ``domain_error(ccsds_frame_byte_sequence,Bytes)``


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

.. index:: generate/2
.. _ccsds_frame_protocol/0::generate/2:

``generate/2``
^^^^^^^^^^^^^^

Generates CCSDS transfer frame bytes to a sink. Supported sink terms are ``file(File)``, ``stream(Stream)``, and ``bytes(Bytes)``.

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

| **Template:**
|    ``generate(Sink,Frames)``
| **Mode and number of proofs:**
|    ``generate(+compound,+list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Sink`` is a variable:
|        ``instantiation_error``
|    ``Sink`` is not a valid CCSDS frame sink term:
|        ``domain_error(ccsds_frame_sink,Sink)``
|    ``Frames`` is not a valid list of CCSDS transfer frame terms for the selected frame type:
|        ``domain_error(ccsds_frame_term,Frame)``


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

.. index:: generate/3
.. _ccsds_frame_protocol/0::generate/3:

``generate/3``
^^^^^^^^^^^^^^

Generates a list of bytes from a single CCSDS transfer frame term with an open tail. When the selected object includes an FECF, the generated bytes use a freshly computed FECF derived from the remaining frame fields.

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

| **Template:**
|    ``generate(Frame,Bytes,Tail)``
| **Mode and number of proofs:**
|    ``generate(+compound,-list(byte),--variable)`` - ``one_or_error``

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


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

.. index:: valid/1
.. _ccsds_frame_protocol/0::valid/1:

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

True if the argument is a valid transfer frame term for the selected object and, when applicable, carries the correct FECF for the remaining frame fields.

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

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


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

.. index:: update_fecf/2
.. _ccsds_frame_protocol/0::update_fecf/2:

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

Computes the correct frame error control field for the selected object configuration and returns the corresponding updated frame term.

| **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 for the selected frame type:
|        ``domain_error(ccsds_frame_term,Frame)``


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

.. index:: verify_fecf/1
.. _ccsds_frame_protocol/0::verify_fecf/1:

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

True if the frame term contains the correct FECF for the selected object configuration.

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

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


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

.. index:: frame_type/2
.. _ccsds_frame_protocol/0::frame_type/2:

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

Returns the transfer frame type for a frame term.

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

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


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

.. index:: version/2
.. _ccsds_frame_protocol/0::version/2:

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

Extracts the transfer frame version number.

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

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


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

.. index:: spacecraft_id/2
.. _ccsds_frame_protocol/0::spacecraft_id/2:

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

Extracts the spacecraft identifier.

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

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


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

.. index:: virtual_channel_id/2
.. _ccsds_frame_protocol/0::virtual_channel_id/2:

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

Extracts the virtual channel identifier.

| **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_frame_protocol/0::data_field/2:

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

Extracts the transfer frame data field as a list of bytes.

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

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


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

.. index:: ocf/2
.. _ccsds_frame_protocol/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_frame_protocol/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``


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

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

(none)

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

(none)

Operators
---------

(none)

