From eb4698612dc0d0820cf270c03e16858ce69f25a1 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Thu, 17 Sep 2009 10:50:11 +0000 Subject: [PATCH] minor changes: removing some unused code, restructuring, added getID() methods --- .../src/se/sics/cooja/mspmote/ESBMote.java | 10 +-- .../src/se/sics/cooja/mspmote/MspMote.java | 75 +++++++++---------- .../se/sics/cooja/mspmote/MspMoteType.java | 20 +++-- .../sics/cooja/mspmote/SkyCompileDialog.java | 7 +- .../src/se/sics/cooja/mspmote/SkyMote.java | 18 ++--- .../se/sics/cooja/mspmote/SkyMoteType.java | 56 ++++++++------ 6 files changed, 90 insertions(+), 96 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 f2e4ca440..425eaed29 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,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBMote.java,v 1.8 2009/04/20 16:12:01 fros4943 Exp $ + * $Id: ESBMote.java,v 1.9 2009/09/17 10:50:11 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -66,14 +66,6 @@ public class ESBMote extends MspMote { return true; } - protected MoteInterfaceHandler createMoteInterfaceHandler() { - /* Uses current mote type configuration */ - MoteInterfaceHandler moteInterfaceHandler = - super.createMoteInterfaceHandler(); - - return moteInterfaceHandler; - } - public String toString() { MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null; if (moteID != null) { 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 db826535d..0fd25a343 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.31 2009/06/15 09:44:42 fros4943 Exp $ + * $Id: MspMote.java,v 1.32 2009/09/17 10:50:11 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -39,18 +39,19 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Hashtable; import java.util.Observable; -import java.util.Observer; import java.util.Vector; + import org.apache.log4j.Logger; import org.jdom.Element; + import se.sics.cooja.GUI; import se.sics.cooja.Mote; import se.sics.cooja.MoteInterface; import se.sics.cooja.MoteInterfaceHandler; import se.sics.cooja.MoteMemory; import se.sics.cooja.MoteType; -import se.sics.cooja.Watchpoint; import se.sics.cooja.Simulation; +import se.sics.cooja.Watchpoint; import se.sics.cooja.WatchpointMote; import se.sics.cooja.interfaces.IPAddress; import se.sics.cooja.mspmote.interfaces.TR1001Radio; @@ -89,8 +90,6 @@ public abstract class MspMote implements Mote, WatchpointMote { private MoteInterfaceHandler myMoteInterfaceHandler = null; private ELF myELFModule = null; - protected TR1001Radio myRadio = null; /* TODO Only used by ESB (TR1001) */ - /* Stack monitoring variables */ private boolean stopNextInstruction = false; private boolean monitorStackUsage = false; @@ -99,14 +98,6 @@ public abstract class MspMote implements Mote, WatchpointMote { private StackOverflowObservable stackOverflowObservable = new StackOverflowObservable(); private MspBreakpointContainer breakpointsContainer; - - /** - * Abort current tick immediately. - * May for example be called by a breakpoint handler. - */ - public void stopNextInstruction() { - stopNextInstruction = true; - } public MspMote() { myMoteType = null; @@ -120,7 +111,7 @@ public abstract class MspMote implements Mote, WatchpointMote { myMoteType = moteType; mySimulation = simulation; } - + protected void initMote() { if (myMoteType != null) { initEmulator(myMoteType.getContikiFirmwareFile()); @@ -131,6 +122,14 @@ public abstract class MspMote implements Mote, WatchpointMote { } } + /** + * Abort current tick immediately. + * May for example be called by a breakpoint handler. + */ + public void stopNextInstruction() { + stopNextInstruction = true; + } + protected MoteInterfaceHandler createMoteInterfaceHandler() { return new MoteInterfaceHandler(this, getType().getMoteInterfaceClasses()); } @@ -267,14 +266,6 @@ public abstract class MspMote implements Mote, WatchpointMote { myCpu.reset(); } - public void setState(State newState) { - logger.warn("Msp motes can't change state"); - } - - public State getState() { - return Mote.State.ACTIVE; - } - /* called when moteID is updated */ public void idUpdated(int newID) { } @@ -287,12 +278,6 @@ public abstract class MspMote implements Mote, WatchpointMote { myMoteType = (MspMoteType) type; } - public void addStateObserver(Observer newObserver) { - } - - public void deleteStateObserver(Observer newObserver) { - } - public MoteInterfaceHandler getInterfaces() { return myMoteInterfaceHandler; } @@ -315,6 +300,7 @@ public abstract class MspMote implements Mote, WatchpointMote { public boolean tick(long simTime) { if (stopNextInstruction) { stopNextInstruction = false; + sendCLICommandAndPrint("trace 1000"); throw new RuntimeException("MSPSim requested simulation stop"); } @@ -348,18 +334,7 @@ public abstract class MspMote implements Mote, WatchpointMote { } catch (EmulationException e) { if (e.getMessage().startsWith("Bad operation")) { /* Experimental: print program counter history */ - LineListener oldListener = commandListener; - LineListener tmpListener = new LineListener() { - public void lineRead(String line) { - logger.fatal(line); - } - }; - setCLIListener(tmpListener); - logger.fatal("Bad operation detected. Program counter history:"); - for (int element : pcHistory) { - sendCLICommand("line " + element); - } - setCLIListener(oldListener); + sendCLICommandAndPrint("trace 1000"); } throw (RuntimeException) @@ -383,6 +358,26 @@ public abstract class MspMote implements Mote, WatchpointMote { return true; } + private void sendCLICommandAndPrint(String comamnd) { + /* Backup listener */ + LineListener oldListener = commandListener; + + + setCLIListener(new LineListener() { + public void lineRead(String line) { + logger.fatal(line); + } + }); + sendCLICommand(comamnd); + + /* Restore listener */ + setCLIListener(oldListener); + } + + public int getID() { + return getInterfaces().getMoteID().getMoteID(); + } + public boolean setConfigXML(Simulation simulation, Collection configXML, boolean visAvailable) { for (Element element: configXML) { String name = element.getName(); 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 e27078a65..a809dc6d2 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.30 2009/04/20 16:48:53 fros4943 Exp $ + * $Id: MspMoteType.java,v 1.31 2009/09/17 10:50:11 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -123,6 +123,7 @@ public abstract class MspMoteType implements MoteType { protected abstract MspMote createMote(Simulation simulation); public JPanel getTypeVisualizer() { + /* TODO Move to emulated layer */ JPanel panel = new JPanel(); JLabel label = new JLabel(); JPanel smallPane; @@ -255,11 +256,10 @@ public abstract class MspMoteType implements MoteType { } else if (name.equals("description")) { description = element.getText(); } else if (name.equals("source")) { - File file = new File(element.getText()); - if (!file.exists()) { - file = simulation.getGUI().restorePortablePath(file); + fileSource = new File(element.getText()); + if (!fileSource.exists()) { + fileSource = simulation.getGUI().restorePortablePath(fileSource); } - fileSource = file; } else if (name.equals("command")) { /* Backwards compatibility: command is now commands */ logger.warn("Old simulation config detected: old version only supports a single compile command"); @@ -267,11 +267,10 @@ public abstract class MspMoteType implements MoteType { } else if (name.equals("commands")) { compileCommands = element.getText(); } else if (name.equals("firmware")) { - File file = new File(element.getText()); - if (!file.exists()) { - file = simulation.getGUI().restorePortablePath(file); + fileFirmware = new File(element.getText()); + if (!fileFirmware.exists()) { + fileFirmware = simulation.getGUI().restorePortablePath(fileSource); } - fileFirmware = file; } else if (name.equals("elf")) { /* Backwards compatibility: elf is now firmware */ logger.warn("Old simulation config detected: firmware specified as elf"); @@ -300,8 +299,7 @@ public abstract class MspMoteType implements MoteType { } } - Class[] intfClasses = new Class[intfClassList.size()]; - intfClasses = intfClassList.toArray(intfClasses); + Class[] intfClasses = intfClassList.toArray(new Class[0]); if (intfClasses.length == 0) { /* Backwards compatibility: No interfaces specifed */ diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyCompileDialog.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyCompileDialog.java index ce5078f4e..ed7c15b24 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyCompileDialog.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyCompileDialog.java @@ -26,12 +26,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyCompileDialog.java,v 1.4 2009/08/27 12:25:12 nvt-se Exp $ + * $Id: SkyCompileDialog.java,v 1.5 2009/09/17 10:50:11 fros4943 Exp $ */ package se.sics.cooja.mspmote; + import java.awt.Container; import java.io.File; + import org.apache.log4j.Logger; import se.sics.cooja.GUI; @@ -77,6 +79,9 @@ public class SkyCompileDialog extends AbstractCompileDialog { } public boolean canLoadFirmware(File file) { + if (file.getName().endsWith(".sky")) { + return true; + } if (ELF.isELF(file)) { return true; } 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 36e9029b2..c913b7438 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,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMote.java,v 1.14 2009/04/20 16:12:01 fros4943 Exp $ + * $Id: SkyMote.java,v 1.15 2009/09/17 10:50:11 fros4943 Exp $ */ package se.sics.cooja.mspmote; import java.io.File; + import org.apache.log4j.Logger; -import se.sics.cooja.MoteInterfaceHandler; + import se.sics.cooja.Simulation; -import se.sics.cooja.interfaces.*; +import se.sics.cooja.interfaces.MoteID; import se.sics.mspsim.platform.sky.SkyNode; /** @@ -58,22 +59,13 @@ public class SkyMote extends MspMote { try { skyNode = new SkyNode(); prepareMote(fileELF, skyNode); - } catch (Exception e) { - logger.fatal("Error when creating Sky mote:", e); + logger.fatal("Error when creating Sky mote: ", e); return false; } return true; } - protected MoteInterfaceHandler createMoteInterfaceHandler() { - /* Uses current mote type configuration */ - MoteInterfaceHandler moteInterfaceHandler = - super.createMoteInterfaceHandler(); - - return moteInterfaceHandler; - } - public void idUpdated(int newID) { skyNode.setNodeID(newID); } 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 d96686529..022b25b2d 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,18 +26,30 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMoteType.java,v 1.10 2009/08/11 17:09:34 fros4943 Exp $ + * $Id: SkyMoteType.java,v 1.11 2009/09/17 10:50:11 fros4943 Exp $ */ package se.sics.cooja.mspmote; -import java.awt.*; +import java.awt.Container; +import java.awt.Image; +import java.awt.MediaTracker; +import java.awt.Toolkit; import java.io.File; import java.net.URL; -import javax.swing.*; + +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JOptionPane; import org.apache.log4j.Logger; -import se.sics.cooja.*; + +import se.sics.cooja.AbstractionLevelDescription; +import se.sics.cooja.ClassDescription; +import se.sics.cooja.GUI; +import se.sics.cooja.MoteInterface; +import se.sics.cooja.MoteType; +import se.sics.cooja.Simulation; import se.sics.cooja.dialogs.CompileContiki; import se.sics.cooja.dialogs.MessageList; import se.sics.cooja.dialogs.MessageList.MessageContainer; @@ -59,24 +71,6 @@ import se.sics.cooja.mspmote.interfaces.SkySerial; public class SkyMoteType extends MspMoteType { private static Logger logger = Logger.getLogger(SkyMoteType.class); - public Icon getMoteTypeIcon() { - Toolkit toolkit = Toolkit.getDefaultToolkit(); - URL imageURL = this.getClass().getClassLoader().getResource("images/sky.jpg"); - Image image = toolkit.getImage(imageURL); - MediaTracker tracker = new MediaTracker(GUI.getTopParentContainer()); - tracker.addImage(image, 1); - try { - tracker.waitForAll(); - } catch (InterruptedException ex) { - } - if (image.getHeight(GUI.getTopParentContainer()) > 0 && image.getWidth(GUI.getTopParentContainer()) > 0) { - image = image.getScaledInstance((200*image.getWidth(GUI.getTopParentContainer())/image.getHeight(GUI.getTopParentContainer())), 200, Image.SCALE_DEFAULT); - return new ImageIcon(image); - } - - return null; - } - protected MspMote createMote(Simulation simulation) { return new SkyMote(this, simulation); } @@ -189,6 +183,24 @@ public class SkyMoteType extends MspMoteType { return true; } + public Icon getMoteTypeIcon() { + Toolkit toolkit = Toolkit.getDefaultToolkit(); + URL imageURL = this.getClass().getClassLoader().getResource("images/sky.jpg"); + Image image = toolkit.getImage(imageURL); + MediaTracker tracker = new MediaTracker(GUI.getTopParentContainer()); + tracker.addImage(image, 1); + try { + tracker.waitForAll(); + } catch (InterruptedException ex) { + } + if (image.getHeight(GUI.getTopParentContainer()) > 0 && image.getWidth(GUI.getTopParentContainer()) > 0) { + image = image.getScaledInstance((200*image.getWidth(GUI.getTopParentContainer())/image.getHeight(GUI.getTopParentContainer())), 200, Image.SCALE_DEFAULT); + return new ImageIcon(image); + } + + return null; + } + public Class[] getAllMoteInterfaceClasses() { return new Class[] { Position.class,