From 34844188dd9a4e64a20810b1daebca03eae6cf5f Mon Sep 17 00:00:00 2001 From: fros4943 Date: Fri, 15 Jan 2010 10:52:55 +0000 Subject: [PATCH] added script example, demonstrating how to interact with surrounding cooja plugins --- tools/cooja/config/scripts/plugins.js | 50 +++++++++++++++++++ .../se/sics/cooja/plugins/ScriptRunner.java | 3 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tools/cooja/config/scripts/plugins.js diff --git a/tools/cooja/config/scripts/plugins.js b/tools/cooja/config/scripts/plugins.js new file mode 100644 index 000000000..9efb6964c --- /dev/null +++ b/tools/cooja/config/scripts/plugins.js @@ -0,0 +1,50 @@ +/* + * 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 */ + +while (true) { + + 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) { + 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")); + + /* Extract Timeline statistics */ + plugin = mote.getSimulation().getGUI().getStartedPlugin("se.sics.cooja.plugins.TimeLine"); + if (plugin != null) { + stats = plugin.extractStatistics(); + if (stats.length() > 40) { + /* Stripping */ + stats = stats.substring(0, 40) + "..."; + } + log.log("Timeline: Extracted statistics:\n" + stats + "\n"); + } + + 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) { + log.log("RadioLogger: Showing logged radio packet at mid simulation\n"); + plugin.trySelectTime(time/2); + } + +} diff --git a/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java b/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java index 51205ad41..5127de972 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java +++ b/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ScriptRunner.java,v 1.24 2009/10/29 14:39:08 fros4943 Exp $ + * $Id: ScriptRunner.java,v 1.25 2010/01/15 10:52:55 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -70,6 +70,7 @@ public class ScriptRunner extends VisPlugin { "helloworld.js", "Wait for 'Hello, world'", "log_all.js", "Just log all printf()'s and timeout", "shell.js", "Basic shell interaction", + "plugins.js", "Interact with surrounding COOJA plugins", }; private Simulation simulation;