.. _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.000047] system: Copyright (c) 2016-2017 Satlab ApS <satlab@satlab.com>
    [    0.000230] system: boot: 1 reset cause: general reset
    [    0.000389] system: board serial #201af5db
    [    0.000974] prop: using default system properties
    [    0.005753] prop: using default conf properties
    [    0.012056] prop: using default demod properties
    [    0.018446] prop: using default store properties

    Satlab Polaris v1.0.0 (builder@builder) Nov  1 2017 12:00:00

    [polaris] help
    Available commands:
    board           Board commands
    boot            Bootloader commands
    csp             CSP commands
    fpga            FPGA commands
    fs              File system commands
    help            Show available commands
    history         Show previous commands
    prop            System configuration properties
    reboot          Reboot system
    rf              RF frontend commands
    sdcard          SD-card commands
    sdram           SDRAM commands
    store           Frame store commands
    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

    [polaris] watch -b tm show
    Running command 'tm show' every 1000 ms
    Power Channels
    FPGA          On
    RF            On
    SD-card       Off
    Ethernet      Off

    Power Rails
    VIN       4900.00 mV   269.00 mA  1302.00 mW
    3V3       3336.00 mV   371.00 mA  1239.00 mW
    2V0       2000.00 mV   183.00 mA   367.00 mW
    1V0        958.00 mV   196.00 mA   187.00 mW

    Temperature Sensors
    MCU core    32.48 C
    MCU         33.31 C
    FPGA core   36.87 C
    Power       32.25 C
    LNA         33.37 C
    ADC         33.50 C
    SD-card     32.18 C
    Interrupted

To list the last 5 received messages, the ``store read`` command can be used:

.. code-block:: none

    [polaris] store read 5
    Frame 607650 ch: 2 type:  1 mmsi: 111219505 scale: 780 mean: -418
    041a844cc7e03c002dbd5da09f39b0bcffc20850a8ce50 [23]
    Frame 607649 ch: 2 type:  1 mmsi: 111219505 scale: 655 mean: -321
    041a844cc7e03f002dbf9820a020549dffa40850a46ec1 [23]
    Frame 607648 ch: 2 type:  1 mmsi: 111219516 scale: 744 mean: 155
    041a844cf02021302dc542209ffd0c2bffb20940edc345 [23]
    Frame 607647 ch: 1 type:  1 mmsi: 111219516 scale: 780 mean: 80
    041a844cf0201e602dc613209ff26ba9ffae0883736bbc [23]
    Frame 607646 ch: 2 type:  1 mmsi: 111219516 scale: 585 mean: -20
    041a844cf0201c502dc6ee209fec0b2dffaa090328bcb6 [23]

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 print csp all``:

.. code-block:: none

    [polaris] trace print csp all
    [   55.551903] csp: INP: S 1, D 20, Dp 1, Sp 62, Pr 2, Fl 0x00, Sz 1 VIA: KISS
    [   55.552103] csp: SERVICE: Ping received
    [   55.552210] csp: OUT: S 20, D 1, Dp 62, Sp 1, Pr 2, Fl 0x00, Sz 1 VIA: KISS

Logging of all incoming AIS messages can also be enabled with ``trace print store info``.
