簡體   English   中英

示例:在OMNeT ++中進行調試

[英]Example: Debugging in OMNeT++

我知道,這可能要問很多,但是誰能幫助我調試此代碼:

#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");
}

我收到以下錯誤消息:

Exercise2.cc:66:38:錯誤:沒有匹配的函數可以調用“ omnetpp :: cOutVector :: record(omnetpp :: cMessage *&)”

Exercise2.cc:67:39:錯誤:沒有匹配的函數可以調用“ omnetpp :: cLongHistogram :: collect(omnetpp :: cMessage *&)”

所以我真的不知道這應該告訴我什么。 這些內置函數分別不是cOutVectorcLongHistogram類的一部分嗎?

這些內置函數分別不是cOutVectorcLongHistogram類的一部分嗎?

他們不是。 好吧, cOutVector確實有一個名為record的成員函數,它只是不能將cMessage *作為參數,因此不存在您要使用的特定函數重載 cLongHistogram相同並collect

只需看一下文檔

一個cOutVector對象可以將雙精度數寫入輸出矢量文件...

而且,順便說一句,您期望看到“消息直方圖”到底是什么? :D 這個漫畫浮現在我的腦海...

要記錄消息(不記錄到cOutVector ),可以啟用事件記錄 可以在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