diff --git a/tools/cooja/java/se/sics/cooja/ConnectionLogger.java b/tools/cooja/java/se/sics/cooja/ConnectionLogger.java index e7ba41f1e..2d3fd64d1 100644 --- a/tools/cooja/java/se/sics/cooja/ConnectionLogger.java +++ b/tools/cooja/java/se/sics/cooja/ConnectionLogger.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: ConnectionLogger.java,v 1.3 2006/12/15 12:03:32 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: ConnectionLogger.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $ */ 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 * 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] * [dest_z] DEST_DATA [received data bytes] [newline] * * @see RadioConnection * @see RadioMedium - * * @author Fredrik Osterlind */ public class ConnectionLogger { private static final long serialVersionUID = 1L; + private static Logger logger = Logger.getLogger(ConnectionLogger.class); private static int LOG_TO_FILE = 1; + private static int LOG_TO_LOG4J = 2; + private static int LOG_TO_FILE_AND_LOG4J = 3; private int myType; + private File myFile; /** @@ -123,7 +124,8 @@ public class ConnectionLogger { out.write("SRC_DATA\t".getBytes()); for (byte b : conn.getSourceData()) { 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("\t".getBytes()); @@ -142,9 +144,11 @@ public class ConnectionLogger { out.write("DEST_DATA\t".getBytes()); for (byte b : conn.getDestinationData()[i]) { 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("\t".getBytes()); + } + out.write("\t".getBytes()); out.write("\n".getBytes()); } @@ -164,7 +168,8 @@ public class ConnectionLogger { out.write("SRC_DATA\t".getBytes()); for (byte b : conn.getSourceData()) { 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("\n".getBytes()); diff --git a/tools/cooja/java/se/sics/cooja/CoreComm.java b/tools/cooja/java/se/sics/cooja/CoreComm.java index 377d7c70a..9c97ce900 100644 --- a/tools/cooja/java/se/sics/cooja/CoreComm.java +++ b/tools/cooja/java/se/sics/cooja/CoreComm.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: CoreComm.java,v 1.2 2006/08/23 17:11:09 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: CoreComm.java,v 1.3 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; @@ -35,19 +33,19 @@ import java.io.File; import se.sics.cooja.corecomm.*; /** - * The package corecomm's purpose is communicating with the simulation core - * using Java Native Interface (JNI). Each implementing class (named - * Lib[1-MAX]), loads a shared library which belongs to one mote type. The - * reason for this somewhat strange design is that once loaded, a native library - * cannot be unloaded in Java (yet). Therefore if we wish to load several - * libraries, the names and associated native functions must have unique names. - * And those names are defined via the calling class in JNI. For example, the - * native tick function in class Lib1 is named - * contiki_javasim_corecomm_Lib1_tick. When creating a new mote type, the main - * contiki source file is generated with function names compatible with the next - * available corecomm. This also implies that even if a mote type is deleted, a - * new one cannot be created without restarting the JVM and thus the entire - * simulation. + * The purpose of corecomm's is communicating with a compiled Contiki system + * using Java Native Interface (JNI). Each implemented class (named Lib[1-MAX]), + * loads a shared library which belongs to one mote type. The reason for this + * somewhat strange design is that once loaded, a native library cannot be + * unloaded in Java (in the current versions available). Therefore if we wish to + * load several libraries, the names and associated native functions must have + * unique names. And those names are defined via the calling class in JNI. For + * example, the corresponding function for a native tick method in class Lib1 + * will be named Java_se_sics_cooja_corecomm_Lib1_tick. When creating a new mote + * type, the main Contiki source file is generated with function names + * compatible with the next available corecomm class. This also implies that + * even if a mote type is deleted, a new one cannot be created using the same + * corecomm class without restarting the JVM and thus the entire simulation. * * Each implemented CoreComm class needs read access to the following core * variables: @@ -56,23 +54,23 @@ import se.sics.cooja.corecomm.*; * * and the following native functions: * * * @author Fredrik Osterlind */ 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; // Static pointers to current libraries private final static CoreComm[] coreComms = new CoreComm[MAX_LIBRARIES]; + private final static File[] coreCommFiles = new File[MAX_LIBRARIES]; /** @@ -195,7 +193,7 @@ public abstract class CoreComm { 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) */ protected abstract void init(); diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index f70ec5dba..990e0d9c3 100644 --- a/tools/cooja/java/se/sics/cooja/GUI.java +++ b/tools/cooja/java/se/sics/cooja/GUI.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: GUI.java,v 1.14 2007/01/10 09:03:02 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: GUI.java,v 1.15 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; @@ -39,7 +37,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.*; import java.util.List; - import javax.swing.*; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; @@ -58,12 +55,18 @@ import se.sics.cooja.dialogs.*; 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 */ public class GUI { - + /** * External tools default Win32 settings filename. */ @@ -118,36 +121,44 @@ public class GUI { }; /** - * Main frame for current GUI. - * Null when COOJA is run without GUI! + * Main frame for current GUI. Null when COOJA is run without visualizer! */ public static JFrame frame; private static final long serialVersionUID = 1L; + private static Logger logger = Logger.getLogger(GUI.class); // External tools setting names 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_C_COMPILER", "COMPILER_ARGS", "PATH_LINKER", "PATH_NM", "NM_ARGS", - "PATH_OBJDUMP", "OBJDUMP_ARGS", "LINKER_ARGS_1", - "LINKER_ARGS_2", "CONTIKI_STANDARD_PROCESSES", "CMD_GREP_PROCESSES", + "PATH_OBJDUMP", "OBJDUMP_ARGS", "LINKER_ARGS_1", "LINKER_ARGS_2", + "CONTIKI_STANDARD_PROCESSES", "CMD_GREP_PROCESSES", "REGEXP_PARSE_PROCESSES", "CMD_GREP_INTERFACES", "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_STANDARD_WIDTH = 150; + private static final int FRAME_STANDARD_HEIGHT = 300; private GUI myGUI; + private Simulation mySimulation; + protected Mote selectedMote = null; + protected GUIEventHandler guiEventHandler = new GUIEventHandler(); private JMenu menuPlugins, menuMoteTypeClasses, menuMoteTypes; + private JPopupMenu menuMotePlugins; + private JDesktopPane myDesktopPane; private Vector startedPlugins = new Vector(); @@ -155,14 +166,21 @@ public class GUI { // Platform configuration variables // Maintained via method reparsePlatformConfig() private PlatformConfig platformConfig; + private Vector currentUserPlatforms = new Vector(); + private ClassLoader userPlatformClassLoader; private Vector> moteTypeClasses = new Vector>(); + private Vector> pluginClasses = new Vector>(); + private Vector> pluginClassesTemporary = new Vector>(); + private Vector> radioMediumClasses = new Vector>(); + private Vector> ipDistributorClasses = new Vector>(); + private Vector> positionerClasses = new Vector>(); /** @@ -177,18 +195,18 @@ public class GUI { if (frame != null) { frame.setJMenuBar(createMenuBar()); } - - + // Load default and overwrite with user settings (if any) loadExternalToolsDefaultSettings(); loadExternalToolsUserSettings(); // Register default user platforms - String defaultUserPlatforms = getExternalToolsSetting("DEFAULT_USERPLATFORMS", null); + String defaultUserPlatforms = getExternalToolsSetting( + "DEFAULT_USERPLATFORMS", null); if (defaultUserPlatforms != null) { String[] defaultUserPlatformsArr = defaultUserPlatforms.split(";"); if (defaultUserPlatformsArr.length > 0) { - for (String defaultUserPlatform: defaultUserPlatformsArr) { + for (String defaultUserPlatform : defaultUserPlatformsArr) { File userPlatform = new File(defaultUserPlatform); if (userPlatform.exists() && userPlatform.isDirectory()) { currentUserPlatforms.add(userPlatform); @@ -196,14 +214,13 @@ public class GUI { } } } - + // Load extendable parts (using current platform config) reparsePlatformConfig(); - // EXPERIMENTAL: Start all standard GUI plugins + // Start all standard GUI plugins for (Class visPluginClass : pluginClasses) { - int pluginType = visPluginClass.getAnnotation(PluginType.class) - .value(); + int pluginType = visPluginClass.getAnnotation(PluginType.class).value(); if (pluginType == PluginType.COOJA_STANDARD_PLUGIN) { startPlugin(visPluginClass, this, null, null); } @@ -217,7 +234,7 @@ public class GUI { public boolean isVisualized() { return frame != null; } - + private JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu; @@ -321,8 +338,10 @@ public class GUI { menuMoteTypeClasses.add(menuItem); } } + public void menuDeselected(MenuEvent e) { } + public void menuCanceled(MenuEvent e) { } }); @@ -364,8 +383,10 @@ public class GUI { menuMoteTypes.add(menuItem); } } + public void menuDeselected(MenuEvent e) { } + public void menuCanceled(MenuEvent e) { } }); @@ -421,7 +442,6 @@ public class GUI { frame.setSize(700, 700); frame.addWindowListener(gui.guiEventHandler); - // Display the window. frame.setVisible(true); } @@ -486,7 +506,7 @@ public class GUI { // Add menu bar frame.setSize(700, 700); frame.addWindowListener(gui.guiEventHandler); - + JComponent newContentPane = gui.getDesktopPane(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane); @@ -501,8 +521,8 @@ public class GUI { userPlatforms = new Vector(); 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"); for (String userPlatform : userPlatforms) { logger.info(">> Adding: " + userPlatform); @@ -521,12 +541,12 @@ public class GUI { File contikiBaseDir = new File(getExternalToolsSetting("PATH_CONTIKI")); File contikiCoreDir = new File(contikiBaseDir, getExternalToolsSetting("PATH_COOJA_CORE_RELATIVE")); - File libFile = new File(ContikiMoteType.tempOutputDirectory, - moteTypeID + ContikiMoteType.librarySuffix); - File mapFile = new File(ContikiMoteType.tempOutputDirectory, - moteTypeID + ContikiMoteType.mapSuffix); - File depFile = new File(ContikiMoteType.tempOutputDirectory, - moteTypeID + ContikiMoteType.dependSuffix); + File libFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID + + ContikiMoteType.librarySuffix); + File mapFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID + + ContikiMoteType.mapSuffix); + File depFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID + + ContikiMoteType.dependSuffix); if (libFile.exists()) libFile.delete(); if (depFile.exists()) @@ -772,8 +792,9 @@ public class GUI { GUI.class, "RADIOMEDIUMS")[0]; Class radioMediumClass = gui.tryLoadClass(gui, RadioMedium.class, radioMediumClassName); - - RadioMedium radioMedium = RadioMedium.generateRadioMedium(radioMediumClass, simulation); + + RadioMedium radioMedium = RadioMedium.generateRadioMedium( + radioMediumClass, simulation); simulation.setRadioMedium(radioMedium); } catch (Exception e) { logger.fatal(">> Failed to load radio medium, aborting: " @@ -832,12 +853,12 @@ public class GUI { } return true; } - + // // PLATFORM CONFIG AND EXTENDABLE PARTS METHODS //// /** * Register new mote type class. - * + * * @param moteTypeClass * Class to register */ @@ -861,7 +882,7 @@ public class GUI { /** * Register new IP distributor class - * + * * @param ipDistributorClass * Class to register * @return True if class was registered @@ -870,7 +891,7 @@ public class GUI { Class ipDistributorClass) { // Check that vector constructor exists try { - ipDistributorClass.getConstructor(new Class[]{Vector.class}); + ipDistributorClass.getConstructor(new Class[] { Vector.class }); } catch (Exception e) { logger.fatal("No vector constructor found of IP distributor: " + ipDistributorClass); @@ -897,7 +918,7 @@ public class GUI { /** * Register new positioner class. - * + * * @param positionerClass * Class to register * @return True if class was registered @@ -906,8 +927,8 @@ public class GUI { // Check that interval constructor exists try { positionerClass - .getConstructor(new Class[]{int.class, double.class, double.class, - double.class, double.class, double.class, double.class}); + .getConstructor(new Class[] { int.class, double.class, double.class, + double.class, double.class, double.class, double.class }); } catch (Exception e) { logger.fatal("No interval constructor found of positioner: " + positionerClass); @@ -934,7 +955,7 @@ public class GUI { /** * Register new radio medium class. - * + * * @param radioMediumClass * Class to register * @return True if class was registered @@ -943,8 +964,7 @@ public class GUI { Class radioMediumClass) { // Check that simulation constructor exists try { - radioMediumClass - .getConstructor(new Class[]{Simulation.class}); + radioMediumClass.getConstructor(new Class[] { Simulation.class }); } catch (Exception e) { logger.fatal("No simulation constructor found of radio medium: " + radioMediumClass); @@ -975,9 +995,9 @@ public class GUI { * mediums. This method may still return true even if all classes could not be * registered, but always returns false if all user platform configuration * files were not parsed correctly. - * + * * Any registered temporary plugins will be saved and reregistered. - * + * * @return True if external configuration files were found and parsed OK */ public boolean reparsePlatformConfig() { @@ -1012,15 +1032,15 @@ public class GUI { try { // Append config to general config - // logger.info("Appending user platform configuration: " + userPlatform); + // logger.info("Appending user platform configuration: " + + // userPlatform); platformConfig.appendUserPlatform(userPlatform); } catch (FileNotFoundException e) { - logger.fatal("Could not find platform config file: " - + userPlatform); + logger.fatal("Could not find platform config file: " + userPlatform); return false; } catch (IOException e) { - logger.fatal("Error when reading platform config file: " - + userPlatform); + logger + .fatal("Error when reading platform config file: " + userPlatform); return false; } } @@ -1053,8 +1073,8 @@ public class GUI { "PLUGINS"); if (pluginClassNames != null) { for (String pluginClassName : pluginClassNames) { - Class pluginClass = tryLoadClass(this, - Plugin.class, pluginClassName); + Class pluginClass = tryLoadClass(this, Plugin.class, + pluginClassName); if (pluginClass != null) { registerPlugin(pluginClass); @@ -1136,7 +1156,7 @@ public class GUI { /** * Returns the current platform configuration common to the entire simulator. - * + * * @return Current platform configuration */ public PlatformConfig getPlatformConfig() { @@ -1145,7 +1165,7 @@ public class GUI { /** * Returns the current user platforms common to the entire simulator. - * + * * @return Current user platforms. */ public Vector getUserPlatforms() { @@ -1156,7 +1176,7 @@ public class GUI { /** * Show a started plugin in working area. - * + * * @param plugin * Internal frame to add */ @@ -1175,10 +1195,10 @@ public class GUI { * FRAME_NEW_OFFSET); plugin.setVisible(true); } - + // Deselect all other plugins before selecting the new one try { - for (JInternalFrame existingPlugin: myDesktopPane.getAllFrames()) { + for (JInternalFrame existingPlugin : myDesktopPane.getAllFrames()) { existingPlugin.setSelected(false); } plugin.setSelected(true); @@ -1192,7 +1212,7 @@ public class GUI { /** * Remove a plugin from working area. - * + * * @param plugin * Plugin to remove * @param askUser @@ -1203,7 +1223,7 @@ public class GUI { // Clear any allocated resources and remove plugin plugin.closePlugin(); startedPlugins.remove(plugin); - + // Dispose plugin if it has visualizer if (plugin instanceof VisPlugin) { ((VisPlugin) plugin).dispose(); @@ -1212,7 +1232,7 @@ public class GUI { if (askUser && startedPlugins.isEmpty()) { String s1 = "Remove"; String s2 = "Cancel"; - Object[] options = {s1, s2}; + Object[] options = { s1, s2 }; int n = JOptionPane.showOptionDialog(frame, "You have an active simulation.\nDo you want to remove it?", "Remove current simulation?", JOptionPane.YES_NO_OPTION, @@ -1237,19 +1257,16 @@ public class GUI { * Mote passed as argument to mote plugins * @return Start plugin if any */ - public Plugin startPlugin(Class pluginClass, - GUI gui, - Simulation simulation, - Mote mote - ) { - + public Plugin startPlugin(Class pluginClass, GUI gui, + Simulation simulation, Mote mote) { + // Check that plugin class is registered if (!pluginClasses.contains(pluginClass)) { logger.fatal("Plugin class not registered: " + pluginClass); return null; } - // Check that visualizer plugin is not started without GUI + // Check that visualizer plugin is not started without GUI if (!isVisualized()) { try { pluginClass.asSubclass(VisPlugin.class); @@ -1260,7 +1277,7 @@ public class GUI { } catch (ClassCastException e) { } } - + // Construct plugin depending on plugin type Plugin newPlugin = null; int pluginType = pluginClass.getAnnotation(PluginType.class).value(); @@ -1275,26 +1292,27 @@ public class GUI { newPlugin = pluginClass.getConstructor( new Class[] { Mote.class, Simulation.class, GUI.class }) .newInstance(mote, simulation, gui); - + // Tag plugin with mote newPlugin.tagWithObject(mote); - } else if (pluginType == PluginType.SIM_PLUGIN || - pluginType == PluginType.SIM_STANDARD_PLUGIN) { + } else if (pluginType == PluginType.SIM_PLUGIN + || pluginType == PluginType.SIM_STANDARD_PLUGIN) { if (simulation == null) { logger.fatal("Can't start simulation plugin (no simulation)"); return null; } - newPlugin = pluginClass.getConstructor(new Class[]{Simulation.class, GUI.class}) - .newInstance(simulation, gui); - } else if (pluginType == PluginType.COOJA_PLUGIN || - pluginType == PluginType.COOJA_STANDARD_PLUGIN) { + newPlugin = pluginClass.getConstructor( + new Class[] { Simulation.class, GUI.class }).newInstance( + simulation, gui); + } else if (pluginType == PluginType.COOJA_PLUGIN + || pluginType == PluginType.COOJA_STANDARD_PLUGIN) { if (gui == null) { logger.fatal("Can't start COOJA plugin (no GUI)"); return null; } - newPlugin = pluginClass.getConstructor(new Class[]{GUI.class}) + newPlugin = pluginClass.getConstructor(new Class[] { GUI.class }) .newInstance(gui); } } catch (Exception e) { @@ -1308,7 +1326,7 @@ public class GUI { // Add to active plugins list startedPlugins.add(newPlugin); - + // Show plugin if visualizer type if (newPlugin instanceof VisPlugin) { myGUI.showPlugin((VisPlugin) newPlugin); @@ -1320,7 +1338,7 @@ public class GUI { /** * Register a plugin to be included in the GUI. The plugin will be visible in * the menubar. - * + * * @param newPluginClass * New plugin to register * @return True if this plugin was registered ok, false otherwise @@ -1333,13 +1351,12 @@ public class GUI { * Register a temporary plugin to be included in the GUI. The plugin will be * visible in the menubar. This plugin will automatically be unregistered if * the current simulation is removed. - * + * * @param newPluginClass * New plugin to register * @return True if this plugin was registered ok, false otherwise */ - public boolean registerTemporaryPlugin( - Class newPluginClass) { + public boolean registerTemporaryPlugin(Class newPluginClass) { if (pluginClasses.contains(newPluginClass)) return false; @@ -1353,7 +1370,7 @@ public class GUI { /** * Unregister a plugin class. Removes any plugin menu items links as well. - * + * * @param pluginClass * Plugin class to unregister */ @@ -1384,7 +1401,7 @@ public class GUI { /** * Register a plugin to be included in the GUI. - * + * * @param newPluginClass * New plugin to register * @param addToMenu @@ -1408,13 +1425,15 @@ public class GUI { // Check that plugin type is valid and constructor exists try { if (pluginType == PluginType.MOTE_PLUGIN) { - newPluginClass.getConstructor(new Class[]{Mote.class, Simulation.class, GUI.class}); - } else if (pluginType == PluginType.SIM_PLUGIN || - pluginType == PluginType.SIM_STANDARD_PLUGIN) { - newPluginClass.getConstructor(new Class[]{Simulation.class, GUI.class}); - } else if (pluginType == PluginType.COOJA_PLUGIN || - pluginType == PluginType.COOJA_STANDARD_PLUGIN) { - newPluginClass.getConstructor(new Class[]{GUI.class}); + newPluginClass.getConstructor(new Class[] { Mote.class, + Simulation.class, GUI.class }); + } else if (pluginType == PluginType.SIM_PLUGIN + || pluginType == PluginType.SIM_STANDARD_PLUGIN) { + newPluginClass + .getConstructor(new Class[] { Simulation.class, GUI.class }); + } else if (pluginType == PluginType.COOJA_PLUGIN + || pluginType == PluginType.COOJA_STANDARD_PLUGIN) { + newPluginClass.getConstructor(new Class[] { GUI.class }); } else { logger.fatal("Could not find valid plugin type annotation in class " + newPluginClass); @@ -1467,7 +1486,7 @@ public class GUI { /** * Show mote plugins menu for starting a mote plugin. All registered mote * plugins can be selected from. - * + * * @param invoker * Component that wants to display the menu * @param mote @@ -1490,7 +1509,7 @@ public class GUI { public Simulation getSimulation() { return mySimulation; } - + public void setSimulation(Simulation sim) { if (sim != null) { doRemoveSimulation(false); @@ -1531,7 +1550,8 @@ public class GUI { boolean moteTypeOK = false; try { newMoteType = moteTypeClass.newInstance(); - moteTypeOK = newMoteType.configureAndInit(frame, mySimulation, isVisualized()); + moteTypeOK = newMoteType.configureAndInit(frame, mySimulation, + isVisualized()); } catch (Exception e) { logger.fatal("Exception when creating mote type: " + e); return; @@ -1545,7 +1565,7 @@ public class GUI { /** * Remove current simulation - * + * * @param askForConfirmation * Should we ask for confirmation if a simulation is already active? */ @@ -1555,7 +1575,7 @@ public class GUI { if (askForConfirmation) { String s1 = "Remove"; String s2 = "Cancel"; - Object[] options = {s1, s2}; + Object[] options = { s1, s2 }; int n = JOptionPane.showOptionDialog(frame, "You have an active simulation.\nDo you want to remove it?", "Remove current simulation?", JOptionPane.YES_NO_OPTION, @@ -1566,11 +1586,12 @@ public class GUI { } // Close all started non-GUI plugins - for (Object startedPlugin: startedPlugins.toArray()) { - int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); - if (pluginType != PluginType.COOJA_PLUGIN && - pluginType != PluginType.COOJA_STANDARD_PLUGIN) - removePlugin((Plugin)startedPlugin, false); + for (Object startedPlugin : startedPlugins.toArray()) { + int pluginType = startedPlugin.getClass().getAnnotation( + PluginType.class).value(); + if (pluginType != PluginType.COOJA_PLUGIN + && pluginType != PluginType.COOJA_STANDARD_PLUGIN) + removePlugin((Plugin) startedPlugin, false); } // Delete simulation @@ -1592,7 +1613,7 @@ public class GUI { /** * Load a simulation configuration file from disk - * + * * @param askForConfirmation * Should we ask for confirmation if a simulation is already active? */ @@ -1610,7 +1631,7 @@ public class GUI { if (askForConfirmation && mySimulation != null) { String s1 = "Remove"; String s2 = "Cancel"; - Object[] options = {s1, s2}; + Object[] options = { s1, s2 }; int n = JOptionPane.showOptionDialog(frame, "You have an active simulation.\nDo you want to remove it?", "Remove current simulation?", JOptionPane.YES_NO_OPTION, @@ -1658,7 +1679,7 @@ public class GUI { /** * Save current simulation configuration to disk - * + * * @param askForConfirmation * Ask for confirmation before overwriting file */ @@ -1682,7 +1703,7 @@ public class GUI { if (askForConfirmation) { String s1 = "Overwrite"; String s2 = "Cancel"; - Object[] options = {s1, s2}; + Object[] options = { s1, s2 }; int n = JOptionPane .showOptionDialog( frame, @@ -1713,7 +1734,8 @@ public class GUI { if (mySimulation != null) { mySimulation.stopSimulation(); - Vector newMotes = AddMoteDialog.showDialog(frame, mySimulation, moteType); + Vector newMotes = AddMoteDialog.showDialog(frame, mySimulation, + moteType); if (newMotes != null) { for (Mote newMote : newMotes) mySimulation.addMote(newMote); @@ -1725,7 +1747,7 @@ public class GUI { /** * Create a new simulation - * + * * @param askForConfirmation * Should we ask for confirmation if a simulation is already active? */ @@ -1733,7 +1755,7 @@ public class GUI { if (askForConfirmation && mySimulation != null) { String s1 = "Remove"; String s2 = "Cancel"; - Object[] options = {s1, s2}; + Object[] options = { s1, s2 }; int n = JOptionPane.showOptionDialog(frame, "You have an active simulation.\nDo you want to remove it?", "Remove current simulation?", JOptionPane.YES_NO_OPTION, @@ -1754,7 +1776,7 @@ public class GUI { /** * Quit program - * + * * @param askForConfirmation * Should we ask for confirmation before quitting? */ @@ -1762,7 +1784,7 @@ public class GUI { if (askForConfirmation) { String s1 = "Quit"; String s2 = "Cancel"; - Object[] options = {s1, s2}; + Object[] options = { s1, s2 }; int n = JOptionPane.showOptionDialog(frame, "Sure you want to quit?", "Close COOJA Simulator", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, s1); @@ -1772,7 +1794,7 @@ public class GUI { // Clean up resources Object[] plugins = startedPlugins.toArray(); - for (Object plugin: plugins) + for (Object plugin : plugins) removePlugin((Plugin) plugin, false); System.exit(0); @@ -1789,7 +1811,7 @@ public class GUI { /** * Get name of external tools setting at given index. - * + * * @param index * Setting index * @return Name @@ -1863,7 +1885,7 @@ public class GUI { private static void loadExternalToolsUserSettings() { File configFile = new File(System.getProperty("user.home"), GUI.EXTERNAL_TOOLS_USER_SETTINGS_FILENAME); - + try { FileInputStream in = new FileInputStream(configFile); Properties settings = new Properties(); @@ -1888,15 +1910,16 @@ public class GUI { * Save external tools user settings to file. */ 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 { FileOutputStream out = new FileOutputStream(configFile); currentExternalToolsSettings.store(out, "COOJA User Settings"); out.close(); } catch (FileNotFoundException ex) { // Could not open settings file for writing, aborting - logger.warn("Could not save external tools user settings to " + configFile - + ", aborting"); + logger.warn("Could not save external tools user settings to " + + configFile + ", aborting"); } catch (IOException ex) { // Could not open settings file for writing, aborting logger.warn("Error while saving external tools user settings to " @@ -1909,14 +1932,19 @@ public class GUI { private class GUIEventHandler implements ActionListener, WindowListener { public void windowDeactivated(WindowEvent e) { } + public void windowIconified(WindowEvent e) { } + public void windowDeiconified(WindowEvent e) { } + public void windowOpened(WindowEvent e) { } + public void windowClosed(WindowEvent e) { } + public void windowActivated(WindowEvent e) { } @@ -1947,7 +1975,7 @@ public class GUI { ExternalToolsDialog.showDialog(frame); } else if (e.getActionCommand().equals("close plugins")) { Object[] plugins = startedPlugins.toArray(); - for (Object plugin: plugins) + for (Object plugin : plugins) removePlugin((Plugin) plugin, false); } else if (e.getActionCommand().equals("manage platforms")) { Vector newPlatforms = UserPlatformsDialog.showDialog(frame, @@ -1969,7 +1997,7 @@ public class GUI { /** * Help method that tries to load and initialize a class with given name. - * + * * @param * Class extending given class type * @param classType @@ -2013,7 +2041,8 @@ public class GUI { } private ClassLoader createClassLoader(Vector currentUserPlatforms) { - return createClassLoader(ClassLoader.getSystemClassLoader(), currentUserPlatforms); + return createClassLoader(ClassLoader.getSystemClassLoader(), + currentUserPlatforms); } private File findJarFile(File platformPath, String jarfile) { @@ -2038,7 +2067,7 @@ public class GUI { if (platformsList == null || platformsList.isEmpty()) { return parent; } - + // Combine class loader from all user platforms (including any // specified JAR files) ArrayList urls = new ArrayList(); @@ -2046,7 +2075,7 @@ public class GUI { File userPlatform = platformsList.get(j); try { urls.add((new File(userPlatform, "java")).toURL()); - + // Read configuration to check if any JAR files should be loaded PlatformConfig userPlatformConfig = new PlatformConfig(false); userPlatformConfig.appendUserPlatform(userPlatform); @@ -2061,21 +2090,22 @@ public class GUI { urls.add(jarpath.toURL()); } } - + } catch (Exception e) { logger.fatal("Error when trying to read JAR-file in " + userPlatform + ": " + e); } } - - return new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]), parent); + + return new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]), + parent); } - + /** * Help method that returns the description for given object. This method * reads from the object's class annotations if existing. Otherwise it returns * the simple class name of object's class. - * + * * @param object * Object * @return Description @@ -2088,7 +2118,7 @@ public class GUI { * Help method that returns the description for given class. This method reads * from class annotations if existing. Otherwise it returns the simple class * name. - * + * * @param clazz * Class * @return Description @@ -2221,7 +2251,7 @@ public class GUI { } } - + /** * Loads a simulation configuration from given file. * @@ -2235,7 +2265,8 @@ public class GUI { * @throws UnsatisfiedLinkError * 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; @@ -2286,8 +2317,7 @@ public class GUI { * Saves current simulation configuration to given file and notifies * observers. * - * @see #loadSimulationConfig(File file) - * @see #getConfigXML() + * @see #loadSimulationConfig(File, boolean) * @param file * File to write */ @@ -2299,12 +2329,12 @@ public class GUI { Element simulationElement = new Element("simulation"); simulationElement.addContent(mySimulation.getConfigXML()); root.addContent(simulationElement); - + // Create started plugins config Collection pluginsConfig = getPluginsConfigXML(); if (pluginsConfig != null) root.addContent(pluginsConfig); - + // Create and write to document Document doc = new Document(root); FileOutputStream out = new FileOutputStream(file); @@ -2322,27 +2352,30 @@ public class GUI { /** * Returns started plugins config. + * * @return Config or null */ public Collection getPluginsConfigXML() { Vector config = new Vector(); - + // Loop through all started plugins // (Only return config of non-GUI plugins) Element pluginElement, pluginSubElement; - for (Plugin startedPlugin: startedPlugins) { - int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); - + for (Plugin startedPlugin : startedPlugins) { + int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class) + .value(); + // Ignore GUI plugins - if (pluginType == PluginType.COOJA_PLUGIN || - pluginType == PluginType.COOJA_STANDARD_PLUGIN) + if (pluginType == PluginType.COOJA_PLUGIN + || pluginType == PluginType.COOJA_STANDARD_PLUGIN) continue; - + pluginElement = new Element("plugin"); pluginElement.setText(startedPlugin.getClass().getName()); - + // 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"); Mote taggedMote = (Mote) startedPlugin.getTag(); for (int moteNr = 0; moteNr < mySimulation.getMotesCount(); moteNr++) { @@ -2361,39 +2394,41 @@ public class GUI { pluginSubElement.addContent(pluginXML); pluginElement.addContent(pluginSubElement); } - + // If plugin is visualizer plugin, create visualization arguments if (startedPlugin instanceof VisPlugin) { VisPlugin startedVisPlugin = (VisPlugin) startedPlugin; - + pluginSubElement = new Element("width"); pluginSubElement.setText("" + startedVisPlugin.getSize().width); pluginElement.addContent(pluginSubElement); - + pluginSubElement = new Element("z"); - pluginSubElement.setText("" + getDesktopPane().getComponentZOrder(startedVisPlugin)); + pluginSubElement.setText("" + + getDesktopPane().getComponentZOrder(startedVisPlugin)); pluginElement.addContent(pluginSubElement); - + pluginSubElement = new Element("height"); pluginSubElement.setText("" + startedVisPlugin.getSize().height); pluginElement.addContent(pluginSubElement); - + pluginSubElement = new Element("location_x"); pluginSubElement.setText("" + startedVisPlugin.getLocation().x); pluginElement.addContent(pluginSubElement); - + pluginSubElement = new Element("location_y"); pluginSubElement.setText("" + startedVisPlugin.getLocation().y); pluginElement.addContent(pluginSubElement); - + pluginSubElement = new Element("minimized"); - pluginSubElement.setText(new Boolean(startedVisPlugin.isIcon()).toString()); + pluginSubElement.setText(new Boolean(startedVisPlugin.isIcon()) + .toString()); pluginElement.addContent(pluginSubElement); } - + config.add(pluginElement); } - + return config; } @@ -2433,14 +2468,15 @@ public class GUI { } // Start plugin (before applying rest of config) - Plugin startedPlugin = startPlugin(visPluginClass, this, - simulation, mote); + Plugin startedPlugin = startPlugin(visPluginClass, this, simulation, + mote); // Apply plugin specific configuration for (Element pluginSubElement : (List) pluginElement .getChildren()) { if (pluginSubElement.getName().equals("plugin_config")) { - startedPlugin.setConfigXML(pluginSubElement.getChildren(), visAvailable); + startedPlugin.setConfigXML(pluginSubElement.getChildren(), + visAvailable); } } @@ -2477,14 +2513,15 @@ public class GUI { // Ignoring } } else if (pluginSubElement.getName().equals("plugin_config")) { - startedVisPlugin.setConfigXML(pluginSubElement.getChildren(), visAvailable); + startedVisPlugin.setConfigXML(pluginSubElement.getChildren(), + visAvailable); } } } } } - + // For all started visplugins, check if they have a zorder property for (JInternalFrame plugin : getDesktopPane().getAllFrames()) { if (plugin.getClientProperty("zorder") != null) { diff --git a/tools/cooja/java/se/sics/cooja/IPDistributor.java b/tools/cooja/java/se/sics/cooja/IPDistributor.java index 1e6cb8f8a..8dc96b800 100644 --- a/tools/cooja/java/se/sics/cooja/IPDistributor.java +++ b/tools/cooja/java/se/sics/cooja/IPDistributor.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: IPDistributor.java,v 1.1 2006/08/21 12:12:56 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: IPDistributor.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $ */ 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. * + * @see se.sics.cooja.Positioner * @author Fredrik Osterlind */ public abstract class IPDistributor { @@ -48,17 +47,19 @@ public abstract class IPDistributor { * constructor argument. Instead of calling the constructors directly this * method may be used. * - * @param ipDistClass Class - * @param newMotes All motes that later should be assigned IP numbers + * @param ipDistClass + * Class + * @param newMotes + * All motes that later should be assigned IP numbers * @return IP distributor instance */ - public static final IPDistributor generateInterface( + public static final IPDistributor generateIPDistributor( Class ipDistClass, Vector newMotes) { try { // Generating IP distributor Constructor constr = ipDistClass - .getConstructor(new Class[]{Vector.class}); - return (IPDistributor) constr.newInstance(new Object[]{newMotes}); + .getConstructor(new Class[] { Vector.class }); + return (IPDistributor) constr.newInstance(new Object[] { newMotes }); } catch (Exception e) { logger.fatal("Exception when creating " + ipDistClass + ": " + e); 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(); diff --git a/tools/cooja/java/se/sics/cooja/Mote.java b/tools/cooja/java/se/sics/cooja/Mote.java index 6fc90d390..3eb6c6218 100644 --- a/tools/cooja/java/se/sics/cooja/Mote.java +++ b/tools/cooja/java/se/sics/cooja/Mote.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: Mote.java,v 1.3 2007/01/09 10:16:26 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: Mote.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; @@ -36,10 +34,11 @@ import java.util.Observer; 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. - * Motes in different states may be handled differently by the for example simulation loops and plugins. + * A mote is always in some state, describing the status of the CPU etc. Motes + * 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. * @@ -55,16 +54,20 @@ public interface Mote { * Possible mote states */ public static enum State { - ACTIVE, // Active state - LPM, // Low power mode (sleeping) - DEAD // Dead (for example out of batteries) + /* Active state */ + ACTIVE, + /* Low power mode (sleeping) */ + LPM, + /* Dead (for example out of batteries) */ + DEAD } - + /** - * Tries to change state to given argument. - * A dead mote can typically not change state, while a sleeping or active mote can. + * Tries to change state to given argument. A dead mote can typically not + * 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); @@ -74,11 +77,11 @@ public interface Mote { public State getState(); /** - * Adds new state observer. - * This observer is notified if mote changes state. - * + * Adds new state observer. This observer is notified if mote changes state. + * * @see #deleteStateObserver(Observer) - * @param newObserver New observer + * @param newObserver + * New observer */ public void addStateObserver(Observer newObserver); @@ -86,11 +89,11 @@ public interface Mote { * Delete existing state observer. * * @see #addStateObserver(Observer) - * @param newObserver Registered state observer + * @param newObserver + * Registered state observer */ public void deleteStateObserver(Observer newObserver); - /** * Returns the interface handler of this mote. * @@ -102,12 +105,12 @@ public interface Mote { /** * Sets the interface handler of this mote. * - * @param moteInterfaceHandler New interface handler + * @param moteInterfaceHandler + * New interface handler * @see #getInterfaces() */ public void setInterfaces(MoteInterfaceHandler moteInterfaceHandler); - /** * Returns the memory of this mote. * @@ -120,11 +123,11 @@ public interface Mote { * Sets the memory of this mote. * * @see #getMemory() - * @param memory Mote memory + * @param memory + * Mote memory */ public void setMemory(MoteMemory memory); - /** * Returns mote type. * @@ -137,11 +140,11 @@ public interface Mote { * Sets mote type to given argument. * * @see #getType() - * @param type New type + * @param type + * New type */ public void setType(MoteType type); - /** * Returns simulation which holds this mote. * @@ -149,42 +152,42 @@ public interface Mote { * @return Simulation */ public Simulation getSimulation(); - + /** * Sets the simulation which holds this mote. * * @see #getSimulation() - * @param simulation Simulation + * @param simulation + * Simulation */ public void setSimulation(Simulation simulation); /** * Ticks this mote and increases any internal time to given argument. * - * Each mote implementation may handle calls to this method differently, - * but, if existing, the simulated mote should at least handle one event. + * Each mote implementation may handle calls to this method differently, but + * 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 - * polls all interfaces, - * activates the memory, - * lets the underlying mote software handle one event, - * fetches the updated memory and - * finally polls all interfaces again. - * - * @param simTime New simulation time + * A call to this method typically polls all interfaces, activates the memory, + * lets the underlying mote software handle one event, fetches the updated + * memory and finally polls all interfaces again. + * + * @param simTime + * New simulation time */ public void tick(int simTime); - + /** - * Returns XML elements representing the current config of this mote. - * This is fetched by the simulator for example when saving a simulation configuration file. - * For example a mote may return the configs of all its interfaces. - * This method should however not return state specific information such as the mote state. - * (All nodes are restarted when loading a simulation.) + * Returns XML elements representing the current config of this mote. This is + * fetched by the simulator for example when saving a simulation configuration + * file. For example a mote may return the configs of all its interfaces. This + * method should however not return state specific information such as the + * 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 */ public abstract Collection getConfigXML(); @@ -192,11 +195,14 @@ public interface Mote { /** * Sets the current mote config depending on the given XML elements. * - * @param simulation Simulation holding this mote - * @param configXML Config XML elements + * @param simulation + * Simulation holding this mote + * @param configXML + * Config XML elements * * @see #getConfigXML() */ - public abstract boolean setConfigXML(Simulation simulation, Collection configXML, boolean visAvailable); + public abstract boolean setConfigXML(Simulation simulation, + Collection configXML, boolean visAvailable); } diff --git a/tools/cooja/java/se/sics/cooja/MoteInterface.java b/tools/cooja/java/se/sics/cooja/MoteInterface.java index 549eabef3..ec2233616 100644 --- a/tools/cooja/java/se/sics/cooja/MoteInterface.java +++ b/tools/cooja/java/se/sics/cooja/MoteInterface.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: MoteInterface.java,v 1.2 2007/01/09 10:16:42 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: MoteInterface.java,v 1.3 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; @@ -38,16 +36,19 @@ import org.apache.log4j.Logger; import org.jdom.Element; /** - * A mote interface represents a mote property. - * Often this is a simulated hardware peripheral such as a button or a led. - * This can also be a property the mote software itself is unaware of, - * for example the current position of the mote. + * A mote interface represents a mote property. Often this is a simulated + * hardware peripheral such as a button or a led. This can also be a property + * the mote software itself is unaware of, for example the current position of + * 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. - * In order to create a passive interfaces, the class should also implement the dummy Java interface PassiveMoteInterface. - * For an explanation of the differences of active and passive interfaces see class PassiveMoteInterface. + * Interfaces are divided into active and passive interfaces, which are handled + * differently. In order to create a passive interface, the class should also + * implement the dummy Java interface PassiveMoteInterface. For an explanation + * of the differences of active and passive interfaces see class + * PassiveMoteInterface. * * @see PassiveMoteInterface * @author Fredrik Osterlind @@ -56,19 +57,23 @@ public abstract class MoteInterface extends Observable { private static Logger logger = Logger.getLogger(MoteInterface.class); /** - * This method creates an instance of the given class with the given mote as constructor - * argument. Instead of calling the interface constructors directly this method may be used. - * - * @param interfaceClass Mote interface class - * @param mote Mote that will hold the interface + * This method creates an instance of the given class with the given mote as + * constructor argument. Instead of calling the interface constructors + * directly this method may be used. + * + * @param interfaceClass + * Mote interface class + * @param mote + * Mote that will hold the interface * @return Mote interface instance */ - public static final MoteInterface generateInterface(Class interfaceClass, Mote mote) { + public static final MoteInterface generateInterface( + Class interfaceClass, Mote mote) { try { // Generating interface MoteInterface instance = (MoteInterface) interfaceClass.getConstructor( new Class[] { Mote.class }).newInstance(new Object[] { mote }); - + return instance; } catch (Exception e) { logger.fatal("Exception when creating " + interfaceClass + ": " + e); @@ -87,12 +92,12 @@ public abstract class MoteInterface extends Observable { public abstract void doActionsAfterTick(); /** - * Returns a panel with interesting data for this interface. - * This could for example show last messages sent/received for - * a radio interface, or logged message for a log interface. + * Returns a panel with interesting data for this interface. This could for + * example show last messages sent/received for a radio interface, or logged + * message for a log interface. * - * All panels returned from this method must later be released - * for memory reasons. + * All panels returned from this method must later be released for memory + * reasons. * * If returned panel is null, this interface will not be visualized. * @@ -103,46 +108,55 @@ public abstract class MoteInterface extends Observable { /** * 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() - * @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); - + /** - * Returns approximated energy consumed (mQ) during the current tick. - * If the interface is active, this information must be available after the doActionsAfterTick method. - * If the interface is passive, this information must be available after the doActionsBeforeTick method. + * Returns approximated energy consumed (mQ) during the current tick. If the + * interface is active, this information must be available after the + * 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, - * 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 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 - * 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 sending something which would take longer than one tick, it may either return - * the total energy used directly, or a smaller amount during several ticks. + * The interface is responsible to gather information about the current + * 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 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 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 sending something which would take longer than + * 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 all energy used during one tick and decreases the battery energy + * left. * - * This method may typically be used by the passive interface battery, which sums up - * all energy used during one tick and decreases the battery energy left. - * * @see se.sics.cooja.interfaces.Battery * @return Energy consumption of this device during the current tick */ public abstract double energyConsumptionPerTick(); /** - * Returns XML elements representing the current config of this mote interface. - * This is fetched by the simulator for example when saving a simulation configuration file. - * For example an IP interface may return one element with the mote IP address. - * This method should however not return state specific information such as a log history. - * (All nodes are restarted when loading a simulation.) + * Returns XML elements representing the current config of this mote + * interface. This is fetched by the simulator for example when saving a + * simulation configuration file. For example an IP interface may return one + * element with the mote IP address. This method should however not return + * 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 */ public abstract Collection getConfigXML(); @@ -151,8 +165,12 @@ public abstract class MoteInterface extends Observable { * Sets the current mote interface config depending on the given XML elements. * * @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 configXML, boolean visAvailable); - + public abstract void setConfigXML(Collection configXML, + boolean visAvailable); + } diff --git a/tools/cooja/java/se/sics/cooja/MoteInterfaceHandler.java b/tools/cooja/java/se/sics/cooja/MoteInterfaceHandler.java index c4f45ded6..ae86a224b 100644 --- a/tools/cooja/java/se/sics/cooja/MoteInterfaceHandler.java +++ b/tools/cooja/java/se/sics/cooja/MoteInterfaceHandler.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: MoteInterfaceHandler.java,v 1.1 2006/08/21 12:12:56 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: MoteInterfaceHandler.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $ */ 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 * 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, for example when visualizing nodes.) + * position, for example a typical visualizer.) * * Interfaces are divided into active and passive interfaces. Active interfaces * 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 Battery myBattery; + private Beeper myBeeper; + private Button myButton; + private Clock myClock; + private IPAddress myIPAddress; + private LED myLED; + private Log myLog; + private MoteID myMoteID; + private PIR myPIR; + private Position myPosition; + private Radio myRadio; private Vector myActiveInterfaces = new Vector(); + private Vector myPassiveInterfaces = new Vector(); /** @@ -120,13 +129,15 @@ public class MoteInterfaceHandler { */ public N getInterfaceOfType(Class interfaceType) { - Enumeration allActive = myActiveInterfaces.elements(); + Enumeration allActive = myActiveInterfaces + .elements(); while (allActive.hasMoreElements()) { N nextInterface = (N) allActive.nextElement(); if (interfaceType.isAssignableFrom(nextInterface.getClass())) return nextInterface; } - Enumeration allPassive = myPassiveInterfaces.elements(); + Enumeration allPassive = myPassiveInterfaces + .elements(); while (allPassive.hasMoreElements()) { N nextInterface = (N) allPassive.nextElement(); if (interfaceType.isAssignableFrom(nextInterface.getClass())) @@ -266,7 +277,7 @@ public class MoteInterfaceHandler { } return myRadio; } - + /** * Polls all active interfaces. This method should be called during a mote * tick before the mote software is executed. diff --git a/tools/cooja/java/se/sics/cooja/MoteMemory.java b/tools/cooja/java/se/sics/cooja/MoteMemory.java index 3f69b93b0..08184a0d9 100644 --- a/tools/cooja/java/se/sics/cooja/MoteMemory.java +++ b/tools/cooja/java/se/sics/cooja/MoteMemory.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 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; @@ -41,6 +41,7 @@ package se.sics.cooja; * different memory sections, not covering the entire range * between the start address and the end address of this memory. * + * @see se.sics.cooja.SectionMoteMemory * @author Fredrik Osterlind */ public interface MoteMemory { @@ -49,7 +50,7 @@ public interface MoteMemory { * Clears the entire memory. */ public void clearMemory(); - + /** * Returns a memory segment. * diff --git a/tools/cooja/java/se/sics/cooja/MoteType.java b/tools/cooja/java/se/sics/cooja/MoteType.java index b193584a0..df15e5914 100644 --- a/tools/cooja/java/se/sics/cooja/MoteType.java +++ b/tools/cooja/java/se/sics/cooja/MoteType.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: MoteType.java,v 1.2 2007/01/09 10:16:26 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: MoteType.java,v 1.3 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; @@ -37,15 +35,14 @@ import javax.swing.JPanel; import org.jdom.Element; /** - * Every simulated motes belongs to a mote type. - * * The mote type defines properties common for several motes. These properties * may differ between different implementations, but typically includes how a * mote of that type is initialized, which hardware peripherals each mote has * etc. + * Every simulated motes must belong to a mote type. * * A mote type may also hold the connection to an underlying simulation - * framework. + * framework, such as a compiled Contiki system. * * @author Fredrik Osterlind */ @@ -99,7 +96,7 @@ public interface MoteType { * Generates a mote of this mote type. * * @param simulation - * Newly created mote's simulation + * Simulation that will contain mote * @return New mote */ public Mote generateMote(Simulation simulation); @@ -116,16 +113,19 @@ public interface MoteType { * Parent frame or null * @param simulation * 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 */ - 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. * This is fetched by the simulator for example when saving a simulation * 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 */ public Collection getConfigXML(); @@ -141,6 +141,8 @@ public interface MoteType { * Simulation that will hold the mote type * @param configXML * Config XML elements + * @param visAvailable + * True if this method is allowed to show a visualizer * @return True if config was set successfully, false otherwise */ public boolean setConfigXML(Simulation simulation, diff --git a/tools/cooja/java/se/sics/cooja/PassiveMoteInterface.java b/tools/cooja/java/se/sics/cooja/PassiveMoteInterface.java index fc4aa0989..5d8f375a9 100644 --- a/tools/cooja/java/se/sics/cooja/PassiveMoteInterface.java +++ b/tools/cooja/java/se/sics/cooja/PassiveMoteInterface.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 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; @@ -34,19 +34,18 @@ package se.sics.cooja; /** * Mote interfaces are divided into active and passive interfaces. * - * A passive mote interface is treated different than an ordinary (active) - * mote interface; - * Passive interfaces are allowed to act even when the mote is sleeping, - * while active interface only acts when the mote is in active state. + * A passive mote interface is treated different than an ordinary (active) mote + * interface; Passive interfaces are allowed to act even when the mote is + * sleeping, while active interface only acts when the mote is in active state. * - * A typical active interface is the radio interface, since radio - * messages only can be received when the mote is active. + * A typical active interface is the radio interface, since radio messages only + * can be received when the mote is active. * - * A typical passive interface is the battery interface, since a mote - * consumes energy even though it is sleeping. + * A typical passive interface is the battery interface, since a mote consumes + * energy even though it is sleeping. * - * All passive interface should implement this interface. - * All interfaces not implemented this interface will be handled as active interfaces. + * All passive interface should implement this interface. All interfaces not + * implemented this interface will be handled as active interfaces. * * Any energy required by this interface must be available after the * doActionsBeforeTick method. diff --git a/tools/cooja/java/se/sics/cooja/PlatformConfig.java b/tools/cooja/java/se/sics/cooja/PlatformConfig.java index 7417d2576..79ece4ca4 100644 --- a/tools/cooja/java/se/sics/cooja/PlatformConfig.java +++ b/tools/cooja/java/se/sics/cooja/PlatformConfig.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 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; @@ -149,12 +149,12 @@ public class PlatformConfig { * instead. * * @param callingClass - * Class which value belongs to + * Class which value belong to * @param key * Key - * @param value - * Element of array - * @return User platform + * @param arrayElement + * Value or array element + * @return User platform defining arguments or null */ public File getUserPlatformDefining(Class callingClass, String key, String arrayElement) { diff --git a/tools/cooja/java/se/sics/cooja/Plugin.java b/tools/cooja/java/se/sics/cooja/Plugin.java index 506b57406..4b0573604 100644 --- a/tools/cooja/java/se/sics/cooja/Plugin.java +++ b/tools/cooja/java/se/sics/cooja/Plugin.java @@ -26,30 +26,30 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 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; import java.util.Collection; - 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. * + * @see se.sics.cooja.VisPlugin * @author Fredrik Osterlind */ public interface Plugin { - + /** * This method is called when an opened plugin is about to close. * It should release any resources such as registered observers or * opened interface visualizers. */ public void closePlugin(); - + /** * This method is used by the simulator for book-keeping purposes, and should * normally not be called by the plugin itself. @@ -66,8 +66,7 @@ public interface Plugin { * @return Object */ public Object getTag(); - - + /** * Returns XML elements representing the current config of this plugin. This * is fetched by the simulator for example when saving a simulation @@ -76,11 +75,11 @@ public interface Plugin { * such as the value of a mote LED, or total number of motes. (All nodes are * restarted when loading a simulation.) * - * @see #setConfigXML(Collection) + * @see #setConfigXML(Collection, boolean) * @return XML elements representing the current radio medium config */ public Collection getConfigXML(); - + /** * Sets the current plugin config depending on the given XML elements. * @@ -89,6 +88,7 @@ public interface Plugin { * Config XML elements * @return True if config was set successfully, false otherwise */ - public boolean setConfigXML(Collection configXML, boolean visAvailable); + public boolean setConfigXML(Collection configXML, + boolean visAvailable); } diff --git a/tools/cooja/java/se/sics/cooja/PluginType.java b/tools/cooja/java/se/sics/cooja/PluginType.java index f7f6505d5..16084db25 100644 --- a/tools/cooja/java/se/sics/cooja/PluginType.java +++ b/tools/cooja/java/se/sics/cooja/PluginType.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: PluginType.java,v 1.1 2007/01/09 10:15:26 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: PluginType.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; @@ -35,8 +33,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** - * Annotation type to describe a plugin type. - * + * Annotation type to identify a plugin type. + * * @author Fredrik Osterlind */ @Retention(RetentionPolicy.RUNTIME) @@ -45,75 +43,73 @@ public @interface PluginType { /** * Mote Plugin - * + * * A mote plugin concerns one specific mote. - * - * An example of such a plugin may be to display - * some mote information in a frame. - * - * Mote plugins can not be instantiated from the - * regular menu bar, but are instead started from - * other plugins, for example a visualizer that let's - * a user select a mote. - * - * When constructed, a mote plugin is given a Mote. - * - * If the current simulation is removed, so are - * all instances of this plugin. + * + * An example of such a plugin may be to display some mote information in a + * frame. + * + * Mote plugins can not be instantiated from the regular menu bar, but are + * instead started from other plugins, for example a visualizer that let's a + * user select 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 all instances of this plugin. */ public static final int MOTE_PLUGIN = 1; /** * Simulation Plugin - * + * * A simulation plugin concerns one specific simulation. - * - * An example of such a plugin may be to display - * number of motes and current simulation time in a window. - * + * + * An example of such a plugin may be to display number of motes and current + * simulation time in a window. + * * Simulation plugins are available via the plugins menubar. - * - * When constructed, a simulation plugin is given the current - * active simulation. - * - * If the current simulation is removed, so are - * all instances of this plugin. + * + * When constructed, a simulation plugin is given the current active + * simulation and the GUI object. + * + * If the current simulation is removed, so are all instances of this plugin. */ public static final int SIM_PLUGIN = 2; /** * COOJA Plugin - * - * A COOJA plugin does not depend on the current simulation to function. - * - * An example of such a plugin may be a control panel - * where a user can control the current simulation. - * + * + * A COOJA plugin does not depend on the current simulation (if any). + * + * An example of such a plugin may be a control panel where a user can save + * and load different simulations. + * * COOJA plugins are available via the plugins menubar. - * + * * When constructed, a COOJA plugin is given the current GUI. */ public static final int COOJA_PLUGIN = 3; /** * Simulation Standard Plugin - * - * This is treated exactly like a Simulation Plugin, with the - * only difference that this will automatically be opened - * when a new simulation is created. + * + * This is treated exactly like a Simulation Plugin, with the only difference + * that this will automatically be opened when a new simulation is created. + * + * @see #SIM_PLUGIN */ public static final int SIM_STANDARD_PLUGIN = 4; - /** * COOJA Standard Plugin - * - * This is treated exactly like a COOJA Plugin, with the - * only difference that this will automatically be opened - * when the simulator is started. + * + * This is treated exactly like a COOJA Plugin, with the only difference that + * this will automatically be opened when the simulator is started. + * + * @see #COOJA_PLUGIN */ public static final int COOJA_STANDARD_PLUGIN = 5; int value(); } - diff --git a/tools/cooja/java/se/sics/cooja/Positioner.java b/tools/cooja/java/se/sics/cooja/Positioner.java index 6c6968a69..b608518f0 100644 --- a/tools/cooja/java/se/sics/cooja/Positioner.java +++ b/tools/cooja/java/se/sics/cooja/Positioner.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 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; @@ -72,11 +72,11 @@ public abstract class Positioner { double endZ) { try { // Generating positioner - Constructor constr = positionerClass.getConstructor(new Class[]{ + Constructor constr = positionerClass.getConstructor(new Class[] { int.class, double.class, double.class, double.class, double.class, - double.class, double.class}); - return (Positioner) constr.newInstance(new Object[]{totalNumberOfMotes, - startX, endX, startY, endY, startZ, endZ}); + double.class, double.class }); + return (Positioner) constr.newInstance(new Object[] { totalNumberOfMotes, + startX, endX, startY, endY, startZ, endZ }); } catch (Exception e) { logger.fatal("Exception when creating " + positionerClass + ": " + e); return null; diff --git a/tools/cooja/java/se/sics/cooja/RadioMedium.java b/tools/cooja/java/se/sics/cooja/RadioMedium.java index d75e88371..612751052 100644 --- a/tools/cooja/java/se/sics/cooja/RadioMedium.java +++ b/tools/cooja/java/se/sics/cooja/RadioMedium.java @@ -26,25 +26,24 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 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; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Collection; -import java.util.Observable; -import java.util.Observer; -import org.apache.log4j.Logger; +import java.util.*; import org.jdom.Element; import se.sics.cooja.interfaces.Position; import se.sics.cooja.interfaces.Radio; /** - * This interface represents a radio medium. Radios registered to this medium - * can both send and receive radio data. Depending on the implementation of this - * interface, more or less accurate radio behaviour imitation is aquired. + * The abstract class RadioMedium should be implemented by all COOJA radio + * mediums. Radios registered in this medium can both send and receive radio + * 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 * plugins. These plugins shows the user some radio medium specific details, @@ -53,7 +52,6 @@ import se.sics.cooja.interfaces.Radio; * @author Fredrik Osterlind */ public abstract class RadioMedium { - private static Logger logger = Logger.getLogger(RadioMedium.class); /** * 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 * loading a simulation.) * - * @see #setConfigXML(Collection) + * @see #setConfigXML(Collection, boolean) * @return XML elements representing the current radio medium config */ public abstract Collection getConfigXML(); @@ -182,7 +180,6 @@ public abstract class RadioMedium { */ public abstract boolean setConfigXML(Collection configXML, boolean visAvailable); - /** * This method creates an instance of the given class with the given * simulation constructor argument. Instead of calling the constructors diff --git a/tools/cooja/java/se/sics/cooja/SectionMoteMemory.java b/tools/cooja/java/se/sics/cooja/SectionMoteMemory.java index b0418cb21..ed5c30635 100644 --- a/tools/cooja/java/se/sics/cooja/SectionMoteMemory.java +++ b/tools/cooja/java/se/sics/cooja/SectionMoteMemory.java @@ -1,32 +1,30 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: SectionMoteMemory.java,v 1.3 2006/12/15 11:47:40 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: SectionMoteMemory.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; @@ -39,8 +37,8 @@ import org.apache.log4j.Logger; import se.sics.cooja.MoteMemory; /** - * Represents a mote memory consisting of non-overlapping memory sections. This - * memory also contains information about variable starts addresses. + * Represents a mote memory consisting of non-overlapping memory sections with + * variables' memory addresses. *

* When an unhandled memory segment is set a new section is automatically * created for this segment. @@ -52,6 +50,7 @@ public class SectionMoteMemory implements MoteMemory { private static Logger logger = Logger.getLogger(SectionMoteMemory.class); private Vector sections = new Vector(); + 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 */ public int getVariableAddress(String varName) { @@ -86,7 +86,7 @@ public class SectionMoteMemory implements MoteMemory { return -1; return ((Integer) variableAddresses.get(varName)).intValue(); } - + public void clearMemory() { sections.clear(); } @@ -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 */ private class MoteMemorySection { private byte[] data = null; + private int startAddr; /** diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index b2cc376bd..51591f690 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -1,37 +1,34 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. - * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: Simulation.java,v 1.8 2007/01/10 09:02:38 fros4943 Exp $ + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of the + * Institute nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: Simulation.java,v 1.9 2007/01/10 14:57:42 fros4943 Exp $ */ package se.sics.cooja; -import java.io.*; import java.util.*; import org.apache.log4j.Logger; import org.jdom.*; @@ -39,13 +36,15 @@ import org.jdom.*; import se.sics.cooja.dialogs.*; /** - * A simulation contains motes and ticks them one by one. When all motes has - * been ticked once, the simulation sleeps for some specified time, and the - * current simulation time is updated. Some observers (tick observers) are also - * notified. + * A simulation consists of a number of motes and mote types. + * + * The motes in the simulation are ticked one by one in a simulation loop. When + * 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 - * 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 * interfaces. * @@ -54,24 +53,29 @@ import se.sics.cooja.dialogs.*; public class Simulation extends Observable implements Runnable { private Vector motes = new Vector(); + private Vector moteTypes = new Vector(); private int delayTime = 100; + private int currentSimulationTime = 0; + private int tickTime = 1; + private String title = null; - // Radio Medium private RadioMedium currentRadioMedium = null; private static Logger logger = Logger.getLogger(Simulation.class); private boolean isRunning = false; + private boolean stopSimulation = false; + private Thread thread = null; private GUI myGUI = null; - + // Tick observable private class TickObservable extends Observable { private void allTicksPerformed() { @@ -79,6 +83,7 @@ public class Simulation extends Observable implements Runnable { notifyObservers(); } } + 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) { - // New simulation instance myGUI = gui; } @@ -202,12 +206,11 @@ public class Simulation extends Observable implements Runnable { } 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. */ 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 * config also includes the current radio medium, all mote types and motes. * - * @see #saveSimulationConfig(File file) * @return Current simulation config */ public Collection getConfigXML() { @@ -294,21 +303,21 @@ public class Simulation extends Observable implements Runnable { return config; } - /** - * @return GUI holding this simulation - */ - public GUI getGUI() { - return myGUI; - } - /** * Sets the current simulation config depending on the given XML elements. * * @see #getConfigXML() * @param configXML * 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 configXML, boolean visAvailable) throws Exception { + public boolean setConfigXML(Collection configXML, + boolean visAvailable) throws Exception { // Parse elements for (Element element : configXML) { @@ -336,20 +345,21 @@ public class Simulation extends Observable implements Runnable { // Radio medium if (element.getName().equals("radiomedium")) { String radioMediumClassName = element.getText().trim(); - Class radioMediumClass = myGUI - .tryLoadClass(this, RadioMedium.class, radioMediumClassName); + Class radioMediumClass = myGUI.tryLoadClass( + this, RadioMedium.class, radioMediumClassName); if (radioMediumClass != null) { // Create radio medium specified in config try { - currentRadioMedium = RadioMedium.generateRadioMedium(radioMediumClass, this); + currentRadioMedium = RadioMedium.generateRadioMedium( + radioMediumClass, this); } catch (Exception e) { currentRadioMedium = null; logger.warn("Could not load radio medium class: " + radioMediumClassName); } } - + // Show configure simulation dialog boolean createdOK = false; if (visAvailable) { @@ -377,8 +387,8 @@ public class Simulation extends Observable implements Runnable { if (element.getName().equals("motetype")) { String moteTypeClassName = element.getText().trim(); - Class moteTypeClass = myGUI.tryLoadClass( - this, MoteType.class, moteTypeClassName); + Class moteTypeClass = myGUI.tryLoadClass(this, + MoteType.class, moteTypeClassName); if (moteTypeClass == null) { 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) .newInstance(); - boolean createdOK = moteType.setConfigXML(this, element.getChildren(), visAvailable); + boolean createdOK = moteType.setConfigXML(this, element.getChildren(), + visAvailable); if (createdOK) { addMoteType(moteType); } else { @@ -400,8 +411,8 @@ public class Simulation extends Observable implements Runnable { // Mote if (element.getName().equals("mote")) { - Class moteClass = myGUI.tryLoadClass(this, - Mote.class, element.getText().trim()); + Class moteClass = myGUI.tryLoadClass(this, Mote.class, + element.getText().trim()); Mote mote = moteClass.getConstructor((Class[]) null).newInstance(); if (mote.setConfigXML(this, element.getChildren(), visAvailable)) { @@ -460,7 +471,7 @@ public class Simulation extends Observable implements Runnable { * Get a mote from this simulation. * * @param pos - * Position of mote + * Internal list position of mote * @return Mote */ public Mote getMote(int pos) { @@ -503,7 +514,7 @@ public class Simulation extends Observable implements Runnable { /** * Adds given mote type to simulation. * - * @param newMoteType + * @param newMoteType Mote type */ public void addMoteType(MoteType newMoteType) { moteTypes.add(newMoteType); @@ -593,7 +604,7 @@ public class Simulation extends Observable implements Runnable { } 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++) currentRadioMedium.registerMote(motes.get(i), this); } diff --git a/tools/cooja/java/se/sics/cooja/VisPlugin.java b/tools/cooja/java/se/sics/cooja/VisPlugin.java index 822ff3840..ef67697ec 100644 --- a/tools/cooja/java/se/sics/cooja/VisPlugin.java +++ b/tools/cooja/java/se/sics/cooja/VisPlugin.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * 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; @@ -38,14 +38,15 @@ import javax.swing.event.InternalFrameListener; import org.jdom.Element; /** - * Abstract class VisPlugin should be implemented by plugins for COOJA Simulator. - * By extending JInternalFrame, the visual apperence is decided by the plugin itself. - * - * An implemented plugin should be registered at runtime using the following method: - * GUI.registerPlugin(Class, String) - * - * For example how to implement a plugin see classes SimControl or Vis2D. - * + * Abstract class VisPlugin should be implemented by all plugins with + * visualizers. By extending JInternalFrame, the visual apperence is decided by + * the plugin itself. + * + * To add a new plugin to the simulator environment either add it via a user + * platform or by altering the standard configuration files. + * + * For example how to implement a plugin see plugins SimControl or Visualizer2D. + * * @author Fredrik Osterlind */ public abstract class VisPlugin extends JInternalFrame implements Plugin { @@ -104,5 +105,4 @@ public abstract class VisPlugin extends JInternalFrame implements Plugin { return tag; } - }