伙计们,我有这个代码(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;
}
答案 0 :(得分:0)
您正在尝试从另一种方法访问局部变量。 <Border>
<Grid x:Name="grv">
<TextBox Width="{Binding ElementName=grv,
Path=ActualWidth}">
</TextBox>
</Grid>
</Border>
和tmsg
分别在hmsg
和Temperature::initialize
的本地范围内定义。
您需要在这些消息的有效负载中添加一些内容,以便在Heartrate::initialize
收到消息时,您知道Aggregator::handleMessage(cMessage *msg)
参数是来自msg
还是来自{ {1}}。
此外,在Temperature
中,门的名称与Heartrate
文件中的门不匹配。