using mote type configuration for generating correct mote interfaces:
it is now possible to configure which interfaces msp430-based have
This commit is contained in:
parent
1c0e432969
commit
e5a5f7dd5d
4 changed files with 54 additions and 95 deletions
|
@ -26,18 +26,16 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ESBMote.java,v 1.6 2009/02/18 11:50:11 fros4943 Exp $
|
* $Id: ESBMote.java,v 1.7 2009/03/09 17:12:27 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote;
|
package se.sics.cooja.mspmote;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Random;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import se.sics.cooja.MoteInterfaceHandler;
|
import se.sics.cooja.MoteInterfaceHandler;
|
||||||
import se.sics.cooja.Simulation;
|
import se.sics.cooja.Simulation;
|
||||||
import se.sics.cooja.interfaces.*;
|
import se.sics.cooja.interfaces.*;
|
||||||
import se.sics.cooja.mspmote.interfaces.*;
|
|
||||||
import se.sics.mspsim.platform.esb.ESBNode;
|
import se.sics.mspsim.platform.esb.ESBNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,37 +67,19 @@ public class ESBMote extends MspMote {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MoteInterfaceHandler createMoteInterfaceHandler() {
|
protected MoteInterfaceHandler createMoteInterfaceHandler() {
|
||||||
MoteInterfaceHandler moteInterfaceHandler = new MoteInterfaceHandler();
|
/* Uses current mote type configuration */
|
||||||
|
MoteInterfaceHandler moteInterfaceHandler =
|
||||||
|
super.createMoteInterfaceHandler();
|
||||||
|
|
||||||
// Add position interface
|
/* TODO check if uIP is used, remove IPv4 interface otherwise */
|
||||||
Position motePosition = new Position(this);
|
// moteInterfaceHandler.getIPAddress()
|
||||||
Random random = new Random(); /* Do not use main random generator for positioning */
|
// try {
|
||||||
motePosition.setCoordinates(random.nextDouble()*100, random.nextDouble()*100, random.nextDouble()*100);
|
// if (((MspMoteMemory)this.getMemory()).getVariableAddress("uip_hostaddr") != 0) {
|
||||||
moteInterfaceHandler.addInterface(motePosition);
|
// IPAddress ip = new MspIPAddress(this);
|
||||||
|
// moteInterfaceHandler.addInterface(ip);
|
||||||
// Add log interface
|
// }
|
||||||
Log moteLog = new ESBLog(this);
|
// } catch (UnknownVariableException e) {
|
||||||
moteInterfaceHandler.addInterface(moteLog);
|
// }
|
||||||
|
|
||||||
// Add time interface
|
|
||||||
Clock moteClock = new MspClock(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteClock);
|
|
||||||
|
|
||||||
// Add led interface
|
|
||||||
LED moteLed = new ESBLED(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteLed);
|
|
||||||
|
|
||||||
// Add button interface
|
|
||||||
Button moteButton = new ESBButton(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteButton);
|
|
||||||
|
|
||||||
// Add ID interface
|
|
||||||
MoteID moteID = new MspMoteID(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteID);
|
|
||||||
|
|
||||||
// Add radio interface
|
|
||||||
myRadio = new TR1001Radio(this);
|
|
||||||
moteInterfaceHandler.addInterface(myRadio);
|
|
||||||
|
|
||||||
return moteInterfaceHandler;
|
return moteInterfaceHandler;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: MspMote.java,v 1.21 2009/03/09 16:01:29 fros4943 Exp $
|
* $Id: MspMote.java,v 1.22 2009/03/09 17:12:27 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote;
|
package se.sics.cooja.mspmote;
|
||||||
|
@ -117,6 +117,10 @@ public abstract class MspMote implements Mote {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected MoteInterfaceHandler createMoteInterfaceHandler() {
|
||||||
|
return new MoteInterfaceHandler(this, getType().getMoteInterfaceClasses());
|
||||||
|
}
|
||||||
|
|
||||||
public void sendCLICommand(String line) {
|
public void sendCLICommand(String line) {
|
||||||
if (commandHandler != null) {
|
if (commandHandler != null) {
|
||||||
commandHandler.lineRead(line);
|
commandHandler.lineRead(line);
|
||||||
|
@ -283,13 +287,6 @@ public abstract class MspMote implements Mote {
|
||||||
myMoteInterfaceHandler = moteInterfaceHandler;
|
myMoteInterfaceHandler = moteInterfaceHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an interface handler object and registers interfaces to it.
|
|
||||||
*
|
|
||||||
* @return Interface handler
|
|
||||||
*/
|
|
||||||
protected abstract MoteInterfaceHandler createMoteInterfaceHandler();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes emulator by creating CPU, memory and node object.
|
* Initializes emulator by creating CPU, memory and node object.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,13 +26,14 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: MspMoteType.java,v 1.25 2009/03/09 16:00:16 fros4943 Exp $
|
* $Id: MspMoteType.java,v 1.26 2009/03/09 17:12:27 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote;
|
package se.sics.cooja.mspmote;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -227,12 +228,20 @@ public abstract class MspMoteType implements MoteType {
|
||||||
element.setText(fileFirmware.getPath().replaceAll("\\\\", "/"));
|
element.setText(fileFirmware.getPath().replaceAll("\\\\", "/"));
|
||||||
config.add(element);
|
config.add(element);
|
||||||
|
|
||||||
|
// Mote interfaces
|
||||||
|
for (Class moteInterface : getMoteInterfaceClasses()) {
|
||||||
|
element = new Element("moteinterface");
|
||||||
|
element.setText(moteInterface.getName());
|
||||||
|
config.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setConfigXML(Simulation simulation,
|
public boolean setConfigXML(Simulation simulation,
|
||||||
Collection<Element> configXML, boolean visAvailable)
|
Collection<Element> configXML, boolean visAvailable)
|
||||||
throws MoteTypeCreationException {
|
throws MoteTypeCreationException {
|
||||||
|
ArrayList<Class<? extends MoteInterface>> intfClassList = new ArrayList<Class<? extends MoteInterface>>();
|
||||||
for (Element element : configXML) {
|
for (Element element : configXML) {
|
||||||
String name = element.getName();
|
String name = element.getName();
|
||||||
|
|
||||||
|
@ -249,6 +258,15 @@ public abstract class MspMoteType implements MoteType {
|
||||||
} else if (name.equals("elf")) {
|
} else if (name.equals("elf")) {
|
||||||
/* Backwards compatibility: elf is now firmware */
|
/* Backwards compatibility: elf is now firmware */
|
||||||
fileFirmware = new File(element.getText());
|
fileFirmware = new File(element.getText());
|
||||||
|
} else if (name.equals("moteinterface")) {
|
||||||
|
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 {
|
||||||
|
intfClassList.add(moteInterfaceClass);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.fatal("Unrecognized entry in loaded configuration: " + name);
|
logger.fatal("Unrecognized entry in loaded configuration: " + name);
|
||||||
throw new MoteTypeCreationException(
|
throw new MoteTypeCreationException(
|
||||||
|
@ -256,6 +274,10 @@ public abstract class MspMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Class<? extends MoteInterface>[] intfClasses = new Class[intfClassList.size()];
|
||||||
|
intfClassList.toArray(intfClasses);
|
||||||
|
setMoteInterfaceClasses(intfClasses);
|
||||||
|
|
||||||
return configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
|
return configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,19 +26,16 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: SkyMote.java,v 1.12 2009/02/26 13:48:08 fros4943 Exp $
|
* $Id: SkyMote.java,v 1.13 2009/03/09 17:12:27 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote;
|
package se.sics.cooja.mspmote;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Random;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import se.sics.cooja.MoteInterfaceHandler;
|
import se.sics.cooja.MoteInterfaceHandler;
|
||||||
import se.sics.cooja.Simulation;
|
import se.sics.cooja.Simulation;
|
||||||
import se.sics.cooja.AddressMemory.UnknownVariableException;
|
|
||||||
import se.sics.cooja.interfaces.*;
|
import se.sics.cooja.interfaces.*;
|
||||||
import se.sics.cooja.mspmote.interfaces.*;
|
|
||||||
import se.sics.mspsim.platform.sky.SkyNode;
|
import se.sics.mspsim.platform.sky.SkyNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,56 +67,19 @@ public class SkyMote extends MspMote {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MoteInterfaceHandler createMoteInterfaceHandler() {
|
protected MoteInterfaceHandler createMoteInterfaceHandler() {
|
||||||
MoteInterfaceHandler moteInterfaceHandler = new MoteInterfaceHandler();
|
/* Uses current mote type configuration */
|
||||||
|
MoteInterfaceHandler moteInterfaceHandler =
|
||||||
|
super.createMoteInterfaceHandler();
|
||||||
|
|
||||||
// Add position interface
|
/* TODO check if uIP is used, remove IPv4 interface otherwise */
|
||||||
Position motePosition = new Position(this);
|
// moteInterfaceHandler.getIPAddress()
|
||||||
Random random = new Random(); /* Do not use main random generator for positioning */
|
// try {
|
||||||
motePosition.setCoordinates(random.nextDouble()*100, random.nextDouble()*100, random.nextDouble()*100);
|
// if (((MspMoteMemory)this.getMemory()).getVariableAddress("uip_hostaddr") != 0) {
|
||||||
moteInterfaceHandler.addInterface(motePosition);
|
// IPAddress ip = new MspIPAddress(this);
|
||||||
|
// moteInterfaceHandler.addInterface(ip);
|
||||||
// Add time interface
|
// }
|
||||||
Clock moteClock = new MspClock(this);
|
// } catch (UnknownVariableException e) {
|
||||||
moteInterfaceHandler.addInterface(moteClock);
|
// }
|
||||||
|
|
||||||
// Add button interface
|
|
||||||
Button moteButton = new SkyButton(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteButton);
|
|
||||||
|
|
||||||
// Add Flash interface
|
|
||||||
SkyFlash moteFlash = new SkyFlash(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteFlash);
|
|
||||||
|
|
||||||
// Add ID interface
|
|
||||||
MoteID moteID = new MspMoteID(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteID);
|
|
||||||
|
|
||||||
// Add radio interface
|
|
||||||
// SkyRadio moteRadio = new SkyRadio(this);
|
|
||||||
// moteInterfaceHandler.addActiveInterface(moteRadio);
|
|
||||||
SkyByteRadio moteRadio = new SkyByteRadio(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteRadio);
|
|
||||||
|
|
||||||
// Add serial interface
|
|
||||||
SkySerial moteSerial = new SkySerial(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteSerial);
|
|
||||||
|
|
||||||
// Add LED interface
|
|
||||||
SkyLED moteLED = new SkyLED(this);
|
|
||||||
moteInterfaceHandler.addInterface(moteLED);
|
|
||||||
|
|
||||||
/* IP Address (if uIP is used) */
|
|
||||||
try {
|
|
||||||
if (((MspMoteMemory)this.getMemory()).getVariableAddress("uip_hostaddr") != 0) {
|
|
||||||
IPAddress ip = new MspIPAddress(this);
|
|
||||||
moteInterfaceHandler.addInterface(ip);
|
|
||||||
}
|
|
||||||
} catch (UnknownVariableException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mote relation listener */
|
|
||||||
Mote2MoteRelations mote2moteRelation = new Mote2MoteRelations(this);
|
|
||||||
moteInterfaceHandler.addInterface(mote2moteRelation);
|
|
||||||
|
|
||||||
return moteInterfaceHandler;
|
return moteInterfaceHandler;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue