c++ - 在 Omnet++ 上使用 INet 更改消息内容

标签 c++ omnet++ inet

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

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

有人可以帮我吗?我在 unser 手册等中找不到任何东西。

谢谢你!

最佳答案

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

INET 的文档有一节关于处理数据包 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++ 代码中
Packet *packet = new Packet();
const auto& payload = makeShared<YourAppHeader>();
payload->setChunkLength(B(<someValue>));
payload->setSomeFiled(<intHere>);

packet->insertAtBack(payload);

//and then send it

关于c++ - 在 Omnet++ 上使用 INet 更改消息内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57198776/

相关文章:

omnet++ - 如何在静脉模拟中使用inet模块

c++ - 如何将我的自定义模块与 Omnet++INET 的简单模块结合起来

dynamic - 如何在 OMNet++ 中将动态模块连接到静态模块

c++ - 如何将传入流量重定向到模块到 Omnet++ 中的简单子(monad)模块?

c++ - Qt QOpenGLWidget 在哪里?

c++ - 使用 UDP 的 OMNeT++ 和 INET 无线通信

c++ - omn​​et : Simulation terminated with exit code: 139 中的导航层次结构错误

c++ - Poco/数据/SQLite/Connector.h : No Such file or directory

java - 使用 jni.h 在 C++ 中编译 java 方法时生成错误

c++ - make_pair 不适用于字符串,适用于字符串&