2011-02-11 13:27:17 +01:00
|
|
|
/*
|
|
|
|
* Example showing how to reference and interact with surrounding
|
|
|
|
* COOJA plugins from a test script.
|
|
|
|
* The code looks up three common plugins and, if found, performs some
|
|
|
|
* simple plugin-specific task.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Started plugins are available from the GUI object */
|
|
|
|
|
2011-03-14 18:33:18 +01:00
|
|
|
TIMEOUT(60000);
|
2011-02-11 13:27:17 +01:00
|
|
|
|
2011-03-14 18:33:18 +01:00
|
|
|
counter=0;
|
|
|
|
plugins=0;
|
|
|
|
|
|
|
|
timeout_function = function my_fun() {
|
|
|
|
log.log("Script timed out.\n");
|
|
|
|
log.log(plugins + " plugins were referenced\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
while (counter<10) {
|
|
|
|
counter++;
|
|
|
|
|
2011-02-11 13:27:17 +01:00
|
|
|
GENERATE_MSG(1000, "wait");
|
|
|
|
YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
|
|
|
|
|
|
|
|
/* Toggle Log Listener filter */
|
|
|
|
plugin = mote.getSimulation().getGUI().getStartedPlugin("se.sics.cooja.plugins.LogListener");
|
|
|
|
if (plugin != null) {
|
2011-03-14 18:33:18 +01:00
|
|
|
plugins++;
|
2011-02-11 13:27:17 +01:00
|
|
|
log.log("LogListener: Setting filter: " + plugin.getFilter() + "\n");
|
|
|
|
if (plugin.getFilter() == null || !plugin.getFilter().equals("Contiki")) {
|
|
|
|
plugin.setFilter("Contiki");
|
|
|
|
} else {
|
|
|
|
plugin.setFilter("MAC");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GENERATE_MSG(1000, "wait");
|
|
|
|
YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
|
|
|
|
|
2012-04-10 13:52:12 +02:00
|
|
|
/* Extract PowerTracker statistics */
|
|
|
|
plugin = mote.getSimulation().getGUI().getStartedPlugin("PowerTracker");
|
2011-02-11 13:27:17 +01:00
|
|
|
if (plugin != null) {
|
2011-03-14 18:33:18 +01:00
|
|
|
plugins++;
|
2012-04-10 13:52:12 +02:00
|
|
|
stats = plugin.radioStatistics();
|
2011-02-11 13:27:17 +01:00
|
|
|
if (stats.length() > 40) {
|
|
|
|
/* Stripping */
|
|
|
|
stats = stats.substring(0, 40) + "...";
|
|
|
|
}
|
2012-04-10 13:52:12 +02:00
|
|
|
log.log("PowerTracker: Extracted statistics:\n" + stats + "\n");
|
|
|
|
} else {
|
|
|
|
log.log("No PowerTracker plugin\n");
|
2011-02-11 13:27:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GENERATE_MSG(1000, "wait");
|
|
|
|
YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
|
|
|
|
|
|
|
|
/* Select time in Radio Logger */
|
|
|
|
plugin = mote.getSimulation().getGUI().getStartedPlugin("se.sics.cooja.plugins.RadioLogger");
|
|
|
|
if (plugin != null) {
|
2011-03-14 18:33:18 +01:00
|
|
|
plugins++;
|
2011-02-11 13:27:17 +01:00
|
|
|
log.log("RadioLogger: Showing logged radio packet at mid simulation\n");
|
|
|
|
plugin.trySelectTime(time/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|