简体   繁体   中英

Change message content with INet on Omnet++

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.

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

thank you!

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's documentation has a section on working with packets https://inet.omnetpp.org/docs/developers-guide/ch-packets.html#representing-packets

The .msg file can look something like this:

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

class YourAppHeader extends FieldsChunk
{

    chunkLength = YOUR_APP_HEADER_LENGTH;

    int someField;
    bool someBit;

};

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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