mirror of https://github.com/contiki-ng/mspsim
Added support for platforms Sentilla JCreate and Sentilla Gateway USB
git-svn-id: https://mspsim.svn.sourceforge.net/svnroot/mspsim/mspsim@727 23d1a52b-0c3c-0410-b72d-8f29ab48fe35
This commit is contained in:
parent
c1795858f2
commit
303915baf7
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
|
|
@ -66,6 +66,22 @@ public class Main {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static String getNodeTypeByPlatform(String platform) {
|
||||
if ("jcreate".equals(platform)) {
|
||||
return "se.sics.mspsim.platform.jcreate.JCreateNode";
|
||||
}
|
||||
if ("sentilla-usb".equals(platform)) {
|
||||
return "se.sics.mspsim.platform.sentillausb.SentillaUSBNode";
|
||||
}
|
||||
if ("esb".equals(platform)) {
|
||||
return "se.sics.mspsim.platform.esb.ESBNode";
|
||||
}
|
||||
// Try to guess the node type.
|
||||
return "se.sics.mspsim.platform." + platform + '.'
|
||||
+ Character.toUpperCase(platform.charAt(0))
|
||||
+ platform.substring(1).toLowerCase() + "Node";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ArgumentManager config = new ArgumentManager();
|
||||
config.handleArguments(args);
|
||||
|
|
@ -77,13 +93,8 @@ public class Main {
|
|||
node = createNode(nodeType);
|
||||
} else {
|
||||
platform = config.getProperty("platform", "sky");
|
||||
nodeType = "se.sics.mspsim.platform." + platform + '.' +
|
||||
Character.toUpperCase(platform.charAt(0)) + platform.substring(1).toLowerCase() + "Node";
|
||||
nodeType = getNodeTypeByPlatform(platform);
|
||||
node = createNode(nodeType);
|
||||
if (node == null) {
|
||||
nodeType = "se.sics.mspsim.platform." + platform + '.' + platform.toUpperCase() + "Node";
|
||||
node = createNode(nodeType);
|
||||
}
|
||||
}
|
||||
if (node == null) {
|
||||
System.err.println("MSPSim does not currently support the platform '" + platform + "'.");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 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 MSPSim.
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* MMA7260QT
|
||||
*
|
||||
* Authors : Niclas Finne
|
||||
* Created : 7 jul 2010
|
||||
* Updated : $Date$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
package se.sics.mspsim.chip;
|
||||
import se.sics.mspsim.core.Chip;
|
||||
import se.sics.mspsim.core.MSP430Core;
|
||||
|
||||
/**
|
||||
* MMA7260QT - 1.5g-6g Three Axis Low-g Micromachined Accelerometer
|
||||
*/
|
||||
public class MMA7260QT extends Chip {
|
||||
|
||||
public static final int MODE_SLEEP = 0x00;
|
||||
public static final int MODE_ACTIVE = 0x01;
|
||||
private static final String[] MODE_NAMES = new String[] {
|
||||
"sleep", "active"
|
||||
};
|
||||
private static final float[] GSELECT = new float[] {
|
||||
1.5f, 2, 4, 6
|
||||
};
|
||||
|
||||
private int x = 4095, y = 2715, z = 2715;
|
||||
private int gSelect = 0;
|
||||
|
||||
public MMA7260QT(MSP430Core cpu) {
|
||||
super("MMA7260QT", "Accelerometer", cpu);
|
||||
setModeNames(MODE_NAMES);
|
||||
setMode(MODE_SLEEP);
|
||||
}
|
||||
|
||||
public int getADCX() {
|
||||
int v = getX();
|
||||
return v > 4095 ? 4095 : v;
|
||||
}
|
||||
|
||||
public int getADCY() {
|
||||
int v = getY();
|
||||
return v > 4095 ? 4095 : v;
|
||||
}
|
||||
|
||||
public int getADCZ() {
|
||||
int v = getZ();
|
||||
return v > 4095 ? 4095 : v;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setZ(int z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public int getSensitivity() {
|
||||
return gSelect;
|
||||
}
|
||||
|
||||
public String getSensitivityAsString() {
|
||||
return GSELECT[gSelect] + "g (" + (int)(1200/GSELECT[gSelect]) + "mV/g)";
|
||||
}
|
||||
|
||||
public void setSensitivity(int gSelect) {
|
||||
this.gSelect = gSelect & 0x03;
|
||||
}
|
||||
|
||||
public void setMode(int mode) {
|
||||
super.setMode(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModeMax() {
|
||||
return MODE_NAMES.length;
|
||||
}
|
||||
|
||||
public String info() {
|
||||
return "Mode: " + getModeName(getMode())
|
||||
+ " Sensitivity: " + getSensitivityAsString()
|
||||
+ " [x=" + getADCX() + ",y=" + getADCY() + ",z=" + getADCZ() + ']';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/**
|
||||
* Copyright (c) 2010, 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 MSPSim.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* JCreateGui
|
||||
*
|
||||
* Author : Joakim Eriksson, Niclas Finne
|
||||
* Created : 7 jul 2010
|
||||
* Updated : $Date$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
package se.sics.mspsim.platform.jcreate;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
|
||||
import se.sics.mspsim.platform.AbstractNodeGUI;
|
||||
|
||||
public class JCreateGui extends AbstractNodeGUI {
|
||||
|
||||
private static final long serialVersionUID = -1377998375300964966L;
|
||||
|
||||
private static final Color RED_TRANS = new Color(0xff, 0x40, 0x40, 0xa0);
|
||||
private static final Color RED_O = new Color(0xff,0x40,0x40,0xff);
|
||||
private static final Color RED_I = new Color(0xff,0x60,0x60,0xff);
|
||||
private static final Color RED_CORE = new Color(0xff,0xa0,0xa0,0xff);
|
||||
|
||||
private static final int LEDS_Y = 66;
|
||||
private static final int LEDS_X[] = {29, 49, 67, 86, 103, 122, 142, 162};
|
||||
private static final Rectangle LEDS_CLIP = new Rectangle(LEDS_X[0], LEDS_Y,
|
||||
LEDS_X[LEDS_X.length - 1] + 10 - LEDS_X[0], 10);
|
||||
|
||||
private final JCreateNode node;
|
||||
|
||||
public JCreateGui(JCreateNode node) {
|
||||
super("JCreateGui", "images/jcreate.jpg");
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startGUI() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopGUI() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
Color old = g.getColor();
|
||||
// Display all active leds
|
||||
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
int leds = node.getLeds();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((leds & (0x80 >> i)) != 0) {
|
||||
paintLed(g, i);
|
||||
}
|
||||
}
|
||||
g.setColor(old);
|
||||
}
|
||||
|
||||
protected void paintLed(Graphics g, int led) {
|
||||
int x = LEDS_X[led];
|
||||
g.setColor(RED_TRANS);
|
||||
g.fillOval(x, LEDS_Y, 10, 10);
|
||||
g.setColor(RED_O);
|
||||
g.fillOval(x + 2, LEDS_Y + 2, 6, 6);
|
||||
g.setColor(RED_I);
|
||||
g.fillOval(x + 3, LEDS_Y + 3, 4, 4);
|
||||
g.setColor(RED_CORE);
|
||||
g.fillRect(x + 3, LEDS_Y + 3, 2, 2);
|
||||
}
|
||||
|
||||
void updateLeds() {
|
||||
repaint(LEDS_CLIP);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/**
|
||||
* Copyright (c) 2010, 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 MSPSim.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* JCreateNode
|
||||
*
|
||||
* Author : Joakim Eriksson, Niclas Finne
|
||||
* Created : 7 jul 2010
|
||||
* Updated : $Date$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
package se.sics.mspsim.platform.jcreate;
|
||||
import java.io.IOException;
|
||||
|
||||
import se.sics.mspsim.chip.FileM25P80;
|
||||
import se.sics.mspsim.chip.M25P80;
|
||||
import se.sics.mspsim.chip.MMA7260QT;
|
||||
import se.sics.mspsim.core.ADC12;
|
||||
import se.sics.mspsim.core.ADCInput;
|
||||
import se.sics.mspsim.core.IOPort;
|
||||
import se.sics.mspsim.core.IOUnit;
|
||||
import se.sics.mspsim.core.USART;
|
||||
import se.sics.mspsim.platform.sky.CC2420Node;
|
||||
import se.sics.mspsim.util.ArgumentManager;
|
||||
|
||||
/**
|
||||
* Emulation of Sentilla JCreate Mote
|
||||
*/
|
||||
public class JCreateNode extends CC2420Node {
|
||||
|
||||
public static final int MODE_LEDS_OFF = 0;
|
||||
public static final int MODE_MAX = 9;
|
||||
|
||||
private MMA7260QT accelerometer;
|
||||
private M25P80 flash;
|
||||
|
||||
private JCreateGui gui;
|
||||
private int leds;
|
||||
|
||||
public JCreateNode() {
|
||||
super("Sentilla JCreate");
|
||||
setMode(MODE_LEDS_OFF);
|
||||
}
|
||||
|
||||
public int getLeds() {
|
||||
return leds;
|
||||
}
|
||||
|
||||
public MMA7260QT getAccelerometer() {
|
||||
return accelerometer;
|
||||
}
|
||||
|
||||
public M25P80 getFlash() {
|
||||
return flash;
|
||||
}
|
||||
|
||||
public void setFlash(M25P80 flash) {
|
||||
this.flash = flash;
|
||||
registry.registerComponent("xmem", flash);
|
||||
}
|
||||
|
||||
// USART Listener
|
||||
@Override
|
||||
public void dataReceived(USART source, int data) {
|
||||
radio.dataReceived(source, data);
|
||||
flash.dataReceived(source, data);
|
||||
/* if nothing selected, just write back a random byte to this device */
|
||||
if (!radio.getChipSelect() && !flash.getChipSelect()) {
|
||||
source.byteReceived(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void flashWrite(IOPort source, int data) {
|
||||
flash.portWrite(source, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupNodePorts() {
|
||||
super.setupNodePorts();
|
||||
accelerometer = new MMA7260QT(cpu);
|
||||
IOUnit io = cpu.getIOUnit("ADC12");
|
||||
if (io instanceof ADC12) {
|
||||
ADC12 adc = (ADC12) io;
|
||||
adc.setADCInput(4, new ADCInput() {
|
||||
public int nextData() {
|
||||
return accelerometer.getADCX();
|
||||
}
|
||||
});
|
||||
adc.setADCInput(5, new ADCInput() {
|
||||
public int nextData() {
|
||||
return accelerometer.getADCY();
|
||||
}
|
||||
});
|
||||
adc.setADCInput(6, new ADCInput() {
|
||||
public int nextData() {
|
||||
return accelerometer.getADCZ();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (flashFile != null) {
|
||||
setFlash(new FileM25P80(cpu, flashFile));
|
||||
}
|
||||
}
|
||||
|
||||
public void setupGUI() {
|
||||
if (gui == null) {
|
||||
gui = new JCreateGui(this);
|
||||
registry.registerComponent("nodegui", gui);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portWrite(IOPort source, int data) {
|
||||
super.portWrite(source, data);
|
||||
|
||||
if (source == port5) {
|
||||
if (leds != ~(data & 0xff)) {
|
||||
leds = ~(data & 0xff);
|
||||
|
||||
int newMode = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((data & (1 << i)) != 0) {
|
||||
newMode++;
|
||||
}
|
||||
}
|
||||
setMode(newMode);
|
||||
|
||||
if (gui != null) {
|
||||
gui.updateLeds();
|
||||
}
|
||||
}
|
||||
} else if (source == port2) {
|
||||
int out = source.getOut() & source.getDirection();
|
||||
if ((out & 0x08) == 0x08) {
|
||||
accelerometer.setMode(MMA7260QT.MODE_ACTIVE);
|
||||
} else {
|
||||
accelerometer.setMode(MMA7260QT.MODE_SLEEP);
|
||||
}
|
||||
accelerometer.setSensitivity(out & 0x03);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModeMax() {
|
||||
return MODE_MAX;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
JCreateNode node = new JCreateNode();
|
||||
ArgumentManager config = new ArgumentManager();
|
||||
config.handleArguments(args);
|
||||
node.setupArgs(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* Copyright (c) 2010, 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 MSPSim.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* SentillaUSBGui
|
||||
*
|
||||
* Author : Joakim Eriksson, Niclas Finne
|
||||
* Created : 7 jul 2010
|
||||
* Updated : $Date$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
package se.sics.mspsim.platform.sentillausb;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
|
||||
import se.sics.mspsim.platform.AbstractNodeGUI;
|
||||
|
||||
public class SentillaUSBGui extends AbstractNodeGUI {
|
||||
|
||||
private static final long serialVersionUID = -692114865639672141L;
|
||||
|
||||
private static final Color[] RED = new Color[] {
|
||||
new Color(0xff, 0x40, 0x40, 0xa0),
|
||||
new Color(0xff,0x40,0x40,0xff),
|
||||
new Color(0xff,0x60,0x60,0xff),
|
||||
new Color(0xff,0xa0,0xa0,0xff)
|
||||
};
|
||||
private static final Color[] GREEN = new Color[] {
|
||||
new Color(0x40, 0xff, 0x40, 0xa0),
|
||||
new Color(0x40,0xff,0x40,0xff),
|
||||
new Color(0x60,0xff,0x60,0xff),
|
||||
new Color(0xa0,0xff,0xa0,0xff)
|
||||
};
|
||||
|
||||
private static final int LEDS_GREEN_X = 8;
|
||||
private static final int LEDS_RED_X = 126;
|
||||
private static final int LEDS_Y = 89;
|
||||
|
||||
private static final Rectangle LEDS_CLIP =
|
||||
new Rectangle(LEDS_GREEN_X, LEDS_Y, LEDS_RED_X + 10 - LEDS_GREEN_X, 13);
|
||||
|
||||
private final SentillaUSBNode node;
|
||||
|
||||
public SentillaUSBGui(SentillaUSBNode node) {
|
||||
super("SentillaUSBGui", "images/sentilla-usb.jpg");
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startGUI() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopGUI() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
Color old = g.getColor();
|
||||
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
if (node.greenLed) {
|
||||
paintLed(g, LEDS_GREEN_X, GREEN);
|
||||
}
|
||||
if (node.redLed) {
|
||||
paintLed(g, LEDS_RED_X, RED);
|
||||
}
|
||||
g.setColor(old);
|
||||
}
|
||||
|
||||
protected void paintLed(Graphics g, int x, Color[] colors) {
|
||||
g.setColor(colors[0]);
|
||||
g.fillOval(x, LEDS_Y, 10, 13);
|
||||
g.setColor(colors[1]);
|
||||
g.fillOval(x + 2, LEDS_Y + 2, 6, 7);
|
||||
g.setColor(colors[2]);
|
||||
g.fillOval(x + 3, LEDS_Y + 3, 4, 5);
|
||||
g.setColor(colors[3]);
|
||||
g.fillRect(x + 3, LEDS_Y + 3, 2, 2);
|
||||
}
|
||||
|
||||
void updateLeds() {
|
||||
repaint(LEDS_CLIP);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
/**
|
||||
* Copyright (c) 2010, 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 MSPSim.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* JCreateNode
|
||||
*
|
||||
* Author : Joakim Eriksson, Niclas Finne
|
||||
* Created : 7 jul 2010
|
||||
* Updated : $Date$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
package se.sics.mspsim.platform.sentillausb;
|
||||
import java.io.IOException;
|
||||
|
||||
import se.sics.mspsim.chip.FileM25P80;
|
||||
import se.sics.mspsim.chip.M25P80;
|
||||
import se.sics.mspsim.core.IOPort;
|
||||
import se.sics.mspsim.core.USART;
|
||||
import se.sics.mspsim.platform.sky.CC2420Node;
|
||||
import se.sics.mspsim.util.ArgumentManager;
|
||||
|
||||
/**
|
||||
* Emulation of Sentilla Gateway USB Mote
|
||||
*/
|
||||
public class SentillaUSBNode extends CC2420Node {
|
||||
|
||||
public static final int MODE_LEDS_OFF = 0;
|
||||
public static final int MODE_LEDS_1 = 1;
|
||||
public static final int MODE_LEDS_2 = 2;
|
||||
public static final int MODE_MAX = MODE_LEDS_2;
|
||||
|
||||
public static final int GREEN_LED = 0x20;
|
||||
public static final int RED_LED = 0x10;
|
||||
|
||||
private M25P80 flash;
|
||||
private SentillaUSBGui gui;
|
||||
|
||||
boolean redLed;
|
||||
boolean greenLed;
|
||||
|
||||
public SentillaUSBNode() {
|
||||
super("Sentilla USB");
|
||||
setMode(MODE_LEDS_OFF);
|
||||
}
|
||||
|
||||
public M25P80 getFlash() {
|
||||
return flash;
|
||||
}
|
||||
|
||||
public void setFlash(M25P80 flash) {
|
||||
this.flash = flash;
|
||||
registry.registerComponent("xmem", flash);
|
||||
}
|
||||
|
||||
// USART Listener
|
||||
@Override
|
||||
public void dataReceived(USART source, int data) {
|
||||
radio.dataReceived(source, data);
|
||||
flash.dataReceived(source, data);
|
||||
/* if nothing selected, just write back a random byte to this device */
|
||||
if (!radio.getChipSelect() && !flash.getChipSelect()) {
|
||||
source.byteReceived(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void flashWrite(IOPort source, int data) {
|
||||
flash.portWrite(source, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupNodePorts() {
|
||||
super.setupNodePorts();
|
||||
if (flashFile != null) {
|
||||
setFlash(new FileM25P80(cpu, flashFile));
|
||||
}
|
||||
}
|
||||
|
||||
public void setupGUI() {
|
||||
if (gui == null) {
|
||||
gui = new SentillaUSBGui(this);
|
||||
registry.registerComponent("nodegui", gui);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portWrite(IOPort source, int data) {
|
||||
super.portWrite(source, data);
|
||||
|
||||
if (source == port5) {
|
||||
redLed = (data & RED_LED) == 0;
|
||||
greenLed = (data & GREEN_LED) == 0;
|
||||
int newMode = (redLed ? 1 : 0) + (greenLed ? 1 : 0);
|
||||
setMode(newMode);
|
||||
|
||||
if (gui != null) {
|
||||
gui.updateLeds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModeMax() {
|
||||
return MODE_MAX;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
SentillaUSBNode node = new SentillaUSBNode();
|
||||
ArgumentManager config = new ArgumentManager();
|
||||
config.handleArguments(args);
|
||||
node.setupArgs(config);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue