Wireless sensor networks OMNET ++ study notes and (iii) simple module

Four main functions:

  1.  the initialize (); (initialize variables, initialization scheduled events, such as call 2) is not a constructor
  2.  handleMessage(cMessage *msg);
    • send () sends a message to other modules
    • scheduleAt () message to yourself
    • cancelEvent () deletes a scheduleAt () event scheduled
  3. activity();
  4.  finish (); simulation end recording statistics. Not analyzer configuration.

.h file

#include <omnetpp.h>

using namespace omnetpp;

namespace sin {   //包名,项目名


class Txc : public cSimpleModule
{
  protected:
    virtual void initialize();
    virtual void handleMessage(cMessage *msg);
    virtual void finish();
};

}; 

.cc file

#include "Txc.h"

namespace sin {

Define_Module(Txc);

void Txc::initialize()
{
    if (par("sendInitialMessage").boolValue())
    {
        cMessage *msg = new cMessage("tictocMsg");
        send(msg, "out");
    }
}

void Txc::handleMessage(cMessage *msg)
{
    send(msg, "out");
}

}; // namespace

 

Guess you like

Origin www.cnblogs.com/codinghard/p/11084968.html