From 9929cc2a10ec3fd37401b2344bf2d3770a5cb992 Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Wed, 14 Aug 2013 13:30:15 +0200 Subject: [PATCH] added new mote type method that returns the by default used mote interfaces, as opposed to all compatible mote interfaces this allows a user to override default settings in the create-new-mote-type dialogs --- .../cooja/avrmote/interfaces/MicaZRadio.java | 16 ++++++++++++---- .../mspmote/interfaces/Msp802154Radio.java | 7 +++++++ .../cooja/mspmote/interfaces/TR1001Radio.java | 8 ++++++++ .../sics/cooja/interfaces/CustomDataRadio.java | 2 ++ .../cooja/radiomediums/AbstractRadioMedium.java | 17 ++++++++++------- 5 files changed, 39 insertions(+), 11 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 ba9192cd6..bf44ddc34 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 @@ -32,16 +32,17 @@ package se.sics.cooja.avrmote.interfaces; import org.apache.log4j.Logger; +import se.sics.cooja.ClassDescription; +import se.sics.cooja.Mote; +import se.sics.cooja.avrmote.MicaZMote; +import se.sics.cooja.emulatedmote.Radio802154; +import se.sics.cooja.interfaces.CustomDataRadio; import avrora.sim.FiniteStateMachine; import avrora.sim.FiniteStateMachine.Probe; import avrora.sim.platform.MicaZ; import avrora.sim.radio.CC2420Radio; import avrora.sim.radio.Medium; -import se.sics.cooja.*; -import se.sics.cooja.avrmote.MicaZMote; -import se.sics.cooja.emulatedmote.Radio802154; - /** * CC2420 to COOJA wrapper. * @@ -152,4 +153,11 @@ public class MicaZRadio extends Radio802154 { //System.out.println("MicaZ: Received: " + (b &0xff)); recv.nextByte(true, (byte)b); } + + public boolean canReceiveFrom(CustomDataRadio radio) { + if (radio.getClass().equals(this.getClass())) { + return true; + } + return false; + } } 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 cc475ee23..266befe89 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 @@ -423,4 +423,11 @@ public class Msp802154Radio extends Radio implements CustomDataRadio { } return true; } + + public boolean canReceiveFrom(CustomDataRadio radio) { + if (radio.getClass().equals(this.getClass())) { + return true; + } + return false; + } } 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 873c028b0..abef5d9f6 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 @@ -357,4 +357,12 @@ public class TR1001Radio extends Radio implements USARTListener, CustomDataRadio /* TODO Implement me */ return true; } + + public boolean canReceiveFrom(CustomDataRadio radio) { + if (radio.getClass().equals(this.getClass())) { + return true; + } + return false; + } + } diff --git a/tools/cooja/java/se/sics/cooja/interfaces/CustomDataRadio.java b/tools/cooja/java/se/sics/cooja/interfaces/CustomDataRadio.java index 7c7ce8f7c..1f64f5810 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/CustomDataRadio.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/CustomDataRadio.java @@ -39,6 +39,8 @@ package se.sics.cooja.interfaces; */ public interface CustomDataRadio { + public boolean canReceiveFrom(CustomDataRadio radio); + public void receiveCustomData(Object data); public Object getLastCustomDataTransmitted(); diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java b/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java index 903af3cfd..179332de0 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java @@ -341,8 +341,8 @@ public abstract class AbstractRadioMedium extends RadioMedium { } for (Radio dstRadio : connection.getAllDestinations()) { - - if (!radio.getClass().equals(dstRadio.getClass()) || !(radio instanceof CustomDataRadio)) { + if (!(dstRadio instanceof CustomDataRadio) || + !((CustomDataRadio) dstRadio).canReceiveFrom((CustomDataRadio)radio)) { /* Radios communicate via radio packets */ continue; } @@ -383,11 +383,14 @@ public abstract class AbstractRadioMedium extends RadioMedium { } for (Radio dstRadio : connection.getAllDestinations()) { - - if (radio.getClass().equals(dstRadio.getClass()) && radio instanceof CustomDataRadio) { - /* Radios instead communicate via custom data objects */ - continue; - } + + if ((radio instanceof CustomDataRadio) && + (dstRadio instanceof CustomDataRadio) && + ((CustomDataRadio) dstRadio).canReceiveFrom((CustomDataRadio)radio)) { + /* Radios instead communicate via custom data objects */ + continue; + } + /* Forward radio packet */ if (connection.getDestinationDelay(dstRadio) == 0) {