Getting the path to access variables from other modules

Viewed 151

I'm new to OMNeT++ and I'm using Inet framework for a project. I want to access Mac module to get a variable while I'm in an Application module. I saw this in the omnet++ manual.

cModule *targetModule = getParentModule()->getSubmodule("foo");
Foo *target = check_and_cast<Foo *>(targetModule);
target->doSomething();

and this

cModule *app = module->getModuleByPath(".app[3]");  // note leading dot
cModule *gen = module->getModuleByPath(".app[3].gen");

so I combined them and my representation of this came out like this :

cModule *macModule = cModule::getModuleByPath("TestNetwork.wlan[0].mac");
updatedMac *target = check_and_cast<updatedMac *>(macModule);
var = target->getVar(); 

the path is from the ini file.
I get this error :

<!> check_and_cast(): Cannot cast nullptr to type 'inet::updatedMac *' -- in module (inet::ApplicationApp) TestNetwork.host[1].app[0] (id=85), at t=0.305s, event #250

Did I get the path wrong? Then how can I write the path from applicationlayer module to linklayer module.

I could really use the help.

1 Answers

The path is incorrect,

   cModule *macModule =  cModule::getModuleByPath("TestNetwork.host[1].wlan[0].mac");

There are other alternatives.

   auto modNode = getContainingNode(this);
   auto macModule = modNode->module->getSubmodule("wlan", 0);
   if (macModule != nullptr) {
   }
Related