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)

This commit is contained in:
fros4943 2009-12-02 17:12:32 +00:00
parent 36d09eaa69
commit 5f88fac53c
6 changed files with 32 additions and 150 deletions

View file

@ -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,

View file

@ -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<? extends MoteInterface> moteInterfaceClass = simulation.getGUI().tryLoadClass(
this, MoteInterface.class, intfClass);

View file

@ -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<? extends MoteInterface> moteInterfaceClass =
simulation.getGUI().tryLoadClass(this, MoteInterface.class, intfClass);

View file

@ -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
};
}

View file

@ -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<Element> getConfigXML() {
return null;
}
public void setConfigXML(Collection<Element> 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) {
}
}

View file

@ -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<Byte> incomingData = new Vector<Byte>();
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) {