I would request your help on this issue I'm facing on. Actually, I want to change the energyConsumer module's parameters at run time. The scenario is that I should specify an amount of energy when the nodes are transmitting or receiving depending on the state of the radio. I came through with the help of this piece of code. Thanks to that, the value of the designated parameters are well settled but the problem is that they never took effect as wished.
The parameterization of the energyConsumer module is s follow :
cModule *module = getGrandParentModule->getParentModule()->getSubmodule("node",myCHIndex);
cModule *energyConsumerCHModule = module->getSubmodule("wlan",0)->getSubmodule("radio")->getSubmodule("energyConsumer");
StateBasedEpEnergyConsumer *energconsumption = check_and_cast<StateBasedEpEnergyConsumer *>(energyConsumerCHModule);
cModule *chmodule = module->getSubmodule("generic")->getSubmodule("np");
Sim *chsim = check_and_cast<Sim *>(chmodule);
cPar *receivingPower = &energconsumption->par("receiverReceivingPowerConsumption");
EV_DEBUG <<"MY CLUSTER HEAD RECEIVING POWER IS : "<<receivingPower->doubleValue()<<endl;
EV_DEBUG <<"NEW VALUE CALCULATED : "<<((chsim->EnergyCH_RX)*bitrate)/(K)<<endl;
receivingPower->setDoubleValue(((chsim->EnergyCH_RX)*bitrate)/(K));
EV_DEBUG <<"MY CLUSTER HEAD RECEIVING POWER APPLIED IS : "<<receivingPower->doubleValue()<<endl;
EV_DEBUG <<"**************************************************************"<<endl;
cPar *transmittingPower = &energyconsumption->par("transmitterTransmittingPowerConsumption");
EV_DEBUG <<"MY CURRENT TRANSMITTING POWER IS : "<<&energyconsumption->par("transmitterTransmittingPowerConsumption")<<endl;
EV_DEBUG <<"NEW VALUE CALCULATED : "<<(EnergyToCH*bitrate)/(K)<<endl;
transmittingPower->setDoubleValue((EnergyToCH*bitrate)/(K));
EV_DEBUG <<"MY CURRENT TRANSMITTING POWER APPLIED IS : "<<&energyconsumption->par("transmitterTransmittingPowerConsumption")<<endl;
THE OUTPUT IS AS PER THE IMAGES :
But as you can see, no energy consumption happens (the energyStorage module still keeps the initial energy provided, 0.5J) despite there being some well-defined value.
THE NEXT IMAGE IS THE STATE OF THE ENERGY STORAGE MODULE:
Could you please advise on how should I process it?
Many thanks for your support...
CodePudding user response:
The StateBasedEpEnergyConsumer
module is not written in a way that it expects that certain parameters are changing during runtime (in fact almost none of the INET modules are). A parameter is usually read only once (usually during the initialization phase). After that point they usually store the value of the parameter in an internal member variable and they do not care about any change in the future. (you can check that in StateBasedEpEnergyConsumer.cc
).
If you want to change the energy consumption values during runtime, you should write your own EnergyConsumer module by implementing the power::IEpEnergyConsumer
interface. (or modify the current implementation by adding a handleParameterChange()
method to store the actual new value in the member variable.