fixed possible null pointer exception
+ some formatting
This commit is contained in:
parent
d272b062f0
commit
7f25afcfe4
2 changed files with 149 additions and 95 deletions
|
@ -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: RadioLogger.java,v 1.9 2007/07/17 21:21:19 fros4943 Exp $
|
* $Id: RadioLogger.java,v 1.10 2007/08/21 13:28:52 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins;
|
package se.sics.cooja.plugins;
|
||||||
|
@ -52,7 +52,7 @@ import se.sics.cooja.interfaces.Radio;
|
||||||
* Radio logger listens to the simulation radio medium and lists all transmitted
|
* Radio logger listens to the simulation radio medium and lists all transmitted
|
||||||
* data in a table. By overriding the transformDataToString method, protocol
|
* data in a table. By overriding the transformDataToString method, protocol
|
||||||
* specific data can be interpreted.
|
* specific data can be interpreted.
|
||||||
*
|
*
|
||||||
* @see #transformDataToString(byte[])
|
* @see #transformDataToString(byte[])
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
|
@ -130,8 +130,9 @@ public class RadioLogger extends VisPlugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col == COLUMN_TO)
|
if (col == COLUMN_TO) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +146,9 @@ public class RadioLogger extends VisPlugin {
|
||||||
comboBox.addItemListener(new ItemListener() {
|
comboBox.addItemListener(new ItemListener() {
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
if (e.getItem() instanceof Mote)
|
if (e.getItem() instanceof Mote) {
|
||||||
gui.signalMoteHighlight((Mote) e.getItem());
|
gui.signalMoteHighlight((Mote) e.getItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -155,18 +157,20 @@ public class RadioLogger extends VisPlugin {
|
||||||
public TableCellEditor getCellEditor(int row, int column) {
|
public TableCellEditor getCellEditor(int row, int column) {
|
||||||
// Populate combo box
|
// Populate combo box
|
||||||
comboBox.removeAllItems();
|
comboBox.removeAllItems();
|
||||||
if (row < 0 || row >= rowData.size())
|
if (row < 0 || row >= rowData.size()) {
|
||||||
return super.getCellEditor(row, column);
|
return super.getCellEditor(row, column);
|
||||||
|
}
|
||||||
|
|
||||||
RadioConnection conn = (RadioConnection) rowData.get(row)[DATAPOS_CONNECTION];
|
RadioConnection conn = (RadioConnection) rowData.get(row)[DATAPOS_CONNECTION];
|
||||||
if (conn == null)
|
if (conn == null) {
|
||||||
return super.getCellEditor(row, column);
|
return super.getCellEditor(row, column);
|
||||||
|
}
|
||||||
|
|
||||||
for (Radio destRadio: conn.getDestinations()) {
|
for (Radio destRadio: conn.getDestinations()) {
|
||||||
if (destRadio.getMote() != null) {
|
if (destRadio.getMote() != null) {
|
||||||
comboBox.addItem(destRadio.getMote());
|
comboBox.addItem(destRadio.getMote());
|
||||||
} else {
|
} else {
|
||||||
comboBox.addItem("[standalone radio]");
|
comboBox.addItem("[standalone radio]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,8 +208,27 @@ public class RadioLogger extends VisPlugin {
|
||||||
dataTable.getSelectionModel().addListSelectionListener(
|
dataTable.getSelectionModel().addListSelectionListener(
|
||||||
new ListSelectionListener() {
|
new ListSelectionListener() {
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
gui.signalMoteHighlight(((RadioConnection) rowData.get(
|
int selectedRowIndex = dataTable.getSelectedRow();
|
||||||
dataTable.getSelectedRow())[DATAPOS_CONNECTION]).getSource().getMote());
|
if (selectedRowIndex < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] row = rowData.get(selectedRowIndex);
|
||||||
|
if (row == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RadioConnection conn = (RadioConnection) row[DATAPOS_CONNECTION];
|
||||||
|
if (conn == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mote mote = conn.getSource().getMote();
|
||||||
|
if (mote == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.signalMoteHighlight(mote);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -220,8 +243,9 @@ public class RadioLogger extends VisPlugin {
|
||||||
simulation.getRadioMedium().addRadioMediumObserver(radioMediumObserver = new Observer() {
|
simulation.getRadioMedium().addRadioMediumObserver(radioMediumObserver = new Observer() {
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
RadioConnection[] newConnections = radioMedium.getLastTickConnections();
|
RadioConnection[] newConnections = radioMedium.getLastTickConnections();
|
||||||
if (newConnections == null)
|
if (newConnections == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (RadioConnection newConnection: newConnections) {
|
for (RadioConnection newConnection: newConnections) {
|
||||||
Object[] data = new Object[3];
|
Object[] data = new Object[3];
|
||||||
|
@ -249,19 +273,21 @@ public class RadioLogger extends VisPlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform transmitted data to representable object, such as a string.
|
* Transform transmitted data to representable object, such as a string.
|
||||||
*
|
*
|
||||||
* @param data Transmitted data
|
* @param data Transmitted data
|
||||||
* @return Representable object
|
* @return Representable object
|
||||||
*/
|
*/
|
||||||
public Object transformDataToString(byte[] data) {
|
public Object transformDataToString(byte[] data) {
|
||||||
if (data == null)
|
if (data == null) {
|
||||||
return "[unknown data]";
|
return "[unknown data]";
|
||||||
|
}
|
||||||
|
|
||||||
Packet packet = analyzePacket(data);
|
Packet packet = analyzePacket(data);
|
||||||
if (packet == null)
|
if (packet == null) {
|
||||||
return "Unknown packet, size " + data.length;
|
return "Unknown packet, size " + data.length;
|
||||||
else
|
} else {
|
||||||
return packet.getShortDescription();
|
return packet.getShortDescription();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static abstract class Packet {
|
static abstract class Packet {
|
||||||
|
@ -297,7 +323,7 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID() {
|
public int getID() {
|
||||||
int id =
|
int id =
|
||||||
((data[4] & 0xFF) << 24) +
|
((data[4] & 0xFF) << 24) +
|
||||||
((data[5] & 0xFF) << 16) +
|
((data[5] & 0xFF) << 16) +
|
||||||
((data[6] & 0xFF) << 8) +
|
((data[6] & 0xFF) << 8) +
|
||||||
|
@ -306,11 +332,11 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDestAddr() {
|
public String getDestAddr() {
|
||||||
return (int) (0xff&data[8]) + "." + (int) (0xff&data[9]) + "." + (int) (0xff&data[10]) + "." + (int) (0xff&data[11]);
|
return (0xff&data[8]) + "." + (0xff&data[9]) + "." + (0xff&data[10]) + "." + (0xff&data[11]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDestSeqNo() {
|
public int getDestSeqNo() {
|
||||||
int seqNo =
|
int seqNo =
|
||||||
((data[12] & 0xFF) << 24) +
|
((data[12] & 0xFF) << 24) +
|
||||||
((data[13] & 0xFF) << 16) +
|
((data[13] & 0xFF) << 16) +
|
||||||
((data[14] & 0xFF) << 8) +
|
((data[14] & 0xFF) << 8) +
|
||||||
|
@ -319,11 +345,11 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOrigAddr() {
|
public String getOrigAddr() {
|
||||||
return (int) (0xff&data[16]) + "." + (int) (0xff&data[17]) + "." + (int) (0xff&data[18]) + "." + (int) (0xff&data[19]);
|
return (0xff&data[16]) + "." + (0xff&data[17]) + "." + (0xff&data[18]) + "." + (0xff&data[19]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOrigSeqNo() {
|
public int getOrigSeqNo() {
|
||||||
int seqNo =
|
int seqNo =
|
||||||
((data[20] & 0xFF) << 24) +
|
((data[20] & 0xFF) << 24) +
|
||||||
((data[21] & 0xFF) << 16) +
|
((data[21] & 0xFF) << 16) +
|
||||||
((data[22] & 0xFF) << 8) +
|
((data[22] & 0xFF) << 8) +
|
||||||
|
@ -350,14 +376,16 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dataFits(byte[] packetData) {
|
public static boolean dataFits(byte[] packetData) {
|
||||||
if (packetData.length != SIZE)
|
if (packetData.length != SIZE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
byte[] dataNoHeader = new byte[HEADER_SIZE];
|
byte[] dataNoHeader = new byte[HEADER_SIZE];
|
||||||
System.arraycopy(packetData, packetData.length - HEADER_SIZE, dataNoHeader, 0, HEADER_SIZE);
|
System.arraycopy(packetData, packetData.length - HEADER_SIZE, dataNoHeader, 0, HEADER_SIZE);
|
||||||
|
|
||||||
if (dataNoHeader[0] != TYPE)
|
if (dataNoHeader[0] != TYPE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -392,11 +420,11 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDestAddr() {
|
public String getDestAddr() {
|
||||||
return (int) (0xff&data[4]) + "." + (int) (0xff&data[5]) + "." + (int) (0xff&data[6]) + "." + (int) (0xff&data[7]);
|
return (0xff&data[4]) + "." + (0xff&data[5]) + "." + (0xff&data[6]) + "." + (0xff&data[7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDestSeqNo() {
|
public int getDestSeqNo() {
|
||||||
int seqNo =
|
int seqNo =
|
||||||
((data[8] & 0xFF) << 24) +
|
((data[8] & 0xFF) << 24) +
|
||||||
((data[9] & 0xFF) << 16) +
|
((data[9] & 0xFF) << 16) +
|
||||||
((data[10] & 0xFF) << 8) +
|
((data[10] & 0xFF) << 8) +
|
||||||
|
@ -405,11 +433,11 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOrigAddr() {
|
public String getOrigAddr() {
|
||||||
return (int) (0xff&data[12]) + "." + (int) (0xff&data[13]) + "." + (int) (0xff&data[14]) + "." + (int) (0xff&data[15]);
|
return (0xff&data[12]) + "." + (0xff&data[13]) + "." + (0xff&data[14]) + "." + (0xff&data[15]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLifetime() {
|
public int getLifetime() {
|
||||||
int seqNo =
|
int seqNo =
|
||||||
((data[16] & 0xFF) << 24) +
|
((data[16] & 0xFF) << 24) +
|
||||||
((data[17] & 0xFF) << 16) +
|
((data[17] & 0xFF) << 16) +
|
||||||
((data[18] & 0xFF) << 8) +
|
((data[18] & 0xFF) << 8) +
|
||||||
|
@ -423,7 +451,7 @@ public class RadioLogger extends VisPlugin {
|
||||||
|
|
||||||
public String getToolTip() {
|
public String getToolTip() {
|
||||||
return "<html>" +
|
return "<html>" +
|
||||||
"AODV RREP type: " + getType() + "<br>" +
|
"AODV RREP type: " + getType() + "<br>" +
|
||||||
"AODV RREP flags: " + getFlags() + "<br>" +
|
"AODV RREP flags: " + getFlags() + "<br>" +
|
||||||
"AODV RREP prefix: " + getPrefix() + "<br>" +
|
"AODV RREP prefix: " + getPrefix() + "<br>" +
|
||||||
"AODV RREP hop_count: " + getHopCount() + "<br>" +
|
"AODV RREP hop_count: " + getHopCount() + "<br>" +
|
||||||
|
@ -435,14 +463,16 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dataFits(byte[] packetData) {
|
public static boolean dataFits(byte[] packetData) {
|
||||||
if (packetData.length != SIZE)
|
if (packetData.length != SIZE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
byte[] dataNoHeader = new byte[HEADER_SIZE];
|
byte[] dataNoHeader = new byte[HEADER_SIZE];
|
||||||
System.arraycopy(packetData, packetData.length - HEADER_SIZE, dataNoHeader, 0, HEADER_SIZE);
|
System.arraycopy(packetData, packetData.length - HEADER_SIZE, dataNoHeader, 0, HEADER_SIZE);
|
||||||
|
|
||||||
if (dataNoHeader[0] != TYPE)
|
if (dataNoHeader[0] != TYPE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -476,11 +506,11 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUnreachAddr() {
|
public String getUnreachAddr() {
|
||||||
return (int) (0xff&data[4]) + "." + (int) (0xff&data[5]) + "." + (int) (0xff&data[6]) + "." + (int) (0xff&data[7]);
|
return (0xff&data[4]) + "." + (0xff&data[5]) + "." + (0xff&data[6]) + "." + (0xff&data[7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnreachSeqNo() {
|
public int getUnreachSeqNo() {
|
||||||
int seqNo =
|
int seqNo =
|
||||||
((data[8] & 0xFF) << 24) +
|
((data[8] & 0xFF) << 24) +
|
||||||
((data[9] & 0xFF) << 16) +
|
((data[9] & 0xFF) << 16) +
|
||||||
((data[10] & 0xFF) << 8) +
|
((data[10] & 0xFF) << 8) +
|
||||||
|
@ -494,7 +524,7 @@ public class RadioLogger extends VisPlugin {
|
||||||
|
|
||||||
public String getToolTip() {
|
public String getToolTip() {
|
||||||
return "<html>" +
|
return "<html>" +
|
||||||
"AODV RERR type: " + getType() + "<br>" +
|
"AODV RERR type: " + getType() + "<br>" +
|
||||||
"AODV RERR flags: " + getFlags() + "<br>" +
|
"AODV RERR flags: " + getFlags() + "<br>" +
|
||||||
"AODV RERR reserved: " + getReserved() + "<br>" +
|
"AODV RERR reserved: " + getReserved() + "<br>" +
|
||||||
"AODV RERR dest_count: " + getDestCount() + "<br>" +
|
"AODV RERR dest_count: " + getDestCount() + "<br>" +
|
||||||
|
@ -504,14 +534,16 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dataFits(byte[] packetData) {
|
public static boolean dataFits(byte[] packetData) {
|
||||||
if (packetData.length != SIZE)
|
if (packetData.length != SIZE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
byte[] dataNoHeader = new byte[HEADER_SIZE];
|
byte[] dataNoHeader = new byte[HEADER_SIZE];
|
||||||
System.arraycopy(packetData, packetData.length - HEADER_SIZE, dataNoHeader, 0, HEADER_SIZE);
|
System.arraycopy(packetData, packetData.length - HEADER_SIZE, dataNoHeader, 0, HEADER_SIZE);
|
||||||
|
|
||||||
if (dataNoHeader[0] != TYPE)
|
if (dataNoHeader[0] != TYPE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -526,7 +558,7 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChecksum() {
|
public int getChecksum() {
|
||||||
int checksum =
|
int checksum =
|
||||||
((data[3] & 0xFF) << 8) +
|
((data[3] & 0xFF) << 8) +
|
||||||
((data[4] & 0xFF) << 0);
|
((data[4] & 0xFF) << 0);
|
||||||
return checksum;
|
return checksum;
|
||||||
|
@ -538,27 +570,31 @@ public class RadioLogger extends VisPlugin {
|
||||||
|
|
||||||
public String getToolTip() {
|
public String getToolTip() {
|
||||||
return "<html>" +
|
return "<html>" +
|
||||||
"ACK checksum: " + getChecksum() + "<br>" +
|
"ACK checksum: " + getChecksum() + "<br>" +
|
||||||
"</html>";
|
"</html>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dataFits(byte[] packetData) {
|
public static boolean dataFits(byte[] packetData) {
|
||||||
if (packetData.length != SIZE)
|
if (packetData.length != SIZE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (packetData[0] != (byte) 'a')
|
if (packetData[0] != (byte) 'a') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (packetData[1] != (byte) 'C')
|
|
||||||
|
if (packetData[1] != (byte) 'C') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (packetData[2] != (byte) 'k')
|
|
||||||
|
if (packetData[2] != (byte) 'k') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static class ForwardedPacketUnknown extends PacketUnknown {
|
static class ForwardedPacketUnknown extends PacketUnknown {
|
||||||
public final static int MINIMUM_SIZE = 4;
|
public final static int MINIMUM_SIZE = 4;
|
||||||
|
|
||||||
|
@ -571,21 +607,26 @@ public class RadioLogger extends VisPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dataFits(byte[] packetData) {
|
public static boolean dataFits(byte[] packetData) {
|
||||||
if (packetData.length < ForwardedPacketUnknown.MINIMUM_SIZE)
|
if (packetData.length < ForwardedPacketUnknown.MINIMUM_SIZE) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (packetData[0] != (byte) 'f')
|
|
||||||
|
if (packetData[0] != (byte) 'f') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (packetData[1] != (byte) 'W')
|
|
||||||
|
if (packetData[1] != (byte) 'W') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (packetData[2] != (byte) 'd')
|
|
||||||
|
if (packetData[2] != (byte) 'd') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (packetData[3] != (byte) ':')
|
|
||||||
|
if (packetData[3] != (byte) ':') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -626,27 +667,33 @@ public class RadioLogger extends VisPlugin {
|
||||||
|
|
||||||
private Packet analyzePacket(byte[] data) {
|
private Packet analyzePacket(byte[] data) {
|
||||||
|
|
||||||
if (PacketAODV_RREQ.dataFits(data))
|
if (PacketAODV_RREQ.dataFits(data)) {
|
||||||
return new PacketAODV_RREQ(data);
|
return new PacketAODV_RREQ(data);
|
||||||
|
}
|
||||||
|
|
||||||
if (PacketAODV_RREP.dataFits(data))
|
if (PacketAODV_RREP.dataFits(data)) {
|
||||||
return new PacketAODV_RREP(data);
|
return new PacketAODV_RREP(data);
|
||||||
|
}
|
||||||
|
|
||||||
if (PacketAODV_RERR.dataFits(data))
|
if (PacketAODV_RERR.dataFits(data)) {
|
||||||
return new PacketAODV_RERR(data);
|
return new PacketAODV_RERR(data);
|
||||||
|
}
|
||||||
|
|
||||||
if (ForwardedPacketUnknown.dataFits(data))
|
if (ForwardedPacketUnknown.dataFits(data)) {
|
||||||
return new ForwardedPacketUnknown(data);
|
return new ForwardedPacketUnknown(data);
|
||||||
|
}
|
||||||
|
|
||||||
if (AckPacket.dataFits(data))
|
if (AckPacket.dataFits(data)) {
|
||||||
return new AckPacket(data);
|
return new AckPacket(data);
|
||||||
|
}
|
||||||
|
|
||||||
return new PacketUnknown(data);
|
return new PacketUnknown(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
if (radioMediumObserver != null)
|
if (radioMediumObserver != null) {
|
||||||
radioMedium.deleteRadioMediumObserver(radioMediumObserver);
|
radioMedium.deleteRadioMediumObserver(radioMediumObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Element> getConfigXML() {
|
public Collection<Element> getConfigXML() {
|
||||||
|
|
|
@ -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: UDGM.java,v 1.7 2007/08/21 09:17:18 fros4943 Exp $
|
* $Id: UDGM.java,v 1.8 2007/08/21 13:31:26 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.radiomediums;
|
package se.sics.cooja.radiomediums;
|
||||||
|
@ -46,26 +46,23 @@ import se.sics.cooja.plugins.Visualizer2D;
|
||||||
/**
|
/**
|
||||||
* The Unit Disk Graph medium has two different range parameters; one for
|
* The Unit Disk Graph medium has two different range parameters; one for
|
||||||
* transmitting and one for interfering other transmissions.
|
* transmitting and one for interfering other transmissions.
|
||||||
*
|
*
|
||||||
* The radio medium supports both byte and packet radios.
|
* The radio medium supports both byte and packet radios.
|
||||||
*
|
*
|
||||||
* TODO Any transmitted bytes are forwarded immediately with a timestamp
|
|
||||||
* (more fine-grained than ticks).
|
|
||||||
*
|
|
||||||
* The radio medium registers a visualizer plugin. Via this plugin the current
|
* The radio medium registers a visualizer plugin. Via this plugin the current
|
||||||
* radio states and range parameters can be viewed and changed.
|
* radio states and range parameters can be viewed and changed.
|
||||||
*
|
*
|
||||||
* The registered radios' signal strengths are updated whenever the radio medium
|
* The registered radios' signal strengths are updated whenever the radio medium
|
||||||
* changes. There are three fixed levels: no surrounding traffic heard, noise
|
* changes. There are three fixed levels: no surrounding traffic heard, noise
|
||||||
* heard and data heard.
|
* heard and data heard.
|
||||||
*
|
*
|
||||||
* The radio output power indicator (0-100) is used in a very simple way; the
|
* The radio output power indicator (0-100) is used in a very simple way; the
|
||||||
* total transmission (and interfering) range is multiplied with [power_ind]%.
|
* total transmission (and interfering) range is multiplied with [power_ind]%.
|
||||||
*
|
*
|
||||||
* @see #SS_OK
|
* @see #SS_OK
|
||||||
* @see #SS_NOISE
|
* @see #SS_NOISE
|
||||||
* @see #SS_NOTHING
|
* @see #SS_NOTHING
|
||||||
*
|
*
|
||||||
* @see VisUDGM
|
* @see VisUDGM
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
|
@ -91,20 +88,20 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
private static double INTERFERENCE_RANGE = 100;
|
private static double INTERFERENCE_RANGE = 100;
|
||||||
|
|
||||||
private Simulation mySimulation;
|
private Simulation mySimulation;
|
||||||
|
|
||||||
private boolean usingRandom = false;
|
private boolean usingRandom = false;
|
||||||
|
|
||||||
private Random random = new Random();
|
private Random random = new Random();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visualizes radio traffic in the UDGM. Allows a user to
|
* Visualizes radio traffic in the UDGM. Allows a user to
|
||||||
* change transmission ranges.
|
* change transmission ranges.
|
||||||
*
|
*
|
||||||
* Sending motes are blue, receiving motes are green and motes that hear noise
|
* Sending motes are blue, receiving motes are green and motes that hear noise
|
||||||
* are painted red. Motes without radios are painted gray, and the rest are
|
* are painted red. Motes without radios are painted gray, and the rest are
|
||||||
* white.
|
* white.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("UDGM Visualizer")
|
@ClassDescription("UDGM Visualizer")
|
||||||
|
@ -182,8 +179,8 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
successRatioSpinner = new JSpinner(successRatioModel);
|
successRatioSpinner = new JSpinner(successRatioModel);
|
||||||
editor = new JSpinner.NumberEditor(successRatioSpinner, "0%");
|
editor = new JSpinner.NumberEditor(successRatioSpinner, "0%");
|
||||||
successRatioSpinner.setEditor(editor);
|
successRatioSpinner.setEditor(editor);
|
||||||
|
|
||||||
|
|
||||||
((JSpinner.DefaultEditor) transmissionSpinner.getEditor()).getTextField()
|
((JSpinner.DefaultEditor) transmissionSpinner.getEditor()).getTextField()
|
||||||
.setColumns(5);
|
.setColumns(5);
|
||||||
((JSpinner.DefaultEditor) interferenceSpinner.getEditor()).getTextField()
|
((JSpinner.DefaultEditor) interferenceSpinner.getEditor()).getTextField()
|
||||||
|
@ -253,10 +250,11 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
// Select one of the clicked motes
|
// Select one of the clicked motes
|
||||||
if (clickedMotes.contains(selectedMote)) {
|
if (clickedMotes.contains(selectedMote)) {
|
||||||
int pos = clickedMotes.indexOf(selectedMote);
|
int pos = clickedMotes.indexOf(selectedMote);
|
||||||
if (pos < clickedMotes.size() - 1)
|
if (pos < clickedMotes.size() - 1) {
|
||||||
selectedMote = clickedMotes.get(pos + 1);
|
selectedMote = clickedMotes.get(pos + 1);
|
||||||
else
|
} else {
|
||||||
selectedMote = clickedMotes.firstElement();
|
selectedMote = clickedMotes.firstElement();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
selectedMote = clickedMotes.firstElement();
|
selectedMote = clickedMotes.firstElement();
|
||||||
}
|
}
|
||||||
|
@ -270,7 +268,7 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
// Register change ranges and change success ratio action
|
// Register change ranges and change success ratio action
|
||||||
addMoteMenuAction(new ChangeRangesMenuAction());
|
addMoteMenuAction(new ChangeRangesMenuAction());
|
||||||
addMoteMenuAction(new ChangeSuccessRadioMenuAction());
|
addMoteMenuAction(new ChangeSuccessRadioMenuAction());
|
||||||
|
|
||||||
// Observe our own radio medium
|
// Observe our own radio medium
|
||||||
myRadioMedium
|
myRadioMedium
|
||||||
.addRadioMediumObserver(radioMediumObserver = new Observer() {
|
.addRadioMediumObserver(radioMediumObserver = new Observer() {
|
||||||
|
@ -289,23 +287,29 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
|
|
||||||
public Color[] getColorOf(Mote mote) {
|
public Color[] getColorOf(Mote mote) {
|
||||||
Radio moteRadio = mote.getInterfaces().getRadio();
|
Radio moteRadio = mote.getInterfaces().getRadio();
|
||||||
if (moteRadio == null)
|
if (moteRadio == null) {
|
||||||
return new Color[] { Color.GRAY };
|
return new Color[] { Color.GRAY };
|
||||||
|
}
|
||||||
|
|
||||||
if (mote.getState() == Mote.State.DEAD)
|
if (mote.getState() == Mote.State.DEAD) {
|
||||||
return new Color[] { Color.GRAY };
|
return new Color[] { Color.GRAY };
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedMote != null && mote == selectedMote)
|
if (selectedMote != null && mote == selectedMote) {
|
||||||
return new Color[] { Color.CYAN };
|
return new Color[] { Color.CYAN };
|
||||||
|
}
|
||||||
|
|
||||||
if (moteRadio.isTransmitting())
|
if (moteRadio.isTransmitting()) {
|
||||||
return new Color[] { Color.BLUE };
|
return new Color[] { Color.BLUE };
|
||||||
|
}
|
||||||
|
|
||||||
if (moteRadio.isInterfered())
|
if (moteRadio.isInterfered()) {
|
||||||
return new Color[] { Color.RED };
|
return new Color[] { Color.RED };
|
||||||
|
}
|
||||||
|
|
||||||
if (moteRadio.isReceiving())
|
if (moteRadio.isReceiving()) {
|
||||||
return new Color[] { Color.GREEN };
|
return new Color[] { Color.GREEN };
|
||||||
|
}
|
||||||
|
|
||||||
return new Color[] { Color.WHITE };
|
return new Color[] { Color.WHITE };
|
||||||
}
|
}
|
||||||
|
@ -323,10 +327,10 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
// Fetch current output power indicator (scale with as percent)
|
// Fetch current output power indicator (scale with as percent)
|
||||||
if (selectedMote.getInterfaces().getRadio() != null) {
|
if (selectedMote.getInterfaces().getRadio() != null) {
|
||||||
double moteInterferenceRange = INTERFERENCE_RANGE
|
double moteInterferenceRange = INTERFERENCE_RANGE
|
||||||
* (0.01 * (double) selectedMote.getInterfaces().getRadio()
|
* (0.01 * selectedMote.getInterfaces().getRadio()
|
||||||
.getCurrentOutputPowerIndicator());
|
.getCurrentOutputPowerIndicator());
|
||||||
double moteTransmissionRange = TRANSMITTING_RANGE
|
double moteTransmissionRange = TRANSMITTING_RANGE
|
||||||
* (0.01 * (double) selectedMote.getInterfaces().getRadio()
|
* (0.01 * selectedMote.getInterfaces().getRadio()
|
||||||
.getCurrentOutputPowerIndicator());
|
.getCurrentOutputPowerIndicator());
|
||||||
|
|
||||||
Point translatedZero = transformPositionToPixel(0.0, 0.0, 0.0);
|
Point translatedZero = transformPositionToPixel(0.0, 0.0, 0.0);
|
||||||
|
@ -362,9 +366,10 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
super.visualizeSimulation(g);
|
super.visualizeSimulation(g);
|
||||||
|
|
||||||
// Paint just finished connections
|
// Paint just finished connections
|
||||||
|
RadioConnection[] conns;
|
||||||
if (myRadioMedium != null
|
if (myRadioMedium != null
|
||||||
&& myRadioMedium.getLastTickConnections() != null) {
|
&& (conns = myRadioMedium.getLastTickConnections()) != null) {
|
||||||
for (RadioConnection conn : myRadioMedium.getLastTickConnections()) {
|
for (RadioConnection conn : conns) {
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
Point sourcePoint = transformPositionToPixel(conn.getSource()
|
Point sourcePoint = transformPositionToPixel(conn.getSource()
|
||||||
.getPosition());
|
.getPosition());
|
||||||
|
@ -388,7 +393,7 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
|
|
||||||
public UDGM(Simulation simulation) {
|
public UDGM(Simulation simulation) {
|
||||||
super(simulation);
|
super(simulation);
|
||||||
|
|
||||||
// Register this radio medium's plugins
|
// Register this radio medium's plugins
|
||||||
simulation.getGUI().registerTemporaryPlugin(VisUDGM.class);
|
simulation.getGUI().registerTemporaryPlugin(VisUDGM.class);
|
||||||
|
|
||||||
|
@ -405,25 +410,27 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
|
|
||||||
// Fetch current output power indicator (scale with as percent)
|
// Fetch current output power indicator (scale with as percent)
|
||||||
double moteTransmissionRange = TRANSMITTING_RANGE
|
double moteTransmissionRange = TRANSMITTING_RANGE
|
||||||
* (0.01 * (double) sendingRadio.getCurrentOutputPowerIndicator());
|
* (0.01 * sendingRadio.getCurrentOutputPowerIndicator());
|
||||||
double moteInterferenceRange = INTERFERENCE_RANGE
|
double moteInterferenceRange = INTERFERENCE_RANGE
|
||||||
* (0.01 * (double) sendingRadio.getCurrentOutputPowerIndicator());
|
* (0.01 * sendingRadio.getCurrentOutputPowerIndicator());
|
||||||
|
|
||||||
// If in random state, check if transmission fails
|
// If in random state, check if transmission fails
|
||||||
if (usingRandom && random.nextDouble() > PACKET_SUCCESS_RATIO) {
|
if (usingRandom && random.nextDouble() > PACKET_SUCCESS_RATIO) {
|
||||||
return newConnection;
|
return newConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through all radios
|
// Loop through all radios
|
||||||
for (int listenNr = 0; listenNr < getRegisteredRadios().size(); listenNr++) {
|
for (int listenNr = 0; listenNr < getRegisteredRadios().size(); listenNr++) {
|
||||||
Radio listeningRadio = getRegisteredRadios().get(listenNr);
|
Radio listeningRadio = getRegisteredRadios().get(listenNr);
|
||||||
Position listeningRadioPosition = listeningRadio.getPosition();
|
Position listeningRadioPosition = listeningRadio.getPosition();
|
||||||
|
|
||||||
// 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 distance = sendingPosition.getDistanceTo(listeningRadioPosition);
|
double distance = sendingPosition.getDistanceTo(listeningRadioPosition);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue