Skip to content

Commit

Permalink
added functionality to download geofences and rallypoints (#2404)
Browse files Browse the repository at this point in the history
* added functionality to download geofences and rallypoints

* added missing protobuffer code

* Update merged proto and fixed style

---------

Co-authored-by: Julian Oes <[email protected]>
  • Loading branch information
mattes-bru and julianoes authored Sep 30, 2024
1 parent d2ce771 commit 0b564f0
Show file tree
Hide file tree
Showing 10 changed files with 2,706 additions and 433 deletions.
2 changes: 1 addition & 1 deletion proto
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,48 @@ class MissionRaw : public PluginBase {
*/
std::pair<Result, std::vector<MissionRaw::MissionItem>> download_mission() const;

/**
* @brief Callback type for download_geofence_async.
*/
using DownloadGeofenceCallback = std::function<void(Result, std::vector<MissionItem>)>;

/**
* @brief Download a list of raw geofence items from the system (asynchronous).
*
* This function is non-blocking. See 'download_geofence' for the blocking counterpart.
*/
void download_geofence_async(const DownloadGeofenceCallback callback);

/**
* @brief Download a list of raw geofence items from the system (asynchronous).
*
* This function is blocking. See 'download_geofence_async' for the non-blocking counterpart.
*
* @return Result of request.
*/
std::pair<Result, std::vector<MissionRaw::MissionItem>> download_geofence() const;

/**
* @brief Callback type for download_rallypoints_async.
*/
using DownloadRallypointsCallback = std::function<void(Result, std::vector<MissionItem>)>;

/**
* @brief Download a list of raw rallypoint items from the system (asynchronous).
*
* This function is non-blocking. See 'download_rallypoints' for the blocking counterpart.
*/
void download_rallypoints_async(const DownloadRallypointsCallback callback);

/**
* @brief Download a list of raw rallypoint items from the system (asynchronous).
*
* This function is blocking. See 'download_rallypoints_async' for the non-blocking counterpart.
*
* @return Result of request.
*/
std::pair<Result, std::vector<MissionRaw::MissionItem>> download_rallypoints() const;

/**
* @brief Cancel an ongoing mission download.
*
Expand Down
22 changes: 22 additions & 0 deletions src/mavsdk/plugins/mission_raw/mission_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ MissionRaw::download_mission() const
return _impl->download_mission();
}

void MissionRaw::download_geofence_async(const DownloadGeofenceCallback callback)
{
_impl->download_geofence_async(callback);
}

std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>>
MissionRaw::download_geofence() const
{
return _impl->download_geofence();
}

void MissionRaw::download_rallypoints_async(const DownloadRallypointsCallback callback)
{
_impl->download_rallypoints_async(callback);
}

std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>>
MissionRaw::download_rallypoints() const
{
return _impl->download_rallypoints();
}

MissionRaw::Result MissionRaw::cancel_mission_download() const
{
return _impl->cancel_mission_download();
Expand Down
81 changes: 81 additions & 0 deletions src/mavsdk/plugins/mission_raw/mission_raw_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,32 @@ MissionRawImpl::download_mission()
return fut.get();
}

std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>>
MissionRawImpl::download_geofence()
{
auto prom = std::promise<std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>>>();
auto fut = prom.get_future();

download_geofence_async(
[&prom](MissionRaw::Result result, std::vector<MissionRaw::MissionItem> geofence) {
prom.set_value(std::make_pair<>(result, geofence));
});
return fut.get();
}

std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>>
MissionRawImpl::download_rallypoints()
{
auto prom = std::promise<std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>>>();
auto fut = prom.get_future();

download_rallypoints_async(
[&prom](MissionRaw::Result result, std::vector<MissionRaw::MissionItem> rallypoints) {
prom.set_value(std::make_pair<>(result, rallypoints));
});
return fut.get();
}

void MissionRawImpl::download_mission_async(const MissionRaw::DownloadMissionCallback& callback)
{
auto work_item = _last_download.lock();
Expand Down Expand Up @@ -269,6 +295,61 @@ void MissionRawImpl::download_mission_async(const MissionRaw::DownloadMissionCal
});
}

void MissionRawImpl::download_geofence_async(const MissionRaw::DownloadGeofenceCallback& callback)
{
auto work_item = _last_download.lock();
if (work_item && !work_item->is_done()) {
_system_impl->call_user_callback([callback]() {
if (callback) {
std::vector<MissionRaw::MissionItem> empty_items;
callback(MissionRaw::Result::Busy, empty_items);
}
});
return;
}

_last_download = _system_impl->mission_transfer_client().download_items_async(
MAV_MISSION_TYPE_FENCE,
_system_impl->get_system_id(),
[this, callback](
MavlinkMissionTransferClient::Result result,
std::vector<MavlinkMissionTransferClient::ItemInt> items) {
auto converted_result = convert_result(result);
auto converted_items = convert_items(items);
_system_impl->call_user_callback([callback, converted_result, converted_items]() {
callback(converted_result, converted_items);
});
});
}

void MissionRawImpl::download_rallypoints_async(
const MissionRaw::DownloadRallypointsCallback& callback)
{
auto work_item = _last_download.lock();
if (work_item && !work_item->is_done()) {
_system_impl->call_user_callback([callback]() {
if (callback) {
std::vector<MissionRaw::MissionItem> empty_items;
callback(MissionRaw::Result::Busy, empty_items);
}
});
return;
}

_last_download = _system_impl->mission_transfer_client().download_items_async(
MAV_MISSION_TYPE_RALLY,
_system_impl->get_system_id(),
[this, callback](
MavlinkMissionTransferClient::Result result,
std::vector<MavlinkMissionTransferClient::ItemInt> items) {
auto converted_result = convert_result(result);
auto converted_items = convert_items(items);
_system_impl->call_user_callback([callback, converted_result, converted_items]() {
callback(converted_result, converted_items);
});
});
}

MissionRaw::Result MissionRawImpl::cancel_mission_download()
{
auto ptr = _last_download.lock();
Expand Down
4 changes: 4 additions & 0 deletions src/mavsdk/plugins/mission_raw/mission_raw_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class MissionRawImpl : public PluginImplBase {
void disable() override;

std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>> download_mission();
std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>> download_geofence();
std::pair<MissionRaw::Result, std::vector<MissionRaw::MissionItem>> download_rallypoints();
void download_mission_async(const MissionRaw::DownloadMissionCallback& callback);
void download_geofence_async(const MissionRaw::DownloadMissionCallback& callback);
void download_rallypoints_async(const MissionRaw::DownloadMissionCallback& callback);
MissionRaw::Result cancel_mission_download();

MissionRaw::Result upload_mission(std::vector<MissionRaw::MissionItem> mission_items);
Expand Down
Loading

0 comments on commit 0b564f0

Please sign in to comment.