繁体   English   中英

如何在 .net 数据包定义中使用 c++ 类型(结构)

[英]How to use a c++ type (struct) in inet packet definition

我想创建一个 .net 数据包,数据包内容需要是在消息文件外部定义的 c++ 类型结构。 我之前这样做是为了在 OMNeT 中定义从 cMessages 派生的 .msg 文件,如下所示:

cplusplus{{
       #include "util/DataTypes/StateDataTypes.h" 
}};

struct StateWithCovariance;

message WirelessMsg
{
   StateWithCovariance VehicleLocation; 
}

现在我正在使用 simu5g 并希望发送与 .net 数据包相同的 msg 内容。 我知道 .net 数据包数据结构建立在数据结构块之上。 因此,我遵循了 .net 中的操作方式,当我尝试创建数据包时,我不能使用上面相同的格式来定义数据包,因为那时

cplusplus{{
     #include "inet/common/INETDefs"
     #include "inet/common/packet/chunk/chunk"
}}
class WirelessAppPacket extends inet::FieldsChunk
{
   simtime_t payloadTimestamp;
   StateWithCovariance VehicleLocation;
}

不会工作并给我错误:

modules/communication/NR/App/WirelessAppPacket.msg:34: Error: 'WirelessAppPacket': unknown base class 'inet::FieldsChunk', 
available classes' (inet::StateWithCovariance:1)' ,'(omnetpp::cMessage:4)', '(omnetpp::cNamedObject:5)','(omnetpp::cObject:3)','(omnetpp::cOwnedObject:4)','(omnetpp::cPacket:4)'

如果我给它

import inet.common.INETDefs;
import inet.common.packet.chunk.Chunk;

class WirelessAppPacket extends inet::FieldsChunk
{
   simtime_t payloadTimestamp;
   StateWithCovariance VehicleLocation;
}

如果我将项目属性中的消息编译器更改为 --msg6,它不会给出关于块的任何错误,如下所示

MSGC:=$(MSGC) --msg6

但它给我一个关于数据类型定义的错误:

modules/communication/NR/App/WirelessAppPacket.msg:28: Error: Type declarations are not needed with imports, try invoking the message compiler in legacy (4.x) mode using the --msg4 option
modules/communication/NR/App/WirelessAppPacket.msg:32: Error: unknown type 'StateWithCovariance' for field 'VehicleLocation' in 'WirelessAppPacket'

我使用的整个代码看起来像这样

import inet.common.INETDefs;
import inet.common.packet.chunk.Chunk;

cplusplus{{
   #include "util/DataTypes/StateDataTypes.h" 
   #include "modules/vehicle/CommunicationCoordinator.h"   
}};

struct StateWithCovariance;
class WirelessAppPacket extends inet::FieldsChunk
{
   simtime_t payloadTimestamp;
   StateWithCovariance VehicleLocation;
}

如果我将消息编译器更改为 --msg4,那么我无法在 .NET 框架中从块基 class 定义我的数据包,并且使用 --msg6 我无法使用我想使用的数据类型。

有没有办法纠正这个问题?

我使用 OMNeT++ 版本 5.6.2、.NET 版本 4.2.2 和 Simu5G 版本 1.1.0

该线程解释了该做什么。 基本上你需要改变线

struct StateWithCovariance;

从你的最后一个代码片段到

struct StateWithCovariance {
   @existingClass;
}

这适用于--msg6消息编译器,因此您仍然可以导入 .NET 个类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM