Search in sources :

Example 1 with Watchpoint

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));
    }
}
Also used : AbstractEmulatedMote(org.contikios.cooja.motes.AbstractEmulatedMote) LED(org.contikios.cooja.interfaces.LED) Radio(org.contikios.cooja.interfaces.Radio) Watchpoint(org.contikios.cooja.Watchpoint) Observable(java.util.Observable) Point(java.awt.Point) Watchpoint(org.contikios.cooja.Watchpoint) Observer(java.util.Observer) WatchpointListener(org.contikios.cooja.WatchpointMote.WatchpointListener) RadioEvent(org.contikios.cooja.interfaces.Radio.RadioEvent) WatchpointMote(org.contikios.cooja.WatchpointMote)

Example 2 with Watchpoint

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);
        }
    }
}
Also used : Action(javax.swing.Action) DefaultSyntaxAction(de.sciss.syntaxpane.actions.DefaultSyntaxAction) Watchpoint(org.contikios.cooja.Watchpoint) JMenuItem(javax.swing.JMenuItem) WatchpointMote(org.contikios.cooja.WatchpointMote) File(java.io.File)

Example 3 with Watchpoint

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) {
        }
    }
}
Also used : Watchpoint(org.contikios.cooja.Watchpoint) Point(java.awt.Point) JSyntaxRemoveBreakpoint(org.contikios.cooja.util.JSyntaxRemoveBreakpoint) Watchpoint(org.contikios.cooja.Watchpoint) JSyntaxAddBreakpoint(org.contikios.cooja.util.JSyntaxAddBreakpoint) BadLocationException(javax.swing.text.BadLocationException) Highlighter(javax.swing.text.Highlighter)

Aggregations

Watchpoint (org.contikios.cooja.Watchpoint)3 Point (java.awt.Point)2 WatchpointMote (org.contikios.cooja.WatchpointMote)2 DefaultSyntaxAction (de.sciss.syntaxpane.actions.DefaultSyntaxAction)1 File (java.io.File)1 Observable (java.util.Observable)1 Observer (java.util.Observer)1 Action (javax.swing.Action)1 JMenuItem (javax.swing.JMenuItem)1 BadLocationException (javax.swing.text.BadLocationException)1 Highlighter (javax.swing.text.Highlighter)1 WatchpointListener (org.contikios.cooja.WatchpointMote.WatchpointListener)1 LED (org.contikios.cooja.interfaces.LED)1 Radio (org.contikios.cooja.interfaces.Radio)1 RadioEvent (org.contikios.cooja.interfaces.Radio.RadioEvent)1 AbstractEmulatedMote (org.contikios.cooja.motes.AbstractEmulatedMote)1 JSyntaxAddBreakpoint (org.contikios.cooja.util.JSyntaxAddBreakpoint)1 JSyntaxRemoveBreakpoint (org.contikios.cooja.util.JSyntaxRemoveBreakpoint)1