K-FSW ec10f94
Modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
Shell commands

Basics

Type commands at the shell prompt:

kfsw:~$ status

Wait for @READY before using services. help lists the commands in the build and <command> -h shows the syntax. Tab completes command and subcommand names, but not arguments such as a node or a path. A command with the wrong number of arguments prints its usage:

kfsw:~$ ftp generate
generate: wrong parameter count
generate - Create deterministic local data: generate <path> <bytes 0..32768>.

Commands and build options

The shell needs CONFIG_KFSW_DEBUG_SHELL. Each command group depends on its service:

Command Build option
status, version, time, log always
csp CONFIG_KFSW_CSP
uart CONFIG_KFSW_CSP_KISS_UART
param CONFIG_KFSW_PARAM; saving needs CONFIG_KFSW_PARAM_PERSISTENCE
storage CONFIG_KFSW_STORAGE
ftp CONFIG_KFSW_FTP
cmd CONFIG_KFSW_COMMAND
event CONFIG_KFSW_EVENT
hk CONFIG_KFSW_HK
fbo CONFIG_KFSW_FBO
fwu CONFIG_KFSW_FWU
watchdog CONFIG_KFSW_WATCHDOG
health CONFIG_KFSW_HEALTH
gndwdt CONFIG_KFSW_GNDWDT
resmon CONFIG_KFSW_RESMON
uhf CONFIG_KFSW_RADIO_UHF_SHELL
temp CONFIG_KFSW_TEMP_EXAMPLE_SHELL
boton_test, test CONFIG_KFSW_BOTON_TEST_SHELL

Identity and time

Command Prints
status Role, name, CSP node, board, hardware ID and uptime
version K-FSW version, Zephyr version, board, SoC and hardware ID
time Milliseconds and microseconds since boot
kfsw:~$ status
K-FSW status
Role: flight
Name: kfsw
CSP node: 1
board: native_sim/native/64
unit: 007f0101
uptime_ms: 10

Role and name are labels set in the build. time is time since boot; wall time is in csp clock.

Logging

log test prints one message at each level compiled into the image. Change log_level, or log_levels for a single module, to filter them.

log history shows up to 32 recent retained messages when CONFIG_KFSW_LOG_HISTORY is enabled. It includes sequence, uptime, module, level and truncation status. To retrieve them over CSP, use the host csp-kiss logs command described in communications.

UHF radio

uhf status prints the radio implementation, the expected hardware and serial settings, and the link state. With CONFIG_KFSW_RADIO_UHF_CRYPTO, uhf connect starts new encrypted sessions with the configured peer.

kfsw-gnd-uhf# uhf status
UHF radio
enabled: yes
implementation: holybro-sik
expected hardware: RFD SiK 2.0 on HM-TRP
configuration source: build-time expectation, not hardware readback
expected serial: 57600 8N1
expected flow control: none
hardware status: unavailable
RF link: unknown

uhf status doesn't talk to the modem. Traffic and errors are in uart info and csp interfaces.

Button and LED example

Command Arguments Meaning
boton_test status none Press count, last press and LED states

| test led | <green|blue|red> <on|off> | Switch one LED |

kfsw:~$ boton_test status
press_count: 0
last_press_s: 0
led_green: off
led_blue: off
led_red: off
debounce_ms: 30

test led and the LED parameters use the same module function. Holding the button counts one press, and everything resets at boot.

temp status prints the cached die temperature of the temperature example and its read counters.

CSP

Command Arguments Meaning
csp info none Local address, identity, build date and free buffers
csp ident [node] Hostname, model, revision, build date and clock
csp interfaces none Interfaces with addresses and packet, error and drop counters
csp ifstat <node> <interface> Remote interface packet/byte/error counters
csp routes none Route table
csp ping [node] Ping with CRC32 and a one-second timeout
csp debug [on\|off] Print every packet in and out
csp clock [set <utc>] or <node> [sync] Read or set wall time
csp reboot <node> <pin> Restart a node
kfsw:~$ csp routes
0/0 -> KISS direct
kfsw:~$ csp ping 2
CSP ping 2: success, rtt_ms=...

