diff --git a/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMote.java b/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMote.java index 7f01daa3c..173525c5b 100644 --- a/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMote.java +++ b/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMote.java @@ -1,7 +1,7 @@ /* * Copyright (c) 2007, Swedish Institute of Computer Science. All rights * reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 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 * products derived from this software without specific prior written * permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * 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; @@ -39,6 +39,13 @@ import se.sics.cooja.interfaces.ApplicationRadio; import se.sics.cooja.interfaces.Position; 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 { private static Logger logger = Logger.getLogger(AbstractApplicationMote.class); @@ -58,19 +65,21 @@ public abstract class AbstractApplicationMote implements Mote { handleNewRadioData(obs, obj); } }; - + public void handleNewRadioData(Observable obs, Object obj) { - if (myApplicationRadio.getLastEvent() != Radio.RadioEvent.RECEPTION_FINISHED) + if (myApplicationRadio.getLastEvent() != Radio.RadioEvent.RECEPTION_FINISHED) { return; + } logger.info("Application mote received radio data:"); - byte[] packet = myApplicationRadio.getLastPacketReceived(); + byte[] packet = myApplicationRadio.getLastPacketReceived().getPacketData(); String data = ""; - for (byte b: packet) + for (byte b: packet) { data += (char)b; + } logger.info(data); } - + public AbstractApplicationMote() { } @@ -163,7 +172,7 @@ public abstract class AbstractApplicationMote implements Mote { config.add(element); } } - + // Passive interface configs (if any) for (MoteInterface moteInterface: getInterfaces().getAllPassiveInterfaces()) { element = new Element("interface_config"); @@ -191,7 +200,7 @@ public abstract class AbstractApplicationMote implements Mote { myApplicationRadio = new ApplicationRadio(this); myApplicationRadio.addObserver(radioDataObserver); myInterfaceHandler.addActiveInterface(myApplicationRadio); - + for (Element element : configXML) { String name = element.getName(); @@ -218,8 +227,9 @@ public abstract class AbstractApplicationMote implements Mote { public String toString() { if (getInterfaces().getMoteID() != null) { return "Application Mote, ID=" + getInterfaces().getMoteID().getMoteID(); - } else + } else { return "Application Mote, ID=null"; + } } }