added cooja mote type using mspsim's msp430x platforms (ti's exp5438)

This commit is contained in:
Fredrik Osterlind 2012-01-18 21:27:11 +01:00
parent 79e26d79a8
commit 5cca043a84
12 changed files with 1030 additions and 12 deletions

View File

@ -59,8 +59,15 @@
</javadoc>
</target>
<target name="jar" depends="init, compile">
<jar destfile="${cooja_mspsim_jar}" basedir="${build}">
<target name="copy" depends="init">
<copy todir="build">
<fileset file="exp5438.png"/>
<fileset file="tyndall.png"/>
</copy>
</target>
<target name="jar" depends="init, compile, copy">
<jar destfile="${cooja_mspsim_jar}" basedir="${build}">
<manifest>
<attribute name="Class-Path" value="."/>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote;
import java.io.File;
import org.apache.log4j.Logger;
import se.sics.cooja.Simulation;
import se.sics.mspsim.platform.ti.Exp5438Node;
/**
* @author Fredrik Osterlind
*/
public class Exp5438Mote extends MspMote {
private static Logger logger = Logger.getLogger(Exp5438Mote.class);
public Exp5438Node exp5438Node = null;
public Exp5438Mote() {
super();
}
public Exp5438Mote(MspMoteType moteType, Simulation sim) {
super(moteType, sim);
}
protected boolean initEmulator(File fileELF) {
try {
exp5438Node = new Exp5438Node();
registry = exp5438Node.getRegistry();
prepareMote(fileELF, exp5438Node);
} catch (Exception e) {
logger.fatal("Error when creating Exp5438 mote: ", e);
return false;
}
return true;
}
public void idUpdated(int newID) {
}
public String toString() {
return "Exp5438 " + getID();
}
}

View File

