example directional antenna

This commit is contained in:
Fredrik Osterlind 2011-11-01 11:39:31 +01:00
parent eb84fbeb79
commit ff42490e7b

View file

@ -34,6 +34,8 @@ package se.sics.cooja.interfaces;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Observable;
@ -42,6 +44,7 @@ import java.util.Observer;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
@ -62,7 +65,7 @@ import se.sics.cooja.Simulation;
*
* @author Fredrik Osterlind
*/
public class ApplicationRadio extends Radio implements NoiseSourceRadio {
public class ApplicationRadio extends Radio implements NoiseSourceRadio, DirectionalAntennaRadio {
private static Logger logger = Logger.getLogger(ApplicationRadio.class);
private Simulation simulation;
@ -82,7 +85,7 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio {
private double signalStrength = -100;
private int radioChannel = -1;
private double outputPower = 0;
private double outputPower = 0; /* typical cc2420 values: -25 <-> 0 dBm */
private int outputPowerIndicator = 100;
private int interfered;
@ -264,7 +267,7 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio {
/**
* @param p New output power
*/
public void setOutputPower(int p) {
public void setOutputPower(double p) {
outputPower = p;
}
@ -286,6 +289,7 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio {
final JLabel statusLabel = new JLabel("");
final JLabel lastEventLabel = new JLabel("");
final JLabel channelLabel = new JLabel("");
final JLabel powerLabel = new JLabel("Output power (dBm):");
final JLabel ssLabel = new JLabel("");
final JButton updateButton = new JButton("Update SS");
@ -311,6 +315,12 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio {
} else {
channelMenu.setSelectedIndex(getChannel());
}
final JFormattedTextField outputPower = new JFormattedTextField(new Double(getCurrentOutputPower()));
outputPower.addPropertyChangeListener("value", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
setOutputPower(((Number)outputPower.getValue()).doubleValue());
}
});
box.add(statusLabel);
box.add(lastEventLabel);
@ -318,6 +328,8 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio {
box.add(updateButton);
box.add(channelLabel);
box.add(channelMenu);
box.add(powerLabel);
box.add(outputPower);
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@ -357,6 +369,7 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio {
public Collection<Element> getConfigXML() {
/* TODO Save channel info? */
/* TODO Save output power? */
return null;
}
@ -404,5 +417,16 @@ public class ApplicationRadio extends Radio implements NoiseSourceRadio {
}
}
public double getDirection() {
return 0;
}
public double getRelativeGain(double radians, double distance) {
/* Simple sinus-based gain */
return 5.0*Math.sin(5.0*radians)/(0.01*distance);
}
public void addDirectionChangeListener(DirectionChangeListener l) {
}
public void removeDirectionChangeListener(DirectionChangeListener l) {
}
}