small optimizations and cleanups

This commit is contained in:
joxe 2010-10-04 12:54:01 +00:00
parent 63c685c852
commit 67c76649d9
5 changed files with 29 additions and 61 deletions

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: MicaZMote.java,v 1.14 2010/02/03 16:04:44 fros4943 Exp $ * $Id: MicaZMote.java,v 1.15 2010/10/04 12:54:01 joxe Exp $
*/ */
package se.sics.cooja.avrmote; package se.sics.cooja.avrmote;
@ -64,7 +64,6 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
/* 8 MHz according to Contiki config */ /* 8 MHz according to Contiki config */
public static long NR_CYCLES_PER_MSEC = 8000; public static long NR_CYCLES_PER_MSEC = 8000;
private Simulation mySimulation = null;
private MoteInterfaceHandler myMoteInterfaceHandler; private MoteInterfaceHandler myMoteInterfaceHandler;
private AtmelMicrocontroller myCpu = null; private AtmelMicrocontroller myCpu = null;
private MicaZ micaZ = null; private MicaZ micaZ = null;
@ -81,14 +80,13 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
public MicaZMote() { public MicaZMote() {
myMoteType = null; myMoteType = null;
mySimulation = null;
myCpu = null; myCpu = null;
/* TODO myMemory = null; */ /* TODO myMemory = null; */
myMoteInterfaceHandler = null; myMoteInterfaceHandler = null;
} }
public MicaZMote(Simulation simulation, MicaZMoteType type) { public MicaZMote(Simulation simulation, MicaZMoteType type) {
mySimulation = simulation; setSimulation(simulation);
myMoteType = type; myMoteType = type;
/* Schedule us immediately */ /* Schedule us immediately */
@ -128,14 +126,6 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
} }
} }
public Simulation getSimulation() {
return mySimulation;
}
public void setSimulation(Simulation simulation) {
mySimulation = simulation;
}
/** /**
* Prepares CPU, memory and ELF module. * Prepares CPU, memory and ELF module.
* *

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.47 2010/08/13 10:18:54 fros4943 Exp $ * $Id: MspMote.java,v 1.48 2010/10/04 12:54:01 joxe Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
@ -82,7 +82,6 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
Visualizer.registerVisualizerSkin(CodeVisualizerSkin.class); Visualizer.registerVisualizerSkin(CodeVisualizerSkin.class);
} }
private Simulation simulation;
private CommandHandler commandHandler; private CommandHandler commandHandler;
private ArrayList<LineListener> commandListeners = new ArrayList<LineListener>(); private ArrayList<LineListener> commandListeners = new ArrayList<LineListener>();
private MSP430 myCpu = null; private MSP430 myCpu = null;
@ -101,7 +100,6 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
private MspBreakpointContainer breakpointsContainer; private MspBreakpointContainer breakpointsContainer;
public MspMote() { public MspMote() {
simulation = null;
myMoteType = null; myMoteType = null;
myCpu = null; myCpu = null;
myMemory = null; myMemory = null;
@ -184,14 +182,6 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
myMemory = (MspMoteMemory) memory; myMemory = (MspMoteMemory) memory;
} }
public Simulation getSimulation() {
return simulation;
}
public void setSimulation(Simulation simulation) {
this.simulation = simulation;
}
/* Stack monitoring variables */ /* Stack monitoring variables */
public class StackOverflowObservable extends Observable { public class StackOverflowObservable extends Observable {
public void signalStackOverflow() { public void signalStackOverflow() {

View File

@ -26,14 +26,13 @@
* 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: ContikiMote.java,v 1.17 2010/02/03 16:06:21 fros4943 Exp $ * $Id: ContikiMote.java,v 1.18 2010/10/04 12:54:01 joxe Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Vector;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
@ -68,7 +67,6 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
private ContikiMoteType myType = null; private ContikiMoteType myType = null;
private SectionMoteMemory myMemory = null; private SectionMoteMemory myMemory = null;
private MoteInterfaceHandler myInterfaceHandler = null; private MoteInterfaceHandler myInterfaceHandler = null;
private Simulation simulation = null;
/** /**
* Creates a new uninitialized Contiki mote. * Creates a new uninitialized Contiki mote.
@ -88,7 +86,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
* @param sim Mote's simulation * @param sim Mote's simulation
*/ */
public ContikiMote(ContikiMoteType moteType, Simulation sim) { public ContikiMote(ContikiMoteType moteType, Simulation sim) {
this.simulation = sim; setSimulation(sim);
this.myType = moteType; this.myType = moteType;
this.myMemory = moteType.createInitialMemory(); this.myMemory = moteType.createInitialMemory();
this.myInterfaceHandler = new MoteInterfaceHandler(this, moteType.getMoteInterfaceClasses()); this.myInterfaceHandler = new MoteInterfaceHandler(this, moteType.getMoteInterfaceClasses());
@ -124,14 +122,6 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
myType = (ContikiMoteType) type; myType = (ContikiMoteType) type;
} }
public Simulation getSimulation() {
return simulation;
}
public void setSimulation(Simulation simulation) {
this.simulation = simulation;
}
/** /**
* Ticks mote once. This is done by first polling all interfaces * Ticks mote once. This is done by first polling all interfaces
* and letting them act on the stored memory before the memory is set. Then * and letting them act on the stored memory before the memory is set. Then
@ -194,7 +184,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
} }
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) { public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
this.simulation = simulation; setSimulation(simulation);
myMemory = myType.createInitialMemory(); myMemory = myType.createInitialMemory();
myInterfaceHandler = new MoteInterfaceHandler(this, myType.getMoteInterfaceClasses()); myInterfaceHandler = new MoteInterfaceHandler(this, myType.getMoteInterfaceClasses());

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: AbstractApplicationMote.java,v 1.11 2010/07/05 16:48:55 fros4943 Exp $ * $Id: AbstractApplicationMote.java,v 1.12 2010/10/04 12:54:01 joxe Exp $
*/ */
package se.sics.cooja.motes; package se.sics.cooja.motes;
@ -66,8 +66,6 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
protected MoteInterfaceHandler moteInterfaces = null; protected MoteInterfaceHandler moteInterfaces = null;
private Simulation simulation = null;
/* Observe our own radio for incoming radio packets */ /* Observe our own radio for incoming radio packets */
private Observer radioDataObserver = new Observer() { private Observer radioDataObserver = new Observer() {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
@ -90,7 +88,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
} }
public AbstractApplicationMote(MoteType moteType, Simulation sim) { public AbstractApplicationMote(MoteType moteType, Simulation sim) {
this.simulation = sim; setSimulation(sim);
this.moteType = moteType; this.moteType = moteType;
this.memory = new SectionMoteMemory(new Properties()); this.memory = new SectionMoteMemory(new Properties());
this.moteInterfaces = new MoteInterfaceHandler(this, moteType.getMoteInterfaceClasses()); this.moteInterfaces = new MoteInterfaceHandler(this, moteType.getMoteInterfaceClasses());
@ -126,14 +124,6 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
moteType = type; moteType = type;
} }
public Simulation getSimulation() {
return simulation;
}
public void setSimulation(Simulation simulation) {
this.simulation = simulation;
}
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
ArrayList<Element> config = new ArrayList<Element>(); ArrayList<Element> config = new ArrayList<Element>();
Element element; Element element;
@ -154,7 +144,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
public boolean setConfigXML(Simulation simulation, public boolean setConfigXML(Simulation simulation,
Collection<Element> configXML, boolean visAvailable) { Collection<Element> configXML, boolean visAvailable) {
this.simulation = simulation; setSimulation(simulation);
this.memory = new SectionMoteMemory(new Properties()); this.memory = new SectionMoteMemory(new Properties());
moteInterfaces.getRadio().addObserver(radioDataObserver); moteInterfaces.getRadio().addObserver(radioDataObserver);

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: AbstractWakeupMote.java,v 1.1 2009/10/27 10:07:56 fros4943 Exp $ * $Id: AbstractWakeupMote.java,v 1.2 2010/10/04 12:54:01 joxe Exp $
*/ */
package se.sics.cooja.motes; package se.sics.cooja.motes;
@ -38,7 +38,8 @@ import se.sics.cooja.TimeEvent;
public abstract class AbstractWakeupMote implements Mote { public abstract class AbstractWakeupMote implements Mote {
private static Logger logger = Logger.getLogger(AbstractWakeupMote.class); private static Logger logger = Logger.getLogger(AbstractWakeupMote.class);
private Simulation simulation = null;
protected Simulation simulation = null;
private TimeEvent executeMoteEvent = new MoteTimeEvent(this, 0) { private TimeEvent executeMoteEvent = new MoteTimeEvent(this, 0) {
public void execute(long t) { public void execute(long t) {
@ -49,6 +50,15 @@ public abstract class AbstractWakeupMote implements Mote {
} }
}; };
public Simulation getSimulation() {
return simulation;
}
public void setSimulation(Simulation simulation) {
this.simulation = simulation;
}
/** /**
* Execute mote software. * Execute mote software.
* This method is only called from the simulation thread. * This method is only called from the simulation thread.
@ -67,9 +77,9 @@ public abstract class AbstractWakeupMote implements Mote {
* the mote software will execute as soon as possible. * the mote software will execute as soon as possible.
*/ */
public void requestImmediateWakeup() { public void requestImmediateWakeup() {
if (simulation == null) { // if (simulation == null) {
simulation = getSimulation(); // simulation = getSimulation();
} // }
if (simulation.isSimulationThread()) { if (simulation.isSimulationThread()) {
/* Schedule wakeup immediately */ /* Schedule wakeup immediately */
@ -97,14 +107,12 @@ public abstract class AbstractWakeupMote implements Mote {
* @return True iff wakeup request rescheduled the wakeup time. * @return True iff wakeup request rescheduled the wakeup time.
*/ */
public boolean scheduleNextWakeup(long time) { public boolean scheduleNextWakeup(long time) {
if (simulation == null) { // if (simulation == null) {
simulation = getSimulation(); // simulation = getSimulation();
} // }
if (!simulation.isSimulationThread()) {
throw new IllegalStateException("Scheduling wakeup from non-simulation thread");
}
assert simulation.isSimulationThread() : "Scheduling event from non-simulation thread";
if (executeMoteEvent.isScheduled() && if (executeMoteEvent.isScheduled() &&
executeMoteEvent.getTime() <= time) { executeMoteEvent.getTime() <= time) {
/* Already scheduled wakeup event precedes given time - ignore wakeup request */ /* Already scheduled wakeup event precedes given time - ignore wakeup request */