我有一个已设置并正在运行的自定义应用程序。我可以使用 onmetpp.ini 来获得应用程序值,该值随后在开始模拟后应用。我想要做的是更改应用程序文件中的值(例如 messageLength 参数)。这是我的设置:
...
*.drone[*].**.bitrate = 10Mbps
*.drone[*].ipv4.arp.typename = "GlobalArp"
*.drone[*].numApps = 1
*.drone[*].app[0].typename = "MyApp"
*.drone[*].app[0].destAddresses = "server"
*.drone[*].app[0].destPort = 5000
*.drone[*].app[0].messageLength = 30000B
*.drone[*].app[0].sendInterval = exponential(120ms)
*.drone[*].app[0].packetName = "myUDPData"
*.drone[*].wlan[0].typename = "AckingWirelessInterface"
*.drone[*].wlan[0].mac.useAck = false
*.drone[*].wlan[0].mac.fullDuplex = false
*.drone[*].wlan[0].radio.transmitter.communicationRange = 50000m
*.drone[*].wlan[0].radio.receiver.ignoreInterference = true
*.drone[*].wlan[0].mac.headerLength = 23B
...
import inet.node.contract.INetworkNode;
import inet.physicallayer.wireless.common.contract.packetlevel.IRadioMedium;
import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator;
network myNetwork {
...
submodules:
drone[numDrones]: <default("ganetwork.DroneNode")> like INetworkNode {
@display("p=400,150;i=device/drone;is=vs");
}
...
#include "inet/applications/base/ApplicationBase.h"
#include "inet/common/clock/ClockUserModuleMixin.h"
#include "inet/transportlayer/contract/udp/UdpSocket.h"
class INET_API MyApp : public inet::ClockUserModuleMixin<inet::ApplicationBase>, public inet::UdpSocket::ICallback {
public:
void setMessageLength() {messageLength = 1234;};
protected:
enum SelfMsgKinds { START = 1, SEND, STOP };
// parameters
std::vector<inet::L3Address> destAddresses;
std::vector<std::string> destAddressStr;
int localPort = -1, destPort = -1;
inet::clocktime_t startTime;
inet::clocktime_t stopTime;
bool dontFragment = false;
const char *packetName = nullptr;
int messageLength = 0;
...
}
droneNode.cc:56:11:错误:“omnetpp::cModule”中没有名为“setMessageLength”的成员
...
#include "droneNode.h"
#include "myApp.h"
Define_Module(DroneNode);
DroneNode::DroneNode() {}
DroneNode::~DroneNode() {}
void DroneNode::initialize(int stage) {'some init code in here'}
void DroneNode::move() {
char buf2[20] = "app";
cModule *mod2 = (MyApp*)getSubmodule(buf2, 0); //magic numbers until I get this working!
mod2->setMessageLength(); //<--- this give me compile issue
}
...
注意:我的网络和设置基于以下两个教程:
环境:
OMNeT++集成开发环境,
版本:6.0,内部版本号:220413-71d8fab425
版权所有 (C) 2005-2022 OpenSim Ltd.
图书馆
inet-4.5.0-3833582230
感谢您的帮助,如果我的问题中有任何遗漏的细节,请告诉我。
在您的代码中,
mod2
是指向cModule
实例的指针,而不是MyApp
。 cModule
没有 setMessageLength()
因此编译器会显示上述错误。您应该将该指针强制转换为指向 MyApp
的指针,例如使用以下代码:
char buf2[20] = "app";
cModule *mod2 = getSubmodule(buf2, 0);
if (mod2) {
MyApp * mod3 = dynamic_cast<MyApp*>(mod2);
if (mod3) {
mod3->setMessageLength();
}
}