我正在创建一个简单的 omnet++ 模拟。该模拟的一部分使用了一个名为数据包生成器的简单模块。它将成为名为 complete 的项目内复合模块的一部分。但是,当我尝试在复合模块中使用 packetGenerator 时,在尝试运行模拟时收到以下错误消息:
Error in module (omnetpp::cModule) net.tx (id=2) during network setup: Class "packetGenerator" not found -- perhaps its code was not linked in, or the class wasn't registered with Register_Class(), or in the case of modules and channels, with Define_Module()/Define_Channel().
是的,我进入了属性-->项目引用并引用了packetGenerator项目(如图所示)。我还调用了 Define_Module(packetGenerator),如 packetGenerator.cc
中所示我推断问题发生在复合模块的子模块部分,但我不知道如何解决这个问题。如有任何帮助,我们将不胜感激。如果我省略了 TransmitterNode 复合模块中的 packetGenerator 子模块,那么模拟将运行良好(并且不执行任何操作,因为还没有任何功能)。 p>
packetGenerator.cc(在项目packetGenerator内)
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include <AppMessage_m.h>
using namespace omnetpp;
//Simple module responsible for continuously generating AppMessage messages
class packetGenerator: public cSimpleModule {
private:
cMessage* event;
int seqno;
int senderId;
public:
packetGenerator();
virtual ~packetGenerator();
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
virtual AppMessage* generateMessage();
};
Define_Module(packetGenerator);
packetGenerator::packetGenerator() {
event = nullptr;
seqno = 0;
}
packetGenerator::~packetGenerator() {
cancelAndDelete(event);
}
void packetGenerator::initialize() {
senderId = par("nodeIdentifier");
event = new cMessage("event");
scheduleAt(0.0, event);
}
void packetGenerator::handleMessage(cMessage* msg) {
WATCH(seqno);
//Go here when the new message is scheduled to be sent (after the delay)
if (msg == event) {
send(generateMessage(), "out");
simtime_t delay = par("iatDistribution");
scheduleAt(simTime() + delay, event);
}
//If we receive a message that isn't our timer-expiry message (e.g. from the MAC), go here
else {
AppMessage* appmsg = check_and_cast<AppMessage*>(msg);
EV << "Message received" << endl;
EV << "Message kind: " << msg->getKind() << endl;
delete appmsg;
}
}
AppMessage* packetGenerator::generateMessage() {
simtime_t timeStamp = simTime();
int sequenceNumber = seqno;
seqno++;
int msgSize = par("messageSize");
char messageName[30];
sprintf(messageName, "Message from %d", senderId);
AppMessage* msg = new AppMessage(messageName);
msg->setTimeStamp(timeStamp);
msg->setSenderId(senderId);
msg->setSequenceNumber(sequenceNumber);
msg->setMsgSize(msgSize);
return msg;
}
net.ned(在项目内完成)
package complete;
import packetgenerator.packetGenerator;
module TransmitterNode
{
parameters:
int nodeIdentifier; //These need to be unique in the simulation
double nodeXPosition;
double nodeYPosition;
@display("bgb=468,188;i=device/cellphone");
gates:
submodules:
packetGenerator: packetGenerator {
@display("p=79,90;i=block/source");
}
connections:
}
network net
{
submodules:
tx: TransmitterNode;
connections:
}
最佳答案
项目 packetGenerator
必须构建为共享库,并选中 Project
中的复选框为其他项目导出此共享/静态库
| 属性
| OMNeT++
| | 鸟神星
|选择根目录或 src 目录 | 选项...
| 目标
。
关于c++ - Omnet++:作为复合模块的子模块调用时找不到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39683567/