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
* 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;
import java.io.File;
import java.util.*;
import java.util.Random;
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.mspmote.interfaces.*;
import se.sics.mspsim.platform.esb.ESBNode;
@ -51,8 +52,8 @@ public class ESBMote extends MspMote {
super();
}
public ESBMote(MoteType moteType, Simulation sim) {
super((MspMoteType) moteType, sim);
public ESBMote(MspMoteType moteType, Simulation sim) {
super(moteType, sim);
}
protected boolean initEmulator(File fileELF) {
@ -62,7 +63,7 @@ public class ESBMote extends MspMote {
prepareMote(fileELF, esbNode.getCPU());
} catch (Exception e) {
logger.fatal("Error when creating ESB mote: " + e);
logger.fatal("Error when creating ESB mote:", e);
return false;
}
return true;
@ -105,12 +106,12 @@ public class ESBMote extends MspMote {
}
public String toString() {
if (getInterfaces().getMoteID() != null) {
return "ESB Mote, ID=" + getInterfaces().getMoteID().getMoteID();
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
if (moteID != null) {
return "ESB Mote, ID=" + moteID.getMoteID();
} else {
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
* 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;
import java.awt.Container;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.*;
import java.io.File;
import java.net.URL;
import javax.swing.*;
import org.apache.log4j.Logger;
import se.sics.cooja.*;
@ClassDescription("ESB Mote Type")
@ -76,7 +72,7 @@ public class ESBMoteType extends MspMoteType {
return null;
}
public Mote generateMote(Simulation simulation) {
protected MspMote createMote(Simulation 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
* 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;
@ -37,13 +37,10 @@ import java.net.URLConnection;
import java.util.*;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.*;
import se.sics.cooja.mspmote.interfaces.TR1001Radio;
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.util.ELF;
import se.sics.mspsim.util.MapEntry;
import se.sics.mspsim.util.MapTable;
import se.sics.mspsim.util.*;
/**
* @author Fredrik Osterlind
@ -92,9 +89,13 @@ public abstract class MspMote implements Mote {
public MspMote(MspMoteType moteType, Simulation simulation) {
myMoteType = moteType;
mySimulation = simulation;
initEmulator(myMoteType.getELFFile());
}
myMoteInterfaceHandler = createMoteInterfaceHandler();
protected void initMote() {
if (myMoteType != null) {
initEmulator(myMoteType.getELFFile());
myMoteInterfaceHandler = createMoteInterfaceHandler();
}
}
/**

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -35,14 +35,14 @@ import java.awt.*;
import java.awt.Dialog.ModalityType;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.Collection;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.*;
import se.sics.cooja.dialogs.MessageList;
@ -129,6 +129,14 @@ public abstract class MspMoteType implements MoteType {
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.
*

View File

@ -26,16 +26,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
import java.io.File;
import java.util.*;
import java.util.Random;
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.mspmote.interfaces.*;
import se.sics.mspsim.platform.sky.SkyNode;
@ -52,8 +52,8 @@ public class SkyMote extends MspMote {
super();
}
public SkyMote(MoteType moteType, Simulation sim) {
super((SkyMoteType) moteType, sim);
public SkyMote(MspMoteType moteType, Simulation sim) {
super(moteType, sim);
}
protected boolean initEmulator(File fileELF) {
@ -63,7 +63,7 @@ public class SkyMote extends MspMote {
prepareMote(fileELF, skyNode.getCPU());
} catch (Exception e) {
logger.fatal("Error when creating Sky mote: " + e);
logger.fatal("Error when creating Sky mote:", e);
return false;
}
return true;
@ -82,10 +82,14 @@ public class SkyMote extends MspMote {
Clock moteClock = new MspClock(this);
moteInterfaceHandler.addActiveInterface(moteClock);
// Add button interface
Button moteButton = new SkyButton(this);
moteInterfaceHandler.addActiveInterface(moteButton);
// Add Flash interface
SkyFlash moteFlash = new SkyFlash(this);
moteInterfaceHandler.addActiveInterface(moteFlash);
// Add ID interface
MoteID moteID = new MspMoteID(this);
moteInterfaceHandler.addActiveInterface(moteID);
@ -106,12 +110,12 @@ public class SkyMote extends MspMote {
}
public String toString() {
if (getInterfaces().getMoteID() != null) {
return "Sky Mote, ID=" + getInterfaces().getMoteID().getMoteID();
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
if (moteID != null) {
return "Sky Mote, ID=" + moteID.getMoteID();
} else {
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
* 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;
import java.awt.Container;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.*;
import java.io.File;
import java.net.URL;
import javax.swing.*;
import org.apache.log4j.Logger;
import se.sics.cooja.*;
@ClassDescription("Sky Mote Type")
@ -76,7 +72,7 @@ public class SkyMoteType extends MspMoteType {
return null;
}
public Mote generateMote(Simulation simulation) {
protected MspMote createMote(Simulation simulation) {
return new SkyMote(this, simulation);
}