application-level mote type implementing new mote type methods
+ radio disturber mote extending abstract application mote
This commit is contained in:
parent
dadc67abd7
commit
74647ce2de
7 changed files with 177 additions and 780 deletions
|
@ -24,7 +24,7 @@
|
|||
* (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: AbstractApplicationMote.java,v 1.3 2008/10/28 13:38:55 fros4943 Exp $
|
||||
* $Id: AbstractApplicationMote.java,v 1.4 2009/03/09 15:38:10 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.motes;
|
||||
|
@ -35,8 +35,6 @@ import org.apache.log4j.Logger;
|
|||
import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.*;
|
||||
import se.sics.cooja.interfaces.ApplicationRadio;
|
||||
import se.sics.cooja.interfaces.Position;
|
||||
import se.sics.cooja.interfaces.Radio;
|
||||
|
||||
/**
|
||||
|
@ -50,55 +48,47 @@ public abstract class AbstractApplicationMote implements Mote {
|
|||
|
||||
private static Logger logger = Logger.getLogger(AbstractApplicationMote.class);
|
||||
|
||||
private MoteType myType = null;
|
||||
private MoteType moteType = null;
|
||||
|
||||
private SectionMoteMemory myMemory = null;
|
||||
private SectionMoteMemory memory = null;
|
||||
|
||||
protected MoteInterfaceHandler myInterfaceHandler = null;
|
||||
protected MoteInterfaceHandler moteInterfaces = null;
|
||||
|
||||
private Simulation mySim = null;
|
||||
|
||||
protected ApplicationRadio myApplicationRadio;
|
||||
private Simulation simulation = null;
|
||||
|
||||
private Observer radioDataObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
handleNewRadioData(obs, obj);
|
||||
if (getInterfaces().getRadio().getLastEvent() != Radio.RadioEvent.RECEPTION_FINISHED) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Called at incoming data packets */
|
||||
logger.info("Application mote received radio data:");
|
||||
byte[] packet = getInterfaces().getRadio().getLastPacketReceived().getPacketData();
|
||||
String data = "";
|
||||
for (byte b: packet) {
|
||||
data += (char)b;
|
||||
}
|
||||
logger.info(data);
|
||||
}
|
||||
};
|
||||
|
||||
public void handleNewRadioData(Observable obs, Object obj) {
|
||||
if (myApplicationRadio.getLastEvent() != Radio.RadioEvent.RECEPTION_FINISHED) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Application mote received radio data:");
|
||||
byte[] packet = myApplicationRadio.getLastPacketReceived().getPacketData();
|
||||
String data = "";
|
||||
for (byte b: packet) {
|
||||
data += (char)b;
|
||||
}
|
||||
logger.info(data);
|
||||
}
|
||||
|
||||
public AbstractApplicationMote() {
|
||||
}
|
||||
|
||||
public AbstractApplicationMote(MoteType moteType, Simulation sim) {
|
||||
mySim = sim;
|
||||
myType = moteType;
|
||||
this.simulation = sim;
|
||||
this.moteType = moteType;
|
||||
|
||||
// Create memory
|
||||
myMemory = new SectionMoteMemory(new Properties());
|
||||
this.memory = new SectionMoteMemory(new Properties());
|
||||
|
||||
// Create position
|
||||
myInterfaceHandler = new MoteInterfaceHandler();
|
||||
Position myPosition = new Position(this);
|
||||
myInterfaceHandler.addInterface(myPosition);
|
||||
// Create mote interfaces
|
||||
this.moteInterfaces = new MoteInterfaceHandler(this, moteType.getMoteInterfaceClasses());
|
||||
|
||||
// Create radio
|
||||
myApplicationRadio = new ApplicationRadio(this);
|
||||
myApplicationRadio.addObserver(radioDataObserver);
|
||||
myInterfaceHandler.addInterface(myApplicationRadio);
|
||||
if (moteInterfaces.getRadio() != null) {
|
||||
moteInterfaces.getRadio().addObserver(radioDataObserver);
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(State newState) {
|
||||
|
@ -116,35 +106,46 @@ public abstract class AbstractApplicationMote implements Mote {
|
|||
}
|
||||
|
||||
public MoteInterfaceHandler getInterfaces() {
|
||||
return myInterfaceHandler;
|
||||
return moteInterfaces;
|
||||
}
|
||||
|
||||
public void setInterfaces(MoteInterfaceHandler moteInterfaceHandler) {
|
||||
myInterfaceHandler = moteInterfaceHandler;
|
||||
moteInterfaces = moteInterfaceHandler;
|
||||
}
|
||||
|
||||
public MoteMemory getMemory() {
|
||||
return myMemory;
|
||||
return memory;
|
||||
}
|
||||
|
||||
public void setMemory(MoteMemory memory) {
|
||||
myMemory = (SectionMoteMemory) memory;
|
||||
this.memory = (SectionMoteMemory) memory;
|
||||
}
|
||||
|
||||
public MoteType getType() {
|
||||
return myType;
|
||||
return moteType;
|
||||
}
|
||||
|
||||
public void setType(MoteType type) {
|
||||
myType = type;
|
||||
moteType = type;
|
||||
}
|
||||
|
||||
public Simulation getSimulation() {
|
||||
return mySim;
|
||||
return simulation;
|
||||
}
|
||||
|
||||
public void setSimulation(Simulation simulation) {
|
||||
this.mySim = simulation;
|
||||
this.simulation = simulation;
|
||||
}
|
||||
|
||||
public boolean tick(long simTime) {
|
||||
moteInterfaces.doPassiveActionsBeforeTick();
|
||||
moteInterfaces.doActiveActionsBeforeTick();
|
||||
|
||||
/* TODO Implement application functionality here */
|
||||
|
||||
moteInterfaces.doActiveActionsAfterTick();
|
||||
moteInterfaces.doPassiveActionsAfterTick();
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
|
@ -157,12 +158,8 @@ public abstract class AbstractApplicationMote implements Mote {
|
|||
element.setText(getType().getIdentifier());
|
||||
config.add(element);
|
||||
|
||||
// The position interface should also save its config
|
||||
element = new Element("interface_config");
|
||||
element.setText(myInterfaceHandler.getPosition().getClass().getName());
|
||||
|
||||
// Interfaces
|
||||
for (MoteInterface moteInterface: getInterfaces().getInterfaces()) {
|
||||
for (MoteInterface moteInterface: moteInterfaces.getInterfaces()) {
|
||||
element = new Element("interface_config");
|
||||
element.setText(moteInterface.getClass().getName());
|
||||
|
||||
|
@ -180,22 +177,17 @@ public abstract class AbstractApplicationMote implements Mote {
|
|||
Collection<Element> configXML, boolean visAvailable) {
|
||||
|
||||
// Set initial configuration
|
||||
mySim = simulation;
|
||||
myMemory = new SectionMoteMemory(new Properties());
|
||||
myInterfaceHandler = new MoteInterfaceHandler();
|
||||
Position myPosition = new Position(this);
|
||||
myInterfaceHandler.addInterface(myPosition);
|
||||
myApplicationRadio = new ApplicationRadio(this);
|
||||
myApplicationRadio.addObserver(radioDataObserver);
|
||||
myInterfaceHandler.addInterface(myApplicationRadio);
|
||||
this.simulation = simulation;
|
||||
this.memory = new SectionMoteMemory(new Properties());
|
||||
|
||||
for (Element element : configXML) {
|
||||
String name = element.getName();
|
||||
|
||||
if (name.equals("motetype_identifier")) {
|
||||
myType = simulation.getMoteType(element.getText());
|
||||
moteType = simulation.getMoteType(element.getText());
|
||||
this.moteInterfaces = new MoteInterfaceHandler(this, moteType.getMoteInterfaceClasses());
|
||||
} else if (name.equals("interface_config")) {
|
||||
Class<? extends MoteInterface> moteInterfaceClass =
|
||||
Class<? extends MoteInterface> moteInterfaceClass =
|
||||
simulation.getGUI().tryLoadClass(this, MoteInterface.class, element.getText().trim());
|
||||
|
||||
if (moteInterfaceClass == null) {
|
||||
|
@ -203,8 +195,7 @@ public abstract class AbstractApplicationMote implements Mote {
|
|||
return false;
|
||||
}
|
||||
|
||||
MoteInterface moteInterface = myInterfaceHandler
|
||||
.getInterfaceOfType(moteInterfaceClass);
|
||||
MoteInterface moteInterface = moteInterfaces.getInterfaceOfType(moteInterfaceClass);
|
||||
moteInterface.setConfigXML(element.getChildren(), visAvailable);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
* (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: AbstractApplicationMoteType.java,v 1.2 2008/02/12 15:10:49 fros4943 Exp $
|
||||
* $Id: AbstractApplicationMoteType.java,v 1.3 2009/03/09 15:38:10 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.motes;
|
||||
|
@ -32,7 +32,9 @@ package se.sics.cooja.motes;
|
|||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
@ -50,7 +52,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
|
||||
private String description = null;
|
||||
|
||||
private Vector<Class<? extends MoteInterface>> moteInterfaces = null;
|
||||
private Class<? extends MoteInterface>[] moteInterfaces = null;
|
||||
|
||||
// Type specific class configuration
|
||||
private ProjectConfig myConfig = null;
|
||||
|
@ -83,12 +85,6 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (description == null) {
|
||||
// Create description
|
||||
description = "Application Mote Type #" + counter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (description == null) {
|
||||
|
@ -96,33 +92,13 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
description = "Application Mote Type #" + identifier;
|
||||
}
|
||||
|
||||
moteInterfaces = new Vector<Class<? extends MoteInterface>>();
|
||||
moteInterfaces.add(Position.class);
|
||||
moteInterfaces.add(ApplicationRadio.class);
|
||||
moteInterfaces = new Class[2];
|
||||
moteInterfaces[0] = Position.class;
|
||||
moteInterfaces[1] = ApplicationRadio.class;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all mote interfaces of this mote type
|
||||
*
|
||||
* @return All mote interfaces
|
||||
*/
|
||||
public Vector<Class<? extends MoteInterface>> getMoteInterfaces() {
|
||||
return moteInterfaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mote interfaces of this mote type
|
||||
*
|
||||
* @param moteInterfaces
|
||||
* New mote interfaces
|
||||
*/
|
||||
public void setMoteInterfaces(
|
||||
Vector<Class<? extends MoteInterface>> moteInterfaces) {
|
||||
this.moteInterfaces = moteInterfaces;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
@ -139,8 +115,15 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
this.description = description;
|
||||
}
|
||||
|
||||
public JPanel getTypeVisualizer() {
|
||||
public Class<? extends MoteInterface>[] getMoteInterfaceClasses() {
|
||||
return moteInterfaces;
|
||||
}
|
||||
|
||||
public void setMoteInterfaceClasses(Class<? extends MoteInterface>[] moteInterfaces) {
|
||||
this.moteInterfaces = moteInterfaces;
|
||||
}
|
||||
|
||||
public JPanel getTypeVisualizer() {
|
||||
JPanel panel = new JPanel();
|
||||
JLabel label = new JLabel();
|
||||
JPanel smallPane;
|
||||
|
@ -180,6 +163,31 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
return panel;
|
||||
}
|
||||
|
||||
public File getContikiSourceFile() {
|
||||
return null; /* Contiki-independent */
|
||||
}
|
||||
|
||||
public File getContikiFirmwareFile() {
|
||||
return null; /* Contiki-independent */
|
||||
}
|
||||
|
||||
public void setContikiSourceFile(File file) {
|
||||
/* Contiki-independent */
|
||||
}
|
||||
|
||||
public void setContikiFirmwareFile(File file) {
|
||||
/* Contiki-independent */
|
||||
}
|
||||
|
||||
public String getCompileCommands() {
|
||||
/* Contiki-independent */
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCompileCommands(String commands) {
|
||||
/* Contiki-independent */
|
||||
}
|
||||
|
||||
public ProjectConfig getConfig() {
|
||||
return myConfig;
|
||||
}
|
||||
|
@ -200,7 +208,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
config.add(element);
|
||||
|
||||
// Mote interfaces
|
||||
for (Class moteInterface : getMoteInterfaces()) {
|
||||
for (Class moteInterface : getMoteInterfaceClasses()) {
|
||||
element = new Element("moteinterface");
|
||||
element.setText(moteInterface.getName());
|
||||
config.add(element);
|
||||
|
@ -211,8 +219,8 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
|
||||
public boolean setConfigXML(Simulation simulation,
|
||||
Collection<Element> configXML, boolean visAvailable) {
|
||||
ArrayList<Class<? extends MoteInterface>> moteInterfacesList = new ArrayList<Class<? extends MoteInterface>>();
|
||||
for (Element element : configXML) {
|
||||
moteInterfaces = new Vector<Class<? extends MoteInterface>>();
|
||||
|
||||
String name = element.getName();
|
||||
|
||||
|
@ -221,19 +229,23 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
} else if (name.equals("description")) {
|
||||
description = element.getText();
|
||||
} else if (name.equals("moteinterface")) {
|
||||
Class<? extends MoteInterface> moteInterfaceClass = simulation.getGUI()
|
||||
.tryLoadClass(this, MoteInterface.class, element.getText().trim());
|
||||
Class<? extends MoteInterface> moteInterfaceClass =
|
||||
simulation.getGUI().tryLoadClass(
|
||||
this, MoteInterface.class, element.getText().trim());
|
||||
|
||||
if (moteInterfaceClass == null) {
|
||||
logger.warn("Can't find mote interface class: " + element.getText());
|
||||
} else {
|
||||
moteInterfaces.add(moteInterfaceClass);
|
||||
moteInterfacesList.add(moteInterfaceClass);
|
||||
}
|
||||
} else {
|
||||
logger.fatal("Unrecognized entry in loaded configuration: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
moteInterfaces = new Class[moteInterfacesList.size()];
|
||||
moteInterfacesList.toArray(moteInterfaces);
|
||||
|
||||
boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
|
||||
return createdOK;
|
||||
}
|
||||
|
|
|
@ -24,196 +24,31 @@
|
|||
* (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: DisturberMote.java,v 1.6 2009/02/18 11:49:54 fros4943 Exp $
|
||||
* $Id: DisturberMote.java,v 1.7 2009/03/09 15:38:10 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.motes;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.*;
|
||||
import se.sics.cooja.interfaces.Position;
|
||||
import se.sics.cooja.motes.DisturberRadio;
|
||||
|
||||
/**
|
||||
* A disturber mote is a purely Java-based mote. It is used to disturb
|
||||
* transmission of other nodes on a certain channel (currently this is
|
||||
* hard-coded in the DisturberRadio.
|
||||
* Simple application-level mote that periodically transmits dummy radio packets
|
||||
* on a configurable radio channel, interfering all surrounding radio communication.
|
||||
*
|
||||
* @see DisturberMoteType
|
||||
* @author Fredrik Osterlind, Thiemo Voigt
|
||||
*/
|
||||
public class DisturberMote implements Mote {
|
||||
public class DisturberMote extends AbstractApplicationMote {
|
||||
|
||||
private static Logger logger = Logger.getLogger(DisturberMote.class);
|
||||
|
||||
private MoteType myType = null;
|
||||
|
||||
private SectionMoteMemory myMemory = null;
|
||||
|
||||
private MoteInterfaceHandler myInterfaceHandler = null;
|
||||
|
||||
private Simulation mySim = null;
|
||||
|
||||
private DisturberRadio myDisturberRadio;
|
||||
|
||||
/**
|
||||
* Creates a new uninitialized dummy mote.
|
||||
*/
|
||||
public DisturberMote() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new dummy mote of the given type in the given simulation. An
|
||||
* empty mote memory and a position interface is added to this mote.
|
||||
*
|
||||
* @param moteType
|
||||
* Mote type
|
||||
* @param sim
|
||||
* Simulation
|
||||
*/
|
||||
public DisturberMote(MoteType moteType, Simulation sim) {
|
||||
mySim = sim;
|
||||
myType = moteType;
|
||||
Random random = new Random(); /* Do not use main random generator for positioning */
|
||||
|
||||
// Create memory
|
||||
myMemory = new SectionMoteMemory(new Properties());
|
||||
|
||||
// Create interface handler
|
||||
myInterfaceHandler = new MoteInterfaceHandler();
|
||||
Position myPosition = new Position(this);
|
||||
myPosition.setCoordinates(
|
||||
random.nextDouble() * 100,
|
||||
random.nextDouble() * 100,
|
||||
random.nextDouble() * 100
|
||||
);
|
||||
myInterfaceHandler.addInterface(myPosition);
|
||||
|
||||
// create interface handler for radio
|
||||
myDisturberRadio = new DisturberRadio(this);
|
||||
myInterfaceHandler.addInterface(myDisturberRadio);
|
||||
}
|
||||
|
||||
public void setState(State newState) {
|
||||
logger.fatal("Disturber mote can not change state");
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return Mote.State.ACTIVE;
|
||||
}
|
||||
|
||||
public void addStateObserver(Observer newObserver) {
|
||||
}
|
||||
|
||||
public void deleteStateObserver(Observer newObserver) {
|
||||
}
|
||||
|
||||
public MoteInterfaceHandler getInterfaces() {
|
||||
return myInterfaceHandler;
|
||||
}
|
||||
|
||||
public void setInterfaces(MoteInterfaceHandler moteInterfaceHandler) {
|
||||
myInterfaceHandler = moteInterfaceHandler;
|
||||
}
|
||||
|
||||
public MoteMemory getMemory() {
|
||||
return myMemory;
|
||||
}
|
||||
|
||||
public void setMemory(MoteMemory memory) {
|
||||
myMemory = (SectionMoteMemory) memory;
|
||||
}
|
||||
|
||||
public MoteType getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
public void setType(MoteType type) {
|
||||
myType = type;
|
||||
}
|
||||
|
||||
public Simulation getSimulation() {
|
||||
return mySim;
|
||||
}
|
||||
|
||||
public void setSimulation(Simulation simulation) {
|
||||
this.mySim = simulation;
|
||||
}
|
||||
|
||||
public boolean tick(long simTime) {
|
||||
myInterfaceHandler.doPassiveActionsBeforeTick();
|
||||
myInterfaceHandler.doActiveActionsBeforeTick();
|
||||
myInterfaceHandler.doActiveActionsAfterTick();
|
||||
myInterfaceHandler.doPassiveActionsAfterTick();
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
Vector<Element> config = new Vector<Element>();
|
||||
|
||||
Element element;
|
||||
|
||||
// We need to save the mote type identifier
|
||||
element = new Element("motetype_identifier");
|
||||
element.setText(getType().getIdentifier());
|
||||
config.add(element);
|
||||
|
||||
// The position interface should also save its config
|
||||
element = new Element("interface_config");
|
||||
element.setText(myInterfaceHandler.getPosition().getClass().getName());
|
||||
|
||||
// Interfaces
|
||||
for (MoteInterface moteInterface: getInterfaces().getInterfaces()) {
|
||||
element = new Element("interface_config");
|
||||
element.setText(moteInterface.getClass().getName());
|
||||
|
||||
Collection interfaceXML = moteInterface.getConfigXML();
|
||||
if (interfaceXML != null) {
|
||||
element.addContent(interfaceXML);
|
||||
config.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public boolean setConfigXML(Simulation simulation,
|
||||
Collection<Element> configXML, boolean visAvailable) {
|
||||
|
||||
// Set initial configuration
|
||||
mySim = simulation;
|
||||
myMemory = new SectionMoteMemory(new Properties());
|
||||
myInterfaceHandler = new MoteInterfaceHandler();
|
||||
Position myPosition = new Position(this);
|
||||
myInterfaceHandler.addInterface(myPosition);
|
||||
myDisturberRadio = new DisturberRadio(this);
|
||||
myInterfaceHandler.addInterface(myDisturberRadio);
|
||||
|
||||
|
||||
for (Element element : configXML) {
|
||||
String name = element.getName();
|
||||
|
||||
if (name.equals("motetype_identifier")) {
|
||||
myType = simulation.getMoteType(element.getText());
|
||||
} else if (name.equals("interface_config")) {
|
||||
Class<? extends MoteInterface> moteInterfaceClass = simulation.getGUI()
|
||||
.tryLoadClass(this, MoteInterface.class, element.getText().trim());
|
||||
|
||||
if (moteInterfaceClass == null) {
|
||||
logger.warn("Can't find mote interface class: " + element.getText());
|
||||
return false;
|
||||
}
|
||||
|
||||
MoteInterface moteInterface = myInterfaceHandler
|
||||
.getInterfaceOfType(moteInterfaceClass);
|
||||
moteInterface.setConfigXML(element.getChildren(), visAvailable);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
public DisturberMote(MoteType moteType, Simulation simulation) {
|
||||
super(moteType, simulation);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -223,5 +58,4 @@ public class DisturberMote implements Mote {
|
|||
return "Disturber Mote, ID=null";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,46 +31,30 @@
|
|||
|
||||
package se.sics.cooja.motes;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.*;
|
||||
import se.sics.cooja.interfaces.Position;
|
||||
|
||||
/**
|
||||
* Simple application-level mote that periodically transmits dummy radio packets
|
||||
* on a configurable radio channel, interfering all surrounding radio communication.
|
||||
*
|
||||
*
|
||||
* @see DisturberMote
|
||||
* @author Fredrik Osterlind, Thiemo Voigt
|
||||
*/
|
||||
@ClassDescription("Disturber Mote Type")
|
||||
@AbstractionLevelDescription("Application level")
|
||||
public class DisturberMoteType implements MoteType {
|
||||
public class DisturberMoteType extends AbstractApplicationMoteType {
|
||||
private static Logger logger = Logger.getLogger(DisturberMoteType.class);
|
||||
|
||||
// Mote type specific data
|
||||
private String identifier = null;
|
||||
|
||||
private String description = null;
|
||||
|
||||
private Vector<Class<? extends MoteInterface>> moteInterfaces = null;
|
||||
|
||||
// Type specific class configuration
|
||||
private ProjectConfig myConfig = null;
|
||||
|
||||
// Simulation holding this mote type
|
||||
private Simulation mySimulation = null;
|
||||
|
||||
public DisturberMoteType() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DisturberMoteType(String identifier) {
|
||||
this.identifier = identifier;
|
||||
description = "Disturber Mote Type #" + identifier;
|
||||
super(identifier);
|
||||
setDescription("Disturber Mote Type #" + getIdentifier());
|
||||
}
|
||||
|
||||
public Mote generateMote(Simulation simulation) {
|
||||
|
@ -78,182 +62,14 @@ public class DisturberMoteType implements MoteType {
|
|||
}
|
||||
|
||||
public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) {
|
||||
super.configureAndInit(parentContainer, simulation, visAvailable);
|
||||
setDescription("Disturber Mote Type #" + getIdentifier());
|
||||
|
||||
if (identifier == null) {
|
||||
// Create unique identifier
|
||||
int counter = 0;
|
||||
boolean identifierOK = false;
|
||||
while (!identifierOK) {
|
||||
counter++;
|
||||
identifier = "dist" + counter;
|
||||
identifierOK = true;
|
||||
|
||||
// Check if identifier is already used by some other type
|
||||
for (MoteType existingMoteType : simulation.getMoteTypes()) {
|
||||
if (existingMoteType != this
|
||||
&& existingMoteType.getIdentifier().equals(identifier)) {
|
||||
identifierOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (description == null) {
|
||||
// Create description
|
||||
description = "Disturber Mote Type #" + counter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (description == null) {
|
||||
// Create description
|
||||
description = "Disturber Mote Type #" + identifier;
|
||||
}
|
||||
|
||||
moteInterfaces = new Vector<Class<? extends MoteInterface>>();
|
||||
moteInterfaces.add(Position.class);
|
||||
moteInterfaces.add(DisturberRadio.class);
|
||||
Class<? extends MoteInterface>[] moteInterfaces = new Class[2];
|
||||
moteInterfaces[0] = Position.class;
|
||||
moteInterfaces[1] = DisturberRadio.class;
|
||||
setMoteInterfaceClasses(moteInterfaces);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* TV: add next two for interfaces */
|
||||
/**
|
||||
* Returns all mote interfaces of this mote type
|
||||
*
|
||||
* @return All mote interfaces
|
||||
*/
|
||||
public Vector<Class<? extends MoteInterface>> getMoteInterfaces() {
|
||||
return moteInterfaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mote interfaces of this mote type
|
||||
*
|
||||
* @param moteInterfaces
|
||||
* New mote interfaces
|
||||
*/
|
||||
public void setMoteInterfaces(
|
||||
Vector<Class<? extends MoteInterface>> moteInterfaces) {
|
||||
this.moteInterfaces = moteInterfaces;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/* TV replaced return null with this */
|
||||
public JPanel getTypeVisualizer() {
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
JLabel label = new JLabel();
|
||||
JPanel smallPane;
|
||||
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
|
||||
// Identifier
|
||||
smallPane = new JPanel(new BorderLayout());
|
||||
label = new JLabel("Identifier");
|
||||
smallPane.add(BorderLayout.WEST, label);
|
||||
label = new JLabel(identifier);
|
||||
smallPane.add(BorderLayout.EAST, label);
|
||||
panel.add(smallPane);
|
||||
|
||||
// Description
|
||||
smallPane = new JPanel(new BorderLayout());
|
||||
label = new JLabel("Description");
|
||||
smallPane.add(BorderLayout.WEST, label);
|
||||
label = new JLabel(description);
|
||||
smallPane.add(BorderLayout.EAST, label);
|
||||
panel.add(smallPane);
|
||||
|
||||
// Mote Interfaces
|
||||
smallPane = new JPanel(new BorderLayout());
|
||||
label = new JLabel("Mote interfaces");
|
||||
smallPane.add(BorderLayout.WEST, label);
|
||||
panel.add(smallPane);
|
||||
|
||||
for (Class moteInterface : moteInterfaces) {
|
||||
smallPane = new JPanel(new BorderLayout());
|
||||
label = new JLabel(moteInterface.getSimpleName());
|
||||
smallPane.add(BorderLayout.EAST, label);
|
||||
panel.add(smallPane);
|
||||
}
|
||||
|
||||
panel.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
return panel;
|
||||
}
|
||||
|
||||
public ProjectConfig getConfig() {
|
||||
return myConfig;
|
||||
//return null; /* TV */
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
Vector<Element> config = new Vector<Element>();
|
||||
|
||||
Element element;
|
||||
|
||||
// Identifier
|
||||
element = new Element("identifier");
|
||||
element.setText(getIdentifier());
|
||||
config.add(element);
|
||||
|
||||
// Description
|
||||
element = new Element("description");
|
||||
element.setText(getDescription());
|
||||
config.add(element);
|
||||
|
||||
// Mote interfaces
|
||||
for (Class moteInterface : getMoteInterfaces()) {
|
||||
element = new Element("moteinterface");
|
||||
element.setText(moteInterface.getName());
|
||||
config.add(element);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public boolean setConfigXML(Simulation simulation,
|
||||
Collection<Element> configXML, boolean visAvailable) {
|
||||
for (Element element : configXML) {
|
||||
moteInterfaces = new Vector<Class<? extends MoteInterface>>(); /* TV */
|
||||
mySimulation = simulation; /* TV */
|
||||
|
||||
String name = element.getName();
|
||||
|
||||
if (name.equals("identifier")) {
|
||||
identifier = element.getText();
|
||||
} else if (name.equals("description")) {
|
||||
description = element.getText();
|
||||
} else if (name.equals("moteinterface")) { /* TV */
|
||||
Class<? extends MoteInterface> moteInterfaceClass = simulation.getGUI()
|
||||
.tryLoadClass(this, MoteInterface.class, element.getText().trim());
|
||||
|
||||
if (moteInterfaceClass == null) {
|
||||
logger.warn("Can't find mote interface class: " + element.getText());
|
||||
} else {
|
||||
moteInterfaces.add(moteInterfaceClass);
|
||||
}
|
||||
} else {
|
||||
logger.fatal("Unrecognized entry in loaded configuration: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
|
||||
return createdOK;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: DisturberRadio.java,v 1.9 2008/12/04 14:03:42 joxe Exp $
|
||||
* $Id: DisturberRadio.java,v 1.10 2009/03/09 15:38:10 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.motes;
|
||||
|
@ -47,7 +47,7 @@ import se.sics.cooja.interfaces.*;
|
|||
*
|
||||
* @author Fredrik Osterlind, Thiemo Voigt
|
||||
*/
|
||||
public class DisturberRadio extends Radio {
|
||||
public class DisturberRadio extends Radio implements PolledBeforeAllTicks {
|
||||
private Mote myMote;
|
||||
|
||||
private static Logger logger = Logger.getLogger(DisturberRadio.class);
|
||||
|
@ -155,6 +155,10 @@ public class DisturberRadio extends Radio {
|
|||
long currentTime = myMote.getSimulation().getSimulationTime();
|
||||
|
||||
if (!transmitting && currentTime % TRANSMISSION_INTERVAL == 0) {
|
||||
if (distChannel < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
transmitting = true;
|
||||
lastEvent = RadioEvent.TRANSMISSION_STARTED;
|
||||
lastEventTime = currentTime;
|
||||
|
@ -163,6 +167,10 @@ public class DisturberRadio extends Radio {
|
|||
this.notifyObservers();
|
||||
} else if (transmitting && currentTime >= transEndTime) {
|
||||
transmitting = false;
|
||||
lastEvent = RadioEvent.PACKET_TRANSMITTED;
|
||||
lastEventTime = currentTime;
|
||||
this.setChanged();
|
||||
this.notifyObservers();
|
||||
lastEvent = RadioEvent.TRANSMISSION_FINISHED;
|
||||
lastEventTime = currentTime;
|
||||
this.setChanged();
|
||||
|
@ -170,9 +178,6 @@ public class DisturberRadio extends Radio {
|
|||
}
|
||||
}
|
||||
|
||||
public void doActionsAfterTick() {
|
||||
}
|
||||
|
||||
public JPanel getInterfaceVisualizer() {
|
||||
// Location
|
||||
JPanel panel = new JPanel();
|
||||
|
@ -212,9 +217,7 @@ public class DisturberRadio extends Radio {
|
|||
channelPicker.addPropertyChangeListener("value", new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
distChannel = ((Number) channelPicker.getValue()).intValue();
|
||||
if (observer != null) {
|
||||
observer.update(null, null);
|
||||
}
|
||||
observer.update(null, null);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -244,7 +247,6 @@ public class DisturberRadio extends Radio {
|
|||
Vector<Element> config = new Vector<Element>();
|
||||
Element element;
|
||||
|
||||
// We need to save the mote type identifier
|
||||
element = new Element("channel");
|
||||
element.setText(Integer.toString(distChannel));
|
||||
config.add(element);
|
||||
|
|
|
@ -1,229 +1,69 @@
|
|||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
* 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: DummyMote.java,v 1.7 2009/02/18 10:41:50 fros4943 Exp $
|
||||
* $Id: DummyMote.java,v 1.8 2009/03/09 15:38:10 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.motes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Observer;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.*;
|
||||
import se.sics.cooja.interfaces.Position;
|
||||
|
||||
/**
|
||||
* A dummy mote is a purely Java-based mote, and can be used as an example of
|
||||
* how to implement motes other than the usual Contiki mote.
|
||||
*
|
||||
* The dummy mote uses an empty section mote memory without any variable
|
||||
* mappings.
|
||||
*
|
||||
* The mote interface handler has a position interface, added when the mote is
|
||||
* constructed.
|
||||
*
|
||||
* When the dummy mote is ticked all (one!) interfaces are polled and a random
|
||||
* variable decides if the position should be changed. The node never leaves the
|
||||
* active state.
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class DummyMote implements Mote {
|
||||
public class DummyMote extends AbstractApplicationMote {
|
||||
|
||||
private static Logger logger = Logger.getLogger(DummyMote.class);
|
||||
private Random random = new Random(); /* XXX Not using Cooja main random generator */
|
||||
|
||||
private MoteType myType = null;
|
||||
private SectionMoteMemory myMemory = null;
|
||||
private MoteInterfaceHandler myInterfaceHandler = null;
|
||||
private Simulation mySim = null;
|
||||
|
||||
private Random random = null;
|
||||
|
||||
/**
|
||||
* Creates a new uninitialized dummy mote.
|
||||
*/
|
||||
public DummyMote() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new dummy mote of the given type in the given simulation. An
|
||||
* empty mote memory and a position interface is added to this mote.
|
||||
*
|
||||
* @param moteType
|
||||
* Mote type
|
||||
* @param sim
|
||||
* Simulation
|
||||
*/
|
||||
public DummyMote(MoteType moteType, Simulation sim) {
|
||||
mySim = sim;
|
||||
myType = moteType;
|
||||
random = mySim.getRandomGenerator();
|
||||
|
||||
// Create memory
|
||||
myMemory = new SectionMoteMemory(new Properties());
|
||||
|
||||
// Create interface handler
|
||||
myInterfaceHandler = new MoteInterfaceHandler();
|
||||
Position myPosition = new Position(this);
|
||||
myPosition.setCoordinates(
|
||||
random.nextDouble() * 100,
|
||||
random.nextDouble() * 100,
|
||||
random.nextDouble() * 100
|
||||
);
|
||||
myInterfaceHandler.addInterface(myPosition);
|
||||
}
|
||||
|
||||
public void setState(State newState) {
|
||||
logger.fatal("Dummy mote can not change state");
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return Mote.State.ACTIVE;
|
||||
}
|
||||
|
||||
public void addStateObserver(Observer newObserver) {
|
||||
}
|
||||
|
||||
public void deleteStateObserver(Observer newObserver) {
|
||||
}
|
||||
|
||||
public MoteInterfaceHandler getInterfaces() {
|
||||
return myInterfaceHandler;
|
||||
}
|
||||
|
||||
public void setInterfaces(MoteInterfaceHandler moteInterfaceHandler) {
|
||||
myInterfaceHandler = moteInterfaceHandler;
|
||||
}
|
||||
|
||||
public MoteMemory getMemory() {
|
||||
return myMemory;
|
||||
}
|
||||
|
||||
public void setMemory(MoteMemory memory) {
|
||||
myMemory = (SectionMoteMemory) memory;
|
||||
}
|
||||
|
||||
public MoteType getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
public void setType(MoteType type) {
|
||||
myType = type;
|
||||
}
|
||||
|
||||
public Simulation getSimulation() {
|
||||
return mySim;
|
||||
}
|
||||
|
||||
public void setSimulation(Simulation simulation) {
|
||||
this.mySim = simulation;
|
||||
public DummyMote(MoteType moteType, Simulation simulation) {
|
||||
super(moteType, simulation);
|
||||
}
|
||||
|
||||
public boolean tick(long simTime) {
|
||||
|
||||
// Perform some dummy task
|
||||
/* Dummy task: move randomly */
|
||||
if (random.nextDouble() > 0.9) {
|
||||
// Move mote randomly
|
||||
Position myPosition = myInterfaceHandler.getPosition();
|
||||
myPosition.setCoordinates(myPosition.getXCoordinate()
|
||||
+ random.nextDouble() - 0.5, myPosition.getYCoordinate()
|
||||
+ random.nextDouble() - 0.5, myPosition.getZCoordinate()
|
||||
+ random.nextDouble() - 0.5);
|
||||
Position pos = getInterfaces().getPosition();
|
||||
pos.setCoordinates(
|
||||
pos.getXCoordinate() + random.nextDouble() - 0.5,
|
||||
pos.getYCoordinate() + random.nextDouble() - 0.5,
|
||||
pos.getZCoordinate() + random.nextDouble() - 0.5
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
Vector<Element> config = new Vector<Element>();
|
||||
|
||||
Element element;
|
||||
|
||||
// We need to save the mote type identifier
|
||||
element = new Element("motetype_identifier");
|
||||
element.setText(getType().getIdentifier());
|
||||
config.add(element);
|
||||
|
||||
// The position interface should also save its config
|
||||
element = new Element("interface_config");
|
||||
element.setText(myInterfaceHandler.getPosition().getClass().getName());
|
||||
|
||||
Collection interfaceXML = myInterfaceHandler.getPosition().getConfigXML();
|
||||
if (interfaceXML != null) {
|
||||
element.addContent(interfaceXML);
|
||||
config.add(element);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public boolean setConfigXML(Simulation simulation,
|
||||
Collection<Element> configXML, boolean visAvailable) {
|
||||
mySim = simulation;
|
||||
myMemory = new SectionMoteMemory(new Properties());
|
||||
random = mySim.getRandomGenerator();
|
||||
myInterfaceHandler = new MoteInterfaceHandler();
|
||||
myInterfaceHandler.addInterface(new Position(this));
|
||||
|
||||
for (Element element : configXML) {
|
||||
String name = element.getName();
|
||||
|
||||
if (name.equals("motetype_identifier")) {
|
||||
myType = simulation.getMoteType(element.getText());
|
||||
} else if (name.equals("interface_config")) {
|
||||
Class<? extends MoteInterface> moteInterfaceClass = simulation.getGUI()
|
||||
.tryLoadClass(this, MoteInterface.class, element.getText().trim());
|
||||
|
||||
if (moteInterfaceClass == null) {
|
||||
logger.warn("Can't find mote interface class: " + element.getText());
|
||||
return false;
|
||||
}
|
||||
|
||||
MoteInterface moteInterface = myInterfaceHandler
|
||||
.getInterfaceOfType(moteInterfaceClass);
|
||||
moteInterface.setConfigXML(element.getChildren(), visAvailable);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (getInterfaces().getMoteID() != null) {
|
||||
return "Dummy Mote, ID=" + getInterfaces().getMoteID().getMoteID();
|
||||
} else {
|
||||
return "Dummy Mote, ID=null";
|
||||
}
|
||||
return "Dummy Mote";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -26,36 +26,28 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: DummyMoteType.java,v 1.5 2008/02/12 15:10:49 fros4943 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
package se.sics.cooja.motes;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.*;
|
||||
import se.sics.cooja.interfaces.Position;
|
||||
|
||||
@ClassDescription("Dummy Mote Type")
|
||||
@AbstractionLevelDescription("Application level")
|
||||
public class DummyMoteType implements MoteType {
|
||||
public class DummyMoteType extends AbstractApplicationMoteType {
|
||||
private static Logger logger = Logger.getLogger(DummyMoteType.class);
|
||||
|
||||
// Mote type specific data
|
||||
private String identifier = null;
|
||||
private String description = null;
|
||||
|
||||
public DummyMoteType() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DummyMoteType(String identifier) {
|
||||
this.identifier = identifier;
|
||||
description = "Dummy Mote Type #" + identifier;
|
||||
super(identifier);
|
||||
setDescription("Dummy Mote Type #" + getIdentifier());
|
||||
}
|
||||
|
||||
public Mote generateMote(Simulation simulation) {
|
||||
|
@ -63,98 +55,8 @@ public class DummyMoteType implements MoteType {
|
|||
}
|
||||
|
||||
public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) {
|
||||
|
||||
if (identifier == null) {
|
||||
// Create unique identifier
|
||||
int counter = 0;
|
||||
boolean identifierOK = false;
|
||||
while (!identifierOK) {
|
||||
counter++;
|
||||
identifier = "dummy" + counter;
|
||||
identifierOK = true;
|
||||
|
||||
// Check if identifier is already used by some other type
|
||||
for (MoteType existingMoteType : simulation.getMoteTypes()) {
|
||||
if (existingMoteType != this
|
||||
&& existingMoteType.getIdentifier().equals(identifier)) {
|
||||
identifierOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (description == null) {
|
||||
// Create description
|
||||
description = "Dummy Mote Type #" + counter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (description == null) {
|
||||
// Create description
|
||||
description = "Dummy Mote Type #" + identifier;
|
||||
}
|
||||
|
||||
super.configureAndInit(parentContainer, simulation, visAvailable);
|
||||
setDescription("Dummy Mote Type #" + getIdentifier());
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public JPanel getTypeVisualizer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProjectConfig getConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
Vector<Element> config = new Vector<Element>();
|
||||
|
||||
Element element;
|
||||
|
||||
// Identifier
|
||||
element = new Element("identifier");
|
||||
element.setText(getIdentifier());
|
||||
config.add(element);
|
||||
|
||||
// Description
|
||||
element = new Element("description");
|
||||
element.setText(getDescription());
|
||||
config.add(element);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
|
||||
for (Element element : configXML) {
|
||||
String name = element.getName();
|
||||
|
||||
if (name.equals("identifier")) {
|
||||
identifier = element.getText();
|
||||
} else if (name.equals("description")) {
|
||||
description = element.getText();
|
||||
} else {
|
||||
logger.fatal("Unrecognized entry in loaded configuration: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
|
||||
return createdOK;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue