Skip to content

Commit b67ffb5

Browse files
committed
refactor(phase5b): Remove duplicate conversion functions from CLI
- Import convert_vbat_to_volts and convert_amperage_to_amps from crate - Remove duplicate function definitions (~55 lines) - Remove unused semver::Version import - Verified: all tests pass, clippy clean Part of issue #16: CLI-to-Crate Unification Phase 5
1 parent 104cd0a commit b67ffb5

1 file changed

Lines changed: 3 additions & 56 deletions

File tree

src/main.rs

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use anyhow::{Context, Result};
22
use clap::{Arg, Command};
33
use glob::glob;
4-
use semver::Version;
54
use std::collections::{HashMap, HashSet};
65
use std::fs;
76
use std::io::Write;
87
use std::path::{Path, PathBuf};
98

109
// Import conversion functions from crate library to avoid code duplication
1110
use bbl_parser::conversion::{
12-
convert_gps_altitude, convert_gps_coordinate, convert_gps_course, convert_gps_speed,
13-
format_failsafe_phase, format_flight_mode_flags, format_state_flags, generate_gpx_timestamp,
11+
convert_amperage_to_amps, convert_gps_altitude, convert_gps_coordinate, convert_gps_course,
12+
convert_gps_speed, convert_vbat_to_volts, format_failsafe_phase, format_flight_mode_flags,
13+
format_state_flags, generate_gpx_timestamp,
1414
};
1515

1616
// Import parser types from crate library
@@ -2260,59 +2260,6 @@ fn parse_numeric_data(numeric_data: &str) -> Vec<u8> {
22602260
.collect()
22612261
}
22622262

2263-
/// Converts raw vbatLatest value to volts using firmware-aware scaling.
2264-
///
2265-
/// Betaflight < 4.3.0: tenths (0.1V units)
2266-
/// Betaflight >= 4.3.0: hundredths (0.01V units)
2267-
/// EmuFlight: always tenths (0.1V units)
2268-
/// iNav: always hundredths (0.01V units)
2269-
fn convert_vbat_to_volts(raw_value: i32, firmware_revision: &str) -> f32 {
2270-
// Determine scaling factor based on firmware
2271-
let scale_factor = if firmware_revision.contains("EmuFlight") {
2272-
// EmuFlight always uses tenths
2273-
0.1
2274-
} else if firmware_revision.contains("iNav") {
2275-
// iNav always uses hundredths
2276-
0.01
2277-
} else if firmware_revision.contains("Betaflight") {
2278-
// Betaflight version-dependent scaling
2279-
if let Some(version) = extract_firmware_version(firmware_revision) {
2280-
if version >= Version::new(4, 3, 0) {
2281-
0.01 // hundredths for >= 4.3.0
2282-
} else {
2283-
0.1 // tenths for < 4.3.0
2284-
}
2285-
} else {
2286-
// Default to modern Betaflight scaling if version can't be parsed
2287-
0.01
2288-
}
2289-
} else {
2290-
// Unknown firmware, default to hundredths
2291-
0.01
2292-
};
2293-
2294-
raw_value as f32 * scale_factor
2295-
}
2296-
2297-
/// Extract version from firmware revision string
2298-
fn extract_firmware_version(firmware_revision: &str) -> Option<Version> {
2299-
// Parse version from strings like "Betaflight 4.5.1 (77d01ba3b) AT32F435M"
2300-
let words: Vec<&str> = firmware_revision.split_whitespace().collect();
2301-
for (i, word) in words.iter().enumerate() {
2302-
if word.to_lowercase().contains("betaflight") && i + 1 < words.len() {
2303-
if let Ok(version) = Version::parse(words[i + 1]) {
2304-
return Some(version);
2305-
}
2306-
}
2307-
}
2308-
None
2309-
}
2310-
2311-
/// Converts raw amperageLatest value to amps (0.01A units)
2312-
fn convert_amperage_to_amps(raw_value: i32) -> f32 {
2313-
raw_value as f32 / 100.0
2314-
}
2315-
23162263
fn parse_bbl_file_streaming(
23172264
file_path: &Path,
23182265
debug: bool,

0 commit comments

Comments
 (0)