简体   繁体   English

示例:在OMNeT ++中进行调试

[英]Example: Debugging in OMNeT++

I know, this may be a lot to ask, but can anyone help me debug this code: 我知道,这可能要问很多,但是谁能帮助我调试此代码:

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>

using namespace omnetpp;


class Node : public cSimpleModule
{
  private:
    cMessage *out_msg;

    long no_sent = 0;
    long no_rcvd = 0;
    cOutVector rcvdRecord;
    cLongHistogram Statistics;

  public:
    Node();
    virtual ~Node();

  protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
    virtual void finish() override;
};

Define_Module(Node);

Node::Node()
{
    out_msg = nullptr;
}

Node::~Node()
{
    delete out_msg;
}

void Node::initialize()
{
    out_msg = nullptr;

    if (strcmp("sender", getName()) == 0) {
        EV << "Scheduling first send to t=5.0s\n";
        scheduleAt(5.0, out_msg);
        out_msg = new cMessage("Sending Message");
    }
}

void Node::handleMessage(cMessage *msg)
{
    if (msg == out_msg) {
        EV << "Sending message to receiver\n";
        send(out_msg, "out");
        out_msg = nullptr;
        no_sent++;

        simtime_t delay = par("delayTime");
        scheduleAt(simTime() + delay, out_msg);
    }

        else {
            out_msg = msg;
            no_rcvd++;
            rcvdRecord.record(out_msg);
            Statistics.collect(out_msg); //what's going on here ?
    }
}

void Node::finish()
{
    EV << "Sent:     " << no_sent << endl;
    EV << "Received: " << no_rcvd << endl;
    EV << "Messages sent, mean:   " << Statistics.getMean() << endl;
    EV << "Messages sent, standard deviation: " << Statistics.getStddev() << endl;
    EV << "Messages sent, variance: " << Statistics.getVariance() << endl;
    recordScalar("#sent", no_sent);
    recordScalar("#received", no_rcvd);
    Statistics.recordAs("Message Statistics");
}

I get the following error message: 我收到以下错误消息:

Exercise2.cc:66:38: error: no matching function for call to 'omnetpp::cOutVector::record(omnetpp::cMessage*&)' Exercise2.cc:66:38:错误:没有匹配的函数可以调用“ omnetpp :: cOutVector :: record(omnetpp :: cMessage *&)”

Exercise2.cc:67:39: error: no matching function for call to 'omnetpp::cLongHistogram::collect(omnetpp::cMessage*&)' Exercise2.cc:67:39:错误:没有匹配的函数可以调用“ omnetpp :: cLongHistogram :: collect(omnetpp :: cMessage *&)”

So I really don't know what this is supposed to tell me. 所以我真的不知道这应该告诉我什么。 Aren't these built-in functions, part of the cOutVector or cLongHistogram classes respectively? 这些内置函数分别不是cOutVectorcLongHistogram类的一部分吗?

Aren't these built-in functions, part of the cOutVector or cLongHistogram classes respectively? 这些内置函数分别不是cOutVectorcLongHistogram类的一部分吗?

They aren't. 他们不是。 Well, cOutVector does have a member function named record , it just can't take a cMessage * as an argument, so that specific function overload you wanted to use doesn't exist. 好吧, cOutVector确实有一个名为record的成员函数,它只是不能将cMessage *作为参数,因此不存在您要使用的特定函数重载 Same with cLongHistogram and collect . cLongHistogram相同并collect

Just take a look at the documentation : 只需看一下文档

A cOutVector object can write doubles to the output vector file ... 一个cOutVector对象可以将双精度数写入输出矢量文件...

And, by the way, what exactly do you expect to see as a "histogram of messages"? 而且,顺便说一句,您期望看到“消息直方图”到底是什么? :D This comic comes to my mind... :D 这个漫画浮现在我的脑海...

To record the messages (not into a cOutVector ), you can enable event logging . 要记录消息(不记录到cOutVector ),可以启用事件记录 The resulting file can be visualized in the Sequence Chart tool of the IDE, see: https://docs.omnetpp.org/tutorials/tictoc/part2/#25-visualizing-on-a-sequence-chart 可以在IDE的“序列表”工具中可视化生成的文件,请参见: https : //docs.omnetpp.org/tutorials/tictoc/part2/#25-visualizing-on-a-sequence-chart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM