Skip to content

Be consistent in the use of power units throughout the code. #1

@boulis

Description

@boulis

Julien Romieux reported this in the forum:
I would like to add an extra cost every time a sensor sampling is done.
I would like to know if I am right on few points:

  1.   In Resource Manager module the unit of the variable currentNodePower is mWatts. TRUE?
    
  2.   In Sensor Manager module the unit of the variable pwrConsumptionPerDevice is Watts. (because after reading it, it is divided by 1000, see code below). TRUE?
    
while ((token = pwrTokenizer.nextToken()) != NULL)
   pwrConsumptionPerDevice.push_back(((double)atof(token)) / 1000.0f);

In order to achieve my goal which was to add an extra cost every time a sensor sampling is done, I went into the Sensor Manager module, in handleMessage() function, case SENSOR_READING_MESSAGE and I found these few lines of comments:

// update the remaining energy of the node
// CONSUME_ENERGY(pwrConsumptionPerDevice[sensorIndex]);
// +++ will need to change to powerDrawn();

I replaced them by:

powerDrawn(pwrConsumptionPerDevice[sensorIndex]);

PROBLEM: This line of code above called in the Sensor Manager module, will call the function handleMessage(), case RESOURCE_MANAGER_DRAW_POWER in the Resource Manager module.

Then the power sent by the Sensor Manager module pwrConsumptionPerDevice[sensorIndex] which is in Watts will be added to the currentNodePower which is in mWatts.

To avoid that, I removed the “/ 1000.0f” in the function which read the value of pwrConsumptionPerDevice:

AM I RIGHT ?


Julien is right (double check pending). We should have uniform handling of units in all code, and mW seems the right unit scale. So just delete the /1000.0 and also add the powerDrawn statement.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions