Skip to content
138 changes: 138 additions & 0 deletions CRATE_USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Focused guidance for using the bbl_parser Rust crate.
- [Basic usage](#basic-usage)
- [Multi-log processing](#multi-log-processing)
- [Parsing from memory](#parsing-from-memory)
- [Export functionality](#export-functionality)
- [Examples](#examples)
- [Notes](#notes)

Expand Down Expand Up @@ -78,6 +79,143 @@ fn main() -> anyhow::Result<()> {
}
```

## Export functionality

The crate now provides full export capabilities for CSV, GPX, and Event data formats.

### CSV Export

Export parsed log data to CSV files (flight data + headers):

```rust
use bbl_parser::{parse_bbl_file, export_to_csv, ExportOptions};
use std::path::Path;

fn main() -> anyhow::Result<()> {
let export_opts = ExportOptions {
csv: true,
gpx: false,
event: false,
output_dir: Some("output".to_string()),
force_export: false,
};

let log = parse_bbl_file(Path::new("flight.BBL"), export_opts.clone(), false)?;
export_to_csv(&log, Path::new("flight.BBL"), &export_opts)?;
println!("CSV exported successfully");
Ok(())
}
```

This creates two files:
- `flight.csv` - Main flight data with blackbox_decode compatible format
- `flight.headers.csv` - Complete header information

### GPX Export

Export GPS data to GPX format for mapping applications:

```rust
use bbl_parser::{parse_bbl_file, export_to_gpx, ExportOptions};
use std::path::Path;

fn main() -> anyhow::Result<()> {
let export_opts = ExportOptions {
csv: false,
gpx: true,
event: false,
output_dir: None,
force_export: false,
};

let log = parse_bbl_file(Path::new("flight.BBL"), export_opts.clone(), false)?;

if !log.gps_coordinates.is_empty() {
export_to_gpx(
Path::new("flight.BBL"),
0, // log index
log.total_logs,
&log.gps_coordinates,
&log.home_coordinates,
&export_opts
)?;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
println!("GPX exported successfully");
}
Ok(())
}
```

### Event Export

Export flight events to JSONL format:

```rust
use bbl_parser::{parse_bbl_file, export_to_event, ExportOptions};
use std::path::Path;

fn main() -> anyhow::Result<()> {
let export_opts = ExportOptions {
csv: false,
gpx: false,
event: true,
output_dir: None,
force_export: false,
};

let log = parse_bbl_file(Path::new("flight.BBL"), export_opts.clone(), false)?;

if !log.event_frames.is_empty() {
export_to_event(
Path::new("flight.BBL"),
0, // log index
log.total_logs,
&log.event_frames,
&export_opts
)?;
println!("Events exported successfully");
}
Ok(())
}
```

### Complete Export Example

Export all formats at once:

```rust
use bbl_parser::{parse_bbl_file, export_to_csv, export_to_gpx, export_to_event, ExportOptions};
use std::path::Path;

fn main() -> anyhow::Result<()> {
let export_opts = ExportOptions {
csv: true,
gpx: true,
event: true,
output_dir: Some("output".to_string()),
force_export: false,
};

let input_path = Path::new("flight.BBL");
let log = parse_bbl_file(input_path, export_opts.clone(), false)?;

// Export CSV
export_to_csv(&log, input_path, &export_opts)?;

// Export GPX if GPS data exists
if !log.gps_coordinates.is_empty() {
export_to_gpx(input_path, 0, log.total_logs, &log.gps_coordinates, &log.home_coordinates, &export_opts)?;
}

// Export events if event data exists
if !log.event_frames.is_empty() {
export_to_event(input_path, 0, log.total_logs, &log.event_frames, &export_opts)?;
}

println!("All exports completed successfully");
Ok(())
}
```

## Examples

Run the crate example that demonstrates multi-firmware support and PID extraction:
Expand Down
14 changes: 6 additions & 8 deletions OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,22 @@ The BBL parser implements a streaming architecture designed for memory efficienc
- **E-frames:** Flight events with official Betaflight FlightLogEvent enum mapping

### **Export Functionality**
- **CSV Export:** blackbox_decode compatible format with proper field ordering (CLI functional, crate stub)
- **GPX Export:** Standard GPS exchange format for mapping applications (CLI functional)
- **Event Export:** JSONL format with Betaflight event type descriptions (CLI functional)

**Note:** Export functionality is currently implemented in the CLI (`src/main.rs`). Crate-level export functions in `src/export.rs` are stubs pending systematic migration.
- **CSV Export:** blackbox_decode compatible format with proper field ordering (CLI and crate functional)
- **GPX Export:** Standard GPS exchange format for mapping applications (CLI and crate functional)
- **Event Export:** JSONL format with Betaflight event type descriptions (CLI and crate functional)

### **Encoding Support**
BBL encoding compatibility: `SIGNED_VB`, `UNSIGNED_VB`, `NEG_14BIT`, `TAG8_8SVB`, `TAG2_3S32`, `TAG8_4S16`

### **Project Structure**
```text
src/
├── main.rs # CLI interface, file handling, statistics, CSV export
├── main.rs # CLI interface, file handling, statistics
├── lib.rs # Library API exports and documentation
├── bbl_format.rs # BBL binary format decoding and encoding
├── conversion.rs # Unit conversions (GPS coordinates, altitude, speed)
├── error.rs # Error handling and result types
├── export.rs # Export function stubs (CSV/GPX/Event migration in progress)
├── export.rs # Export functions for CSV/GPX/Event formats
├── types/ # Core data structures
│ ├── mod.rs # Module definitions and re-exports
│ ├── log.rs # BBLLog container type
Expand Down Expand Up @@ -127,7 +125,7 @@ src/
- **Serde Integration:** Optional serialization support for data structures
- **Rust Crate:** Available as library dependency for 3rd party projects

### **Data Export Capabilities (CLI)**
### **Data Export Capabilities (CLI and Crate)**
- **CSV Export:** blackbox_decode compatible field ordering and formatting
- Main flight data `[.XX].csv` with proper field order and "time (us)" column
- Headers `[.XX].headers.csv` with complete configuration
Expand Down
Loading
Loading