2015-08-14 54 views
1

我想熟悉Omnetpp,所以我正在做TicToc示例。但在那里我发现了一个我不明白的问题:为什么limit的默认值不起作用?限制始终设置为5,只有当我将其设置为其他值时才像我在Toc5中那样。Omnetpp .ned参数文件默认值

这里我的日志从Txc5 ::初始化

Initializing module Tictoc5, stage 0 
Tictoc5.tic: Initializing module Tictoc5.tic, stage 0 
Tictoc5.tic: limit is 10 
Tictoc5.tic: tic's counter is set to 10 
Tictoc5.tic: Sending initial message 
Tictoc5.toc: Initializing module Tictoc5.toc, stage 0 
Tictoc5.toc: limit is 5 
Tictoc5.toc: toc's counter is set to 5 

在这里你可以看到,抽动症的计数器设置为10,这是确定的,但TOC的计数器是5 我不明白为什么它不设置为20,就像我在int limit = default(20);

说我已经tictoc5.ned:

simple Txc5 
{ 
parameters: 
    bool sendMsgOnInit = default(false); 
    int limit = default(20); 
    @display("i=block/routing"); 
gates: 
    input in; 
    output out; 
} 

simple Tic5 extends Txc5 
{ 
parameters: 
    @display("i=,cyan"); 
    sendMsgOnInit = true; 
    limit = 10; 
} 

simple Toc5 extends Txc5 
{ 
parameters: 
    @display("i=,gold"); 
} 

network Tictoc5 
{ 
submodules: 
    tic: Tic5; 
    toc: Toc5; 

connections: 
    tic.out --> { delay = 100ms; } --> toc.in; 
    tic.in <-- { delay = 100ms; } <-- toc.out; 
} 

,我有txc5.cc

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


class Txc5 : public cSimpleModule 
{ 
private: 
    int counter; 

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

Define_Module(Txc5); 

void Txc5::initialize() 
{ 
    counter = par("limit"); 
    EV << "limit is " << (int)par("limit") << " \n"; 
    EV << getName() << "'s counter is set to " << counter << "\n"; 
    if (par("sendMsgOnInit").boolValue() == true) 
    { 
     // The `ev' object works like `cout' in C++. 
     EV << "Sending initial message\n"; 
     cMessage *msg = new cMessage("tictocMsg"); 
     send(msg, "out"); 
    } 
} 

void Txc5::handleMessage(cMessage *msg) 
{ 
    counter--; 
    if(counter == 0) { 
     EV << getName() << "'s counter reached zero, deleting message \n"; 

    } else { 
     EV << getName() << "'s counter is " << counter << "\n"; 
     EV << "Received message `" << msg->getName() << "', sending it out again\n"; 
     send(msg, "out"); 
    } 
} 

回答

4

参数的默认值是从NED采取前提是在omnetpp.ini文件中查找该参数不匹配的条目(和参数不硬编码 - 解释后)。在omnetpp.iniTictoc5例如有以下项:
**.limit = 5
因此对于Toc5极限等于5
然而,在Tic5定义在NED行:
limit = 10
意味着限制参数的值被硬编码 10.而且根据OMNeT++ Manual硬编码参数:

  • 不能由值从omnetpp.ini覆盖文件
  • 不再使用默认值