📄 channelmodel.java
字号:
/* * Copyright (c) 2006, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Institute nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: ChannelModel.java,v 1.3 2007/03/23 21:13:43 fros4943 Exp $ */package se.sics.mrm;import java.awt.geom.*;import java.util.*;import javax.swing.tree.DefaultMutableTreeNode;import org.apache.log4j.Logger;import org.jdom.Element;import statistics.GaussianWrapper;/** * The channel model object in MRM is responsible for calulating propagation * impact on packets being sent in the radio medium. * * By registering as a settings observer on this channel model, other parts will * be notified if the settings change. * * TODO Add better support for different signal strengths * * @author Fredrik Osterlind */public class ChannelModel { private static Logger logger = Logger.getLogger(ChannelModel.class); enum TransmissionData { SIGNAL_STRENGTH, SIGNAL_STRENGTH_VAR, SNR, SNR_VAR, PROB_OF_RECEPTION, DELAY_SPREAD, DELAY_SPREAD_RMS} private Properties parameters = new Properties(); private Properties parameterDescriptions = new Properties(); // Parameters used for speeding up calculations private boolean needToPrecalculateFSPL = true; private static double paramFSPL = 0; private boolean needToPrecalculateOutputPower = true; private static double paramOutputPower = 0; private ObstacleWorld myObstacleWorld = new ObstacleWorld(); // Ray tracing components temporary vector private boolean inLoggingMode = false; private Vector<Line2D> savedRays = null; private Vector<Vector<Line2D>> calculatedVisibleSides = new Vector<Vector<Line2D>>(); private Vector<Point2D> calculatedVisibleSidesSources = new Vector<Point2D>(); private Vector<Line2D> calculatedVisibleSidesLines = new Vector<Line2D>(); private Vector<AngleInterval> calculatedVisibleSidesAngleIntervals = new Vector<AngleInterval>(); private static int maxSavedVisibleSides = 30; // Max size of lists above /** * Notifies observers when this channel model has changed settings. */ private class SettingsObservable extends Observable { private void notifySettingsChanged() { setChanged(); notifyObservers(); } } private SettingsObservable settingsObservable = new SettingsObservable(); // A random number generator private Random random = new Random(); public ChannelModel() { // - Set initial parameter values - // Using random variables parameters.put("apply_random", new Boolean(false)); // TODO Should not use random variables as default parameterDescriptions.put("apply_random", "Apply random values immediately"); // Signal to noise reception threshold parameters.put("snr_threshold", new Double(6)); parameterDescriptions.put("snr_threshold", "SNR reception threshold (dB)"); // Background noise mean parameters.put("bg_noise_mean", new Double(-150)); parameterDescriptions.put("bg_noise_mean", "Background noise mean (dBm)"); // Background noise variance parameters.put("bg_noise_var", new Double(1)); parameterDescriptions.put("bg_noise_var", "Background noise variance (dB)"); // Extra system gain mean parameters.put("system_gain_mean", new Double(0)); parameterDescriptions.put("system_gain_mean", "Extra system gain mean (dB)"); // Extra system gain variance parameters.put("system_gain_var", new Double(4)); // TODO Should probably be default 0 or 1 parameterDescriptions.put("system_gain_var", "Extra system gain variance (dB)"); // Transmission wavelength parameters.put("wavelength", new Double(0.346)); // ~868 MHz (RFM TR1001) parameterDescriptions.put("wavelength", "Wavelength w (m)"); // Transmitter output power parameters.put("tx_power", new Double(1.5)); // dBm (deciBel milliwatts) parameterDescriptions.put("tx_power", "Transmitter output power (dBm)"); // Transmitter antenna gain parameters.put("tx_antenna_gain", new Double(0)); // TODO Should use angle parameterDescriptions.put("tx_antenna_gain", "Transmitter antenna gain (dB)"); // Receiver sensitivity parameters.put("rx_sensitivity", new Double(-100)); parameterDescriptions.put("rx_sensitivity", "Receiver sensitivity (dBm)"); // Receiver antenna gain parameters.put("rx_antenna_gain", new Double(0)); // TODO Should use angle parameterDescriptions.put("rx_antenna_gain", "Receiver antenna gain (dB)"); // Ray Tracer - Disallow direct path parameters.put("rt_disallow_direct_path", new Boolean(false)); parameterDescriptions.put("rt_disallow_direct_path", "Disallow direct path"); // Ray Tracer - If direct path exists, ignore the non-direct (used for debugging) parameters.put("rt_ignore_non_direct", new Boolean(false)); parameterDescriptions.put("rt_ignore_non_direct", "If existing, only use direct path"); // Ray Tracer - Use FSPL on total length only parameters.put("rt_fspl_on_total_length", new Boolean(true)); parameterDescriptions.put("rt_fspl_on_total_length", "Use FSPL on total path lengths only"); // Ray Tracer - Max number of subrays parameters.put("rt_max_rays", new Integer(1)); parameterDescriptions.put("rt_max_rays", "Max path rays"); // Ray Tracer - Max number of refractions parameters.put("rt_max_refractions", new Integer(1)); parameterDescriptions.put("rt_max_refractions", "Max refractions"); // Ray Tracer - Max number of reflections parameters.put("rt_max_reflections", new Integer(1)); parameterDescriptions.put("rt_max_reflections", "Max reflections"); // Ray Tracer - Max number of diffractions parameters.put("rt_max_diffractions", new Integer(0)); parameterDescriptions.put("rt_max_diffractions", "Max diffractions"); // Ray Tracer - Use scattering //parameters.put("rt_use_scattering", new Boolean(false)); // TODO Not used yet //parameterDescriptions.put("rt_use_scattering", "Use simple scattering"); // Ray Tracer - Refraction coefficient parameters.put("rt_refrac_coefficient", new Double(-3)); parameterDescriptions.put("rt_refrac_coefficient", "Refraction coefficient (dB)"); // Ray Tracer - Reflection coefficient parameters.put("rt_reflec_coefficient", new Double(-5)); parameterDescriptions.put("rt_reflec_coefficient", "Reflection coefficient (dB)"); // Ray Tracer - Diffraction coefficient parameters.put("rt_diffr_coefficient", new Double(-10)); parameterDescriptions.put("rt_diffr_coefficient", "Diffraction coefficient (dB)"); // Ray Tracer - Scattering coefficient //parameters.put("rt_scatt_coefficient", new Double(-20)); // TODO Not used yet //parameterDescriptions.put("rt_scatt_coefficient", "!! Scattering coefficient (dB)"); // Shadowing - Obstacle Attenuation constant parameters.put("obstacle_attenuation", new Double(-3)); parameterDescriptions.put("obstacle_attenuation", "Obstacle attenuation (dB/m)"); } /** * Adds a settings observer to this channel model. * Every time the settings are changed all observers * will be notified. * * @param obs New observer */ public void addSettingsObserver(Observer obs) { settingsObservable.addObserver(obs); } /** * Deletes an earlier registered setting observer. * * @param osb * Earlier registered observer */ public void deleteSettingsObserver(Observer obs) { settingsObservable.deleteObserver(obs); } /** * Remove all previously registered obstacles */ public void removeAllObstacles() { myObstacleWorld.removeAll(); settingsObservable.notifySettingsChanged(); } /** * Add new obstacle with a rectangle shape. * Notifies observers of the new obstacle. * * @param startX Low X coordinate * @param startY Low Y coordinate * @param width Width of obstacle * @param height Height of obstacle */ public void addRectObstacle(double startX, double startY, double width, double height) { addRectObstacle(startX, startY, width, height, true); } /** * Add new obstacle with a rectangle shape. * Notifies observers depending on given notify argument. * * @param startX Low X coordinate * @param startY Low Y coordinate * @param width Width of obstacle * @param height Height of obstacle * @param notify If true, notifies all observers of this new obstacle */ public void addRectObstacle(double startX, double startY, double width, double height, boolean notify) { myObstacleWorld.addObstacle(startX, startY, width, height); if (notify) settingsObservable.notifySettingsChanged(); } /** * @return Number of registered obstacles */ public int getNumberOfObstacles() { return myObstacleWorld.getNrObstacles(); } /** * Returns an obstacle at given position * @param i Obstacle position * @return Obstacle */ public Rectangle2D getObstacle(int i) { return myObstacleWorld.getObstacle(i); } /** * Returns a parameter value * * @param identifier Parameter identifier * @return Current parameter value */ public Object getParameterValue(String id) { Object value = parameters.get(id); if (value == null) { logger.fatal("No parameter with id:" + id + ", aborting"); return null; } return value; } /** * Returns a double parameter value * * @param identifier Parameter identifier * @return Current parameter value */ public double getParameterDoubleValue(String id) { return ((Double) getParameterValue(id)).doubleValue(); } /** * Returns an integer parameter value * * @param identifier Parameter identifier * @return Current parameter value */ public int getParameterIntegerValue(String id) { return ((Integer) getParameterValue(id)).intValue(); } /** * Returns a boolean parameter value * * @param identifier Parameter identifier * @return Current parameter value */ public boolean getParameterBooleanValue(String id) { return ((Boolean) getParameterValue(id)).booleanValue(); } /** * Saves a new parameter value * * @param id Parameter identifier * @param newValue New parameter value */ public void setParameterValue(String id, Object newValue) { if (!parameters.containsKey(id)) { logger.fatal("No parameter with id:" + id + ", aborting"); return; } parameters.put(id, newValue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -