0
votes

Hey guys I have this code (Aggregator.cc) that is supposed to receive the messages sent from Temperature.cc and Heartrate.cc and concatenate them together however it is not doing so please help. In aggregator.cc it keeps telling me that tmsg and hmasg are not defined in the scope. Isn't aggregator supposed to have received the messages.

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
To be able to run your simulation you need to specify a network. Could you post the code of your network? - thardes2

1 Answers

0
votes

You're trying to access local variables from another method. tmsg and hmsg are defined in the local scope of Temperature::initialize and Heartrate::initialize, respectively.

You'll need to add something to the payload of these messages, so that when you receive one at Aggregator::handleMessage(cMessage *msg), you know whether the msg argument is from Temperature or from Heartrate.

Also, in Temperature::initialize, the name of your gate doesn't match the one in your .ned file.