簡體   English   中英

Omnet++ 中的模擬時間

[英]Simulation time in Omnet++

我正在使用 Omnetpp-5.6.1,我想獲得時間模擬。 我正在使用 tic toc 示例,當我輸入 function simTime()時,它只返回 0。我的代碼是這樣的:

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


using namespace omnetpp;

/**
 * Derive the Txc1 class from cSimpleModule. In the Tictoc1 network,
 * both the `tic' and `toc' modules are Txc1 objects, created by OMNeT++
 * at the beginning of the simulation.
 */
class Txc1 : public cSimpleModule
{
  protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

// The module class needs to be registered with OMNeT++
Define_Module(Txc1);

void Txc1::initialize()
{
    if (strcmp("source", getName()) == 0) {
        // create and send first message on gate "out". "tictocMsg" is an
        // arbitrary string which will be the name of the message object.

        cMessage *msg = new cMessage("tictocMsg");

        send(msg, "out");

    }
}

void Txc1::handleMessage(cMessage *msg)
{

    EV<< msg->getSendingTime()<< Simtime() ;
    send(msg, "out"); // send out the message

}

我在這里找到了這個 function 但我不知道如何使用它。

我該如何解決這個問題?

在一些 Tic Toc 示例中,通道中既沒有延遲,也沒有處理消息的延遲,因此一切都可能發生在 t=0 時。
看看您的示例中是否存在通道延遲,或者 C++ 代碼中是否存在帶有未來時間的scheduleAt()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM