documentation (including javadoc) update

This commit is contained in:
fros4943 2007-01-10 14:57:42 +00:00
parent b2516a09ef
commit 0c98ce0651
18 changed files with 807 additions and 724 deletions

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: ConnectionLogger.java,v 1.3 2006/12/15 12:03:32 fros4943 Exp $ * $Id: ConnectionLogger.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -42,24 +40,27 @@ import se.sics.cooja.interfaces.Position;
* connections given via the method logConnection will be written to either * connections given via the method logConnection will be written to either
* default Log4J info stream, a log file or both. * default Log4J info stream, a log file or both.
* *
* Log files have the following structure (spaces are tabs): SRC_POS [src_x] * Log files have the following structure (seprated by tabs): SRC_POS [src_x]
* [src_y] [src_z] SRC_DATA [sent data bytes] DEST_POS [dest_x] [dest_y] * [src_y] [src_z] SRC_DATA [sent data bytes] DEST_POS [dest_x] [dest_y]
* [dest_z] DEST_DATA [received data bytes] [newline] * [dest_z] DEST_DATA [received data bytes] [newline]
* *
* @see RadioConnection * @see RadioConnection
* @see RadioMedium * @see RadioMedium
*
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public class ConnectionLogger { public class ConnectionLogger {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(ConnectionLogger.class); private static Logger logger = Logger.getLogger(ConnectionLogger.class);
private static int LOG_TO_FILE = 1; private static int LOG_TO_FILE = 1;
private static int LOG_TO_LOG4J = 2; private static int LOG_TO_LOG4J = 2;
private static int LOG_TO_FILE_AND_LOG4J = 3; private static int LOG_TO_FILE_AND_LOG4J = 3;
private int myType; private int myType;
private File myFile; private File myFile;
/** /**
@ -123,7 +124,8 @@ public class ConnectionLogger {
out.write("SRC_DATA\t".getBytes()); out.write("SRC_DATA\t".getBytes());
for (byte b : conn.getSourceData()) { for (byte b : conn.getSourceData()) {
String hexString = Integer.toHexString((int) b); String hexString = Integer.toHexString((int) b);
if (hexString.length() == 1) hexString = "0" + hexString; if (hexString.length() == 1)
hexString = "0" + hexString;
out.write(hexString.getBytes()); out.write(hexString.getBytes());
} }
out.write("\t".getBytes()); out.write("\t".getBytes());
@ -142,9 +144,11 @@ public class ConnectionLogger {
out.write("DEST_DATA\t".getBytes()); out.write("DEST_DATA\t".getBytes());
for (byte b : conn.getDestinationData()[i]) { for (byte b : conn.getDestinationData()[i]) {
String hexString = Integer.toHexString((int) b); String hexString = Integer.toHexString((int) b);
if (hexString.length() == 1) hexString = "0" + hexString; if (hexString.length() == 1)
hexString = "0" + hexString;
out.write(hexString.getBytes()); out.write(hexString.getBytes());
} out.write("\t".getBytes()); }
out.write("\t".getBytes());
out.write("\n".getBytes()); out.write("\n".getBytes());
} }
@ -164,7 +168,8 @@ public class ConnectionLogger {
out.write("SRC_DATA\t".getBytes()); out.write("SRC_DATA\t".getBytes());
for (byte b : conn.getSourceData()) { for (byte b : conn.getSourceData()) {
String hexString = Integer.toHexString((int) b); String hexString = Integer.toHexString((int) b);
if (hexString.length() == 1) hexString = "0" + hexString; if (hexString.length() == 1)
hexString = "0" + hexString;
out.write(hexString.getBytes()); out.write(hexString.getBytes());
} }
out.write("\n".getBytes()); out.write("\n".getBytes());

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: CoreComm.java,v 1.2 2006/08/23 17:11:09 fros4943 Exp $ * $Id: CoreComm.java,v 1.3 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -35,19 +33,19 @@ import java.io.File;
import se.sics.cooja.corecomm.*; import se.sics.cooja.corecomm.*;
/** /**
* The package corecomm's purpose is communicating with the simulation core * The purpose of corecomm's is communicating with a compiled Contiki system
* using Java Native Interface (JNI). Each implementing class (named * using Java Native Interface (JNI). Each implemented class (named Lib[1-MAX]),
* Lib[1-MAX]), loads a shared library which belongs to one mote type. The * loads a shared library which belongs to one mote type. The reason for this
* reason for this somewhat strange design is that once loaded, a native library * somewhat strange design is that once loaded, a native library cannot be
* cannot be unloaded in Java (yet). Therefore if we wish to load several * unloaded in Java (in the current versions available). Therefore if we wish to
* libraries, the names and associated native functions must have unique names. * load several libraries, the names and associated native functions must have
* And those names are defined via the calling class in JNI. For example, the * unique names. And those names are defined via the calling class in JNI. For
* native tick function in class Lib1 is named * example, the corresponding function for a native tick method in class Lib1
* contiki_javasim_corecomm_Lib1_tick. When creating a new mote type, the main * will be named Java_se_sics_cooja_corecomm_Lib1_tick. When creating a new mote
* contiki source file is generated with function names compatible with the next * type, the main Contiki source file is generated with function names
* available corecomm. This also implies that even if a mote type is deleted, a * compatible with the next available corecomm class. This also implies that
* new one cannot be created without restarting the JVM and thus the entire * even if a mote type is deleted, a new one cannot be created using the same
* simulation. * corecomm class without restarting the JVM and thus the entire simulation.
* *
* Each implemented CoreComm class needs read access to the following core * Each implemented CoreComm class needs read access to the following core
* variables: * variables:
@ -56,23 +54,23 @@ import se.sics.cooja.corecomm.*;
* </ul> * </ul>
* and the following native functions: * and the following native functions:
* <ul> * <ul>
* <li>init()
* <li>tick() * <li>tick()
* <li>init()
* <li>getReferenceAbsAddr() * <li>getReferenceAbsAddr()
* <li>getMemory(int start, int length) * <li>getMemory(int start, int length, byte[] mem)
* <li>setMemory(int start, int length, byte[] mem) * <li>setMemory(int start, int length, byte[] mem)
* </ul>
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public abstract class CoreComm { public abstract class CoreComm {
/** /**
* Maximum supported core communicators in a simulation. * Maximum supported core communicators in a simulator.
*/ */
private final static int MAX_LIBRARIES = 8; private final static int MAX_LIBRARIES = 8;
// Static pointers to current libraries // Static pointers to current libraries
private final static CoreComm[] coreComms = new CoreComm[MAX_LIBRARIES]; private final static CoreComm[] coreComms = new CoreComm[MAX_LIBRARIES];
private final static File[] coreCommFiles = new File[MAX_LIBRARIES]; private final static File[] coreCommFiles = new File[MAX_LIBRARIES];
/** /**
@ -195,7 +193,7 @@ public abstract class CoreComm {
public abstract void tick(); public abstract void tick();
/** /**
* Initializes a mote by running a startup script in the core. (Should only by * Initializes a mote by running a startup script in the core. (Should only be
* run once, at the same time as the library is loaded) * run once, at the same time as the library is loaded)
*/ */
protected abstract void init(); protected abstract void init();

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: GUI.java,v 1.14 2007/01/10 09:03:02 fros4943 Exp $ * $Id: GUI.java,v 1.15 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -39,7 +37,6 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.MenuEvent; import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener; import javax.swing.event.MenuListener;
@ -58,7 +55,13 @@ import se.sics.cooja.dialogs.*;
import se.sics.cooja.plugins.*; import se.sics.cooja.plugins.*;
/** /**
* Main file of COOJA Simulator. * Main file of COOJA Simulator. Typically contains a visualizer for the
* simulator, but can also be started without visualizer.
*
* This class loads external Java classes (in user platforms), and handles the
* COOJA plugins as well as the configuration system. If provides a number of
* help methods for the rest of the COOJA system, and is the starting point for
* loading and saving simulation configs.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ -118,36 +121,44 @@ public class GUI {
}; };
/** /**
* Main frame for current GUI. * Main frame for current GUI. Null when COOJA is run without visualizer!
* Null when COOJA is run without GUI!
*/ */
public static JFrame frame; public static JFrame frame;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(GUI.class); private static Logger logger = Logger.getLogger(GUI.class);
// External tools setting names // External tools setting names
private static Properties currentExternalToolsSettings; private static Properties currentExternalToolsSettings;
private static final String externalToolsSettingNames[] = new String[]{
private static final String externalToolsSettingNames[] = new String[] {
"PATH_CONTIKI", "PATH_COOJA_CORE_RELATIVE", "PATH_MAKE", "PATH_SHELL", "PATH_CONTIKI", "PATH_COOJA_CORE_RELATIVE", "PATH_MAKE", "PATH_SHELL",
"PATH_C_COMPILER", "COMPILER_ARGS", "PATH_LINKER", "PATH_NM", "NM_ARGS", "PATH_C_COMPILER", "COMPILER_ARGS", "PATH_LINKER", "PATH_NM", "NM_ARGS",
"PATH_OBJDUMP", "OBJDUMP_ARGS", "LINKER_ARGS_1", "PATH_OBJDUMP", "OBJDUMP_ARGS", "LINKER_ARGS_1", "LINKER_ARGS_2",
"LINKER_ARGS_2", "CONTIKI_STANDARD_PROCESSES", "CMD_GREP_PROCESSES", "CONTIKI_STANDARD_PROCESSES", "CMD_GREP_PROCESSES",
"REGEXP_PARSE_PROCESSES", "CMD_GREP_INTERFACES", "REGEXP_PARSE_PROCESSES", "CMD_GREP_INTERFACES",
"REGEXP_PARSE_INTERFACES", "CMD_GREP_SENSORS", "REGEXP_PARSE_SENSORS", "REGEXP_PARSE_INTERFACES", "CMD_GREP_SENSORS", "REGEXP_PARSE_SENSORS",
"CONTIKI_MAIN_TEMPLATE_FILENAME", "DEFAULT_USERPLATFORMS"}; "CONTIKI_MAIN_TEMPLATE_FILENAME", "DEFAULT_USERPLATFORMS" };
private static final int FRAME_NEW_OFFSET = 30; private static final int FRAME_NEW_OFFSET = 30;
private static final int FRAME_STANDARD_WIDTH = 150; private static final int FRAME_STANDARD_WIDTH = 150;
private static final int FRAME_STANDARD_HEIGHT = 300; private static final int FRAME_STANDARD_HEIGHT = 300;
private GUI myGUI; private GUI myGUI;
private Simulation mySimulation; private Simulation mySimulation;
protected Mote selectedMote = null; protected Mote selectedMote = null;
protected GUIEventHandler guiEventHandler = new GUIEventHandler(); protected GUIEventHandler guiEventHandler = new GUIEventHandler();
private JMenu menuPlugins, menuMoteTypeClasses, menuMoteTypes; private JMenu menuPlugins, menuMoteTypeClasses, menuMoteTypes;
private JPopupMenu menuMotePlugins; private JPopupMenu menuMotePlugins;
private JDesktopPane myDesktopPane; private JDesktopPane myDesktopPane;
private Vector<Plugin> startedPlugins = new Vector<Plugin>(); private Vector<Plugin> startedPlugins = new Vector<Plugin>();
@ -155,14 +166,21 @@ public class GUI {
// Platform configuration variables // Platform configuration variables
// Maintained via method reparsePlatformConfig() // Maintained via method reparsePlatformConfig()
private PlatformConfig platformConfig; private PlatformConfig platformConfig;
private Vector<File> currentUserPlatforms = new Vector<File>(); private Vector<File> currentUserPlatforms = new Vector<File>();
private ClassLoader userPlatformClassLoader; private ClassLoader userPlatformClassLoader;
private Vector<Class<? extends MoteType>> moteTypeClasses = new Vector<Class<? extends MoteType>>(); private Vector<Class<? extends MoteType>> moteTypeClasses = new Vector<Class<? extends MoteType>>();
private Vector<Class<? extends Plugin>> pluginClasses = new Vector<Class<? extends Plugin>>(); private Vector<Class<? extends Plugin>> pluginClasses = new Vector<Class<? extends Plugin>>();
private Vector<Class<? extends Plugin>> pluginClassesTemporary = new Vector<Class<? extends Plugin>>(); private Vector<Class<? extends Plugin>> pluginClassesTemporary = new Vector<Class<? extends Plugin>>();
private Vector<Class<? extends RadioMedium>> radioMediumClasses = new Vector<Class<? extends RadioMedium>>(); private Vector<Class<? extends RadioMedium>> radioMediumClasses = new Vector<Class<? extends RadioMedium>>();
private Vector<Class<? extends IPDistributor>> ipDistributorClasses = new Vector<Class<? extends IPDistributor>>(); private Vector<Class<? extends IPDistributor>> ipDistributorClasses = new Vector<Class<? extends IPDistributor>>();
private Vector<Class<? extends Positioner>> positionerClasses = new Vector<Class<? extends Positioner>>(); private Vector<Class<? extends Positioner>> positionerClasses = new Vector<Class<? extends Positioner>>();
/** /**
@ -178,17 +196,17 @@ public class GUI {
frame.setJMenuBar(createMenuBar()); frame.setJMenuBar(createMenuBar());
} }
// Load default and overwrite with user settings (if any) // Load default and overwrite with user settings (if any)
loadExternalToolsDefaultSettings(); loadExternalToolsDefaultSettings();
loadExternalToolsUserSettings(); loadExternalToolsUserSettings();
// Register default user platforms // Register default user platforms
String defaultUserPlatforms = getExternalToolsSetting("DEFAULT_USERPLATFORMS", null); String defaultUserPlatforms = getExternalToolsSetting(
"DEFAULT_USERPLATFORMS", null);
if (defaultUserPlatforms != null) { if (defaultUserPlatforms != null) {
String[] defaultUserPlatformsArr = defaultUserPlatforms.split(";"); String[] defaultUserPlatformsArr = defaultUserPlatforms.split(";");
if (defaultUserPlatformsArr.length > 0) { if (defaultUserPlatformsArr.length > 0) {
for (String defaultUserPlatform: defaultUserPlatformsArr) { for (String defaultUserPlatform : defaultUserPlatformsArr) {
File userPlatform = new File(defaultUserPlatform); File userPlatform = new File(defaultUserPlatform);
if (userPlatform.exists() && userPlatform.isDirectory()) { if (userPlatform.exists() && userPlatform.isDirectory()) {
currentUserPlatforms.add(userPlatform); currentUserPlatforms.add(userPlatform);
@ -200,10 +218,9 @@ public class GUI {
// Load extendable parts (using current platform config) // Load extendable parts (using current platform config)
reparsePlatformConfig(); reparsePlatformConfig();
// EXPERIMENTAL: Start all standard GUI plugins // Start all standard GUI plugins
for (Class<? extends Plugin> visPluginClass : pluginClasses) { for (Class<? extends Plugin> visPluginClass : pluginClasses) {
int pluginType = visPluginClass.getAnnotation(PluginType.class) int pluginType = visPluginClass.getAnnotation(PluginType.class).value();
.value();
if (pluginType == PluginType.COOJA_STANDARD_PLUGIN) { if (pluginType == PluginType.COOJA_STANDARD_PLUGIN) {
startPlugin(visPluginClass, this, null, null); startPlugin(visPluginClass, this, null, null);
} }
@ -321,8 +338,10 @@ public class GUI {
menuMoteTypeClasses.add(menuItem); menuMoteTypeClasses.add(menuItem);
} }
} }
public void menuDeselected(MenuEvent e) { public void menuDeselected(MenuEvent e) {
} }
public void menuCanceled(MenuEvent e) { public void menuCanceled(MenuEvent e) {
} }
}); });
@ -364,8 +383,10 @@ public class GUI {
menuMoteTypes.add(menuItem); menuMoteTypes.add(menuItem);
} }
} }
public void menuDeselected(MenuEvent e) { public void menuDeselected(MenuEvent e) {
} }
public void menuCanceled(MenuEvent e) { public void menuCanceled(MenuEvent e) {
} }
}); });
@ -421,7 +442,6 @@ public class GUI {
frame.setSize(700, 700); frame.setSize(700, 700);
frame.addWindowListener(gui.guiEventHandler); frame.addWindowListener(gui.guiEventHandler);
// Display the window. // Display the window.
frame.setVisible(true); frame.setVisible(true);
} }
@ -502,7 +522,7 @@ public class GUI {
userPlatforms.add("."); userPlatforms.add(".");
} }
//XXX Should add user prop platforms as well here... // XXX Should add user prop platforms as well here...
logger.info("> Reparsing user platforms and creating config"); logger.info("> Reparsing user platforms and creating config");
for (String userPlatform : userPlatforms) { for (String userPlatform : userPlatforms) {
logger.info(">> Adding: " + userPlatform); logger.info(">> Adding: " + userPlatform);
@ -521,12 +541,12 @@ public class GUI {
File contikiBaseDir = new File(getExternalToolsSetting("PATH_CONTIKI")); File contikiBaseDir = new File(getExternalToolsSetting("PATH_CONTIKI"));
File contikiCoreDir = new File(contikiBaseDir, File contikiCoreDir = new File(contikiBaseDir,
getExternalToolsSetting("PATH_COOJA_CORE_RELATIVE")); getExternalToolsSetting("PATH_COOJA_CORE_RELATIVE"));
File libFile = new File(ContikiMoteType.tempOutputDirectory, File libFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID
moteTypeID + ContikiMoteType.librarySuffix); + ContikiMoteType.librarySuffix);
File mapFile = new File(ContikiMoteType.tempOutputDirectory, File mapFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID
moteTypeID + ContikiMoteType.mapSuffix); + ContikiMoteType.mapSuffix);
File depFile = new File(ContikiMoteType.tempOutputDirectory, File depFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID
moteTypeID + ContikiMoteType.dependSuffix); + ContikiMoteType.dependSuffix);
if (libFile.exists()) if (libFile.exists())
libFile.delete(); libFile.delete();
if (depFile.exists()) if (depFile.exists())
@ -773,7 +793,8 @@ public class GUI {
Class<? extends RadioMedium> radioMediumClass = gui.tryLoadClass(gui, Class<? extends RadioMedium> radioMediumClass = gui.tryLoadClass(gui,
RadioMedium.class, radioMediumClassName); RadioMedium.class, radioMediumClassName);
RadioMedium radioMedium = RadioMedium.generateRadioMedium(radioMediumClass, simulation); RadioMedium radioMedium = RadioMedium.generateRadioMedium(
radioMediumClass, simulation);
simulation.setRadioMedium(radioMedium); simulation.setRadioMedium(radioMedium);
} catch (Exception e) { } catch (Exception e) {
logger.fatal(">> Failed to load radio medium, aborting: " logger.fatal(">> Failed to load radio medium, aborting: "
@ -870,7 +891,7 @@ public class GUI {
Class<? extends IPDistributor> ipDistributorClass) { Class<? extends IPDistributor> ipDistributorClass) {
// Check that vector constructor exists // Check that vector constructor exists
try { try {
ipDistributorClass.getConstructor(new Class[]{Vector.class}); ipDistributorClass.getConstructor(new Class[] { Vector.class });
} catch (Exception e) { } catch (Exception e) {
logger.fatal("No vector constructor found of IP distributor: " logger.fatal("No vector constructor found of IP distributor: "
+ ipDistributorClass); + ipDistributorClass);
@ -906,8 +927,8 @@ public class GUI {
// Check that interval constructor exists // Check that interval constructor exists
try { try {
positionerClass positionerClass
.getConstructor(new Class[]{int.class, double.class, double.class, .getConstructor(new Class[] { int.class, double.class, double.class,
double.class, double.class, double.class, double.class}); double.class, double.class, double.class, double.class });
} catch (Exception e) { } catch (Exception e) {
logger.fatal("No interval constructor found of positioner: " logger.fatal("No interval constructor found of positioner: "
+ positionerClass); + positionerClass);
@ -943,8 +964,7 @@ public class GUI {
Class<? extends RadioMedium> radioMediumClass) { Class<? extends RadioMedium> radioMediumClass) {
// Check that simulation constructor exists // Check that simulation constructor exists
try { try {
radioMediumClass radioMediumClass.getConstructor(new Class[] { Simulation.class });
.getConstructor(new Class[]{Simulation.class});
} catch (Exception e) { } catch (Exception e) {
logger.fatal("No simulation constructor found of radio medium: " logger.fatal("No simulation constructor found of radio medium: "
+ radioMediumClass); + radioMediumClass);
@ -1012,15 +1032,15 @@ public class GUI {
try { try {
// Append config to general config // Append config to general config
// logger.info("Appending user platform configuration: " + userPlatform); // logger.info("Appending user platform configuration: " +
// userPlatform);
platformConfig.appendUserPlatform(userPlatform); platformConfig.appendUserPlatform(userPlatform);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
logger.fatal("Could not find platform config file: " logger.fatal("Could not find platform config file: " + userPlatform);
+ userPlatform);
return false; return false;
} catch (IOException e) { } catch (IOException e) {
logger.fatal("Error when reading platform config file: " logger
+ userPlatform); .fatal("Error when reading platform config file: " + userPlatform);
return false; return false;
} }
} }
@ -1053,8 +1073,8 @@ public class GUI {
"PLUGINS"); "PLUGINS");
if (pluginClassNames != null) { if (pluginClassNames != null) {
for (String pluginClassName : pluginClassNames) { for (String pluginClassName : pluginClassNames) {
Class<? extends Plugin> pluginClass = tryLoadClass(this, Class<? extends Plugin> pluginClass = tryLoadClass(this, Plugin.class,
Plugin.class, pluginClassName); pluginClassName);
if (pluginClass != null) { if (pluginClass != null) {
registerPlugin(pluginClass); registerPlugin(pluginClass);
@ -1178,7 +1198,7 @@ public class GUI {
// Deselect all other plugins before selecting the new one // Deselect all other plugins before selecting the new one
try { try {
for (JInternalFrame existingPlugin: myDesktopPane.getAllFrames()) { for (JInternalFrame existingPlugin : myDesktopPane.getAllFrames()) {
existingPlugin.setSelected(false); existingPlugin.setSelected(false);
} }
plugin.setSelected(true); plugin.setSelected(true);
@ -1212,7 +1232,7 @@ public class GUI {
if (askUser && startedPlugins.isEmpty()) { if (askUser && startedPlugins.isEmpty()) {
String s1 = "Remove"; String s1 = "Remove";
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = {s1, s2}; Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(frame, int n = JOptionPane.showOptionDialog(frame,
"You have an active simulation.\nDo you want to remove it?", "You have an active simulation.\nDo you want to remove it?",
"Remove current simulation?", JOptionPane.YES_NO_OPTION, "Remove current simulation?", JOptionPane.YES_NO_OPTION,
@ -1237,11 +1257,8 @@ public class GUI {
* Mote passed as argument to mote plugins * Mote passed as argument to mote plugins
* @return Start plugin if any * @return Start plugin if any
*/ */
public Plugin startPlugin(Class<? extends Plugin> pluginClass, public Plugin startPlugin(Class<? extends Plugin> pluginClass, GUI gui,
GUI gui, Simulation simulation, Mote mote) {
Simulation simulation,
Mote mote
) {
// Check that plugin class is registered // Check that plugin class is registered
if (!pluginClasses.contains(pluginClass)) { if (!pluginClasses.contains(pluginClass)) {
@ -1278,23 +1295,24 @@ public class GUI {
// Tag plugin with mote // Tag plugin with mote
newPlugin.tagWithObject(mote); newPlugin.tagWithObject(mote);
} else if (pluginType == PluginType.SIM_PLUGIN || } else if (pluginType == PluginType.SIM_PLUGIN
pluginType == PluginType.SIM_STANDARD_PLUGIN) { || pluginType == PluginType.SIM_STANDARD_PLUGIN) {
if (simulation == null) { if (simulation == null) {
logger.fatal("Can't start simulation plugin (no simulation)"); logger.fatal("Can't start simulation plugin (no simulation)");
return null; return null;
} }
newPlugin = pluginClass.getConstructor(new Class[]{Simulation.class, GUI.class}) newPlugin = pluginClass.getConstructor(
.newInstance(simulation, gui); new Class[] { Simulation.class, GUI.class }).newInstance(
} else if (pluginType == PluginType.COOJA_PLUGIN || simulation, gui);
pluginType == PluginType.COOJA_STANDARD_PLUGIN) { } else if (pluginType == PluginType.COOJA_PLUGIN
|| pluginType == PluginType.COOJA_STANDARD_PLUGIN) {
if (gui == null) { if (gui == null) {
logger.fatal("Can't start COOJA plugin (no GUI)"); logger.fatal("Can't start COOJA plugin (no GUI)");
return null; return null;
} }
newPlugin = pluginClass.getConstructor(new Class[]{GUI.class}) newPlugin = pluginClass.getConstructor(new Class[] { GUI.class })
.newInstance(gui); .newInstance(gui);
} }
} catch (Exception e) { } catch (Exception e) {
@ -1338,8 +1356,7 @@ public class GUI {
* New plugin to register * New plugin to register
* @return True if this plugin was registered ok, false otherwise * @return True if this plugin was registered ok, false otherwise
*/ */
public boolean registerTemporaryPlugin( public boolean registerTemporaryPlugin(Class<? extends Plugin> newPluginClass) {
Class<? extends Plugin> newPluginClass) {
if (pluginClasses.contains(newPluginClass)) if (pluginClasses.contains(newPluginClass))
return false; return false;
@ -1408,13 +1425,15 @@ public class GUI {
// Check that plugin type is valid and constructor exists // Check that plugin type is valid and constructor exists
try { try {
if (pluginType == PluginType.MOTE_PLUGIN) { if (pluginType == PluginType.MOTE_PLUGIN) {
newPluginClass.getConstructor(new Class[]{Mote.class, Simulation.class, GUI.class}); newPluginClass.getConstructor(new Class[] { Mote.class,
} else if (pluginType == PluginType.SIM_PLUGIN || Simulation.class, GUI.class });
pluginType == PluginType.SIM_STANDARD_PLUGIN) { } else if (pluginType == PluginType.SIM_PLUGIN
newPluginClass.getConstructor(new Class[]{Simulation.class, GUI.class}); || pluginType == PluginType.SIM_STANDARD_PLUGIN) {
} else if (pluginType == PluginType.COOJA_PLUGIN || newPluginClass
pluginType == PluginType.COOJA_STANDARD_PLUGIN) { .getConstructor(new Class[] { Simulation.class, GUI.class });
newPluginClass.getConstructor(new Class[]{GUI.class}); } else if (pluginType == PluginType.COOJA_PLUGIN
|| pluginType == PluginType.COOJA_STANDARD_PLUGIN) {
newPluginClass.getConstructor(new Class[] { GUI.class });
} else { } else {
logger.fatal("Could not find valid plugin type annotation in class " logger.fatal("Could not find valid plugin type annotation in class "
+ newPluginClass); + newPluginClass);
@ -1531,7 +1550,8 @@ public class GUI {
boolean moteTypeOK = false; boolean moteTypeOK = false;
try { try {
newMoteType = moteTypeClass.newInstance(); newMoteType = moteTypeClass.newInstance();
moteTypeOK = newMoteType.configureAndInit(frame, mySimulation, isVisualized()); moteTypeOK = newMoteType.configureAndInit(frame, mySimulation,
isVisualized());
} catch (Exception e) { } catch (Exception e) {
logger.fatal("Exception when creating mote type: " + e); logger.fatal("Exception when creating mote type: " + e);
return; return;
@ -1555,7 +1575,7 @@ public class GUI {
if (askForConfirmation) { if (askForConfirmation) {
String s1 = "Remove"; String s1 = "Remove";
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = {s1, s2}; Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(frame, int n = JOptionPane.showOptionDialog(frame,
"You have an active simulation.\nDo you want to remove it?", "You have an active simulation.\nDo you want to remove it?",
"Remove current simulation?", JOptionPane.YES_NO_OPTION, "Remove current simulation?", JOptionPane.YES_NO_OPTION,
@ -1566,11 +1586,12 @@ public class GUI {
} }
// Close all started non-GUI plugins // Close all started non-GUI plugins
for (Object startedPlugin: startedPlugins.toArray()) { for (Object startedPlugin : startedPlugins.toArray()) {
int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); int pluginType = startedPlugin.getClass().getAnnotation(
if (pluginType != PluginType.COOJA_PLUGIN && PluginType.class).value();
pluginType != PluginType.COOJA_STANDARD_PLUGIN) if (pluginType != PluginType.COOJA_PLUGIN
removePlugin((Plugin)startedPlugin, false); && pluginType != PluginType.COOJA_STANDARD_PLUGIN)
removePlugin((Plugin) startedPlugin, false);
} }
// Delete simulation // Delete simulation
@ -1610,7 +1631,7 @@ public class GUI {
if (askForConfirmation && mySimulation != null) { if (askForConfirmation && mySimulation != null) {
String s1 = "Remove"; String s1 = "Remove";
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = {s1, s2}; Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(frame, int n = JOptionPane.showOptionDialog(frame,
"You have an active simulation.\nDo you want to remove it?", "You have an active simulation.\nDo you want to remove it?",
"Remove current simulation?", JOptionPane.YES_NO_OPTION, "Remove current simulation?", JOptionPane.YES_NO_OPTION,
@ -1682,7 +1703,7 @@ public class GUI {
if (askForConfirmation) { if (askForConfirmation) {
String s1 = "Overwrite"; String s1 = "Overwrite";
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = {s1, s2}; Object[] options = { s1, s2 };
int n = JOptionPane int n = JOptionPane
.showOptionDialog( .showOptionDialog(
frame, frame,
@ -1713,7 +1734,8 @@ public class GUI {
if (mySimulation != null) { if (mySimulation != null) {
mySimulation.stopSimulation(); mySimulation.stopSimulation();
Vector<Mote> newMotes = AddMoteDialog.showDialog(frame, mySimulation, moteType); Vector<Mote> newMotes = AddMoteDialog.showDialog(frame, mySimulation,
moteType);
if (newMotes != null) { if (newMotes != null) {
for (Mote newMote : newMotes) for (Mote newMote : newMotes)
mySimulation.addMote(newMote); mySimulation.addMote(newMote);
@ -1733,7 +1755,7 @@ public class GUI {
if (askForConfirmation && mySimulation != null) { if (askForConfirmation && mySimulation != null) {
String s1 = "Remove"; String s1 = "Remove";
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = {s1, s2}; Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(frame, int n = JOptionPane.showOptionDialog(frame,
"You have an active simulation.\nDo you want to remove it?", "You have an active simulation.\nDo you want to remove it?",
"Remove current simulation?", JOptionPane.YES_NO_OPTION, "Remove current simulation?", JOptionPane.YES_NO_OPTION,
@ -1762,7 +1784,7 @@ public class GUI {
if (askForConfirmation) { if (askForConfirmation) {
String s1 = "Quit"; String s1 = "Quit";
String s2 = "Cancel"; String s2 = "Cancel";
Object[] options = {s1, s2}; Object[] options = { s1, s2 };
int n = JOptionPane.showOptionDialog(frame, "Sure you want to quit?", int n = JOptionPane.showOptionDialog(frame, "Sure you want to quit?",
"Close COOJA Simulator", JOptionPane.YES_NO_OPTION, "Close COOJA Simulator", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, s1); JOptionPane.QUESTION_MESSAGE, null, options, s1);
@ -1772,7 +1794,7 @@ public class GUI {
// Clean up resources // Clean up resources
Object[] plugins = startedPlugins.toArray(); Object[] plugins = startedPlugins.toArray();
for (Object plugin: plugins) for (Object plugin : plugins)
removePlugin((Plugin) plugin, false); removePlugin((Plugin) plugin, false);
System.exit(0); System.exit(0);
@ -1888,15 +1910,16 @@ public class GUI {
* Save external tools user settings to file. * Save external tools user settings to file.
*/ */
public static void saveExternalToolsUserSettings() { public static void saveExternalToolsUserSettings() {
File configFile = new File(System.getProperty("user.home"), GUI.EXTERNAL_TOOLS_USER_SETTINGS_FILENAME); File configFile = new File(System.getProperty("user.home"),
GUI.EXTERNAL_TOOLS_USER_SETTINGS_FILENAME);
try { try {
FileOutputStream out = new FileOutputStream(configFile); FileOutputStream out = new FileOutputStream(configFile);
currentExternalToolsSettings.store(out, "COOJA User Settings"); currentExternalToolsSettings.store(out, "COOJA User Settings");
out.close(); out.close();
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
// Could not open settings file for writing, aborting // Could not open settings file for writing, aborting
logger.warn("Could not save external tools user settings to " + configFile logger.warn("Could not save external tools user settings to "
+ ", aborting"); + configFile + ", aborting");
} catch (IOException ex) { } catch (IOException ex) {
// Could not open settings file for writing, aborting // Could not open settings file for writing, aborting
logger.warn("Error while saving external tools user settings to " logger.warn("Error while saving external tools user settings to "
@ -1909,14 +1932,19 @@ public class GUI {
private class GUIEventHandler implements ActionListener, WindowListener { private class GUIEventHandler implements ActionListener, WindowListener {
public void windowDeactivated(WindowEvent e) { public void windowDeactivated(WindowEvent e) {
} }
public void windowIconified(WindowEvent e) { public void windowIconified(WindowEvent e) {
} }
public void windowDeiconified(WindowEvent e) { public void windowDeiconified(WindowEvent e) {
} }
public void windowOpened(WindowEvent e) { public void windowOpened(WindowEvent e) {
} }
public void windowClosed(WindowEvent e) { public void windowClosed(WindowEvent e) {
} }
public void windowActivated(WindowEvent e) { public void windowActivated(WindowEvent e) {
} }
@ -1947,7 +1975,7 @@ public class GUI {
ExternalToolsDialog.showDialog(frame); ExternalToolsDialog.showDialog(frame);
} else if (e.getActionCommand().equals("close plugins")) { } else if (e.getActionCommand().equals("close plugins")) {
Object[] plugins = startedPlugins.toArray(); Object[] plugins = startedPlugins.toArray();
for (Object plugin: plugins) for (Object plugin : plugins)
removePlugin((Plugin) plugin, false); removePlugin((Plugin) plugin, false);
} else if (e.getActionCommand().equals("manage platforms")) { } else if (e.getActionCommand().equals("manage platforms")) {
Vector<File> newPlatforms = UserPlatformsDialog.showDialog(frame, Vector<File> newPlatforms = UserPlatformsDialog.showDialog(frame,
@ -2013,7 +2041,8 @@ public class GUI {
} }
private ClassLoader createClassLoader(Vector<File> currentUserPlatforms) { private ClassLoader createClassLoader(Vector<File> currentUserPlatforms) {
return createClassLoader(ClassLoader.getSystemClassLoader(), currentUserPlatforms); return createClassLoader(ClassLoader.getSystemClassLoader(),
currentUserPlatforms);
} }
private File findJarFile(File platformPath, String jarfile) { private File findJarFile(File platformPath, String jarfile) {
@ -2068,7 +2097,8 @@ public class GUI {
} }
} }
return new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]), parent); return new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]),
parent);
} }
/** /**
@ -2235,7 +2265,8 @@ public class GUI {
* @throws UnsatisfiedLinkError * @throws UnsatisfiedLinkError
* If associated libraries could not be loaded * If associated libraries could not be loaded
*/ */
public Simulation loadSimulationConfig(File file, boolean quick) throws UnsatisfiedLinkError { public Simulation loadSimulationConfig(File file, boolean quick)
throws UnsatisfiedLinkError {
Simulation newSim = null; Simulation newSim = null;
@ -2286,8 +2317,7 @@ public class GUI {
* Saves current simulation configuration to given file and notifies * Saves current simulation configuration to given file and notifies
* observers. * observers.
* *
* @see #loadSimulationConfig(File file) * @see #loadSimulationConfig(File, boolean)
* @see #getConfigXML()
* @param file * @param file
* File to write * File to write
*/ */
@ -2322,6 +2352,7 @@ public class GUI {
/** /**
* Returns started plugins config. * Returns started plugins config.
*
* @return Config or null * @return Config or null
*/ */
public Collection<Element> getPluginsConfigXML() { public Collection<Element> getPluginsConfigXML() {
@ -2330,19 +2361,21 @@ public class GUI {
// Loop through all started plugins // Loop through all started plugins
// (Only return config of non-GUI plugins) // (Only return config of non-GUI plugins)
Element pluginElement, pluginSubElement; Element pluginElement, pluginSubElement;
for (Plugin startedPlugin: startedPlugins) { for (Plugin startedPlugin : startedPlugins) {
int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class)
.value();
// Ignore GUI plugins // Ignore GUI plugins
if (pluginType == PluginType.COOJA_PLUGIN || if (pluginType == PluginType.COOJA_PLUGIN
pluginType == PluginType.COOJA_STANDARD_PLUGIN) || pluginType == PluginType.COOJA_STANDARD_PLUGIN)
continue; continue;
pluginElement = new Element("plugin"); pluginElement = new Element("plugin");
pluginElement.setText(startedPlugin.getClass().getName()); pluginElement.setText(startedPlugin.getClass().getName());
// Create mote argument config (if mote plugin) // Create mote argument config (if mote plugin)
if (pluginType == PluginType.MOTE_PLUGIN && startedPlugin.getTag() != null) { if (pluginType == PluginType.MOTE_PLUGIN
&& startedPlugin.getTag() != null) {
pluginSubElement = new Element("mote_arg"); pluginSubElement = new Element("mote_arg");
Mote taggedMote = (Mote) startedPlugin.getTag(); Mote taggedMote = (Mote) startedPlugin.getTag();
for (int moteNr = 0; moteNr < mySimulation.getMotesCount(); moteNr++) { for (int moteNr = 0; moteNr < mySimulation.getMotesCount(); moteNr++) {
@ -2371,7 +2404,8 @@ public class GUI {
pluginElement.addContent(pluginSubElement); pluginElement.addContent(pluginSubElement);
pluginSubElement = new Element("z"); pluginSubElement = new Element("z");
pluginSubElement.setText("" + getDesktopPane().getComponentZOrder(startedVisPlugin)); pluginSubElement.setText(""
+ getDesktopPane().getComponentZOrder(startedVisPlugin));
pluginElement.addContent(pluginSubElement); pluginElement.addContent(pluginSubElement);
pluginSubElement = new Element("height"); pluginSubElement = new Element("height");
@ -2387,7 +2421,8 @@ public class GUI {
pluginElement.addContent(pluginSubElement); pluginElement.addContent(pluginSubElement);
pluginSubElement = new Element("minimized"); pluginSubElement = new Element("minimized");
pluginSubElement.setText(new Boolean(startedVisPlugin.isIcon()).toString()); pluginSubElement.setText(new Boolean(startedVisPlugin.isIcon())
.toString());
pluginElement.addContent(pluginSubElement); pluginElement.addContent(pluginSubElement);
} }
@ -2433,14 +2468,15 @@ public class GUI {
} }
// Start plugin (before applying rest of config) // Start plugin (before applying rest of config)
Plugin startedPlugin = startPlugin(visPluginClass, this, Plugin startedPlugin = startPlugin(visPluginClass, this, simulation,
simulation, mote); mote);
// Apply plugin specific configuration // Apply plugin specific configuration
for (Element pluginSubElement : (List<Element>) pluginElement for (Element pluginSubElement : (List<Element>) pluginElement
.getChildren()) { .getChildren()) {
if (pluginSubElement.getName().equals("plugin_config")) { if (pluginSubElement.getName().equals("plugin_config")) {
startedPlugin.setConfigXML(pluginSubElement.getChildren(), visAvailable); startedPlugin.setConfigXML(pluginSubElement.getChildren(),
visAvailable);
} }
} }
@ -2477,7 +2513,8 @@ public class GUI {
// Ignoring // Ignoring
} }
} else if (pluginSubElement.getName().equals("plugin_config")) { } else if (pluginSubElement.getName().equals("plugin_config")) {
startedVisPlugin.setConfigXML(pluginSubElement.getChildren(), visAvailable); startedVisPlugin.setConfigXML(pluginSubElement.getChildren(),
visAvailable);
} }
} }
} }

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: IPDistributor.java,v 1.1 2006/08/21 12:12:56 fros4943 Exp $ * $Id: IPDistributor.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -38,6 +36,7 @@ import org.apache.log4j.Logger;
/** /**
* A IP distributor is used for determining IP addresses of newly created motes. * A IP distributor is used for determining IP addresses of newly created motes.
* *
* @see se.sics.cooja.Positioner
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public abstract class IPDistributor { public abstract class IPDistributor {
@ -48,17 +47,19 @@ public abstract class IPDistributor {
* constructor argument. Instead of calling the constructors directly this * constructor argument. Instead of calling the constructors directly this
* method may be used. * method may be used.
* *
* @param ipDistClass Class * @param ipDistClass
* @param newMotes All motes that later should be assigned IP numbers * Class
* @param newMotes
* All motes that later should be assigned IP numbers
* @return IP distributor instance * @return IP distributor instance
*/ */
public static final IPDistributor generateInterface( public static final IPDistributor generateIPDistributor(
Class<? extends IPDistributor> ipDistClass, Vector<Mote> newMotes) { Class<? extends IPDistributor> ipDistClass, Vector<Mote> newMotes) {
try { try {
// Generating IP distributor // Generating IP distributor
Constructor constr = ipDistClass Constructor constr = ipDistClass
.getConstructor(new Class[]{Vector.class}); .getConstructor(new Class[] { Vector.class });
return (IPDistributor) constr.newInstance(new Object[]{newMotes}); return (IPDistributor) constr.newInstance(new Object[] { newMotes });
} catch (Exception e) { } catch (Exception e) {
logger.fatal("Exception when creating " + ipDistClass + ": " + e); logger.fatal("Exception when creating " + ipDistClass + ": " + e);
return null; return null;
@ -66,9 +67,9 @@ public abstract class IPDistributor {
} }
/** /**
* Returns the next mote position. * Returns the next mote IP address.
* *
* @return Position * @return IP Address
*/ */
public abstract String getNextIPAddress(); public abstract String getNextIPAddress();

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: Mote.java,v 1.3 2007/01/09 10:16:26 fros4943 Exp $ * $Id: Mote.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -36,10 +34,11 @@ import java.util.Observer;
import org.jdom.Element; import org.jdom.Element;
/** /**
* This interface represents a simulated mote. * A simulated mote.
* *
* A mote is always in some state, describing the status of the CPU etc. * A mote is always in some state, describing the status of the CPU etc. Motes
* Motes in different states may be handled differently by the for example simulation loops and plugins. * in different states may be handled differently by for example the simulation
* loop and plugins.
* *
* All motes must also have an interface handler, a mote type and a mote memory. * All motes must also have an interface handler, a mote type and a mote memory.
* *
@ -55,16 +54,20 @@ public interface Mote {
* Possible mote states * Possible mote states
*/ */
public static enum State { public static enum State {
ACTIVE, // Active state /* Active state */
LPM, // Low power mode (sleeping) ACTIVE,
DEAD // Dead (for example out of batteries) /* Low power mode (sleeping) */
LPM,
/* Dead (for example out of batteries) */
DEAD
} }
/** /**
* Tries to change state to given argument. * Tries to change state to given argument. A dead mote can typically not
* A dead mote can typically not change state, while a sleeping or active mote can. * change state, while a sleeping or active mote can.
* *
* @param newState New state of mote. * @param newState
* New state of mote.
*/ */
public void setState(State newState); public void setState(State newState);
@ -74,11 +77,11 @@ public interface Mote {
public State getState(); public State getState();
/** /**
* Adds new state observer. * Adds new state observer. This observer is notified if mote changes state.
* This observer is notified if mote changes state.
* *
* @see #deleteStateObserver(Observer) * @see #deleteStateObserver(Observer)
* @param newObserver New observer * @param newObserver
* New observer
*/ */
public void addStateObserver(Observer newObserver); public void addStateObserver(Observer newObserver);
@ -86,11 +89,11 @@ public interface Mote {
* Delete existing state observer. * Delete existing state observer.
* *
* @see #addStateObserver(Observer) * @see #addStateObserver(Observer)
* @param newObserver Registered state observer * @param newObserver
* Registered state observer
*/ */
public void deleteStateObserver(Observer newObserver); public void deleteStateObserver(Observer newObserver);
/** /**
* Returns the interface handler of this mote. * Returns the interface handler of this mote.
* *
@ -102,12 +105,12 @@ public interface Mote {
/** /**
* Sets the interface handler of this mote. * Sets the interface handler of this mote.
* *
* @param moteInterfaceHandler New interface handler * @param moteInterfaceHandler
* New interface handler
* @see #getInterfaces() * @see #getInterfaces()
*/ */
public void setInterfaces(MoteInterfaceHandler moteInterfaceHandler); public void setInterfaces(MoteInterfaceHandler moteInterfaceHandler);
/** /**
* Returns the memory of this mote. * Returns the memory of this mote.
* *
@ -120,11 +123,11 @@ public interface Mote {
* Sets the memory of this mote. * Sets the memory of this mote.
* *
* @see #getMemory() * @see #getMemory()
* @param memory Mote memory * @param memory
* Mote memory
*/ */
public void setMemory(MoteMemory memory); public void setMemory(MoteMemory memory);
/** /**
* Returns mote type. * Returns mote type.
* *
@ -137,11 +140,11 @@ public interface Mote {
* Sets mote type to given argument. * Sets mote type to given argument.
* *
* @see #getType() * @see #getType()
* @param type New type * @param type
* New type
*/ */
public void setType(MoteType type); public void setType(MoteType type);
/** /**
* Returns simulation which holds this mote. * Returns simulation which holds this mote.
* *
@ -154,37 +157,37 @@ public interface Mote {
* Sets the simulation which holds this mote. * Sets the simulation which holds this mote.
* *
* @see #getSimulation() * @see #getSimulation()
* @param simulation Simulation * @param simulation
* Simulation
*/ */
public void setSimulation(Simulation simulation); public void setSimulation(Simulation simulation);
/** /**
* Ticks this mote and increases any internal time to given argument. * Ticks this mote and increases any internal time to given argument.
* *
* Each mote implementation may handle calls to this method differently, * Each mote implementation may handle calls to this method differently, but
* but, if existing, the simulated mote should at least handle one event. * typically the simulated mote should at least handle one event.
* *
* This method is responsible for updating the mote interfaces, the memory and the mote state. * This method is responsible for updating the mote interfaces, the memory and
* the mote state.
* *
* A call to this method typically * A call to this method typically polls all interfaces, activates the memory,
* polls all interfaces, * lets the underlying mote software handle one event, fetches the updated
* activates the memory, * memory and finally polls all interfaces again.
* lets the underlying mote software handle one event,
* fetches the updated memory and
* finally polls all interfaces again.
* *
* @param simTime New simulation time * @param simTime
* New simulation time
*/ */
public void tick(int simTime); public void tick(int simTime);
/** /**
* Returns XML elements representing the current config of this mote. * Returns XML elements representing the current config of this mote. This is
* This is fetched by the simulator for example when saving a simulation configuration file. * fetched by the simulator for example when saving a simulation configuration
* For example a mote may return the configs of all its interfaces. * file. For example a mote may return the configs of all its interfaces. This
* This method should however not return state specific information such as the mote state. * method should however not return state specific information such as the
* (All nodes are restarted when loading a simulation.) * mote state. (All nodes are restarted when loading a simulation.)
* *
* @see #setConfigXML(Simulation, Collection) * @see #setConfigXML(Simulation, Collection, boolean)
* @return XML elements representing the current mote config * @return XML elements representing the current mote config
*/ */
public abstract Collection<Element> getConfigXML(); public abstract Collection<Element> getConfigXML();
@ -192,11 +195,14 @@ public interface Mote {
/** /**
* Sets the current mote config depending on the given XML elements. * Sets the current mote config depending on the given XML elements.
* *
* @param simulation Simulation holding this mote * @param simulation
* @param configXML Config XML elements * Simulation holding this mote
* @param configXML
* Config XML elements
* *
* @see #getConfigXML() * @see #getConfigXML()
*/ */
public abstract boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable); public abstract boolean setConfigXML(Simulation simulation,
Collection<Element> configXML, boolean visAvailable);
} }

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: MoteInterface.java,v 1.2 2007/01/09 10:16:42 fros4943 Exp $ * $Id: MoteInterface.java,v 1.3 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -38,16 +36,19 @@ import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
/** /**
* A mote interface represents a mote property. * A mote interface represents a mote property. Often this is a simulated
* Often this is a simulated hardware peripheral such as a button or a led. * hardware peripheral such as a button or a led. This can also be a property
* This can also be a property the mote software itself is unaware of, * the mote software itself is unaware of, for example the current position of
* for example the current position of the mote. * the mote.
* *
* Interfaces are the main way for the simulator to interact with a simulated mote. * Interfaces are the main way for the simulator to interact with a simulated
* mote.
* *
* Interfaces are divided into active and passive interfaces, and are handled differently. * Interfaces are divided into active and passive interfaces, which are handled
* In order to create a passive interfaces, the class should also implement the dummy Java interface PassiveMoteInterface. * differently. In order to create a passive interface, the class should also
* For an explanation of the differences of active and passive interfaces see class PassiveMoteInterface. * implement the dummy Java interface PassiveMoteInterface. For an explanation
* of the differences of active and passive interfaces see class
* PassiveMoteInterface.
* *
* @see PassiveMoteInterface * @see PassiveMoteInterface
* @author Fredrik Osterlind * @author Fredrik Osterlind
@ -56,14 +57,18 @@ public abstract class MoteInterface extends Observable {
private static Logger logger = Logger.getLogger(MoteInterface.class); private static Logger logger = Logger.getLogger(MoteInterface.class);
/** /**
* This method creates an instance of the given class with the given mote as constructor * This method creates an instance of the given class with the given mote as
* argument. Instead of calling the interface constructors directly this method may be used. * constructor argument. Instead of calling the interface constructors
* directly this method may be used.
* *
* @param interfaceClass Mote interface class * @param interfaceClass
* @param mote Mote that will hold the interface * Mote interface class
* @param mote
* Mote that will hold the interface
* @return Mote interface instance * @return Mote interface instance
*/ */
public static final MoteInterface generateInterface(Class<? extends MoteInterface> interfaceClass, Mote mote) { public static final MoteInterface generateInterface(
Class<? extends MoteInterface> interfaceClass, Mote mote) {
try { try {
// Generating interface // Generating interface
MoteInterface instance = (MoteInterface) interfaceClass.getConstructor( MoteInterface instance = (MoteInterface) interfaceClass.getConstructor(
@ -87,12 +92,12 @@ public abstract class MoteInterface extends Observable {
public abstract void doActionsAfterTick(); public abstract void doActionsAfterTick();
/** /**
* Returns a panel with interesting data for this interface. * Returns a panel with interesting data for this interface. This could for
* This could for example show last messages sent/received for * example show last messages sent/received for a radio interface, or logged
* a radio interface, or logged message for a log interface. * message for a log interface.
* *
* All panels returned from this method must later be released * All panels returned from this method must later be released for memory
* for memory reasons. * reasons.
* *
* If returned panel is null, this interface will not be visualized. * If returned panel is null, this interface will not be visualized.
* *
@ -103,32 +108,40 @@ public abstract class MoteInterface extends Observable {
/** /**
* This method should be called when a visualizer panel is no longer in use. * This method should be called when a visualizer panel is no longer in use.
* Any resources of that panel, for example registered observers, will be released. * Any resources of that panel, for example registered observers, will be
* released.
* *
* @see #getInterfaceVisualizer() * @see #getInterfaceVisualizer()
* @param panel A interface visualizer panel fetched earlier for this mote interface. * @param panel
* A interface visualizer panel fetched earlier for this mote
* interface.
*/ */
public abstract void releaseInterfaceVisualizer(JPanel panel); public abstract void releaseInterfaceVisualizer(JPanel panel);
/** /**
* Returns approximated energy consumed (mQ) during the current tick. * Returns approximated energy consumed (mQ) during the current tick. If the
* If the interface is active, this information must be available after the doActionsAfterTick method. * interface is active, this information must be available after the
* If the interface is passive, this information must be available after the doActionsBeforeTick method. * doActionsAfterTick method. If the interface is passive, this information
* must be available after the doActionsBeforeTick method.
* *
* The interface is responsible to gather information about the current internal state, * The interface is responsible to gather information about the current
* and calculate whatever energy it needs in that state and during one tick. * internal state, and calculate whatever energy it needs in that state and
* during one tick.
* *
* If the holding mote is dead, this method will not be called. * If the holding mote is dead, this method will not be called. If the holding
* If the holding mote is sleeping and this interface is active, this method will not be called. * mote is sleeping and this interface is active, this method will not be
* called.
* *
* For example, a radio transmitter or a PIR sensor often has a much higher energy * For example, a radio transmitter or a PIR sensor often has a much higher
* usage than a button sensor which virtually needs no energy at all. * energy usage than a button sensor which virtually needs no energy at all.
* If the radio is turned off in hardware, it should return a zero energy consumption. * If the radio is turned off in hardware, it should return a zero energy
* If the radio is sending something which would take longer than one tick, it may either return * consumption. If the radio is sending something which would take longer than
* the total energy used directly, or a smaller amount during several ticks. * one tick, it may either return the total energy used directly, or a smaller
* amount during several ticks.
* *
* This method may typically be used by the passive interface battery, which sums up * This method may typically be used by the passive interface battery, which
* all energy used during one tick and decreases the battery energy left. * sums up all energy used during one tick and decreases the battery energy
* left.
* *
* @see se.sics.cooja.interfaces.Battery * @see se.sics.cooja.interfaces.Battery
* @return Energy consumption of this device during the current tick * @return Energy consumption of this device during the current tick
@ -136,13 +149,14 @@ public abstract class MoteInterface extends Observable {
public abstract double energyConsumptionPerTick(); public abstract double energyConsumptionPerTick();
/** /**
* Returns XML elements representing the current config of this mote interface. * Returns XML elements representing the current config of this mote
* This is fetched by the simulator for example when saving a simulation configuration file. * interface. This is fetched by the simulator for example when saving a
* For example an IP interface may return one element with the mote IP address. * simulation configuration file. For example an IP interface may return one
* This method should however not return state specific information such as a log history. * element with the mote IP address. This method should however not return
* (All nodes are restarted when loading a simulation.) * state specific information such as a log history. (All nodes are restarted
* when loading a simulation.)
* *
* @see #setConfigXML(Collection) * @see #setConfigXML(Collection, boolean)
* @return XML elements representing the current interface config * @return XML elements representing the current interface config
*/ */
public abstract Collection<Element> getConfigXML(); public abstract Collection<Element> getConfigXML();
@ -151,8 +165,12 @@ public abstract class MoteInterface extends Observable {
* Sets the current mote interface config depending on the given XML elements. * Sets the current mote interface config depending on the given XML elements.
* *
* @see #getConfigXML() * @see #getConfigXML()
* @param configXML Config XML elements * @param configXML
* Config XML elements
* @param visAvailable
* Is this object allowed to show a visualizer?
*/ */
public abstract void setConfigXML(Collection<Element> configXML, boolean visAvailable); public abstract void setConfigXML(Collection<Element> configXML,
boolean visAvailable);
} }

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: MoteInterfaceHandler.java,v 1.1 2006/08/21 12:12:56 fros4943 Exp $ * $Id: MoteInterfaceHandler.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -40,7 +38,7 @@ import se.sics.cooja.interfaces.*;
* A mote interface handler holds all interfaces for a specific mote. Even * A mote interface handler holds all interfaces for a specific mote. Even
* though an interface handler strictly does not need any interfaces at all, a * though an interface handler strictly does not need any interfaces at all, a
* position interface is highly recommended. (A lot of plugins depend on a mote * position interface is highly recommended. (A lot of plugins depend on a mote
* position, for example when visualizing nodes.) * position, for example a typical visualizer.)
* *
* Interfaces are divided into active and passive interfaces. Active interfaces * Interfaces are divided into active and passive interfaces. Active interfaces
* are only polled if the mote is active, while passive interfaces are polled in * are only polled if the mote is active, while passive interfaces are polled in
@ -54,18 +52,29 @@ public class MoteInterfaceHandler {
private static Logger logger = Logger.getLogger(MoteInterfaceHandler.class); private static Logger logger = Logger.getLogger(MoteInterfaceHandler.class);
private Battery myBattery; private Battery myBattery;
private Beeper myBeeper; private Beeper myBeeper;
private Button myButton; private Button myButton;
private Clock myClock; private Clock myClock;
private IPAddress myIPAddress; private IPAddress myIPAddress;
private LED myLED; private LED myLED;
private Log myLog; private Log myLog;
private MoteID myMoteID; private MoteID myMoteID;
private PIR myPIR; private PIR myPIR;
private Position myPosition; private Position myPosition;
private Radio myRadio; private Radio myRadio;
private Vector<MoteInterface> myActiveInterfaces = new Vector<MoteInterface>(); private Vector<MoteInterface> myActiveInterfaces = new Vector<MoteInterface>();
private Vector<MoteInterface> myPassiveInterfaces = new Vector<MoteInterface>(); private Vector<MoteInterface> myPassiveInterfaces = new Vector<MoteInterface>();
/** /**
@ -120,13 +129,15 @@ public class MoteInterfaceHandler {
*/ */
public <N extends MoteInterface> N getInterfaceOfType(Class<N> interfaceType) { public <N extends MoteInterface> N getInterfaceOfType(Class<N> interfaceType) {
Enumeration<? extends MoteInterface> allActive = myActiveInterfaces.elements(); Enumeration<? extends MoteInterface> allActive = myActiveInterfaces
.elements();
while (allActive.hasMoreElements()) { while (allActive.hasMoreElements()) {
N nextInterface = (N) allActive.nextElement(); N nextInterface = (N) allActive.nextElement();
if (interfaceType.isAssignableFrom(nextInterface.getClass())) if (interfaceType.isAssignableFrom(nextInterface.getClass()))
return nextInterface; return nextInterface;
} }
Enumeration<? extends MoteInterface> allPassive = myPassiveInterfaces.elements(); Enumeration<? extends MoteInterface> allPassive = myPassiveInterfaces
.elements();
while (allPassive.hasMoreElements()) { while (allPassive.hasMoreElements()) {
N nextInterface = (N) allPassive.nextElement(); N nextInterface = (N) allPassive.nextElement();
if (interfaceType.isAssignableFrom(nextInterface.getClass())) if (interfaceType.isAssignableFrom(nextInterface.getClass()))

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: MoteMemory.java,v 1.1 2006/08/21 12:12:55 fros4943 Exp $ * $Id: MoteMemory.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -41,6 +41,7 @@ package se.sics.cooja;
* different memory sections, not covering the entire range * different memory sections, not covering the entire range
* between the start address and the end address of this memory. * between the start address and the end address of this memory.
* *
* @see se.sics.cooja.SectionMoteMemory
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public interface MoteMemory { public interface MoteMemory {

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: MoteType.java,v 1.2 2007/01/09 10:16:26 fros4943 Exp $ * $Id: MoteType.java,v 1.3 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -37,15 +35,14 @@ import javax.swing.JPanel;
import org.jdom.Element; import org.jdom.Element;
/** /**
* Every simulated motes belongs to a mote type.
*
* The mote type defines properties common for several motes. These properties * The mote type defines properties common for several motes. These properties
* may differ between different implementations, but typically includes how a * may differ between different implementations, but typically includes how a
* mote of that type is initialized, which hardware peripherals each mote has * mote of that type is initialized, which hardware peripherals each mote has
* etc. * etc.
* Every simulated motes must belong to a mote type.
* *
* A mote type may also hold the connection to an underlying simulation * A mote type may also hold the connection to an underlying simulation
* framework. * framework, such as a compiled Contiki system.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ -99,7 +96,7 @@ public interface MoteType {
* Generates a mote of this mote type. * Generates a mote of this mote type.
* *
* @param simulation * @param simulation
* Newly created mote's simulation * Simulation that will contain mote
* @return New mote * @return New mote
*/ */
public Mote generateMote(Simulation simulation); public Mote generateMote(Simulation simulation);
@ -116,16 +113,19 @@ public interface MoteType {
* Parent frame or null * Parent frame or null
* @param simulation * @param simulation
* Simulation holding (or that should hold) mote type * Simulation holding (or that should hold) mote type
* @param visAvailable
* True if this method is allowed to show a visualizer
* @return True if mote type has valid settings and is ready to be used * @return True if mote type has valid settings and is ready to be used
*/ */
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, boolean visAvailable); public boolean configureAndInit(JFrame parentFrame, Simulation simulation,
boolean visAvailable);
/** /**
* Returns XML elements representing the current config of this mote type. * Returns XML elements representing the current config of this mote type.
* This is fetched by the simulator for example when saving a simulation * This is fetched by the simulator for example when saving a simulation
* configuration file. For example a Contiki base directory may be saved. * configuration file. For example a Contiki base directory may be saved.
* *
* @see #setConfigXML(Simulation, Collection) * @see #setConfigXML(Simulation, Collection, boolean)
* @return XML elements representing the current mote type's config * @return XML elements representing the current mote type's config
*/ */
public Collection<Element> getConfigXML(); public Collection<Element> getConfigXML();
@ -141,6 +141,8 @@ public interface MoteType {
* Simulation that will hold the mote type * Simulation that will hold the mote type
* @param configXML * @param configXML
* Config XML elements * Config XML elements
* @param visAvailable
* True if this method is allowed to show a visualizer
* @return True if config was set successfully, false otherwise * @return True if config was set successfully, false otherwise
*/ */
public boolean setConfigXML(Simulation simulation, public boolean setConfigXML(Simulation simulation,

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: PassiveMoteInterface.java,v 1.1 2006/08/21 12:12:57 fros4943 Exp $ * $Id: PassiveMoteInterface.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -34,19 +34,18 @@ package se.sics.cooja;
/** /**
* Mote interfaces are divided into active and passive interfaces. * Mote interfaces are divided into active and passive interfaces.
* *
* A passive mote interface is treated different than an ordinary (active) * A passive mote interface is treated different than an ordinary (active) mote
* mote interface; * interface; Passive interfaces are allowed to act even when the mote is
* Passive interfaces are allowed to act even when the mote is sleeping, * sleeping, while active interface only acts when the mote is in active state.
* while active interface only acts when the mote is in active state.
* *
* A typical active interface is the radio interface, since radio * A typical active interface is the radio interface, since radio messages only
* messages only can be received when the mote is active. * can be received when the mote is active.
* *
* A typical passive interface is the battery interface, since a mote * A typical passive interface is the battery interface, since a mote consumes
* consumes energy even though it is sleeping. * energy even though it is sleeping.
* *
* All passive interface should implement this interface. * All passive interface should implement this interface. All interfaces not
* All interfaces not implemented this interface will be handled as active interfaces. * implemented this interface will be handled as active interfaces.
* *
* Any energy required by this interface must be available after the * Any energy required by this interface must be available after the
* doActionsBeforeTick method. * doActionsBeforeTick method.

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: PlatformConfig.java,v 1.3 2006/09/06 12:26:33 fros4943 Exp $ * $Id: PlatformConfig.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -149,12 +149,12 @@ public class PlatformConfig {
* instead. * instead.
* *
* @param callingClass * @param callingClass
* Class which value belongs to * Class which value belong to
* @param key * @param key
* Key * Key
* @param value * @param arrayElement
* Element of array * Value or array element
* @return User platform * @return User platform defining arguments or null
*/ */
public File getUserPlatformDefining(Class callingClass, String key, String arrayElement) { public File getUserPlatformDefining(Class callingClass, String key, String arrayElement) {

View file

@ -26,19 +26,19 @@
* 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: Plugin.java,v 1.1 2007/01/09 10:15:42 fros4943 Exp $ * $Id: Plugin.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
import java.util.Collection; import java.util.Collection;
import org.jdom.Element; import org.jdom.Element;
/** /**
* Interface for a COOJA interaction plugin. The typical interaction plugin * Main interface for a COOJA interaction plugin. The typical interaction plugin
* is a visualization plugin, see abstract VisPlugin for more information. * is a visualization plugin, see abstract VisPlugin for more information.
* *
* @see se.sics.cooja.VisPlugin
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public interface Plugin { public interface Plugin {
@ -67,7 +67,6 @@ public interface Plugin {
*/ */
public Object getTag(); public Object getTag();
/** /**
* Returns XML elements representing the current config of this plugin. This * Returns XML elements representing the current config of this plugin. This
* is fetched by the simulator for example when saving a simulation * is fetched by the simulator for example when saving a simulation
@ -76,7 +75,7 @@ public interface Plugin {
* such as the value of a mote LED, or total number of motes. (All nodes are * such as the value of a mote LED, or total number of motes. (All nodes are
* restarted when loading a simulation.) * restarted when loading a simulation.)
* *
* @see #setConfigXML(Collection) * @see #setConfigXML(Collection, boolean)
* @return XML elements representing the current radio medium config * @return XML elements representing the current radio medium config
*/ */
public Collection<Element> getConfigXML(); public Collection<Element> getConfigXML();
@ -89,6 +88,7 @@ public interface Plugin {
* Config XML elements * Config XML elements
* @return True if config was set successfully, false otherwise * @return True if config was set successfully, false otherwise
*/ */
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable); public boolean setConfigXML(Collection<Element> configXML,
boolean visAvailable);
} }

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: PluginType.java,v 1.1 2007/01/09 10:15:26 fros4943 Exp $ * $Id: PluginType.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -35,7 +33,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
/** /**
* Annotation type to describe a plugin type. * Annotation type to identify a plugin type.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ -48,18 +46,17 @@ public @interface PluginType {
* *
* A mote plugin concerns one specific mote. * A mote plugin concerns one specific mote.
* *
* An example of such a plugin may be to display * An example of such a plugin may be to display some mote information in a
* some mote information in a frame. * frame.
* *
* Mote plugins can not be instantiated from the * Mote plugins can not be instantiated from the regular menu bar, but are
* regular menu bar, but are instead started from * instead started from other plugins, for example a visualizer that let's a
* other plugins, for example a visualizer that let's * user select a mote.
* a user select a mote.
* *
* When constructed, a mote plugin is given a Mote. * When constructed, a mote plugin is given a mote, the current active
* simulation and the GUI object.
* *
* If the current simulation is removed, so are * If the current simulation is removed, so are all instances of this plugin.
* all instances of this plugin.
*/ */
public static final int MOTE_PLUGIN = 1; public static final int MOTE_PLUGIN = 1;
@ -68,26 +65,25 @@ public @interface PluginType {
* *
* A simulation plugin concerns one specific simulation. * A simulation plugin concerns one specific simulation.
* *
* An example of such a plugin may be to display * An example of such a plugin may be to display number of motes and current
* number of motes and current simulation time in a window. * simulation time in a window.
* *
* Simulation plugins are available via the plugins menubar. * Simulation plugins are available via the plugins menubar.
* *
* When constructed, a simulation plugin is given the current * When constructed, a simulation plugin is given the current active
* active simulation. * simulation and the GUI object.
* *
* If the current simulation is removed, so are * If the current simulation is removed, so are all instances of this plugin.
* all instances of this plugin.
*/ */
public static final int SIM_PLUGIN = 2; public static final int SIM_PLUGIN = 2;
/** /**
* COOJA Plugin * COOJA Plugin
* *
* A COOJA plugin does not depend on the current simulation to function. * A COOJA plugin does not depend on the current simulation (if any).
* *
* An example of such a plugin may be a control panel * An example of such a plugin may be a control panel where a user can save
* where a user can control the current simulation. * and load different simulations.
* *
* COOJA plugins are available via the plugins menubar. * COOJA plugins are available via the plugins menubar.
* *
@ -98,22 +94,22 @@ public @interface PluginType {
/** /**
* Simulation Standard Plugin * Simulation Standard Plugin
* *
* This is treated exactly like a Simulation Plugin, with the * This is treated exactly like a Simulation Plugin, with the only difference
* only difference that this will automatically be opened * that this will automatically be opened when a new simulation is created.
* when a new simulation is created. *
* @see #SIM_PLUGIN
*/ */
public static final int SIM_STANDARD_PLUGIN = 4; public static final int SIM_STANDARD_PLUGIN = 4;
/** /**
* COOJA Standard Plugin * COOJA Standard Plugin
* *
* This is treated exactly like a COOJA Plugin, with the * This is treated exactly like a COOJA Plugin, with the only difference that
* only difference that this will automatically be opened * this will automatically be opened when the simulator is started.
* when the simulator is started. *
* @see #COOJA_PLUGIN
*/ */
public static final int COOJA_STANDARD_PLUGIN = 5; public static final int COOJA_STANDARD_PLUGIN = 5;
int value(); int value();
} }

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: Positioner.java,v 1.1 2006/08/21 12:12:51 fros4943 Exp $ * $Id: Positioner.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -72,11 +72,11 @@ public abstract class Positioner {
double endZ) { double endZ) {
try { try {
// Generating positioner // Generating positioner
Constructor constr = positionerClass.getConstructor(new Class[]{ Constructor constr = positionerClass.getConstructor(new Class[] {
int.class, double.class, double.class, double.class, double.class, int.class, double.class, double.class, double.class, double.class,
double.class, double.class}); double.class, double.class });
return (Positioner) constr.newInstance(new Object[]{totalNumberOfMotes, return (Positioner) constr.newInstance(new Object[] { totalNumberOfMotes,
startX, endX, startY, endY, startZ, endZ}); startX, endX, startY, endY, startZ, endZ });
} catch (Exception e) { } catch (Exception e) {
logger.fatal("Exception when creating " + positionerClass + ": " + e); logger.fatal("Exception when creating " + positionerClass + ": " + e);
return null; return null;

View file

@ -26,25 +26,24 @@
* 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: RadioMedium.java,v 1.3 2007/01/10 09:02:17 fros4943 Exp $ * $Id: RadioMedium.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Collection; import java.util.*;
import java.util.Observable;
import java.util.Observer;
import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.interfaces.Position; import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
/** /**
* This interface represents a radio medium. Radios registered to this medium * The abstract class RadioMedium should be implemented by all COOJA radio
* can both send and receive radio data. Depending on the implementation of this * mediums. Radios registered in this medium can both send and receive radio
* interface, more or less accurate radio behaviour imitation is aquired. * data. Depending on the implementation of this interface, more or less
* accurate radio behaviour imitation is aquired.
* *
* Often a radio medium, at initialization, registers one or several dynamic * Often a radio medium, at initialization, registers one or several dynamic
* plugins. These plugins shows the user some radio medium specific details, * plugins. These plugins shows the user some radio medium specific details,
@ -53,7 +52,6 @@ import se.sics.cooja.interfaces.Radio;
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public abstract class RadioMedium { public abstract class RadioMedium {
private static Logger logger = Logger.getLogger(RadioMedium.class);
/** /**
* Registers a mote to this medium. * Registers a mote to this medium.
@ -167,7 +165,7 @@ public abstract class RadioMedium {
* information such as a current radio status. (All nodes are restarted when * information such as a current radio status. (All nodes are restarted when
* loading a simulation.) * loading a simulation.)
* *
* @see #setConfigXML(Collection) * @see #setConfigXML(Collection, boolean)
* @return XML elements representing the current radio medium config * @return XML elements representing the current radio medium config
*/ */
public abstract Collection<Element> getConfigXML(); public abstract Collection<Element> getConfigXML();
@ -182,7 +180,6 @@ public abstract class RadioMedium {
*/ */
public abstract boolean setConfigXML(Collection<Element> configXML, boolean visAvailable); public abstract boolean setConfigXML(Collection<Element> configXML, boolean visAvailable);
/** /**
* This method creates an instance of the given class with the given * This method creates an instance of the given class with the given
* simulation constructor argument. Instead of calling the constructors * simulation constructor argument. Instead of calling the constructors

View file

@ -1,32 +1,30 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: SectionMoteMemory.java,v 1.3 2006/12/15 11:47:40 fros4943 Exp $ * $Id: SectionMoteMemory.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -39,8 +37,8 @@ import org.apache.log4j.Logger;
import se.sics.cooja.MoteMemory; import se.sics.cooja.MoteMemory;
/** /**
* Represents a mote memory consisting of non-overlapping memory sections. This * Represents a mote memory consisting of non-overlapping memory sections with
* memory also contains information about variable starts addresses. * variables' memory addresses.
* <p> * <p>
* When an unhandled memory segment is set a new section is automatically * When an unhandled memory segment is set a new section is automatically
* created for this segment. * created for this segment.
@ -52,6 +50,7 @@ public class SectionMoteMemory implements MoteMemory {
private static Logger logger = Logger.getLogger(SectionMoteMemory.class); private static Logger logger = Logger.getLogger(SectionMoteMemory.class);
private Vector<MoteMemorySection> sections = new Vector<MoteMemorySection>(); private Vector<MoteMemorySection> sections = new Vector<MoteMemorySection>();
private final Properties variableAddresses; private final Properties variableAddresses;
/** /**
@ -78,7 +77,8 @@ public class SectionMoteMemory implements MoteMemory {
} }
/** /**
* @param varName Variable name * @param varName
* Variable name
* @return Address of given variable, or -1 * @return Address of given variable, or -1
*/ */
public int getVariableAddress(String varName) { public int getVariableAddress(String varName) {
@ -341,12 +341,13 @@ public class SectionMoteMemory implements MoteMemory {
} }
/** /**
* A memory section represented of a byte array and a start address. * A memory section contains a byte array and a start address.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
private class MoteMemorySection { private class MoteMemorySection {
private byte[] data = null; private byte[] data = null;
private int startAddr; private int startAddr;
/** /**

View file

@ -1,37 +1,34 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* All rights reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in the * materials provided with the distribution. 3. Neither the name of the
* documentation and/or other materials provided with the distribution. * Institute nor the names of its contributors may be used to endorse or promote
* 3. Neither the name of the Institute nor the names of its contributors * products derived from this software without specific prior written
* may be used to endorse or promote products derived from this software * permission.
* without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SUCH DAMAGE.
* *
* $Id: Simulation.java,v 1.8 2007/01/10 09:02:38 fros4943 Exp $ * $Id: Simulation.java,v 1.9 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
import java.io.*;
import java.util.*; import java.util.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.*; import org.jdom.*;
@ -39,13 +36,15 @@ import org.jdom.*;
import se.sics.cooja.dialogs.*; import se.sics.cooja.dialogs.*;
/** /**
* A simulation contains motes and ticks them one by one. When all motes has * A simulation consists of a number of motes and mote types.
* been ticked once, the simulation sleeps for some specified time, and the *
* current simulation time is updated. Some observers (tick observers) are also * The motes in the simulation are ticked one by one in a simulation loop. When
* notified. * all motes have been ticked once, the simulation time is updated and then the
* simulation sleeps for some specified delay time. Any tick observers are also
* notified at this time.
* *
* When observing the simulation itself, the simulation state, added or deleted * When observing the simulation itself, the simulation state, added or deleted
* motes etc are observed, as opposed to individual mote changes. Changes of * motes etc. are observed, as opposed to individual mote changes. Changes of
* individual motes should instead be observed via corresponding mote * individual motes should instead be observed via corresponding mote
* interfaces. * interfaces.
* *
@ -54,20 +53,25 @@ import se.sics.cooja.dialogs.*;
public class Simulation extends Observable implements Runnable { public class Simulation extends Observable implements Runnable {
private Vector<Mote> motes = new Vector<Mote>(); private Vector<Mote> motes = new Vector<Mote>();
private Vector<MoteType> moteTypes = new Vector<MoteType>(); private Vector<MoteType> moteTypes = new Vector<MoteType>();
private int delayTime = 100; private int delayTime = 100;
private int currentSimulationTime = 0; private int currentSimulationTime = 0;
private int tickTime = 1; private int tickTime = 1;
private String title = null; private String title = null;
// Radio Medium
private RadioMedium currentRadioMedium = null; private RadioMedium currentRadioMedium = null;
private static Logger logger = Logger.getLogger(Simulation.class); private static Logger logger = Logger.getLogger(Simulation.class);
private boolean isRunning = false; private boolean isRunning = false;
private boolean stopSimulation = false; private boolean stopSimulation = false;
private Thread thread = null; private Thread thread = null;
private GUI myGUI = null; private GUI myGUI = null;
@ -79,6 +83,7 @@ public class Simulation extends Observable implements Runnable {
notifyObservers(); notifyObservers();
} }
} }
private TickObservable tickObservable = new TickObservable(); private TickObservable tickObservable = new TickObservable();
/** /**
@ -168,10 +173,9 @@ public class Simulation extends Observable implements Runnable {
} }
/** /**
* Creates a new simulation with a delay time of 1 second. * Creates a new simulation with a delay time of 100 ms.
*/ */
public Simulation(GUI gui) { public Simulation(GUI gui) {
// New simulation instance
myGUI = gui; myGUI = gui;
} }
@ -202,12 +206,11 @@ public class Simulation extends Observable implements Runnable {
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
} // else logger.fatal("Could not stop simulation: isRunning=" + isRunning + }
// ", thread=" + thread);
} }
/** /**
* Starts simulation if stopped, ticks all motes once, and finally stop * Starts simulation if stopped, ticks all motes once, and finally stops
* simulation again. * simulation again.
*/ */
public void tickSimulation() { public void tickSimulation() {
@ -228,11 +231,17 @@ public class Simulation extends Observable implements Runnable {
} }
/**
* @return GUI holding this simulation
*/
public GUI getGUI() {
return myGUI;
}
/** /**
* Returns the current simulation config represented by XML elements. This * Returns the current simulation config represented by XML elements. This
* config also includes the current radio medium, all mote types and motes. * config also includes the current radio medium, all mote types and motes.
* *
* @see #saveSimulationConfig(File file)
* @return Current simulation config * @return Current simulation config
*/ */
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
@ -294,21 +303,21 @@ public class Simulation extends Observable implements Runnable {
return config; return config;
} }
/**
* @return GUI holding this simulation
*/
public GUI getGUI() {
return myGUI;
}
/** /**
* Sets the current simulation config depending on the given XML elements. * Sets the current simulation config depending on the given XML elements.
* *
* @see #getConfigXML() * @see #getConfigXML()
* @param configXML * @param configXML
* Config XML elements * Config XML elements
* @param visAvailable
* True if simulation is allowed to show visualizers while loading
* the given config
* @return True if simulation config set successfully
* @throws Exception
* If configuration could not be loaded
*/ */
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) throws Exception { public boolean setConfigXML(Collection<Element> configXML,
boolean visAvailable) throws Exception {
// Parse elements // Parse elements
for (Element element : configXML) { for (Element element : configXML) {
@ -336,13 +345,14 @@ public class Simulation extends Observable implements Runnable {
// Radio medium // Radio medium
if (element.getName().equals("radiomedium")) { if (element.getName().equals("radiomedium")) {
String radioMediumClassName = element.getText().trim(); String radioMediumClassName = element.getText().trim();
Class<? extends RadioMedium> radioMediumClass = myGUI Class<? extends RadioMedium> radioMediumClass = myGUI.tryLoadClass(
.tryLoadClass(this, RadioMedium.class, radioMediumClassName); this, RadioMedium.class, radioMediumClassName);
if (radioMediumClass != null) { if (radioMediumClass != null) {
// Create radio medium specified in config // Create radio medium specified in config
try { try {
currentRadioMedium = RadioMedium.generateRadioMedium(radioMediumClass, this); currentRadioMedium = RadioMedium.generateRadioMedium(
radioMediumClass, this);
} catch (Exception e) { } catch (Exception e) {
currentRadioMedium = null; currentRadioMedium = null;
logger.warn("Could not load radio medium class: " logger.warn("Could not load radio medium class: "
@ -377,8 +387,8 @@ public class Simulation extends Observable implements Runnable {
if (element.getName().equals("motetype")) { if (element.getName().equals("motetype")) {
String moteTypeClassName = element.getText().trim(); String moteTypeClassName = element.getText().trim();
Class<? extends MoteType> moteTypeClass = myGUI.tryLoadClass( Class<? extends MoteType> moteTypeClass = myGUI.tryLoadClass(this,
this, MoteType.class, moteTypeClassName); MoteType.class, moteTypeClassName);
if (moteTypeClass == null) { if (moteTypeClass == null) {
logger.fatal("Could not load mote type class: " + moteTypeClassName); logger.fatal("Could not load mote type class: " + moteTypeClassName);
@ -388,7 +398,8 @@ public class Simulation extends Observable implements Runnable {
MoteType moteType = moteTypeClass.getConstructor((Class[]) null) MoteType moteType = moteTypeClass.getConstructor((Class[]) null)
.newInstance(); .newInstance();
boolean createdOK = moteType.setConfigXML(this, element.getChildren(), visAvailable); boolean createdOK = moteType.setConfigXML(this, element.getChildren(),
visAvailable);
if (createdOK) { if (createdOK) {
addMoteType(moteType); addMoteType(moteType);
} else { } else {
@ -400,8 +411,8 @@ public class Simulation extends Observable implements Runnable {
// Mote // Mote
if (element.getName().equals("mote")) { if (element.getName().equals("mote")) {
Class<? extends Mote> moteClass = myGUI.tryLoadClass(this, Class<? extends Mote> moteClass = myGUI.tryLoadClass(this, Mote.class,
Mote.class, element.getText().trim()); element.getText().trim());
Mote mote = moteClass.getConstructor((Class[]) null).newInstance(); Mote mote = moteClass.getConstructor((Class[]) null).newInstance();
if (mote.setConfigXML(this, element.getChildren(), visAvailable)) { if (mote.setConfigXML(this, element.getChildren(), visAvailable)) {
@ -460,7 +471,7 @@ public class Simulation extends Observable implements Runnable {
* Get a mote from this simulation. * Get a mote from this simulation.
* *
* @param pos * @param pos
* Position of mote * Internal list position of mote
* @return Mote * @return Mote
*/ */
public Mote getMote(int pos) { public Mote getMote(int pos) {
@ -503,7 +514,7 @@ public class Simulation extends Observable implements Runnable {
/** /**
* Adds given mote type to simulation. * Adds given mote type to simulation.
* *
* @param newMoteType * @param newMoteType Mote type
*/ */
public void addMoteType(MoteType newMoteType) { public void addMoteType(MoteType newMoteType) {
moteTypes.add(newMoteType); moteTypes.add(newMoteType);
@ -593,7 +604,7 @@ public class Simulation extends Observable implements Runnable {
} }
this.currentRadioMedium = radioMedium; this.currentRadioMedium = radioMedium;
// Add all current motes to be observered by new radio medium // Add all current motes to the new radio medium
for (int i = 0; i < motes.size(); i++) for (int i = 0; i < motes.size(); i++)
currentRadioMedium.registerMote(motes.get(i), this); currentRadioMedium.registerMote(motes.get(i), this);
} }

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: VisPlugin.java,v 1.3 2007/01/09 10:14:21 fros4943 Exp $ * $Id: VisPlugin.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -38,13 +38,14 @@ import javax.swing.event.InternalFrameListener;
import org.jdom.Element; import org.jdom.Element;
/** /**
* Abstract class VisPlugin should be implemented by plugins for COOJA Simulator. * Abstract class VisPlugin should be implemented by all plugins with
* By extending JInternalFrame, the visual apperence is decided by the plugin itself. * visualizers. By extending JInternalFrame, the visual apperence is decided by
* the plugin itself.
* *
* An implemented plugin should be registered at runtime using the following method: * To add a new plugin to the simulator environment either add it via a user
* GUI.registerPlugin(Class<? extends VisPlugin>, String) * platform or by altering the standard configuration files.
* *
* For example how to implement a plugin see classes SimControl or Vis2D. * For example how to implement a plugin see plugins SimControl or Visualizer2D.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ -104,5 +105,4 @@ public abstract class VisPlugin extends JInternalFrame implements Plugin {
return tag; return tag;
} }
} }