@ -0,0 +1,211 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote;
import java.awt.Container;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.io.File;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.apache.log4j.Logger;
import se.sics.cooja.AbstractionLevelDescription;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.GUI;
import se.sics.cooja.MoteInterface;
import se.sics.cooja.MoteType;
import se.sics.cooja.Simulation;
import se.sics.cooja.dialogs.CompileContiki;
import se.sics.cooja.dialogs.MessageList;
import se.sics.cooja.dialogs.MessageList.MessageContainer;
import se.sics.cooja.interfaces.IPAddress;
import se.sics.cooja.interfaces.Mote2MoteRelations;
import se.sics.cooja.interfaces.MoteAttributes;
import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.RimeAddress;
import se.sics.cooja.mspmote.interfaces.Exp5438LED;
import se.sics.cooja.mspmote.interfaces.MspClock;
import se.sics.cooja.mspmote.interfaces.MspDebugOutput;
import se.sics.cooja.mspmote.interfaces.MspMoteID;
import se.sics.cooja.mspmote.interfaces.SkyByteRadio;
import se.sics.cooja.mspmote.interfaces.UsciA1Serial;
@ClassDescription("TI MSP-EXP430F5438")
@AbstractionLevelDescription("Emulated level")
public class Exp5438MoteType extends MspMoteType {
private static Logger logger = Logger.getLogger(Exp5438MoteType.class);
protected MspMote createMote(Simulation simulation) {
return new Exp5438Mote(this, simulation);
}
public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable)
throws MoteTypeCreationException {
this.simulation = simulation;
/* If visualized, show compile dialog and let user configure */
if (visAvailable) {
/* Create unique identifier */
if (getIdentifier() == null) {
int counter = 0;
boolean identifierOK = false;
while (!identifierOK) {
identifierOK = true;
counter++;
setIdentifier("exp5438#" + counter);
for (MoteType existingMoteType : simulation.getMoteTypes()) {
if (existingMoteType == this) {
continue;
}
if (existingMoteType.getIdentifier().equals(getIdentifier())) {
identifierOK = false;
break;
}
}
}
}
/* Create initial description */
if (getDescription() == null) {
setDescription("Exp5438 Mote Type " + getIdentifier());
}
return MspCompileDialog.showDialog(parentContainer, simulation, this, "exp5438");
}
/* Not visualized: Compile Contiki immediately */
if (getIdentifier() == null) {
throw new MoteTypeCreationException("No identifier");
}
final MessageList compilationOutput = new MessageList();
if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */
String[] arr = getCompileCommands().split("\n");
for (String cmd: arr) {
if (cmd.trim().isEmpty()) {
continue;
}
try {
CompileContiki.compile(
cmd,
null,
null /* Do not observe output firmware file */,
getContikiSourceFile().getParentFile(),
null,
null,
compilationOutput,
true
);
} catch (Exception e) {
MoteTypeCreationException newException =
new MoteTypeCreationException("Mote type creation failed: " + e.getMessage());
newException = (MoteTypeCreationException) newException.initCause(e);
newException.setCompilationOutput(compilationOutput);
/* Print last 10 compilation errors to console */
MessageContainer[] messages = compilationOutput.getMessages();
for (int i=messages.length-10; i < messages.length; i++) {
if (i < 0) {
continue;
}
logger.fatal(">> " + messages[i]);
}
logger.fatal("Compilation error: " + e.getMessage());
throw newException;
}
}
}
if (getContikiFirmwareFile() == null ||
!getContikiFirmwareFile().exists()) {
throw new MoteTypeCreationException("Contiki firmware file does not exist: " + getContikiFirmwareFile());
}
return true;
}
public Icon getMoteTypeIcon() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
URL imageURL = this.getClass().getClassLoader().getResource("exp5438.png");
Image image = toolkit.getImage(imageURL);
MediaTracker tracker = new MediaTracker(GUI.getTopParentContainer());
tracker.addImage(image, 1);
try {
tracker.waitForAll();
} catch (InterruptedException ex) {
}
if (image.getHeight(GUI.getTopParentContainer()) > 0 && image.getWidth(GUI.getTopParentContainer()) > 0) {
image = image.getScaledInstance((200*image.getWidth(GUI.getTopParentContainer())/image.getHeight(GUI.getTopParentContainer())), 200, Image.SCALE_DEFAULT);
return new ImageIcon(image);
}
return null;
}
public Class<? extends MoteInterface>[] getAllMoteInterfaceClasses() {
return new Class[] {
Position.class,
RimeAddress.class,
IPAddress.class,
Mote2MoteRelations.class,
MoteAttributes.class,
MspClock.class,
MspMoteID.class,
SkyByteRadio.class,
UsciA1Serial.class,
Exp5438LED.class,
/*Exp5438LCD.class,*/ /* TODO */
MspDebugOutput.class
};
}
public File getExpectedFirmwareFile(File source) {
File parentDir = source.getParentFile();
String sourceNoExtension = source.getName().substring(0, source.getName().length()-2);
return new File(parentDir, sourceNoExtension + ".exp5438");
}
protected String getTargetName() {
return "exp5438";
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote;
import java.io.File;
import org.apache.log4j.Logger;
import se.sics.cooja.Simulation;
import se.sics.mspsim.platform.ti.Exp5438Node;
import se.sics.mspsim.platform.tyndall.TyndallNode;
/**
* @author Fredrik Osterlind
*/
public class TyndallMote extends MspMote {
private static Logger logger = Logger.getLogger(TyndallMote.class);
public TyndallNode tyndallNode = null;
public TyndallMote() {
super();
}
public TyndallMote(MspMoteType moteType, Simulation sim) {
super(moteType, sim);
}
protected boolean initEmulator(File fileELF) {
try {
tyndallNode = new TyndallNode();
registry = tyndallNode.getRegistry();
prepareMote(fileELF, tyndallNode);
} catch (Exception e) {
logger.fatal("Error when creating Tyndall mote: ", e);
return false;
}
return true;
}
public void idUpdated(int newID) {
}
public String toString() {
return "Tyndall " + getID();
}
}

View File

@ -0,0 +1,210 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote;
import java.awt.Container;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.io.File;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.apache.log4j.Logger;
import se.sics.cooja.AbstractionLevelDescription;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.GUI;
import se.sics.cooja.MoteInterface;
import se.sics.cooja.MoteType;
import se.sics.cooja.Simulation;
import se.sics.cooja.dialogs.CompileContiki;
import se.sics.cooja.dialogs.MessageList;
import se.sics.cooja.dialogs.MessageList.MessageContainer;
import se.sics.cooja.interfaces.IPAddress;
import se.sics.cooja.interfaces.Mote2MoteRelations;
import se.sics.cooja.interfaces.MoteAttributes;
import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.RimeAddress;
import se.sics.cooja.mspmote.interfaces.MspClock;
import se.sics.cooja.mspmote.interfaces.MspDebugOutput;
import se.sics.cooja.mspmote.interfaces.MspMoteID;
import se.sics.cooja.mspmote.interfaces.SkyByteRadio;
import se.sics.cooja.mspmote.interfaces.TyndallLED;
import se.sics.cooja.mspmote.interfaces.UsciA0Serial;
@ClassDescription("Tyndall")
@AbstractionLevelDescription("Emulated level")
public class TyndallMoteType extends MspMoteType {
private static Logger logger = Logger.getLogger(TyndallMoteType.class);
protected MspMote createMote(Simulation simulation) {
return new TyndallMote(this, simulation);
}
public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable)
throws MoteTypeCreationException {
this.simulation = simulation;
/* If visualized, show compile dialog and let user configure */
if (visAvailable) {
/* Create unique identifier */
if (getIdentifier() == null) {
int counter = 0;
boolean identifierOK = false;
while (!identifierOK) {
identifierOK = true;
counter++;
setIdentifier("tyndall#" + counter);
for (MoteType existingMoteType : simulation.getMoteTypes()) {
if (existingMoteType == this) {
continue;
}
if (existingMoteType.getIdentifier().equals(getIdentifier())) {
identifierOK = false;
break;
}
}
}
}
/* Create initial description */
if (getDescription() == null) {
setDescription("Tyndall Mote Type " + getIdentifier());
}
return MspCompileDialog.showDialog(parentContainer, simulation, this, "tyndall");
}
/* Not visualized: Compile Contiki immediately */
if (getIdentifier() == null) {
throw new MoteTypeCreationException("No identifier");
}
final MessageList compilationOutput = new MessageList();
if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */
String[] arr = getCompileCommands().split("\n");
for (String cmd: arr) {
if (cmd.trim().isEmpty()) {
continue;
}
try {
CompileContiki.compile(
cmd,
null,
null /* Do not observe output firmware file */,
getContikiSourceFile().getParentFile(),
null,
null,
compilationOutput,
true
);
} catch (Exception e) {
MoteTypeCreationException newException =
new MoteTypeCreationException("Mote type creation failed: " + e.getMessage());
newException = (MoteTypeCreationException) newException.initCause(e);
newException.setCompilationOutput(compilationOutput);
/* Print last 10 compilation errors to console */
MessageContainer[] messages = compilationOutput.getMessages();
for (int i=messages.length-10; i < messages.length; i++) {
if (i < 0) {
continue;
}
logger.fatal(">> " + messages[i]);
}
logger.fatal("Compilation error: " + e.getMessage());
throw newException;
}
}
}
if (getContikiFirmwareFile() == null ||
!getContikiFirmwareFile().exists()) {
throw new MoteTypeCreationException("Contiki firmware file does not exist: " + getContikiFirmwareFile());
}
return true;
}
public Icon getMoteTypeIcon() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
URL imageURL = this.getClass().getClassLoader().getResource("tyndall.png");
Image image = toolkit.getImage(imageURL);
MediaTracker tracker = new MediaTracker(GUI.getTopParentContainer());
tracker.addImage(image, 1);
try {
tracker.waitForAll();
} catch (InterruptedException ex) {
}
if (image.getHeight(GUI.getTopParentContainer()) > 0 && image.getWidth(GUI.getTopParentContainer()) > 0) {
image = image.getScaledInstance((200*image.getWidth(GUI.getTopParentContainer())/image.getHeight(GUI.getTopParentContainer())), 200, Image.SCALE_DEFAULT);
return new ImageIcon(image);
}
return null;
}
public Class<? extends MoteInterface>[] getAllMoteInterfaceClasses() {
return new Class[] {
Position.class,
RimeAddress.class,
IPAddress.class,
Mote2MoteRelations.class,
MoteAttributes.class,
MspClock.class,
MspMoteID.class,
SkyByteRadio.class,
UsciA0Serial.class,
TyndallLED.class,
MspDebugOutput.class
};
}
public File getExpectedFirmwareFile(File source) {
File parentDir = source.getParentFile();
String sourceNoExtension = source.getName().substring(0, source.getName().length()-2);
return new File(parentDir, sourceNoExtension + ".tyndall");
}
protected String getTargetName() {
return "tyndall";
}
}

