diff --git a/tools/cooja/java/se/sics/cooja/dialogs/SerialUI.java b/tools/cooja/java/se/sics/cooja/dialogs/SerialUI.java index b9561b6dc..1465e278d 100644 --- a/tools/cooja/java/se/sics/cooja/dialogs/SerialUI.java +++ b/tools/cooja/java/se/sics/cooja/dialogs/SerialUI.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SerialUI.java,v 1.2 2009/06/02 09:34:12 fros4943 Exp $ + * $Id: SerialUI.java,v 1.3 2010/02/05 09:07:58 fros4943 Exp $ */ package se.sics.cooja.dialogs; @@ -263,10 +263,6 @@ public abstract class SerialUI extends Log implements SerialPort { this.deleteObserver(observer); } - public double energyConsumption() { - return 0; - } - public Collection getConfigXML() { return null; } diff --git a/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java b/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java index 10ff93010..678169ff9 100644 --- a/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java +++ b/tools/cooja/java/se/sics/cooja/emulatedmote/Radio802154.java @@ -1,347 +1,345 @@ -/* - * Copyright (c) 2009, 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: Radio802154.java,v 1.1 2009/11/10 12:54:39 joxe Exp $ - */ -package se.sics.cooja.emulatedmote; - -import java.awt.BorderLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.*; -import javax.swing.*; -import org.apache.log4j.Logger; -import org.jdom.Element; - -import se.sics.cooja.*; -import se.sics.cooja.interfaces.CustomDataRadio; -import se.sics.cooja.interfaces.Position; -import se.sics.cooja.interfaces.Radio; - -/** - * 802.15.4 radio class for COOJA. - * - * @author Joakim Eriksson - */ - -public abstract class Radio802154 extends Radio implements CustomDataRadio { - - private final static boolean DEBUG = false; - - private static Logger logger = Logger.getLogger(Radio802154.class); - - protected long lastEventTime = 0; - - protected RadioEvent lastEvent = RadioEvent.UNKNOWN; - - protected boolean isInterfered = false; - - private boolean isTransmitting = false; - - protected boolean isReceiving = false; - // private boolean hasFailedReception = false; - - private boolean radioOn = true; - - private RadioByte lastOutgoingByte = null; - - private RadioByte lastIncomingByte = null; - - private RadioPacket lastOutgoingPacket = null; - - private RadioPacket lastIncomingPacket = null; - - // private int mode; - protected Mote mote; - - public Radio802154(Mote mote) { - this.mote = mote; - } - - int len = 0; - int expLen = 0; - byte[] buffer = new byte[127 + 15]; - protected void handleTransmit(byte val) { - if (len == 0) { - lastEventTime = mote.getSimulation().getSimulationTime(); - lastEvent = RadioEvent.TRANSMISSION_STARTED; - if (DEBUG) logger.debug("----- 802.15.4 TRANSMISSION STARTED -----"); - setChanged(); - notifyObservers(); - } - /* send this byte to all nodes */ - lastOutgoingByte = new RadioByte(val); - lastEventTime = mote.getSimulation().getSimulationTime(); - lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED; - setChanged(); - notifyObservers(); - - buffer[len++] = val; - - //System.out.println("## 802.15.4: " + (val&0xff) + " transmitted..."); - - if (len == 6) { - //System.out.println("## CC2420 Packet of length: " + val + " expected..."); - expLen = val + 6; - } - - if (len == expLen) { - if (DEBUG) logger.debug("----- 802.15.4 CUSTOM DATA TRANSMITTED -----"); - - lastOutgoingPacket = Radio802154PacketConverter.fromCC2420ToCooja(buffer); - lastEventTime = mote.getSimulation().getSimulationTime(); - lastEvent = RadioEvent.PACKET_TRANSMITTED; - if (DEBUG) logger.debug("----- 802.15.4 PACKET TRANSMITTED -----"); - setChanged(); - notifyObservers(); - - // System.out.println("## CC2420 Transmission finished..."); - - lastEventTime = mote.getSimulation().getSimulationTime(); - /*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/ - lastEvent = RadioEvent.TRANSMISSION_FINISHED; - setChanged(); - notifyObservers(); - len = 0; - } - } - - /* Packet radio support */ - public RadioPacket getLastPacketTransmitted() { - return lastOutgoingPacket; - } - - public RadioPacket getLastPacketReceived() { - return lastIncomingPacket; - } - - public void setReceivedPacket(RadioPacket packet) { - } - - /* Custom data radio support */ - public Object getLastCustomDataTransmitted() { - return lastOutgoingByte; - } - - public Object getLastCustomDataReceived() { - return lastIncomingByte; - } - - public void receiveCustomData(Object data) { - if (data instanceof RadioByte) { - lastIncomingByte = (RadioByte) data; - handleReceive(lastIncomingByte.getPacketData()[0]); - } - } - - /* General radio support */ - public boolean isTransmitting() { - return isTransmitting; - } - - public boolean isReceiving() { - return isReceiving; - } - - public boolean isInterfered() { - return isInterfered; - } - - protected abstract void handleReceive(byte b); - - protected abstract void handleEndOfReception(); - - public abstract int getChannel(); - - public abstract int getFrequency(); - - public abstract boolean isReceiverOn(); - - public abstract double getCurrentOutputPower(); - - public abstract int getCurrentOutputPowerIndicator(); - - public abstract int getOutputPowerIndicatorMax(); - - public abstract double getCurrentSignalStrength(); - - public abstract void setCurrentSignalStrength(double signalStrength); - - public abstract double energyConsumption(); - - /* need to add a few more methods later??? */ - public void signalReceptionStart() { - isReceiving = true; - - // cc2420.setCCA(true); - // hasFailedReception = mode == CC2420.MODE_TXRX_OFF; - /* TODO cc2420.setSFD(true); */ - - lastEventTime = mote.getSimulation().getSimulationTime(); - lastEvent = RadioEvent.RECEPTION_STARTED; - if (DEBUG) logger.debug("----- 802.15.4 RECEPTION STARTED -----"); - setChanged(); - notifyObservers(); - } - - public void signalReceptionEnd() { - /* Deliver packet data */ - isReceiving = false; - // hasFailedReception = false; - isInterfered = false; - // cc2420.setCCA(false); - - /* tell the receiver that the packet is ended */ - handleEndOfReception(); - - lastEventTime = mote.getSimulation().getSimulationTime(); - lastEvent = RadioEvent.RECEPTION_FINISHED; - if (DEBUG) logger.debug("----- 802.15.4 RECEPTION FINISHED -----"); - // Exception e = new IllegalStateException("Why finished?"); - // e.printStackTrace(); - setChanged(); - notifyObservers(); - } - - public RadioEvent getLastEvent() { - return lastEvent; - } - - public void interfereAnyReception() { - isInterfered = true; - isReceiving = false; - // hasFailedReception = false; - lastIncomingPacket = null; - - //cc2420.setCCA(true); - - /* is this ok ?? */ - handleEndOfReception(); - //recv.nextByte(false, (byte)0); - - lastEventTime = mote.getSimulation().getSimulationTime(); - lastEvent = RadioEvent.RECEPTION_INTERFERED; - /*logger.debug("----- SKY RECEPTION INTERFERED -----");*/ - setChanged(); - notifyObservers(); - } - - public JPanel getInterfaceVisualizer() { - // Location - JPanel wrapperPanel = new JPanel(new BorderLayout()); - JPanel panel = new JPanel(new GridLayout(5, 2)); - - final JLabel statusLabel = new JLabel(""); - final JLabel lastEventLabel = new JLabel(""); - final JLabel channelLabel = new JLabel(""); - final JLabel powerLabel = new JLabel(""); - final JLabel ssLabel = new JLabel(""); - final JButton updateButton = new JButton("Update"); - - panel.add(new JLabel("STATE:")); - panel.add(statusLabel); - - panel.add(new JLabel("LAST EVENT:")); - panel.add(lastEventLabel); - - panel.add(new JLabel("CHANNEL:")); - panel.add(channelLabel); - - panel.add(new JLabel("OUTPUT POWER:")); - panel.add(powerLabel); - - panel.add(new JLabel("SIGNAL STRENGTH:")); - JPanel smallPanel = new JPanel(new GridLayout(1, 2)); - smallPanel.add(ssLabel); - smallPanel.add(updateButton); - panel.add(smallPanel); - - updateButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - channelLabel.setText(getChannel() + " (freq=" + getFrequency() + " MHz)"); - powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")"); - ssLabel.setText(getCurrentSignalStrength() + " dBm"); - } - }); - - Observer observer; - this.addObserver(observer = new Observer() { - public void update(Observable obs, Object obj) { - if (isTransmitting()) { - statusLabel.setText("transmitting"); - } else if (isReceiving()) { - statusLabel.setText("receiving"); - } else if (radioOn /* mode != CC2420.MODE_TXRX_OFF */) { - statusLabel.setText("listening for traffic"); - } else { - statusLabel.setText("HW off"); - } - - lastEventLabel.setText(lastEvent + " @ time=" + lastEventTime); - - channelLabel.setText(getChannel() + " (freq=" + getFrequency() + " MHz)"); - powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")"); - ssLabel.setText(getCurrentSignalStrength() + " dBm"); - } - }); - - observer.update(null, null); - - wrapperPanel.add(BorderLayout.NORTH, panel); - - // Saving observer reference for releaseInterfaceVisualizer - wrapperPanel.putClientProperty("intf_obs", observer); - return wrapperPanel; - } - - 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 Mote getMote() { - return mote; - } - - public Position getPosition() { - return mote.getInterfaces().getPosition(); - } - - public Collection getConfigXML() { - return null; - } - - public void setConfigXML(Collection configXML, boolean visAvailable) { - } -} +/* + * Copyright (c) 2009, 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: Radio802154.java,v 1.2 2010/02/05 09:07:58 fros4943 Exp $ + */ +package se.sics.cooja.emulatedmote; + +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.*; +import javax.swing.*; +import org.apache.log4j.Logger; +import org.jdom.Element; + +import se.sics.cooja.*; +import se.sics.cooja.interfaces.CustomDataRadio; +import se.sics.cooja.interfaces.Position; +import se.sics.cooja.interfaces.Radio; + +/** + * 802.15.4 radio class for COOJA. + * + * @author Joakim Eriksson + */ + +public abstract class Radio802154 extends Radio implements CustomDataRadio { + + private final static boolean DEBUG = false; + + private static Logger logger = Logger.getLogger(Radio802154.class); + + protected long lastEventTime = 0; + + protected RadioEvent lastEvent = RadioEvent.UNKNOWN; + + protected boolean isInterfered = false; + + private boolean isTransmitting = false; + + protected boolean isReceiving = false; + // private boolean hasFailedReception = false; + + private boolean radioOn = true; + + private RadioByte lastOutgoingByte = null; + + private RadioByte lastIncomingByte = null; + + private RadioPacket lastOutgoingPacket = null; + + private RadioPacket lastIncomingPacket = null; + + // private int mode; + protected Mote mote; + + public Radio802154(Mote mote) { + this.mote = mote; + } + + int len = 0; + int expLen = 0; + byte[] buffer = new byte[127 + 15]; + protected void handleTransmit(byte val) { + if (len == 0) { + lastEventTime = mote.getSimulation().getSimulationTime(); + lastEvent = RadioEvent.TRANSMISSION_STARTED; + if (DEBUG) logger.debug("----- 802.15.4 TRANSMISSION STARTED -----"); + setChanged(); + notifyObservers(); + } + /* send this byte to all nodes */ + lastOutgoingByte = new RadioByte(val); + lastEventTime = mote.getSimulation().getSimulationTime(); + lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED; + setChanged(); + notifyObservers(); + + buffer[len++] = val; + + //System.out.println("## 802.15.4: " + (val&0xff) + " transmitted..."); + + if (len == 6) { + //System.out.println("## CC2420 Packet of length: " + val + " expected..."); + expLen = val + 6; + } + + if (len == expLen) { + if (DEBUG) logger.debug("----- 802.15.4 CUSTOM DATA TRANSMITTED -----"); + + lastOutgoingPacket = Radio802154PacketConverter.fromCC2420ToCooja(buffer); + lastEventTime = mote.getSimulation().getSimulationTime(); + lastEvent = RadioEvent.PACKET_TRANSMITTED; + if (DEBUG) logger.debug("----- 802.15.4 PACKET TRANSMITTED -----"); + setChanged(); + notifyObservers(); + + // System.out.println("## CC2420 Transmission finished..."); + + lastEventTime = mote.getSimulation().getSimulationTime(); + /*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/ + lastEvent = RadioEvent.TRANSMISSION_FINISHED; + setChanged(); + notifyObservers(); + len = 0; + } + } + + /* Packet radio support */ + public RadioPacket getLastPacketTransmitted() { + return lastOutgoingPacket; + } + + public RadioPacket getLastPacketReceived() { + return lastIncomingPacket; + } + + public void setReceivedPacket(RadioPacket packet) { + } + + /* Custom data radio support */ + public Object getLastCustomDataTransmitted() { + return lastOutgoingByte; + } + + public Object getLastCustomDataReceived() { + return lastIncomingByte; + } + + public void receiveCustomData(Object data) { + if (data instanceof RadioByte) { + lastIncomingByte = (RadioByte) data; + handleReceive(lastIncomingByte.getPacketData()[0]); + } + } + + /* General radio support */ + public boolean isTransmitting() { + return isTransmitting; + } + + public boolean isReceiving() { + return isReceiving; + } + + public boolean isInterfered() { + return isInterfered; + } + + protected abstract void handleReceive(byte b); + + protected abstract void handleEndOfReception(); + + public abstract int getChannel(); + + public abstract int getFrequency(); + + public abstract boolean isReceiverOn(); + + public abstract double getCurrentOutputPower(); + + public abstract int getCurrentOutputPowerIndicator(); + + public abstract int getOutputPowerIndicatorMax(); + + public abstract double getCurrentSignalStrength(); + + public abstract void setCurrentSignalStrength(double signalStrength); + + /* need to add a few more methods later??? */ + public void signalReceptionStart() { + isReceiving = true; + + // cc2420.setCCA(true); + // hasFailedReception = mode == CC2420.MODE_TXRX_OFF; + /* TODO cc2420.setSFD(true); */ + + lastEventTime = mote.getSimulation().getSimulationTime(); + lastEvent = RadioEvent.RECEPTION_STARTED; + if (DEBUG) logger.debug("----- 802.15.4 RECEPTION STARTED -----"); + setChanged(); + notifyObservers(); + } + + public void signalReceptionEnd() { + /* Deliver packet data */ + isReceiving = false; + // hasFailedReception = false; + isInterfered = false; + // cc2420.setCCA(false); + + /* tell the receiver that the packet is ended */ + handleEndOfReception(); + + lastEventTime = mote.getSimulation().getSimulationTime(); + lastEvent = RadioEvent.RECEPTION_FINISHED; + if (DEBUG) logger.debug("----- 802.15.4 RECEPTION FINISHED -----"); + // Exception e = new IllegalStateException("Why finished?"); + // e.printStackTrace(); + setChanged(); + notifyObservers(); + } + + public RadioEvent getLastEvent() { + return lastEvent; + } + + public void interfereAnyReception() { + isInterfered = true; + isReceiving = false; + // hasFailedReception = false; + lastIncomingPacket = null; + + //cc2420.setCCA(true); + + /* is this ok ?? */ + handleEndOfReception(); + //recv.nextByte(false, (byte)0); + + lastEventTime = mote.getSimulation().getSimulationTime(); + lastEvent = RadioEvent.RECEPTION_INTERFERED; + /*logger.debug("----- SKY RECEPTION INTERFERED -----");*/ + setChanged(); + notifyObservers(); + } + + public JPanel getInterfaceVisualizer() { + // Location + JPanel wrapperPanel = new JPanel(new BorderLayout()); + JPanel panel = new JPanel(new GridLayout(5, 2)); + + final JLabel statusLabel = new JLabel(""); + final JLabel lastEventLabel = new JLabel(""); + final JLabel channelLabel = new JLabel(""); + final JLabel powerLabel = new JLabel(""); + final JLabel ssLabel = new JLabel(""); + final JButton updateButton = new JButton("Update"); + + panel.add(new JLabel("STATE:")); + panel.add(statusLabel); + + panel.add(new JLabel("LAST EVENT:")); + panel.add(lastEventLabel); + + panel.add(new JLabel("CHANNEL:")); + panel.add(channelLabel); + + panel.add(new JLabel("OUTPUT POWER:")); + panel.add(powerLabel); + + panel.add(new JLabel("SIGNAL STRENGTH:")); + JPanel smallPanel = new JPanel(new GridLayout(1, 2)); + smallPanel.add(ssLabel); + smallPanel.add(updateButton); + panel.add(smallPanel); + + updateButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + channelLabel.setText(getChannel() + " (freq=" + getFrequency() + " MHz)"); + powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")"); + ssLabel.setText(getCurrentSignalStrength() + " dBm"); + } + }); + + Observer observer; + this.addObserver(observer = new Observer() { + public void update(Observable obs, Object obj) { + if (isTransmitting()) { + statusLabel.setText("transmitting"); + } else if (isReceiving()) { + statusLabel.setText("receiving"); + } else if (radioOn /* mode != CC2420.MODE_TXRX_OFF */) { + statusLabel.setText("listening for traffic"); + } else { + statusLabel.setText("HW off"); + } + + lastEventLabel.setText(lastEvent + " @ time=" + lastEventTime); + + channelLabel.setText(getChannel() + " (freq=" + getFrequency() + " MHz)"); + powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")"); + ssLabel.setText(getCurrentSignalStrength() + " dBm"); + } + }); + + observer.update(null, null); + + wrapperPanel.add(BorderLayout.NORTH, panel); + + // Saving observer reference for releaseInterfaceVisualizer + wrapperPanel.putClientProperty("intf_obs", observer); + return wrapperPanel; + } + + 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 Mote getMote() { + return mote; + } + + public Position getPosition() { + return mote.getInterfaces().getPosition(); + } + + public Collection getConfigXML() { + return null; + } + + public void setConfigXML(Collection configXML, boolean visAvailable) { + } +} diff --git a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationLED.java b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationLED.java index 4ecbc7eff..886999328 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationLED.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationLED.java @@ -1,152 +1,148 @@ -package se.sics.cooja.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.*; -import se.sics.cooja.contikimote.interfaces.ContikiLED; - -public class ApplicationLED extends LED { - private static Logger logger = Logger.getLogger(ContikiLED.class); - - private Mote mote = null; - private byte currentLedValue = 0; - - public static final byte LEDS_GREEN = 1; - public static final byte LEDS_YELLOW = 2; - public static final byte LEDS_RED = 4; - - private static final Color DARK_GREEN = new Color(0, 50, 0); - private static final Color DARK_YELLOW = new Color(50, 50, 0); - private static final Color DARK_RED = new Color(50, 0, 0); - private static final Color GREEN = new Color(0, 255, 0); - private static final Color YELLOW = new Color(255, 255, 0); - private static final Color RED = new Color(255, 0, 0); - - public ApplicationLED(Mote mote) { - this.mote = mote; - } - - public static String[] getCoreInterfaceDependencies() { - return new String[]{"leds_interface"}; - } - - public boolean isAnyOn() { - return currentLedValue > 0; - } - - public boolean isGreenOn() { - return (currentLedValue & LEDS_GREEN) > 0; - } - - public boolean isYellowOn() { - return (currentLedValue & LEDS_YELLOW) > 0; - } - - public boolean isRedOn() { - return (currentLedValue & LEDS_RED) > 0; - } - - public void setLED(int led) { - boolean ledChanged; - ledChanged = led != currentLedValue; - - currentLedValue = (byte) led; - if (ledChanged) { - this.setChanged(); - this.notifyObservers(mote); - } - } - - public JPanel getInterfaceVisualizer() { - final JPanel panel = new JPanel() { - 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); - } - - 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 double energyConsumption() { - return 0; - } - - public Collection getConfigXML() { - return null; - } - - @Override - public void setConfigXML(Collection configXML, boolean visAvailable) { - // TODO Auto-generated method stub - } +package se.sics.cooja.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.*; +import se.sics.cooja.contikimote.interfaces.ContikiLED; + +public class ApplicationLED extends LED { + private static Logger logger = Logger.getLogger(ContikiLED.class); + + private Mote mote = null; + private byte currentLedValue = 0; + + public static final byte LEDS_GREEN = 1; + public static final byte LEDS_YELLOW = 2; + public static final byte LEDS_RED = 4; + + private static final Color DARK_GREEN = new Color(0, 50, 0); + private static final Color DARK_YELLOW = new Color(50, 50, 0); + private static final Color DARK_RED = new Color(50, 0, 0); + private static final Color GREEN = new Color(0, 255, 0); + private static final Color YELLOW = new Color(255, 255, 0); + private static final Color RED = new Color(255, 0, 0); + + public ApplicationLED(Mote mote) { + this.mote = mote; + } + + public static String[] getCoreInterfaceDependencies() { + return new String[]{"leds_interface"}; + } + + public boolean isAnyOn() { + return currentLedValue > 0; + } + + public boolean isGreenOn() { + return (currentLedValue & LEDS_GREEN) > 0; + } + + public boolean isYellowOn() { + return (currentLedValue & LEDS_YELLOW) > 0; + } + + public boolean isRedOn() { + return (currentLedValue & LEDS_RED) > 0; + } + + public void setLED(int led) { + boolean ledChanged; + ledChanged = led != currentLedValue; + + currentLedValue = (byte) led; + if (ledChanged) { + this.setChanged(); + this.notifyObservers(mote); + } + } + + public JPanel getInterfaceVisualizer() { + final JPanel panel = new JPanel() { + 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); + } + + 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 getConfigXML() { + return null; + } + + @Override + public void setConfigXML(Collection configXML, boolean visAvailable) { + // TODO Auto-generated method stub + } } \ No newline at end of file diff --git a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java index b32a97086..490c921f9 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/ApplicationRadio.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ApplicationRadio.java,v 1.11 2010/01/24 23:16:17 joxe Exp $ + * $Id: ApplicationRadio.java,v 1.12 2010/02/05 09:07:58 fros4943 Exp $ */ package se.sics.cooja.interfaces; @@ -335,10 +335,6 @@ private int interfered; this.deleteObserver(observer); } - public double energyConsumption() { - return 0; - } - public Collection getConfigXML() { return null; } diff --git a/tools/cooja/java/se/sics/cooja/interfaces/Mote2MoteRelations.java b/tools/cooja/java/se/sics/cooja/interfaces/Mote2MoteRelations.java index 84cfa2dad..a722bad66 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/Mote2MoteRelations.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/Mote2MoteRelations.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: Mote2MoteRelations.java,v 1.3 2010/01/12 09:36:10 fros4943 Exp $ + * $Id: Mote2MoteRelations.java,v 1.4 2010/02/05 09:07:58 fros4943 Exp $ */ package se.sics.cooja.interfaces; @@ -225,10 +225,6 @@ public class Mote2MoteRelations extends MoteInterface { this.deleteObserver(observer); } - public double energyConsumption() { - return 0; - } - public Collection getConfigXML() { return null; } diff --git a/tools/cooja/java/se/sics/cooja/interfaces/Position.java b/tools/cooja/java/se/sics/cooja/interfaces/Position.java index 585ad256a..992196d1e 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/Position.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/Position.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: Position.java,v 1.5 2009/03/09 14:08:54 fros4943 Exp $ + * $Id: Position.java,v 1.6 2010/02/05 09:07:58 fros4943 Exp $ */ package se.sics.cooja.interfaces; @@ -168,10 +168,6 @@ public class Position extends MoteInterface { this.deleteObserver(observer); } - public double energyConsumption() { - return 0.0; - } - public Collection getConfigXML() { Vector config = new Vector(); Element element; diff --git a/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMoteType.java b/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMoteType.java index 77c993401..35f497d87 100644 --- a/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMoteType.java +++ b/tools/cooja/java/se/sics/cooja/motes/AbstractApplicationMoteType.java @@ -24,7 +24,7 @@ * (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: AbstractApplicationMoteType.java,v 1.8 2010/02/03 15:11:48 fros4943 Exp $ + * $Id: AbstractApplicationMoteType.java,v 1.9 2010/02/05 09:08:07 fros4943 Exp $ */ package se.sics.cooja.motes; @@ -245,9 +245,6 @@ public abstract class AbstractApplicationMoteType implements MoteType { public void setMoteID(int newID) { this.id = newID; } - public double energyConsumption() { - return 0; - } public JPanel getInterfaceVisualizer() { return null; }