Я использую издатель и приложение для подписчика, работающее на одной и той же машине. Они работают нормально, когда на одном домене. Издатель выдвигает некоторые случайные числа на одну тему. Абонент читает эти цифры и записывает их во вторую тему. Нет проблем. < /P>
Однако, когда издатель и абонент находятся в разных доменах, абонент не может записать во вторую тему. Я подтвердил, что функция обратного вызова (ниже) вызывается. Однако, когда я запускаю rtiddsspy по второй теме, ничего не происходит. PrettyPrint-Override ">
Код: Выделить всё
#include
#include
#include
#include
#include "sensor_data.hpp"
void publishSensor(const std::string& sensorName) {
dds::domain::DomainParticipant participant(0);
dds::topic::Topic sensorTopic(participant, "SensorTopic");
dds::pub::DataWriter writer(sensorTopic);
std::default_random_engine generator;
std::normal_distribution distribution(0.0, 1.0);
SensorData sensorData { sensorName, 0 };
while (true) {
sensorData.value(distribution(generator));
writer.write(sensorData);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
int main(int argc, char *argv[]) {
std::string sensor_name = (argc > 1) ? argv[1] : "Sensor1";
publishSensor(sensor_name);
return 0;
}
< /code>
Мой подписчик: < /p>
#include
#include
#include
#include
#include
#include "sensor_data.hpp"
using KeyedString = dds::core::KeyedStringTopicType;
int main(int argc, char *argv[]) {
// Note: The domain ID here is 1 instead of 0. In order to receive data from domain 0, we need to run the routing service.
dds::domain::DomainParticipant participant(1);
// Reads incoming raw sensor data from the SensorTopic
dds::topic::Topic sensorTopic(participant, "SensorTopic");
dds::sub::DataReader sensorReader(sensorTopic);
// Create a new topic for writing alerts to based on analysis of incoming data.
dds::topic::Topic alertTopic(participant, "AlertTopic");
dds::pub::DataWriter alertWriter(alertTopic);
// Define sample processor with a callback function to process the data and write it back out.
rti::sub::SampleProcessor statusProcessor;
statusProcessor.attach_reader(
sensorReader,
[alertWriter](const rti::sub::LoanedSample& sample) mutable
{
if (sample.info().valid()) {
std::string alertMsg = "Processed sample: " + std::to_string(sample.data().value() * 0.1);
KeyedString alert(sample.data().sensorName(), alertMsg);
alertWriter.write(alert, sample.info().source_timestamp());
}
}
);
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(4));
}
}
< /code>
Конфигурация службы маршрутизации: < /p>
0
1
SensorTopic
SensorData
SensorTopic
SensorData
< /code>
Команды, которые я использую для запуска ddsspy и службы маршрутизации:
../rti_connext_dds-7.5.0/bin/rtiddsspy -printSample COMPACT -topic AlertTopic
Проект:
Подробнее здесь: https://stackoverflow.com/questions/796 ... oy-example