K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
Ground station

k-ground runs Linux ground nodes built from the same application and services as KFSW-Linux. A node file sets each role's name, address, peer and build options.

Roles and addresses

Role CSP address Use
kfsw-gnd-uhf 16 Opens the UHF radio for the ground network
kfsw-gnd-can 17 Reaches a flight node over a SocketCAN interface
kfsw-beacon 18 Receives beacons from a flight node
kfsw-ops 19 Operator shell; doesn't open the radio
kfsw-rotctl 20 Antenna rotator control

The address says which link the ground node is on: 16 is reached over KISS and 17 over CAN. A flight profile that carries both links names one route per link, as nucleo-can.conf does with "3 CAN,17 CAN,16 KISS,0/0 KISS".

Each node file sets:

Variable Meaning
KFSW_ROLE Role name; must match the file name
KFSW_CSP_NODE The node's own address. tools/k-ground refuses a ground node below 16, and accepts up to 16382 under CSP 2 and 30 under CSP 1
KFSW_CSP_PEER The node at the other end of the serial link, the one comms uart test pings when given no node. It becomes CONFIG_KFSW_CSP_UART_PEER_ADDRESS and is not a route
KFSW_CSP_ROUTES The route table, at most 99 characters
KFSW_CSP_VERSION 1 builds for a CSP 1 satellite; unset or 2 otherwise. A CSP 1 node gets its own configuration file and build directory, with a -csp1 suffix
KFSW_RADIO_UHF holybro selects the radio module
KFSW_EXTRA_KCONFIG, KFSW_EXTRA_OVERLAY Extra Kconfig lines and a devicetree overlay

To make a bench variant of a role, for example the UHF gateway routed to flight node 2:

  1. Copy nodes/kfsw-gnd-uhf.env to nodes/kfsw-gnd-uhf-bench.env. Git ignores *-bench.env, so device paths and bench routes stay on the machine they belong to.
  2. Set KFSW_ROLE=kfsw-gnd-uhf-bench in it, and the peer and routes the bench needs.
  3. Run it as k-ground run kfsw-gnd-uhf-bench.

status shows the node identity and comms uhf status the radio settings:

kfsw-gnd-uhf# status
K-FSW status
Role: kfsw-gnd-uhf
Name: kfsw-gnd-uhf
CSP node: 16
board: native_sim/native/64

A normal Linux image keeps the kfsw:~$ prompt and Role: flight.

Environment

