fixed problem with the initialization order

This commit is contained in:
nifi 2008-06-27 14:09:26 +00:00
parent 4eb02a56a0
commit 52d6ea2738
6 changed files with 50 additions and 44 deletions

View file

@ -26,15 +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.2 2008/03/17 09:54:19 fros4943 Exp $ * $Id: ESBMote.java,v 1.3 2008/06/27 14:09:26 nifi Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
import java.io.File; import java.io.File;
import java.util.*; import java.util.Random;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.*; import se.sics.cooja.MoteInterfaceHandler;
import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.*; import se.sics.cooja.interfaces.*;
import se.sics.cooja.mspmote.interfaces.*; import se.sics.cooja.mspmote.interfaces.*;
import se.sics.mspsim.platform.esb.ESBNode; import se.sics.mspsim.platform.esb.ESBNode;
@ -51,8 +52,8 @@ public class ESBMote extends MspMote {
super(); super();
} }
public ESBMote(MoteType moteType, Simulation sim) { public ESBMote(MspMoteType moteType, Simulation sim) {
super((MspMoteType) moteType, sim); super(moteType, sim);
} }
protected boolean initEmulator(File fileELF) { protected boolean initEmulator(File fileELF) {
@ -62,7 +63,7 @@ public class ESBMote extends MspMote {
prepareMote(fileELF, esbNode.getCPU()); prepareMote(fileELF, esbNode.getCPU());
} catch (Exception e) { } catch (Exception e) {
logger.fatal("Error when creating ESB mote: " + e); logger.fatal("Error when creating ESB mote:", e);
return false; return false;
} }
return true; return true;
@ -105,12 +106,12 @@ public class ESBMote extends MspMote {
} }
public String toString() { public String toString() {
if (getInterfaces().getMoteID() != null) { MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
return "ESB Mote, ID=" + getInterfaces().getMoteID().getMoteID(); if (moteID != null) {
return "ESB Mote, ID=" + moteID.getMoteID();
} else { } else {
return "ESB Mote, ID=null"; return "ESB Mote, ID=null";
} }
} }
} }

View file

@ -26,20 +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: ESBMoteType.java,v 1.4 2008/04/03 14:01:33 fros4943 Exp $ * $Id: ESBMoteType.java,v 1.5 2008/06/27 14:09:26 nifi Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
import java.awt.Container; import java.awt.*;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import javax.swing.*; import javax.swing.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.*; import se.sics.cooja.*;
@ClassDescription("ESB Mote Type") @ClassDescription("ESB Mote Type")
@ -76,7 +72,7 @@ public class ESBMoteType extends MspMoteType {
return null; return null;
} }
public Mote generateMote(Simulation simulation) { protected MspMote createMote(Simulation simulation) {
return new ESBMote(this, simulation); return new ESBMote(this, simulation);
} }

View file

