I need to define 3 kinds of messages in omnet

348 Views Asked by At

I want to define 3 kinds of messages in omnet I know I have to use messagekind but I couldnt please help me I want help message, control message and jobs, which jobs should be processed thank you so much

2

There are 2 best solutions below

6
Pasha M. On BEST ANSWER

After creating the three message classes, in a class, say DemoLayer, you need 2 changes in .h file and 1 in .cc file.

In .h file, under the public specifier add

enum DemoMessageKinds {
    SEND_DATA-MESSAGE,
    SEND_CONTROL-MESSAGE,
    SEND_JOB-MESSAGE
};

and under protected specifier add

void handleSelfMsg(cMessage* msg) override;

In .cc file, add

void DemoLayer::handleSelfMsg(cMessage* msg)
{   
   switch (msg->getKind()) 
   {
      case SEND_DATA-MESSAGE: 
      {
        ControlMessage* cm = new ControlMessage();
        ....//

For an example, check this https://github.com/sommer/veins/tree/master/src/veins/modules/application/ieee80211p

0
Jerzy D. On

Creating of messages is described in OMNeT++ Simulation Manual as well as in TicToc Tutorial.
In short:

  1. You have to create a new .msg file, for example ControlMessage.msg, with your content, for example:

    message ControlMessage {
      int someAddress;
      // ...
    }
    
  2. In your C++ code you have to add the following line:

    #include "ControlMessage_m.h"
    

(during compilation ControlMessage_m.h is automatically created from ControlMessage.msg)