From 8ec88e2fcb0d52c97fb3f2bbc80f8bc55e20eff0 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Mon, 8 Feb 2010 16:00:46 +0000 Subject: [PATCH] added method for turning off radio receiver of application motes --- .../cooja/interfaces/ApplicationRadio.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java index 490c921f9..721bbfc1d 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ApplicationRadio.java,v 1.12 2010/02/05 09:07:58 fros4943 Exp $ + * $Id: ApplicationRadio.java,v 1.13 2010/02/08 16:00:46 fros4943 Exp $ */ package se.sics.cooja.interfaces; @@ -83,7 +83,7 @@ public class ApplicationRadio extends Radio { private double outputPower = 0; private int outputPowerIndicator = 100; -private int interfered; + private int interfered; public ApplicationRadio(Mote mote) { this.mote = mote; @@ -119,14 +119,14 @@ private int interfered; } public void signalReceptionEnd() { - //System.out.println("SignalReceptionEnded for node: " + mote.getID() + " intf:" + interfered); + //System.out.println("SignalReceptionEnded for node: " + mote.getID() + " intf:" + interfered); if (isInterfered() || packetToMote == null) { interfered--; if (interfered == 0) isInterfered = false; if (interfered < 0) { - isInterfered = false; - //logger.warn("Interfered got lower than 0!!!"); - interfered = 0; + isInterfered = false; + //logger.warn("Interfered got lower than 0!!!"); + interfered = 0; } packetToMote = null; if (interfered > 0) return; @@ -222,7 +222,7 @@ private int interfered; lastEventTime = simulation.getSimulationTime(); ApplicationRadio.this.setChanged(); ApplicationRadio.this.notifyObservers(); - + /* Deliver data */ packetFromMote = packet; lastEvent = RadioEvent.PACKET_TRANSMITTED; @@ -346,7 +346,19 @@ private int interfered; return mote; } + private boolean radioOn = true; + public void setReceiverOn(boolean radioOn) { + if (this.radioOn == radioOn) { + return; + } + + this.radioOn = radioOn; + lastEvent = radioOn?RadioEvent.HW_ON:RadioEvent.HW_OFF; + lastEventTime = simulation.getSimulationTime(); + this.setChanged(); + this.notifyObservers(); + } public boolean isReceiverOn() { - return true; + return radioOn; } }