From 5f88fac53ce32834875282a48ece691c6db23e6f Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 2 Dec 2009 17:12:32 +0000 Subject: [PATCH] renamed serial port mote interface SkySerial to MspSerial + replaced ESB's log mote interface with the new MspSerial (ESB motes can now read serial port data) --- .../se/sics/cooja/mspmote/ESBMoteType.java | 6 +- .../src/se/sics/cooja/mspmote/MspMote.java | 9 +- .../se/sics/cooja/mspmote/MspMoteType.java | 11 +- .../se/sics/cooja/mspmote/SkyMoteType.java | 6 +- .../sics/cooja/mspmote/interfaces/ESBLog.java | 134 ------------------ .../{SkySerial.java => MspSerial.java} | 16 +-- 6 files changed, 32 insertions(+), 150 deletions(-) delete mode 100644 tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/ESBLog.java rename tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/{SkySerial.java => MspSerial.java} (92%) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java index 3a50ab148..aee64e90d 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBMoteType.java,v 1.11 2009/12/02 16:27:59 fros4943 Exp $ + * $Id: ESBMoteType.java,v 1.12 2009/12/02 17:12:32 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -47,9 +47,9 @@ import se.sics.cooja.interfaces.Position; import se.sics.cooja.interfaces.RimeAddress; import se.sics.cooja.mspmote.interfaces.ESBButton; import se.sics.cooja.mspmote.interfaces.ESBLED; -import se.sics.cooja.mspmote.interfaces.ESBLog; import se.sics.cooja.mspmote.interfaces.MspClock; import se.sics.cooja.mspmote.interfaces.MspMoteID; +import se.sics.cooja.mspmote.interfaces.MspSerial; import se.sics.cooja.mspmote.interfaces.TR1001Radio; @ClassDescription("ESB Mote Type") @@ -192,7 +192,7 @@ public class ESBMoteType extends MspMoteType { Position.class, RimeAddress.class, IPAddress.class, - ESBLog.class, + MspSerial.class, MspClock.class, ESBLED.class, ESBButton.class, diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java index 0f753915e..d7934f305 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspMote.java,v 1.35 2009/11/27 15:53:10 fros4943 Exp $ + * $Id: MspMote.java,v 1.36 2009/12/02 17:12:32 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -55,6 +55,7 @@ import se.sics.cooja.Watchpoint; import se.sics.cooja.WatchpointMote; import se.sics.cooja.interfaces.IPAddress; import se.sics.cooja.motes.AbstractEmulatedMote; +import se.sics.cooja.mspmote.interfaces.MspSerial; import se.sics.cooja.mspmote.plugins.MspBreakpointContainer; import se.sics.mspsim.cli.CommandHandler; import se.sics.mspsim.cli.LineListener; @@ -413,6 +414,12 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc if (intfClass.equals("se.sics.cooja.mspmote.interfaces.MspIPAddress")) { intfClass = IPAddress.class.getName(); } + if (intfClass.equals("se.sics.cooja.mspmote.interfaces.ESBLog")) { + intfClass = MspSerial.class.getName(); + } + if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkySerial")) { + intfClass = MspSerial.class.getName(); + } Class moteInterfaceClass = simulation.getGUI().tryLoadClass( this, MoteInterface.class, intfClass); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java index 722f7afb2..a00cf61fe 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspMoteType.java,v 1.32 2009/09/18 09:26:22 fros4943 Exp $ + * $Id: MspMoteType.java,v 1.33 2009/12/02 17:15:59 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -41,6 +41,7 @@ import org.apache.log4j.Logger; import org.jdom.Element; import se.sics.cooja.*; import se.sics.cooja.interfaces.IPAddress; +import se.sics.cooja.mspmote.interfaces.MspSerial; /** * MSP430-based mote types emulated in MSPSim. @@ -283,6 +284,14 @@ public abstract class MspMoteType implements MoteType { logger.warn("Old simulation config detected: IP address interface was moved"); intfClass = IPAddress.class.getName(); } + if (intfClass.equals("se.sics.cooja.mspmote.interfaces.ESBLog")) { + logger.warn("Old simulation config detected: ESBLog was replaced by MspSerial"); + intfClass = MspSerial.class.getName(); + } + if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkySerial")) { + logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial"); + intfClass = MspSerial.class.getName(); + } Class moteInterfaceClass = simulation.getGUI().tryLoadClass(this, MoteInterface.class, intfClass); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java index 571b59ad4..186d069a7 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMoteType.java,v 1.12 2009/12/02 16:27:59 fros4943 Exp $ + * $Id: SkyMoteType.java,v 1.13 2009/12/02 17:12:32 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -64,7 +64,7 @@ import se.sics.cooja.mspmote.interfaces.SkyByteRadio; import se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem; import se.sics.cooja.mspmote.interfaces.SkyFlash; import se.sics.cooja.mspmote.interfaces.SkyLED; -import se.sics.cooja.mspmote.interfaces.SkySerial; +import se.sics.cooja.mspmote.interfaces.MspSerial; @ClassDescription("Sky Mote Type") @AbstractionLevelDescription("Emulated level") @@ -213,7 +213,7 @@ public class SkyMoteType extends MspMoteType { SkyFlash.class, SkyCoffeeFilesystem.class, SkyByteRadio.class, - SkySerial.class, + MspSerial.class, SkyLED.class }; } diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/ESBLog.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/ESBLog.java deleted file mode 100644 index c2510d039..000000000 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/ESBLog.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the 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 DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND 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: ESBLog.java,v 1.5 2009/03/09 17:14:35 fros4943 Exp $ - */ - -package se.sics.cooja.mspmote.interfaces; - -import java.awt.*; -import java.util.*; -import javax.swing.*; -import org.apache.log4j.Logger; -import org.jdom.Element; - -import se.sics.cooja.*; -import se.sics.mspsim.core.*; -import se.sics.cooja.interfaces.Log; -import se.sics.cooja.mspmote.ESBMote; - -/** - * @author Fredrik Osterlind - */ -@ClassDescription("Serial port") -public class ESBLog extends Log implements USARTListener { - private static Logger logger = Logger.getLogger(ESBLog.class); - - private ESBMote mote; - private String lastLogMessage = ""; - private String newMessage = ""; - - public ESBLog(Mote mote) { - this.mote = (ESBMote) mote; - - /* Listen to port writes */ - IOUnit usart = this.mote.getCPU().getIOUnit("USART 1"); - if (usart instanceof USART) { - ((USART) usart).setUSARTListener(this); - } - } - - public String getLastLogMessage() { - return lastLogMessage; - } - - public JPanel getInterfaceVisualizer() { - JPanel panel = new JPanel(); - panel.setLayout(new BorderLayout()); - final JTextArea logTextPane = new JTextArea(); - logTextPane.setOpaque(false); - logTextPane.setEditable(false); - - if (getLastLogMessage() == null) { - logTextPane.setText(""); - } else { - logTextPane.append(getLastLogMessage()); - } - - Observer observer; - this.addObserver(observer = new Observer() { - public void update(Observable obs, Object obj) { - logTextPane.append(getLastLogMessage()); - logTextPane.setCaretPosition(logTextPane.getDocument().getLength()); - } - }); - - // Saving observer reference for releaseInterfaceVisualizer - panel.putClientProperty("intf_obs", observer); - - JScrollPane scrollPane = new JScrollPane(logTextPane); - scrollPane.setPreferredSize(new Dimension(100,100)); - panel.add(BorderLayout.NORTH, new JLabel("Last log messages:")); - panel.add(BorderLayout.CENTER, scrollPane); - return panel; - } - - public void releaseInterfaceVisualizer(JPanel panel) { - Observer observer = (Observer) panel.getClientProperty("intf_obs"); - if (observer == null) { - logger.fatal("Error when releasing panel, observer is null"); - return; - } - - this.deleteObserver(observer); - } - - public double energyConsumption() { - return 0; - } - - public Collection getConfigXML() { - return null; - } - - public void setConfigXML(Collection configXML, boolean visAvailable) { - } - - public void dataReceived(USART source, int data) { - newMessage += (char) data; - if (data == '\n') { - lastLogMessage = newMessage; - newMessage = ""; - this.setChanged(); - this.notifyObservers(mote); - } - } - - public void stateChanged(int state) { - } -} diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkySerial.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspSerial.java similarity index 92% rename from tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkySerial.java rename to tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspSerial.java index 2b7f862a3..f944c6537 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkySerial.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspSerial.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkySerial.java,v 1.18 2009/10/28 15:58:42 fros4943 Exp $ + * $Id: MspSerial.java,v 1.1 2009/12/02 17:12:32 fros4943 Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -42,7 +42,7 @@ import se.sics.cooja.Simulation; import se.sics.cooja.TimeEvent; import se.sics.cooja.dialogs.SerialUI; import se.sics.cooja.interfaces.SerialPort; -import se.sics.cooja.mspmote.SkyMote; +import se.sics.cooja.mspmote.MspMote; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTListener; @@ -51,19 +51,19 @@ import se.sics.mspsim.core.USARTListener; * @author Fredrik Osterlind */ @ClassDescription("Serial port") -public class SkySerial extends SerialUI implements SerialPort { +public class MspSerial extends SerialUI implements SerialPort { private static final long DELAY_INCOMING_DATA = 69; /* 115200 bit/s */ - private static Logger logger = Logger.getLogger(SkySerial.class); + private static Logger logger = Logger.getLogger(MspSerial.class); private Simulation simulation; - private SkyMote mote; + private MspMote mote; private USART usart; private Vector incomingData = new Vector(); - public SkySerial(Mote mote) { - this.mote = (SkyMote) mote; + public MspSerial(Mote mote) { + this.mote = (MspMote) mote; this.simulation = mote.getSimulation(); /* Listen to port writes */ @@ -72,7 +72,7 @@ public class SkySerial extends SerialUI implements SerialPort { usart = (USART) ioUnit; usart.setUSARTListener(new USARTListener() { public void dataReceived(USART arg0, int arg1) { - SkySerial.this.dataReceived(arg1); + MspSerial.this.dataReceived(arg1); } public void stateChanged(int state) { if (state == USARTListener.RXFLAG_CLEARED) {