【问题标题】:Getting the path to access variables from other modules获取从其他模块访问变量的路径
【发布时间】:2020-12-16 13:23:51
【问题描述】:

我是 OMNeT++ 的新手,我正在为一个项目使用 Inet 框架。 我想在应用程序模块中访问 Mac 模块以获取变量。我在 omnet++ 手册中看到了这一点。

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

还有这个

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

所以我把它们结合起来,我的表现是这样的:

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

路径来自ini文件。
我收到此错误:

check_and_cast(): 无法将 nullptr 转换为类型 'inet::updatedMac *' -- 在模块 (inet::ApplicationApp) TestNetwork.host[1].app[0] (id=85) 中,位于t=0.305s,事件#250

我是不是弄错了路径?那么我该如何编写从应用层模块到链接层模块的路径。

我真的可以使用帮助。

【问题讨论】:

  • 其实你得到了 nullptr ...

标签: c++ frameworks omnet++ inet


【解决方案1】:

路径不正确,

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

还有其他选择。

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

【讨论】:

    猜你喜欢
    • 2021-11-19
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多