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:
fros4943 2009-03-09 17:12:27 +00:00
parent 1c0e432969
commit e5a5f7dd5d
4 changed files with 54 additions and 95 deletions

View file

@ -26,18 +26,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
import java.io.File;
import java.util.Random;
import org.apache.log4j.Logger;
import se.sics.cooja.MoteInterfaceHandler;
import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.*;
import se.sics.cooja.mspmote.interfaces.*;
import se.sics.mspsim.platform.esb.ESBNode;
/**
@ -69,37 +67,19 @@ public class ESBMote extends MspMote {
}
protected MoteInterfaceHandler createMoteInterfaceHandler() {
MoteInterfaceHandler moteInterfaceHandler = new MoteInterfaceHandler();
/* Uses current mote type configuration */
MoteInterfaceHandler moteInterfaceHandler =
super.createMoteInterfaceHandler();
// Add position interface
Position motePosition = new Position(this);
Random random = new Random(); /* Do not use main random generator for positioning */
motePosition.setCoordinates(random.nextDouble()*100, random.nextDouble()*100, random.nextDouble()*100);
moteInterfaceHandler.addInterface(motePosition);
// Add log interface
Log moteLog = new ESBLog(this);
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);
/* TODO check if uIP is used, remove IPv4 interface otherwise */
// moteInterfaceHandler.getIPAddress()
// try {
// if (((MspMoteMemory)this.getMemory()).getVariableAddress("uip_hostaddr") != 0) {
// IPAddress ip = new MspIPAddress(this);
// moteInterfaceHandler.addInterface(ip);
// }
// } catch (UnknownVariableException e) {
// }
return moteInterfaceHandler;
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -117,6 +117,10 @@ public abstract class MspMote implements Mote {
}
}
protected MoteInterfaceHandler createMoteInterfaceHandler() {
return new MoteInterfaceHandler(this, getType().getMoteInterfaceClasses());
}
public void sendCLICommand(String line) {
if (commandHandler != null) {
commandHandler.lineRead(line);
@ -283,13 +287,6 @@ public abstract class MspMote implements Mote {
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.
*

View file

@ -26,13 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
import java.awt.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
import javax.swing.*;
@ -227,12 +228,20 @@ public abstract class MspMoteType implements MoteType {
element.setText(fileFirmware.getPath().replaceAll("\\\\", "/"));
config.add(element);
// Mote interfaces
for (Class moteInterface : getMoteInterfaceClasses()) {
element = new Element("moteinterface");
element.setText(moteInterface.getName());
config.add(element);
}
return config;
}
public boolean setConfigXML(Simulation simulation,
Collection<Element> configXML, boolean visAvailable)
throws MoteTypeCreationException {
ArrayList<Class<? extends MoteInterface>> intfClassList = new ArrayList<Class<? extends MoteInterface>>();
for (Element element : configXML) {
String name = element.getName();
@ -249,6 +258,15 @@ public abstract class MspMoteType implements MoteType {
} else if (name.equals("elf")) {
/* Backwards compatibility: elf is now firmware */
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 {
logger.fatal("Unrecognized entry in loaded configuration: " + name);
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);
}
}

View file

@ -26,19 +26,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
import java.io.File;
import java.util.Random;
import org.apache.log4j.Logger;
import se.sics.cooja.MoteInterfaceHandler;
import se.sics.cooja.Simulation;
import se.sics.cooja.AddressMemory.UnknownVariableException;
import se.sics.cooja.interfaces.*;
import se.sics.cooja.mspmote.interfaces.*;
import se.sics.mspsim.platform.sky.SkyNode;
/**
@ -70,56 +67,19 @@ public class SkyMote extends MspMote {
}
protected MoteInterfaceHandler createMoteInterfaceHandler() {
MoteInterfaceHandler moteInterfaceHandler = new MoteInterfaceHandler();
/* Uses current mote type configuration */
MoteInterfaceHandler moteInterfaceHandler =
super.createMoteInterfaceHandler();
// Add position interface
Position motePosition = new Position(this);
Random random = new Random(); /* Do not use main random generator for positioning */
motePosition.setCoordinates(random.nextDouble()*100, random.nextDouble()*100, random.nextDouble()*100);
moteInterfaceHandler.addInterface(motePosition);
// Add time interface
Clock moteClock = new MspClock(this);
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);
/* TODO check if uIP is used, remove IPv4 interface otherwise */
// moteInterfaceHandler.getIPAddress()
// try {
// if (((MspMoteMemory)this.getMemory()).getVariableAddress("uip_hostaddr") != 0) {
// IPAddress ip = new MspIPAddress(this);
// moteInterfaceHandler.addInterface(ip);
// }
// } catch (UnknownVariableException e) {
// }
return moteInterfaceHandler;
}