omn​​et ++中聚合器模块中的消息接收错误

时间:2018-12-12 19:18:58

标签: omnet++

伙计们,我有这个代码(Aggregator.cc),应该可以接收从Temperature.cc和Heartrate.cc发送的消息并将它们串联在一起,但是这样做没有帮助,请帮助。在aggregator.cc中,它一直告诉我tmsg和hmasg没有在范围内定义。聚合器不应该收到消息吗?

Temperature.cc

#include "Temperature.h"

Define_Module(Temperature);

void Temperature::initialize()
{
    // TODO - Generated method body
    cMessage *tmsg = new cMessage("hi");
       send(tmsg,"temperatured");
}

void Temperature::handleMessage(cMessage *msg)
{
    // TODO - Generated method body
}

Heartrate.cc

#include "Heartrate.h"

Define_Module(Heartrate);

void Heartrate::initialize()
{
    // TODO - Generated method body
    cMessage *hmsg = new cMessage("hello");
        send(hmsg,"heartrateexit");
}

void Heartrate::handleMessage(cMessage *msg)
{
    // TODO - Generated method body
}

Aggregator.cc

#include "Aggregator.h"
#include "Temperature.h"
#include "Heartrate.h"

Define_Module(Aggregator);

void Aggregator::initialize()
{
    // TODO - Generated method body

}

void Aggregator::handleMessage(cMessage *msg)
{
    // TODO - Generated method body


    cPacket *data = new cPacket("data");
    data ->addPar(tmsg); // added parameter of type cMessage
    data ->addPar(hmsg); // added parameter of type cMessage
    data->setByteLength(20);

    cPacket *udp = new cPacket("data1"); // subclassed from cPacket
    udp->setByteLength(30);
    udp->encapsulate(data);
    EV << udp->getByteLength(); 
    EV << udp;
    cPacket *payload = udp->decapsulate();
    EV << payload;

}

network.ned

network Network
{
    submodules:

        aggregator: Aggregator {
            @display("p=128,147");
        }
        heartrate: Heartrate {
            @display("p=40,112");
        }
        temperature: Temperature {
            @display("p=40,173");
        }
    connections:

        temperature.tempexit --> aggregator.data;
        heartrate.heartrateexit --> aggregator.data1;
}  

1 个答案:

答案 0 :(得分:0)

您正在尝试从另一种方法访问局部变量。 <Border> <Grid x:Name="grv"> <TextBox Width="{Binding ElementName=grv, Path=ActualWidth}"> </TextBox> </Grid> </Border> tmsg分别在hmsgTemperature::initialize的本地范围内定义。

您需要在这些消息的有效负载中添加一些内容,以便在Heartrate::initialize收到消息时,您知道Aggregator::handleMessage(cMessage *msg)参数是来自msg还是来自{ {1}}。

此外,在Temperature中,门的名称与Heartrate文件中的门不匹配。