我正在使用Omnetpp-5.6.1,我想进行时间仿真。我使用的是tic toc示例,当我放置函数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
}
我找到了此功能here,但是我不知道如何使用它。
我该如何解决?
最佳答案
在某些Tic Toc示例中,既没有通道延迟也没有消息处理延迟,因此所有事情都可能在t = 0时发生。
看一下您的示例中C ++代码中是否存在通道延迟或将来的时间scheduleAt()
。