I have a custom application which is setup and working. I can make chances to the application values using the onmetpp.ini which is subsequently applied after starting the simulation. What I'm looking to do is make changes to values in the application file (for example the messageLength parameter). Here is my setup:
- Omnetpp.ini file (section with the app defined)
...
*.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
...
- Ned file for the network where the node for the drone is defined
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");
}
...
- The MyApp header file
#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 file (this is where I want to change the message length from the application MyApp.cc. There is an instance of this class for every drone so I'm trying to use getModuleByPath() to access a specific one(?). When I do this, there is no access to an existing instance of MyApp to allow me to change the messagelength.
Note: I do not want to create an instance of MyApp here, it is already created by the simulator based on the omnetpp.ini file.
The below code give me the following compile issue even though the debugger can see members and variables on breakpoint.
droneNode.cc:56:11: error: no member named 'setMessageLength' in 'omnetpp::cModule'
...
#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
}
...
Note: My network and setup is based on the on the following two tutorials:
- https://inet.omnetpp.org/docs/tutorials/wireless/doc/index.html
- osg-earth include with omnetpp-6.0
Environment:
OMNeT++ Integrated Development Environment,
Version: 6.0, Build id: 220413-71d8fab425
Copyright (C) 2005-2022 OpenSim Ltd.
Library
inet-4.5.0-3833582230
Thanks for any help, let me know if there is any missing details in my question.
In your code
mod2is a pointer to an instance ofcModulenotMyApp.cModuledoes not havesetMessageLength()therefore the compiler shows the above mentioned error. You should cast that pointer to the pointer toMyApp, for example using the following code: