From b143dbe4b28dbd7f71b170278b56c862528a1ec7 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 26 May 2009 14:34:43 +0000 Subject: [PATCH] example updates --- .../java/DummyInterface.java | 5 +-- .../java/MyDummyPlugin.java | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/tools/cooja/examples/project_new_interface/java/DummyInterface.java b/tools/cooja/examples/project_new_interface/java/DummyInterface.java index 8a3ba6693..ca61689c3 100644 --- a/tools/cooja/examples/project_new_interface/java/DummyInterface.java +++ b/tools/cooja/examples/project_new_interface/java/DummyInterface.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: DummyInterface.java,v 1.2 2008/10/28 16:09:52 fros4943 Exp $ + * $Id: DummyInterface.java,v 1.3 2009/05/26 14:34:43 fros4943 Exp $ */ import java.util.*; @@ -76,9 +76,6 @@ public class DummyInterface extends MoteInterface implements ContikiMoteInterfac } public void doActionsBeforeTick() { - /* Wake up potentially sleeping Contiki mote */ - mote.setState(Mote.State.ACTIVE); - logger.debug("Java-part of dummy interface acts BEFORE mote tick: " + memory.getByteValueOf("simDummyVar")); } diff --git a/tools/cooja/examples/project_new_plugin/java/MyDummyPlugin.java b/tools/cooja/examples/project_new_plugin/java/MyDummyPlugin.java index 5baf53e5e..b34a26832 100644 --- a/tools/cooja/examples/project_new_plugin/java/MyDummyPlugin.java +++ b/tools/cooja/examples/project_new_plugin/java/MyDummyPlugin.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MyDummyPlugin.java,v 1.2 2008/10/28 16:22:35 fros4943 Exp $ + * $Id: MyDummyPlugin.java,v 1.3 2009/05/26 14:34:43 fros4943 Exp $ */ import java.awt.event.*; @@ -45,10 +45,10 @@ import se.sics.cooja.*; @ClassDescription("Dummy Plugin") /* Description shown in menu */ @PluginType(PluginType.SIM_PLUGIN) public class MyDummyPlugin extends VisPlugin { - private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(MyDummyPlugin.class); + private Simulation mySimulation; - private Observer tickObserver; + private Observer millisecondObserver; /** * Creates a new dummy plugin. @@ -56,37 +56,43 @@ public class MyDummyPlugin extends VisPlugin { * @param simulationToVisualize Simulation to visualize */ public MyDummyPlugin(Simulation simulationToVisualize, GUI gui) { - super("This is my title!", gui); + super("Example plugin title", gui); mySimulation = simulationToVisualize; // Create and add a button JButton button = new JButton("dummy button"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - logger.info("You just pressed my button"); + logger.info("Button clicked"); } }); add(button); - // Register as tickobserver - mySimulation.addTickObserver(tickObserver = new Observer() { + /* Register as millisecond observer */ + mySimulation.addMillisecondObserver(millisecondObserver = new Observer() { public void update(Observable obs, Object obj) { - logger.info("Another tick loop completed - simulation time is now:\t" + mySimulation.getSimulationTime()); + logger.info("Another millisecond passed - simulation time is now " + mySimulation.getSimulationTimeMillis() + " ms"); } }); + + /* Register self-repeating event */ + repeatEvent.execute(mySimulation.getSimulationTime()); setSize(300,100); // Set an initial size of this plugin - - // Tries to select this plugin - try { - setSelected(true); - } catch (java.beans.PropertyVetoException e) { - // Could not select - } } + private TimeEvent repeatEvent = new TimeEvent(0) { + public void execute(long t) { + logger.info("Event executed - simulation time is now " + mySimulation.getSimulationTimeMillis() + " ms"); + + mySimulation.scheduleEvent(this, t+10*Simulation.MILLISECOND); + } + }; + public void closePlugin() { - mySimulation.deleteTickObserver(tickObserver); + /* Clean up plugin resources */ + mySimulation.deleteMillisecondObserver(millisecondObserver); + repeatEvent.remove(); } }