[cooja] Added @Override annotations for relevant files

This commit is contained in:
Enrico Joerns 2014-07-18 11:39:02 +02:00
parent 01bd045570
commit c6f8a2d558
7 changed files with 185 additions and 1 deletions

View file

@ -60,28 +60,34 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
interpreter.getSimulator().insertWatch(w, address);
}
@Override
public void clearMemory() {
logger.fatal("not implemented");
}
@Override
public byte[] getMemorySegment(int address, int size) {
logger.fatal("getMemorySegment is not implemented");
return null;
}
@Override
public int getTotalSize() {
return 0;
}
@Override
public void setMemorySegment(int address, byte[] data) {
logger.fatal("setMemorySegment is not implemented");
}
@Override
public byte[] getByteArray(String varName, int length)
throws UnknownVariableException {
return null;
}
@Override
public byte getByteValueOf(String varName) throws UnknownVariableException {
return (byte) getValueOf(varName, 1);
}
@ -131,19 +137,23 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
}
}
@Override
public int getIntValueOf(String varName) throws UnknownVariableException {
return getValueOf(varName, 2);
}
@Override
public int getIntegerLength() {
return 2;
}
@Override
public int getVariableAddress(String varName)
throws UnknownVariableException {
return 0;
}
@Override
public String[] getVariableNames() {
ArrayList<String> symbols = new ArrayList<String>();
for (Iterator i = memoryMap.getIterator(); i.hasNext();) {
@ -152,32 +162,39 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
return symbols.toArray(new String[0]);
}
@Override
public void setByteArray(String varName, byte[] data)
throws UnknownVariableException {
}
@Override
public void setByteValueOf(String varName, byte newVal)
throws UnknownVariableException {
setValue(varName, newVal, 1);
}
@Override
public void setIntValueOf(String varName, int newVal)
throws UnknownVariableException {
setValue(varName, newVal, 2);
}
@Override
public boolean variableExists(String varName) {
return memoryMap.getLocation(varName) != null;
}
@Override
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
logger.warn("Not implemented");
return false;
}
@Override
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
}
@Override
public int parseInt(byte[] memorySegment) {
logger.warn("Not implemented");
return 0;

View file

@ -58,6 +58,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
this.cpu = cpu;
}
@Override
public String[] getVariableNames() {
String[] names = new String[mapEntries.size()];
for (int i = 0; i < mapEntries.size(); i++) {
@ -75,19 +76,23 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
throw new UnknownVariableException(varName);
}
@Override
public int getVariableAddress(String varName) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
return entry.getAddress();
}
@Override
public int getIntegerLength() {
return 2;
}
@Override
public void clearMemory() {
logger.fatal("clearMemory() not implemented");
}
@Override
public byte[] getMemorySegment(int address, int size) {
int[] memInts = new int[size];
@ -102,6 +107,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
return memBytes;
}
@Override
public void setMemorySegment(int address, byte[] data) {
/* Convert to int array */
int[] memInts = new int[data.length];
@ -112,10 +118,12 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
System.arraycopy(memInts, 0, cpu.memory, address, data.length);
}
@Override
public int getTotalSize() {
return cpu.memory.length;
}
@Override
public boolean variableExists(String varName) {
for (MapEntry entry: mapEntries) {
if (entry.getName().equals(varName)) {
@ -128,6 +136,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
/* TODO Check correct variable size in below methods */
@Override
public int getIntValueOf(String varName) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
@ -136,6 +145,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
return parseInt(varData);
}
@Override
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
@ -152,6 +162,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
setMemorySegment(varAddr, varData);
}
@Override
public byte getByteValueOf(String varName) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
@ -161,6 +172,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
return varData[0];
}
@Override
public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
@ -172,6 +184,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
setMemorySegment(varAddr, varData);
}
@Override
public byte[] getByteArray(String varName, int length) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
@ -179,6 +192,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
return getMemorySegment(varAddr, length);
}
@Override
public void setByteArray(String varName, byte[] data) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
@ -209,6 +223,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
}
}
@Override
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
MemoryCPUMonitor t = new MemoryCPUMonitor(mm, address, size);
cpuMonitorArray.add(t);
@ -220,6 +235,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
return true;
}
@Override
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
for (MemoryCPUMonitor mcm: cpuMonitorArray) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
@ -233,6 +249,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
}
}
@Override
public int parseInt(byte[] memorySegment) {
if (memorySegment.length < 2) {
return -1;

View file

@ -66,10 +66,12 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
this.offset = offset;
}
@Override
public String[] getVariableNames() {
return addresses.keySet().toArray(new String[0]);
}
@Override
public int getVariableAddress(String varName) throws UnknownVariableException {
/* Cooja address space */
if (!addresses.containsKey(varName)) {
@ -79,14 +81,17 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
return addresses.get(varName).intValue() + offset;
}
@Override
public int getIntegerLength() {
return 4;
}
@Override
public void clearMemory() {
sections.clear();
}
@Override
public byte[] getMemorySegment(int address, int size) {
/* Cooja address space */
address -= offset;
@ -113,6 +118,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
setMemorySegment(address+offset, data);
}
@Override
public void setMemorySegment(int address, byte[] data) {
/* Cooja address space */
address -= offset;
@ -193,10 +199,12 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
return sections.get(sectionNr).getData();
}
@Override
public boolean variableExists(String varName) {
return addresses.containsKey(varName);
}
@Override
public int getIntValueOf(String varName) throws UnknownVariableException {
int varAddr = getVariableAddress(varName);
byte[] varData = getMemorySegment(varAddr, 4);
@ -208,6 +216,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
return parseInt(varData);
}
@Override
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
int varAddr = getVariableAddress(varName);
@ -225,6 +234,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
setMemorySegment(varAddr, varData);
}
@Override
public byte getByteValueOf(String varName) throws UnknownVariableException {
int varAddr = getVariableAddress(varName);
byte[] varData = getMemorySegment(varAddr, 1);
@ -236,6 +246,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
return varData[0];
}
@Override
public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException {
int varAddr = getVariableAddress(varName);
byte[] varData = new byte[1];
@ -245,11 +256,13 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
setMemorySegment(varAddr, varData);
}
@Override
public byte[] getByteArray(String varName, int length) throws UnknownVariableException {
int varAddr = getVariableAddress(varName);
return getMemorySegment(varAddr, length);
}
@Override
public void setByteArray(String varName, byte[] data) throws UnknownVariableException {
int varAddr = getVariableAddress(varName);
setMemorySegment(varAddr, data);
@ -347,6 +360,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
System.arraycopy(data, 0, this.data, addr - startAddr, data.length);
}
@Override
public MoteMemorySection clone() {
byte[] dataClone = new byte[data.length];
System.arraycopy(data, 0, dataClone, 0, data.length);
@ -356,6 +370,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
}
@Override
public SectionMoteMemory clone() {
ArrayList<MoteMemorySection> sectionsClone = new ArrayList<MoteMemorySection>();
for (MoteMemorySection section : sections) {
@ -401,12 +416,14 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
}
@Override
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
PolledMemorySegments t = new PolledMemorySegments(mm, address, size);
polledMemories.add(t);
return true;
}
@Override
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
for (PolledMemorySegments mcm: polledMemories) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
@ -417,6 +434,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
}
@Override
public int parseInt(byte[] memorySegment) {
int retVal = 0;
int pos = 0;

View file

@ -83,10 +83,12 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
requestImmediateWakeup();
}
@Override
public int getID() {
return myInterfaceHandler.getMoteID().getMoteID();
}
@Override
public MoteInterfaceHandler getInterfaces() {
return myInterfaceHandler;
}
@ -95,6 +97,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
myInterfaceHandler = newInterfaces;
}
@Override
public MoteMemory getMemory() {
return myMemory;
}
@ -103,6 +106,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
myMemory = (SectionMoteMemory) memory;
}
@Override
public MoteType getType() {
return myType;
}
@ -121,6 +125,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
*
* @param simTime Current simulation time
*/
@Override
public void execute(long simTime) {
/* Poll mote interfaces */
@ -154,6 +159,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
*
* @return Current simulation config
*/
@Override
public Collection<Element> getConfigXML() {
ArrayList<Element> config = new ArrayList<Element>();
Element element;
@ -173,6 +179,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
return config;
}
@Override
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
setSimulation(simulation);
myMemory = myType.createInitialMemory();
@ -212,6 +219,7 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
return true;
}
@Override
public String toString() {
return "Contiki " + getID();
}

