added method to get last tick used energy

This commit is contained in:
fros4943 2006-09-26 12:47:06 +00:00
parent 328071ff10
commit 7ef9271567

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: Battery.java,v 1.1 2006/08/21 12:12:59 fros4943 Exp $ * $Id: Battery.java,v 1.2 2006/09/26 12:47:06 fros4943 Exp $
*/ */
package se.sics.cooja.interfaces; package se.sics.cooja.interfaces;
@ -90,6 +90,7 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
private double myEnergy; private double myEnergy;
private boolean hasInfiniteEnergy; private boolean hasInfiniteEnergy;
private double lastEnergyConsumption = 0;
/** /**
* Creates a new battery connected to given mote. * Creates a new battery connected to given mote.
@ -125,6 +126,8 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
} }
public void doActionsAfterTick() { public void doActionsAfterTick() {
lastEnergyConsumption = 0;
// If infinite energy, do nothing // If infinite energy, do nothing
if (hasInfiniteEnergy) if (hasInfiniteEnergy)
return; return;
@ -145,6 +148,7 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
} }
decreaseEnergy(totalEnergyConsumption); decreaseEnergy(totalEnergyConsumption);
lastEnergyConsumption += totalEnergyConsumption;
} else { } else {
// Mote is awake. Sum up energy usage. // Mote is awake. Sum up energy usage.
double totalEnergyConsumption = 0.0; double totalEnergyConsumption = 0.0;
@ -160,6 +164,7 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
} }
decreaseEnergy(totalEnergyConsumption); decreaseEnergy(totalEnergyConsumption);
lastEnergyConsumption += totalEnergyConsumption;
} }
// Check if we are out of energy // Check if we are out of energy
@ -264,6 +269,10 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
return 0.0; return 0.0;
} }
public double getLastTotalEnergyConsumption() {
return lastEnergyConsumption;
}
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
Vector<Element> config = new Vector<Element>(); Vector<Element> config = new Vector<Element>();
Element element; Element element;