sendDirect():目标模块指针为nullptr ...如何解决此错误?

时间:2018-12-21 16:34:26

标签: omnet++

#include <stdio.h>
#include "event.h"
#include <omnetpp.h>

using namespace omnetpp;

event::event() {
    // TODO Auto-generated constructor stub

}

void event::refreshDisplay()
{

    // event mobility

}

void event::initialize()
{
    cModule *target;
    cModule *target1;
    //cModule *msg1;
    cMessage *msg5 = new cMessage("timer");
    //send(msg, "out");
    scheduleAt(simTime()+1, msg5);

    cMessage *msg2 = new cMessage("RTS");

         //  For Broadcasting
    int n = 15;
    for (int i = 0; i < n; i++)
    {
        msg2 = msg2->dup();
        target = getParentModule()->getSubmodule("Anchor", i);
        target1 = getParentModule()->getSubmodule("Node", i);
        sendDirect(msg2,target,"radioIn");
        sendDirect(msg2,target1,"radioIn");
    }
}


void event::handleMessage(cMessage *msg)
{
    EV << msg->isSelfMessage() << endl;
    EV << msg->getName() << endl;
    EV << msg->getKind() << endl;
    cMessage *msgl = new cMessage("timer");
    scheduleAt(simTime()+1, msgl);
    refreshDisplay();

    cModule *target;
    cModule *target1;
    cMessage *msg2 = new cMessage("RTS");

    target = getParentModule()->getSubmodule("Anchor");
    target1 = getParentModule()->getSubmodule("Node");

        sendDirect(msg2,target,"radioIn");
        sendDirect(msg2,target1,"radioIn");

        scheduleAt(simTime() + dblrand(), msg2->dup());
}

event::~event() {
    // TODO Auto-generated destructor stub
}

我收到此错误>

  

模块(事件)中的错误。在网络初始化期间:sendDirect():目标模块指针为nullptr

我该如何解决?

网络包含目标节点,锚节点和事件。事件将在网络中移动并在网络中广播消息。当我尝试运行模拟时,出现上述错误。 enter image description here

谢谢

0 个答案:

没有答案