diff --git a/tools/cooja/apps/mrm/java/se/sics/mrm/FormulaViewer.java b/tools/cooja/apps/mrm/java/se/sics/mrm/FormulaViewer.java index 9aa0f2ebe..cc2e1fe79 100644 --- a/tools/cooja/apps/mrm/java/se/sics/mrm/FormulaViewer.java +++ b/tools/cooja/apps/mrm/java/se/sics/mrm/FormulaViewer.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: FormulaViewer.java,v 1.2 2007/03/23 21:13:43 fros4943 Exp $ + * $Id: FormulaViewer.java,v 1.3 2008/02/18 08:21:59 fros4943 Exp $ */ package se.sics.mrm; @@ -45,7 +45,7 @@ import se.sics.cooja.*; /** * This plugin allows a user to reconfigure current radio channel parameters. - * + * * @author Fredrik Osterlind */ @ClassDescription("MRM - Formula Viewer") @@ -61,11 +61,11 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { private static Dimension labelDimension = new Dimension(240, 20); private static NumberFormat doubleFormat = NumberFormat.getNumberInstance(); private static NumberFormat integerFormat = NumberFormat.getIntegerInstance(); - + private Vector allIntegerParameters = new Vector(); private Vector allDoubleParameters = new Vector(); private Vector allBooleanParameters = new Vector(); - + private JPanel areaGeneral; private JPanel areaTransmitter; private JPanel areaReceiver; @@ -74,12 +74,12 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { /** * Creates a new formula viewer. - * + * * @param simulationToVisualize Simulation which holds the MRM channel model. */ public FormulaViewer(Simulation simulationToVisualize, GUI gui) { super("MRM - Formula Viewer", gui); - + currentSimulation = simulationToVisualize; currentRadioMedium = (MRM) currentSimulation.getRadioMedium(); currentChannelModel = currentRadioMedium.getChannelModel(); @@ -96,7 +96,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { setContentPane(scrollPane); JPanel collapsableArea; - + // General parameters collapsableArea = createCollapsableArea("General parameters", allComponents); areaGeneral = collapsableArea; @@ -135,14 +135,14 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { collapsableArea, currentChannelModel.getParameterDoubleValue("system_gain_mean") ); - + addDoubleParameter( "system_gain_var", currentChannelModel.getParameterDescription("system_gain_var"), collapsableArea, currentChannelModel.getParameterDoubleValue("system_gain_var") ); - + addDoubleParameter( "wavelength", currentChannelModel.getParameterDescription("wavelength"), @@ -160,7 +160,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { collapsableArea, currentChannelModel.getParameterDoubleValue("tx_power") ); - + addDoubleParameter( "tx_antenna_gain", currentChannelModel.getParameterDescription("tx_antenna_gain"), @@ -185,7 +185,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { collapsableArea, currentChannelModel.getParameterDoubleValue("rx_antenna_gain") ); - + // Ray Tracer parameters collapsableArea = createCollapsableArea("Ray Tracer parameters", allComponents); areaRayTracer = collapsableArea; @@ -238,7 +238,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { collapsableArea, currentChannelModel.getParameterIntegerValue("rt_max_diffractions") ); - + /* addBooleanParameter( "rt_use_scattering", currentChannelModel.getParameterDescription("rt_use_scattering"), @@ -266,14 +266,14 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { collapsableArea, currentChannelModel.getParameterDoubleValue("rt_diffr_coefficient") ); - + /* addDoubleParameter( "rt_scatt_coefficient", currentChannelModel.getParameterDescription("rt_scatt_coefficient"), collapsableArea, currentChannelModel.getParameterDoubleValue("rt_scatt_coefficient") ); -*/ +*/ // Shadowing parameters collapsableArea = createCollapsableArea("Shadowing parameters", allComponents); areaShadowing = collapsableArea; @@ -285,22 +285,22 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { currentChannelModel.getParameterDoubleValue("obstacle_attenuation") ); - - + + // Add channel model observer responsible to keep all GUI components synched currentChannelModel.addSettingsObserver(channelModelSettingsObserver); - + // Set initial size etc. pack(); setVisible(true); - + // Tries to select this plugin try { setSelected(true); } catch (java.beans.PropertyVetoException e) { // Could not select } - + } /** @@ -325,43 +325,44 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { }; collapsableArea.setLayout(new BoxLayout(collapsableArea, BoxLayout.Y_AXIS)); collapsableArea.setVisible(false); - + JPanel titlePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return new Dimension(super.getMaximumSize().width, getPreferredSize().height); } }; - + titlePanel.add(BorderLayout.WEST, new JLabel(title)); JCheckBox collapseCheckBox = new JCheckBox("show settings", false); collapseCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if (((JCheckBox) e.getSource()).isSelected()) + if (((JCheckBox) e.getSource()).isSelected()) { collapsableArea.setVisible(true); - else + } else { collapsableArea.setVisible(false); + } } }); collapsableArea.putClientProperty("my_checkbox", collapseCheckBox); titlePanel.add(BorderLayout.EAST, collapseCheckBox); - + collapsableArea.setBorder( BorderFactory.createLineBorder(Color.LIGHT_GRAY) - ); + ); collapsableArea.setAlignmentY(Component.TOP_ALIGNMENT); - + holdingPanel.add(titlePanel); holdingPanel.add(collapsableArea); contentPane.add(holdingPanel); return collapsableArea; } - + /** - * Creates and adds a panel with a label and a + * Creates and adds a panel with a label and a * text field which accepts doubles. - * + * * @param id Identifier of new parameter * @param description Description of new parameter * @param contentPane Where to add created panel @@ -372,7 +373,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { JPanel panel = new JPanel(); JLabel label; JFormattedTextField textField; - + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); @@ -392,16 +393,16 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { } }); allDoubleParameters.add(textField); - + contentPane.add(panel); return textField; } - + /** - * Creates and adds a panel with a label and a + * Creates and adds a panel with a label and a * text field which accepts integers. - * + * * @param id Identifier of new parameter * @param description Description of new parameter * @param contentPane Where to add created panel @@ -412,7 +413,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { JPanel panel = new JPanel(); JLabel label; JFormattedTextField textField; - + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); @@ -438,11 +439,11 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { return textField; } - + /** - * Creates and adds a panel with a label and a + * Creates and adds a panel with a label and a * boolean checkbox. - * + * * @param id Identifier of new parameter * @param description Description of new parameter * @param contentPane Where to add created panel @@ -453,7 +454,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { JPanel panel = new JPanel(); JLabel label; JCheckBox checkBox; - + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); @@ -479,10 +480,10 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { return checkBox; } - + /** * Creates and adds a panel with a description label. - * + * * @param description Description of new parameter * @param contentPane Where to add created panel * @return Created label @@ -490,7 +491,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { private JLabel addLabelParameter(String description, Container contentPane) { JPanel panel = new JPanel(); JLabel label; - + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); @@ -502,7 +503,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { return label; } - + /** * Listens to settings changes in the channel model. * If it changes, all GUI parameters are updated accordingly. @@ -511,21 +512,21 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { public void update(Observable obs, Object obj) { // Update all integers for (int i=0; i < allIntegerParameters.size(); i++) { - JFormattedTextField textField = (JFormattedTextField) allIntegerParameters.get(i); + JFormattedTextField textField = allIntegerParameters.get(i); String id = (String) textField.getClientProperty("id"); textField.setValue(currentChannelModel.getParameterValue(id)); } // Update all doubles for (int i=0; i < allDoubleParameters.size(); i++) { - JFormattedTextField textField = (JFormattedTextField) allDoubleParameters.get(i); + JFormattedTextField textField = allDoubleParameters.get(i); String id = (String) textField.getClientProperty("id"); textField.setValue(currentChannelModel.getParameterValue(id)); } // Update all booleans for (int i=0; i < allBooleanParameters.size(); i++) { - JCheckBox checkBox = (JCheckBox) allBooleanParameters.get(i); + JCheckBox checkBox = allBooleanParameters.get(i); String id = (String) checkBox.getClientProperty("id"); checkBox.setSelected(currentChannelModel.getParameterBooleanValue(id)); } @@ -533,7 +534,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { repaint(); } }; - + public void closePlugin() { // Remove the channel model observer if (currentChannelModel != null && channelModelSettingsObserver != null) { @@ -542,12 +543,12 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { logger.fatal("Can't remove channel model observer: " + channelModelSettingsObserver); } } - + /** * Returns XML elements representing the current configuration. - * + * * @see #setConfigXML(Collection) - * @return XML element collection + * @return XML element collection */ public Collection getConfigXML() { Vector config = new Vector(); @@ -573,7 +574,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { /** * Sets the configuration depending on the given XML elements. - * + * * @see #getConfigXML() * @param configXML * Config XML elements @@ -608,7 +609,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin { ActionEvent.ACTION_PERFORMED, "")); } } - return true; + return true; } } diff --git a/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java b/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java index 59f08f0f8..32c27ba1f 100644 --- a/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java +++ b/tools/cooja/apps/mrm/java/se/sics/mrm/MRM.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MRM.java,v 1.5 2007/03/23 21:22:37 fros4943 Exp $ + * $Id: MRM.java,v 1.6 2008/02/18 08:21:59 fros4943 Exp $ */ package se.sics.mrm; @@ -42,18 +42,18 @@ import se.sics.cooja.radiomediums.AbstractRadioMedium; /** * This is the main class of the COOJA Multi-path Ray-tracing Medium (MRM) * package. - * + * * MRM is meant to be an alternative to the simpler radio mediums available in * COOJA. It is packet based and uses a 2D ray-tracing approach to approximate * signal strength attenuations between simulated radios. Currently the * ray-tracing only supports reflections and refractions through homogeneous * obstacles. - * + * * MRM provides a number of plugins for example a plugin for visualizing radio * environments, and a plugin for configuring the radio medium. - * + * * Future work includes adding diffractions and scattering support. - * + * * @author Fredrik Osterlind */ @ClassDescription("Multi-path Ray-tracer Medium (MRM)") @@ -62,20 +62,20 @@ public class MRM extends AbstractRadioMedium { private ChannelModel currentChannelModel = null; private Simulation mySimulation = null; - + private Random random = new Random(); /** * Notifies observers when this radio medium has changed settings. */ private SettingsObservable settingsObservable = new SettingsObservable(); - + /** * Creates a new Multi-path Ray-tracing Medium (MRM). */ public MRM(Simulation simulation) { super(simulation); - + // Create the channel model currentChannelModel = new ChannelModel(); @@ -91,20 +91,22 @@ public class MRM extends AbstractRadioMedium { // Loop through all radios for (Radio listeningRadio: getRegisteredRadios()) { // Ignore sending radio and radios on different channels - if (sendingRadio == listeningRadio) + if (sendingRadio == listeningRadio) { continue; - if (sendingRadio.getChannel() != listeningRadio.getChannel()) + } + if (sendingRadio.getChannel() != listeningRadio.getChannel()) { continue; + } double listeningPositionX = listeningRadio.getPosition().getXCoordinate(); double listeningPositionY = listeningRadio.getPosition().getYCoordinate(); // Calculate probability of reception of listening radio double[] probData = currentChannelModel.getProbability( - sendingPosition.getXCoordinate(), - sendingPosition.getYCoordinate(), - listeningPositionX, - listeningPositionY, + sendingPosition.getXCoordinate(), + sendingPosition.getYCoordinate(), + listeningPositionX, + listeningPositionY, -Double.MAX_VALUE ); @@ -148,7 +150,7 @@ public class MRM extends AbstractRadioMedium { // Interfere radio newConnection.addInterfered(listeningRadio, probData[1]); listeningRadio.interfereAnyReception(); - + // TODO Radios always get interfered right now, should recalculate probability // if (maxInterferenceSignalStrength + SOME_RELEVANT_LIMIT > transmissionSignalStrength) { // // Recalculating probability of delivery @@ -166,7 +168,7 @@ public class MRM extends AbstractRadioMedium { } } - + return newConnection; } @@ -188,8 +190,9 @@ public class MRM extends AbstractRadioMedium { // ((MRMRadioConnection) conn).getSource().setCurrentSignalStrength(12345); // TODO Set signal strength on source? for (Radio dstRadio : ((MRMRadioConnection) conn).getDestinations()) { double signalStrength = ((MRMRadioConnection) conn).getDestinationSignalStrength(dstRadio); - if (signalStrength > dstRadio.getCurrentSignalStrength()) + if (signalStrength > dstRadio.getCurrentSignalStrength()) { dstRadio.setCurrentSignalStrength(signalStrength); + } } } @@ -197,8 +200,9 @@ public class MRM extends AbstractRadioMedium { for (RadioConnection conn : getActiveConnections()) { for (Radio interferedRadio : ((MRMRadioConnection) conn).getInterfered()) { double signalStrength = ((MRMRadioConnection) conn).getInterferenceSignalStrength(interferedRadio); - if (signalStrength > interferedRadio.getCurrentSignalStrength()) + if (signalStrength > interferedRadio.getCurrentSignalStrength()) { interferedRadio.setCurrentSignalStrength(signalStrength); + } if (!interferedRadio.isInterfered()) { // Set to interfered again @@ -226,20 +230,20 @@ public class MRM extends AbstractRadioMedium { // Forwarding to current channel model return currentChannelModel.getConfigXML(); } - + public boolean setConfigXML(Collection configXML, boolean visAvailable) { // Forwarding to current channel model return currentChannelModel.setConfigXML(configXML); } - + // -- MRM specific methods -- /** * Adds an observer which is notified when this radio medium has * changed settings, such as added or removed radios. - * + * * @param obs New observer */ public void addSettingsObserver(Observer obs) { @@ -248,24 +252,24 @@ public class MRM extends AbstractRadioMedium { /** * Deletes an earlier registered setting observer. - * + * * @param osb * Earlier registered observer */ public void deleteSettingsObserver(Observer obs) { settingsObservable.deleteObserver(obs); } - + /** * Returns position of given radio. - * + * * @param radio Registered radio * @return Position of given radio */ public Position getRadioPosition(Radio radio) { return radio.getPosition(); } - + /** * @return Number of registered radios. */ @@ -275,7 +279,7 @@ public class MRM extends AbstractRadioMedium { /** * Returns radio at given index. - * + * * @param index Index of registered radio. * @return Radio at given index */ @@ -286,7 +290,7 @@ public class MRM extends AbstractRadioMedium { /** * Returns the current channel model object, responsible for * all probability and transmission calculations. - * + * * @return Current channel model */ public ChannelModel getChannelModel() { @@ -302,11 +306,11 @@ public class MRM extends AbstractRadioMedium { class MRMRadioConnection extends RadioConnection { private Hashtable signalStrengths = new Hashtable(); - + public MRMRadioConnection(Radio sourceRadio) { super(sourceRadio); } - + public void addDestination(Radio radio, double signalStrength) { signalStrengths.put(radio, signalStrength); addDestination(radio); @@ -325,5 +329,5 @@ public class MRM extends AbstractRadioMedium { return signalStrengths.get(radio); } } - + }