minor changes: removing some unused code, restructuring, added getID() methods

This commit is contained in:
fros4943 2009-09-17 10:50:11 +00:00
parent 969154c6f0
commit eb4698612d
6 changed files with 90 additions and 96 deletions

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.mspmote;
@ -66,14 +66,6 @@ public class ESBMote extends MspMote {
return true; return true;
} }
protected MoteInterfaceHandler createMoteInterfaceHandler() {
/* Uses current mote type configuration */
MoteInterfaceHandler moteInterfaceHandler =
super.createMoteInterfaceHandler();
return moteInterfaceHandler;
}
public String toString() { public String toString() {
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null; MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
if (moteID != null) { if (moteID != null) {

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.mspmote;
@ -39,18 +39,19 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Observable; import java.util.Observable;
import java.util.Observer;
import java.util.Vector; import java.util.Vector;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.GUI; import se.sics.cooja.GUI;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface; import se.sics.cooja.MoteInterface;
import se.sics.cooja.MoteInterfaceHandler; import se.sics.cooja.MoteInterfaceHandler;
import se.sics.cooja.MoteMemory; import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteType; import se.sics.cooja.MoteType;
import se.sics.cooja.Watchpoint;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.Watchpoint;
import se.sics.cooja.WatchpointMote; import se.sics.cooja.WatchpointMote;
import se.sics.cooja.interfaces.IPAddress; import se.sics.cooja.interfaces.IPAddress;
import se.sics.cooja.mspmote.interfaces.TR1001Radio; import se.sics.cooja.mspmote.interfaces.TR1001Radio;
@ -89,8 +90,6 @@ public abstract class MspMote implements Mote, WatchpointMote {
private MoteInterfaceHandler myMoteInterfaceHandler = null; private MoteInterfaceHandler myMoteInterfaceHandler = null;
private ELF myELFModule = null; private ELF myELFModule = null;
protected TR1001Radio myRadio = null; /* TODO Only used by ESB (TR1001) */
/* Stack monitoring variables */ /* Stack monitoring variables */
private boolean stopNextInstruction = false; private boolean stopNextInstruction = false;
private boolean monitorStackUsage = false; private boolean monitorStackUsage = false;
@ -99,14 +98,6 @@ public abstract class MspMote implements Mote, WatchpointMote {
private StackOverflowObservable stackOverflowObservable = new StackOverflowObservable(); private StackOverflowObservable stackOverflowObservable = new StackOverflowObservable();
private MspBreakpointContainer breakpointsContainer; private MspBreakpointContainer breakpointsContainer;
/**
* Abort current tick immediately.
* May for example be called by a breakpoint handler.
*/
public void stopNextInstruction() {
stopNextInstruction = true;
}
public MspMote() { public MspMote() {
myMoteType = null; myMoteType = null;
@ -120,7 +111,7 @@ public abstract class MspMote implements Mote, WatchpointMote {
myMoteType = moteType; myMoteType = moteType;
mySimulation = simulation; mySimulation = simulation;
} }
protected void initMote() { protected void initMote() {
if (myMoteType != null) { if (myMoteType != null) {
initEmulator(myMoteType.getContikiFirmwareFile()); 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() { protected MoteInterfaceHandler createMoteInterfaceHandler() {
return new MoteInterfaceHandler(this, getType().getMoteInterfaceClasses()); return new MoteInterfaceHandler(this, getType().getMoteInterfaceClasses());
} }
@ -267,14 +266,6 @@ public abstract class MspMote implements Mote, WatchpointMote {
myCpu.reset(); 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 */ /* called when moteID is updated */
public void idUpdated(int newID) { public void idUpdated(int newID) {
} }
@ -287,12 +278,6 @@ public abstract class MspMote implements Mote, WatchpointMote {
myMoteType = (MspMoteType) type; myMoteType = (MspMoteType) type;
} }
public void addStateObserver(Observer newObserver) {
}
public void deleteStateObserver(Observer newObserver) {
}
public MoteInterfaceHandler getInterfaces() { public MoteInterfaceHandler getInterfaces() {
return myMoteInterfaceHandler; return myMoteInterfaceHandler;
} }
@ -315,6 +300,7 @@ public abstract class MspMote implements Mote, WatchpointMote {
public boolean tick(long simTime) { public boolean tick(long simTime) {
if (stopNextInstruction) { if (stopNextInstruction) {
stopNextInstruction = false; stopNextInstruction = false;
sendCLICommandAndPrint("trace 1000");
throw new RuntimeException("MSPSim requested simulation stop"); throw new RuntimeException("MSPSim requested simulation stop");
} }
@ -348,18 +334,7 @@ public abstract class MspMote implements Mote, WatchpointMote {
} catch (EmulationException e) { } catch (EmulationException e) {
if (e.getMessage().startsWith("Bad operation")) { if (e.getMessage().startsWith("Bad operation")) {
/* Experimental: print program counter history */ /* Experimental: print program counter history */
LineListener oldListener = commandListener; sendCLICommandAndPrint("trace 1000");
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);
} }
throw (RuntimeException) throw (RuntimeException)
@ -383,6 +358,26 @@ public abstract class MspMote implements Mote, WatchpointMote {
return true; 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<Element> configXML, boolean visAvailable) { public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
for (Element element: configXML) { for (Element element: configXML) {
String name = element.getName(); String name = element.getName();

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.mspmote;
@ -123,6 +123,7 @@ public abstract class MspMoteType implements MoteType {
protected abstract MspMote createMote(Simulation simulation); protected abstract MspMote createMote(Simulation simulation);
public JPanel getTypeVisualizer() { public JPanel getTypeVisualizer() {
/* TODO Move to emulated layer */
JPanel panel = new JPanel(); JPanel panel = new JPanel();
JLabel label = new JLabel(); JLabel label = new JLabel();
JPanel smallPane; JPanel smallPane;
@ -255,11 +256,10 @@ public abstract class MspMoteType implements MoteType {
} else if (name.equals("description")) { } else if (name.equals("description")) {
description = element.getText(); description = element.getText();
} else if (name.equals("source")) { } else if (name.equals("source")) {
File file = new File(element.getText()); fileSource = new File(element.getText());
if (!file.exists()) { if (!fileSource.exists()) {
file = simulation.getGUI().restorePortablePath(file); fileSource = simulation.getGUI().restorePortablePath(fileSource);
} }
fileSource = file;
} else if (name.equals("command")) { } else if (name.equals("command")) {
/* Backwards compatibility: command is now commands */ /* Backwards compatibility: command is now commands */
logger.warn("Old simulation config detected: old version only supports a single compile command"); 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")) { } else if (name.equals("commands")) {
compileCommands = element.getText(); compileCommands = element.getText();
} else if (name.equals("firmware")) { } else if (name.equals("firmware")) {
File file = new File(element.getText()); fileFirmware = new File(element.getText());
if (!file.exists()) { if (!fileFirmware.exists()) {
file = simulation.getGUI().restorePortablePath(file); fileFirmware = simulation.getGUI().restorePortablePath(fileSource);
} }
fileFirmware = file;
} else if (name.equals("elf")) { } else if (name.equals("elf")) {
/* Backwards compatibility: elf is now firmware */ /* Backwards compatibility: elf is now firmware */
logger.warn("Old simulation config detected: firmware specified as elf"); logger.warn("Old simulation config detected: firmware specified as elf");
@ -300,8 +299,7 @@ public abstract class MspMoteType implements MoteType {
} }
} }
Class<? extends MoteInterface>[] intfClasses = new Class[intfClassList.size()]; Class<? extends MoteInterface>[] intfClasses = intfClassList.toArray(new Class[0]);
intfClasses = intfClassList.toArray(intfClasses);
if (intfClasses.length == 0) { if (intfClasses.length == 0) {
/* Backwards compatibility: No interfaces specifed */ /* Backwards compatibility: No interfaces specifed */

View File

@ -26,12 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.mspmote;
import java.awt.Container; import java.awt.Container;
import java.io.File; import java.io.File;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.GUI; import se.sics.cooja.GUI;
@ -77,6 +79,9 @@ public class SkyCompileDialog extends AbstractCompileDialog {
} }
public boolean canLoadFirmware(File file) { public boolean canLoadFirmware(File file) {
if (file.getName().endsWith(".sky")) {
return true;
}
if (ELF.isELF(file)) { if (ELF.isELF(file)) {
return true; return true;
} }

View File

@ -26,16 +26,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.mspmote;
import java.io.File; import java.io.File;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.MoteInterfaceHandler;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.*; import se.sics.cooja.interfaces.MoteID;
import se.sics.mspsim.platform.sky.SkyNode; import se.sics.mspsim.platform.sky.SkyNode;
/** /**
@ -58,22 +59,13 @@ public class SkyMote extends MspMote {
try { try {
skyNode = new SkyNode(); skyNode = new SkyNode();
prepareMote(fileELF, skyNode); prepareMote(fileELF, skyNode);
} catch (Exception e) { } catch (Exception e) {
logger.fatal("Error when creating Sky mote:", e); logger.fatal("Error when creating Sky mote: ", e);
return false; return false;
} }
return true; return true;
} }
protected MoteInterfaceHandler createMoteInterfaceHandler() {
/* Uses current mote type configuration */
MoteInterfaceHandler moteInterfaceHandler =
super.createMoteInterfaceHandler();
return moteInterfaceHandler;
}
public void idUpdated(int newID) { public void idUpdated(int newID) {
skyNode.setNodeID(newID); skyNode.setNodeID(newID);
} }

View File

@ -26,18 +26,30 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; 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.io.File;
import java.net.URL; 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 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.CompileContiki;
import se.sics.cooja.dialogs.MessageList; import se.sics.cooja.dialogs.MessageList;
import se.sics.cooja.dialogs.MessageList.MessageContainer; import se.sics.cooja.dialogs.MessageList.MessageContainer;
@ -59,24 +71,6 @@ import se.sics.cooja.mspmote.interfaces.SkySerial;
public class SkyMoteType extends MspMoteType { public class SkyMoteType extends MspMoteType {
private static Logger logger = Logger.getLogger(SkyMoteType.class); 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) { protected MspMote createMote(Simulation simulation) {
return new SkyMote(this, simulation); return new SkyMote(this, simulation);
} }
@ -189,6 +183,24 @@ public class SkyMoteType extends MspMoteType {
return true; 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<? extends MoteInterface>[] getAllMoteInterfaceClasses() { public Class<? extends MoteInterface>[] getAllMoteInterfaceClasses() {
return new Class[] { return new Class[] {
Position.class, Position.class,