documentation (including javadoc) update
This commit is contained in:
parent
b2516a09ef
commit
0c98ce0651
@ -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());
|
||||
|
@ -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.*;
|
||||
* </ul>
|
||||
* and the following native functions:
|
||||
* <ul>
|
||||
* <li>init()
|
||||
* <li>tick()
|
||||
* <li>init()
|
||||
* <li>getReferenceAbsAddr()
|
||||
* <li>getMemory(int start, int length)
|
||||
* <li>getMemory(int start, int length, byte[] mem)
|
||||
* <li>setMemory(int start, int length, byte[] mem)
|
||||
* </ul>
|
||||
*
|
||||
* @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();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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<? extends IPDistributor> ipDistClass, Vector<Mote> 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();
|
||||
|
||||
|
@ -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<Element> 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<Element> configXML, boolean visAvailable);
|
||||
public abstract boolean setConfigXML(Simulation simulation,
|
||||
Collection<Element> configXML, boolean visAvailable);
|
||||
|
||||
}
|
||||
|
@ -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<? extends MoteInterface> interfaceClass, Mote mote) {
|
||||
public static final MoteInterface generateInterface(
|
||||
Class<? extends MoteInterface> 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<Element> 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<Element> configXML, boolean visAvailable);
|
||||
|
||||
public abstract void setConfigXML(Collection<Element> configXML,
|
||||
boolean visAvailable);
|
||||
|
||||
}
|
||||
|
@ -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<MoteInterface> myActiveInterfaces = new Vector<MoteInterface>();
|
||||
|
||||
private Vector<MoteInterface> myPassiveInterfaces = new Vector<MoteInterface>();
|
||||
|
||||
/**
|
||||
@ -120,13 +129,15 @@ public class MoteInterfaceHandler {
|
||||
*/
|
||||
public <N extends MoteInterface> N getInterfaceOfType(Class<N> interfaceType) {
|
||||
|
||||
Enumeration<? extends MoteInterface> allActive = myActiveInterfaces.elements();
|
||||
Enumeration<? extends MoteInterface> allActive = myActiveInterfaces
|
||||
.elements();
|
||||
while (allActive.hasMoreElements()) {
|
||||
N nextInterface = (N) allActive.nextElement();
|
||||
if (interfaceType.isAssignableFrom(nextInterface.getClass()))
|
||||
return nextInterface;
|
||||
}
|
||||
Enumeration<? extends MoteInterface> allPassive = myPassiveInterfaces.elements();
|
||||
Enumeration<? extends MoteInterface> 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.
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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<Element> 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,
|
||||
|
@ -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.
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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<Element> 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<Element> configXML, boolean visAvailable);
|
||||
public boolean setConfigXML(Collection<Element> configXML,
|
||||
boolean visAvailable);
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Element> getConfigXML();
|
||||
@ -182,7 +180,6 @@ public abstract class RadioMedium {
|
||||
*/
|
||||
public abstract boolean setConfigXML(Collection<Element> configXML, boolean visAvailable);
|
||||
|
||||
|
||||
/**
|
||||
* This method creates an instance of the given class with the given
|
||||
* simulation constructor argument. Instead of calling the constructors
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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<MoteMemorySection> sections = new Vector<MoteMemorySection>();
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -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<Mote> motes = new Vector<Mote>();
|
||||
|
||||
private Vector<MoteType> moteTypes = new Vector<MoteType>();
|
||||
|
||||
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<Element> 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<Element> configXML, boolean visAvailable) throws Exception {
|
||||
public boolean setConfigXML(Collection<Element> 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<? extends RadioMedium> radioMediumClass = myGUI
|
||||
.tryLoadClass(this, RadioMedium.class, radioMediumClassName);
|
||||
Class<? extends RadioMedium> 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<? extends MoteType> moteTypeClass = myGUI.tryLoadClass(
|
||||
this, MoteType.class, moteTypeClassName);
|
||||
Class<? extends MoteType> 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<? extends Mote> moteClass = myGUI.tryLoadClass(this,
|
||||
Mote.class, element.getText().trim());
|
||||
Class<? extends Mote> 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);
|
||||
}
|
||||
|
@ -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<? extends VisPlugin>, 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user