use of org.contikios.cooja.Watchpoint in project cooja by contiki-ng.
the class TimeLine method addMoteObservers.
private void addMoteObservers(final Mote mote, final MoteEvents moteEvents) {
/* LEDs */
final LED moteLEDs = mote.getInterfaces().getLED();
if (moteLEDs != null) {
LEDEvent startupEv = new LEDEvent(simulation.getSimulationTime(), moteLEDs.isRedOn(), moteLEDs.isGreenOn(), moteLEDs.isYellowOn());
moteEvents.addLED(startupEv);
Observer observer = new Observer() {
@Override
public void update(Observable o, Object arg) {
LEDEvent ev = new LEDEvent(simulation.getSimulationTime(), moteLEDs.isRedOn(), moteLEDs.isGreenOn(), moteLEDs.isYellowOn());
moteEvents.addLED(ev);
}
};
moteLEDs.addObserver(observer);
activeMoteObservers.add(new MoteObservation(mote, moteLEDs, observer));
}
/* Radio OnOff, RXTX, and channels */
final Radio moteRadio = mote.getInterfaces().getRadio();
if (moteRadio != null) {
RadioChannelEvent startupChannel = new RadioChannelEvent(simulation.getSimulationTime(), moteRadio.getChannel(), moteRadio.isRadioOn());
moteEvents.addRadioChannel(startupChannel);
RadioHWEvent startupHW = new RadioHWEvent(simulation.getSimulationTime(), moteRadio.isRadioOn());
moteEvents.addRadioHW(startupHW);
RadioRXTXEvent startupRXTX = new RadioRXTXEvent(simulation.getSimulationTime(), RXTXRadioEvent.IDLE);
moteEvents.addRadioRXTX(startupRXTX);
Observer observer = new Observer() {
int lastChannel = -1;
@Override
public void update(Observable o, Object arg) {
RadioEvent radioEv = moteRadio.getLastEvent();
String details = null;
if (executionDetails && mote instanceof AbstractEmulatedMote) {
details = ((AbstractEmulatedMote) mote).getExecutionDetails();
if (details != null) {
details = "<br>" + details.replace("\n", "<br>");
}
}
/* Radio channel */
int nowChannel = moteRadio.getChannel();
if (nowChannel != lastChannel) {
lastChannel = nowChannel;
RadioChannelEvent ev = new RadioChannelEvent(simulation.getSimulationTime(), nowChannel, moteRadio.isRadioOn());
moteEvents.addRadioChannel(ev);
ev.details = details;
}
if (radioEv == RadioEvent.HW_ON || radioEv == RadioEvent.HW_OFF) {
RadioHWEvent ev = new RadioHWEvent(simulation.getSimulationTime(), moteRadio.isRadioOn());
moteEvents.addRadioHW(ev);
ev.details = details;
/* Also create another channel event here */
lastChannel = nowChannel;
RadioChannelEvent ev2 = new RadioChannelEvent(simulation.getSimulationTime(), nowChannel, moteRadio.isRadioOn());
ev2.details = details;
moteEvents.addRadioChannel(ev2);
}
/* Radio RXTX events */
if (radioEv == RadioEvent.TRANSMISSION_STARTED || radioEv == RadioEvent.TRANSMISSION_FINISHED || radioEv == RadioEvent.RECEPTION_STARTED || radioEv == RadioEvent.RECEPTION_INTERFERED || radioEv == RadioEvent.RECEPTION_FINISHED) {
RadioRXTXEvent ev;
/* Override events, instead show state */
if (moteRadio.isTransmitting()) {
ev = new RadioRXTXEvent(simulation.getSimulationTime(), RXTXRadioEvent.TRANSMITTING);
} else if (!moteRadio.isRadioOn()) {
ev = new RadioRXTXEvent(simulation.getSimulationTime(), RXTXRadioEvent.IDLE);
} else if (moteRadio.isInterfered()) {
ev = new RadioRXTXEvent(simulation.getSimulationTime(), RXTXRadioEvent.INTERFERED);
} else if (moteRadio.isReceiving()) {
ev = new RadioRXTXEvent(simulation.getSimulationTime(), RXTXRadioEvent.RECEIVING);
} else {
ev = new RadioRXTXEvent(simulation.getSimulationTime(), RXTXRadioEvent.IDLE);
}
moteEvents.addRadioRXTX(ev);
ev.details = details;
}
}
};
moteRadio.addObserver(observer);
activeMoteObservers.add(new MoteObservation(mote, moteRadio, observer));
}
/* Watchpoints */
if (mote instanceof WatchpointMote) {
final WatchpointMote watchpointMote = ((WatchpointMote) mote);
WatchpointListener listener = new WatchpointListener() {
@Override
public void watchpointTriggered(Watchpoint watchpoint) {
WatchpointEvent ev = new WatchpointEvent(simulation.getSimulationTime(), watchpoint);
if (executionDetails && mote instanceof AbstractEmulatedMote) {
String details = ((AbstractEmulatedMote) mote).getExecutionDetails();
if (details != null) {
details = "<br>" + details.replace("\n", "<br>");
ev.details = details;
}
}
moteEvents.addWatchpoint(ev);
}
@Override
public void watchpointsChanged() {
}
};
watchpointMote.addWatchpointListener(listener);
activeMoteObservers.add(new MoteObservation(mote, watchpointMote, listener));
}
}
use of org.contikios.cooja.Watchpoint in project cooja by contiki-ng.
the class JSyntaxRemoveBreakpoint method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem menuItem = (JMenuItem) e.getSource();
Action action = menuItem.getAction();
WatchpointMote watchpointMote = (WatchpointMote) action.getValue("WatchpointMote");
if (watchpointMote == null) {
logger.warn("Error: No source, cannot configure breakpoint");
return;
}
File file = (File) action.getValue("WatchpointFile");
Integer line = (Integer) action.getValue("WatchpointLine");
Integer address = (Integer) action.getValue("WatchpointAddress");
if (file == null || line == null || address == null) {
logger.warn("Error: Bad breakpoint info, cannot remove breakpoint");
return;
}
for (Watchpoint w : watchpointMote.getBreakpoints()) {
if (file.equals(w.getCodeFile()) && line.equals(w.getLineNumber()) && address.equals(w.getExecutableAddress())) {
watchpointMote.removeBreakpoint(w);
}
}
}
use of org.contikios.cooja.Watchpoint in project cooja by contiki-ng.
the class CodeUI method updateBreakpoints.
public void updateBreakpoints() {
Highlighter hl = codeEditor.getHighlighter();
for (Object breakpointsLineTag : breakpointsLineTags) {
hl.removeHighlight(breakpointsLineTag);
}
breakpointsLineTags.clear();
for (Watchpoint w : mote.getBreakpoints()) {
if (!w.getCodeFile().equals(displayedFile)) {
continue;
}
final int start = codeEditorLines.get(w.getLineNumber());
int end = codeEditorLines.get(w.getLineNumber() + 1);
try {
breakpointsLineTags.add(hl.addHighlight(start, end, BREAKPOINTS_MARKER));
} catch (BadLocationException e1) {
}
}
}
Aggregations