csp debug on prints each packet's source and destination node and port, priority, flags, size and interface. It is off by default and only affects the node where it is turned on.

kfsw:~$ csp debug on
CSP packet trace: on
kfsw:~$ csp ping 2
[DEBUG] OUT: S 33, D 2, Dp 1, Sp 17, Pr 2, Fl 0x01, Sz 10 VIA: CAN (2), Tms 51060
[DEBUG] INP: S 2, D 33, Dp 17, Sp 1, Pr 2, Fl 0x01, Sz 14 VIA: CAN, Tms 51120
CSP ping 2: success, rtt_ms=60

With several links, csp routes shows the interface and next hop of each route:

kfsw:~$ csp routes
10/14 -> KISS_1 direct
11/14 -> KISS_2 via 11

Routes are set at build time and can't be changed from the shell. A ping timeout can mean no peer, a wrong address or route, framing errors or no free buffers; check csp interfaces, csp routes and uart info.

Restarting a node

csp reboot <node> <pin> restarts a node if the pin matches:

kfsw:~$ csp reboot 2 1234
reboot node=2: denied wrong pin
kfsw:~$ csp reboot 2 0000
reboot node=2: OK rebooting in 500 ms

The pin is reboot_pin in the system table: 0000 by default, persistent, and settable from the ground. It is text, so 0007 doesn't match 7. The pin is sent in clear text and only protects against rebooting the wrong node by mistake.

After a restart the boot table shows why the previous run ended:

kfsw:~$ param table 2 32
32 0x30 last_reason u8 r 1 commanded
32 0x34 last_detail x32 r 0x00000000 the faulting address, for a fault
32 0x38 last_uptime_ms u32 r 5427214

All three at zero means no valid reset note was found. Power loss is one possible cause; a reset before a note was written gives the same result. Check the hardware reset cause as well.

UART/KISS

Command Arguments Meaning
uart info none Each CSP UART with baud, state, KISS name, address and counters
uart test [node] Check that the route uses a UART/KISS link, then ping with a 128-byte payload

Give the node to test one link out of several, for example uart test 10 and uart test 11. On the NUCLEO these commands run on the ST-LINK console and the packets leave on USART3; don't connect the shell terminal to the CSP UART.

Parameters

Command Arguments Meaning
param tables none Local tables with ID, band, size and saved values
param tablelist [node] Tables of a node
param list [node] All parameters
param table [node] <table> One table
param get [node] <name> Read a value
param set [node] <name> <value> Write a value
kfsw:~$ param tables
id band name params kept
--- ------- ---------- ------ ------
1 core board 11 0
2 core system 3 3
3 core telemetry 5 0
4 core csp 8 0
5 core storage 4 0
25 service log 5 2
kfsw:~$ param list
table addr name type mode value
---------- ---- -------------------------------- ------ ---- -----
board 0x00 node_id u16 r 1
system 0x00 boot_delay_ms u16 wpb 0
system 0x02 app_report_ms u16 wp 1000
telemetry 0x00 uptime_s u32 r 0
log 0x00 log_level u8 wp 1

Mode letters: r read-only, w writable, p saved in the snapshot, b applied at the next boot. Strings are printed quoted and arrays as lists. Input is parsed with the parameter's type; overflow, negative unsigned values and bad numbers are rejected.

echo_enabled makes the console repeat what it receives. It is off by default:

kfsw:~$ param set echo_enabled 1
kfsw:~$ status <- repeated by the shell
K-FSW status

Remote nodes

With CONFIG_KFSW_PARAM_CSP, put the node before the other arguments:

kfsw:~$ param get 2 log_level
2:log_level = 1
kfsw:~$ param set 2 log_level 2
2:log_level = 2
kfsw:~$ param table 2 25

The node is a decimal number. Remote listings show the table number instead of its name, because table names are not sent over the link.

Saving

