.. _cspifc:

==============
CSP Interfaces
==============

The SRX-8 transmitter is operated remotely via `CubeSat Space Protocol (CSP)
<http://www.libcsp.org/>`_ messages.
The :ref:`srx8-client` and :ref:`prop-client` all contain wrapper function around CSP protocols.
In addition, SRX-8 also implements the standard CSP service ports such as ``CSP_PING`` and
``CSP_REBOOT``.

Configuration CSP parameters
----------------------------

By default, the system uses address 28 but this can be changed by adjusting the address
property ``sys.csp.address`` and saving the ``sys`` group. The system must be rebooted for the
address change to take effect.

The system supports CSP via CAN-bus (``CAN`` interface) and RS-422 (``KISS`` interface) in the
P1 connector.
The interfaces are always enabled for incoming messages, but the default routing table sends egress
messages on the CAN interface for all traffic except loopback.

The current routing table can be listed using the ``csp route show`` command in the EGSE shell:

.. code-block:: none

    [srx-8] csp route show
    28/5 LOOP
    0/0 CAN

The results are listed using `CIDR notation <https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing>`_.
CSP addresses are 5 bits long so, ``28/5`` is an exact match to address ``28``, i.e. the loopback
address. ``0/0`` marks the default route. To adjust CSP routing, the ``sys.csp.routes`` property
should be used. As an example, to send all traffic via the RS-422/KISS interface set the property
to ``0/0 KISS`` and save the ``sys`` group. It is not necessary to add an explicit route for the
loopback interface.

The CSP stack is configured for 256 packet buffers of up to 1024 bytes. The ``CAN`` and ``KISS``
interfaces both have an MTU of 1024 bytes.

The CSP connection can be tested using the ``csp ping`` EGSE shell command.
The example below pings satctl on address 2 with 100 byte frames 10 times:

.. code-block:: none

    [srx-8] csp ping -s100 -c10 -r 2
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Reply in 3.000 ms
    Sent: 10 Received: 10 (100.0%) Lost: 0 (0.0%)
    RTT: min=3.000 max=3.000 avg=3.000
