updated interfaces to new polling format.
This commit is contained in:
parent
5650f8ba89
commit
7e864bd3c7
5 changed files with 67 additions and 114 deletions
|
@ -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: ApplicationRadio.java,v 1.4 2008/03/18 13:03:24 fros4943 Exp $
|
* $Id: ApplicationRadio.java,v 1.5 2008/10/28 12:30:48 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.interfaces;
|
package se.sics.cooja.interfaces;
|
||||||
|
@ -45,9 +45,9 @@ import se.sics.cooja.*;
|
||||||
* radio functionality. Supports radio channels and output power functionality.
|
* radio functionality. Supports radio channels and output power functionality.
|
||||||
* The mote should observe the radio for incoming radio packet data.
|
* The mote should observe the radio for incoming radio packet data.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
public class ApplicationRadio extends Radio {
|
public class ApplicationRadio extends Radio implements PolledBeforeActiveTicks {
|
||||||
private Mote myMote;
|
private Mote myMote;
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger(ApplicationRadio.class);
|
private static Logger logger = Logger.getLogger(ApplicationRadio.class);
|
||||||
|
@ -244,9 +244,6 @@ public class ApplicationRadio extends Radio {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsAfterTick() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public JPanel getInterfaceVisualizer() {
|
public JPanel getInterfaceVisualizer() {
|
||||||
// Location
|
// Location
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
* Copyright (c) 2008, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -26,13 +26,12 @@
|
||||||
* 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.4 2007/01/09 10:02:44 fros4943 Exp $
|
* $Id: Battery.java,v 1.5 2008/10/28 12:30:48 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.interfaces;
|
package se.sics.cooja.interfaces;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
@ -41,27 +40,25 @@ import se.sics.cooja.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Battery represents the energy source for a mote. This implementation has no
|
* A Battery represents the energy source for a mote. This implementation has no
|
||||||
* connection with any underlying simulated software, hence a mote does not know
|
* connection with underlying simulated software: a mote does not know about energy.
|
||||||
* the current energy levels.
|
|
||||||
* <p>
|
* <p>
|
||||||
* This Battery decreases current energy left each tick depending on the current
|
* This Battery updates energy after each mote tick:
|
||||||
* mote state. If the mote is sleeping all passive interfaces' energy
|
* the energy consumption of each interface is summed up.
|
||||||
* consumptions will be summed up and detracted from the current energy. If the
|
* In addtion, the energy used by the CPU (depends on mote state) is
|
||||||
* mote is awake both the active and passive interfaces' energy consumptions
|
* detracted each tick.
|
||||||
* will be used. Also, the energy used by the CPU (depends on mote state) will
|
|
||||||
* be detracted each tick.
|
|
||||||
* <p>
|
* <p>
|
||||||
* This observable is changed and notifies observers every time the energy left
|
*
|
||||||
* is changed. When current energy left has decreased below 0 the mote state is
|
* This observable notifies every tick (!).
|
||||||
* set to dead.
|
*
|
||||||
|
* When energy left is below 0 the mote is dead.
|
||||||
*
|
*
|
||||||
* @see MoteInterface
|
* @see MoteInterface
|
||||||
* @see MoteInterface#energyConsumptionPerTick()
|
* @see MoteInterface#energyConsumptionPerTick()
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("Battery")
|
@ClassDescription("Battery")
|
||||||
public class Battery extends MoteInterface implements PassiveMoteInterface {
|
public class Battery extends MoteInterface implements PolledAfterAllTicks {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Approximate energy consumption of a mote's CPU in active mode (mA). ESB
|
* Approximate energy consumption of a mote's CPU in active mode (mA). ESB
|
||||||
|
@ -111,62 +108,37 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
|
||||||
Battery.class, "INFINITE_ENERGY_bool");
|
Battery.class, "INFINITE_ENERGY_bool");
|
||||||
|
|
||||||
if (energyConsumptionAwakePerTick < 0) {
|
if (energyConsumptionAwakePerTick < 0) {
|
||||||
energyConsumptionAwakePerTick = ENERGY_CONSUMPTION_AWAKE_mA
|
energyConsumptionAwakePerTick = ENERGY_CONSUMPTION_AWAKE_mA * 0.001;
|
||||||
* mote.getSimulation().getTickTimeInSeconds();
|
energyConsumptionLPMPerTick = ENERGY_CONSUMPTION_LPM_mA * 0.001;
|
||||||
energyConsumptionLPMPerTick = ENERGY_CONSUMPTION_LPM_mA
|
|
||||||
* mote.getSimulation().getTickTimeInSeconds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mote = mote;
|
this.mote = mote;
|
||||||
myEnergy = INITIAL_ENERGY;
|
myEnergy = INITIAL_ENERGY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsBeforeTick() {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doActionsAfterTick() {
|
public void doActionsAfterTick() {
|
||||||
lastEnergyConsumption = 0;
|
lastEnergyConsumption = 0;
|
||||||
|
|
||||||
// If infinite energy, do nothing
|
// If infinite energy, do nothing
|
||||||
if (hasInfiniteEnergy)
|
if (hasInfiniteEnergy) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If mote is dead, do nothing
|
// If mote is dead, do nothing
|
||||||
if (mote.getState() == Mote.State.DEAD)
|
if (mote.getState() == Mote.State.DEAD) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check mote state
|
|
||||||
if (mote.getState() == Mote.State.LPM) {
|
|
||||||
// Mote is sleeping. Sum up energy usage.
|
|
||||||
double totalEnergyConsumption = 0.0;
|
|
||||||
totalEnergyConsumption += energyConsumptionLPMPerTick;
|
|
||||||
|
|
||||||
for (MoteInterface passiveInterface : mote.getInterfaces()
|
|
||||||
.getAllPassiveInterfaces()) {
|
|
||||||
totalEnergyConsumption += passiveInterface.energyConsumptionPerTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
decreaseEnergy(totalEnergyConsumption);
|
|
||||||
lastEnergyConsumption += totalEnergyConsumption;
|
|
||||||
} else {
|
|
||||||
// Mote is awake. Sum up energy usage.
|
|
||||||
double totalEnergyConsumption = 0.0;
|
|
||||||
totalEnergyConsumption += energyConsumptionAwakePerTick;
|
|
||||||
|
|
||||||
for (MoteInterface activeInterface : mote.getInterfaces()
|
|
||||||
.getAllActiveInterfaces()) {
|
|
||||||
totalEnergyConsumption += activeInterface.energyConsumptionPerTick();
|
|
||||||
}
|
|
||||||
for (MoteInterface passiveInterface : mote.getInterfaces()
|
|
||||||
.getAllPassiveInterfaces()) {
|
|
||||||
totalEnergyConsumption += passiveInterface.energyConsumptionPerTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
decreaseEnergy(totalEnergyConsumption);
|
|
||||||
lastEnergyConsumption += totalEnergyConsumption;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double totalEnergyConsumption = 0.0;
|
||||||
|
|
||||||
|
totalEnergyConsumption += energyConsumptionLPMPerTick;
|
||||||
|
for (MoteInterface intf : mote.getInterfaces().getInterfaces()) {
|
||||||
|
totalEnergyConsumption += intf.energyConsumptionPerTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
decreaseEnergy(totalEnergyConsumption);
|
||||||
|
lastEnergyConsumption += totalEnergyConsumption;
|
||||||
|
|
||||||
// Check if we are out of energy
|
// Check if we are out of energy
|
||||||
if (getCurrentEnergy() <= 0.0) {
|
if (getCurrentEnergy() <= 0.0) {
|
||||||
setChanged();
|
setChanged();
|
||||||
|
@ -176,8 +148,7 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param inf
|
* @param inf Infinite energy
|
||||||
* Set infinite energy state
|
|
||||||
*/
|
*/
|
||||||
public void setInfiniteEnergy(boolean inf) {
|
public void setInfiniteEnergy(boolean inf) {
|
||||||
hasInfiniteEnergy = inf;
|
hasInfiniteEnergy = inf;
|
||||||
|
@ -187,7 +158,7 @@ public class Battery extends MoteInterface implements PassiveMoteInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return True if this battery has inifinite energy
|
* @return True if battery has infinite energy
|
||||||
*/
|
*/
|
||||||
public boolean hasInfiniteEnergy() {
|
public boolean hasInfiniteEnergy() {
|
||||||
return hasInfiniteEnergy;
|
return hasInfiniteEnergy;
|
||||||
|
|
|
@ -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: IPAddress.java,v 1.1 2006/08/21 12:12:59 fros4943 Exp $
|
* $Id: IPAddress.java,v 1.2 2008/10/28 12:30:48 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.interfaces;
|
package se.sics.cooja.interfaces;
|
||||||
|
@ -34,7 +34,7 @@ package se.sics.cooja.interfaces;
|
||||||
import se.sics.cooja.*;
|
import se.sics.cooja.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A IPAdress represents a mote Internet address. An implementation should notify all
|
* IP Address represents a mote Internet address. An implementation should notify all
|
||||||
* observers if the address is set or changed.
|
* observers if the address is set or changed.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
|
|
|
@ -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: PolledAfterAllTicks.java,v 1.1 2008/10/28 12:09:14 fros4943 Exp $
|
* $Id: PolledAfterAllTicks.java,v 1.2 2008/10/28 12:30:48 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.interfaces;
|
package se.sics.cooja.interfaces;
|
||||||
|
@ -34,6 +34,8 @@ package se.sics.cooja.interfaces;
|
||||||
/**
|
/**
|
||||||
* A mote interface polled after ALL mote ticks.
|
* A mote interface polled after ALL mote ticks.
|
||||||
*
|
*
|
||||||
|
* @see Battery
|
||||||
|
*
|
||||||
* @author Fredrik Österlind
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
public interface PolledAfterAllTicks {
|
public interface PolledAfterAllTicks {
|
||||||
|
|
|
@ -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: Position.java,v 1.2 2007/01/09 10:02:44 fros4943 Exp $
|
* $Id: Position.java,v 1.3 2008/10/28 12:30:48 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.interfaces;
|
package se.sics.cooja.interfaces;
|
||||||
|
@ -40,14 +40,12 @@ import org.jdom.Element;
|
||||||
import se.sics.cooja.*;
|
import se.sics.cooja.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Position represents the simulated 3D position of a mote. This
|
* Mote 3D position.
|
||||||
* implementation has no connection with any underlying simulated software,
|
|
||||||
* hence a mote does not know its current position.
|
|
||||||
* <p>
|
|
||||||
* This observable is changed and notifies observers whenever new coordinates
|
|
||||||
* are set.
|
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* <p>
|
||||||
|
* This observable notifies when the position is changed.
|
||||||
|
*
|
||||||
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("Position")
|
@ClassDescription("Position")
|
||||||
public class Position extends MoteInterface {
|
public class Position extends MoteInterface {
|
||||||
|
@ -72,14 +70,11 @@ public class Position extends MoteInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates coordiantes of associated mote to (x,y,z).
|
* Set position to (x,y,z).
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x New X coordinate
|
||||||
* New X coordinate
|
* @param y New Y coordinate
|
||||||
* @param y
|
* @param z New Z coordinate
|
||||||
* New Y coordinate
|
|
||||||
* @param z
|
|
||||||
* New Z coordinate
|
|
||||||
*/
|
*/
|
||||||
public void setCoordinates(double x, double y, double z) {
|
public void setCoordinates(double x, double y, double z) {
|
||||||
coords[0] = x;
|
coords[0] = x;
|
||||||
|
@ -114,8 +109,7 @@ public class Position extends MoteInterface {
|
||||||
/**
|
/**
|
||||||
* Calculates distance from this position to given position.
|
* Calculates distance from this position to given position.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param pos Compared position
|
||||||
* Compared position
|
|
||||||
* @return Distance
|
* @return Distance
|
||||||
*/
|
*/
|
||||||
public double getDistanceTo(Position pos) {
|
public double getDistanceTo(Position pos) {
|
||||||
|
@ -130,42 +124,31 @@ public class Position extends MoteInterface {
|
||||||
/**
|
/**
|
||||||
* Calculates distance from associated mote to another mote.
|
* Calculates distance from associated mote to another mote.
|
||||||
*
|
*
|
||||||
* @param m
|
* @param m Another mote
|
||||||
* Another mote
|
|
||||||
* @return Distance
|
* @return Distance
|
||||||
*/
|
*/
|
||||||
public double getDistanceTo(Mote m) {
|
public double getDistanceTo(Mote m) {
|
||||||
return getDistanceTo(m.getInterfaces().getPosition());
|
return getDistanceTo(m.getInterfaces().getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsBeforeTick() {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doActionsAfterTick() {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
public JPanel getInterfaceVisualizer() {
|
public JPanel getInterfaceVisualizer() {
|
||||||
|
|
||||||
// Location
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
final NumberFormat form = NumberFormat.getNumberInstance();
|
final NumberFormat form = NumberFormat.getNumberInstance();
|
||||||
|
|
||||||
final JLabel positionLabel = new JLabel();
|
final JLabel positionLabel = new JLabel();
|
||||||
positionLabel.setText("(" + form.format(getXCoordinate()) + ","
|
positionLabel.setText("x=" + form.format(getXCoordinate()) + " "
|
||||||
+ form.format(getYCoordinate()) + "," + form.format(getZCoordinate())
|
+ "y=" + form.format(getYCoordinate()) + " "
|
||||||
+ ")");
|
+ "z=" + form.format(getZCoordinate()));
|
||||||
|
|
||||||
panel.add(positionLabel);
|
panel.add(positionLabel);
|
||||||
|
|
||||||
Observer observer;
|
Observer observer;
|
||||||
this.addObserver(observer = new Observer() {
|
this.addObserver(observer = new Observer() {
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
positionLabel.setText("(" + form.format(getXCoordinate()) + ","
|
positionLabel.setText("x=" + form.format(getXCoordinate()) + " "
|
||||||
+ form.format(getYCoordinate()) + ","
|
+ "y=" + form.format(getYCoordinate()) + " "
|
||||||
+ form.format(getZCoordinate()) + ")");
|
+ "z=" + form.format(getZCoordinate()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue