updated example interface
This commit is contained in:
parent
641c48ee00
commit
1d7efba71a
3 changed files with 65 additions and 23 deletions
23
tools/cooja/examples/project_new_interface/build.xml
Normal file
23
tools/cooja/examples/project_new_interface/build.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<project name="Mote interface example" default="compile" basedir=".">
|
||||||
|
<property name="src" location="java"/>
|
||||||
|
<property name="build" location="java"/>
|
||||||
|
|
||||||
|
<property name="cooja" location="../.."/>
|
||||||
|
<property name="cooja_jar" value="${cooja}/dist/cooja.jar"/>
|
||||||
|
|
||||||
|
<target name="init">
|
||||||
|
<tstamp/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile" depends="init">
|
||||||
|
<mkdir dir="${build}"/>
|
||||||
|
<javac srcdir="${src}" destdir="${build}" debug="on">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${cooja_jar}"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
|
@ -26,33 +26,35 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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 "dummy_intf.h"
|
||||||
#include "lib/simEnvChange.h"
|
#include "lib/simEnvChange.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
const struct simInterface beep_interface;
|
const struct simInterface dummy_interface;
|
||||||
|
|
||||||
// COOJA variables (shared between Java and C)
|
/* COOJA variable simDummyVar is shared between Cooja and Contiki */
|
||||||
char simDummyVar;
|
char simDummyVar = 0;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
doInterfaceActionsBeforeTick(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
|
static void
|
||||||
doInterfaceActionsAfterTick(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,
|
SIM_INTERFACE(dummy_interface,
|
||||||
doInterfaceActionsBeforeTick,
|
doInterfaceActionsBeforeTick,
|
||||||
doInterfaceActionsAfterTick);
|
doInterfaceActionsAfterTick);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
* Copyright (c) 2008, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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.*;
|
import java.util.*;
|
||||||
|
@ -35,29 +35,39 @@ import org.apache.log4j.Logger;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
|
||||||
import se.sics.cooja.*;
|
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.
|
* An example of how to implement new mote interfaces.
|
||||||
*
|
*
|
||||||
* It needs read/write access to the following core variables:
|
* Contiki variables:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>char simDummyVar
|
* <li>char simDummyVar
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* Dependency core interfaces are:
|
*
|
||||||
|
* Core interface:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>dummy_interface
|
* <li>dummy_interface
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
|
*
|
||||||
* This observable never changes.
|
* This observable never changes.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("Dummy Interface")
|
@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 static Logger logger = Logger.getLogger(DummyInterface.class);
|
||||||
|
|
||||||
|
private Mote mote;
|
||||||
|
private SectionMoteMemory memory;
|
||||||
|
|
||||||
public DummyInterface(Mote mote) {
|
public DummyInterface(Mote mote) {
|
||||||
|
this.mote = mote;
|
||||||
|
memory = (SectionMoteMemory) mote.getMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getCoreInterfaceDependencies() {
|
public static String[] getCoreInterfaceDependencies() {
|
||||||
|
@ -66,29 +76,36 @@ public class DummyInterface extends MoteInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsBeforeTick() {
|
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() {
|
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() {
|
public JPanel getInterfaceVisualizer() {
|
||||||
return null; // No visualizer exists
|
return null; // No visualizer exists
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseInterfaceVisualizer(JPanel panel) {
|
public void releaseInterfaceVisualizer(JPanel panel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double energyConsumptionPerTick() {
|
public double energyConsumption() {
|
||||||
return 0.0; // I never require any energy
|
return 0; /* My total energy consumption is always zero */
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Element> getConfigXML() {
|
public Collection<Element> getConfigXML() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
|
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue