通过 CMessage 发送数组 - OMNET++
Sending Array through CMessage - OMNET++
我正在尝试制作一个结构并使用 send() 命令将其数据发送到 Application/MAC 层。现在我面临的问题是 send() 只允许 cMessage object/pointer 作为参数。这是一个使项目停滞不前的问题。
到目前为止我尝试过的是:
- 继承自cMessage(但如何处理数组?)
- 重载 HandleCommand 函数但 send() 再次不允许发送数组。
任何帮助将不胜感激。谢谢!
在OMNeT++
中可以定义自己的消息。该定义可以使用嵌入类型(int、double、string 等)以及自己的类型。
假设您要发送 Foo.h
:
中定义的 Foo
实例
// Foo.h
#ifndef _FOO_H
#define _FOO_H
class Foo {
public:
int x;
};
#endif
您应该创建一个扩展名为 .msg
的新文件,例如 TestMsg.msg
:
// TestMsg.msg
cplusplus {{
#include "Foo.h"
}}
class noncobject Foo;
message TestMsg {
Foo oneObject;
Foo tab[10]; // example of fixed-size array
}
构建项目后,将创建新的 C++ 文件(TestMsg_m.h
和 TestMsg_m.cc
)。这些文件包含继承自 cMessage
的 TestMsg
class 的定义。 TestMsg
class 具有所有需要的设置和获取方法。
这是对我有用的实现:
namespace inet;
struct NodeM
{
int type;
string description;
double coords[3];
};
// TODO generated message class
//
message Signal extends cMessage {
NodeM Result[500];
int sizeRes;
NodeM RedQ[500];
int sizeRed;
}
我正在尝试制作一个结构并使用 send() 命令将其数据发送到 Application/MAC 层。现在我面临的问题是 send() 只允许 cMessage object/pointer 作为参数。这是一个使项目停滞不前的问题。
到目前为止我尝试过的是:
- 继承自cMessage(但如何处理数组?)
- 重载 HandleCommand 函数但 send() 再次不允许发送数组。
任何帮助将不胜感激。谢谢!
在OMNeT++
中可以定义自己的消息。该定义可以使用嵌入类型(int、double、string 等)以及自己的类型。
假设您要发送 Foo.h
:
Foo
实例
// Foo.h
#ifndef _FOO_H
#define _FOO_H
class Foo {
public:
int x;
};
#endif
您应该创建一个扩展名为 .msg
的新文件,例如 TestMsg.msg
:
// TestMsg.msg
cplusplus {{
#include "Foo.h"
}}
class noncobject Foo;
message TestMsg {
Foo oneObject;
Foo tab[10]; // example of fixed-size array
}
构建项目后,将创建新的 C++ 文件(TestMsg_m.h
和 TestMsg_m.cc
)。这些文件包含继承自 cMessage
的 TestMsg
class 的定义。 TestMsg
class 具有所有需要的设置和获取方法。
这是对我有用的实现:
namespace inet;
struct NodeM
{
int type;
string description;
double coords[3];
};
// TODO generated message class
//
message Signal extends cMessage {
NodeM Result[500];
int sizeRes;
NodeM RedQ[500];
int sizeRed;
}