From fa6748f45a74794c559e7b385655d211f5625db7 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 21 Aug 2007 09:17:18 +0000 Subject: [PATCH] reset success ratio to 100&, and added configuration ability in plugin --- .../java/se/sics/cooja/radiomediums/UDGM.java | 63 ++++++++++++++++--- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java index 656037280..a9601f5ae 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: UDGM.java,v 1.6 2007/07/13 09:08:25 fros4943 Exp $ + * $Id: UDGM.java,v 1.7 2007/08/21 09:17:18 fros4943 Exp $ */ package se.sics.cooja.radiomediums; @@ -83,7 +83,7 @@ public class UDGM extends AbstractRadioMedium { public static final double SS_OK_WORST = -30; - public static final double PACKET_SUCCESS_RATIO = 0.95; + public static double PACKET_SUCCESS_RATIO = 1.0; // Maximum ranges (SS indicator 100) private static double TRANSMITTING_RANGE = 50; @@ -116,6 +116,8 @@ public class UDGM extends AbstractRadioMedium { private JSpinner interferenceSpinner = null; + private JSpinner successRatioSpinner = null; + private Observer radioMediumObserver; private class ChangeRangesMenuAction implements MoteMenuAction { @@ -134,6 +136,21 @@ public class UDGM extends AbstractRadioMedium { } }; + private class ChangeSuccessRadioMenuAction implements MoteMenuAction { + public boolean isEnabled(Mote mote) { + return true; + } + + public String getDescription(Mote mote) { + return "Change transmission success ratio"; + } + + public void doAction(Mote mote) { + successRatioSpinner.setVisible(true); + repaint(); + } + }; + public VisUDGM(Simulation sim, GUI gui) { super(sim, gui); setTitle("UDGM Visualizer"); @@ -149,15 +166,33 @@ public class UDGM extends AbstractRadioMedium { interferenceModel.setStepSize(new Double(1.0)); // 1m interferenceModel.setMinimum(new Double(0.0)); - transmissionSpinner = new JSpinner(transmissionModel); - interferenceSpinner = new JSpinner(interferenceModel); + SpinnerNumberModel successRatioModel = new SpinnerNumberModel(); + successRatioModel.setValue(new Double(PACKET_SUCCESS_RATIO)); + successRatioModel.setStepSize(new Double(0.01)); // 1% + successRatioModel.setMinimum(new Double(0.0)); + successRatioModel.setMaximum(new Double(1.0)); + JSpinner.NumberEditor editor; + transmissionSpinner = new JSpinner(transmissionModel); + editor = new JSpinner.NumberEditor(transmissionSpinner, "0m"); + transmissionSpinner.setEditor(editor); + interferenceSpinner = new JSpinner(interferenceModel); + editor = new JSpinner.NumberEditor(interferenceSpinner, "0m"); + interferenceSpinner.setEditor(editor); + successRatioSpinner = new JSpinner(successRatioModel); + editor = new JSpinner.NumberEditor(successRatioSpinner, "0%"); + successRatioSpinner.setEditor(editor); + + ((JSpinner.DefaultEditor) transmissionSpinner.getEditor()).getTextField() - .setColumns(5); + .setColumns(5); ((JSpinner.DefaultEditor) interferenceSpinner.getEditor()).getTextField() - .setColumns(5); + .setColumns(5); + ((JSpinner.DefaultEditor) successRatioSpinner.getEditor()).getTextField() + .setColumns(5); transmissionSpinner.setToolTipText("Transmitting range"); interferenceSpinner.setToolTipText("Interference range"); + successRatioSpinner.setToolTipText("Transmission success ratio in green area"); transmissionSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { @@ -175,10 +210,20 @@ public class UDGM extends AbstractRadioMedium { } }); + successRatioSpinner.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + PACKET_SUCCESS_RATIO = ((SpinnerNumberModel) successRatioSpinner + .getModel()).getNumber().doubleValue(); + repaint(); + } + }); + getCurrentCanvas().add(transmissionSpinner); getCurrentCanvas().add(interferenceSpinner); + getCurrentCanvas().add(successRatioSpinner); transmissionSpinner.setVisible(false); interferenceSpinner.setVisible(false); + successRatioSpinner.setVisible(false); // Add mouse listener for selecting motes getCurrentCanvas().addMouseListener(new MouseListener() { @@ -200,6 +245,7 @@ public class UDGM extends AbstractRadioMedium { selectedMote = null; transmissionSpinner.setVisible(false); interferenceSpinner.setVisible(false); + successRatioSpinner.setVisible(false); repaint(); return; } @@ -221,9 +267,10 @@ public class UDGM extends AbstractRadioMedium { } }); - // Register change ranges action + // Register change ranges and change success ratio action addMoteMenuAction(new ChangeRangesMenuAction()); - + addMoteMenuAction(new ChangeSuccessRadioMenuAction()); + // Observe our own radio medium myRadioMedium .addRadioMediumObserver(radioMediumObserver = new Observer() {