.. _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.000664] prop: using stored sys properties
    [    0.000869] system: Copyright (c) 2016-2019 Satlab ApS <satlab@satlab.com>
    [    0.002031] system: boot: 1 reset cause: general reset
    [    0.002471] system: board serial #21123456

    Satlab Polaris ADS-B v1.0.0 (builder@builder) Jun  1 2019 12:00:00

    [polaris] help
    Available commands:
    boot            Bootloader commands
    csp             CSP commands
    demod           Demod commands
    fs              File system commands
    help            Show available commands
    history         Show previous commands
    prop            System configuration properties
    reboot          Reboot system
    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       4925.00 mV   296.00 mA  1442.00 mW
    3V3       3336.00 mV   412.00 mA  1375.00 mW
    2V0       2000.00 mV   214.00 mA   430.00 mW
    1V0        958.00 mV   149.00 mA   141.00 mW

    Temperature Sensors
    MCU         38.00 C
    FPGA core   41.25 C
    Power       37.43 C
    LNA         37.75 C
    ADC         37.75 C
    SD-card     37.25 C
    Interrupted

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

.. code-block:: none

    [polaris] store read 5
    7826: T: 203.303338650 R: -28.1 dBFS F: .. DF 17 8d45aa4b990072a8a050003dd1fd 
    7825: T: 203.302914850 R: -26.8 dBFS F: .. DF 17 8d45aa4b90832406abd5bce348c5 
    7824: T: 203.276235450 R: -25.6 dBFS F: .. DF 17 8d45b8b799119d2a30082103d4e4 
    7838: T: 203.442283000 R: -28.9 dBFS F: .. DF 17 8f43e9d75cc7f08b7fcbba2d7e7f 
    7837: T: 203.417461600 R: -29.0 dBFS F: .. DF 17 8d4cabbd60b5040aabd3ed6a817e 
    7836: T: 203.413607550 R: -20.5 dBFS F: .. DF 17 8d4ba9cc9945712828041491e699 

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

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

Logging of all incoming ADS-B messages can also be enabled with ``trace mask demod info``.
