From 8a7f572e87a1f650e4b110c42df8c7bbcb582888 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 31 May 2012 01:33:25 +0200 Subject: [PATCH] Added serial interface that looks up default serial usart from MSPSim --- .../sics/cooja/mspmote/WismoteMoteType.java | 5 +- .../src/se/sics/cooja/mspmote/Z1MoteType.java | 4 +- .../mspmote/interfaces/MspDefaultSerial.java | 56 +++++++++++++++++++ .../cooja/mspmote/interfaces/MspSerial.java | 11 ++-- 4 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDefaultSerial.java diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/WismoteMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/WismoteMoteType.java index a73d44707..1ca3d841d 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/WismoteMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/WismoteMoteType.java @@ -41,9 +41,9 @@ import se.sics.cooja.mspmote.interfaces.Msp802154Radio; import se.sics.cooja.mspmote.interfaces.MspButton; import se.sics.cooja.mspmote.interfaces.MspClock; import se.sics.cooja.mspmote.interfaces.MspDebugOutput; +import se.sics.cooja.mspmote.interfaces.MspDefaultSerial; import se.sics.cooja.mspmote.interfaces.MspLED; import se.sics.cooja.mspmote.interfaces.MspMoteID; -import se.sics.cooja.mspmote.interfaces.UsciA1Serial; @ClassDescription("Wismote Mote Type") @AbstractionLevelDescription("Emulated level") @@ -84,8 +84,7 @@ public class WismoteMoteType extends AbstractMspMoteType { // SkyFlash.class, // SkyCoffeeFilesystem.class, Msp802154Radio.class, -// MspSerial.class, - UsciA1Serial.class, + MspDefaultSerial.class, MspLED.class, MspDebugOutput.class /* EXPERIMENTAL: Enable me for COOJA_DEBUG(..) */ ); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/Z1MoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/Z1MoteType.java index bd947f9e1..7b3fbcd39 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/Z1MoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/Z1MoteType.java @@ -41,9 +41,9 @@ import se.sics.cooja.interfaces.RimeAddress; import se.sics.cooja.mspmote.interfaces.Msp802154Radio; import se.sics.cooja.mspmote.interfaces.MspClock; import se.sics.cooja.mspmote.interfaces.MspDebugOutput; +import se.sics.cooja.mspmote.interfaces.MspDefaultSerial; import se.sics.cooja.mspmote.interfaces.MspLED; import se.sics.cooja.mspmote.interfaces.MspMoteID; -import se.sics.cooja.mspmote.interfaces.UsciA0Serial; @ClassDescription("Z1 Mote Type") @AbstractionLevelDescription("Emulated level") @@ -82,7 +82,7 @@ public class Z1MoteType extends AbstractMspMoteType { MspMoteID.class, // SkyFlash.class, Msp802154Radio.class, - UsciA0Serial.class, + MspDefaultSerial.class, MspLED.class, MspDebugOutput.class /* EXPERIMENTAL: Enable me for COOJA_DEBUG(..) */ ); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDefaultSerial.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDefaultSerial.java new file mode 100644 index 000000000..c2832c609 --- /dev/null +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDefaultSerial.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2012, 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. + * + * This file is part of COOJA. + * + */ +package se.sics.cooja.mspmote.interfaces; + +import se.sics.cooja.Mote; +import se.sics.cooja.mspmote.MspMote; +import se.sics.mspsim.core.USARTSource; + +/** + * @author Niclas Finne + * + */ +public class MspDefaultSerial extends MspSerial { + + public MspDefaultSerial(Mote mote) { + super(mote); + } + + @Override + protected USARTSource getUSARTSource(MspMote mote) { + USARTSource usart = mote.getCPU().getRegistry().getComponent(USARTSource.class, "serialio"); + if (usart != null) { + return usart; + } + return super.getUSARTSource(mote); + } + +} diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspSerial.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspSerial.java index 6b0ee14a3..6ef845a99 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspSerial.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspSerial.java @@ -41,7 +41,6 @@ import se.sics.cooja.dialogs.SerialUI; import se.sics.cooja.interfaces.SerialPort; import se.sics.cooja.mspmote.MspMote; import se.sics.cooja.mspmote.MspMoteTimeEvent; -import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.core.USARTSource; @@ -68,11 +67,9 @@ public class MspSerial extends SerialUI implements SerialPort { public MspSerial(Mote mote) { this.mote = (MspMote) mote; this.simulation = mote.getSimulation(); - /* Listen to port writes */ - IOUnit ioUnit = this.mote.getCPU().getIOUnit(ioConfigString()); - if (ioUnit instanceof USARTSource) { - usart = (USARTSource) ioUnit; + usart = getUSARTSource(this.mote); + if (usart != null) { usart.addUSARTListener(new USARTListener() { public void dataReceived(USARTSource source, int data) { MspSerial.this.dataReceived(data); @@ -93,6 +90,10 @@ public class MspSerial extends SerialUI implements SerialPort { } + protected USARTSource getUSARTSource(MspMote mote) { + return mote.getCPU().getIOUnit(USARTSource.class, ioConfigString()); + } + public void writeByte(byte b) { incomingData.add(b); if (writeDataEvent.isScheduled()) {