mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-12 15:20:35 +08:00
uORB add ORB_COMMUNICATOR define to enable remote uORB
This commit is contained in:
committed by
Lorenz Meier
parent
6579b7254a
commit
8599495082
@@ -63,7 +63,11 @@
|
||||
#include "uORBDevices.hpp"
|
||||
#include "uORBUtils.hpp"
|
||||
#include "uORBManager.hpp"
|
||||
|
||||
#ifdef ORB_COMMUNICATOR
|
||||
#include "uORBCommunicator.hpp"
|
||||
#endif /* ORB_COMMUNICATOR */
|
||||
|
||||
#include <px4_sem.hpp>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -85,14 +89,8 @@ uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const char *name,
|
||||
int priority, unsigned int queue_size) :
|
||||
CDev(name, path),
|
||||
_meta(meta),
|
||||
_data(nullptr),
|
||||
_last_update(0),
|
||||
_generation(0),
|
||||
_priority((uint8_t)priority),
|
||||
_published(false),
|
||||
_queue_size(queue_size),
|
||||
_subscriber_count(0),
|
||||
_publisher(0)
|
||||
_queue_size(queue_size)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -163,7 +161,9 @@ uORB::DeviceNode::open(device::file_t *filp)
|
||||
|
||||
ret = CDev::open(filp);
|
||||
|
||||
#ifdef ORB_COMMUNICATOR
|
||||
add_internal_subscriber();
|
||||
#endif /* ORB_COMMUNICATOR */
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
PX4_ERR("CDev::open failed");
|
||||
@@ -196,7 +196,10 @@ uORB::DeviceNode::close(device::file_t *filp)
|
||||
hrt_cancel(&sd->update_interval->update_call);
|
||||
}
|
||||
|
||||
#ifdef ORB_COMMUNICATOR
|
||||
remove_internal_subscriber();
|
||||
#endif /* ORB_COMMUNICATOR */
|
||||
|
||||
delete sd;
|
||||
sd = nullptr;
|
||||
}
|
||||
@@ -454,6 +457,7 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
#ifdef ORB_COMMUNICATOR
|
||||
/*
|
||||
* if the write is successful, send the data over the Multi-ORB link
|
||||
*/
|
||||
@@ -466,6 +470,8 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ORB_COMMUNICATOR */
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
@@ -493,6 +499,7 @@ int uORB::DeviceNode::unadvertise(orb_advert_t handle)
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
#ifdef ORB_COMMUNICATOR
|
||||
int16_t uORB::DeviceNode::topic_advertised(const orb_metadata *meta, int priority)
|
||||
{
|
||||
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
|
||||
@@ -503,6 +510,7 @@ int16_t uORB::DeviceNode::topic_advertised(const orb_metadata *meta, int priorit
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
//TODO: Check if we need this since we only unadvertise when things all shutdown and it doesn't actually remove the device
|
||||
int16_t uORB::DeviceNode::topic_unadvertised(const orb_metadata *meta, int priority)
|
||||
@@ -514,6 +522,7 @@ int16_t uORB::DeviceNode::topic_unadvertised(const orb_metadata *meta, int prior
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
#endif /* ORB_COMMUNICATOR */
|
||||
|
||||
pollevent_t
|
||||
uORB::DeviceNode::poll_state(device::file_t *filp)
|
||||
@@ -728,8 +737,7 @@ uORB::DeviceNode::print_statistics(bool reset)
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef ORB_COMMUNICATOR
|
||||
void uORB::DeviceNode::add_internal_subscriber()
|
||||
{
|
||||
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
|
||||
@@ -746,8 +754,6 @@ void uORB::DeviceNode::add_internal_subscriber()
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void uORB::DeviceNode::remove_internal_subscriber()
|
||||
{
|
||||
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
|
||||
@@ -764,31 +770,6 @@ void uORB::DeviceNode::remove_internal_subscriber()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
bool uORB::DeviceNode::is_published()
|
||||
{
|
||||
return _published;
|
||||
}
|
||||
|
||||
int uORB::DeviceNode::update_queue_size(unsigned int queue_size)
|
||||
{
|
||||
if (_queue_size == queue_size) {
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
//queue size is limited to 255 for the single reason that we use uint8 to store it
|
||||
if (_data || _queue_size > queue_size || queue_size > 255) {
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
_queue_size = queue_size;
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
int16_t uORB::DeviceNode::process_add_subscription(int32_t rateInHz)
|
||||
{
|
||||
// if there is already data in the node, send this out to
|
||||
@@ -803,15 +784,11 @@ int16_t uORB::DeviceNode::process_add_subscription(int32_t rateInHz)
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
int16_t uORB::DeviceNode::process_remove_subscription()
|
||||
{
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
int16_t uORB::DeviceNode::process_received_message(int32_t length, uint8_t *data)
|
||||
{
|
||||
int16_t ret = -1;
|
||||
@@ -835,6 +812,22 @@ int16_t uORB::DeviceNode::process_received_message(int32_t length, uint8_t *data
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
#endif /* ORB_COMMUNICATOR */
|
||||
|
||||
int uORB::DeviceNode::update_queue_size(unsigned int queue_size)
|
||||
{
|
||||
if (_queue_size == queue_size) {
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
//queue size is limited to 255 for the single reason that we use uint8 to store it
|
||||
if (_data || _queue_size > queue_size || queue_size > 255) {
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
_queue_size = queue_size;
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
uORB::DeviceMaster::DeviceMaster() :
|
||||
CDev("obj_master", TOPIC_MASTER_DEVICE_PATH)
|
||||
|
||||
Reference in New Issue
Block a user