|
|
|
@ -42,36 +42,59 @@
@@ -42,36 +42,59 @@
|
|
|
|
|
namespace uORB |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
bool Subscription::subscribe() |
|
|
|
|
bool |
|
|
|
|
Subscription::subscribe() |
|
|
|
|
{ |
|
|
|
|
DeviceMaster *device_master = uORB::Manager::get_instance()->get_device_master(); |
|
|
|
|
_node = device_master->getDeviceNode(_meta, _instance); |
|
|
|
|
// valid ORB_ID required
|
|
|
|
|
if (_meta == nullptr) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if already subscribed
|
|
|
|
|
if (_node != nullptr) { |
|
|
|
|
_node->add_internal_subscriber(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DeviceMaster *device_master = uORB::Manager::get_instance()->get_device_master(); |
|
|
|
|
|
|
|
|
|
// If there were any previous publications, allow the subscriber to read them
|
|
|
|
|
const unsigned curr_gen = _node->published_message_count(); |
|
|
|
|
const unsigned q_size = _node->get_queue_size(); |
|
|
|
|
if (device_master != nullptr) { |
|
|
|
|
uORB::DeviceNode *node = device_master->getDeviceNode(_meta, _instance); |
|
|
|
|
|
|
|
|
|
_last_generation = curr_gen - (q_size < curr_gen ? q_size : curr_gen); |
|
|
|
|
if (node != nullptr) { |
|
|
|
|
_node = node; |
|
|
|
|
_node->add_internal_subscriber(); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
// If there were any previous publications, allow the subscriber to read them
|
|
|
|
|
const unsigned curr_gen = _node->published_message_count(); |
|
|
|
|
const uint8_t q_size = _node->get_queue_size(); |
|
|
|
|
|
|
|
|
|
if (q_size < curr_gen) { |
|
|
|
|
_last_generation = curr_gen - q_size; |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
_last_generation = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Subscription::unsubscribe() |
|
|
|
|
void |
|
|
|
|
Subscription::unsubscribe() |
|
|
|
|
{ |
|
|
|
|
if (_node != nullptr) { |
|
|
|
|
_node->remove_internal_subscriber(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_node = nullptr; |
|
|
|
|
_last_generation = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Subscription::init() |
|
|
|
|
bool |
|
|
|
|
Subscription::init() |
|
|
|
|
{ |
|
|
|
|
if (_meta != nullptr) { |
|
|
|
|
// this throttles the relatively expensive calls to getDeviceNode()
|
|
|
|
@ -90,18 +113,8 @@ bool Subscription::init()
@@ -90,18 +113,8 @@ bool Subscription::init()
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Subscription::forceInit() |
|
|
|
|
{ |
|
|
|
|
if (_node == nullptr) { |
|
|
|
|
// reset generation to force subscription attempt
|
|
|
|
|
_last_generation = 0; |
|
|
|
|
return subscribe(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Subscription::update(uint64_t *time, void *dst) |
|
|
|
|
bool |
|
|
|
|
Subscription::update(uint64_t *time, void *dst) |
|
|
|
|
{ |
|
|
|
|
if ((time != nullptr) && (dst != nullptr) && published()) { |
|
|
|
|
// always copy data to dst regardless of update
|
|
|
|
|