1. DDS安装
请参考博主的另一篇文章:https://blog.csdn.net/SuperYang_/article/details/130396183
2. IDL编写
创建Message.idl文件, 内容如下
module Messenger {
@topic
struct Message {
string from;
string subject;
@key long subject_id;
string text;
long count;
};
};
3. IDL处理
3.1 tao_idl & opendds_idl命令处理
tao_idl --idl-version 4 Message.idl
opendds --idl-version 4 Message.idl
tao_idl --idl-version 4 MessageTypeSupport.idl
[ps]:如果第三步报错找不到dds/[xxx].idl, 可以加上-I选项指定idl包含目录,如:
tao_idl -I $DDS_ROOT --idl-version 4 MessageTypeSupport.idl)
[ps]:处理过程中可能报警告error in lookup of symbol: topic, 这个不影响最终生成效果, 有强迫症的话可以加上警告忽略选项 --unknown-annotations ignore -as -Sa -St, 如:
tao_idl --idl-version 4 --unknown-annotations ignore -as -Sa Message.idl
3.2 mwc.pl命令处理(官方推荐)
1> 编写mpc文件, 如:
project(*idl): dcps {
requires += no_opendds_safety_profile
TypeSupport_Files {
Messenger.idl
}
custom_only = 1
}
project(*publisher) : dcpsexe, dcps_tcp, dcps_rtps_udp {
requires += no_opendds_safety_profile
exename = publisher
after += *idl
TypeSupport_Files {
Messenger.idl
}
Source_Files {
Publisher.cpp
}
}
project(*subscriber) : dcpsexe, dcps_tcp, dcps_rtps_udp {
requires += no_opendds_safety_profile
exename = subscriber
after += *publisher
TypeSupport_Files {
Messenger.idl
}
Source_Files {
DataReaderListenerImpl.cpp
Subscriber.cpp
}
}
2> 命令编译生成
mwc.pl -type make # 生成MakeFile
mwc.pl -type cmake # 生成CMakeLists.txt
mwc.pl -type gnuace # 生成GNUMakeFile
4. 编译
1> 生成的是make或GNUMake工程直接make编译即可
2> 生成的是cmake工程编译过程如下:
mkdir build
cd build
cmake ..
make
5. DCPS集中发现
1> 新建repo.ior文件
2> 配置ini, 以官方DevGuideExamples/DCPS/message为例, 可在目录下建立message.ini配置文件, 内容如下
[common]
DCPSDebugLevel = 0
DCPSInfoRepo = corbaloc::127.0.0.1:12345/DCPSInfoRepo
DCPSGlobalTransportConfig = dcpstransport
[config/config1]
transports = tcp1
[transport/tcp1]
transport_type = tcp
3> 启动DCPS仓库
DCPSInfoRepo -ORBListenEndpoints iiop://127.0.0.1:12345
4> 启动订阅端
./subscriber -DCPSConfigFile message.ini
5> 启动发布端
./publisher -DCPSConfigFile message.ini
[ps]官方文档上提供的方式为
DCPSInfoRepo -o repo.ior
./subscriber -DCPSInfoRepo file://repo.ior
./publisher -DCPSInfoRepo file://repo.ior
6. RTPS对等发现
1> 编写rtps.ini配置文件, 内容如下:
[common]
DCPSDefaultDiscovery=DEFAULT_RTPS
DCPSGlobalTransportConfig=$file
[transport/the_rtps_transport]
transport_type=rtps_udp
2> 运行发布端、订阅端
./subscriber -DCPSConfigFile rtps.ini
./publisher -DCPSConfigFile rtps.ini