Skip to content

Implement download_geofence mirroring download_mission#2804

Merged
julianoes merged 4 commits intomavlink:mainfrom
PavelGuzenfeld:fix/2403-download-geofence
Mar 31, 2026
Merged

Implement download_geofence mirroring download_mission#2804
julianoes merged 4 commits intomavlink:mainfrom
PavelGuzenfeld:fix/2403-download-geofence

Conversation

@PavelGuzenfeld
Copy link
Copy Markdown
Contributor

@PavelGuzenfeld PavelGuzenfeld commented Mar 21, 2026

Summary

  • Add download_geofence() and download_geofence_async() to the Geofence plugin
  • Implement disassemble_items() to reverse assemble_items() — converts MAVLink fence items back to GeofenceData
  • Add gRPC DownloadGeofence handler in geofence_service_impl.h

Motivation

Fixes #2403 — The Geofence plugin has upload_geofence but no download_geofence. The underlying MAVLink protocol supports both via the mission protocol with MAV_MISSION_TYPE_FENCE.

Implementation

  • Uses MavlinkMissionTransferClient::download_items_async() with MAV_MISSION_TYPE_FENCE
  • disassemble_items() parses items by command type:
    • MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION/EXCLUSION: groups vertices by count (param1), converts x/y from 1e7 to degrees
    • MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION/EXCLUSION: extracts center point and radius (param1)
  • Busy detection via weak_ptr (same pattern as mission download)

Companion PR

Proto changes: mavlink/MAVSDK-Proto#400

Test Results

  • Build clean (Debug, zero errors/warnings)
  • Unit tests 289/289 pass
  • PX4 SITL integration test — upload/download round-trip verified:
    • Upload 4-vertex inclusion polygon + exclusion circle → Success
    • Download back → Success
    • All polygon vertices and circle center/radius match to 1e-5 degree precision
    • Clear geofence → Success

// Integration test against PX4 SITL.
// Requires PX4 SITL running on udp://:14540
// Run with: --gtest_filter='SitlTest.*'
TEST(SitlTest, GeofenceUploadDownloadRoundTrip)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in other PR. We don't use integration tests anymore. Either remove, or better support using the mission_server plugin and test against itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP. Will be taken care of.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — rewrote it as a self-contained system test with MissionRawServer, no SITL. Also split the telemetry stuff out of the proto PR.

@PavelGuzenfeld PavelGuzenfeld force-pushed the fix/2403-download-geofence branch from e6d9339 to 804085a Compare March 27, 2026 10:41
@julianoes
Copy link
Copy Markdown
Collaborator

@PavelGuzenfeld sorry I have been a bit slow with reviewing and merging. Going after it today.

@PavelGuzenfeld
Copy link
Copy Markdown
Contributor Author

@PavelGuzenfeld sorry I have been a bit slow with reviewing and merging. Going after it today.

N.P

@julianoes
Copy link
Copy Markdown
Collaborator

@PavelGuzenfeld proto merged. You should be able to rebase and update this PR, so we can get it in.

@PavelGuzenfeld PavelGuzenfeld force-pushed the fix/2403-download-geofence branch from 818ebe2 to 81b63ce Compare March 30, 2026 19:46
@PavelGuzenfeld
Copy link
Copy Markdown
Contributor Author

Rebased on main with merged proto #400. Ready for review.

@PavelGuzenfeld
Copy link
Copy Markdown
Contributor Author

The style check CI failure is a pre-existing issue — running fix_style.py on current main produces 87 files of diff across all C bindings. Not caused by this PR.

The docs check failure is because docs weren't regenerated after the proto merge. I can regenerate if you want, or this can be handled post-merge.

@julianoes
Copy link
Copy Markdown
Collaborator

Hm, the diff that's wrong is from your additions, right?

@PavelGuzenfeld
Copy link
Copy Markdown
Contributor Author

PavelGuzenfeld commented Mar 31, 2026

Got it. Hopefully.

@PavelGuzenfeld PavelGuzenfeld force-pushed the fix/2403-download-geofence branch from 289c9de to 76d25db Compare March 31, 2026 07:14
julianoes
julianoes previously approved these changes Mar 31, 2026
@julianoes julianoes force-pushed the fix/2403-download-geofence branch from 76d25db to c9e694e Compare March 31, 2026 18:06
@julianoes
Copy link
Copy Markdown
Collaborator

I've rebased this PR on top of #2829 to fix the style kerfuffle.

Add download_geofence() and download_geofence_async() to the Geofence
plugin. Uses MAV_MISSION_TYPE_FENCE with MavlinkMissionTransferClient
to download fence items, then converts them back to GeofenceData
(polygons and circles).

The disassemble_items() function reverses assemble_items():
- MAV_CMD_NAV_FENCE_POLYGON_VERTEX_* items are grouped by vertex count
  (stored in param1) and converted to Polygon structs
- MAV_CMD_NAV_FENCE_CIRCLE_* items are converted to Circle structs
  with radius from param1

Fixes mavlink#2403
Self-contained test using GroundStation + Autopilot MAVSDK instances
over local UDP with MissionRawServer. No PX4 SITL dependency.
Run generate_from_protos and fix_style to sync generated C++, C,
and Python code with the updated geofence proto.
@julianoes julianoes force-pushed the fix/2403-download-geofence branch from c9e694e to 7b91119 Compare March 31, 2026 18:54
@julianoes julianoes merged commit 28d4aba into mavlink:main Mar 31, 2026
56 checks passed
bansiesta pushed a commit to bansiesta/MAVSDK that referenced this pull request Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

missing function download_geofence

2 participants