removed passive/active interfaces notion.
also, new energy estimation method
This commit is contained in:
parent
1fdb3c21f0
commit
a45f451dcf
1 changed files with 65 additions and 82 deletions
|
@ -1,30 +1,32 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights
|
* Copyright (c) 2008, Swedish Institute of Computer Science.
|
||||||
* 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
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
* are met:
|
||||||
* this list of conditions and the following disclaimer. 2. Redistributions in
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* binary form must reproduce the above copyright notice, this list of
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* conditions and the following disclaimer in the documentation and/or other
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* materials provided with the distribution. 3. Neither the name of the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* Institute nor the names of its contributors may be used to endorse or promote
|
* documentation and/or other materials provided with the distribution.
|
||||||
* products derived from this software without specific prior written
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
* permission.
|
* may be used to endorse or promote products derived from this software
|
||||||
*
|
* without specific prior written permission.
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
|
*
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
*
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* $Id: MoteInterface.java,v 1.3 2007/01/10 14:57:42 fros4943 Exp $
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* $Id: MoteInterface.java,v 1.4 2008/10/28 12:50:38 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -35,23 +37,30 @@ import javax.swing.JPanel;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
import se.sics.cooja.interfaces.PolledAfterActiveTicks;
|
||||||
|
import se.sics.cooja.interfaces.PolledAfterAllTicks;
|
||||||
|
import se.sics.cooja.interfaces.PolledBeforeActiveTicks;
|
||||||
|
import se.sics.cooja.interfaces.PolledBeforeAllTicks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mote interface represents a mote property. Often this is a simulated
|
* A mote interface represents a mote property. Typically, this is a simulated
|
||||||
* hardware peripheral such as a button or a led. This can also be a property
|
* hardware peripheral such as a button or LEDs. This may also be a property
|
||||||
* the mote software itself is unaware of, for example the current position of
|
* that the mote itself is unaware of, for example the current position of
|
||||||
* the mote.
|
* the mote.
|
||||||
*
|
*
|
||||||
* Interfaces are the main way for the simulator to interact with a simulated
|
* Interfaces are the main way for the simulator to interact with a simulated
|
||||||
* mote.
|
* mote.
|
||||||
*
|
*
|
||||||
* Interfaces are divided into active and passive interfaces, which are handled
|
* Each interface can be polled before and after mote ticks.
|
||||||
* differently. In order to create a passive interface, the class should also
|
* This is controlled by implementing the correct Java interfaces,
|
||||||
* implement the dummy Java interface PassiveMoteInterface. For an explanation
|
* such as PolledBeforeActiveTicks.
|
||||||
* of the differences of active and passive interfaces see class
|
*
|
||||||
* PassiveMoteInterface.
|
* @see PolledBeforeActiveTicks
|
||||||
*
|
* @see PolledAfterActiveTicks
|
||||||
* @see PassiveMoteInterface
|
* @see PolledBeforeAllTicks
|
||||||
* @author Fredrik Osterlind
|
* @see PolledAfterAllTicks
|
||||||
|
*
|
||||||
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
public abstract class MoteInterface extends Observable {
|
public abstract class MoteInterface extends Observable {
|
||||||
private static Logger logger = Logger.getLogger(MoteInterface.class);
|
private static Logger logger = Logger.getLogger(MoteInterface.class);
|
||||||
|
@ -60,7 +69,7 @@ public abstract class MoteInterface extends Observable {
|
||||||
* This method creates an instance of the given class with the given mote as
|
* This method creates an instance of the given class with the given mote as
|
||||||
* constructor argument. Instead of calling the interface constructors
|
* constructor argument. Instead of calling the interface constructors
|
||||||
* directly this method may be used.
|
* directly this method may be used.
|
||||||
*
|
*
|
||||||
* @param interfaceClass
|
* @param interfaceClass
|
||||||
* Mote interface class
|
* Mote interface class
|
||||||
* @param mote
|
* @param mote
|
||||||
|
@ -70,8 +79,7 @@ public abstract class MoteInterface extends Observable {
|
||||||
public static final MoteInterface generateInterface(
|
public static final MoteInterface generateInterface(
|
||||||
Class<? extends MoteInterface> interfaceClass, Mote mote) {
|
Class<? extends MoteInterface> interfaceClass, Mote mote) {
|
||||||
try {
|
try {
|
||||||
// Generating interface
|
MoteInterface instance = interfaceClass.getConstructor(
|
||||||
MoteInterface instance = (MoteInterface) interfaceClass.getConstructor(
|
|
||||||
new Class[] { Mote.class }).newInstance(new Object[] { mote });
|
new Class[] { Mote.class }).newInstance(new Object[] { mote });
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -82,25 +90,15 @@ public abstract class MoteInterface extends Observable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actions to be performed just before the holding mote is ticked
|
* Returns a panel visualizing this interface. This could for
|
||||||
*/
|
|
||||||
public abstract void doActionsBeforeTick();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Actions to be performed just after the holding mote has been ticked
|
|
||||||
*/
|
|
||||||
public abstract void doActionsAfterTick();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a panel with interesting data for this interface. This could for
|
|
||||||
* example show last messages sent/received for a radio interface, or logged
|
* example show last messages sent/received for a radio interface, or logged
|
||||||
* message for a log interface.
|
* message for a log interface.
|
||||||
*
|
*
|
||||||
* All panels returned from this method must later be released for memory
|
* All panels returned from this method must later be released for memory
|
||||||
* reasons.
|
* reasons.
|
||||||
*
|
*
|
||||||
* If returned panel is null, this interface will not be visualized.
|
* This method may return null.
|
||||||
*
|
*
|
||||||
* @see #releaseInterfaceVisualizer(JPanel)
|
* @see #releaseInterfaceVisualizer(JPanel)
|
||||||
* @return Interface visualizer or null
|
* @return Interface visualizer or null
|
||||||
*/
|
*/
|
||||||
|
@ -110,7 +108,7 @@ public abstract class MoteInterface extends Observable {
|
||||||
* This method should be called when a visualizer panel is no longer in use.
|
* This method should be called when a visualizer panel is no longer in use.
|
||||||
* Any resources of that panel, for example registered observers, will be
|
* Any resources of that panel, for example registered observers, will be
|
||||||
* released.
|
* released.
|
||||||
*
|
*
|
||||||
* @see #getInterfaceVisualizer()
|
* @see #getInterfaceVisualizer()
|
||||||
* @param panel
|
* @param panel
|
||||||
* A interface visualizer panel fetched earlier for this mote
|
* A interface visualizer panel fetched earlier for this mote
|
||||||
|
@ -119,34 +117,19 @@ public abstract class MoteInterface extends Observable {
|
||||||
public abstract void releaseInterfaceVisualizer(JPanel panel);
|
public abstract void releaseInterfaceVisualizer(JPanel panel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns approximated energy consumed (mQ) during the current tick. If the
|
* Returns total energy (mQ) consumed by this interface.
|
||||||
* interface is active, this information must be available after the
|
*
|
||||||
* doActionsAfterTick method. If the interface is passive, this information
|
|
||||||
* must be available after the doActionsBeforeTick method.
|
|
||||||
*
|
|
||||||
* The interface is responsible to gather information about the current
|
* The interface is responsible to gather information about the current
|
||||||
* internal state, and calculate whatever energy it needs in that state and
|
* internal state, and calculate whatever energy it needs in that state and
|
||||||
* during one tick.
|
* during one tick.
|
||||||
*
|
*
|
||||||
* If the holding mote is dead, this method will not be called. If the holding
|
* This method is typically used battery interface, to keep track of the
|
||||||
* mote is sleeping and this interface is active, this method will not be
|
* mote energy consumption.
|
||||||
* called.
|
*
|
||||||
*
|
|
||||||
* For example, a radio transmitter or a PIR sensor often has a much higher
|
|
||||||
* energy usage than a button sensor which virtually needs no energy at all.
|
|
||||||
* If the radio is turned off in hardware, it should return a zero energy
|
|
||||||
* consumption. If the radio is sending something which would take longer than
|
|
||||||
* one tick, it may either return the total energy used directly, or a smaller
|
|
||||||
* amount during several ticks.
|
|
||||||
*
|
|
||||||
* This method may typically be used by the passive interface battery, which
|
|
||||||
* sums up all energy used during one tick and decreases the battery energy
|
|
||||||
* left.
|
|
||||||
*
|
|
||||||
* @see se.sics.cooja.interfaces.Battery
|
* @see se.sics.cooja.interfaces.Battery
|
||||||
* @return Energy consumption of this device during the current tick
|
* @return Total energy consumption of mote interface
|
||||||
*/
|
*/
|
||||||
public abstract double energyConsumptionPerTick();
|
public abstract double energyConsumption();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns XML elements representing the current config of this mote
|
* Returns XML elements representing the current config of this mote
|
||||||
|
@ -155,7 +138,7 @@ public abstract class MoteInterface extends Observable {
|
||||||
* element with the mote IP address. This method should however not return
|
* element with the mote IP address. This method should however not return
|
||||||
* state specific information such as a log history. (All nodes are restarted
|
* state specific information such as a log history. (All nodes are restarted
|
||||||
* when loading a simulation.)
|
* when loading a simulation.)
|
||||||
*
|
*
|
||||||
* @see #setConfigXML(Collection, boolean)
|
* @see #setConfigXML(Collection, boolean)
|
||||||
* @return XML elements representing the current interface config
|
* @return XML elements representing the current interface config
|
||||||
*/
|
*/
|
||||||
|
@ -163,7 +146,7 @@ public abstract class MoteInterface extends Observable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current mote interface config depending on the given XML elements.
|
* Sets the current mote interface config depending on the given XML elements.
|
||||||
*
|
*
|
||||||
* @see #getConfigXML()
|
* @see #getConfigXML()
|
||||||
* @param configXML
|
* @param configXML
|
||||||
* Config XML elements
|
* Config XML elements
|
||||||
|
|
Loading…
Reference in a new issue