From d26ba2606b1654a4429b77f5c6c33c45f3251fda Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 11 Mar 2009 17:46:59 +0000 Subject: [PATCH] added simulation config backwards compatibility for msp motes --- .../sics/cooja/mspmote/ESBCompileDialog.java | 29 +++------------ .../se/sics/cooja/mspmote/ESBMoteType.java | 31 +++++++++++++++- .../se/sics/cooja/mspmote/MspMoteType.java | 37 ++++++++++++++++--- .../sics/cooja/mspmote/SkyCompileDialog.java | 32 ++++------------ .../se/sics/cooja/mspmote/SkyMoteType.java | 33 ++++++++++++++++- 5 files changed, 106 insertions(+), 56 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBCompileDialog.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBCompileDialog.java index 8357ef7c6..9b82172b7 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBCompileDialog.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBCompileDialog.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBCompileDialog.java,v 1.2 2009/03/09 17:10:14 fros4943 Exp $ + * $Id: ESBCompileDialog.java,v 1.3 2009/03/11 17:46:59 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -34,18 +34,10 @@ import java.awt.Container; import java.io.File; import org.apache.log4j.Logger; +import se.sics.cooja.MoteInterface; import se.sics.cooja.MoteType; import se.sics.cooja.Simulation; import se.sics.cooja.dialogs.AbstractCompileDialog; -import se.sics.cooja.interfaces.Mote2MoteRelations; -import se.sics.cooja.interfaces.Position; -import se.sics.cooja.mspmote.interfaces.ESBButton; -import se.sics.cooja.mspmote.interfaces.ESBLED; -import se.sics.cooja.mspmote.interfaces.ESBLog; -import se.sics.cooja.mspmote.interfaces.MspClock; -import se.sics.cooja.mspmote.interfaces.MspIPAddress; -import se.sics.cooja.mspmote.interfaces.MspMoteID; -import se.sics.cooja.mspmote.interfaces.TR1001Radio; public class ESBCompileDialog extends AbstractCompileDialog { private static Logger logger = Logger.getLogger(ESBCompileDialog.class); @@ -77,15 +69,9 @@ public class ESBCompileDialog extends AbstractCompileDialog { selected = false; } - addMoteInterface(Position.class, selected); - addMoteInterface(MspIPAddress.class, selected); - addMoteInterface(ESBLog.class, selected); - addMoteInterface(MspClock.class, selected); - addMoteInterface(ESBLED.class, selected); - addMoteInterface(ESBButton.class, selected); - addMoteInterface(MspMoteID.class, selected); - addMoteInterface(TR1001Radio.class, selected); - addMoteInterface(Mote2MoteRelations.class, selected); + for (Class intfClass: ((ESBMoteType)moteType).getAllMoteInterfaceClasses()) { + addMoteInterface(intfClass, selected); + } } public boolean canLoadFirmware(File file) { @@ -103,10 +89,7 @@ public class ESBCompileDialog extends AbstractCompileDialog { } public File getExpectedFirmwareFile(File source) { - File parentDir = source.getParentFile(); - String sourceNoExtension = source.getName().substring(0, source.getName().length()-2); - - return new File(parentDir, sourceNoExtension + ".esb"); + return ((ESBMoteType)moteType).getExpectedFirmwareFile(source); } public void writeSettingsToMoteType() { 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 89ac35fb0..a7c4f1ad6 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,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBMoteType.java,v 1.7 2009/03/11 08:42:07 fros4943 Exp $ + * $Id: ESBMoteType.java,v 1.8 2009/03/11 17:46:59 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -41,6 +41,15 @@ import se.sics.cooja.*; import se.sics.cooja.dialogs.CompileContiki; import se.sics.cooja.dialogs.MessageList; import se.sics.cooja.dialogs.MessageList.MessageContainer; +import se.sics.cooja.interfaces.Mote2MoteRelations; +import se.sics.cooja.interfaces.Position; +import se.sics.cooja.mspmote.interfaces.ESBButton; +import se.sics.cooja.mspmote.interfaces.ESBLED; +import se.sics.cooja.mspmote.interfaces.ESBLog; +import se.sics.cooja.mspmote.interfaces.MspClock; +import se.sics.cooja.mspmote.interfaces.MspIPAddress; +import se.sics.cooja.mspmote.interfaces.MspMoteID; +import se.sics.cooja.mspmote.interfaces.TR1001Radio; @ClassDescription("ESB Mote Type") @AbstractionLevelDescription("Emulated level") @@ -184,4 +193,24 @@ public class ESBMoteType extends MspMoteType { return true; } + public Class[] getAllMoteInterfaceClasses() { + return new Class[] { + Position.class, + MspIPAddress.class, + ESBLog.class, + MspClock.class, + ESBLED.class, + ESBButton.class, + MspMoteID.class, + TR1001Radio.class, + Mote2MoteRelations.class + }; + } + + public File getExpectedFirmwareFile(File source) { + File parentDir = source.getParentFile(); + String sourceNoExtension = source.getName().substring(0, source.getName().length()-2); + + return new File(parentDir, sourceNoExtension + ".esb"); + } } 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 5e3689af4..b9f0628e4 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.27 2009/03/11 08:42:07 fros4943 Exp $ + * $Id: MspMoteType.java,v 1.28 2009/03/11 17:46:59 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -214,8 +214,8 @@ public abstract class MspMoteType implements MoteType { // Source file if (fileSource != null) { element = new Element("source"); - fileSource = GUI.stripAbsoluteContikiPath(fileSource); - element.setText(fileSource.getPath().replaceAll("\\\\", "/")); + File file = GUI.stripAbsoluteContikiPath(fileSource); + element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); element = new Element("commands"); element.setText(compileCommands); @@ -224,8 +224,8 @@ public abstract class MspMoteType implements MoteType { // Firmware file element = new Element("firmware"); - fileFirmware = GUI.stripAbsoluteContikiPath(fileFirmware); - element.setText(fileFirmware.getPath().replaceAll("\\\\", "/")); + File file = GUI.stripAbsoluteContikiPath(fileFirmware); + element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); // Mote interfaces @@ -251,12 +251,17 @@ public abstract class MspMoteType implements MoteType { description = element.getText(); } else if (name.equals("source")) { fileSource = new File(element.getText()); + } 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"); + compileCommands = element.getText(); } else if (name.equals("commands")) { compileCommands = element.getText(); } else if (name.equals("firmware")) { fileFirmware = new File(element.getText()); } else if (name.equals("elf")) { /* Backwards compatibility: elf is now firmware */ + logger.warn("Old simulation config detected: firmware specified as elf"); fileFirmware = new File(element.getText()); } else if (name.equals("moteinterface")) { Class moteInterfaceClass = @@ -275,9 +280,29 @@ public abstract class MspMoteType implements MoteType { } Class[] intfClasses = new Class[intfClassList.size()]; - intfClassList.toArray(intfClasses); + intfClasses = intfClassList.toArray(intfClasses); + + if (intfClasses.length == 0) { + /* Backwards compatibility: No interfaces specifed */ + logger.warn("Old simulation config detected: no mote interfaces specified, assuming all."); + intfClasses = getAllMoteInterfaceClasses(); + } setMoteInterfaceClasses(intfClasses); + if (fileFirmware == null) { + if (fileSource == null) { + throw new MoteTypeCreationException("Neither source or firmware specified"); + } + + /* Backwards compatibility: Generate expected firmware file name from source */ + logger.warn("Old simulation config detected: no firmware file specified, generating expected"); + fileFirmware = getExpectedFirmwareFile(fileSource); + } + return configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable); } + + public abstract Class[] getAllMoteInterfaceClasses(); + public abstract File getExpectedFirmwareFile(File source); + } 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 1eb7ac503..68b6d57c2 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,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyCompileDialog.java,v 1.1 2009/03/09 16:04:42 fros4943 Exp $ + * $Id: SkyCompileDialog.java,v 1.2 2009/03/11 17:46:59 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -34,19 +34,10 @@ import java.awt.Container; import java.io.File; import org.apache.log4j.Logger; +import se.sics.cooja.MoteInterface; import se.sics.cooja.MoteType; import se.sics.cooja.Simulation; import se.sics.cooja.dialogs.AbstractCompileDialog; -import se.sics.cooja.interfaces.Mote2MoteRelations; -import se.sics.cooja.interfaces.Position; -import se.sics.cooja.mspmote.interfaces.MspClock; -import se.sics.cooja.mspmote.interfaces.MspIPAddress; -import se.sics.cooja.mspmote.interfaces.MspMoteID; -import se.sics.cooja.mspmote.interfaces.SkyButton; -import se.sics.cooja.mspmote.interfaces.SkyByteRadio; -import se.sics.cooja.mspmote.interfaces.SkyFlash; -import se.sics.cooja.mspmote.interfaces.SkyLED; -import se.sics.cooja.mspmote.interfaces.SkySerial; public class SkyCompileDialog extends AbstractCompileDialog { private static Logger logger = Logger.getLogger(SkyCompileDialog.class); @@ -77,16 +68,10 @@ public class SkyCompileDialog extends AbstractCompileDialog { if (moteIntfBox.getComponentCount() > 0) { selected = false; } - addMoteInterface(Position.class, selected); - addMoteInterface(MspIPAddress.class, selected); - addMoteInterface(Mote2MoteRelations.class, selected); - addMoteInterface(MspClock.class, selected); - addMoteInterface(MspMoteID.class, selected); - addMoteInterface(SkyButton.class, selected); - addMoteInterface(SkyFlash.class, selected); - addMoteInterface(SkyByteRadio.class, selected); - addMoteInterface(SkySerial.class, selected); - addMoteInterface(SkyLED.class, selected); + + for (Class intfClass: ((SkyMoteType)moteType).getAllMoteInterfaceClasses()) { + addMoteInterface(intfClass, selected); + } } public boolean canLoadFirmware(File file) { @@ -104,10 +89,7 @@ public class SkyCompileDialog extends AbstractCompileDialog { } public File getExpectedFirmwareFile(File source) { - File parentDir = source.getParentFile(); - String sourceNoExtension = source.getName().substring(0, source.getName().length()-2); - - return new File(parentDir, sourceNoExtension + ".sky"); + return ((SkyMoteType)moteType).getExpectedFirmwareFile(source); } public void writeSettingsToMoteType() { 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 9a8293f38..93e97e316 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,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMoteType.java,v 1.6 2009/03/11 08:42:07 fros4943 Exp $ + * $Id: SkyMoteType.java,v 1.7 2009/03/11 17:46:59 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -41,6 +41,16 @@ import se.sics.cooja.*; import se.sics.cooja.dialogs.CompileContiki; import se.sics.cooja.dialogs.MessageList; import se.sics.cooja.dialogs.MessageList.MessageContainer; +import se.sics.cooja.interfaces.Mote2MoteRelations; +import se.sics.cooja.interfaces.Position; +import se.sics.cooja.mspmote.interfaces.MspClock; +import se.sics.cooja.mspmote.interfaces.MspIPAddress; +import se.sics.cooja.mspmote.interfaces.MspMoteID; +import se.sics.cooja.mspmote.interfaces.SkyButton; +import se.sics.cooja.mspmote.interfaces.SkyByteRadio; +import se.sics.cooja.mspmote.interfaces.SkyFlash; +import se.sics.cooja.mspmote.interfaces.SkyLED; +import se.sics.cooja.mspmote.interfaces.SkySerial; @ClassDescription("Sky Mote Type") @AbstractionLevelDescription("Emulated level") @@ -184,4 +194,25 @@ public class SkyMoteType extends MspMoteType { return true; } + public Class[] getAllMoteInterfaceClasses() { + return new Class[] { + Position.class, + MspIPAddress.class, + Mote2MoteRelations.class, + MspClock.class, + MspMoteID.class, + SkyButton.class, + SkyFlash.class, + SkyByteRadio.class, + SkySerial.class, + SkyLED.class + }; + } + + public File getExpectedFirmwareFile(File source) { + File parentDir = source.getParentFile(); + String sourceNoExtension = source.getName().substring(0, source.getName().length()-2); + + return new File(parentDir, sourceNoExtension + ".sky"); + } }