View file

@ -123,6 +123,7 @@ public class ContikiMoteType implements MoteType {
DEFAULT, MANUAL;
public String manualHeader = "netstack-conf-example.h";
@Override
public String toString() {
if (this == DEFAULT) {
return "Default (from contiki-conf.h)";
@ -204,10 +205,12 @@ public class ContikiMoteType implements MoteType {
public ContikiMoteType() {
}
@Override
public Mote generateMote(Simulation simulation) {
return new ContikiMote(this, simulation);
}
@Override
public boolean configureAndInit(Container parentContainer, Simulation simulation,
boolean visAvailable) throws MoteTypeCreationException {
myConfig = simulation.getCooja().getProjectConfig().clone();
@ -665,34 +668,42 @@ public class ContikiMoteType implements MoteType {
}
}
@Override
public String getIdentifier() {
return identifier;
}
@Override
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
@Override
public File getContikiSourceFile() {
return fileSource;
}
@Override
public void setContikiSourceFile(File file) {
fileSource = file;
}
@Override
public File getContikiFirmwareFile() {
return fileFirmware;
}
@Override
public void setContikiFirmwareFile(File file) {
fileFirmware = file;
}
@Override
public String getCompileCommands() {
return compileCommands;
}
@Override
public void setCompileCommands(String commands) {
this.compileCommands = commands;
}
@ -1037,14 +1048,17 @@ public class ContikiMoteType implements MoteType {
}
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String newDescription) {
description = newDescription;
}
@Override
public ProjectConfig getConfig() {
return myConfig;
}
@ -1088,6 +1102,7 @@ public class ContikiMoteType implements MoteType {
this.coreInterfaces = coreInterfaces;
}
@Override
public Class<? extends MoteInterface>[] getMoteInterfaceClasses() {
if (moteInterfacesClasses == null) {
return null;
@ -1097,6 +1112,7 @@ public class ContikiMoteType implements MoteType {
return arr;
}
@Override
public void setMoteInterfaceClasses(Class<? extends MoteInterface>[] moteInterfaces) {
this.moteInterfacesClasses = new ArrayList<Class<? extends MoteInterface>>();
for (Class<? extends MoteInterface> intf: moteInterfaces) {
@ -1192,6 +1208,7 @@ public class ContikiMoteType implements MoteType {
*
* @return Mote type visualizer
*/
@Override
public JComponent getTypeVisualizer() {
StringBuilder sb = new StringBuilder();
// Identifier
@ -1240,6 +1257,7 @@ public class ContikiMoteType implements MoteType {
return label;
}
@Override
public Collection<Element> getConfigXML(Simulation simulation) {
ArrayList<Element> config = new ArrayList<Element>();
Element element;
@ -1280,6 +1298,7 @@ public class ContikiMoteType implements MoteType {
return config;
}
@Override
public boolean setConfigXML(Simulation simulation,
Collection<Element> configXML, boolean visAvailable)
throws MoteTypeCreationException {

View file

@ -33,7 +33,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.jdom.Element;
@ -67,6 +66,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
/* Observe our own radio for incoming radio packets */
private Observer radioDataObserver = new Observer() {
@Override
public void update(Observable obs, Object obj) {
ApplicationRadio radio = (ApplicationRadio) obs;
if (radio.getLastEvent() == Radio.RadioEvent.RECEPTION_FINISHED) {
@ -99,6 +99,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
((ApplicationSerialPort)moteInterfaces.getLog()).triggerLog(msg);
}
@Override
public MoteInterfaceHandler getInterfaces() {
return moteInterfaces;
}
@ -107,6 +108,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
moteInterfaces = moteInterfaceHandler;
}
@Override
public MoteMemory getMemory() {
return memory;
}
@ -115,6 +117,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
this.memory = (SectionMoteMemory) memory;
}
@Override
public MoteType getType() {
return moteType;
}
@ -123,6 +126,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
moteType = type;
}
@Override
public Collection<Element> getConfigXML() {
ArrayList<Element> config = new ArrayList<Element>();
Element element;
@ -141,6 +145,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
return config;
}
@Override
public boolean setConfigXML(Simulation simulation,
Collection<Element> configXML, boolean visAvailable) {
setSimulation(simulation);
@ -176,10 +181,12 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
return true;
}
@Override
public int getID() {
return moteInterfaces.getMoteID().getMoteID();
}
@Override
public String toString() {
return "AppMote " + getID();
}

View file

@ -163,6 +163,7 @@ public class BufferListener extends VisPlugin {
private Parser parser = null;
private Buffer buffer = null;
@Override
public void startPlugin() {
super.startPlugin();
if (parser == null) {
@ -214,6 +215,7 @@ public class BufferListener extends VisPlugin {
private ArrayList<SegmentMemoryMonitor> memoryMonitors = new ArrayList<SegmentMemoryMonitor>();
private TimeEvent hourTimeEvent = new TimeEvent(0) {
@Override
public void execute(long t) {
hasHours = true;
repaintTimeColumn();
@ -224,11 +226,13 @@ public class BufferListener extends VisPlugin {
private static final int UPDATE_INTERVAL = 250;
private UpdateAggregator<BufferAccess> logUpdateAggregator = new UpdateAggregator<BufferAccess>(UPDATE_INTERVAL) {
private Runnable scroll = new Runnable() {
@Override
public void run() {
logTable.scrollRectToVisible(
new Rectangle(0, logTable.getHeight() - 2, 1, logTable.getHeight()));
}
};
@Override
protected void handle(List<BufferAccess> ls) {
boolean isVisible = true;
if (logTable.getRowCount() > 0) {
@ -276,18 +280,22 @@ public class BufferListener extends VisPlugin {
model = new AbstractTableModel() {
private static final long serialVersionUID = 3065150390849332924L;
@Override
public String getColumnName(int col) {
if (col == COLUMN_TIME && formatTimeString) {
return "Time";
}
return COLUMN_NAMES[col];
}
@Override
public int getRowCount() {
return logs.size();
}
@Override
public int getColumnCount() {
return COLUMN_NAMES.length;
}
@Override
public Object getValueAt(int row, int col) {
BufferAccess log = logs.get(row);
if (col == COLUMN_TIME) {
@ -307,6 +315,7 @@ public class BufferListener extends VisPlugin {
logTable = new JTable(model) {
private static final long serialVersionUID = -930616018336483196L;
@Override
public String getToolTipText(MouseEvent e) {
java.awt.Point p = e.getPoint();
int rowIndex = rowAtPoint(p);
@ -356,6 +365,7 @@ public class BufferListener extends VisPlugin {
new Color(220, 255, 220),
new Color(255, 200, 255),
};
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
@ -405,6 +415,7 @@ public class BufferListener extends VisPlugin {
logTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
logTable.setFont(new Font("Monospaced", Font.PLAIN, 12));
logTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
showInAllAction.actionPerformed(null);
@ -419,6 +430,7 @@ public class BufferListener extends VisPlugin {
/* Toggle time format */
logTable.getTableHeader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int colIndex = logTable.columnAtPoint(e.getPoint());
int columnIndex = logTable.convertColumnIndexToModel(colIndex);
@ -432,6 +444,7 @@ public class BufferListener extends VisPlugin {
});
logTable.addMouseListener(new MouseAdapter() {
private Parser lastParser = null;
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() != MouseEvent.BUTTON2) {
return;
@ -444,6 +457,7 @@ public class BufferListener extends VisPlugin {
setParser(ByteArrayParser.class);
}
}
@Override
public void mouseExited(MouseEvent e) {
if (lastParser != null) {
/* Switch back to previous parser */
@ -451,6 +465,7 @@ public class BufferListener extends VisPlugin {
lastParser = null;
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (lastParser != null) {
/* Switch back to previous parser */
@ -458,6 +473,7 @@ public class BufferListener extends VisPlugin {
lastParser = null;
}
}
@Override
public void mouseClicked(MouseEvent e) {
int colIndex = logTable.columnAtPoint(e.getPoint());
int columnIndex = logTable.convertColumnIndexToModel(colIndex);
@ -482,21 +498,27 @@ public class BufferListener extends VisPlugin {
/* Popup menu */
JPopupMenu popupMenu = new JPopupMenu();
bufferMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
updateBufferMenu();
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
popupMenu.add(bufferMenu);
parserMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
updateParserMenu();
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
@ -521,6 +543,7 @@ public class BufferListener extends VisPlugin {
colorCheckbox = new JCheckBoxMenuItem("Mote-specific coloring");
popupMenu.add(colorCheckbox);
colorCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
backgroundColors = colorCheckbox.isSelected();
repaint();
@ -529,6 +552,7 @@ public class BufferListener extends VisPlugin {
inverseFilterCheckbox = new JCheckBoxMenuItem("Inverse filter");
popupMenu.add(inverseFilterCheckbox);
inverseFilterCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
inverseFilter = inverseFilterCheckbox.isSelected();
if (inverseFilter) {
@ -543,6 +567,7 @@ public class BufferListener extends VisPlugin {
hideReadsCheckbox = new JCheckBoxMenuItem("Hide READs", hideReads);
popupMenu.add(hideReadsCheckbox);
hideReadsCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
hideReads = hideReadsCheckbox.isSelected();
setFilter(getFilter());
@ -553,6 +578,7 @@ public class BufferListener extends VisPlugin {
withStackTraceCheckbox = new JCheckBoxMenuItem("Capture stack traces", withStackTrace);
popupMenu.add(withStackTraceCheckbox);
withStackTraceCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
withStackTrace = withStackTraceCheckbox.isSelected();
setFilter(getFilter());
@ -564,6 +590,7 @@ public class BufferListener extends VisPlugin {
/* Column width adjustment */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
/* Make sure this happens *after* adding history */
adjuster.setDynamicAdjustment(true);
@ -573,6 +600,7 @@ public class BufferListener extends VisPlugin {
logUpdateAggregator.start();
simulation.getEventCentral().addMoteCountListener(logOutputListener = new MoteCountListener() {
@Override
public void moteWasAdded(Mote mote) {
/* Update title */
try {
@ -581,6 +609,7 @@ public class BufferListener extends VisPlugin {
logger.warn("Could not monitor buffer on: " + mote, e);
}
}
@Override
public void moteWasRemoved(Mote mote) {
/* Update title */
stopObserving(mote);
@ -596,12 +625,14 @@ public class BufferListener extends VisPlugin {
filterPanel.add(filterLabel);
filterPanel.add(filterTextField);
filterTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String str = filterTextField.getText();
setFilter(str);
/* Autoscroll */
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
int s = logTable.getSelectedRow();
if (s < 0) {
@ -673,6 +704,7 @@ public class BufferListener extends VisPlugin {
lastSegmentAddress = segmentAddress;
}
@Override
final public void memoryChanged(MoteMemory memory,
org.contikios.cooja.MoteMemory.MemoryEventType type, int address) {
if (type == MemoryEventType.READ) {
@ -694,10 +726,12 @@ public class BufferListener extends VisPlugin {
}
}
@Override
public MemoryMonitorType getType() {
return MemoryMonitorType.POINTER;
}
@Override
public void dispose() {
super.dispose();
segmentMonitor.dispose();
@ -746,6 +780,7 @@ public class BufferListener extends VisPlugin {
}
}
@Override
public void memoryChanged(MoteMemory memory, MemoryEventType type, int address) {
byte[] newData = getAddress()==0?null:mote.getMemory().getMemorySegment(getAddress(), getSize());
addBufferAccess(bl, mote, oldData, newData, type, this.address);
@ -793,6 +828,7 @@ public class BufferListener extends VisPlugin {
}
}
@Override
public void closePlugin() {
if (hourTimeEvent != null) hourTimeEvent.remove();
@ -805,6 +841,7 @@ public class BufferListener extends VisPlugin {
}
}
@Override
public Collection<Element> getConfigXML() {
ArrayList<Element> config = new ArrayList<Element>();
Element element;
@ -845,12 +882,14 @@ public class BufferListener extends VisPlugin {
return config;
}
@Override
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
for (Element element : configXML) {
String name = element.getName();
if ("filter".equals(name)) {
final String str = element.getText();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
setFilter(str);
}
@ -914,6 +953,7 @@ public class BufferListener extends VisPlugin {
regexp = null;
}
RowFilter<Object, Object> wrapped = new RowFilter<Object, Object>() {
@Override
public boolean include(RowFilter.Entry<? extends Object, ? extends Object> entry) {
if (hideReads) {
int row = (Integer) entry.getIdentifier();
@ -945,6 +985,7 @@ public class BufferListener extends VisPlugin {
public void trySelectTime(final long time) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
for (int i=0; i < logs.size(); i++) {
if (logs.get(i).time < time) {
@ -1054,6 +1095,7 @@ public class BufferListener extends VisPlugin {
private Action saveAction = new AbstractAction("Save to file") {
private static final long serialVersionUID = -4140706275748686944L;
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
File suggest = new File(Cooja.getExternalToolsSetting("BUFFER_LISTENER_SAVEFILE", "BufferAccessLogger.txt"));
@ -1116,6 +1158,7 @@ public class BufferListener extends VisPlugin {
private Action bufferListenerAction = new AbstractAction("in Buffer Listener") {
private static final long serialVersionUID = -6358463434933029699L;
@Override
public void actionPerformed(ActionEvent e) {
int view = logTable.getSelectedRow();
if (view < 0) {
@ -1139,6 +1182,7 @@ public class BufferListener extends VisPlugin {
private Action timeLineAction = new AbstractAction("in Timeline") {
private static final long serialVersionUID = -6358463434933029699L;
@Override
public void actionPerformed(ActionEvent e) {
int view = logTable.getSelectedRow();
if (view < 0) {
@ -1162,6 +1206,7 @@ public class BufferListener extends VisPlugin {
private Action radioLoggerAction = new AbstractAction("in Radio Logger") {
private static final long serialVersionUID = -3041714249257346688L;
@Override
public void actionPerformed(ActionEvent e) {
int view = logTable.getSelectedRow();
if (view < 0) {
@ -1189,6 +1234,7 @@ public class BufferListener extends VisPlugin {
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true));
}
@Override
public void actionPerformed(ActionEvent e) {
timeLineAction.actionPerformed(null);
radioLoggerAction.actionPerformed(null);
@ -1197,6 +1243,7 @@ public class BufferListener extends VisPlugin {
private Action clearAction = new AbstractAction("Clear") {
private static final long serialVersionUID = -2115620313183440224L;
@Override
public void actionPerformed(ActionEvent e) {
int size = logs.size();
if (size > 0) {
@ -1208,6 +1255,7 @@ public class BufferListener extends VisPlugin {
private Action copyAction = new AbstractAction("Selected") {
private static final long serialVersionUID = -8433490108577001803L;
@Override
public void actionPerformed(ActionEvent e) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -1240,6 +1288,7 @@ public class BufferListener extends VisPlugin {
private Action copyAllAction = new AbstractAction("All") {
private static final long serialVersionUID = -5038884975254178373L;
@Override
public void actionPerformed(ActionEvent e) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
@ -1269,6 +1318,7 @@ public class BufferListener extends VisPlugin {
private final ActionListener parserSelectedListener = new ActionListener() {
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
Class<? extends Parser> bpClass =
(Class<? extends Parser>)
@ -1289,6 +1339,7 @@ public class BufferListener extends VisPlugin {
private final ActionListener bufferSelectedListener = new ActionListener() {
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
Class<? extends Buffer> btClass =
(Class<? extends Buffer>)
@ -1421,6 +1472,7 @@ public class BufferListener extends VisPlugin {
}
public static abstract class GraphicalParser implements Parser {
BufferAccess ba = null;
@Override
public Object parse(BufferAccess ba) {
this.ba = ba;
return ba;
@ -1430,6 +1482,7 @@ public class BufferListener extends VisPlugin {
}
public static abstract class StringParser implements Parser {
@Override
public Object parse(BufferAccess ba) {
return parseString(ba);
}
@ -1459,13 +1512,17 @@ public class BufferListener extends VisPlugin {
public void writeConfig(Element element);
}
public static abstract class AbstractBuffer implements Buffer {
@Override
public String getStatusString() {
return null;
}
@Override
public void writeConfig(Element element) {
}
@Override
public void applyConfig(Element element) {
}
@Override
public boolean configure(BufferListener bl) {
return true;
}
@ -1474,6 +1531,7 @@ public class BufferListener extends VisPlugin {
public static abstract class PointerBuffer extends AbstractBuffer {
public abstract int getPointerAddress(Mote mote);
@Override
public SegmentMemoryMonitor createMemoryMonitor(BufferListener bl, Mote mote)
throws Exception {
return new PointerMemoryMonitor(
@ -1486,6 +1544,7 @@ public class BufferListener extends VisPlugin {
}
}
public static abstract class SegmentBuffer extends AbstractBuffer {
@Override
public SegmentMemoryMonitor createMemoryMonitor(BufferListener bl, Mote mote)
throws Exception {
return new SegmentMemoryMonitor(
@ -1521,6 +1580,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Byte array")
public static class ByteArrayParser extends StringParser {
@Override
public String parseString(BufferAccess ba) {
boolean[] diff = ba.getAccessedBitpattern();
if (diff == null) {
@ -1562,6 +1622,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Integer array")
public static class IntegerParser extends StringParser {
@Override
public String parseString(BufferAccess ba) {
StringBuilder sb = new StringBuilder();
@ -1592,6 +1653,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Terminated string")
public static class TerminatedStringParser extends StringParser {
@Override
public String parseString(BufferAccess ba) {
/* TODO Diff? */
int i;
@ -1608,6 +1670,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Printable characters")
public static class PrintableCharactersParser extends StringParser {
@Override
public String parseString(BufferAccess ba) {
/* TODO Diff? */
return new String(ba.mem).replaceAll("[^\\p{Print}]", "");
@ -1616,6 +1679,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("IPv6 address")
public static class IPv6AddressParser extends StringParser {
@Override
public String parseString(BufferAccess ba) {
/* TODO Diff? */
if (ba.mem.length < 16) {
@ -1634,6 +1698,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("IPv4 address")
public static class IPv4AddressParser extends StringParser {
@Override
public String parseString(BufferAccess ba) {
/* TODO Diff? */
if (ba.mem.length < 4) {
@ -1664,6 +1729,7 @@ public class BufferListener extends VisPlugin {
parser.ba = ba;
setPreferredSize(new Dimension(parser.getUnscaledWidth() + 2*XOFFSET, HEIGHT));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.translate(XOFFSET, 0);
@ -1681,9 +1747,11 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Graphical: Height")
public static class GraphicalHeight4BitsParser extends GraphicalParser {
@Override
public int getUnscaledWidth() {
return ba.mem.length*2;
}
@Override
public void paintComponent(Graphics g, JComponent c) {
g.setColor(Color.GRAY);
boolean[] diff = ba.getAccessedBitpattern();
@ -1707,9 +1775,11 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Graphical: Grayscale")
public static class GraphicalGrayscale4BitsParser extends GraphicalParser {
@Override
public int getUnscaledWidth() {
return ba.mem.length*2;
}
@Override
public void paintComponent(Graphics g, JComponent c) {
boolean[] diff = ba.getAccessedBitpattern();
for (int x=0; x < ba.mem.length; x++) {
@ -1730,12 +1800,14 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Variable: node_id")
public static class NodeIDBuffer extends SegmentBuffer {
@Override
public int getAddress(Mote mote) {
if (!mote.getMemory().variableExists("node_id")) {
return -1;
}
return mote.getMemory().getVariableAddress("node_id");
}
@Override
public int getSize(Mote mote) {
return mote.getMemory().getIntegerLength();
}
@ -1744,6 +1816,7 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Queuebuf 0 RAM")
public static class Queuebuf0Buffer extends SegmentBuffer {
@Override
public int getAddress(Mote mote) {
if (!mote.getMemory().variableExists("buframmem")) {
return -1;
@ -1751,6 +1824,7 @@ public class BufferListener extends VisPlugin {
int offset = 0;
return mote.getMemory().getVariableAddress("buframmem") + offset;
}
@Override
public int getSize(Mote mote) {
return 128;
}
@ -1758,12 +1832,14 @@ public class BufferListener extends VisPlugin {
@ClassDescription("packetbuf_aligned")
public static class PacketbufBuffer extends SegmentBuffer {
@Override
public int getAddress(Mote mote) {
if (!mote.getMemory().variableExists("packetbuf_aligned")) {
return -1;
}
return mote.getMemory().getVariableAddress("packetbuf_aligned");
}
@Override
public int getSize(Mote mote) {
return 128;
}
@ -1771,18 +1847,21 @@ public class BufferListener extends VisPlugin {
@ClassDescription("*packetbufptr")
public static class PacketbufPointerBuffer extends PointerBuffer {
@Override
public int getPointerAddress(Mote mote) {
if (!mote.getMemory().variableExists("packetbufptr")) {
return -1;
}
return mote.getMemory().getVariableAddress("packetbufptr");
}
@Override
public int getAddress(Mote mote) {
if (!mote.getMemory().variableExists("packetbufptr")) {
return -1;
}
return mote.getMemory().getIntValueOf("packetbufptr");
}
@Override
public int getSize(Mote mote) {
return 128;
}
@ -1793,18 +1872,21 @@ public class BufferListener extends VisPlugin {
public String variable;
public int size;
public int offset;
@Override
public int getPointerAddress(Mote mote) {
if (!mote.getMemory().variableExists(variable)) {
return -1;
}
return mote.getMemory().getVariableAddress(variable);
}
@Override
public int getAddress(Mote mote) {
if (!mote.getMemory().variableExists(variable)) {
return -1;
}
return mote.getMemory().getIntValueOf(variable)+offset;
}
@Override
public int getSize(Mote mote) {
if (!mote.getMemory().variableExists(variable)) {
return -1;
@ -1812,6 +1894,7 @@ public class BufferListener extends VisPlugin {
return size;
}
@Override
public String getStatusString() {
if (offset > 0) {
return "Pointer *" + variable + "[" + offset + "] (" + size + ")";
@ -1820,16 +1903,19 @@ public class BufferListener extends VisPlugin {
}
}
@Override
public void writeConfig(Element element) {
element.setAttribute("variable", variable);
element.setAttribute("size", "" + size);
element.setAttribute("offset", "" + offset);
}
@Override
public void applyConfig(Element element) {
variable = element.getAttributeValue("variable");
size = Integer.parseInt(element.getAttributeValue("size"));
offset = Integer.parseInt(element.getAttributeValue("offset"));
}
@Override
public boolean configure(BufferListener bl) {
String suggestName = Cooja.getExternalToolsSetting("BUFFER_LISTENER_VARNAME", "node_id");
String suggestSize = Cooja.getExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "2");
@ -1880,12 +1966,14 @@ public class BufferListener extends VisPlugin {
public String variable;
public int size;
public int offset;
@Override
public int getAddress(Mote mote) {
if (!mote.getMemory().variableExists(variable)) {
return -1;
}
return mote.getMemory().getVariableAddress(variable)+offset;
}
@Override
public int getSize(Mote mote) {
if (!mote.getMemory().variableExists(variable)) {
return -1;
@ -1893,6 +1981,7 @@ public class BufferListener extends VisPlugin {
return size;
}
@Override
public String getStatusString() {
if (offset > 0) {
return "Symbol &" + variable + "[" + offset + "] (" + size + ")";
@ -1901,16 +1990,19 @@ public class BufferListener extends VisPlugin {
}
}
@Override
public void writeConfig(Element element) {
element.setAttribute("variable", variable);
element.setAttribute("size", "" + size);
element.setAttribute("offset", "" + offset);
}
@Override
public void applyConfig(Element element) {
variable = element.getAttributeValue("variable");
size = Integer.parseInt(element.getAttributeValue("size"));
offset = Integer.parseInt(element.getAttributeValue("offset"));
}
@Override
public boolean configure(BufferListener bl) {
String suggestName = Cooja.getExternalToolsSetting("BUFFER_LISTENER_VARNAME", "node_id");
String suggestSize = Cooja.getExternalToolsSetting("BUFFER_LISTENER_VARSIZE", "2");
@ -1958,26 +2050,32 @@ public class BufferListener extends VisPlugin {
@ClassDescription("Integer...")
public static class CustomIntegerBuffer extends SegmentBuffer {
public String variable;
@Override
public int getAddress(Mote mote) {
if (!mote.getMemory().variableExists(variable)) {
return -1;
}
return mote.getMemory().getVariableAddress(variable);
}
@Override
public int getSize(Mote mote) {
return mote.getMemory().getIntegerLength();
}
@Override
public String getStatusString() {
return "Integer " + variable;
}
@Override
public void writeConfig(Element element) {
element.setAttribute("variable", variable);
}
@Override
public void applyConfig(Element element) {
variable = element.getAttributeValue("variable");
}
@Override
public boolean configure(BufferListener bl) {
String suggestName = Cooja.getExternalToolsSetting("BUFFER_LISTENER_VARNAME", "node_id");
BufferInput infoComponent =