DDS学习笔记

最近接触到 DDS 中间件,学习一下。

定义

针对实时系统的数据分发服务( DDS )是对象管理组织(OMG)的机器对机器(有时称为中间件或连接框架)标准,旨在通过发布-订阅模式实现可靠、高性能、可互操作、实时、可扩展的 数据交换。

DDS 满足航空航天、国防、空中交通管制、自动驾驶车辆、医疗设备、机器人、发电、仿真和测试、智能电网管理、交通运输系统等 应用领域的实时数据交换需求。

开源实现

  • Fast-DDS (原名 Fast RTPS)
  • Dust DDS
  • OpenDDS

编译安装

下面从源代码编译安装 Fast-DDS。

安装依赖

使用 vcpkg 安装 Fast-DDS 所需依赖库。

1
vcpkg install openssl asio tinyxml2 fastcdr foonathan-memory --triplet x64-windows

编译安装

在Windows平台编译安装使用 Visual Studio 2019.

foonathan_memory_vendor (可选,当找不到库时)

FastDDS 依赖 Foonathan Memory(内存管理库),通过源代码编译安装:

1
2
3
4
5
6
cd i:\project\Fast-DDS\
git clone https://github.com/eProsima/foonathan_memory_vendor.git
cd foonathan_memory_vendor
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=i:/install/foonathan_memory_vendor ..
cmake --build . --config Release --target install

FastCDR (可选,当找不到库)

FastDDS 依赖 FastCDR(序列化库),通过源代码编译安装:

1
2
3
4
5
6
cd i:\project\Fast-DDS\
git clone https://github.com/eProsima/Fast-CDR.git
cd Fast-CDR
mkdir build && cd build
cmake -A x64 -DCMAKE_INSTALL_PREFIX=i:/install/fastcdr ..
cmake --build . --config Release --target install

eProsima Fast DDS

当所有依赖库都安装后,开始安装eProsima Fast DDS,打开 VS2019的X64本地命令提示符,按如下步骤输入命令:

1
2
3
4
5
6
cd i:\project\Fast-DDS\
git clone https://github.com/eProsima/Fast-DDS.git
cd Fast-DDS
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=i:/install/fastdds ..
cmake --build . --config Release --target install

当执行 cmake -DCMAKE_INSTALL_PREFIX=i:/install/fastdds .. 可能会报找不到 ASIO 的错误,可以编辑 CMakeLists.txt,注释如下代码,再重新运行。

1
eprosima_find_thirdparty(Asio asio VERSION 1.13.0)

当执行 cmake –build . –config Release –target install 可能会报如下错误:

1
警告 C4819 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失

请参考以下链接进行处理,主要是配置C++编译选项 /utf-8:

fastddsgen

fastddsgen 是 FastDDS 官方提供的 IDL(Interface Definition Language)编译器,用于将 IDL 定义的数据类型转换为 FastDDS 兼容的代码(支持 C++、Python 等语言),自动生成数据序列化 / 反序列化逻辑、类型注册代码等,是 FastDDS 开发的基础工具。

具体安装步骤请参考:

简单示例

Fast-DDS的简单示例请参考:

参考链接

  1. Data Distribution Service,by wikipedia.
  2. What is DDS?,by dds.
  3. 通信中间件 Fast DDS(一) :编译、安装和测试,by 流星雨爱编程.
  4. 1. Getting Started,by fast-dds.
  5. Fast DDS官方文档机翻之「入门介绍」,by 卢飞腾.
  6. 1.3. Writing a simple C++ publisher and subscriber application,by fast-dds.
  7. 通信中间件 Fast DDS(三) :fastddsgen的安装与利用 ,by ycfenxi.
  8. 不使用默认路径的 cmake 项目管理,by 怀中落霞.
  9. fastdds在windows下的编译和使用,by 飞羽.
  10. 警告 C4819 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失,by 匈牙利认真的小菠萝.