View File

@ -0,0 +1,170 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote.interfaces;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Collection;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.interfaces.LED;
import se.sics.cooja.mspmote.Exp5438Mote;
import se.sics.mspsim.core.IOPort;
import se.sics.mspsim.core.IOUnit;
import se.sics.mspsim.core.PortListener;
import se.sics.mspsim.platform.ti.Exp5438Node;
/**
* @author Fredrik Osterlind
*/
@ClassDescription("Exp5438 LEDs")
public class Exp5438LED extends LED {
private static Logger logger = Logger.getLogger(Exp5438LED.class);
private Exp5438Mote mspMote;
private boolean redOn = false;
private boolean yellowOn = false;
private static final Color RED = new Color(255, 0, 0);
private static final Color DARK_RED = new Color(100, 0, 0);
private static final Color YELLOW = new Color(255, 255, 0);
private static final Color DARK_YELLOW = new Color(184,134,11);
public Exp5438LED(Mote mote) {
mspMote = (Exp5438Mote) mote;
IOUnit unit = mspMote.getCPU().getIOUnit("P1");
if (unit instanceof IOPort) {
((IOPort) unit).setPortListener(new PortListener() {
public void portWrite(IOPort source, int data) {
redOn = (data & Exp5438Node.LEDS_CONF_RED) != 0;
yellowOn = (data & Exp5438Node.LEDS_CONF_YELLOW) != 0;
setChanged();
notifyObservers();
}
});
}
}
public boolean isAnyOn() {
return redOn || yellowOn;
}
public boolean isGreenOn() {
return false; /* does not exist */
}
public boolean isRedOn() {
return redOn;
}
public boolean isYellowOn() {
return yellowOn;
}
public JPanel getInterfaceVisualizer() {
final JPanel panel = new JPanel() {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
super.paintComponent(g);
int x = 20;
int y = 25;
int d = 25;
if (isRedOn()) {
g.setColor(RED);
g.fillOval(x, y, d, d);
g.setColor(Color.BLACK);
g.drawOval(x, y, d, d);
} else {
g.setColor(DARK_RED);
g.fillOval(x + 5, y + 5, d-10, d-10);
}
x += 40;
if (isYellowOn()) {
g.setColor(YELLOW);
g.fillOval(x, y, d, d);
g.setColor(Color.BLACK);
g.drawOval(x, y, d, d);
} else {
g.setColor(DARK_YELLOW);
g.fillOval(x + 5, y + 5, d-10, d-10);
}
}
};
Observer observer;
this.addObserver(observer = new Observer() {
public void update(Observable obs, Object obj) {
panel.repaint();
}
});
// Saving observer reference for releaseInterfaceVisualizer
panel.putClientProperty("intf_obs", observer);
panel.setMinimumSize(new Dimension(140, 60));
panel.setPreferredSize(new Dimension(140, 60));
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 Collection<Element> getConfigXML() {
return null;
}
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* Copyright (c) 2011, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -25,8 +25,6 @@
* 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: MspSerial.java,v 1.4 2010/02/04 00:30:26 fros4943 Exp $
*/
package se.sics.cooja.mspmote.interfaces;
@ -44,7 +42,6 @@ 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.USART;
import se.sics.mspsim.core.USARTListener;
import se.sics.mspsim.core.USARTSource;
@ -59,22 +56,24 @@ public class MspSerial extends SerialUI implements SerialPort {
private Simulation simulation;
private MspMote mote;
private USART usart;
private USARTSource usart;
private Vector<Byte> incomingData = new Vector<Byte>();
private TimeEvent writeDataEvent;
public String ioConfigString() {
return "USART 1";
}
public MspSerial(Mote mote) {
this.mote = (MspMote) mote;
this.simulation = mote.getSimulation();
/* Listen to port writes */
IOUnit ioUnit = this.mote.getCPU().getIOUnit("USART 1");
if (ioUnit instanceof USART) {
usart = (USART) ioUnit;
IOUnit ioUnit = this.mote.getCPU().getIOUnit(ioConfigString());
if (ioUnit instanceof USARTSource) {
usart = (USARTSource) ioUnit;
usart.setUSARTListener(new USARTListener() {
@Override
public void dataReceived(USARTSource source, int data) {
MspSerial.this.dataReceived(data);
}

View File

@ -0,0 +1,180 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote.interfaces;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Collection;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.interfaces.LED;
import se.sics.cooja.mspmote.TyndallMote;
import se.sics.mspsim.core.IOPort;
import se.sics.mspsim.core.IOUnit;
import se.sics.mspsim.core.PortListener;
import se.sics.mspsim.platform.tyndall.TyndallNode;
/**
* @author Fredrik Osterlind
*/
@ClassDescription("Tyndall LEDs")
public class TyndallLED extends LED {
private static Logger logger = Logger.getLogger(TyndallLED.class);
private TyndallMote mspMote;
private boolean greenOn = false;
private boolean redOn = false;
private boolean yellowOn = false;
private static final Color RED = new Color(255, 0, 0);
private static final Color DARK_RED = new Color(100, 0, 0);
private static final Color GREEN = new Color(0, 255, 0);
private static final Color DARK_GREEN = new Color(0,100,0);
public TyndallLED(Mote mote) {
mspMote = (TyndallMote) mote;
IOUnit unit = mspMote.getCPU().getIOUnit("P7");
if (unit instanceof IOPort) {
((IOPort) unit).setPortListener(new PortListener() {
public void portWrite(IOPort source, int data) {
redOn = (data & TyndallNode.LEDS_CONF_RED) == 0;
setChanged();
notifyObservers();
}
});
}
unit = mspMote.getCPU().getIOUnit("P8");
if (unit instanceof IOPort) {
((IOPort) unit).setPortListener(new PortListener() {
public void portWrite(IOPort source, int data) {
greenOn = (data & TyndallNode.LEDS_CONF_GREEN) == 0;
setChanged();
notifyObservers();
}
});
}
}
public boolean isAnyOn() {
return greenOn || redOn || yellowOn;
}
public boolean isGreenOn() {
return greenOn;
}
public boolean isRedOn() {
return redOn;
}
public boolean isYellowOn() {
return yellowOn;
}
public JPanel getInterfaceVisualizer() {
final JPanel panel = new JPanel() {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
super.paintComponent(g);
int x = 20;
int y = 25;
int d = 25;
if (isGreenOn()) {
g.setColor(GREEN);
g.fillOval(x, y, d, d);
g.setColor(Color.BLACK);
g.drawOval(x, y, d, d);
} else {
g.setColor(DARK_GREEN);
g.fillOval(x + 5, y + 5, d-10, d-10);
}
x += 40;
if (isRedOn()) {
g.setColor(RED);
g.fillOval(x, y, d, d);
g.setColor(Color.BLACK);
g.drawOval(x, y, d, d);
} else {
g.setColor(DARK_RED);
g.fillOval(x + 5, y + 5, d-10, d-10);
}
}
};
Observer observer;
this.addObserver(observer = new Observer() {
public void update(Observable obs, Object obj) {
panel.repaint();
}
});
// Saving observer reference for releaseInterfaceVisualizer
panel.putClientProperty("intf_obs", observer);
panel.setMinimumSize(new Dimension(140, 60));
panel.setPreferredSize(new Dimension(140, 60));
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 Collection<Element> getConfigXML() {
return null;
}
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote.interfaces;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
/**
* @author Fredrik Osterlind
*/
@ClassDescription("Serial port")
public class UsciA0Serial extends MspSerial {
public UsciA0Serial(Mote mote) {
super(mote);
}
public String ioConfigString() {
return "USCI A0";
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2011, 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.
*/
package se.sics.cooja.mspmote.interfaces;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
/**
* @author Fredrik Osterlind
*/
@ClassDescription("Serial port")
public class UsciA1Serial extends MspSerial {
public UsciA1Serial(Mote mote) {
super(mote);
}
public String ioConfigString() {
return "USCI A1";
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB