From 95b54f415e8d550a86fb963d0c7bce261f5e1efb Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 01:14:07 +0200 Subject: [PATCH 1/8] [cooja] MemoryLayout: Remove annoying println --- .../cooja/java/org/contikios/cooja/mote/memory/MemoryLayout.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/cooja/java/org/contikios/cooja/mote/memory/MemoryLayout.java b/tools/cooja/java/org/contikios/cooja/mote/memory/MemoryLayout.java index aa3f7a743..132af62d0 100644 --- a/tools/cooja/java/org/contikios/cooja/mote/memory/MemoryLayout.java +++ b/tools/cooja/java/org/contikios/cooja/mote/memory/MemoryLayout.java @@ -166,7 +166,6 @@ public class MemoryLayout { int nextsize = nextType.getSize(); /* limit padding to word size */ nextsize = nextsize > WORD_SIZE ? WORD_SIZE : nextsize; - System.out.println("Nextsize: " + nextsize); /* calc padding */ int pad = nextsize - currType.getSize(); return pad; From 373b00fc47b790bd6fc5985c965af7e31ec8e0ca Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 01:20:27 +0200 Subject: [PATCH 2/8] [cooja] PcapExporter: Use logger Removed unnused imports, replaced println and printStackTrace by logger --- .../contikios/cooja/plugins/analyzers/PcapExporter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java index 64bf5069c..eb9a61690 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java @@ -1,13 +1,13 @@ package org.contikios.cooja.plugins.analyzers; import java.io.DataOutputStream; -import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.File; +import org.apache.log4j.Logger; public class PcapExporter { + private static final Logger logger = Logger.getLogger(PcapExporter.class); DataOutputStream out; @@ -33,7 +33,7 @@ public class PcapExporter { out.writeInt(195); /* 195 for LINKTYPE_IEEE802_15_4 */ out.flush(); - System.out.println("Opened pcap file " + pcapFile); + logger.info("Opened pcap file " + pcapFile); } public void closePcap() throws IOException { @@ -56,7 +56,7 @@ public class PcapExporter { out.write(data); out.flush(); } catch (Exception e) { - e.printStackTrace(); + logger.error(e); } } From c5e034fa1a2740e1d03cf75df4d2d5f713dcf66d Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 01:37:24 +0200 Subject: [PATCH 3/8] [cooja] IEEE802154Analyzer: Use logger Replaced println and printStackTrace by logger --- .../cooja/plugins/analyzers/IEEE802154Analyzer.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java index 74408b363..29e29262b 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java @@ -2,11 +2,14 @@ package org.contikios.cooja.plugins.analyzers; import java.io.IOException; import java.io.File; +import org.apache.log4j.Logger; import org.contikios.cooja.util.StringUtils; public class IEEE802154Analyzer extends PacketAnalyzer { + private static final Logger logger = Logger.getLogger(IEEE802154Analyzer.class); + // Addressing modes public static final int NO_ADDRESS = 0; public static final int RSV_ADDRESS = 1; @@ -33,7 +36,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer { try { pcapExporter = new PcapExporter(); } catch (IOException e) { - e.printStackTrace(); + logger.error(e); } } } @@ -43,8 +46,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer { try { pcapExporter.openPcap(pcapFile); } catch (IOException e) { - System.err.println("Could not open pcap file"); - e.printStackTrace(); + logger.error("Could not open pcap file", e); } } } @@ -69,8 +71,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer { try { pcapExporter.exportPacketData(packet.getPayload()); } catch (IOException e) { - System.err.println("Could not export PCap data"); - e.printStackTrace(); + logger.error("Could not export PCap data", e); } } From c7abba860f2bf543c74cdf6854383e8ec8a3e218 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 01:40:07 +0200 Subject: [PATCH 4/8] [cooja] Radio802154: Added @Override annotations Also removed some unused imports --- .../cooja/emulatedmote/Radio802154.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java b/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java index 4e50daada..f3c8f38ea 100644 --- a/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java +++ b/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java @@ -29,12 +29,7 @@ */ package org.contikios.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; @@ -132,26 +127,32 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { } /* Packet radio support */ + @Override public RadioPacket getLastPacketTransmitted() { return lastOutgoingPacket; } + @Override public RadioPacket getLastPacketReceived() { return lastIncomingPacket; } + @Override public void setReceivedPacket(RadioPacket packet) { } /* Custom data radio support */ + @Override public Object getLastCustomDataTransmitted() { return lastOutgoingByte; } + @Override public Object getLastCustomDataReceived() { return lastIncomingByte; } + @Override public void receiveCustomData(Object data) { if (data instanceof RadioByte) { lastIncomingByte = (RadioByte) data; @@ -160,14 +161,17 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { } /* General radio support */ + @Override public boolean isTransmitting() { return isTransmitting; } + @Override public boolean isReceiving() { return isReceiving; } + @Override public boolean isInterfered() { return isInterfered; } @@ -176,23 +180,31 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { protected abstract void handleEndOfReception(); + @Override public abstract int getChannel(); public abstract int getFrequency(); + @Override public abstract boolean isRadioOn(); + @Override public abstract double getCurrentOutputPower(); + @Override public abstract int getCurrentOutputPowerIndicator(); + @Override public abstract int getOutputPowerIndicatorMax(); + @Override public abstract double getCurrentSignalStrength(); + @Override public abstract void setCurrentSignalStrength(double signalStrength); /* need to add a few more methods later??? */ + @Override public void signalReceptionStart() { isReceiving = true; @@ -207,6 +219,7 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { notifyObservers(); } + @Override public void signalReceptionEnd() { /* Deliver packet data */ isReceiving = false; @@ -226,10 +239,12 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { notifyObservers(); } + @Override public RadioEvent getLastEvent() { return lastEvent; } + @Override public void interfereAnyReception() { isInterfered = true; isReceiving = false; @@ -249,18 +264,22 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { notifyObservers(); } + @Override public Mote getMote() { return mote; } + @Override public Position getPosition() { return mote.getInterfaces().getPosition(); } + @Override public Collection getConfigXML() { return null; } + @Override public void setConfigXML(Collection configXML, boolean visAvailable) { } } From 40f54a8e26ee7f77448b452e04041c7c7cc85dc8 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 01:53:26 +0200 Subject: [PATCH 5/8] [cooja] Radio802154: Removed obsolete comments including println hints --- .../org/contikios/cooja/emulatedmote/Radio802154.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java b/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java index f3c8f38ea..6af42871f 100644 --- a/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java +++ b/tools/cooja/java/org/contikios/cooja/emulatedmote/Radio802154.java @@ -48,7 +48,7 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { private final static boolean DEBUG = false; - private static Logger logger = Logger.getLogger(Radio802154.class); + private static final Logger logger = Logger.getLogger(Radio802154.class); protected long lastEventTime = 0; @@ -98,10 +98,9 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { buffer[len++] = val; - //System.out.println("## 802.15.4: " + (val&0xff) + " transmitted..."); + logger.debug("802.15.4: " + (val & 0xff) + " transmitted..."); if (len == 6) { - //System.out.println("## CC2420 Packet of length: " + val + " expected..."); expLen = val + 6; } @@ -115,10 +114,8 @@ public abstract class Radio802154 extends Radio implements CustomDataRadio { setChanged(); notifyObservers(); - // System.out.println("## CC2420 Transmission finished..."); - lastEventTime = mote.getSimulation().getSimulationTime(); - /*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/ + logger.debug("----- 802.15.4 TRANSMISSION FINISHED -----"); lastEvent = RadioEvent.TRANSMISSION_FINISHED; setChanged(); notifyObservers(); From 927d9a31536fdd2f96faa4128bf4fc3b7e3ab5aa Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 02:05:14 +0200 Subject: [PATCH 6/8] [cooja] dialogs/MessageList: Added @Override annotations --- .../java/org/contikios/cooja/dialogs/MessageList.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java b/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java index cb4dd926a..212a65e34 100644 --- a/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java +++ b/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java @@ -130,6 +130,7 @@ public class MessageList extends JList { final BufferedReader stringInput = new BufferedReader(new InputStreamReader(input)); Thread readThread = new Thread(new Runnable() { + @Override public void run() { String readLine; try { @@ -184,6 +185,7 @@ public class MessageList extends JList { messages.add(msg); java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { updateModel(); } @@ -195,6 +197,7 @@ public class MessageList extends JList { ((DefaultListModel) getModel()).clear(); } + @Override public void setModel(ListModel model) { throw new IllegalArgumentException("changing model not permitted"); } @@ -203,16 +206,19 @@ public class MessageList extends JList { if (popup == null) { popup = new JPopupMenu(); addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(MessageList.this, e.getX(), e.getY()); } } + @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(MessageList.this, e.getX(), e.getY()); } } + @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(MessageList.this, e.getX(), e.getY()); @@ -230,6 +236,7 @@ public class MessageList extends JList { final JMenuItem hideNormalMenuItem = new JCheckBoxMenuItem("Hide normal output"); hideNormalMenuItem.setEnabled(true); hideNormalMenuItem.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { MessageList.this.hideNormal = hideNormalMenuItem.isSelected(); ((MessageModel)getModel()).updateList(); @@ -240,6 +247,7 @@ public class MessageList extends JList { JMenuItem consoleOutputMenuItem = new JMenuItem("Output to console"); consoleOutputMenuItem.setEnabled(true); consoleOutputMenuItem.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { MessageContainer[] messages = getMessages(); System.out.println("\nCOMPILATION OUTPUT:\n"); @@ -257,6 +265,7 @@ public class MessageList extends JList { JMenuItem clipboardMenuItem = new JMenuItem("Copy to clipboard"); clipboardMenuItem.setEnabled(true); clipboardMenuItem.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -299,6 +308,7 @@ public class MessageList extends JList { this.type = type; } + @Override public String toString() { return message; } @@ -318,6 +328,7 @@ public class MessageList extends JList { private class MessageRenderer extends DefaultListCellRenderer { private Dimension nullDimension = new Dimension(0,0); + @Override public Component getListCellRendererComponent( JList list, Object value, From f02266d67c5d606ca35700944e3f90c1cf398968 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 02:05:39 +0200 Subject: [PATCH 7/8] [cooja] dialogs/MessageListe: User Logger instead of println --- .../contikios/cooja/dialogs/MessageList.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java b/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java index 212a65e34..1921a68ce 100644 --- a/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java +++ b/tools/cooja/java/org/contikios/cooja/dialogs/MessageList.java @@ -26,13 +26,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * - * ----------------------------------------------------------------- - * - * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Fredrik Osterlind - * Created : 2006-06-14 - * Updated : $Date: 2009/11/13 14:27:46 $ - * $Revision: 1.15 $ */ package org.contikios.cooja.dialogs; @@ -64,11 +57,21 @@ import javax.swing.JPopupMenu; import javax.swing.JSeparator; import javax.swing.ListModel; import javax.swing.ListSelectionModel; +import org.apache.log4j.Logger; import org.contikios.cooja.Cooja; +/** + * + * @author Adam Dunkels + * @author Joakim Eriksson + * @author Niclas Finne + * @author Fredrik Osterlind + */ public class MessageList extends JList { + private static final Logger logger = Logger.getLogger(MessageList.class); + public static final int NORMAL = 0; public static final int WARNING = 1; public static final int ERROR = 2; @@ -146,8 +149,8 @@ public class MessageList extends JList { readThread.start(); return new PrintStream(output); - } catch (Exception e) { - System.out.println("Exception: "+ e); + } catch (IOException e) { + logger.error(messages); return null; } } @@ -250,14 +253,14 @@ public class MessageList extends JList { @Override public void actionPerformed(ActionEvent e) { MessageContainer[] messages = getMessages(); - System.out.println("\nCOMPILATION OUTPUT:\n"); + logger.info("\nCOMPILATION OUTPUT:\n"); for (MessageContainer msg: messages) { if (hideNormal && msg.type == NORMAL) { continue; } - System.out.println(msg); + logger.info(msg); } - System.out.println(); + logger.info("\n"); } }); popup.add(consoleOutputMenuItem); From 903d0333d3ab7ba3052b0f36c9ca013673ddeeeb Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 2 Oct 2014 02:11:41 +0200 Subject: [PATCH 8/8] [cooja] Removed some further printlns --- tools/cooja/java/org/contikios/cooja/Cooja.java | 2 +- tools/cooja/java/org/contikios/cooja/dialogs/SerialUI.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/Cooja.java b/tools/cooja/java/org/contikios/cooja/Cooja.java index 055cb46f4..d053fd45e 100644 --- a/tools/cooja/java/org/contikios/cooja/Cooja.java +++ b/tools/cooja/java/org/contikios/cooja/Cooja.java @@ -3152,7 +3152,7 @@ public class Cooja extends Observable { if (new File(logConfigFile).exists()) { DOMConfigurator.configure(logConfigFile); } else { - System.err.println("Failed to open " + logConfigFile); + logger.error("Failed to open " + logConfigFile); System.exit(1); } } else if (new File(LOG_CONFIG_FILE).exists()) { diff --git a/tools/cooja/java/org/contikios/cooja/dialogs/SerialUI.java b/tools/cooja/java/org/contikios/cooja/dialogs/SerialUI.java index bcc1a0734..430939482 100644 --- a/tools/cooja/java/org/contikios/cooja/dialogs/SerialUI.java +++ b/tools/cooja/java/org/contikios/cooja/dialogs/SerialUI.java @@ -165,8 +165,7 @@ public abstract class SerialUI extends Log implements SerialPort { writeString(command); } } catch (Exception ex) { - System.err.println("could not send '" + command + "':"); - ex.printStackTrace(); + logger.error("could not send '" + command + "':", ex); JOptionPane.showMessageDialog( logTextPane, "Could not send '" + command + "':\n" + ex.getMessage(), "Error sending message",