new event scheduling api
This commit is contained in:
parent
a81f216acb
commit
ed8867bcb5
12 changed files with 157 additions and 99 deletions
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ContikiButton.java,v 1.13 2009/05/26 14:24:20 fros4943 Exp $
|
||||
* $Id: ContikiButton.java,v 1.14 2009/10/27 10:11:17 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.contikimote.interfaces;
|
||||
|
@ -127,7 +127,7 @@ public class ContikiButton extends Button implements ContikiMoteInterface {
|
|||
moteMem.setByteValueOf("simButtonChanged", (byte) 1);
|
||||
|
||||
/* If mote is inactive, wake it up */
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
|
@ -141,7 +141,7 @@ public class ContikiButton extends Button implements ContikiMoteInterface {
|
|||
moteMem.setByteValueOf("simButtonChanged", (byte) 1);
|
||||
|
||||
/* If mote is inactive, wake it up */
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ContikiPIR.java,v 1.7 2009/05/26 14:24:20 fros4943 Exp $
|
||||
* $Id: ContikiPIR.java,v 1.8 2009/10/27 10:11:17 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.contikimote.interfaces;
|
||||
|
@ -119,7 +119,7 @@ public class ContikiPIR extends PIR implements ContikiMoteInterface {
|
|||
if (moteMem.getByteValueOf("simPirIsActive") == 1) {
|
||||
moteMem.setByteValueOf("simPirChanged", (byte) 1);
|
||||
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ContikiRS232.java,v 1.10 2009/06/15 14:40:28 fros4943 Exp $
|
||||
* $Id: ContikiRS232.java,v 1.11 2009/10/27 10:11:17 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.contikimote.interfaces;
|
||||
|
@ -119,8 +119,8 @@ public class ContikiRS232 extends SerialUI implements ContikiMoteInterface, Poll
|
|||
public void writeString(String message) {
|
||||
final byte[] dataToAppend = message.getBytes();
|
||||
|
||||
TimeEvent writeStringEvent = new MoteTimeEvent(mote, 0) {
|
||||
public void execute(long t) {
|
||||
mote.getSimulation().invokeSimulationThread(new Runnable() {
|
||||
public void run() {
|
||||
/* Append to existing buffer */
|
||||
int oldSize = moteMem.getIntValueOf("simSerialReceivingLength");
|
||||
int newSize = oldSize + dataToAppend.length;
|
||||
|
@ -135,13 +135,9 @@ public class ContikiRS232 extends SerialUI implements ContikiMoteInterface, Poll
|
|||
moteMem.setByteArray("simSerialReceivingData", newData);
|
||||
|
||||
moteMem.setByteValueOf("simSerialReceivingFlag", (byte) 1);
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
}
|
||||
};
|
||||
mote.getSimulation().scheduleEvent(
|
||||
writeStringEvent,
|
||||
mote.getSimulation().getSimulationTime()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public double energyConsumption() {
|
||||
|
@ -196,13 +192,17 @@ public class ContikiRS232 extends SerialUI implements ContikiMoteInterface, Poll
|
|||
|
||||
/* Reschedule us if more bytes are available */
|
||||
mote.getSimulation().scheduleEvent(this, t);
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
}
|
||||
};
|
||||
mote.getSimulation().scheduleEvent(
|
||||
pendingBytesEvent,
|
||||
mote.getSimulation().getSimulationTime()
|
||||
);
|
||||
mote.getSimulation().invokeSimulationThread(new Runnable() {
|
||||
public void run() {
|
||||
mote.getSimulation().scheduleEvent(
|
||||
pendingBytesEvent,
|
||||
mote.getSimulation().getSimulationTime()
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void writeByte(final byte b) {
|
||||
|
@ -245,13 +245,17 @@ public class ContikiRS232 extends SerialUI implements ContikiMoteInterface, Poll
|
|||
|
||||
/* Reschedule us if more bytes are available */
|
||||
mote.getSimulation().scheduleEvent(this, t);
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
}
|
||||
};
|
||||
mote.getSimulation().scheduleEvent(
|
||||
pendingBytesEvent,
|
||||
mote.getSimulation().getSimulationTime()
|
||||
);
|
||||
mote.getSimulation().invokeSimulationThread(new Runnable() {
|
||||
public void run() {
|
||||
mote.getSimulation().scheduleEvent(
|
||||
pendingBytesEvent,
|
||||
mote.getSimulation().getSimulationTime()
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ContikiRadio.java,v 1.29 2009/09/17 11:06:35 fros4943 Exp $
|
||||
* $Id: ContikiRadio.java,v 1.30 2009/10/27 10:11:17 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.contikimote.interfaces;
|
||||
|
@ -223,7 +223,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledA
|
|||
// Unlock (if locked)
|
||||
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
|
||||
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
|
||||
lastEventTime = mote.getSimulation().getSimulationTime();
|
||||
lastEvent = RadioEvent.RECEPTION_FINISHED;
|
||||
|
@ -241,7 +241,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledA
|
|||
|
||||
lastEventTime = mote.getSimulation().getSimulationTime();
|
||||
lastEvent = RadioEvent.RECEPTION_FINISHED;
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
this.setChanged();
|
||||
this.notifyObservers();
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledA
|
|||
* data to the mote.
|
||||
*/
|
||||
private void lockInReceivingMode() {
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
|
||||
// Lock core radio in receiving loop
|
||||
myMoteMemory.setByteValueOf("simReceiving", (byte) 1);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ContikiVib.java,v 1.7 2009/05/26 14:24:20 fros4943 Exp $
|
||||
* $Id: ContikiVib.java,v 1.8 2009/10/27 10:11:17 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.contikimote.interfaces;
|
||||
|
@ -119,7 +119,7 @@ public class ContikiVib extends MoteInterface implements ContikiMoteInterface {
|
|||
if (moteMem.getByteValueOf("simVibIsActive") == 1) {
|
||||
moteMem.setByteValueOf("simVibChanged", (byte) 1);
|
||||
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: Battery.java,v 1.9 2009/09/17 11:08:07 fros4943 Exp $
|
||||
* $Id: Battery.java,v 1.10 2009/10/27 10:11:17 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.interfaces;
|
||||
|
@ -127,7 +127,7 @@ public class Battery extends MoteInterface implements PolledAfterAllTicks {
|
|||
|
||||
/* Check if we are out of energy */
|
||||
if (getEnergyConsumption() > INITIAL_ENERGY) {
|
||||
mote.scheduleImmediateWakeup();
|
||||
mote.requestImmediateWakeup();
|
||||
}
|
||||
|
||||
setChanged();
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: LogScriptEngine.java,v 1.19 2009/10/23 11:55:53 fros4943 Exp $
|
||||
* $Id: LogScriptEngine.java,v 1.20 2009/10/27 10:12:00 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.plugins;
|
||||
|
@ -103,11 +103,11 @@ public class LogScriptEngine {
|
|||
|
||||
/* Check if test script requested us to stop */
|
||||
if (stopSimulation) {
|
||||
stopSimulationEvent.execute(0);
|
||||
stopSimulationRunnable.run();
|
||||
stopSimulation = false;
|
||||
}
|
||||
if (quitCooja) {
|
||||
quitEvent.execute(0);
|
||||
quitRunnable.run();
|
||||
quitCooja = false;
|
||||
}
|
||||
}
|
||||
|
@ -173,8 +173,8 @@ public class LogScriptEngine {
|
|||
* @param mote Mote
|
||||
*/
|
||||
public void fakeMoteLogOutput(final String msg, final Mote mote) {
|
||||
simulation.scheduleEvent(new TimeEvent(0) {
|
||||
public void execute(long time) {
|
||||
simulation.invokeSimulationThread(new Runnable() {
|
||||
public void run() {
|
||||
handleNewMoteOutput(
|
||||
mote,
|
||||
mote.getID(),
|
||||
|
@ -182,7 +182,7 @@ public class LogScriptEngine {
|
|||
msg
|
||||
);
|
||||
}
|
||||
}, simulation.getSimulationTime());
|
||||
});
|
||||
}
|
||||
|
||||
public void setScriptLogObserver(Observer observer) {
|
||||
|
@ -281,17 +281,16 @@ public class LogScriptEngine {
|
|||
String jsCode = parser.getJSCode();
|
||||
|
||||
long timeoutTime = parser.getTimeoutTime();
|
||||
if (timeoutTime > 0) {
|
||||
simulation.scheduleEvent(
|
||||
timeoutEvent,
|
||||
simulation.getSimulationTime() + timeoutTime);
|
||||
} else {
|
||||
logger.info("No timeout defined, using default (us): " +
|
||||
(simulation.getSimulationTime() + DEFAULT_TIMEOUT));
|
||||
simulation.scheduleEvent(
|
||||
timeoutEvent,
|
||||
(simulation.getSimulationTime() + DEFAULT_TIMEOUT));
|
||||
if (timeoutTime < 0) {
|
||||
logger.info("No timeout defined, using default (us): " + DEFAULT_TIMEOUT);
|
||||
timeoutTime = DEFAULT_TIMEOUT;
|
||||
}
|
||||
final long absoluteTimeout = simulation.getSimulationTime() + timeoutTime;
|
||||
simulation.invokeSimulationThread(new Runnable() {
|
||||
public void run() {
|
||||
simulation.scheduleEvent(timeoutEvent, absoluteTimeout);
|
||||
}
|
||||
});
|
||||
|
||||
engine.eval(jsCode);
|
||||
|
||||
|
@ -375,10 +374,10 @@ public class LogScriptEngine {
|
|||
if (GUI.isVisualized()) {
|
||||
log("[if test was run without visualization, COOJA would now have been terminated]\n");
|
||||
stopSimulation = true;
|
||||
simulation.scheduleEvent(stopSimulationEvent, simulation.getSimulationTime());
|
||||
simulation.invokeSimulationThread(stopSimulationRunnable);
|
||||
} else {
|
||||
quitCooja = true;
|
||||
simulation.scheduleEvent(quitEvent, simulation.getSimulationTime());
|
||||
simulation.invokeSimulationThread(quitRunnable);
|
||||
}
|
||||
|
||||
timeoutEvent.remove();
|
||||
|
@ -392,19 +391,19 @@ public class LogScriptEngine {
|
|||
if (GUI.isVisualized()) {
|
||||
log("[if test was run without visualization, COOJA would now have been terminated]\n");
|
||||
stopSimulation = true;
|
||||
simulation.scheduleEvent(stopSimulationEvent, simulation.getSimulationTime());
|
||||
simulation.invokeSimulationThread(stopSimulationRunnable);
|
||||
} else {
|
||||
quitCooja = true;
|
||||
simulation.scheduleEvent(quitEvent, simulation.getSimulationTime());
|
||||
simulation.invokeSimulationThread(quitRunnable);
|
||||
}
|
||||
|
||||
semaphoreSim.release(100);
|
||||
throw new RuntimeException("test script killed");
|
||||
}
|
||||
|
||||
public void generateMessage(long delay, final String msg) {
|
||||
public void generateMessage(final long delay, final String msg) {
|
||||
final Mote currentMote = (Mote) engine.get("mote");
|
||||
TimeEvent generateEvent = new TimeEvent(0) {
|
||||
final TimeEvent generateEvent = new TimeEvent(0) {
|
||||
public void execute(long t) {
|
||||
if (scriptThread == null ||
|
||||
!scriptThread.isAlive()) {
|
||||
|
@ -422,9 +421,13 @@ public class LogScriptEngine {
|
|||
stepScript();
|
||||
}
|
||||
};
|
||||
simulation.scheduleEvent(
|
||||
generateEvent,
|
||||
simulation.getSimulationTime() + delay*Simulation.MILLISECOND);
|
||||
simulation.invokeSimulationThread(new Runnable() {
|
||||
public void run() {
|
||||
simulation.scheduleEvent(
|
||||
generateEvent,
|
||||
simulation.getSimulationTime() + delay*Simulation.MILLISECOND);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -444,14 +447,14 @@ public class LogScriptEngine {
|
|||
stepScript();
|
||||
}
|
||||
};
|
||||
private TimeEvent stopSimulationEvent = new TimeEvent(0) {
|
||||
public void execute(long time) {
|
||||
private Runnable stopSimulationRunnable = new Runnable() {
|
||||
public void run() {
|
||||
simulation.stopSimulation();
|
||||
timeoutEvent.remove();
|
||||
}
|
||||
};
|
||||
private TimeEvent quitEvent = new TimeEvent(0) {
|
||||
public void execute(long time) {
|
||||
private Runnable quitRunnable = new Runnable() {
|
||||
public void run() {
|
||||
simulation.stopSimulation();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: SimControl.java,v 1.15 2009/07/06 12:29:57 fros4943 Exp $
|
||||
* $Id: SimControl.java,v 1.16 2009/10/27 10:12:00 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.plugins;
|
||||
|
@ -122,7 +122,7 @@ public class SimControl extends VisPlugin {
|
|||
stopEvent.remove();
|
||||
}
|
||||
|
||||
long t = ((Number)e.getNewValue()).intValue()*Simulation.MILLISECOND;
|
||||
final long t = ((Number)e.getNewValue()).intValue()*Simulation.MILLISECOND;
|
||||
if (t <= SimControl.this.simulation.getSimulationTime()) {
|
||||
/* No simulation stop scheduled */
|
||||
stopTimeTextField.setBackground(Color.LIGHT_GRAY);
|
||||
|
@ -131,7 +131,11 @@ public class SimControl extends VisPlugin {
|
|||
/* Schedule simulation stop */
|
||||
stopTimeTextField.setBackground(Color.WHITE);
|
||||
stopTimeTextField.setToolTipText("Simulation will stop at time (us): " + t);
|
||||
SimControl.this.simulation.scheduleEvent(stopEvent, t);
|
||||
SimControl.this.simulation.invokeSimulationThread(new Runnable() {
|
||||
public void run() {
|
||||
SimControl.this.simulation.scheduleEvent(stopEvent, t);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue