Crate blackbox_log

source ·
Expand description

Ergonomic parser for Betaflight blackbox logs.

For details about the format of blackbox logs, see the Blackbox Internals development documentation from INAV, Betaflight

§Examples

The simplest way to extract a few fields of interest:

use blackbox_log::frame::FieldDef;
use blackbox_log::prelude::*;
use blackbox_log::Filter;

let filters = blackbox_log::FilterSet {
    // This restricts the included fields to `rcCommand[0]` through `rcCommand[3]`
    main: Filter::OnlyFields(["rcCommand"].into()),
    // ... only `flightModeFlags` for slow frames
    slow: Filter::OnlyFields(["flightModeFlags"].into()),
    // ... and no filter for gps frames -- include all fields
    gps: Filter::Unfiltered,
};

let file = b"...";
for headers in blackbox_log::File::new(file).iter() {
    let headers = headers.expect("valid log headers");

    let mut parser = headers.data_parser_with_filters(&filters);
    while let Some(event) = parser.next() {
        match event {
            ParserEvent::Main(main) => {
                for (value, FieldDef { name, .. }) in
                    main.iter().zip(headers.main_frame_def().iter())
                {
                    println!("{name}: {value:?}");
                }
            }
            ParserEvent::Slow(slow) => {
                for (value, FieldDef { name, .. }) in
                    slow.iter().zip(headers.slow_frame_def().iter())
                {
                    println!("{name}: {value:?}");
                }
            }
            ParserEvent::Event(_) | ParserEvent::Gps(_) => {}
        }
    }
}

Get only the GPS data without parsing logs that cannot contain GPS frames:

use blackbox_log::frame::FieldDef;
use blackbox_log::prelude::*;

let file = b"...";
for headers in blackbox_log::File::new(file).iter() {
    let headers = headers.expect("valid log headers");

    if let Some(gps_def) = &headers.gps_frame_def() {
        let mut parser = headers.data_parser();

        while let Some(event) = parser.next() {
            if let ParserEvent::Gps(gps) = event {
                for (value, FieldDef { name, .. }) in gps.iter().zip(gps_def.iter()) {
                    println!("{name}: {value:?}");
                }
            }
        }
    }
}

§Features

Re-exports§

Modules§

  • Types for the data section of blackbox logs.
  • Types for blackbox log events.
  • Types for blackbox log data frames.
  • Types for the header section of blackbox logs.
  • Minimal set of imports for convenience.

Structs§

Enums§

  • A filter for the fields to include in one kind of frame.