rewriting mote interfaces for faster simulation execution.

vibration sensor interface
This commit is contained in:
fros4943 2008-10-28 12:02:35 +00:00
parent db2c5d3a12
commit f35eeb575d

View file

@ -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,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: ContikiVib.java,v 1.3 2007/01/09 10:05:19 fros4943 Exp $ * $Id: ContikiVib.java,v 1.4 2008/10/28 12:02:35 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote.interfaces; package se.sics.cooja.contikimote.interfaces;
@ -41,35 +41,35 @@ import se.sics.cooja.*;
import se.sics.cooja.contikimote.ContikiMoteInterface; import se.sics.cooja.contikimote.ContikiMoteInterface;
/** /**
* This class represents a vibration sensor. * Vibration sensor mote interface.
* *
* It needs read/write access to the following core variables: * Contiki variables:
* <ul> * <ul>
* <li>char simVibChanged (1=changed, else not changed) * <li>char simVibChanged (1=changed, else not changed)
* <li>char simVibIsActive (1=active, else inactive) * <li>char simVibIsActive (1=active, else inactive)
* </ul> * </ul>
* <p> * <p>
* Dependency core interfaces are: *
* Core interface:
* <ul> * <ul>
* <li>vib_interface * <li>vib_interface
* </ul> * </ul>
* <p> * <p>
* This observable never notifies observers.
* *
* @author Fredrik Osterlind * This observable never notifies.
*
* @author Fredrik Österlind
*/ */
@ClassDescription("Vibration sensor") @ClassDescription("Vibration sensor")
public class ContikiVib extends MoteInterface implements ContikiMoteInterface { public class ContikiVib extends MoteInterface implements ContikiMoteInterface {
private static Logger logger = Logger.getLogger(ContikiVib.class); private static Logger logger = Logger.getLogger(ContikiVib.class);
/** /**
* Approximate energy consumption of an active vibrator sensor. ESB measured * Approximate energy consumption of an active vibration sensor. ESB measured
* energy consumption is 1.58 mA. * energy consumption is 1.58 mA.
*/ */
public final double ENERGY_CONSUMPTION_VIB_mA; public final double ENERGY_CONSUMPTION_VIB_mA;
private final boolean RAISES_EXTERNAL_INTERRUPT;
private double energyActiveVibPerTick = -1; private double energyActiveVibPerTick = -1;
private Mote mote; private Mote mote;
@ -88,15 +88,13 @@ public class ContikiVib extends MoteInterface implements ContikiMoteInterface {
// Read class configurations of this mote type // Read class configurations of this mote type
ENERGY_CONSUMPTION_VIB_mA = mote.getType().getConfig().getDoubleValue( ENERGY_CONSUMPTION_VIB_mA = mote.getType().getConfig().getDoubleValue(
ContikiVib.class, "ACTIVE_CONSUMPTION_mA"); ContikiVib.class, "ACTIVE_CONSUMPTION_mA");
RAISES_EXTERNAL_INTERRUPT = mote.getType().getConfig()
.getBooleanValue(ContikiVib.class, "EXTERNAL_INTERRUPT_bool");
this.mote = mote; this.mote = mote;
this.moteMem = (SectionMoteMemory) mote.getMemory(); this.moteMem = (SectionMoteMemory) mote.getMemory();
if (energyActiveVibPerTick < 0) if (energyActiveVibPerTick < 0) {
energyActiveVibPerTick = ENERGY_CONSUMPTION_VIB_mA energyActiveVibPerTick = ENERGY_CONSUMPTION_VIB_mA * 0.001;
* mote.getSimulation().getTickTimeInSeconds(); }
} }
public static String[] getCoreInterfaceDependencies() { public static String[] getCoreInterfaceDependencies() {
@ -110,22 +108,11 @@ public class ContikiVib extends MoteInterface implements ContikiMoteInterface {
if (moteMem.getByteValueOf("simVibIsActive") == 1) { if (moteMem.getByteValueOf("simVibIsActive") == 1) {
moteMem.setByteValueOf("simVibChanged", (byte) 1); moteMem.setByteValueOf("simVibChanged", (byte) 1);
// If mote is inactive, wake it up
if (RAISES_EXTERNAL_INTERRUPT)
mote.setState(Mote.State.ACTIVE); mote.setState(Mote.State.ACTIVE);
} }
} }
public void doActionsBeforeTick() { /* TODO Energy consumption */
if (moteMem.getByteValueOf("simVibIsActive") == 1) {
myEnergyConsumption = energyActiveVibPerTick; // ESB measured value
} else
myEnergyConsumption = 0.0;
}
public void doActionsAfterTick() {
// Nothing to do
}
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {
JPanel panel = new JPanel(); JPanel panel = new JPanel();