我正在使用这个模块层次结构:
Node: {udpApp[0]<->udp<->networkLayer->wlan[0]} and wlan[0]: {CNPCBeacon<->mac<->radio}
我在ini
文件中给出了一些初始参数udpApp
as :
**.host*.numUdpApps = 2
**.host*.udpApp[0].typename = "UDPBasicApp"
**.host*.udpApp[0].chooseDestAddrMode = "perBurst"
**.host*.udpApp[0].destAddresses = "gw1"
**.host*.udpApp[0].startTime = 1.32s
**.host*.udpApp[0].stopTime = 1.48s
但是在运行时我想通过模块更改startTime
and stopTime
for 。因此,我更改为:-udpAPP[0]
CNPCBeacon
CNPCBeacon.cc
cModule* parentmod = getParentModule();
cModule* grantParentmod = parentmod->getParentModule();
cModule* udpmod;
for (cSubModIterator iter(*grantParentmod); !iter.end(); iter++)
{
//EV<<"get the modulde "<< iter()->getFullName()<<endl;
if (strcmp(iter()->getFullName(), "udpApp[0]") == 0)
{
udpmod = iter();
break;
}
}
cPar& startTime = udpmod->par("startTime");
cPar& stopTime = udpmod->par("stopTime");
而且我能够成功接收 和 的startTime
值stopTime
。但是我想在当前模块中更改这些值,这会通过以下代码导致错误:
udpmod->par("startTime").setDoubleValue(4.2);
任何人都可以建议我在运行时更改它的方法。