在 Omnet++ 上使用 INet 更改消息内容 [英] Change message content with INet on Omnet++

查看:175
本文介绍了在 Omnet++ 上使用 INet 更改消息内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Omnet 上模拟 WSN,因为我希望它是无线的,所以我选择了 Inet 框架.

I am trying to simulate a WSN on Omnet and since I want it to be wireless, I chose the Inet Framework.

现在我需要个性化发送消息的内容,但我找不到这样做的方法.

Now I need to personalize the Content of the Messages sent but I can't find a way to do so.

有人可以帮我吗?我在 unser 手册等中找不到任何内容.

can anybody help me with that? I can't find anything in the unser Manual etc.

谢谢!

推荐答案

这取决于什么是消息"以及您想从哪个模块发送它.如果您正在创建/测试应用程序协议,那么您可能需要创建新的 .msg 文件来描述您的消息结构.

It depends on what is "the Message" and from which module you want to send it. If you are creating/testing application protocol then you might want to create new .msg file which describes the structure of your message.

INET 的文档中有一节是关于处理数据包的https://inet.omnetpp.org/docs/developers-guide/ch-packets.html#representing-packets

INET's documentation has a section on working with packets https://inet.omnetpp.org/docs/developers-guide/ch-packets.html#representing-packets

.msg 文件看起来像这样:

cplusplus {{
const B YOUR_APP_HEADER_LENGTH = B(6);
}}

class YourAppHeader extends FieldsChunk
{

    chunkLength = YOUR_APP_HEADER_LENGTH;

    int someField;
    bool someBit;

};

然后在你的 C++ 代码中

then in your C++ code

Packet *packet = new Packet();
const auto& payload = makeShared<YourAppHeader>();
payload->setChunkLength(B(<someValue>));
payload->setSomeFiled(<intHere>);

packet->insertAtBack(payload);

//and then send it

这篇关于在 Omnet++ 上使用 INet 更改消息内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