Skip to content

Commit

Permalink
Merge pull request #2325 from mavlink/pr-mission-changed
Browse files Browse the repository at this point in the history
mission_raw: implement mission changed based on opaque ID
  • Loading branch information
julianoes committed Jun 2, 2024
2 parents 11f569b + 84a4dc1 commit bc8da64
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ jobs:
container: alpine:3.19.0
steps:
- name: install tools
run: apk update && apk add build-base cmake git linux-headers perl tar python3 py3-pip
run: apk update && apk add build-base cmake git linux-headers perl tar python3 py3-pip rust cargo
- uses: actions/checkout@v4
with:
submodules: recursive
Expand Down
26 changes: 21 additions & 5 deletions src/mavsdk/plugins/mission_raw/mission_raw_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ void MissionRawImpl::process_mission_ack(const mavlink_message_t& message)
return;
}

// We assume that if the vehicle sends an ACCEPTED ack might have received
// a new mission. In that case we need to notify our user.
std::lock_guard<std::mutex> lock(_mission_changed.mutex);
_mission_changed.callbacks.queue(
true, [this](const auto& func) { _system_impl->call_user_callback(func); });
// We assume that if the vehicle sends an ACCEPTED ack, we might have received
// a new mission. In that case we can notify our user.
// However, with the (opaque) mission_id, we can determine this properly using
// the id. Therefore, we only do the notification if the opaque ID is 0 and
// therefore not yet supported. This way we stay backwards compatible with
// previous autopilot versions.
if (mission_ack.opaque_id == 0) {
std::lock_guard<std::mutex> lock(_mission_changed.mutex);
_mission_changed.callbacks.queue(
true, [this](const auto& func) { _system_impl->call_user_callback(func); });
}
}

void MissionRawImpl::process_mission_current(const mavlink_message_t& message)
Expand All @@ -100,6 +106,16 @@ void MissionRawImpl::process_mission_current(const mavlink_message_t& message)
_mission_progress.last.current = mission_current.seq;
}
}
{
std::lock_guard<std::mutex> lock(_mission_changed.mutex);
if (_mission_changed.last_mission_id != mission_current.mission_id) {
_mission_changed.last_mission_id = mission_current.mission_id;

_mission_changed.callbacks.queue(
true, [this](const auto& func) { _system_impl->call_user_callback(func); });
LogDebug() << "Mission changed";
}
}

report_progress_current();
}
Expand Down
1 change: 1 addition & 0 deletions src/mavsdk/plugins/mission_raw/mission_raw_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class MissionRawImpl : public PluginImplBase {
struct {
std::mutex mutex{};
CallbackList<bool> callbacks{};
uint32_t last_mission_id{0};
} _mission_changed{};
};

Expand Down
2 changes: 1 addition & 1 deletion third_party/mavlink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ list(APPEND CMAKE_ARGS
"-DMAVLINK_DIALECT=${MAVLINK_DIALECT}"
)

set(MAVLINK_GIT_HASH 9840105a275db1f48f9711d0fb861e8bf77a2245)
set(MAVLINK_GIT_HASH f1d42e2774cae767a1c0651b0f95e3286c587257)

if(IOS)
ExternalProject_add(
Expand Down

0 comments on commit bc8da64

Please sign in to comment.