因此,我尝试在omnetpp中创建一个简单的模拟,并且在模块参数方面遇到了问题。
我提供了一个简单的例子来说明我的问题。--如果我将注释部分保留在所有注释的代码中,则模拟运行良好。如果我不注释所有代码中的注释部分,则我的程序编译得很好,但是模拟无法运行。调试输出如下消息:
在网络设置期间模块(omnetpp::cModule) net (id=1)中出现错误:(收发信机):未知参数“什么”。
我不知道问题是什么,因为“什么”是在我的.ini文件和.ned中定义的。这是我的代码:
transceiver.cc
#include <omnetpp.h>
using namespace omnetpp;
class transceiver : public cSimpleModule
{
private:
//int what;
public:
transceiver();
virtual ~transceiver();
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage* msg) override;
};
Define_Module(transceiver);
transceiver::transceiver() {
//what = par("what");
}
transceiver::~transceiver() {
}
void transceiver::initialize() {
cMessage* msg = new cMessage("Message");
send(msg, "out");
}
void transceiver::handleMessage(cMessage* msg) {
EV << "We got a message!" << endl;
delete msg;
}package.ned
package packetgenerator;
@license(omnetpp);omnetpp.ini
[General]
network = transceiver.net
#net.transceiver.what = 5transceiver.ned
package transceiver;
simple transceiver
{
parameters:
//int what = default(2);
gates:
input in;
output out;
}
network net
{
submodules:
transceiver: transceiver;
connections:
transceiver.out --> transceiver.in;
}发布于 2016-09-13 11:51:59
您是,而不是,它应该访问模块构造函数中的参数。参数应在initalize()方法中访问。
使用
transceiver::initialize(int stage) {
what = par("what");
}而不是
transceiver::transceiver() {
what = par("what");
}https://stackoverflow.com/questions/39449261
复制相似问题