mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-09-28 01:18:55 +08:00
Support topic groups in MAVLink subscription handling
This commit is contained in:
@@ -904,20 +904,20 @@ Mavlink::send_statustext(unsigned char severity, const char *string)
|
|||||||
mavlink_logbuffer_write(&_logbuffer, &logmsg);
|
mavlink_logbuffer_write(&_logbuffer, &logmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
MavlinkOrbSubscription *Mavlink::add_orb_subscription(const orb_id_t topic)
|
MavlinkOrbSubscription *Mavlink::add_orb_subscription(const orb_id_t topic, int instance)
|
||||||
{
|
{
|
||||||
/* check if already subscribed to this topic */
|
/* check if already subscribed to this topic */
|
||||||
MavlinkOrbSubscription *sub;
|
MavlinkOrbSubscription *sub;
|
||||||
|
|
||||||
LL_FOREACH(_subscriptions, sub) {
|
LL_FOREACH(_subscriptions, sub) {
|
||||||
if (sub->get_topic() == topic) {
|
if (sub->get_topic() == topic && sub->get_instance() == instance) {
|
||||||
/* already subscribed */
|
/* already subscribed */
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add new subscription */
|
/* add new subscription */
|
||||||
MavlinkOrbSubscription *sub_new = new MavlinkOrbSubscription(topic);
|
MavlinkOrbSubscription *sub_new = new MavlinkOrbSubscription(topic, instance);
|
||||||
|
|
||||||
LL_APPEND(_subscriptions, sub_new);
|
LL_APPEND(_subscriptions, sub_new);
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public:
|
|||||||
|
|
||||||
void handle_message(const mavlink_message_t *msg);
|
void handle_message(const mavlink_message_t *msg);
|
||||||
|
|
||||||
MavlinkOrbSubscription *add_orb_subscription(const orb_id_t topic);
|
MavlinkOrbSubscription *add_orb_subscription(const orb_id_t topic, int instance=0);
|
||||||
|
|
||||||
int get_instance_id();
|
int get_instance_id();
|
||||||
|
|
||||||
|
|||||||
@@ -1342,14 +1342,7 @@ protected:
|
|||||||
_act_sub(nullptr),
|
_act_sub(nullptr),
|
||||||
_act_time(0)
|
_act_time(0)
|
||||||
{
|
{
|
||||||
orb_id_t act_topics[] = {
|
_act_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_outputs), N);
|
||||||
ORB_ID(actuator_outputs_0),
|
|
||||||
ORB_ID(actuator_outputs_1),
|
|
||||||
ORB_ID(actuator_outputs_2),
|
|
||||||
ORB_ID(actuator_outputs_3)
|
|
||||||
};
|
|
||||||
|
|
||||||
_act_sub = _mavlink->add_orb_subscription(act_topics[N]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(const hrt_abstime t)
|
void send(const hrt_abstime t)
|
||||||
@@ -1424,7 +1417,7 @@ protected:
|
|||||||
_status_time(0),
|
_status_time(0),
|
||||||
_pos_sp_triplet_sub(_mavlink->add_orb_subscription(ORB_ID(position_setpoint_triplet))),
|
_pos_sp_triplet_sub(_mavlink->add_orb_subscription(ORB_ID(position_setpoint_triplet))),
|
||||||
_pos_sp_triplet_time(0),
|
_pos_sp_triplet_time(0),
|
||||||
_act_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_outputs_0))),
|
_act_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_outputs))),
|
||||||
_act_time(0)
|
_act_time(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,11 @@
|
|||||||
|
|
||||||
#include "mavlink_orb_subscription.h"
|
#include "mavlink_orb_subscription.h"
|
||||||
|
|
||||||
MavlinkOrbSubscription::MavlinkOrbSubscription(const orb_id_t topic) :
|
MavlinkOrbSubscription::MavlinkOrbSubscription(const orb_id_t topic, int instance) :
|
||||||
next(nullptr),
|
next(nullptr),
|
||||||
_topic(topic),
|
_topic(topic),
|
||||||
_fd(orb_subscribe(_topic)),
|
_instance(instance),
|
||||||
|
_fd(orb_subscribe_multi(_topic, instance)),
|
||||||
_published(false)
|
_published(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -65,6 +66,12 @@ MavlinkOrbSubscription::get_topic() const
|
|||||||
return _topic;
|
return _topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
MavlinkOrbSubscription::get_instance() const
|
||||||
|
{
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MavlinkOrbSubscription::update(uint64_t *time, void* data)
|
MavlinkOrbSubscription::update(uint64_t *time, void* data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class MavlinkOrbSubscription
|
|||||||
public:
|
public:
|
||||||
MavlinkOrbSubscription *next; ///< pointer to next subscription in list
|
MavlinkOrbSubscription *next; ///< pointer to next subscription in list
|
||||||
|
|
||||||
MavlinkOrbSubscription(const orb_id_t topic);
|
MavlinkOrbSubscription(const orb_id_t topic, int instance);
|
||||||
~MavlinkOrbSubscription();
|
~MavlinkOrbSubscription();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,9 +77,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool is_published();
|
bool is_published();
|
||||||
orb_id_t get_topic() const;
|
orb_id_t get_topic() const;
|
||||||
|
int get_instance() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const orb_id_t _topic; ///< topic metadata
|
const orb_id_t _topic; ///< topic metadata
|
||||||
|
const int _instance; ///< get topic instance
|
||||||
int _fd; ///< subscription handle
|
int _fd; ///< subscription handle
|
||||||
bool _published; ///< topic was ever published
|
bool _published; ///< topic was ever published
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user