added script example, demonstrating how to interact with surrounding cooja plugins
This commit is contained in:
parent
d3f367ff58
commit
34844188dd
50
tools/cooja/config/scripts/plugins.js
Normal file
50
tools/cooja/config/scripts/plugins.js
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user