Command Effect
param save Write all persistent values to the snapshot
param persist <table> Write the snapshot and show that table's share
param load Apply the saved snapshot
param defaults Reset persistent values to their defaults, in RAM only
param clear Delete the snapshot; RAM is unchanged

These act on the local node. With param_autosave on, a change to a persistent value is saved without param save. See Services and storage.

Storage

Command Arguments Meaning
storage info none Filesystem, backend, mount point, state, total and free bytes
storage test none Create, write, read, overwrite and delete a test file
storage test write <value> Write the persistence test value
storage test read <value> Read and compare the persistence test value
kfsw:~$ storage info
K-FSW storage
filesystem: LittleFS
backend: flash-controller@0
mount_point: /kfsw
ready: yes
total_bytes: 262144
free_bytes: 237568

storage test writes to flash. storage info only reads.

File transfer

Paths are virtual and rooted at /kfsw/ftp on the node.

Command Arguments Meaning
ftp <node> ls [directory] List a directory; list also works
ftp <node> stat <path> Type, size and CRC
ftp <node> mkdir <directory> Create a directory
ftp <node> put <local> <remote> Upload a file
ftp <node> get <remote> <local> Download a file
ftp generate <path> <bytes> Create a test file of up to 32768 bytes
ftp verify <first> <second> Compare two local files

The verb can also go first, ftp put <node> ..., which is the form Tab completion shows. ls, stat and mkdir work on the node's own address without a connection; put and get need another node.

kfsw:~$ ftp generate /build/sample.bin 1024
kfsw:~$ ftp 2 mkdir /exchange
kfsw:~$ ftp put 2 /build/sample.bin /exchange/sample.bin
kfsw:~$ ftp stat 2 /exchange/sample.bin
kfsw:~$ ftp get 2 /exchange/sample.bin /build/returned.bin
kfsw:~$ ftp verify /build/sample.bin /build/returned.bin

Paths must start with / and can't contain .. or empty components.

Commands

Command Arguments Meaning
cmd list none Registered commands with ID, arguments and description
cmd <name> [arguments] Run a command on this node
cmd <node> <name> [arguments] Run a command on another node over CSP
cmd retry <node> <name> [arguments] Reserve a ticket and retry lost exchanges within this invocation
cmd <node> ground_wtd KFSWWSFK Feed the ground watchdog and return countdown/timeout (ID 16)
cmd [node] ground_wtd get Read countdown/timeout without feeding
cmd journal_stats none Persistent journal status
cmd journal_tail <age> Committed event fields and payload; newest is 0
cmd journal_time <age> Sequence, event uptime and writer UTC
kfsw:~$ cmd list
ID NAME ARGS DESCRIPTION
9 journal_stats 0 args Read persistent journal status.
10 journal_tail 1 arg Read a journal event by age, newest is 0.
11 journal_time 1 arg Read a journal event's sequence and time by age.
1 noop 0 args Round trip with no effect.
2 info 0 args Report uptime and storage state.
4 event_stats 0 args Report event record counters.
5 event_tail 1 arg Read one recorded event by age, newest is 0.
6 hk_define 2 args Name what a report collects: <report> "[node:]table:offset ...".
7 hk_period 2 args Collect repeatedly: hk_period <report> <ms>, 0 to stop.
8 hk_clear 1 arg Forget a report: hk_clear <report>.
3 reboot 1 arg [mutating] Reset this node after a short delay: reboot <pin>.
16 ground_wtd 1 arg [mutating] Ground watchdog: get, or KFSWWSFK to feed over CSP.
kfsw:~$ cmd 2 info
info node=2: OK uptime_ms=4140 storage=ready free_bytes=12288

The order is registration order, not ID order.

Identifier allocation

An ID is part of the wire contract: two nodes must agree on it, so an ID is never reused for a different command. Composition commands are defined in app/src/commands/command_definitions.c; a command that belongs to a service is defined by that service and carries its ID in its own header.

