From 86f1c3469222611c2426bb7f58f8665cccbaeae5 Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Mon, 4 Jun 2012 12:39:46 +0200 Subject: [PATCH] renamed radio method isReceiverOn() to isRadioOn() fixed bug in Msp802154Radio causing all packets from non-802154-radios to be dropped --- .../cooja/avrmote/interfaces/MicaZRadio.java | 2 +- .../cooja/apps/mrm/java/se/sics/mrm/MRM.java | 2 +- .../mspmote/interfaces/Msp802154Radio.java | 20 +++++++++++++++---- .../cooja/mspmote/interfaces/TR1001Radio.java | 2 +- .../apps/powertracker/java/PowerTracker.java | 6 +++--- .../contikimote/interfaces/ContikiRadio.java | 2 +- .../sics/cooja/emulatedmote/Radio802154.java | 2 +- .../cooja/interfaces/ApplicationRadio.java | 2 +- .../java/se/sics/cooja/interfaces/Radio.java | 10 +++++----- .../java/se/sics/cooja/plugins/TimeLine.java | 8 ++++---- .../plugins/skins/TrafficVisualizerSkin.java | 2 +- .../radiomediums/DirectedGraphMedium.java | 2 +- .../java/se/sics/cooja/radiomediums/UDGM.java | 2 +- 13 files changed, 37 insertions(+), 25 deletions(-) diff --git a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZRadio.java b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZRadio.java index 2b3bcf340..d8ae03a14 100644 --- a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZRadio.java +++ b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZRadio.java @@ -111,7 +111,7 @@ public class MicaZRadio extends Radio802154 { return (int) cc2420.getFrequency(); } - public boolean isReceiverOn() { + public boolean isRadioOn() { FiniteStateMachine fsm = cc2420.getFiniteStateMachine(); /* based on reading the source code it seems that the fsm state = 3 means on */ //System.out.println("COOJA: cc2420 FSM: " + fsm.getCurrentState()); diff --git a/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java b/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java index 415447472..362418ed8 100644 --- a/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java +++ b/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java @@ -192,7 +192,7 @@ public class MRM extends AbstractRadioMedium { double recvSignalStrength = probData[1]; if (recvProb == 1.0 || random.nextDouble() < recvProb) { /* Yes, the receiver *may* receive this packet (it's strong enough) */ - if (!recv.isReceiverOn()) { + if (!recv.isRadioOn()) { newConnection.addInterfered(recv); recv.interfereAnyReception(); } else if (recv.isInterfered()) { diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/Msp802154Radio.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/Msp802154Radio.java index e2ded9988..59b444c3c 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/Msp802154Radio.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/Msp802154Radio.java @@ -31,8 +31,10 @@ package se.sics.cooja.mspmote.interfaces; import java.util.Collection; + import org.apache.log4j.Logger; import org.jdom.Element; + import se.sics.cooja.ClassDescription; import se.sics.cooja.Mote; import se.sics.cooja.RadioPacket; @@ -42,6 +44,7 @@ import se.sics.cooja.interfaces.Position; import se.sics.cooja.interfaces.Radio; import se.sics.cooja.mspmote.MspMote; import se.sics.cooja.mspmote.MspMoteTimeEvent; +import se.sics.mspsim.chip.CC2420; import se.sics.mspsim.chip.ChannelListener; import se.sics.mspsim.chip.RFListener; import se.sics.mspsim.chip.Radio802154; @@ -207,8 +210,8 @@ public class Msp802154Radio extends Radio implements CustomDataRadio { lastIncomingPacket = packet; /* TODO Check isReceiverOn() instead? */ - if (radio.isReadyToReceive()) { - logger.warn("Radio is turned off, dropping packet data"); + if (!radio.isReadyToReceive()) { + logger.warn("Radio receiver not ready, dropping packet data"); return; } @@ -394,7 +397,16 @@ public class Msp802154Radio extends Radio implements CustomDataRadio { public void setConfigXML(Collection configXML, boolean visAvailable) { } - public boolean isReceiverOn() { - return radio.isReadyToReceive(); + public boolean isRadioOn() { + if (radio.isReadyToReceive()) { + return true; + } + if (radio.getMode() == CC2420.MODE_POWER_OFF) { + return false; + } + if (radio.getMode() == CC2420.MODE_TXRX_OFF) { + return false; + } + return true; } } diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java index d873e579b..cf08583f9 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java @@ -354,7 +354,7 @@ public class TR1001Radio extends Radio implements USARTListener, CustomDataRadio return mote; } - public boolean isReceiverOn() { + public boolean isRadioOn() { /* TODO Implement me */ return true; } diff --git a/tools/cooja/apps/powertracker/java/PowerTracker.java b/tools/cooja/apps/powertracker/java/PowerTracker.java index 0601cb32e..f0758bcda 100644 --- a/tools/cooja/apps/powertracker/java/PowerTracker.java +++ b/tools/cooja/apps/powertracker/java/PowerTracker.java @@ -310,7 +310,7 @@ public class PowerTracker extends VisPlugin { this.mote = mote; this.radio = mote.getInterfaces().getRadio(); - radioWasOn = radio.isReceiverOn(); + radioWasOn = radio.isRadioOn(); if (radio.isTransmitting()) { lastRadioState = RadioState.TRANSMITTING; } else if (radio.isReceiving()) { @@ -350,7 +350,7 @@ public class PowerTracker extends VisPlugin { /* Await next radio event */ if (radio.isTransmitting()) { lastRadioState = RadioState.TRANSMITTING; - } else if (!radio.isReceiverOn()) { + } else if (!radio.isRadioOn()) { lastRadioState = RadioState.IDLE; } else if (radio.isInterfered()) { lastRadioState = RadioState.INTERFERED; @@ -359,7 +359,7 @@ public class PowerTracker extends VisPlugin { } else { lastRadioState = RadioState.IDLE; } - radioWasOn = radio.isReceiverOn(); + radioWasOn = radio.isRadioOn(); lastUpdateTime = now; } diff --git a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiRadio.java b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiRadio.java index b301c2114..0e941fa6f 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiRadio.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiRadio.java @@ -164,7 +164,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledA } /* General radio support */ - public boolean isReceiverOn() { + public boolean isRadioOn() { return radioOn; } diff --git a/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java b/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java index 8fc187310..3dcb73ba7 100644 --- a/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java +++ b/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java @@ -181,7 +181,7 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { public abstract int getFrequency(); - public abstract boolean isReceiverOn(); + public abstract boolean isRadioOn(); public abstract double getCurrentOutputPower(); diff --git a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java index d146bd6ff..87e23b08f 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java @@ -392,7 +392,7 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio, Directi this.setChanged(); this.notifyObservers(); } - public boolean isReceiverOn() { + public boolean isRadioOn() { return radioOn; } diff --git a/tools/cooja/java/se/sics/cooja/interfaces/Radio.java b/tools/cooja/java/se/sics/cooja/interfaces/Radio.java index 0800774b7..49dd82f4a 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/Radio.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/Radio.java @@ -139,18 +139,18 @@ public abstract class Radio extends MoteInterface { public abstract boolean isInterfered(); /** - * @return True if the simulated radio receiver is turned on + * @return True if the simulated radio transceiver is on */ - public abstract boolean isReceiverOn(); + public abstract boolean isRadioOn(); /** * Interferes with any current reception. If this method is called, the packet * will be dropped. This method can be used to simulate radio interference * such as high background noise or radio packet collisions. - * - * When the radio is no longer interfered, the {@link #signalReceptionEnd()} + * + * When the radio is no longer interfered, the {@link #signalReceptionEnd()} * method must be called. - * + * * @see #signalReceptionEnd() */ public abstract void interfereAnyReception(); diff --git a/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java b/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java index 255f99d9c..2f10d021e 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java +++ b/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java @@ -1004,7 +1004,7 @@ public class TimeLine extends VisPlugin implements HasQuickHelp { final Radio moteRadio = mote.getInterfaces().getRadio(); if (moteRadio != null) { RadioHWEvent startupHW = new RadioHWEvent( - simulation.getSimulationTime(), moteRadio.isReceiverOn()); + simulation.getSimulationTime(), moteRadio.isRadioOn()); if (radioChannels) { startupHW.channel = moteRadio.getChannel(); } @@ -1024,7 +1024,7 @@ public class TimeLine extends VisPlugin implements HasQuickHelp { lastChannel = nowChannel; RadioHWEvent ev = new RadioHWEvent( - simulation.getSimulationTime(), moteRadio.isReceiverOn()); + simulation.getSimulationTime(), moteRadio.isRadioOn()); if (radioChannels) { ev.channel = moteRadio.getChannel(); } @@ -1044,7 +1044,7 @@ public class TimeLine extends VisPlugin implements HasQuickHelp { if (moteRadio.getLastEvent() == RadioEvent.HW_ON || moteRadio.getLastEvent() == RadioEvent.HW_OFF) { RadioHWEvent ev = new RadioHWEvent( - simulation.getSimulationTime(), moteRadio.isReceiverOn()); + simulation.getSimulationTime(), moteRadio.isRadioOn()); if (radioChannels) { ev.channel = moteRadio.getChannel(); } @@ -1074,7 +1074,7 @@ public class TimeLine extends VisPlugin implements HasQuickHelp { if (moteRadio.isTransmitting()) { ev = new RadioRXTXEvent( simulation.getSimulationTime(), RXTXRadioEvent.TRANSMITTING); - } else if (!moteRadio.isReceiverOn()) { + } else if (!moteRadio.isRadioOn()) { ev = new RadioRXTXEvent( simulation.getSimulationTime(), RXTXRadioEvent.IDLE); } else if (moteRadio.isInterfered()) { diff --git a/tools/cooja/java/se/sics/cooja/plugins/skins/TrafficVisualizerSkin.java b/tools/cooja/java/se/sics/cooja/plugins/skins/TrafficVisualizerSkin.java index f51d81239..cde0aa039 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/skins/TrafficVisualizerSkin.java +++ b/tools/cooja/java/se/sics/cooja/plugins/skins/TrafficVisualizerSkin.java @@ -192,7 +192,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin { return null; } - if (!moteRadio.isReceiverOn()) { + if (!moteRadio.isRadioOn()) { return new Color[] { Color.GRAY }; } diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java b/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java index f6ba39c3a..78d48e50a 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java @@ -273,7 +273,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium { continue; } - if (!dest.radio.isReceiverOn()) { + if (!dest.radio.isRadioOn()) { /* Fail: radio is off */ /*logger.info(source + ": Fail, off");*/ newConn.addInterfered(dest.radio); diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java index c87fce3ca..82865c6a4 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java @@ -215,7 +215,7 @@ public class UDGM extends AbstractRadioMedium { if (distance <= moteTransmissionRange) { /* Within transmission range */ - if (!recv.isReceiverOn()) { + if (!recv.isRadioOn()) { newConnection.addInterfered(recv); recv.interfereAnyReception(); } else if (recv.isInterfered()) {