added predefined obstacles (no need for external images)

This commit is contained in:
fros4943 2008-02-18 08:21:59 +00:00
parent 3675479274
commit f577b17ab3
2 changed files with 87 additions and 82 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.mrm;
@ -45,7 +45,7 @@ import se.sics.cooja.*;
/** /**
* This plugin allows a user to reconfigure current radio channel parameters. * This plugin allows a user to reconfigure current radio channel parameters.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ClassDescription("MRM - Formula Viewer") @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 Dimension labelDimension = new Dimension(240, 20);
private static NumberFormat doubleFormat = NumberFormat.getNumberInstance(); private static NumberFormat doubleFormat = NumberFormat.getNumberInstance();
private static NumberFormat integerFormat = NumberFormat.getIntegerInstance(); private static NumberFormat integerFormat = NumberFormat.getIntegerInstance();
private Vector<JFormattedTextField> allIntegerParameters = new Vector<JFormattedTextField>(); private Vector<JFormattedTextField> allIntegerParameters = new Vector<JFormattedTextField>();
private Vector<JFormattedTextField> allDoubleParameters = new Vector<JFormattedTextField>(); private Vector<JFormattedTextField> allDoubleParameters = new Vector<JFormattedTextField>();
private Vector<JCheckBox> allBooleanParameters = new Vector<JCheckBox>(); private Vector<JCheckBox> allBooleanParameters = new Vector<JCheckBox>();
private JPanel areaGeneral; private JPanel areaGeneral;
private JPanel areaTransmitter; private JPanel areaTransmitter;
private JPanel areaReceiver; private JPanel areaReceiver;
@ -74,12 +74,12 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
/** /**
* Creates a new formula viewer. * Creates a new formula viewer.
* *
* @param simulationToVisualize Simulation which holds the MRM channel model. * @param simulationToVisualize Simulation which holds the MRM channel model.
*/ */
public FormulaViewer(Simulation simulationToVisualize, GUI gui) { public FormulaViewer(Simulation simulationToVisualize, GUI gui) {
super("MRM - Formula Viewer", gui); super("MRM - Formula Viewer", gui);
currentSimulation = simulationToVisualize; currentSimulation = simulationToVisualize;
currentRadioMedium = (MRM) currentSimulation.getRadioMedium(); currentRadioMedium = (MRM) currentSimulation.getRadioMedium();
currentChannelModel = currentRadioMedium.getChannelModel(); currentChannelModel = currentRadioMedium.getChannelModel();
@ -96,7 +96,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
setContentPane(scrollPane); setContentPane(scrollPane);
JPanel collapsableArea; JPanel collapsableArea;
// General parameters // General parameters
collapsableArea = createCollapsableArea("General parameters", allComponents); collapsableArea = createCollapsableArea("General parameters", allComponents);
areaGeneral = collapsableArea; areaGeneral = collapsableArea;
@ -135,14 +135,14 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
collapsableArea, collapsableArea,
currentChannelModel.getParameterDoubleValue("system_gain_mean") currentChannelModel.getParameterDoubleValue("system_gain_mean")
); );
addDoubleParameter( addDoubleParameter(
"system_gain_var", "system_gain_var",
currentChannelModel.getParameterDescription("system_gain_var"), currentChannelModel.getParameterDescription("system_gain_var"),
collapsableArea, collapsableArea,
currentChannelModel.getParameterDoubleValue("system_gain_var") currentChannelModel.getParameterDoubleValue("system_gain_var")
); );
addDoubleParameter( addDoubleParameter(
"wavelength", "wavelength",
currentChannelModel.getParameterDescription("wavelength"), currentChannelModel.getParameterDescription("wavelength"),
@ -160,7 +160,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
collapsableArea, collapsableArea,
currentChannelModel.getParameterDoubleValue("tx_power") currentChannelModel.getParameterDoubleValue("tx_power")
); );
addDoubleParameter( addDoubleParameter(
"tx_antenna_gain", "tx_antenna_gain",
currentChannelModel.getParameterDescription("tx_antenna_gain"), currentChannelModel.getParameterDescription("tx_antenna_gain"),
@ -185,7 +185,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
collapsableArea, collapsableArea,
currentChannelModel.getParameterDoubleValue("rx_antenna_gain") currentChannelModel.getParameterDoubleValue("rx_antenna_gain")
); );
// Ray Tracer parameters // Ray Tracer parameters
collapsableArea = createCollapsableArea("Ray Tracer parameters", allComponents); collapsableArea = createCollapsableArea("Ray Tracer parameters", allComponents);
areaRayTracer = collapsableArea; areaRayTracer = collapsableArea;
@ -238,7 +238,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
collapsableArea, collapsableArea,
currentChannelModel.getParameterIntegerValue("rt_max_diffractions") currentChannelModel.getParameterIntegerValue("rt_max_diffractions")
); );
/* addBooleanParameter( /* addBooleanParameter(
"rt_use_scattering", "rt_use_scattering",
currentChannelModel.getParameterDescription("rt_use_scattering"), currentChannelModel.getParameterDescription("rt_use_scattering"),
@ -266,14 +266,14 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
collapsableArea, collapsableArea,
currentChannelModel.getParameterDoubleValue("rt_diffr_coefficient") currentChannelModel.getParameterDoubleValue("rt_diffr_coefficient")
); );
/* addDoubleParameter( /* addDoubleParameter(
"rt_scatt_coefficient", "rt_scatt_coefficient",
currentChannelModel.getParameterDescription("rt_scatt_coefficient"), currentChannelModel.getParameterDescription("rt_scatt_coefficient"),
collapsableArea, collapsableArea,
currentChannelModel.getParameterDoubleValue("rt_scatt_coefficient") currentChannelModel.getParameterDoubleValue("rt_scatt_coefficient")
); );
*/ */
// Shadowing parameters // Shadowing parameters
collapsableArea = createCollapsableArea("Shadowing parameters", allComponents); collapsableArea = createCollapsableArea("Shadowing parameters", allComponents);
areaShadowing = collapsableArea; areaShadowing = collapsableArea;
@ -285,22 +285,22 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
currentChannelModel.getParameterDoubleValue("obstacle_attenuation") currentChannelModel.getParameterDoubleValue("obstacle_attenuation")
); );
// Add channel model observer responsible to keep all GUI components synched // Add channel model observer responsible to keep all GUI components synched
currentChannelModel.addSettingsObserver(channelModelSettingsObserver); currentChannelModel.addSettingsObserver(channelModelSettingsObserver);
// Set initial size etc. // Set initial size etc.
pack(); pack();
setVisible(true); setVisible(true);
// Tries to select this plugin // Tries to select this plugin
try { try {
setSelected(true); setSelected(true);
} catch (java.beans.PropertyVetoException e) { } catch (java.beans.PropertyVetoException e) {
// Could not select // Could not select
} }
} }
/** /**
@ -325,43 +325,44 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
}; };
collapsableArea.setLayout(new BoxLayout(collapsableArea, BoxLayout.Y_AXIS)); collapsableArea.setLayout(new BoxLayout(collapsableArea, BoxLayout.Y_AXIS));
collapsableArea.setVisible(false); collapsableArea.setVisible(false);
JPanel titlePanel = new JPanel(new BorderLayout()) { JPanel titlePanel = new JPanel(new BorderLayout()) {
public Dimension getMaximumSize() { public Dimension getMaximumSize() {
return new Dimension(super.getMaximumSize().width, getPreferredSize().height); return new Dimension(super.getMaximumSize().width, getPreferredSize().height);
} }
}; };
titlePanel.add(BorderLayout.WEST, new JLabel(title)); titlePanel.add(BorderLayout.WEST, new JLabel(title));
JCheckBox collapseCheckBox = new JCheckBox("show settings", false); JCheckBox collapseCheckBox = new JCheckBox("show settings", false);
collapseCheckBox.addActionListener(new ActionListener() { collapseCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (((JCheckBox) e.getSource()).isSelected()) if (((JCheckBox) e.getSource()).isSelected()) {
collapsableArea.setVisible(true); collapsableArea.setVisible(true);
else } else {
collapsableArea.setVisible(false); collapsableArea.setVisible(false);
}
} }
}); });
collapsableArea.putClientProperty("my_checkbox", collapseCheckBox); collapsableArea.putClientProperty("my_checkbox", collapseCheckBox);
titlePanel.add(BorderLayout.EAST, collapseCheckBox); titlePanel.add(BorderLayout.EAST, collapseCheckBox);
collapsableArea.setBorder( collapsableArea.setBorder(
BorderFactory.createLineBorder(Color.LIGHT_GRAY) BorderFactory.createLineBorder(Color.LIGHT_GRAY)
); );
collapsableArea.setAlignmentY(Component.TOP_ALIGNMENT); collapsableArea.setAlignmentY(Component.TOP_ALIGNMENT);
holdingPanel.add(titlePanel); holdingPanel.add(titlePanel);
holdingPanel.add(collapsableArea); holdingPanel.add(collapsableArea);
contentPane.add(holdingPanel); contentPane.add(holdingPanel);
return collapsableArea; 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. * text field which accepts doubles.
* *
* @param id Identifier of new parameter * @param id Identifier of new parameter
* @param description Description of new parameter * @param description Description of new parameter
* @param contentPane Where to add created panel * @param contentPane Where to add created panel
@ -372,7 +373,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
JLabel label; JLabel label;
JFormattedTextField textField; JFormattedTextField textField;
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.setAlignmentY(Component.TOP_ALIGNMENT);
panel.add(Box.createHorizontalStrut(10)); panel.add(Box.createHorizontalStrut(10));
@ -392,16 +393,16 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
} }
}); });
allDoubleParameters.add(textField); allDoubleParameters.add(textField);
contentPane.add(panel); contentPane.add(panel);
return textField; 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. * text field which accepts integers.
* *
* @param id Identifier of new parameter * @param id Identifier of new parameter
* @param description Description of new parameter * @param description Description of new parameter
* @param contentPane Where to add created panel * @param contentPane Where to add created panel
@ -412,7 +413,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
JLabel label; JLabel label;
JFormattedTextField textField; JFormattedTextField textField;
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.setAlignmentY(Component.TOP_ALIGNMENT);
panel.add(Box.createHorizontalStrut(10)); panel.add(Box.createHorizontalStrut(10));
@ -438,11 +439,11 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
return textField; return textField;
} }
/** /**
* Creates and adds a panel with a label and a * Creates and adds a panel with a label and a
* boolean checkbox. * boolean checkbox.
* *
* @param id Identifier of new parameter * @param id Identifier of new parameter
* @param description Description of new parameter * @param description Description of new parameter
* @param contentPane Where to add created panel * @param contentPane Where to add created panel
@ -453,7 +454,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
JLabel label; JLabel label;
JCheckBox checkBox; JCheckBox checkBox;
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.setAlignmentY(Component.TOP_ALIGNMENT);
panel.add(Box.createHorizontalStrut(10)); panel.add(Box.createHorizontalStrut(10));
@ -479,10 +480,10 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
return checkBox; return checkBox;
} }
/** /**
* Creates and adds a panel with a description label. * Creates and adds a panel with a description label.
* *
* @param description Description of new parameter * @param description Description of new parameter
* @param contentPane Where to add created panel * @param contentPane Where to add created panel
* @return Created label * @return Created label
@ -490,7 +491,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
private JLabel addLabelParameter(String description, Container contentPane) { private JLabel addLabelParameter(String description, Container contentPane) {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
JLabel label; JLabel label;
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.setAlignmentY(Component.TOP_ALIGNMENT);
panel.add(Box.createHorizontalStrut(10)); panel.add(Box.createHorizontalStrut(10));
@ -502,7 +503,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
return label; return label;
} }
/** /**
* Listens to settings changes in the channel model. * Listens to settings changes in the channel model.
* If it changes, all GUI parameters are updated accordingly. * 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) { public void update(Observable obs, Object obj) {
// Update all integers // Update all integers
for (int i=0; i < allIntegerParameters.size(); i++) { 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"); String id = (String) textField.getClientProperty("id");
textField.setValue(currentChannelModel.getParameterValue(id)); textField.setValue(currentChannelModel.getParameterValue(id));
} }
// Update all doubles // Update all doubles
for (int i=0; i < allDoubleParameters.size(); i++) { 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"); String id = (String) textField.getClientProperty("id");
textField.setValue(currentChannelModel.getParameterValue(id)); textField.setValue(currentChannelModel.getParameterValue(id));
} }
// Update all booleans // Update all booleans
for (int i=0; i < allBooleanParameters.size(); i++) { 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"); String id = (String) checkBox.getClientProperty("id");
checkBox.setSelected(currentChannelModel.getParameterBooleanValue(id)); checkBox.setSelected(currentChannelModel.getParameterBooleanValue(id));
} }
@ -533,7 +534,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
repaint(); repaint();
} }
}; };
public void closePlugin() { public void closePlugin() {
// Remove the channel model observer // Remove the channel model observer
if (currentChannelModel != null && channelModelSettingsObserver != null) { 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); logger.fatal("Can't remove channel model observer: " + channelModelSettingsObserver);
} }
} }
/** /**
* Returns XML elements representing the current configuration. * Returns XML elements representing the current configuration.
* *
* @see #setConfigXML(Collection) * @see #setConfigXML(Collection)
* @return XML element collection * @return XML element collection
*/ */
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
Vector<Element> config = new Vector<Element>(); Vector<Element> config = new Vector<Element>();
@ -573,7 +574,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
/** /**
* Sets the configuration depending on the given XML elements. * Sets the configuration depending on the given XML elements.
* *
* @see #getConfigXML() * @see #getConfigXML()
* @param configXML * @param configXML
* Config XML elements * Config XML elements
@ -608,7 +609,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
ActionEvent.ACTION_PERFORMED, "")); ActionEvent.ACTION_PERFORMED, ""));
} }
} }
return true; return true;
} }
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; 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) * This is the main class of the COOJA Multi-path Ray-tracing Medium (MRM)
* package. * package.
* *
* MRM is meant to be an alternative to the simpler radio mediums available in * 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 * COOJA. It is packet based and uses a 2D ray-tracing approach to approximate
* signal strength attenuations between simulated radios. Currently the * signal strength attenuations between simulated radios. Currently the
* ray-tracing only supports reflections and refractions through homogeneous * ray-tracing only supports reflections and refractions through homogeneous
* obstacles. * obstacles.
* *
* MRM provides a number of plugins for example a plugin for visualizing radio * MRM provides a number of plugins for example a plugin for visualizing radio
* environments, and a plugin for configuring the radio medium. * environments, and a plugin for configuring the radio medium.
* *
* Future work includes adding diffractions and scattering support. * Future work includes adding diffractions and scattering support.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ClassDescription("Multi-path Ray-tracer Medium (MRM)") @ClassDescription("Multi-path Ray-tracer Medium (MRM)")
@ -62,20 +62,20 @@ public class MRM extends AbstractRadioMedium {
private ChannelModel currentChannelModel = null; private ChannelModel currentChannelModel = null;
private Simulation mySimulation = null; private Simulation mySimulation = null;
private Random random = new Random(); private Random random = new Random();
/** /**
* Notifies observers when this radio medium has changed settings. * Notifies observers when this radio medium has changed settings.
*/ */
private SettingsObservable settingsObservable = new SettingsObservable(); private SettingsObservable settingsObservable = new SettingsObservable();
/** /**
* Creates a new Multi-path Ray-tracing Medium (MRM). * Creates a new Multi-path Ray-tracing Medium (MRM).
*/ */
public MRM(Simulation simulation) { public MRM(Simulation simulation) {
super(simulation); super(simulation);
// Create the channel model // Create the channel model
currentChannelModel = new ChannelModel(); currentChannelModel = new ChannelModel();
@ -91,20 +91,22 @@ public class MRM extends AbstractRadioMedium {
// Loop through all radios // Loop through all radios
for (Radio listeningRadio: getRegisteredRadios()) { for (Radio listeningRadio: getRegisteredRadios()) {
// Ignore sending radio and radios on different channels // Ignore sending radio and radios on different channels
if (sendingRadio == listeningRadio) if (sendingRadio == listeningRadio) {
continue; continue;
if (sendingRadio.getChannel() != listeningRadio.getChannel()) }
if (sendingRadio.getChannel() != listeningRadio.getChannel()) {
continue; continue;
}
double listeningPositionX = listeningRadio.getPosition().getXCoordinate(); double listeningPositionX = listeningRadio.getPosition().getXCoordinate();
double listeningPositionY = listeningRadio.getPosition().getYCoordinate(); double listeningPositionY = listeningRadio.getPosition().getYCoordinate();
// Calculate probability of reception of listening radio // Calculate probability of reception of listening radio
double[] probData = currentChannelModel.getProbability( double[] probData = currentChannelModel.getProbability(
sendingPosition.getXCoordinate(), sendingPosition.getXCoordinate(),
sendingPosition.getYCoordinate(), sendingPosition.getYCoordinate(),
listeningPositionX, listeningPositionX,
listeningPositionY, listeningPositionY,
-Double.MAX_VALUE -Double.MAX_VALUE
); );
@ -148,7 +150,7 @@ public class MRM extends AbstractRadioMedium {
// Interfere radio // Interfere radio
newConnection.addInterfered(listeningRadio, probData[1]); newConnection.addInterfered(listeningRadio, probData[1]);
listeningRadio.interfereAnyReception(); listeningRadio.interfereAnyReception();
// TODO Radios always get interfered right now, should recalculate probability // TODO Radios always get interfered right now, should recalculate probability
// if (maxInterferenceSignalStrength + SOME_RELEVANT_LIMIT > transmissionSignalStrength) { // if (maxInterferenceSignalStrength + SOME_RELEVANT_LIMIT > transmissionSignalStrength) {
// // Recalculating probability of delivery // // Recalculating probability of delivery
@ -166,7 +168,7 @@ public class MRM extends AbstractRadioMedium {
} }
} }
return newConnection; return newConnection;
} }
@ -188,8 +190,9 @@ public class MRM extends AbstractRadioMedium {
// ((MRMRadioConnection) conn).getSource().setCurrentSignalStrength(12345); // TODO Set signal strength on source? // ((MRMRadioConnection) conn).getSource().setCurrentSignalStrength(12345); // TODO Set signal strength on source?
for (Radio dstRadio : ((MRMRadioConnection) conn).getDestinations()) { for (Radio dstRadio : ((MRMRadioConnection) conn).getDestinations()) {
double signalStrength = ((MRMRadioConnection) conn).getDestinationSignalStrength(dstRadio); double signalStrength = ((MRMRadioConnection) conn).getDestinationSignalStrength(dstRadio);
if (signalStrength > dstRadio.getCurrentSignalStrength()) if (signalStrength > dstRadio.getCurrentSignalStrength()) {
dstRadio.setCurrentSignalStrength(signalStrength); dstRadio.setCurrentSignalStrength(signalStrength);
}
} }
} }
@ -197,8 +200,9 @@ public class MRM extends AbstractRadioMedium {
for (RadioConnection conn : getActiveConnections()) { for (RadioConnection conn : getActiveConnections()) {
for (Radio interferedRadio : ((MRMRadioConnection) conn).getInterfered()) { for (Radio interferedRadio : ((MRMRadioConnection) conn).getInterfered()) {
double signalStrength = ((MRMRadioConnection) conn).getInterferenceSignalStrength(interferedRadio); double signalStrength = ((MRMRadioConnection) conn).getInterferenceSignalStrength(interferedRadio);
if (signalStrength > interferedRadio.getCurrentSignalStrength()) if (signalStrength > interferedRadio.getCurrentSignalStrength()) {
interferedRadio.setCurrentSignalStrength(signalStrength); interferedRadio.setCurrentSignalStrength(signalStrength);
}
if (!interferedRadio.isInterfered()) { if (!interferedRadio.isInterfered()) {
// Set to interfered again // Set to interfered again
@ -226,20 +230,20 @@ public class MRM extends AbstractRadioMedium {
// Forwarding to current channel model // Forwarding to current channel model
return currentChannelModel.getConfigXML(); return currentChannelModel.getConfigXML();
} }
public boolean setConfigXML(Collection<Element> configXML, public boolean setConfigXML(Collection<Element> configXML,
boolean visAvailable) { boolean visAvailable) {
// Forwarding to current channel model // Forwarding to current channel model
return currentChannelModel.setConfigXML(configXML); return currentChannelModel.setConfigXML(configXML);
} }
// -- MRM specific methods -- // -- MRM specific methods --
/** /**
* Adds an observer which is notified when this radio medium has * Adds an observer which is notified when this radio medium has
* changed settings, such as added or removed radios. * changed settings, such as added or removed radios.
* *
* @param obs New observer * @param obs New observer
*/ */
public void addSettingsObserver(Observer obs) { public void addSettingsObserver(Observer obs) {
@ -248,24 +252,24 @@ public class MRM extends AbstractRadioMedium {
/** /**
* Deletes an earlier registered setting observer. * Deletes an earlier registered setting observer.
* *
* @param osb * @param osb
* Earlier registered observer * Earlier registered observer
*/ */
public void deleteSettingsObserver(Observer obs) { public void deleteSettingsObserver(Observer obs) {
settingsObservable.deleteObserver(obs); settingsObservable.deleteObserver(obs);
} }
/** /**
* Returns position of given radio. * Returns position of given radio.
* *
* @param radio Registered radio * @param radio Registered radio
* @return Position of given radio * @return Position of given radio
*/ */
public Position getRadioPosition(Radio radio) { public Position getRadioPosition(Radio radio) {
return radio.getPosition(); return radio.getPosition();
} }
/** /**
* @return Number of registered radios. * @return Number of registered radios.
*/ */
@ -275,7 +279,7 @@ public class MRM extends AbstractRadioMedium {
/** /**
* Returns radio at given index. * Returns radio at given index.
* *
* @param index Index of registered radio. * @param index Index of registered radio.
* @return Radio at given index * @return Radio at given index
*/ */
@ -286,7 +290,7 @@ public class MRM extends AbstractRadioMedium {
/** /**
* Returns the current channel model object, responsible for * Returns the current channel model object, responsible for
* all probability and transmission calculations. * all probability and transmission calculations.
* *
* @return Current channel model * @return Current channel model
*/ */
public ChannelModel getChannelModel() { public ChannelModel getChannelModel() {
@ -302,11 +306,11 @@ public class MRM extends AbstractRadioMedium {
class MRMRadioConnection extends RadioConnection { class MRMRadioConnection extends RadioConnection {
private Hashtable<Radio, Double> signalStrengths = new Hashtable<Radio, Double>(); private Hashtable<Radio, Double> signalStrengths = new Hashtable<Radio, Double>();
public MRMRadioConnection(Radio sourceRadio) { public MRMRadioConnection(Radio sourceRadio) {
super(sourceRadio); super(sourceRadio);
} }
public void addDestination(Radio radio, double signalStrength) { public void addDestination(Radio radio, double signalStrength) {
signalStrengths.put(radio, signalStrength); signalStrengths.put(radio, signalStrength);
addDestination(radio); addDestination(radio);
@ -325,5 +329,5 @@ public class MRM extends AbstractRadioMedium {
return signalStrengths.get(radio); return signalStrengths.get(radio);
} }
} }
} }