Context
This issue addresses the TODO comment at line 1497 in main.rs:
_home_coords: &[GpsHomeCoordinate], // TODO: Use home coordinates for reference point
Current Status: Functionally Correct ✅
After deep analysis and comparison with blackbox-tools and blackbox-log-viewer, the current implementation is already correct:
What's Working:
- ✅ H frames (GPS home) are correctly parsed from blackbox logs (src/parser/frame.rs:343-367)
- ✅ Home coordinates are correctly used as reference points during GPS decoding (src/parser/frame.rs:430-443)
- ✅ GPS G frames contain deltas from home per Betaflight spec
- ✅ Actual coordinates are calculated as:
actual_position = home_position + delta
- ✅ GPX export receives absolute lat/lon coordinates (not deltas)
Why home_coordinates appears "unused" in GPX export:
The home coordinates are already incorporated into the GPS coordinates during frame parsing. By the time we reach GPX export, gps_coordinates contains absolute positions, so home coordinates don't need to be referenced again.
Enhancement Opportunity: Home Waypoint Marker
While functionally correct, we could enhance GPX files by adding a home position waypoint for better visualization in mapping tools.
Reference Implementation Analysis
Betaflight Blackbox Specification:
GPX 1.1 Specification:
GPX files support both track points (<trkpt>) and waypoints (<wpt>):
<wpt lat="37.123456" lon="-122.123456">
<name>Home</name>
<sym>Flag</sym>
<type>Home Position</type>
</wpt>
Proposed Enhancement
Add a home position waypoint to GPX exports when home coordinates are available. This would:
- ✅ Improve visualization in GPS mapping tools (Google Earth, Garmin BaseCamp, etc.)
- ✅ Provide a clear reference point for flight analysis
- ✅ Match behavior of some GPS analysis tools
- ✅ Remain backward compatible (waypoints are optional in GPX)
Implementation Plan
Phase 1: Add Home Waypoint to GPX Export (Est. 1-2 hours)
File: src/export.rs, function export_to_gpx
Changes:
- Remove underscore prefix from
_home_coordinates parameter (line 296)
- After writing GPX metadata but before
<trk> element, add waypoint logic:
// Add home position waypoint if available
if let Some(home) = home_coordinates.first() {
writeln!(
gpx_file,
r#" <wpt lat="{:.7}" lon="{:.7}">#",
home.home_latitude, home.home_longitude
)?;
writeln!(gpx_file, " <name>Home</name>")?;
writeln!(gpx_file, " <sym>Flag</sym>")?;
writeln!(gpx_file, " <type>Home Position</type>")?;
writeln!(gpx_file, " </wpt>")?;
}
- Update the duplicate logic in
src/main.rs function export_gpx (line 1497) - remove underscore and apply same logic
Validation:
# Test with GPS-enabled log
cargo run -- test.BBL --gpx
# Verify GPX contains home waypoint
grep -A 4 '<wpt' output.gpx
# Validate GPX schema
xmllint --schema http://www.topografix.com/GPX/1/1/gpx.xsd output.gpx
Phase 2: Add Tests (Est. 1 hour)
File: New test in tests/gps_tests.rs or src/export.rs
#[test]
fn test_gpx_includes_home_waypoint() {
let home_coords = vec![GpsHomeCoordinate {
home_latitude: 37.7749,
home_longitude: -122.4194,
timestamp_us: 0,
}];
let gps_coords = vec![/* test coordinates */];
// Export GPX
export_to_gpx(/* params */).unwrap();
// Read and verify GPX contains waypoint
let gpx_content = std::fs::read_to_string("output.gpx").unwrap();
assert!(gpx_content.contains("<wpt lat=\"37.7749\""));
assert!(gpx_content.contains("<name>Home</name>"));
}
Phase 3: Documentation (Est. 30 minutes)
File: README.md or docs/GPS_EXPORT.md
Document:
- GPX files now include home waypoint marker
- Home position derived from H frames in blackbox log
- Waypoint compatible with standard GPS tools
Phase 4: Comparison with blackbox-tools (Est. 1 hour)
Validation:
- Export GPX using blackbox_decode from reference implementation
- Export GPX using bbl_parser
- Compare waypoint handling (they may or may not include home waypoint)
- Document any differences and rationale for bbl_parser's approach
Alternative Considerations
Option A: Only show home waypoint (implemented above)
- Pro: Simple, clear, widely compatible
- Con: Minimal information
Option B: Add metadata to home waypoint
<wpt lat="..." lon="...">
<name>Home</name>
<desc>GPS home position recorded at flight start</desc>
<time>2025-03-26T05:00:00.000000Z</time>
<sym>Flag</sym>
</wpt>
- Pro: More informative, includes timestamp
- Con: Slightly more complex
Option C: Add both home and multiple flight phases as waypoints
- Pro: Rich analysis capability
- Con: Complex, may clutter map view
Recommendation: Start with Option A (simple waypoint), consider Option B if users request more detail.
Testing Checklist
Reference Links
Priority
Low-Medium Priority - This is a quality-of-life enhancement, not a bug fix. Current implementation is functionally correct and produces valid GPS tracks. The enhancement would improve user experience when visualizing flights in mapping tools.
Estimated Effort
Total: 3-4 hours
- Implementation: 1-2 hours
- Testing: 1 hour
- Documentation: 30 minutes
- Validation: 1 hour
AI Implementation Instructions:
If implementing this enhancement, follow the iterative approach:
- Start with Phase 1 - core functionality
- Validate output with sample GPS logs before proceeding
- Add tests in Phase 2 to prevent regressions
- Complete documentation only after functionality is confirmed working
- Optional Phase 4 - compare with reference tools if desired
Each phase should be a separate commit for easy review and potential rollback if needed.
Context
This issue addresses the TODO comment at line 1497 in
main.rs:Current Status: Functionally Correct ✅
After deep analysis and comparison with blackbox-tools and blackbox-log-viewer, the current implementation is already correct:
What's Working:
actual_position = home_position + deltaWhy home_coordinates appears "unused" in GPX export:
The home coordinates are already incorporated into the GPS coordinates during frame parsing. By the time we reach GPX export,
gps_coordinatescontains absolute positions, so home coordinates don't need to be referenced again.Enhancement Opportunity: Home Waypoint Marker
While functionally correct, we could enhance GPX files by adding a home position waypoint for better visualization in mapping tools.
Reference Implementation Analysis
Betaflight Blackbox Specification:
GPX 1.1 Specification:
GPX files support both track points (
<trkpt>) and waypoints (<wpt>):Proposed Enhancement
Add a home position waypoint to GPX exports when home coordinates are available. This would:
Implementation Plan
Phase 1: Add Home Waypoint to GPX Export (Est. 1-2 hours)
File:
src/export.rs, functionexport_to_gpxChanges:
_home_coordinatesparameter (line 296)<trk>element, add waypoint logic:src/main.rsfunctionexport_gpx(line 1497) - remove underscore and apply same logicValidation:
Phase 2: Add Tests (Est. 1 hour)
File: New test in
tests/gps_tests.rsorsrc/export.rsPhase 3: Documentation (Est. 30 minutes)
File:
README.mdordocs/GPS_EXPORT.mdDocument:
Phase 4: Comparison with blackbox-tools (Est. 1 hour)
Validation:
Alternative Considerations
Option A: Only show home waypoint (implemented above)
Option B: Add metadata to home waypoint
Option C: Add both home and multiple flight phases as waypoints
Recommendation: Start with Option A (simple waypoint), consider Option B if users request more detail.
Testing Checklist
Reference Links
Priority
Low-Medium Priority - This is a quality-of-life enhancement, not a bug fix. Current implementation is functionally correct and produces valid GPS tracks. The enhancement would improve user experience when visualizing flights in mapping tools.
Estimated Effort
Total: 3-4 hours
AI Implementation Instructions:
If implementing this enhancement, follow the iterative approach:
Each phase should be a separate commit for easy review and potential rollback if needed.