Skip to content

Commit

Permalink
uORB: ack uorb topic
Browse files Browse the repository at this point in the history
Add uorb interface to just acknowledge the updates for next poll
without needs to copy data from all the updated topics.
  • Loading branch information
Jari Nippula committed Apr 16, 2024
1 parent 4b9ff50 commit 7fbba1d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions platforms/common/uORB/Subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ class Subscription
return valid() ? Manager::orb_data_copy(_node, dst, _last_generation, true) : false;
}

void ack()
{
if (!valid()) {
subscribe();
}

if (valid()) {
Manager::orb_data_ack(_node, _last_generation);
}
}

/**
* Copy the struct
* @param dst The uORB message struct we are updating.
Expand Down
11 changes: 11 additions & 0 deletions platforms/common/uORB/SubscriptionInterval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ class SubscriptionInterval
return false;
}

/**
* Acknowledge a new update.
*/
void ack()
{
_subscription.ack();
const hrt_abstime now = hrt_absolute_time();
// shift last update time forward, but don't let it get further behind than the interval
_last_update = math::constrain(_last_update + _interval_us, now - _interval_us, now);
}

/**
* Copy the struct if updated.
* @param dst The destination pointer where the struct will be copied.
Expand Down
5 changes: 5 additions & 0 deletions platforms/common/uORB/uORB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ int orb_check(orb_sub_t handle, bool *updated)
return uORB::Manager::get_instance()->orb_check(handle, updated);
}

int orb_ack(orb_sub_t handle)
{
return uORB::Manager::get_instance()->orb_ack(handle);
}

int orb_exists(const struct orb_metadata *meta, int instance)
{
return uORB::Manager::orb_exists(meta, instance);
Expand Down
2 changes: 2 additions & 0 deletions platforms/common/uORB/uORB.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ extern int orb_copy(const struct orb_metadata *meta, orb_sub_t handle, void *buf
*/
extern int orb_check(orb_sub_t handle, bool *updated) __EXPORT;

extern int orb_ack(orb_sub_t handle) __EXPORT;

/**
* @see uORB::Manager::orb_exists()
*/
Expand Down
2 changes: 2 additions & 0 deletions platforms/common/uORB/uORBDeviceNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class DeviceNode
*/
bool copy(void *dst, orb_advert_t &handle, unsigned &generation);

void ack(unsigned &generation) { generation = _generation.load(); }

static bool register_callback(orb_advert_t &node_handle, SubscriptionCallback *callback_sub, int8_t poll_lock,
hrt_abstime last_update, uint32_t interval_us, uorb_cb_handle_t &cb_handle)
{
Expand Down
6 changes: 6 additions & 0 deletions platforms/common/uORB/uORBManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ int uORB::Manager::orb_check(orb_sub_t handle, bool *updated)
return PX4_OK;
}

int uORB::Manager::orb_ack(orb_sub_t handle)
{
((uORB::SubscriptionInterval *)handle)->ack();
return PX4_OK;
}

int uORB::Manager::orb_set_interval(orb_sub_t handle, unsigned interval)
{
((uORB::SubscriptionInterval *)handle)->set_interval_us(interval * 1000);
Expand Down
8 changes: 8 additions & 0 deletions platforms/common/uORB/uORBManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ class Manager
*/
static int orb_check(orb_sub_t handle, bool *updated);


static int orb_ack(orb_sub_t handle);

/**
* Check if a topic has already been created and published (advertised)
*
Expand Down Expand Up @@ -356,6 +359,11 @@ class Manager

static uint8_t orb_get_queue_size(const orb_advert_t &node_handle) {return node(node_handle)->get_queue_size();}

static void orb_data_ack(orb_advert_t &node_handle, unsigned &generation)
{
node(node_handle)->ack(generation);
}

static bool orb_data_copy(orb_advert_t &node_handle, void *dst, unsigned &generation,
bool only_if_updated)
{
Expand Down

0 comments on commit 7fbba1d

Please sign in to comment.