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:
Julian Oes
2016-07-13 10:10:45 +02:00
parent 8ded6a58ab
commit 8345a0368b
2 changed files with 42 additions and 8 deletions
@@ -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()
{