Skip to content

Commit

Permalink
added functionality to download geofences and rallypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mattes-bru committed Sep 25, 2024
1 parent ae43792 commit 9db1641
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ class MissionRaw : public PluginBase {
*/
void download_mission_async(const DownloadMissionCallback callback);

/**
* @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 DownloadMissionCallback callback);

/**
* @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 DownloadMissionCallback callback);

/**
* @brief Download a list of raw mission items from the system (asynchronous).
*
Expand All @@ -269,6 +283,24 @@ class MissionRaw : public PluginBase {
*/
std::pair<Result, std::vector<MissionRaw::MissionItem>> download_mission() const;

/**
* @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 Download a list of raw rallypoint items from the system (asynchronous).
*
* This function is blocking. See 'download_rallypoint_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 Expand Up @@ -463,4 +495,4 @@ class MissionRaw : public PluginBase {
std::unique_ptr<MissionRawImpl> _impl;
};

} // namespace mavsdk
} // namespace mavsdk
22 changes: 21 additions & 1 deletion src/mavsdk/plugins/mission_raw/mission_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,32 @@ void MissionRaw::download_mission_async(const DownloadMissionCallback callback)
_impl->download_mission_async(callback);
}

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

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

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

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

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 Expand Up @@ -289,4 +309,4 @@ std::ostream& operator<<(std::ostream& str, MissionRaw::Result const& result)
}
}

} // namespace mavsdk
} // namespace mavsdk
78 changes: 78 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,30 @@ 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 +293,60 @@ void MissionRawImpl::download_mission_async(const MissionRaw::DownloadMissionCal
});
}

void MissionRawImpl::download_geofence_async(const MissionRaw::DownloadMissionCallback &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::DownloadMissionCallback &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

0 comments on commit 9db1641

Please sign in to comment.