DDS C++ - 数据分发服务

DDS C++ - Data Distribution Service

我开始使用 C# 并尝试测试 dds 应用程序后面的代码。我取自:http://www.laas.fr/files/SLides-A_Corsaro.pdf

using System;
/**********************************************************
 * Definition for the TempSensorType
 **********************************************************/
enum TemperatureScale{
    CELSIUS,
    KELVIN,
    FAHRENHEIT
};
struct TempSensorType{
    short id;
    float temp;
    float hum;
    TemperatureScale scale;
};
#pragma keylist TempSensor id

/**********************************************************
 * Main
 **********************************************************/
static public void Main(string[] args){

    dds::Topic<TempSensorType> tsTopic(TempSensorTopic);
    dds::DataWriter<TempSensorType> dw(tsTopic);
    dds::DataReader<TempSensorType> dr(tsTopic);
    dds::SampleInfoSeq info;

    TempSensorSeq data;
    TempSensorType ts;
    ts = new TempSensorType { 1, 25.0F, 65.0F, CELSIUS };
    dw.write(ts);
    ts = new TempSensorType { 2, 26.0F, 70.0F, CELSIUS };
    dw.write(ts);
    ts = new TempSensorType { 3, 27.0F, 75.0F, CELSIUS };
    dw.write(ts);
    sleep(10);
    while (true){
        dr.read(data, info);
        for (int i = 0; i < data.length(); ++i)
            std::cout << data[i] << std::endl;
        sleep(1);
    }
    Console.WriteLine("Bonjour");
}

我开始理解每段代码的用途。但我有疑问 关于主体中的前 4 行,那些以 "dds::" 开头的行,我认为它们是错误的 - 我得到 "Identifier expected"。如能提供帮助,将不胜感激

在我看来,它不是有效的 DDS 代码。您似乎缺少 IDL 定义(应该解释 #pragma)和代码。

你必须先在.idl文件中创建主题,然后构建id才能创建你在程序中使用的类,然后使用程序库,一切都没有。

开始下载 DDS 实现,例如从头开始从工作的 OpenDDS 示例OpenDDS or Fast-RTPS. In addition to this you can check the OpenDDS section in this site