Skip to content
Snippets Groups Projects
Commit 737f7df6 authored by Beat Küng's avatar Beat Küng
Browse files

Subscription & SubscriptionArray: add forcedUpdate() methods

Can be used to immediately get & use the data, as needed for the flight
tasks.
parent 071b09c6
No related branches found
No related tags found
No related merge requests found
......@@ -151,6 +151,8 @@ public:
return -3;
}
_subscription_array.forcedUpdate(); // make sure data is available for all new subscriptions
_current_task_index = task_number;
return 0;
}
......
......@@ -76,3 +76,10 @@ void SubscriptionArray::update()
_subscriptions[i]->update();
}
}
void SubscriptionArray::forcedUpdate()
{
for (int i = 0; i < _subscriptions_count; ++i) {
_subscriptions[i]->forcedUpdate();
}
}
......@@ -60,10 +60,15 @@ public:
bool get(const struct orb_metadata *meta, uORB::Subscription<T> *&subscription, unsigned instance = 0);
/**
* update all subscriptions
* update all subscriptions (if new data is available)
*/
void update();
/**
* update all subscriptions
*/
void forcedUpdate();
private:
void cleanup();
......
......@@ -125,13 +125,18 @@ public:
*/
virtual bool update() = 0;
/**
* Like update(), but does not check first if there is data available
*/
virtual bool forcedUpdate() = 0;
};
/**
* Subscription wrapper class
*/
template<class T>
class __EXPORT Subscription final : public SubscriptionNode
class __EXPORT Subscription : public SubscriptionNode
{
public:
/**
......@@ -150,7 +155,7 @@ public:
_data() // initialize data structure to zero
{}
~Subscription() override final = default;
~Subscription() override = default;
// no copy, assignment, move, move assignment
Subscription(const Subscription &) = delete;
......@@ -161,11 +166,16 @@ public:
/**
* Create an update function that uses the embedded struct.
*/
bool update() override final
bool update() override
{
return SubscriptionBase::update((void *)(&_data));
}
bool forcedUpdate() override
{
return orb_copy(_meta, _handle, &_data) == PX4_OK;
}
/*
* This function gets the T struct data
* */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment