Commit 9d5430ce authored by Russ Fish's avatar Russ Fish

Generalize a little bit for Wifi nodes as well as Motes.

parent 0c278fe7
mote101 350 708 0.2
mote102 95 352 0.2
mote103 195 157 0.2
mote104 383 34 0.2
mote105 706 96 0.2
mote106 874 97 0.2
mote107 597 402 0.2
mote108 365 399 0.2
mote109 350 550 0.2
mote111 437 129 2.3
mote112 102 339 2.3
mote113 119 526 2.3
mote114 123 708 2.3
mote115 268 710 2.3
mote116 265 527 2.3
mote117 255 337 2.3
mote119 731 127 2.3
mote120 736 301 2.3
mote121 437 301 2.3
mote122 582 301 2.3
mote123 253 162 2.3
mote124 584 129 2.3
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -20,7 +20,7 @@ public class ILEStats implements WirelessData {
return null;
}
private static ILEStats parseReader(BufferedReader br) throws Exception {
private static ILEStats parseReader(BufferedReader br, String nodeType) throws Exception {
Hashtable stats = new Hashtable();
Vector moteNames = new Vector();
//Vector moteIDs = new Vector();
......@@ -37,7 +37,7 @@ public class ILEStats implements WirelessData {
while ((line = br.readLine()) != null) {
++linecount;
// parse line: "added phs for mote id 102"
Pattern mote = Pattern.compile("added phs for mote id (\\d+)");
Pattern mote = Pattern.compile("added phs for "+nodeType+" id (\\d+)");
Matcher moteM = mote.matcher(line);
// parse line: "Data for power level 0x2"
Pattern power = Pattern.compile("Data for power level 0x" +
......@@ -56,8 +56,10 @@ public class ILEStats implements WirelessData {
if (moteM.matches()) {
Integer i = new Integer(Integer.parseInt(moteM.group(1)));
//moteIDs.add(i);
if (!moteNames.contains("mote"+moteM.group(1))) {
moteNames.add("mote"+moteM.group(1));
String id = new String(nodeType+moteM.group(1));
if (!moteNames.contains(id)) {
moteNames.add(id);
System.out.println("node " + id);
}
}
else if (powerM.matches()) {
......@@ -84,8 +86,8 @@ public class ILEStats implements WirelessData {
// maxRSSI+","+avgRSSI+","+stddevRSSI+")");
Hashtable r = null;
String rNode = "mote"+recv;
String sNode = "mote"+send;
String rNode = nodeType+recv;
String sNode = nodeType+send;
if ((r = (Hashtable)(pLHash.get(rNode))) == null) {
r = new Hashtable();
......@@ -101,7 +103,9 @@ public class ILEStats implements WirelessData {
}
}
if (pLHash != null) {
stats.put(new Integer(powerLevel),pLHash); // The last one.
}
}
catch (IOException e) {
throw new Exception("file read failed");
......@@ -112,16 +116,16 @@ public class ILEStats implements WirelessData {
return new ILEStats(moteNames,stats);
}
static ILEStats parseInputStream(InputStream is)
static ILEStats parseInputStream(InputStream is, String nodeType)
throws java.io.IOException, Exception {
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(is));
return parseReader(br);
return parseReader(br, nodeType);
}
static ILEStats parseDumpFile(String filename)
static ILEStats parseDumpFile(String filename, String nodeType)
throws java.io.IOException, java.text.ParseException,
java.lang.IllegalArgumentException, Exception {
File f = null;
......@@ -142,7 +146,7 @@ public class ILEStats implements WirelessData {
try {
br = new BufferedReader(new FileReader(f));
retval = parseReader(br);
retval = parseReader(br, nodeType);
}
catch (Exception ex) {
ex.printStackTrace();
......@@ -303,7 +307,7 @@ public class ILEStats implements WirelessData {
public static void main(String args[]) throws Exception {
parseDumpFile(args[0]);
parseDumpFile(args[0], args[1]);
}
// old accessor methods...
......
......@@ -29,7 +29,7 @@ public class MoteLinkViewer extends javax.swing.JFrame {
}
};
bgImage = Toolkit.getDefaultToolkit().getImage("/home/david/work/java/floormap.jpg");
bgImage = Toolkit.getDefaultToolkit().getImage("../floormap.jpg");
mapImages.put("Floor4/WSN",bgImage);
try {
......@@ -50,8 +50,8 @@ public class MoteLinkViewer extends javax.swing.JFrame {
String defaultDatasetName = "Floor4/WSN";
try {
defaultData = ILEStats.parseDumpFile("/home/david/work/java/nn_client.log");
defaultPositions = NodePositions.parseFile("/home/david/work/java/mote_positions");
defaultData = ILEStats.parseDumpFile("../nn_client.log", "mote");
defaultPositions = NodePositions.parseFile("../mote_positions");
defaultModel = new MapDataModel(defaultData,defaultPositions);
datasets.put(defaultDatasetName,defaultModel);
......
......@@ -167,7 +167,7 @@ public class NodeMapPanel extends javax.swing.JPanel implements ChangeListener {
widgets.add(e1.nextElement());
++count;
}
System.out.println("added "+count+" links!");
//System.out.println("added "+count+" links!");
}
// widgets.add(new LinkWidget((NodeWidget)nodeWidgets.get("mote111"),
......@@ -258,7 +258,7 @@ public class NodeMapPanel extends javax.swing.JPanel implements ChangeListener {
if (bgImage != null) {
g2.setColor(java.awt.Color.WHITE);
g2.fillRect(0, 0, getWidth(), getHeight());
System.out.println("tried to draw bg!");
//System.out.println("tried to draw bg!");
g2.drawImage(bgImage,0,0,java.awt.Color.WHITE,null);
......@@ -267,14 +267,14 @@ public class NodeMapPanel extends javax.swing.JPanel implements ChangeListener {
// for the mote stuff, we could draw the obstacles and labels
// ourselves, but that wouldn't help for the wireless stuff...
// Composite old = g2.getComposite();
// AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.5f);
// g2.setComposite(ac);
//
// g2.setColor(java.awt.Color.WHITE);
// g2.fillRect(0,0,getWidth(),getHeight());
//
// g2.setComposite(old);
Composite old = g2.getComposite();
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.25f);
g2.setComposite(ac);
g2.setColor(java.awt.Color.WHITE);
g2.fillRect(0,0,getWidth(),getHeight());
g2.setComposite(old);
}
else {
......@@ -306,21 +306,24 @@ public class NodeMapPanel extends javax.swing.JPanel implements ChangeListener {
g2.dispose(); //clean up
}
public void setBackgroundImage(Image bgImage) {
public void setBackgroundImage(final Image bgImage) {
this.bgImage = bgImage;
java.awt.image.ImageObserver io = new java.awt.Component() {
public boolean updateImage(Image img, int infoflags, int x, int y, int width, int height) {
System.out.println("w = "+width+",h = "+height);
public boolean updateImage(Image img, int infoflags,
int x, int y, int width, int height) {
System.out.println("ImageObserver w = "+width+", h = "+height);
return true;
}
};
System.out.println("sbi: w = "+bgImage.getWidth(null)+", h = "+bgImage.getHeight(null));
//setPreferredSize(new Dimension(bgImage.getWidth(null),bgImage.getHeight(null)));
setPreferredSize(new Dimension(1025,1000));
this.revalidate();
int width = bgImage.getWidth(null);
int height = bgImage.getHeight(null);
System.out.println("sbi: width = "+width+", height = "+height);
setPreferredSize(new Dimension(width, height));
setMinimumSize(new Dimension(width, height));
revalidate();
repaint();
}
}
......@@ -104,7 +104,11 @@ public class Widget {
g2.setFont(newf);
int avgCharSize = 6;
int estTitleLen = title.length()*avgCharSize;
g2.drawString(this.title,this.x - estTitleLen/2,this.y - 16);
int x = this.x - estTitleLen/2;
if ( x < 0 ) x = 0; // Left edge.
int y = this.y - 16;
if ( y < 16 ) y = this.y + 24; // Top edge.
g2.drawString(this.title,x,y);
//g2.rotate(-0.52360);
g2.setFont(oldf);
g2.setColor(oldColor);
......
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
//class ImageObserverImpl implements java.awt.image.ImageObserver {
// public boolean updateImage(Image img, int infoflags, int x, int y, int width, int height) {
// System.out.println("w = "+width+",h = "+height);
// }
//}
public class WifiLinkViewer extends javax.swing.JFrame {
private Image bgImage;
private java.awt.image.ImageObserver io;
private Hashtable datasets;
private Hashtable mapImages;
public WifiLinkViewer() {
this.datasets = new Hashtable();
this.mapImages = new Hashtable();
io = new java.awt.Component() {
public boolean updateImage(Image img, int infoflags, int x, int y, int width, int height) {
System.out.println("w = "+width+",h = "+height);
return true;
}
};
bgImage = Toolkit.getDefaultToolkit().getImage("../meb3fl-2.jpg");
mapImages.put("Floor4/WSN",bgImage);
try {
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(bgImage, 0);
tracker.waitForID(0);
//System.out.println("width = "+bgImage.getWidth(io));
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
// in the applet, we'll read in the possible datasets and
WirelessData defaultData = null;
NodePosition defaultPositions = null;
MapDataModel defaultModel = null;
String defaultDatasetName = "Floor4/WSN";
try {
//defaultData = ILEStats.parseDumpFile("../wifi_data.log", "pcwf");
defaultData = ILEStats.parseDumpFile("../wifi_test.log", "pcwf");
defaultPositions = NodePositions.parseFile("../wifi_positions");
defaultModel = new MapDataModel(defaultData,defaultPositions);
datasets.put(defaultDatasetName,defaultModel);
}
catch (Exception e) {
e.printStackTrace();
System.exit(-2);
}
initComponents();
;
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
nodeMapScrollPane = new javax.swing.JScrollPane();
nodeMapPanel = new NodeMapPanel();
//nodeMapPanel.setBackgroundImage(bgImage);
//nodeMapPanel.setPositions(positions);
//nodeMapPanel.setILEStats(model);
controlPanel = new ControlPanel(datasets,mapImages,nodeMapPanel);
getContentPane().setLayout(new java.awt.GridBagLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
nodeMapScrollPane.setBackground(new java.awt.Color(255, 255, 255));
nodeMapScrollPane.setViewportView(nodeMapPanel);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(nodeMapScrollPane, gridBagConstraints);
controlPanel.setPreferredSize(new java.awt.Dimension(200, 247));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
getContentPane().add(controlPanel, gridBagConstraints);
pack();
}
// </editor-fold>//GEN-END:initComponents
public static void main(final String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WifiLinkViewer().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private ControlPanel controlPanel;
private NodeMapPanel nodeMapPanel;
private javax.swing.JScrollPane nodeMapScrollPane;
// End of variables declaration//GEN-END:variables
}
......@@ -128,7 +128,7 @@ public class WirelessMapApplet extends javax.swing.JApplet {
// now try to parse the data
// every time we add a new kind of data file and an associated parser,
// we must add a try in here with it!
data = ILEStats.parseInputStream(data_is);
data = ILEStats.parseInputStream(data_is, "mote");
int pLs[] = data.getPowerLevels();
System.out.print("power levels = ");
......
pcwf1 22 518 3.0
pcwf10 826 462 4.0
pcwf11 994 326 4.0
pcwf12 573 72 3.0
pcwf13 12 286 3.0
pcwf14 792 448 3.0
pcwf15 774 69 3.0
pcwf16 666 304 3.0
pcwf17 360 394 4.0
pcwf18 852 279 3.0
pcwf2 10 447 3.0
pcwf3 990 240 4.0
pcwf4 228 296 3.0
pcwf5 418 498 3.0
pcwf6 516 663 3.0
pcwf7 22 228 3.0
pcwf8 22 180 3.0
pcwf9 111 14 3.0
#/bin/nawk
# wifi_test.awk
# Generate test data file from the positions, ramp connectivity by distance & power.
BEGIN{ nlevels = split("2 8 15 64 128 192 255", power); }
# Load position data.
{
nodes++;
x[nodes] = $2; y[nodes] = $3; z[nodes] = ( $4 == 3 ? 0 : 10 );
match($1, "[0-9]+"); id[nodes] = substr($1, RSTART, RLENGTH);
print "added phs for wifi id", id[nodes];
}
END {
for ( p = 1; p <= nlevels; p++ ) {
pow = power[p];
printf "Data for power level 0x%x\n", pow;
for ( i = 1; i <= nodes; i++ ) {
for ( j = 1; j <= nodes; j++ ) {
if ( i == j ) continue;
# Distance between nodes in meters.
xd = x[i] - x[j]; yd = y[i] - y[j]; zd = z[i] - z[j];
dist = sqrt((xd*xd) + (yd*yd) + (zd*zd));
# 10.77 pixels/meter on the 1.5-scale images.
meters = dist/10.77;
# Pretend range is 50 meters at full power, degrade linearly.
range = 50 * (pow/255);
if ( meters >= range ) rate = 0;
else rate = int( ( (range - meters) / range) * 100 );
printf "(%d) <- (%d): pkts(%d/100,%d.0%%) %s\n",
id[j], id[i], rate, rate, "rssi(0.0,0.0,0.0,0.0)";
#printf "%d (%d %d %d), %d (%d %d %d), [%f %f %f] %f %f %f\n",
# j, x[j], y[j], z[j], i, x[i], y[i], z[i],
# xd, yd, zd, dist, meters, range;
}
}
printf "\n";
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment