在 RTI DDS 上获取 DataWriter/Publisher 的 IP 地址?

Get IP Address of DataWriter/Publisher on RTI DDS?

我正在使用 RTI DDS 5.2.3.17 并希望获取 DataWriter/Publisher 的 IP 地址以添加到一些日志消息中。

我该怎么做我在形成要做什么的逻辑时遇到了一些困难?

无法以标准化方式访问 DataWriter 的 IP 地址。但是,RTI Connext 实现默认使用 IP 地址作为每个实体的全局唯一标识符 (GUID) 的一部分。

您可以在 RTI 知识库文章 Accessing the GUID of Connext DDS Entities 中找到有关 GUID 以及如何访问它们的更多信息。通常,IP 地址在 GUID 的前 4 个字节中捕获,在 DDS_GUID_t 图中由 rtps_host_id 指示。

您没有详细说明您的情况,但是如果您碰巧有来自 DataWriter 的可用数据,您也可以利用数据附带的 SampleInfo。它有一个名为 source_guid.

的字段

所有这些都假设您正在寻找 IPv4 地址。另请注意,这不是公开的机制,因此将来可能会发生变化。当您的应用程序明确设置其 GUID 时,所有这一切都会中断。

DataWriter GUID 不是获取 DomainParticipant IP 地址的可靠方法。较新版本的 Connext DDS 不再根据 IP 地址或主机 ID 构造 GUID_t。

正确的方法是查看 ParticipantBultinTopicData of the DomainParticipant that owns that DataWriter. The field default_unicast_locators 包含 DomainParticipant 的 IP 地址。

您可以从 SampleInfo 中找到的 SampleInfo. To do this call get_matched_publication_participant_data() on the DataReader passing the publication_handle 中获取拥有写入样本的 DataWriter 的 DomainParticipant 的 ParticipantBultinTopicData。

请注意,以上内容为您提供了拥有 DataWriter 的 DomainParticipant 的 IP 地址(定位器​​)。 DataWriter 可以覆盖这些并提供不同的集合(通常是子集)。如果您只想提供日志记录,这可能无关紧要。但是如果您想查看 DataWriter 是否使用不同的定位器集,您也可以从 unicast_locators field in the PublicationBuiltinTopicData which you can also get from the SampleInfo calling get_matched_publication_data().

中获取这些定位器