首页 > 解决方案 > 如何使用 setDoubleValue() 在 Omnet++ 中更改参数运行时

问题描述

我正在模拟具有 2 个无线主机和 1 个接入点的网络。在运行期间,节点通过访问模块并使用 setDoubleValue(0) 将接入点的发射功率设置为零(将其关闭)。但是新的价值观永远不会生效。AP 的消息继续到达节点。我在这里做错了什么?我想在模拟运行时关闭接入点。请帮忙。

cSimulation *currentSimulation = getSimulation();
cModule *tx = nullptr;
tx=currentSimulation->getModuleByPath("agranet.ap.wlan[0].radio.transmitter");
tx->par("power").setDoubleValue(0);

//cPar& po = tx->par("power");
//po.setDoubleValue(0);

我想在模拟运行时关闭接入点。

标签: omnet++

解决方案


初始化后不能更改 power 参数,因为它是非易失性参数,因此在初始化时读取其值并在之后缓存。您只能操作 C++ 代码已经为此准备好的易失性 NED 参数。

另一方面,您要实现的是在某个时间禁用节点,这就是 ScenaioManager 的用途:

https://inet.omnetpp.org/docs/users-guide/ch-scenario-scripting.html


推荐阅读