Skip to content

Commit

Permalink
uxcre_dds_client: use topic name as defined in the dds_topics.yaml to…
Browse files Browse the repository at this point in the history
… register stream
  • Loading branch information
KonradRudin authored and dagar committed May 15, 2024
1 parent 293389a commit 17916b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/modules/uxrce_dds_client/dds_topics.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct SendSubscription {
const struct orb_metadata *orb_meta;
uxrObjectId data_writer;
const char* dds_type_name;
const char* topic;
uint32_t topic_size;
UcdrSerializeMethod ucdr_serialize_method;
};
Expand All @@ -54,6 +55,7 @@ struct SendTopicsSubs {
{ ORB_ID(@(pub['topic_simple'])),
uxr_object_id(0, UXR_INVALID_ID),
"@(pub['dds_type'])",
"@(pub['topic'])",
ucdr_topic_size_@(pub['simple_base_type'])(),
&ucdr_serialize_@(pub['simple_base_type']),
},
Expand Down Expand Up @@ -96,7 +98,7 @@ void SendTopicsSubs::update(uxrSession *session, uxrStreamId reliable_out_stream
orb_copy(send_subscriptions[idx].orb_meta, fds[idx].fd, &topic_data);
if (send_subscriptions[idx].data_writer.id == UXR_INVALID_ID) {
// data writer not created yet
create_data_writer(session, reliable_out_stream_id, participant_id, static_cast<ORB_ID>(send_subscriptions[idx].orb_meta->o_id), client_namespace, send_subscriptions[idx].orb_meta->o_name,
create_data_writer(session, reliable_out_stream_id, participant_id, static_cast<ORB_ID>(send_subscriptions[idx].orb_meta->o_id), client_namespace, send_subscriptions[idx].topic,
send_subscriptions[idx].dds_type_name, send_subscriptions[idx].data_writer);
}

Expand Down Expand Up @@ -169,7 +171,7 @@ bool RcvTopicsPubs::init(uxrSession *session, uxrStreamId reliable_out_stream_id
@[ for idx, sub in enumerate(subscriptions + subscriptions_multi)]@
{
uint16_t queue_depth = orb_get_queue_size(ORB_ID(@(sub['simple_base_type']))) * 2; // use a bit larger queue size than internal
create_data_reader(session, reliable_out_stream_id, best_effort_in_stream_id, participant_id, @(idx), client_namespace, "@(sub['topic_simple'])", "@(sub['dds_type'])", queue_depth);
create_data_reader(session, reliable_out_stream_id, best_effort_in_stream_id, participant_id, @(idx), client_namespace, "@(sub['topic'])", "@(sub['dds_type'])", queue_depth);
}
@[ end for]@

Expand Down
18 changes: 11 additions & 7 deletions src/modules/uxrce_dds_client/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,29 @@ uxrObjectId topic_id_from_orb(ORB_ID orb_id, uint8_t instance = 0)
return uxrObjectId{};
}

static bool generate_topic_name(char *topic, const char *client_namespace, const char *direction, const char *name)
static bool generate_topic_name(char *topic_name, const char *client_namespace, const char *topic)
{
if (topic[0] == '/') {
topic++;
}

if (client_namespace != nullptr) {
int ret = snprintf(topic, TOPIC_NAME_SIZE, "rt/%s/fmu/%s/%s", client_namespace, direction, name);
int ret = snprintf(topic_name, TOPIC_NAME_SIZE, "rt/%s/%s", client_namespace, topic);
return (ret > 0 && ret < TOPIC_NAME_SIZE);
}

int ret = snprintf(topic, TOPIC_NAME_SIZE, "rt/fmu/%s/%s", direction, name);
int ret = snprintf(topic_name, TOPIC_NAME_SIZE, "rt/%s", topic);
return (ret > 0 && ret < TOPIC_NAME_SIZE);
}

static bool create_data_writer(uxrSession *session, uxrStreamId reliable_out_stream_id, uxrObjectId participant_id,
ORB_ID orb_id, const char *client_namespace, const char *topic_name_simple, const char *type_name,
ORB_ID orb_id, const char *client_namespace, const char *topic, const char *type_name,
uxrObjectId &datawriter_id)
{
// topic
char topic_name[TOPIC_NAME_SIZE];

if (!generate_topic_name(topic_name, client_namespace, "out", topic_name_simple)) {
if (!generate_topic_name(topic_name, client_namespace, topic)) {
PX4_ERR("topic path too long");
return false;
}
Expand Down Expand Up @@ -87,13 +91,13 @@ static bool create_data_writer(uxrSession *session, uxrStreamId reliable_out_str
}

static bool create_data_reader(uxrSession *session, uxrStreamId reliable_out_stream_id, uxrStreamId input_stream_id,
uxrObjectId participant_id, uint16_t index, const char *client_namespace, const char *topic_name_simple,
uxrObjectId participant_id, uint16_t index, const char *client_namespace, const char *topic,
const char *type_name, uint16_t queue_depth)
{
// topic
char topic_name[TOPIC_NAME_SIZE];

if (!generate_topic_name(topic_name, client_namespace, "in", topic_name_simple)) {
if (!generate_topic_name(topic_name, client_namespace, topic)) {
PX4_ERR("topic path too long");
return false;
}
Expand Down

0 comments on commit 17916b7

Please sign in to comment.