.. _shell:

Debugging Shell
===============

The system provides a serial debugging shell on the RX/TX pins in the debugging connector. The serial configuration is 8N1 at 115200 baud, and the console requires an ``Enter`` key press to be activated.

For Linux systems, Satlab recommends the ``tio`` serial terminal application (https://tio.github.io/) but other applications such as ``minicom`` should also work. When using the Satlab JTAG/serial adapter, the debug shell is typically available on ``/dev/ttyUSB1``.

A number of timestamped log messages are printed during boot from various logging groups. Additional logging can be enabled at runtime using the ``trace`` commands. The ``help`` command can be used to list available commands and their usage. The installed software version and build information is also printed in the debugging shell during boot.

.. code-block:: none

    satlab@satlab:~$ tio -b 115200 /dev/ttyUSB1 
    [tio 14:29:41] tio v1.28
    [tio 14:29:41] Press ctrl-t q to quit
    [tio 14:29:41] Connected

    [    0.000052] system: Copyright (c) 2016-2018 Satlab ApS <satlab@satlab.com>
    [    0.000217] system: boot: 1 reset cause: general reset
    [    0.000369] system: board serial #30808b36
    [    0.001049] prop: using stored cal properties

    Satlab SRS-3 v1.0.0 (builder@builder) Aug  1 2018 12:00:00

    [srs-3] help
    Available commands:
    boot            Bootloader commands
    csp             CSP commands
    help            Show available commands
    history         Show previous commands
    prop            System configuration properties
    reboot          Reboot system
    time            Time command execution
    tm              Telemetry commands
    trace           Trace subcommands
    uptime          Show system uptime
    watch           Run command periodically

To show current telemetry values, run the ``tm show`` command. The ``watch`` command can be used to periodically run a command, with the ``-b`` switch enabling screen blanking between updates. Press any key to stop the loop:

.. code-block:: none

    [srs-3] watch -b tm show
    Running command 'tm show' every 1000 ms
    Power Channels
    Ethernet      Off

    Power Rails
    VIN             5000.00 mV   110.00 mA   530.00 mW
    VREG            3760.00 mV   130.00 mA   491.00 mW
    3V3             3335.00 mV   143.00 mA   477.00 mW

    Temperature Sensors
    MCU core          30.55 C
    MCU               29.75 C
    Power             29.56 C
    LNA               29.25 C
    PA                29.12 C

    Transmitter
    Frames             1000 Frames
    Forward power     30.02 dBm
    Reverse power      0.00 dBm

    Receiver
    Frames             1000 Frames
    Last RSSI        -89.50 dBm
    Interrupted

Dynamic debugging messages can be enabled through the ``trace`` command group. This can for example be used to log all received and transmitted CSP messages. To do so, run ``trace mask csp all``:

.. code-block:: none

    [srs-3] trace mask csp all
    [   55.551903] csp: INP: S 1, D 21, Dp 1, Sp 62, Pr 2, Fl 0x00, Sz 1 VIA: KISS
    [   55.552103] csp: SERVICE: Ping received
    [   55.552210] csp: OUT: S 21, D 1, Dp 62, Sp 1, Pr 2, Fl 0x00, Sz 1 VIA: KISS

Logging of all incoming and outgoing spacelink messages can also be enabled with ``trace mask rx info`` and ``trace mask tx info``.
