Skip to main content

Crate tag_tools

Crate tag_tools 

Source
Expand description

Shared command-line handling for the Rust tag tools.

Port of host/commandline/options.cc and the parts of log.c the tools rely on. Every tool that talks to a tag flattens BaseArgs into its own arguments, calls init_logging, then select_base to find the ST-LINK, exactly as the C++ tools call parse_options():

  • -d/--debug logs at DEBUG; otherwise only errors are logged.
  • -b/--base bus:device picks a base. It is required when more than one ST-LINK is connected; with none connected the tool exits.

Log lines go to stderr as HH:MM:SS LEVEL file:line: message, the format of log.c.

Selecting a base touches no hardware beyond USB enumeration; it is the tool’s later Tag::attach that resets the tag.

§Examples

The skeleton every tool follows (Cli is the tool’s own clap parser):

use clap::Parser;
use tag_tools::{BaseArgs, init_logging, select_base};
use tagcore::Tag;

#[derive(Parser)]
struct Cli {
    #[command(flatten)]
    base: BaseArgs,
}

let cli = Cli::parse();
init_logging(&cli.base);
let tag = Tag::new();
let dev = select_base::<Cli>(&tag, &cli.base);
if !tag.attach(&dev) {
    std::process::exit(1);
}

Structs§

BaseArgs
The options every tag tool shares (options.cc).

Functions§

enum_name
The protobuf name of an enum value of type E, or its number.
exit_on_interrupt
Exits with status 1 on Ctrl-C, as the C++ tools’ SIGINT handler does.
init_logging
Starts logging to stderr in the log.c format, at DEBUG with --debug and at ERROR otherwise.
init_logging_at
Starts logging to stderr in the log.c format at level.
parse_bus_device
Parses bus:device as sscanf("%u:%u") would, into USB bus and address.
select_base
Finds the ST-LINK the arguments select, or exits.
set_log_level
Changes the log level after init_logging, as log_set_level() does.
state_name
The protobuf name of a tag state number, such as "IDLE", or the number itself when it has no name, as TagState_Name() prints it.