added method for faking mote output in tests: mostly used for debugging
This commit is contained in:
parent
b2a98f49e6
commit
38b38edf95
1 changed files with 62 additions and 33 deletions
|
@ -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.9 2009/03/03 15:55:39 fros4943 Exp $
|
||||
* $Id: LogScriptEngine.java,v 1.10 2009/04/03 17:05:14 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.plugins;
|
||||
|
@ -138,6 +138,18 @@ public class LogScriptEngine {
|
|||
/* Create log observer: watches all log interfaces */
|
||||
logObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
Mote mote = (Mote) obj;
|
||||
handleNewMoteOutput(
|
||||
mote,
|
||||
mote.getInterfaces().getMoteID().getMoteID(),
|
||||
mote.getSimulation().getSimulationTime(),
|
||||
mote.getInterfaces().getLog().getLastLogMessage()
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void handleNewMoteOutput(Mote mote, int id, long time, String msg) {
|
||||
try {
|
||||
if (scriptThread == null ||
|
||||
!scriptThread.isAlive()) {
|
||||
|
@ -147,11 +159,10 @@ public class LogScriptEngine {
|
|||
}
|
||||
|
||||
/* Update script variables */
|
||||
Mote mote = (Mote) obj;
|
||||
engine.put("mote", mote);
|
||||
engine.put("id", mote.getInterfaces().getMoteID().getMoteID());
|
||||
engine.put("time", mote.getSimulation().getSimulationTime());
|
||||
engine.put("msg", mote.getInterfaces().getLog().getLastLogMessage());
|
||||
engine.put("id", id);
|
||||
engine.put("time", time);
|
||||
engine.put("msg", msg);
|
||||
|
||||
stepScript();
|
||||
|
||||
|
@ -166,8 +177,25 @@ public class LogScriptEngine {
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Inject faked mote log output.
|
||||
* Should only be used for debugging!
|
||||
*
|
||||
* @param msg Log message
|
||||
* @param mote Mote
|
||||
*/
|
||||
public void fakeMoteLogOutput(final String msg, final Mote mote) {
|
||||
gui.getSimulation().scheduleEvent(new TimeEvent(0) {
|
||||
public void execute(long time) {
|
||||
handleNewMoteOutput(
|
||||
mote,
|
||||
mote.getInterfaces().getMoteID().getMoteID(),
|
||||
mote.getSimulation().getSimulationTime(),
|
||||
msg
|
||||
);
|
||||
}
|
||||
}, gui.getSimulation().getSimulationTime());
|
||||
}
|
||||
|
||||
public void setScriptLogObserver(Observer observer) {
|
||||
|
@ -245,15 +273,15 @@ public class LogScriptEngine {
|
|||
semaphoreSim = null;
|
||||
}
|
||||
|
||||
if (scriptThread != null) {
|
||||
if (scriptThread != null && scriptThread != Thread.currentThread()) {
|
||||
try {
|
||||
scriptThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
scriptThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -323,12 +351,13 @@ public class LogScriptEngine {
|
|||
} else {
|
||||
if (!GUI.isVisualized()) {
|
||||
logger.fatal("Test script error, terminating Cooja.");
|
||||
e.printStackTrace();
|
||||
logger.fatal("Script error:", e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
/* Forward exception */
|
||||
throw e;
|
||||
logger.fatal("Script error:", e);
|
||||
gui.getSimulation().stopSimulation();
|
||||
deactivateScript();
|
||||
}
|
||||
}
|
||||
/*logger.info("test script thread exits");*/
|
||||
|
|
Loading…
Reference in a new issue