Layer Contents Loaded by
Workspace .venv Python, west and Zephyr tools Your shell; K-FSW scripts activate it themselves
ground-station/nodes/*.env Role, CSP address, peer and routes tools/k-ground
Holybro bench file Serial paths and radio settings of one host Sourced before a hardware test

From the workspace root:

. .venv/bin/activate
west topdir
west manifest --validate
command -v socat

socat is needed for the local CSP/KISS links (sudo apt install socat). See Getting started for the workspace setup.

The launcher reads the station from KGROUND_STATION_DIR when it is set, otherwise from ./ground-station when that holds the role's node file, otherwise from k-fsw/ground-station. It builds under KGROUND_BUILD_ROOT, which defaults to $KFSW_OUTPUT_ROOT/k-ground or build/k-ground. Each role builds in <role>-node-<node>, with -csp1 appended for CSP 1, for example build/k-ground/kfsw-gnd-uhf-node-16. The generated Kconfig fragment of the same name is in config/ under the build root. k-ground writes it to a temporary file and replaces it only when its contents change, so a repeated build does not rerun CMake; a failed write leaves the previous file in place. To use other directories in the current shell:

export KGROUND_STATION_DIR="$PWD/ground-station"
export KGROUND_BUILD_ROOT="$PWD/build/k-ground"
./k-fsw/tools/k-ground build kfsw-gnd-uhf

Keep USB device paths out of the node files and put them in the bench file.

Configuration

ground-station/
|-- README.md
|-- station.env
|-- satellites.json Gpredict proxy profiles
|-- reports/ HK report definitions
|-- tle/tracked.txt TLEs of the profiled spacecraft
|-- yamcs/ Yamcs configuration (submodule)
`-- nodes/
|-- kfsw-beacon.env
|-- kfsw-gnd-can.env
|-- kfsw-gnd-uhf.env
|-- kfsw-ops.env
`-- kfsw-rotctl.env

A node file is a shell environment file; see kfsw-gnd-uhf.env for the gateway and kfsw-gnd-can.env for one that adds Kconfig and an overlay.

KFSW_CSP_ROUTES such as ‘'2 KISS’means node 2 in either CSP version. tools/k-groundchecks its length and characters and writes it to CONFIG_KFSW_CSP_ROUTE_TABLE; without it the node keeps0/0 KISSfrom config/profiles/k-ground.conf.kfsw-gnd-canenables CAN through KFSW_EXTRA_KCONFIGandKFSW_EXTRA_OVERLAY`.

Ground nodes include FWU lite and host-file reading by default. From kfsw-ops, fwu_lite send <node> /absolute/host/path sends an image without extra Kconfig. See Firmware update for validation and activation.

To copy the reference configuration into your workspace:

./k-fsw/tools/k-ground init

init [directory] creates ./ground-station by default and refuses a path that already exists.

Running

Start the UHF gateway and the operator shell in two terminals:

./k-fsw/tools/k-ground run kfsw-gnd-uhf
./k-fsw/tools/k-ground run kfsw-ops

When the peer is a ground node (16 or above), run joins the KISS PTYs of the two peers through a Unix socket in runtime/ under the build root. The options are:

Option Effect
--node N, --peer N Override the node file's addresses
--no-local-link Leave the PTY unconnected, for a serial bridge
-- ARGS Pass the rest to zephyr.exe, for example --can-if=can0

Without a -flash= argument, the node keeps its storage in k-ground-storage.bin in its build directory.

kfsw-ops# csp ping 16
CSP ping 16: success
rtt_ms: ...
kfsw-gnd-uhf# csp ping 19
CSP ping 19: success
rtt_ms: ...

k-ground demo starts both and opens the operator shell. k-ground test checks both identities, prompts and ping directions (tests/k-ground-csp-smoke.sh):

./k-fsw/tools/k-ground demo
./k-fsw/tools/k-ground test

Moving a file between ground nodes

Ground nodes include the file transfer service. From the operator shell:

kfsw-ops# ftp generate /build/test.txt 256
FTP generate /build/test.txt: PASS
bytes: 256
crc32: 0ce9d363
kfsw-ops# ftp mkdir 16 /uplink
FTP mkdir 16 /uplink: PASS
kfsw-ops# ftp put 16 /build/test.txt /uplink/test.txt
FTP put 16 /build/test.txt -> /uplink/test.txt: PASS
bytes: 256
crc32: 0ce9d363
duration_ms: 190
throughput_Bps: 1347
kfsw-ops# ftp stat 16 /uplink/test.txt
FTP stat 16 /uplink/test.txt
type: file
bytes: 256
crc32: 0ce9d363
kfsw-ops# ftp get 16 /uplink/test.txt /build/test-returned.txt
FTP get 16 /uplink/test.txt -> /build/test-returned.txt: PASS
bytes: 256
crc32: 0ce9d363
...
kfsw-ops# ftp verify /build/test.txt /build/test-returned.txt
FTP verify /build/test.txt /build/test-returned.txt: PASS

The same CRC on both nodes and on the returned copy means the file came back unchanged. The gateway can list its own files without a connection:

kfsw-gnd-uhf# ftp ls 16 /uplink
FTP ls 16 /uplink
file 256 test.txt
entries: 1

tests/k-ground-ftp-smoke.sh runs this sequence, including a missing file.

After checking the copies, ftp rm 16 /uplink/test.txt removes the remote file. ftp rm 16 /uplink then removes the empty directory. Omit the node to remove a local file or empty directory.

Telemetry in Yamcs

Yamcs stores housekeeping samples and has a telemetry browser and archive. Its configuration is the ground-station/yamcs submodule.

Nodes answer housekeeping requests, so the bridge polls them:

./k-fsw/tools/ground/hk-bridge.py --device /dev/pts/7 --node 1 --report 0

The bridge talks CSP over KISS, pulls samples and sends each one to Yamcs on UDP port 10015. Point it at a Linux node's uart_1 PTY, or at the Holybro serial device to reach a flight node over the radio. It speaks CSP 2; add --csp-version 1 for a node built with config/profiles/csp-v1.conf.

Beacons

A report can also send its latest sample periodically:

hk beacon 0 1 5000 # report 0, to node 1, every five seconds
hk beacon 0 1 0 # stop

Beacons use the same frame format as polled samples. Receive them without polling:

./k-fsw/tools/ground/hk-bridge.py --device /dev/pts/7 --node 1 --listen
  • Intervals below CONFIG_KFSW_HK_BEACON_FLOOR_MS (5000 ms) return -ERANGE.
  • The report has to be collecting and the node's clock has to be set.
  • A beacon is skipped when fewer than CONFIG_KFSW_HK_BEACON_BUFFER_RESERVE CSP buffers are free; check hk show and hk_beacons_skipped in table 33.

Beacons are sent to their own port (KFSW_HK_BEACON_PORT) so they never reach a request handler. With persistence enabled, beacon settings are saved with the report.

Keeping what came down

A pass read on a console is gone when the console closes. --store keeps every accepted sample in a SQLite file, so a value can be read against last week instead of only now:

./k-fsw/tools/ground/hk-bridge.py --device /dev/pts/7 --node 1 --listen \
--store passes.db --definitions ground-station/reports/nucleo-temperature.yaml

Two things decide the shape of that file, and both come from how housekeeping works on the node.

A frame carries values and no names, so the report definition is the schema. --definitions stores the document beside the samples and points each sample at the definition that was in force when it arrived. A definition that changes gets a new row, so a sample recorded under the old one is never decoded with the new one.

A gap is data. Every sample carries a sequence number precisely so a missing one is visible, so the store never fills one in. The gap view reports what was not heard, and it knows the sequence is sixteen bits, so the step from 65535 to 0 is one sample and not a loss of sixty-five thousand:

sqlite3 passes.db 'SELECT * FROM gap'
sqlite3 passes.db 'SELECT sequence, node_seconds, hex(frame) FROM sample WHERE report = 0'

A row is one reception, not one unique sample: a duplicate is evidence of the link too. clock_set says whether the node knew the time, because a sample stamped by the host is not the same evidence as one stamped by the node.

This file and Yamcs are not alternatives, and one run feeds both: --yamcs forwards every sample to the archive that plots it, and --store keeps the frames as they arrived with the definition that decodes them and the sequence gaps. Yamcs is where a trend is read; this file is what the trend was built from, and it needs no Java and no server during a pass.

Following a pass with Gpredict

Gpredict computes the pass and speaks only as a client: it connects to a rotator daemon and a radio daemon and sends them bearings and a Doppler-corrected frequency. It exposes nothing that accepts orders, so nothing here tells Gpredict what to track. The proxy listens where those daemons listen instead.

Gpredict --az/el--> gpredict-proxy.py --az/el--> rotctld --> motors
--freq---> gpredict-proxy.py --freq---> rigctld --> radio

Every decision stays Gpredict's. The proxy sees each one, applies the selected profile's rules, and forwards it or refuses it with RPRT -1, which Gpredict shows as an error.

./k-fsw/tools/ground/gpredict-proxy.py --list
./k-fsw/tools/ground/gpredict-proxy.py --profile "LUR-1"

With no upstream the command is accepted, checked and printed but driven nowhere, which is how to watch Gpredict without a rotator attached. Add --rotator-upstream 127.0.0.1:4533 and --radio-upstream 127.0.0.1:4532 to drive the real daemons, and run the proxy on different ports so it can sit in front of them.

ground-station/tle/tracked.txt holds the TLEs of the spacecraft in the profiles below. Gpredict imports them through its TLE update from local files; refresh the file before a pass, because a TLE a few weeks old puts the antenna off the spacecraft.

Pointing Gpredict at it

In Gpredict, Edit > Preferences > Interfaces > Rotators and > Radios, add one of each with host localhost and the proxy's ports, 4533 and 4532 by default. Then open a module, Radio Control and Antenna Control from its menu, pick the satellite and the device, and press Engage and Track. Bearings start arriving once the spacecraft is above the horizon, so for a first look use one that is up now.

The profiles

ground-station/satellites.json holds one profile per spacecraft, seeded with LUR-1 (60506), ROADS 1 (64535) and ROADS 2 (64549). Each carries the travel it allows and what to do with the frequency:

Policy What the radio gets
follow What Gpredict sent. Gpredict owns the Doppler.
hold The profile's own frequency. Gpredict keeps correcting every cycle, so this is a standing override and not a value set once.
ignore Nothing. The rotator is unaffected.

The profile is selected by hand because the protocol carries angles and a frequency and never says which spacecraft they are for. Choosing it from the frequency breaks the day two share a band. A profile with "enabled": false is defined but cannot be selected.

Running Yamcs

Yamcs needs Java 17; Maven comes through ./mvnw.

cd k-fsw/ground-station/yamcs
./mvnw yamcs:run

It prints Yamcs started and serves http://localhost:8090. The instance is kfsw. Keep it running while recording.

Check the mission database before connecting hardware. In another terminal, from k-fsw/ground-station/yamcs:

./scripts/check-mdb.sh

It sends a recorded housekeeping frame to Yamcs and reads the values back; CI runs it on every push. Expect MDB CHECK RESULT: PASS.

Then set up a report on the node:

kfsw:~$ hk define 0 51:0x00 51:0x10 51:0x08 3:0x00 3:0x0c
kfsw:~$ csp clock set 1789066008
kfsw:~$ hk period 0 2000
kfsw:~$ hk show

hk show prints the collections, failures, missing values and stored samples. Set the clock first, otherwise samples have a zero timestamp and the bridge uses the host time.

Start the bridge on the node's link:

./k-fsw/tools/ground/hk-bridge.py --device "$KGROUND_HOLYBRO_DEVICE" \
--baud 57600 --node 2 --report 0 --count 8 --interval 10

The bridge prints each sample. With --yamcs none it prints the frames as hex and sends nothing.

Yamcs page What to check
Links hk-udp shows OK, receiving on 10015; valid datagrams go up, invalid stays at zero
Telemetry, Packets One packet per sample in the nucleo_temperature container
Telemetry, Parameters /kfsw/nucleo_temperature_temp_mcu in degrees, marked ACQUIRED
Archive The stored history

INVALID instead of ACQUIRED means the value is outside its valid range, for example the reserved value sent when the sensor can't be read. Check temp_valid and temp_failures.

The same data is available from the Yamcs API:

curl -s localhost:8090/api/links/kfsw/hk-udp | python3 -m json.tool
curl -s localhost:8090/api/processors/kfsw/realtime/parameters/kfsw/nucleo_temperature_temp_mcu
curl -s 'localhost:8090/api/archive/kfsw/parameters/kfsw/nucleo_temperature_temp_mcu?limit=50&order=asc'

If nothing arrives, look at the frames with --yamcs none, check that hk show counts collections, and then check Links for invalid datagrams.

Commanding

Yamcs only records telemetry. Housekeeping is configured from a ground shell with the node first; hk define, hk period and hk clear work over CSP/KISS or CAN:

kfsw-ops# hk define 2 0 51:0x00 51:0x10 3:0x00
node: 2
report 0 defines 3 values

Report definitions

Housekeeping frames carry the values in report order, without names. hk-report.py generates the node command and the Yamcs XTCE database from one YAML file. Put the node number after hk define to send it from the ground:

report=k-fsw/ground-station/reports/nucleo-temperature.yaml
./k-fsw/tools/ground/hk-report.py "$report" define
# hk define 0 51:0x00 51:0x10 51:0x08 3:0x00 3:0x0c
./k-fsw/tools/ground/hk-report.py "$report" xtce \
-o k-fsw/ground-station/yamcs/src/main/yamcs/mdb/kfsw-hk.xml

hk-report.py check compares the file with a node's param listall, which catches a parameter that moved.

Bridge datagrams

Each UDP datagram has a 12-byte header followed by the frame from the node:

0 u64 Unix milliseconds the node's clock, or the host's when it is not set
8 u32 sequence
12 ... housekeeping frame

The bridge sends one datagram per sample, preserving its timestamp.

tests/hk-yamcs-smoke.sh checks that the bytes the bridge receives match what the node's shell prints for the same sample.

Radio

Only one process opens each physical interface. A serial bridge connects the kfsw-gnd-uhf KISS PTY to the Holybro device; other ground roles reach the gateway over CSP. See the Holybro fixture below for the bridge command.

tests/hil/radio-uhf/
`-- holybro/
|-- raw-peer/
|-- raw-nucleo-smoke.sh
`-- csp-kiss-smoke.sh

kfsw-comms has the UART, KISS and CSP code. kfsw-modules has the radio-uhf module and its holybro-sik implementation, which reports the expected radio settings and adds encryption. Table 50 has the radio identity, status and encryption settings. TX power, network ID and air rate are not writable because the module doesn't use SiK command mode.

  • raw-nucleo-smoke.sh flashes a raw test peer on the NUCLEO and exchanges numbered messages over the radio.
  • csp-kiss-smoke.sh builds ground node 16 and NUCLEO node 2 at 57600 baud, bridges the ground PTY to the USB radio, and checks the interfaces, routes, ping in both directions and the counters.

Radio settings and commands are in tests/hil/radio-uhf/holybro/README.md.

Day to day

Three set-ups cover most work. Each opens a serial device or a pseudo-terminal exclusively, so run one reader per device at a time.

A KFSW-Linux node from the host

./k-fsw/tools/kfsw-linux run starts a node with its shell on the terminal and prints the pseudo-terminal of its CSP UART (uart_1). Host tools talk CSP over KISS on that device without a ground node:

./k-fsw/tools/ground/hk-bridge.py --device /dev/pts/7 --node 1 --report 0
./k-fsw/tools/kfsw-linux csp --device /dev/pts/7 discover --nodes 1

The first pulls report 0 into Yamcs, the second asks node 1 for its identity. Define the report on the node's own shell first, for example hk define 0 3:0x00 3:0x0c. The CSP tools are an optional project in west.yml; fetch and build them once with west update kfsw-csp-tools && ./k-fsw/tools/kfsw-linux csp build, which needs Rust.

Ground nodes on one host

k-ground run kfsw-gnd-uhf and k-ground run kfsw-ops in two terminals, as under Running above, give a gateway and an operator shell joined by a local link. Everything an operator does to a flight node is typed in the kfsw-ops shell with the node number first: param get 2 boot_image, event tail 2 0, hk define 2 0 ..., ftp put 2 ..., csp reboot 2 <pin>. A node left on Golden goes back to the application with the steps in Returning from Golden over CAN.

A pass

For a flight node over the radio, add the radio bridge to the gateway (see Radio below), start Yamcs and the bridge, and let the Gpredict proxy drive the antenna:

./k-fsw/tools/ground/gpredict-proxy.py --profile "LUR-1" \
--rotator-upstream 127.0.0.1:4533 --radio-upstream 127.0.0.1:4532
./k-fsw/tools/ground/hk-bridge.py --device "$KGROUND_HOLYBRO_DEVICE" \
--baud 57600 --node 2 --report 0

During the pass, feed the ground watchdog (gndwdt feed 2), read what happened since the last pass (journal remote 2, event stats 2), then pull stored housekeeping and files.

Saving and replaying HK

From k-fsw, capture accepted HK samples to a new JSONL file:

tools/kfsw-linux hk --device /dev/pts/7 --node 1 --listen --capture hk.jsonl --yamcs none
tools/kfsw-linux hk --replay hk.jsonl --yamcs 127.0.0.1:10015

Each version-1 record contains the source node, host receipt time in milliseconds, and original HK bytes. Replay opens no serial device and sends the saved samples in file order without delays. The Yamcs envelope uses the original sample time, or the saved receipt time when the node's clock was unset. An invalid or truncated record stops replay; earlier records may already have been sent.

Distinct reports with the same sequence number are kept. Exact duplicate samples from the same node are suppressed for up to 60 seconds, within a 1024-entry window. A changed timestamp or value makes a sample distinct. There is no boot identifier on the wire, so a byte-identical sample after a reset cannot be distinguished until it leaves that window. Captures contain samples accepted after this filtering, not every raw frame on the link.

Polling counts only matching replies towards --count; unrelated beacons can still be captured. An incomplete --once poll exits unsuccessfully and retains any accepted samples. Continuous polling reports the timeout and retries after --interval. Passive listening stays active between receive windows.

The bridge checks framing, CRCs, HK version, flags and size bounds. It cannot verify each value's width without the report definition; keep the matching report YAML with a capture. JSONL files grow with accepted samples, so stop or rotate captures between runs. Live serial access needs PySerial; offline replay uses only Python's standard library.