ID Command Defined in
1 to 3 noop, info, reboot k-fsw composition
4, 5 event_stats, event_tail k-fsw composition
6 to 8 hk_define, hk_period, hk_clear k-fsw composition
9 to 11 journal_stats, journal_tail, journal_time k-fsw composition
12 to 15 free —
16 ground_wtd kfsw-services, gndwdt.h

The name is looked up in the local registry before the request is sent, so both nodes need the same command IDs. [mutating] commands change the node. Remote commands need CONFIG_KFSW_COMMAND_CSP (port 11). The command service does not authenticate callers. Radio encryption can protect that link; other interfaces need their own access policy.

Events

Command Meaning
event list Held records, oldest first
event stats Held, capacity, recorded, overwritten and rejected counts
event clear Discard held records; counters are kept
kfsw:~$ event list
SEQ TIME_MS SOURCE SEVERITY ID PAYLOAD
0 0 boot info 1 0000000800
Events listed: 1

Payloads are printed as bytes; their layout is in the producer's header. A gap in SEQ means records were overwritten, and event stats shows how many. The record is lost at reset. For another node:

kfsw:~$ cmd 2 event_stats
event_stats node=2: OK held=9/32 recorded=9 overwritten=0 rejected=0
kfsw:~$ cmd 2 event_tail 0
event_tail node=2: OK seq=8 t=8120ms ftp/1 sev=0 0002000001000ce9d363

Housekeeping

Command Arguments Meaning
hk define <report> [node:]table:offset ... Set what a report collects
hk clear <report> Delete a report
hk show none Reports and counters
hk collect <report> Collect now
hk get <report> [count] Print collected samples
hk period <report> <ms> Collect periodically, 0 to stop
hk store <report> <ms> Also write samples to a file, 0 to stop
hk store_clear <report> Stop storing and delete the file
hk beacon <report> <node> <ms> Send the latest sample periodically, 0 to stop
hk save none Save the report settings

See Ground station for Yamcs and the ground bridge.

File based operations

Command Arguments Meaning
fbo run <name> Run a procedure file
fbo stop none Stop the running procedure
fbo status none Procedure, current line and counters

Firmware update

fwu status state, slot geometry and checksums
fwu begin <size> <crc> start a transfer by hand
fwu finish verify and offer the image to the bootloader
fwu abort abandon a transfer and erase the slot
fwu send <node> <path> send an image block by block
fwu flash <node> ask a node to boot the image it received

send and flash need CONFIG_KFSW_FWU_LITE_CSP. fwu send reports how many blocks had to be resent. Check link counters if retries increase.

After a transfer, check swap_scheduled in fwu status. If it is not set, MCUboot has nothing to swap and boots the old image. See Firmware update.

Watchdog and health

watchdog status configuration and activity
watchdog feed feed once
watchdog starve confirm stop feeding; the board resets
health status whether the watchdog is being fed
health list watched components and deadlines
health report <handle> report a component as alive
health watch <name> <ms> confirm watch a component that never reports

The watchdog commands need CONFIG_KFSW_WATCHDOG and a kfsw,watchdog devicetree property. watchdog status shows the state (unconfigured, configured, running or starved), the timeout, the feed interval, the number of feeds and the time since the last one.

watchdog starve confirm can't be undone, since the STM32 independent watchdog can't be disarmed; the board resets within one timeout. health watch also ends in a reset once the deadline passes. The next boot marker shows the cause:

@BOOT sw=v1.0.1 board=nucleo_l496zg/stm32l496xx unit=203037324d46500c0010001f reset=0x00000011 reset_rc=0 reset_cause=watchdog

The raw mask is printed as well because several causes can be latched at once; 0x11 is the reset pin and the watchdog.

Scripts

Ordinary commands are not retried. cmd retry uses a ticket to suppress duplicates within that invocation when CONFIG_KFSW_COMMAND_RETRY is enabled. A new invocation is a new operation. A timeout can mean the reply was lost after the command ran, so check the state before sending it again.

Wait for @READY, then send one command at a time and wait for the prompt. Use the C APIs or CSP services when a script needs a stable format.