Skip to content

Add sourced console support - #13

Merged
ataffanel merged 7 commits into
mainfrom
sourced-console
Nov 17, 2026
Merged

ataffanel merged 7 commits into
mainfrom
sourced-console

Conversation

@ataffanel

@ataffanel ataffanel commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR adds support for all of the Crazyflie's consoles to cfcli, so users can discover and read output from sources such as the Camera Deck. It makes deck startup and runtime messages available from the CLI through CRTP protocol 13. It follows crazyflie-lib-rs, where consoles are a list of equal entries: cf:stm32 is no longer a default, it is one of the available consoles.

Command Behavior
cfcli console in a terminal Asks which console to show. The question is skipped when there is only one, which is always the case on protocol-12 firmware.
cfcli console non-interactively Exits with code 30 before connecting and asks for --source.
cfcli console --source PATH Shows that console by its exact path. An unknown path exits with code 20 and reports the available paths.
cfcli console --list Prints the available paths, including cf:stm32, in a table or CSV.

This is a breaking change for scripts. cfcli console without a selection now fails when non-interactive, including when only one console exists, because a script would otherwise work until a deck is attached. Use cfcli console --source cf:stm32.

The selected console replays available output and continues streaming live output, formatted or raw. The pinned library can retain packets received before console discovery, so replay may include output from an earlier connection. It keeps a 64 KiB budget for these early packets and cannot recover packets lost over radio.

On timeout, Ctrl-C or SIGTERM, cfcli makes a bounded attempt to close the console before disconnecting. This now applies to every console, so Ctrl-C on cf:stm32 exits with code 130 and saves --preserve-console history.

--preserve-console history still applies only to cf:stm32. With --source cf:stm32 it prints before connecting, so it stays readable if the Crazyflie no longer connects. Through the picker it can only print after connecting. Because the library has no call that returns the history directly, saving reads until output pauses for 10 ms, for at most 500 ms, so very chatty firmware could get a truncated save.

--timeout also counts the time spent answering the picker, so --source should be used with it.

Shell completion offers console paths for --source in bash, zsh and PowerShell, like parameter and log names. The paths are cached on every connection. Listing them asks the Crazyflie for its console catalog, so it gets 500 ms; when that runs out, for example while a deck is still starting, the paths cached from the previous connection are kept and cf:stm32 is always offered. In bash, : splits the word being completed, so the path is rebuilt from the line.

Related work

Verification

On commit e60e5af (on top of main at 0.18.0, pinning crazyflie-lib-rs at 0e7ea9f, the current head of bitcraze/crazyflie-lib-rs#66):

  • cargo test --locked passed: 122 tests, including the console argument tests and the process-signal cleanup tests.
  • cargo build --locked passed.
  • git diff --check passed.
  • cfcli --non-interactive console exits with code 30.

On commit e0be93c, which adds console path completion:

  • cargo test --locked passed: 123 tests, including loading a completion cache written by an older cfcli.
  • On the same hardware, a connection caches cf:stm32 and deck:bcCam, and a command takes 0.29 s, the same as before.
  • In an interactive bash, Tab completes --source de, --source cf:, --source cf:st and --source=deck:b to the full path, and param, --targets, --bin and --zip completion is unchanged.
  • zsh and PowerShell completion was not run; their generated scripts were checked to call console-paths for console --source.

End-to-end hardware test passed on a Crazyflie 2.1 Brushless with a Camera Deck rev G, running crazyflie-firmware master d794c5ca (with bitcraze/crazyflie-firmware#1689), camera-deck-firmware main 2610869, this library at 0e7ea9f and cfcli at e60e5af:

  • Listing shows cf:stm32 and deck:bcCam, in a table and in CSV.
  • deck:bcCam replays the deck startup log, then streams live output. cf:stm32 replays the boot log after a reboot, complete and in order.
  • Output written while no console is open is held by the firmware and delivered on the next open.
  • After an unexpected disconnect (cfcli killed with SIGKILL), output written during the gap is recovered on reconnect.
  • Closing on SIGINT and SIGTERM works, with exit codes 130 and 143.
  • On protocol-12 firmware (release 2026.10), only cf:stm32 is listed and it streams normally.
  • The interactive picker selects a console, and is skipped when there is only one.
  • Exit code 30 when non-interactive without --source, exit code 20 for an unknown console.
  • --preserve-console prints the saved cf:stm32 history before connecting.

Before merge

  • Test on hardware, including the picker.
  • Replace the temporary Git pin with a released crazyflie-lib-rs version containing sourced console support.

@ataffanel
ataffanel marked this pull request as ready for review August 31, 2026 13:03
@ataffanel
ataffanel requested review from evoggy and stefanthorstenson and a lite review from Copilot August 31, 2026 13:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for “sourced console” discovery and streaming on top of the existing legacy Crazyflie console behavior, including CSV output for catalog listing and bounded cleanup on exit.

Changes:

  • Add console --list-sources (human/CSV) and console --source <PATH> (replay history + live streaming) flows.
  • Update command classification and cleanup logic to treat sourced-console streaming correctly and disable an enabled source before disconnecting.
  • Document the new UX and add focused unit tests around argument behavior and source-path rendering.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/modules/console.rs Implements source catalog listing, not-found errors, and single-source streaming (replay + live).
src/main.rs Routes new console flags, adjusts streaming-command detection, and adds bounded disable-on-exit cleanup.
src/cli.rs Adds --source / --list-sources flags and clap conflict rules.
README.md Documents sourced-console discovery/streaming and updates --csv coverage list.
docs/console.md Adds detailed sourced-console UX docs and timeout/cleanup behavior.
Cargo.toml Bumps crazyflie-link and pins crazyflie-lib to a git rev with sourced-console support.
Cargo.lock Updates lockfile for dependency changes and bumps cfcli version.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/modules/console.rs Outdated
Comment on lines +89 to +90
*enabled_source = Some(selector);
cf.console.enable(selector).await?;
crazyflie-lib now exposes all consoles as equal entries, cf:stm32 being
one of them, so cfcli no longer treats the STM32 console as a default.

Running `console` in a terminal asks which console to show, skipping the
question when there is only one. `--source <PATH>` selects it on the
command line and is required in non-interactive use, so `console` alone
now exits with code 30 there. `--list-sources` is renamed `--list` and
includes cf:stm32.

Move to the library's handle API, closing the handle in the bounded
cleanup after a timeout or a signal. Signal cleanup now applies to every
console. Preserved history stays tied to cf:stm32.

Not tested on hardware.
The completion cache now also holds the connected Crazyflie's console
paths, written on every connection like the param and log names, and
`cfcli __complete console-paths` offers them in bash, zsh and PowerShell.

Listing the consoles asks the Crazyflie for its catalog, so it is given
500 ms. When it does not answer in time, the paths cached from the
previous connection are kept, with cf:stm32 always offered. A cache
written by an older cfcli still loads.

In bash, ':' splits the word being completed, so the path is rebuilt
from the line and only the part after its last ':' is replaced. Files
are not offered for --source.

Tested on a Crazyflie 2.1 Brushless with a Camera Deck: the cache lists
cf:stm32 and deck:bcCam, connecting takes no measurably longer, and Tab
completes the paths in bash. zsh and PowerShell were not run.
@ataffanel
ataffanel merged commit 688e5ac into main Nov 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants