From 1d7efba71ae3e69c8a8da227b5e583cfded5c109 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 28 Oct 2008 16:09:52 +0000 Subject: [PATCH] updated example interface --- .../examples/project_new_interface/build.xml | 23 +++++++++ .../project_new_interface/dummy_intf.c | 16 +++--- .../java/DummyInterface.java | 49 +++++++++++++------ 3 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 tools/cooja/examples/project_new_interface/build.xml diff --git a/tools/cooja/examples/project_new_interface/build.xml b/tools/cooja/examples/project_new_interface/build.xml new file mode 100644 index 000000000..4df9641b3 --- /dev/null +++ b/tools/cooja/examples/project_new_interface/build.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/cooja/examples/project_new_interface/dummy_intf.c b/tools/cooja/examples/project_new_interface/dummy_intf.c index b12abdf14..a23c243d1 100644 --- a/tools/cooja/examples/project_new_interface/dummy_intf.c +++ b/tools/cooja/examples/project_new_interface/dummy_intf.c @@ -26,33 +26,35 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: dummy_intf.c,v 1.1 2007/03/23 23:33:54 fros4943 Exp $ + * $Id: dummy_intf.c,v 1.2 2008/10/28 16:09:52 fros4943 Exp $ */ #include "dummy_intf.h" #include "lib/simEnvChange.h" + #include -const struct simInterface beep_interface; +const struct simInterface dummy_interface; -// COOJA variables (shared between Java and C) -char simDummyVar; +/* COOJA variable simDummyVar is shared between Cooja and Contiki */ +char simDummyVar = 0; /*-----------------------------------------------------------------------------------*/ static void doInterfaceActionsBeforeTick(void) { - fprintf(stderr, "Core (C) dummy interface acts BEFORE mote tick\n"); + printf("Contiki-part of dummy interface acts BEFORE mote tick: %i\n", simDummyVar); } /*-----------------------------------------------------------------------------------*/ static void doInterfaceActionsAfterTick(void) { - fprintf(stderr, "Core (C) dummy interface acts AFTER mote tick\n"); + simDummyVar++; + printf("Contiki-part of dummy interface acts AFTER mote tick: %i\n", simDummyVar); } /*-----------------------------------------------------------------------------------*/ -// Register this as an available interface +/* Register interface */ SIM_INTERFACE(dummy_interface, doInterfaceActionsBeforeTick, doInterfaceActionsAfterTick); diff --git a/tools/cooja/examples/project_new_interface/java/DummyInterface.java b/tools/cooja/examples/project_new_interface/java/DummyInterface.java index 3f9ed7bb2..8a3ba6693 100644 --- a/tools/cooja/examples/project_new_interface/java/DummyInterface.java +++ b/tools/cooja/examples/project_new_interface/java/DummyInterface.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. + * Copyright (c) 2008, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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.1 2007/03/23 23:33:54 fros4943 Exp $ + * $Id: DummyInterface.java,v 1.2 2008/10/28 16:09:52 fros4943 Exp $ */ import java.util.*; @@ -35,29 +35,39 @@ import org.apache.log4j.Logger; import org.jdom.Element; import se.sics.cooja.*; +import se.sics.cooja.contikimote.ContikiMoteInterface; +import se.sics.cooja.interfaces.PolledAfterAllTicks; +import se.sics.cooja.interfaces.PolledBeforeAllTicks; /** - * This is an example of how to implement new simulation interfaces. - * - * It needs read/write access to the following core variables: + * An example of how to implement new mote interfaces. + * + * Contiki variables: * *

- * Dependency core interfaces are: + * + * Core interface: *

*

+ * * This observable never changes. * - * @author Fredrik Osterlind + * @author Fredrik Österlind */ @ClassDescription("Dummy Interface") -public class DummyInterface extends MoteInterface { +public class DummyInterface extends MoteInterface implements ContikiMoteInterface, PolledBeforeAllTicks, PolledAfterAllTicks { private static Logger logger = Logger.getLogger(DummyInterface.class); + private Mote mote; + private SectionMoteMemory memory; + public DummyInterface(Mote mote) { + this.mote = mote; + memory = (SectionMoteMemory) mote.getMemory(); } public static String[] getCoreInterfaceDependencies() { @@ -66,29 +76,36 @@ public class DummyInterface extends MoteInterface { } public void doActionsBeforeTick() { - logger.debug("Simulation (Java) dummy interface acts BEFORE mote tick"); + /* 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")); } public void doActionsAfterTick() { - logger.debug("Simulation (Java) dummy interface acts AFTER mote tick"); + byte dummyVal = memory.getByteValueOf("simDummyVar"); + dummyVal++; + memory.setByteValueOf("simDummyVar", dummyVal); + + logger.debug("Java-part of dummy interface acts AFTER mote tick: " + memory.getByteValueOf("simDummyVar")); } public JPanel getInterfaceVisualizer() { return null; // No visualizer exists } - + public void releaseInterfaceVisualizer(JPanel panel) { } - - public double energyConsumptionPerTick() { - return 0.0; // I never require any energy + + public double energyConsumption() { + return 0; /* My total energy consumption is always zero */ } public Collection getConfigXML() { return null; } - + public void setConfigXML(Collection configXML, boolean visAvailable) { } - + }