@ -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.7 2008/04/03 14:01:06 fros4943 Exp $ * $Id: MspMote.java,v 1.8 2008/06/27 14:09:26 nifi Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
@ -37,13 +37,10 @@ import java.net.URLConnection;
import java.util.*; import java.util.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.mspmote.interfaces.TR1001Radio; import se.sics.cooja.mspmote.interfaces.TR1001Radio;
import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.*;
import se.sics.mspsim.util.MapEntry;
import se.sics.mspsim.util.MapTable;
/** /**
* @author Fredrik Osterlind * @author Fredrik Osterlind
@ -92,10 +89,14 @@ public abstract class MspMote implements Mote {
public MspMote(MspMoteType moteType, Simulation simulation) { public MspMote(MspMoteType moteType, Simulation simulation) {
myMoteType = moteType; myMoteType = moteType;
mySimulation = simulation; mySimulation = simulation;
initEmulator(myMoteType.getELFFile()); }
protected void initMote() {
if (myMoteType != null) {
initEmulator(myMoteType.getELFFile());
myMoteInterfaceHandler = createMoteInterfaceHandler(); myMoteInterfaceHandler = createMoteInterfaceHandler();
} }
}
/** /**
* @return MSP430 CPU * @return MSP430 CPU

View file

@ -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: MspMoteType.java,v 1.5 2008/04/03 14:00:21 fros4943 Exp $ * $Id: MspMoteType.java,v 1.6 2008/06/27 14:09:26 nifi Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
@ -35,14 +35,14 @@ import java.awt.*;
import java.awt.Dialog.ModalityType; import java.awt.Dialog.ModalityType;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.Collection;
import java.util.Vector;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.dialogs.MessageList; import se.sics.cooja.dialogs.MessageList;
@ -129,6 +129,14 @@ public abstract class MspMoteType implements MoteType {
return fileSource; return fileSource;
} }
public final Mote generateMote(Simulation simulation) {
MspMote mote = createMote(simulation);
mote.initMote();
return mote;
}
protected abstract MspMote createMote(Simulation simulation);
/** /**
* Configures and initialized Msp mote types. * Configures and initialized Msp mote types.
* *

View file

@ -26,16 +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.4 2008/04/03 14:02:20 fros4943 Exp $ * $Id: SkyMote.java,v 1.5 2008/06/27 14:09:26 nifi Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
import java.io.File; import java.io.File;
import java.util.*; import java.util.Random;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.MoteInterfaceHandler;
import se.sics.cooja.*; import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.*; import se.sics.cooja.interfaces.*;
import se.sics.cooja.mspmote.interfaces.*; import se.sics.cooja.mspmote.interfaces.*;
import se.sics.mspsim.platform.sky.SkyNode; import se.sics.mspsim.platform.sky.SkyNode;
@ -52,8 +52,8 @@ public class SkyMote extends MspMote {
super(); super();
} }
public SkyMote(MoteType moteType, Simulation sim) { public SkyMote(MspMoteType moteType, Simulation sim) {
super((SkyMoteType) moteType, sim); super(moteType, sim);
} }
protected boolean initEmulator(File fileELF) { protected boolean initEmulator(File fileELF) {
@ -63,7 +63,7 @@ public class SkyMote extends MspMote {
prepareMote(fileELF, skyNode.getCPU()); prepareMote(fileELF, skyNode.getCPU());
} catch (Exception e) { } catch (Exception e) {
logger.fatal("Error when creating Sky mote: " + e); logger.fatal("Error when creating Sky mote:", e);
return false; return false;
} }
return true; return true;
@ -82,6 +82,10 @@ public class SkyMote extends MspMote {
Clock moteClock = new MspClock(this); Clock moteClock = new MspClock(this);
moteInterfaceHandler.addActiveInterface(moteClock); moteInterfaceHandler.addActiveInterface(moteClock);
// Add button interface
Button moteButton = new SkyButton(this);
moteInterfaceHandler.addActiveInterface(moteButton);
// Add Flash interface // Add Flash interface
SkyFlash moteFlash = new SkyFlash(this); SkyFlash moteFlash = new SkyFlash(this);
moteInterfaceHandler.addActiveInterface(moteFlash); moteInterfaceHandler.addActiveInterface(moteFlash);
@ -106,12 +110,12 @@ public class SkyMote extends MspMote {
} }
public String toString() { public String toString() {
if (getInterfaces().getMoteID() != null) { MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
return "Sky Mote, ID=" + getInterfaces().getMoteID().getMoteID(); if (moteID != null) {
return "Sky Mote, ID=" + moteID.getMoteID();
} else { } else {
return "Sky Mote, ID=null"; return "Sky Mote, ID=null";
} }
} }
} }

View file

@ -26,20 +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: SkyMoteType.java,v 1.3 2008/04/03 14:00:21 fros4943 Exp $ * $Id: SkyMoteType.java,v 1.4 2008/06/27 14:09:26 nifi Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
import java.awt.Container; import java.awt.*;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import javax.swing.*; import javax.swing.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.*; import se.sics.cooja.*;
@ClassDescription("Sky Mote Type") @ClassDescription("Sky Mote Type")
@ -76,7 +72,7 @@ public class SkyMoteType extends MspMoteType {
return null; return null;
} }
public Mote generateMote(Simulation simulation) { protected MspMote createMote(Simulation simulation) {
return new SkyMote(this, simulation); return new SkyMote(this, simulation);
} }