mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-24 09:46:36 +08:00
mavlink: add function to copy only if updated
The MavlinkOrbSubscription only had an interface to either always copy or copy based on a timestamp. This commit adds a copy interface if the topic has been updated.
This commit is contained in:
@@ -74,7 +74,7 @@ MavlinkOrbSubscription::get_instance() const
|
||||
}
|
||||
|
||||
bool
|
||||
MavlinkOrbSubscription::update(uint64_t *time, void* data)
|
||||
MavlinkOrbSubscription::update(uint64_t *time, void *data)
|
||||
{
|
||||
// TODO this is NOT atomic operation, we can get data newer than time
|
||||
// if topic was published between orb_stat and orb_copy calls.
|
||||
@@ -106,11 +106,34 @@ MavlinkOrbSubscription::update(uint64_t *time, void* data)
|
||||
}
|
||||
|
||||
bool
|
||||
MavlinkOrbSubscription::update(void* data)
|
||||
MavlinkOrbSubscription::update(void *data)
|
||||
{
|
||||
return !orb_copy(_topic, _fd, data);
|
||||
}
|
||||
|
||||
bool
|
||||
MavlinkOrbSubscription::update_if_changed(void *data)
|
||||
{
|
||||
bool updated;
|
||||
if (orb_check(_fd, &updated)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (orb_copy(_topic, _fd, data)) {
|
||||
if (data != nullptr) {
|
||||
/* error copying topic data */
|
||||
memset(data, 0, _topic->o_size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
MavlinkOrbSubscription::is_published()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user