using new radio packet format and some documentation

This commit is contained in:
fros4943 2008-03-18 13:05:23 +00:00
parent 4fc082db35
commit 84d2353966

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2007, Swedish Institute of Computer Science. All rights * Copyright (c) 2007, Swedish Institute of Computer Science. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* Institute nor the names of its contributors may be used to endorse or promote * Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written * products derived from this software without specific prior written
* permission. * permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -23,8 +23,8 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: AbstractApplicationMote.java,v 1.1 2007/05/31 07:21:29 fros4943 Exp $ * $Id: AbstractApplicationMote.java,v 1.2 2008/03/18 13:05:23 fros4943 Exp $
*/ */
package se.sics.cooja.motes; package se.sics.cooja.motes;
@ -39,6 +39,13 @@ import se.sics.cooja.interfaces.ApplicationRadio;
import se.sics.cooja.interfaces.Position; import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
/**
* Abstract application mote.
*
* Simplifies implementation of application level mote types.
*
* @author Fredrik Osterlind
*/
public abstract class AbstractApplicationMote implements Mote { public abstract class AbstractApplicationMote implements Mote {
private static Logger logger = Logger.getLogger(AbstractApplicationMote.class); private static Logger logger = Logger.getLogger(AbstractApplicationMote.class);
@ -58,19 +65,21 @@ public abstract class AbstractApplicationMote implements Mote {
handleNewRadioData(obs, obj); handleNewRadioData(obs, obj);
} }
}; };
public void handleNewRadioData(Observable obs, Object obj) { public void handleNewRadioData(Observable obs, Object obj) {
if (myApplicationRadio.getLastEvent() != Radio.RadioEvent.RECEPTION_FINISHED) if (myApplicationRadio.getLastEvent() != Radio.RadioEvent.RECEPTION_FINISHED) {
return; return;
}
logger.info("Application mote received radio data:"); logger.info("Application mote received radio data:");
byte[] packet = myApplicationRadio.getLastPacketReceived(); byte[] packet = myApplicationRadio.getLastPacketReceived().getPacketData();
String data = ""; String data = "";
for (byte b: packet) for (byte b: packet) {
data += (char)b; data += (char)b;
}
logger.info(data); logger.info(data);
} }
public AbstractApplicationMote() { public AbstractApplicationMote() {
} }
@ -163,7 +172,7 @@ public abstract class AbstractApplicationMote implements Mote {
config.add(element); config.add(element);
} }
} }
// Passive interface configs (if any) // Passive interface configs (if any)
for (MoteInterface moteInterface: getInterfaces().getAllPassiveInterfaces()) { for (MoteInterface moteInterface: getInterfaces().getAllPassiveInterfaces()) {
element = new Element("interface_config"); element = new Element("interface_config");
@ -191,7 +200,7 @@ public abstract class AbstractApplicationMote implements Mote {
myApplicationRadio = new ApplicationRadio(this); myApplicationRadio = new ApplicationRadio(this);
myApplicationRadio.addObserver(radioDataObserver); myApplicationRadio.addObserver(radioDataObserver);
myInterfaceHandler.addActiveInterface(myApplicationRadio); myInterfaceHandler.addActiveInterface(myApplicationRadio);
for (Element element : configXML) { for (Element element : configXML) {
String name = element.getName(); String name = element.getName();
@ -218,8 +227,9 @@ public abstract class AbstractApplicationMote implements Mote {
public String toString() { public String toString() {
if (getInterfaces().getMoteID() != null) { if (getInterfaces().getMoteID() != null) {
return "Application Mote, ID=" + getInterfaces().getMoteID().getMoteID(); return "Application Mote, ID=" + getInterfaces().getMoteID().getMoteID();
} else } else {
return "Application Mote, ID=null"; return "Application Mote, ID=null";
}
} }
} }