updated example interface

This commit is contained in:
fros4943 2008-10-28 16:09:52 +00:00
parent 641c48ee00
commit 1d7efba71a
3 changed files with 65 additions and 23 deletions

View 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>

View file

@ -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 <stdio.h>
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);

View file

@ -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.
* An example of how to implement new mote interfaces.
*
* It needs read/write access to the following core variables:
* Contiki variables:
* <ul>
* <li>char simDummyVar
* </ul>
* <p>
* Dependency core interfaces are:
*
* Core interface:
* <ul>
* <li>dummy_interface
* </ul>
* <p>
*
* 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,11 +76,18 @@ 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() {
@ -80,8 +97,8 @@ public class DummyInterface extends MoteInterface {
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<Element> getConfigXML() {