码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • RTI-DDS代码分析使用介绍


    DDS(Data Distribution Service数据分发服务)是对象管理组织OMG的有关分布式实时系统中数据发布的规范。
    DDS规范采用了发布/订阅体系结构,但对实时性要求提供更好的支持。DDS是以数据为中心的发布/订阅通信模型。

    以下工程基于rti_connext_dds-7.2.0
    hello_world.idl定义的HelloWorld结构体如下

    在这里插入图片描述

    使用RTI Code Generator(rtiddsgen)生成对应工程。

    在这里插入图片描述

    生成的工程目录如下

    在这里插入图片描述

    用VS2017打开工程
    重点关注 hello_world_publisher.cxx和 hello_world_subscriber.cxx两个文件

    Publisher

    publisher实现的是发布,subscriber实现的是订阅。
    在hello_world_publisher.cxx中

        // 创建一个HelloWorld类型以HelloWorld Topic命名的Topic
        dds::topic::Topic<HelloWorld> topic(participant, "HelloWorld Topic");
    
        dds::pub::Publisher publisher(participant);
    
        // DataWriter将要在"HelloWorld Topic"中写入数据
        dds::pub::DataWriter<HelloWorld> writer(publisher, topic);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    定义HelloWorld类型的sample,sample.msg()定义sample输出的内容
    通过write函数写入数据

        HelloWorld sample;
        for (unsigned int count = 0;
             !shutdown_requested && count < sample_count;
             count++) {
    
    		sample.msg("Hello world! " + std::to_string(count));
    
            std::cout << "Writing HelloWorld, count " << count << std::endl;
    
            writer.write(sample);
    
            rti::util::sleep(dds::core::Duration(4));
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    Subscriber

    类似的,定义Subscriber

        // 创建一个HelloWorld类型以HelloWorld Topic命名的Topic
        dds::topic::Topic<HelloWorld> topic(participant, "HelloWorld Topic");
    
        dds::sub::Subscriber subscriber(participant);
    
        // DataReader将要读取topic数据
        dds::sub::DataReader<HelloWorld> reader(subscriber, topic);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    创建状态条件,满足条件才读取数据

        // 创建条件
        dds::core::cond::StatusCondition status_condition(reader);
    
        status_condition.enabled_statuses(
                dds::core::status::StatusMask::data_available());
    
        // 条件触发后关联句柄
        unsigned int samples_read = 0;
        status_condition.extensions().handler([&reader, &samples_read]() {
            samples_read += process_data(reader);
        });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    	dds::core::cond::WaitSet waitset;
        waitset += status_condition;
    
        while (!shutdown_requested && samples_read < sample_count) {
            // 条件激活
            std::cout << "HelloWorld subscriber sleeping for 4 sec..."
                      << std::endl;
    
            waitset.dispatch(dds::core::Duration(4));  // Wait up to 4s each time
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  • 相关阅读:
    AI原生应用速通指南
    【QML】报错 DelegateModel :: index out range xx xx
    京东数据分析软件:2023年8月京东彩妆行业品牌销售排行榜
    hystart++ 出炉
    硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件
    矿山定位系统-矿井人员定位系统在矿山自动化安全监控过程中的应用
    【opencv】形态学重建案例-数糖果(细胞)个数
    01_Cookie&WebStorage
    Kernel Memory 入门系列:Kernel Memory Service
    msys2 |arch pacman:tesseract ocr 安装 - 思源笔记自动调用
  • 原文地址:https://blog.csdn.net/sinat_33896833/article/details/134006199
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号