mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 10:03:35 +08:00
orb_exists support for muorb
Also added builtin command wait_for_topic Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
committed by
Lorenz Meier
parent
dc787830b5
commit
62a3e07423
@@ -56,6 +56,33 @@ public:
|
||||
// INTERFACES FOR Control messages over a channel.
|
||||
//=========================================================================
|
||||
|
||||
/**
|
||||
* @brief Interface to notify the remote entity of a topic being advertised.
|
||||
*
|
||||
* @param messageName
|
||||
* This represents the uORB message name(aka topic); This message name should be
|
||||
* globally unique.
|
||||
* @return
|
||||
* 0 = success; This means the messages is successfully sent to the receiver
|
||||
* Note: This does not mean that the receiver as received it.
|
||||
* otherwise = failure.
|
||||
*/
|
||||
virtual int16_t topic_advertised(const char *messageName) = 0;
|
||||
|
||||
/**
|
||||
* @brief Interface to notify the remote entity of a topic being unadvertised
|
||||
* and is no longer publishing messages.
|
||||
*
|
||||
* @param messageName
|
||||
* This represents the uORB message name(aka topic); This message name should be
|
||||
* globally unique.
|
||||
* @return
|
||||
* 0 = success; This means the messages is successfully sent to the receiver
|
||||
* Note: This does not mean that the receiver as received it.
|
||||
* otherwise = failure.
|
||||
*/
|
||||
//virtual int16_t topic_unadvertised(const char *messageName) = 0;
|
||||
|
||||
/**
|
||||
* @brief Interface to notify the remote entity of interest of a
|
||||
* subscription for a message.
|
||||
@@ -127,6 +154,21 @@ class uORBCommunicator::IChannelRxHandler
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Interface to process a received topic from remote.
|
||||
* @param topic_name
|
||||
* This represents the uORB message Name (topic); This message Name should be
|
||||
* globally unique.
|
||||
* @param isAdvertisement
|
||||
* Represents if the topic has been advertised or is no longer avialable.
|
||||
* @return
|
||||
* 0 = success; This means the messages is successfully handled in the
|
||||
* handler.
|
||||
* otherwise = failure.
|
||||
*/
|
||||
|
||||
virtual int16_t process_remote_topic(const char *topic_name, bool isAdvertisement) = 0;
|
||||
|
||||
/**
|
||||
* Interface to process a received AddSubscription from remote.
|
||||
* @param messageName
|
||||
|
||||
@@ -489,6 +489,26 @@ int uORB::DeviceNode::unadvertise(orb_advert_t handle)
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
int16_t uORB::DeviceNode::topic_advertised(const orb_metadata *meta, int priority)
|
||||
{
|
||||
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
|
||||
if (ch != nullptr && meta != nullptr) {
|
||||
return ch->topic_advertised(meta->o_name);
|
||||
}
|
||||
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)
|
||||
{
|
||||
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
|
||||
if (ch != nullptr && meta != nullptr) {
|
||||
return ch->topic_unadvertised(meta->o_name);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
pollevent_t
|
||||
uORB::DeviceNode::poll_state(device::file_t *filp)
|
||||
{
|
||||
|
||||
@@ -125,6 +125,9 @@ public:
|
||||
|
||||
static int unadvertise(orb_advert_t handle);
|
||||
|
||||
static int16_t topic_advertised(const orb_metadata *meta, int priority);
|
||||
//static int16_t topic_unadvertised(const orb_metadata *meta, int priority);
|
||||
|
||||
/**
|
||||
* processes a request for add subscription from remote
|
||||
* @param rateInHz
|
||||
|
||||
@@ -131,11 +131,15 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
#if __PX4_NUTTX
|
||||
struct stat buffer;
|
||||
return stat(path, &buffer);
|
||||
#else
|
||||
return px4_access(path, F_OK);
|
||||
ret = px4_access(path, F_OK);
|
||||
if (ret == -1 && meta != nullptr && _remote_topics.size() > 0) {
|
||||
ret = (_remote_topics.find(meta->o_name) != _remote_topics.end());
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -197,6 +201,9 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//For remote systems call over and inform them
|
||||
uORB::DeviceNode::topic_advertised(meta, priority);
|
||||
|
||||
/* the advertiser must perform an initial publish to initialise the object */
|
||||
result = orb_publish(meta, advertiser, data);
|
||||
|
||||
@@ -433,6 +440,23 @@ uORBCommunicator::IChannel *uORB::Manager::get_uorb_communicator(void)
|
||||
return _comm_channel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
int16_t uORB::Manager::process_remote_topic(const char *topic_name, bool isAdvertisement)
|
||||
{
|
||||
warnx("[posix-uORB::Manager::process_remote_topic(%d)] name: %s, isAdver: %d",
|
||||
__LINE__, topic_name, isAdvertisement);
|
||||
int16_t rc = 0;
|
||||
|
||||
if (isAdvertisement) {
|
||||
_remote_topics.insert(topic_name);
|
||||
} else {
|
||||
_remote_topics.erase(topic_name);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
int16_t uORB::Manager::process_add_subscription(const char *messageName,
|
||||
|
||||
@@ -410,6 +410,7 @@ private: // data members
|
||||
// the communicator channel instance.
|
||||
uORBCommunicator::IChannel *_comm_channel;
|
||||
ORBSet _remote_subscriber_topics;
|
||||
ORBSet _remote_topics;
|
||||
|
||||
DeviceMaster *_device_masters[Flavor_count]; ///< Allow at most one DeviceMaster per Flavor
|
||||
|
||||
@@ -417,6 +418,20 @@ private: //class methods
|
||||
Manager();
|
||||
~Manager();
|
||||
|
||||
/**
|
||||
* Interface to process a received topic from remote.
|
||||
* @param topic_name
|
||||
* This represents the uORB message Name (topic); This message Name should be
|
||||
* globally unique.
|
||||
* @param isAdvertisement
|
||||
* Represents if the topic has been advertised or is no longer avialable.
|
||||
* @return
|
||||
* 0 = success; This means the messages is successfully handled in the
|
||||
* handler.
|
||||
* otherwise = failure.
|
||||
*/
|
||||
virtual int16_t process_remote_topic(const char *topic_name, bool isAdvertisement);
|
||||
|
||||
/**
|
||||
* Interface to process a received AddSubscription from remote.
|
||||
* @param messageName
|
||||
|
||||
Reference in New Issue
Block a user