From 52d6ea2738b78f09f5688b74dce6d83b54054da9 Mon Sep 17 00:00:00 2001 From: nifi Date: Fri, 27 Jun 2008 14:09:26 +0000 Subject: [PATCH] fixed problem with the initialization order --- .../src/se/sics/cooja/mspmote/ESBMote.java | 19 +++++++------- .../se/sics/cooja/mspmote/ESBMoteType.java | 10 +++---- .../src/se/sics/cooja/mspmote/MspMote.java | 15 ++++++----- .../se/sics/cooja/mspmote/MspMoteType.java | 14 +++++++--- .../src/se/sics/cooja/mspmote/SkyMote.java | 26 +++++++++++-------- .../se/sics/cooja/mspmote/SkyMoteType.java | 10 +++---- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java index 5e6fff997..79abb55fc 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java @@ -26,15 +26,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBMote.java,v 1.2 2008/03/17 09:54:19 fros4943 Exp $ + * $Id: ESBMote.java,v 1.3 2008/06/27 14:09:26 nifi Exp $ */ package se.sics.cooja.mspmote; import java.io.File; -import java.util.*; +import java.util.Random; import org.apache.log4j.Logger; -import se.sics.cooja.*; +import se.sics.cooja.MoteInterfaceHandler; +import se.sics.cooja.Simulation; import se.sics.cooja.interfaces.*; import se.sics.cooja.mspmote.interfaces.*; import se.sics.mspsim.platform.esb.ESBNode; @@ -51,8 +52,8 @@ public class ESBMote extends MspMote { super(); } - public ESBMote(MoteType moteType, Simulation sim) { - super((MspMoteType) moteType, sim); + public ESBMote(MspMoteType moteType, Simulation sim) { + super(moteType, sim); } protected boolean initEmulator(File fileELF) { @@ -62,7 +63,7 @@ public class ESBMote extends MspMote { prepareMote(fileELF, esbNode.getCPU()); } catch (Exception e) { - logger.fatal("Error when creating ESB mote: " + e); + logger.fatal("Error when creating ESB mote:", e); return false; } return true; @@ -105,12 +106,12 @@ public class ESBMote extends MspMote { } public String toString() { - if (getInterfaces().getMoteID() != null) { - return "ESB Mote, ID=" + getInterfaces().getMoteID().getMoteID(); + MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null; + if (moteID != null) { + return "ESB Mote, ID=" + moteID.getMoteID(); } else { return "ESB Mote, ID=null"; } } } - diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java index 605c570ab..a569ba1a4 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java @@ -26,20 +26,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBMoteType.java,v 1.4 2008/04/03 14:01:33 fros4943 Exp $ + * $Id: ESBMoteType.java,v 1.5 2008/06/27 14:09:26 nifi Exp $ */ package se.sics.cooja.mspmote; -import java.awt.Container; -import java.awt.Image; -import java.awt.MediaTracker; -import java.awt.Toolkit; +import java.awt.*; import java.io.File; import java.net.URL; import javax.swing.*; import org.apache.log4j.Logger; - import se.sics.cooja.*; @ClassDescription("ESB Mote Type") @@ -76,7 +72,7 @@ public class ESBMoteType extends MspMoteType { return null; } - public Mote generateMote(Simulation simulation) { + protected MspMote createMote(Simulation simulation) { return new ESBMote(this, simulation); } diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java index 431c37708..ff075c6a3 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspMote.java,v 1.7 2008/04/03 14:01:06 fros4943 Exp $ + * $Id: MspMote.java,v 1.8 2008/06/27 14:09:26 nifi Exp $ */ package se.sics.cooja.mspmote; @@ -37,13 +37,10 @@ import java.net.URLConnection; import java.util.*; import org.apache.log4j.Logger; import org.jdom.Element; - import se.sics.cooja.*; import se.sics.cooja.mspmote.interfaces.TR1001Radio; import se.sics.mspsim.core.MSP430; -import se.sics.mspsim.util.ELF; -import se.sics.mspsim.util.MapEntry; -import se.sics.mspsim.util.MapTable; +import se.sics.mspsim.util.*; /** * @author Fredrik Osterlind @@ -92,9 +89,13 @@ public abstract class MspMote implements Mote { public MspMote(MspMoteType moteType, Simulation simulation) { myMoteType = moteType; mySimulation = simulation; - initEmulator(myMoteType.getELFFile()); + } - myMoteInterfaceHandler = createMoteInterfaceHandler(); + protected void initMote() { + if (myMoteType != null) { + initEmulator(myMoteType.getELFFile()); + myMoteInterfaceHandler = createMoteInterfaceHandler(); + } } /** diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java index 9efe782ec..197de984d 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspMoteType.java,v 1.5 2008/04/03 14:00:21 fros4943 Exp $ + * $Id: MspMoteType.java,v 1.6 2008/06/27 14:09:26 nifi Exp $ */ package se.sics.cooja.mspmote; @@ -35,14 +35,14 @@ import java.awt.*; import java.awt.Dialog.ModalityType; import java.awt.event.*; import java.io.*; -import java.util.*; +import java.util.Collection; +import java.util.Vector; import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.filechooser.FileFilter; import org.apache.log4j.Logger; import org.jdom.Element; - import se.sics.cooja.*; import se.sics.cooja.dialogs.MessageList; @@ -129,6 +129,14 @@ public abstract class MspMoteType implements MoteType { return fileSource; } + public final Mote generateMote(Simulation simulation) { + MspMote mote = createMote(simulation); + mote.initMote(); + return mote; + } + + protected abstract MspMote createMote(Simulation simulation); + /** * Configures and initialized Msp mote types. * diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java index e0f224e03..72a836b2c 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java @@ -26,16 +26,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMote.java,v 1.4 2008/04/03 14:02:20 fros4943 Exp $ + * $Id: SkyMote.java,v 1.5 2008/06/27 14:09:26 nifi Exp $ */ package se.sics.cooja.mspmote; import java.io.File; -import java.util.*; +import java.util.Random; import org.apache.log4j.Logger; - -import se.sics.cooja.*; +import se.sics.cooja.MoteInterfaceHandler; +import se.sics.cooja.Simulation; import se.sics.cooja.interfaces.*; import se.sics.cooja.mspmote.interfaces.*; import se.sics.mspsim.platform.sky.SkyNode; @@ -52,8 +52,8 @@ public class SkyMote extends MspMote { super(); } - public SkyMote(MoteType moteType, Simulation sim) { - super((SkyMoteType) moteType, sim); + public SkyMote(MspMoteType moteType, Simulation sim) { + super(moteType, sim); } protected boolean initEmulator(File fileELF) { @@ -63,7 +63,7 @@ public class SkyMote extends MspMote { prepareMote(fileELF, skyNode.getCPU()); } catch (Exception e) { - logger.fatal("Error when creating Sky mote: " + e); + logger.fatal("Error when creating Sky mote:", e); return false; } return true; @@ -82,10 +82,14 @@ public class SkyMote extends MspMote { Clock moteClock = new MspClock(this); moteInterfaceHandler.addActiveInterface(moteClock); + // Add button interface + Button moteButton = new SkyButton(this); + moteInterfaceHandler.addActiveInterface(moteButton); + // Add Flash interface SkyFlash moteFlash = new SkyFlash(this); moteInterfaceHandler.addActiveInterface(moteFlash); - + // Add ID interface MoteID moteID = new MspMoteID(this); moteInterfaceHandler.addActiveInterface(moteID); @@ -106,12 +110,12 @@ public class SkyMote extends MspMote { } public String toString() { - if (getInterfaces().getMoteID() != null) { - return "Sky Mote, ID=" + getInterfaces().getMoteID().getMoteID(); + MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null; + if (moteID != null) { + return "Sky Mote, ID=" + moteID.getMoteID(); } else { return "Sky Mote, ID=null"; } } } - diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java index 32e01a4a4..71f2fdd26 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java @@ -26,20 +26,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMoteType.java,v 1.3 2008/04/03 14:00:21 fros4943 Exp $ + * $Id: SkyMoteType.java,v 1.4 2008/06/27 14:09:26 nifi Exp $ */ package se.sics.cooja.mspmote; -import java.awt.Container; -import java.awt.Image; -import java.awt.MediaTracker; -import java.awt.Toolkit; +import java.awt.*; import java.io.File; import java.net.URL; import javax.swing.*; import org.apache.log4j.Logger; - import se.sics.cooja.*; @ClassDescription("Sky Mote Type") @@ -76,7 +72,7 @@ public class SkyMoteType extends MspMoteType { return null; } - public Mote generateMote(Simulation simulation) { + protected MspMote createMote(Simulation simulation) { return new SkyMote(this, simulation); }