无法在门外发送cMessage数组

时间:2018-12-21 09:42:44

标签: omnet++

大家好,我正在阅读OMNET手册,因此遇到了 https://doc.omnetpp.org/omnetpp/manual/#sec:messages:encapsulating-several-packets

组合多个数据包/消息。所以我按照建议的方法将数据放入向量中,然后放入数组中。但是,当我尝试将数组输出到门时,它给我一个错误。 PS。当我只是对传入消息进行所有权并将它们传递时,它们到达另一个连接到Aggregator.cc的模块一个又一个很好。 我还尝试了从消息类型更改为数据包,但结果相同。
我如何才能通过门获得所有数据? 请帮忙 Heartrate.cc

//Heartrate.cc
#include "Heartrate.h"
#include "string"
#include <stdio.h>
#include <string.h>
#include "myMessage_m.h"
Define_Module(Heartrate);

void Heartrate::initialize()
{
    // TODO - Generated method body
        myMessage *Newmsg = createMessage(20);
        send(Newmsg,"heartrateexit");
}

void Heartrate::handleMessage(cMessage *msg)
{
    // TODO - Generated method body
}
myMessage *Heartrate::createMessage(int a){
           // int heartrate = 20;
            int msgtype = 2;
            char msgName[20];
            sprintf(msgName,"send message heartrate %d",a);

            myMessage *msg = new myMessage(msgName,msgtype);
            msg->setHeartrate(heartrate);
            msg->setMymessagetype(msgtype);
            return msg;
    } 

Temperature.cc

//Temperature.cc
#include "Temperature.h"
#include <stdio.h>
#include <string.h>
#include "myMessage_m.h"
Define_Module(Temperature);

void Temperature::initialize()
{
    // TODO - Generated method body
    myMessage *Newmsg = createMessage(36.6,37.2);
       send(Newmsg,"tempexit");
}

void Temperature::handleMessage(cMessage *msg)
{
    // TODO - Generated method body
}
myMessage *Temperature::createMessage(double a,double b){
// SIM_API double uniform ( double a,double b )
//SIM_API double intuniform (double a,double b )

        double temperature = uniform (a,b);
        int msgtype = 1;
        char msgName[20];
        sprintf(msgName,"send message Temperature %.2f",temperature);

        myMessage *msg = new myMessage(msgName,msgtype);
        msg->setTemperature(temperature);
        msg->setMymessagetype(msgtype);

        return msg;

    }

Aggregator.cc

//Aggregator.cc
#include "Aggregator.h"
#include "Temperature.h"
#include "Heartrate.h"
#include <string>
#include <sstream>
#include "myMessage_m.h"
#include <stdio.h>
#include <string.h>
#include <vector>
Define_Module(Aggregator);

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

}
void Aggregator:: insertMessage(cMessage *msg){
    std::vector<cMessage *> messages;
    take(msg);  // take ownership
    EV <<"h" << msg;
    messages.push_back(msg);  // store pointer
    int size = messages.size();
    cMessage * mdatabytes[size];
    for(int q=0;q<size;q++){
    mdatabytes[q] = messages[q];
   // EV << "ag databytes data: " << mdatabytes[q] <<"\n";
               }
    send(mdatabytes,"out"); // error here can't get array through
}
void Aggregator::handleMessage(cMessage *msg)
{
    // TODO - Generated method body


    insertMessage(msg); // works on its own

}

void Aggregator::removeMessage(cMessage *msg){

}

0 个答案:

没有答案