rewriting mote interfaces for faster simulation execution.

PIR interface
This commit is contained in:
fros4943 2008-10-28 11:16:37 +00:00
parent 24308b8915
commit ddcd54d24a

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: ContikiPIR.java,v 1.3 2007/01/09 10:05:19 fros4943 Exp $ * $Id: ContikiPIR.java,v 1.4 2008/10/28 11:16:37 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote.interfaces; package se.sics.cooja.contikimote.interfaces;
@ -42,22 +42,24 @@ import se.sics.cooja.contikimote.ContikiMoteInterface;
import se.sics.cooja.interfaces.PIR; import se.sics.cooja.interfaces.PIR;
/** /**
* This class represents a passive infrared sensor. * Passive IR sensor mote interface.
* *
* It needs read/write access to the following core variables: * Contiki variables:
* <ul> * <ul>
* <li>char simPirChanged (1=changed, else not changed) * <li>char simPirChanged (1=changed, else not changed)
* <li>char simPirIsActive (1=active, else inactive) * <li>char simPirIsActive (1=active, else inactive)
* </ul> * </ul>
* <p> * <p>
* Dependency core interfaces are: *
* Core interface:
* <ul> * <ul>
* <li>pir_interface * <li>pir_interface
* </ul> * </ul>
* <p> * <p>
* This observable notifies observers if a change is discovered by the PIR. *
* * This observable notifies if PIR triggers.
* @author Fredrik Osterlind *
* @author Fredrik Österlind
*/ */
public class ContikiPIR extends PIR implements ContikiMoteInterface { public class ContikiPIR extends PIR implements ContikiMoteInterface {
private static Logger logger = Logger.getLogger(ContikiPIR.class); private static Logger logger = Logger.getLogger(ContikiPIR.class);
@ -68,8 +70,6 @@ public class ContikiPIR extends PIR implements ContikiMoteInterface {
*/ */
public final double ENERGY_CONSUMPTION_PIR_mA; public final double ENERGY_CONSUMPTION_PIR_mA;
private final boolean RAISES_EXTERNAL_INTERRUPT;
private double energyActivePerTick = -1; private double energyActivePerTick = -1;
private Mote mote; private Mote mote;
@ -77,10 +77,10 @@ public class ContikiPIR extends PIR implements ContikiMoteInterface {
private double myEnergyConsumption = 0.0; private double myEnergyConsumption = 0.0;
/** /**
* Creates an interface to the pir at mote. * Creates an interface to the PIR at mote.
* *
* @param mote * @param mote Mote
* Button's mote. *
* @see Mote * @see Mote
* @see se.sics.cooja.MoteInterfaceHandler * @see se.sics.cooja.MoteInterfaceHandler
*/ */
@ -88,15 +88,13 @@ public class ContikiPIR extends PIR implements ContikiMoteInterface {
// Read class configurations of this mote type // Read class configurations of this mote type
ENERGY_CONSUMPTION_PIR_mA = mote.getType().getConfig().getDoubleValue( ENERGY_CONSUMPTION_PIR_mA = mote.getType().getConfig().getDoubleValue(
ContikiPIR.class, "ACTIVE_CONSUMPTION_mA"); ContikiPIR.class, "ACTIVE_CONSUMPTION_mA");
RAISES_EXTERNAL_INTERRUPT = mote.getType().getConfig()
.getBooleanValue(ContikiPIR.class, "EXTERNAL_INTERRUPT_bool");
this.mote = mote; this.mote = mote;
this.moteMem = (SectionMoteMemory) mote.getMemory(); this.moteMem = (SectionMoteMemory) mote.getMemory();
if (energyActivePerTick < 0) if (energyActivePerTick < 0) {
energyActivePerTick = ENERGY_CONSUMPTION_PIR_mA energyActivePerTick = ENERGY_CONSUMPTION_PIR_mA * 0.001;
* mote.getSimulation().getTickTimeInSeconds(); }
} }
public static String[] getCoreInterfaceDependencies() { public static String[] getCoreInterfaceDependencies() {
@ -107,25 +105,14 @@ public class ContikiPIR extends PIR implements ContikiMoteInterface {
if (moteMem.getByteValueOf("simPirIsActive") == 1) { if (moteMem.getByteValueOf("simPirIsActive") == 1) {
moteMem.setByteValueOf("simPirChanged", (byte) 1); moteMem.setByteValueOf("simPirChanged", (byte) 1);
// If mote is inactive, wake it up mote.setState(Mote.State.ACTIVE);
if (RAISES_EXTERNAL_INTERRUPT)
mote.setState(Mote.State.ACTIVE);
this.setChanged(); this.setChanged();
this.notifyObservers(); this.notifyObservers();
} }
} }
public void doActionsBeforeTick() { /* TODO Energy consumption of active PIR */
if (moteMem.getByteValueOf("simPirIsActive") == 1) {
myEnergyConsumption = energyActivePerTick;
} else
myEnergyConsumption = 0.0;
}
public void doActionsAfterTick() {
// Nothing to do
}
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {
JPanel panel = new JPanel(); JPanel panel = new JPanel();