-
Notifications
You must be signed in to change notification settings - Fork 136
/
temperature_durable_publisher.cxx
52 lines (45 loc) · 1.74 KB
/
temperature_durable_publisher.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
//
// RTI grants Licensee a license to use, modify, compile, and create derivative
// works of the Software. Licensee has the right to distribute object form
// only for use with RTI products. The Software is provided "as is", with no
// warranty of any type, including any warranty for fitness for any purpose.
// RTI is under no obligation to maintain or support the Software. RTI shall
// not be liable for any incidental or consequential damages arising out of the
// use or inability to use the software.
//
#include <iostream>
#include <thread>
#include <rti/rti.hpp>
#include "temperature.hpp"
void publish_temperature(const std::string &sensor_name)
{
dds::domain::DomainParticipant participant(0);
dds::topic::Topic<Temperature> topic(participant, "Temperature");
dds::pub::qos::DataWriterQos writer_qos {
dds::core::QosProvider::Default().datawriter_qos(
"MyLibrary::Persistence")
};
writer_qos.policy<dds::core::policy::Durability>()
.extensions()
.storage_settings()
.enable(true);
writer_qos.policy<dds::core::policy::Durability>()
.extensions()
.storage_settings()
.file_name(sensor_name);
dds::pub::DataWriter<Temperature> writer(topic, writer_qos);
Temperature temp_reading;
temp_reading.sensor_name(sensor_name);
for (int i = 0; i < 1000; i++) {
temp_reading.degrees((rand() % 10) + 30);
writer.write(temp_reading);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
int main(int argc, char **argv)
{
std::string sensor_name = (argc > 1) ? argv[1] : "Sensor1";
publish_temperature(sensor_name);
}