Commit 753dc231 authored by David Johnson's avatar David Johnson

All these files are for the wireless stats applet. I'll commit the

necessary makefiles later; will not install for now.
parent 960d6ba1
This diff is collapsed.
This diff is collapsed.
public class LinkStats {
private String srcNode;
private String recvNode;
private int pktRecvCount;
private int pktCount;
private float pktPercent;
private float minRSSI;
private float maxRSSI;
private float avgRSSI;
private float stddevRSSI;
public LinkStats(String srcNode,String recvNode,
int pktRecvCount,int pktCount,
float minRSSI,float maxRSSI,float avgRSSI,
float stddevRSSI) {
this.srcNode = srcNode;
this.recvNode = recvNode;
this.pktRecvCount = pktRecvCount;
this.pktCount = pktCount;
this.pktPercent = ((float)this.pktRecvCount)/this.pktCount;
this.minRSSI = minRSSI;
this.maxRSSI = maxRSSI;
this.avgRSSI = avgRSSI;
this.stddevRSSI = stddevRSSI;
}
public String getSrcNode() {
return srcNode;
}
public String getRecvNode() {
return recvNode;
}
public int getPktCount() {
return pktRecvCount;
}
public int getExpectedPktCount() {
return pktCount;
}
public float getPktPercent() {
return pktPercent;
}
public float getMinRSSI() {
return minRSSI;
}
public float getMaxRSSI() {
return maxRSSI;
}
public float getAvgRSSI() {
return avgRSSI;
}
public float getStddevRSSI() {
return stddevRSSI;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
// Don't forget: heap is from heap[1] to heap[initSize]
public class MinHeap {
private float[] heap;
private int heapSize;
public MinHeap(float[] a, int initSize) {
if (initSize < a.length+1) {
throw new IllegalArgumentException("in constructor MinHeap, initSize must be >= to a.length+1");
}
heap = new float[initSize];
for (int i = 0; i < a.length; ++i) {
heap[i+1] = a[i];
}
heapSize = a.length;
buildMinHeap();
}
public MinHeap(int[] a) {
heap = new float[a.length+1];
for (int i = 0; i < a.length; ++i) {
heap[i+1] = a[i];
}
heapSize = a.length;
buildMinHeap();
}
public void printHeapAsArray() {
for (int i = 1; i <= heapSize; i++) {
System.out.print(heap[i]+" ");
}
System.out.println();
}
public void printHeapAsTree() {
int depth = depth();
int maxPrintableAtThisDepth = 1;
int printedSoFar = 0;
int spacing = 24;
for (int i = 1; i <= heapSize; i++) {
if (printedSoFar == maxPrintableAtThisDepth) {
maxPrintableAtThisDepth *= 2;
printedSoFar = 0;
System.out.print("\n");
spacing /= 2;
}
for (int j = 0; j < spacing; j++) {
System.out.print(" ");
}
System.out.print(heap[i]);
for (int j = 0; j < spacing; j++) {
System.out.print(" ");
}
printedSoFar++;
}
System.out.println();
}
// Assume that integers are only max of 2 chars for testing
public int depth() {
int depth = 0;
int i = 1;
while (i < heapSize) {
depth += 1;
i = left(i);
}
return depth;
}
public void minHeapInsert(float key) {
// check to see if we need to expand the array
if (heap.length-1 == heapSize) {
float[] tmp = new float[heap.length];
System.arraycopy(heap,1,tmp,1,heapSize);
heap = new float[heapSize*2];
System.arraycopy(tmp,1,heap,1,heapSize);
}
heapSize++;
heap[heapSize] = Integer.MIN_VALUE;
heapDecreaseKey(heapSize,key);
}
public float heapExtractMin() {
if (heapSize < 1) {
return -1;
}
float min = heap[1];
heap[1] = heap[heapSize];
heapSize--;
minHeapify(1);
return min;
}
public void heapDecreaseKey(int i,float key) {
if (key > heap[i]) {
// add error statement;
}
heap[i] = key;
while(i > 1 && heap[parent(i)] > heap[i]) {
float tmp = heap[parent(i)];
heap[parent(i)] = heap[i];
heap[i] = tmp;
i = parent(i);
}
}
public float heapMinimum() {
return heap[1];
}
private void buildMinHeap() {
for (int i = heapSize/2; i > 0; --i) {
minHeapify(i);
}
}
private void minHeapify(int i) {
int left = left(i);
int right = right(i);
int smallest = i;
if (left <= heapSize && heap[left] < heap[i]) {
smallest = left;
}
if (right <= heapSize && heap[right] < heap[smallest]) {
smallest = right;
}
if (smallest != i) {
float tmp = heap[i];
heap[i] = heap[smallest];
heap[smallest] = tmp;
minHeapify(smallest);
}
}
private int parent(int i) {
return i/2;
}
private int left(int i) {
return 2*i;
}
private int right(int i) {
return 2*i+1;
}
}
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 MoteLinkViewer extends javax.swing.JFrame {
private Image bgImage;
private java.awt.image.ImageObserver io;
private Hashtable datasets;
private Hashtable mapImages;
public MoteLinkViewer() {
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("/home/david/work/java/floormap.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("/home/david/work/java/nn_client.log");
defaultPositions = NodePositions.parseFile("/home/david/work/java/mote_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 MoteLinkViewer().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
}
/*
* NodeLinkModel.java
*
* Created on July 19, 2005, 8:58 PM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
/**
*
* @author david
*/
public class NodeLinkModel {
private ILEStats stats;
private NodePositions positions;
/** Creates a new instance of NodeLinkModel */
public NodeLinkModel(ILEStats s,NodePositions np) {
this.stats = stats;
this.positions = positions;
}
}
This diff is collapsed.
/*
* NodePosition.java
*
* Created on February 1, 2006, 9:41 PM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
/**
*
* @author david
*/
public interface NodePosition {
public float[] getPosition(String nodeName);
public java.awt.Point getPoint(String nodeName);
}
/*
* NodePositions.java
*
* Created on July 19, 2005, 8:26 PM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
import java.io.*;
import java.util.*;
import java.util.regex.*;
/**
*
* @author david
*/
public class NodePositions implements NodePosition {
private Hashtable positions;
/** Creates a new instance of NodePositions */
protected NodePositions(Hashtable positions) {
this.positions = positions;
}
public NodePositions parseDB() {
return null;
}
private static NodePositions parseReader(BufferedReader br)
throws IOException, java.text.ParseException {
Hashtable p = new Hashtable();
try {
//br = new BufferedReader(new FileReader(f));
String line = null;
while ((line = br.readLine()) != null) {
// parse line: "mote101 350 708 0.2"
Pattern posit = Pattern.compile("([a-zA-Z0-9\\-_]+)\\s+(\\-*\\d+)\\s+(\\-*\\d+)\\s+(\\-*\\d+\\.\\d+E*\\-*\\d*)");
Matcher positM = posit.matcher(line);
if (positM.matches()) {
float xyz[] = new float[3];
xyz[0] = Float.parseFloat(positM.group(2));
xyz[1] = Float.parseFloat(positM.group(3));
xyz[2] = Float.parseFloat(positM.group(4));
p.put(positM.group(1),xyz);
//System.out.println(""+positM.group(1)+" ("+xyz[0]+","+xyz[1]+","+xyz[2]+")");
}
}
}
catch (IOException e) {
//throw new Exception("file read failed");
throw e;
}
return new NodePositions(p);
}
public static NodePositions parseInputStream(InputStream is)
throws IOException, java.text.ParseException, Exception {
BufferedReader br = null;
NodePositions retval = null;
br = new BufferedReader(new InputStreamReader(is));
retval = parseReader(br);
return retval;
}
public static NodePositions parseFile(String filename)
throws java.io.IOException, java.text.ParseException,
java.lang.IllegalArgumentException, Exception {
File f = null;
BufferedReader br = null;
if (filename != null) {
f = new File(filename);
if (!f.exists() || !f.canRead()) {
throw new java.io.IOException("Couldn't open and/or read " +
"file "+filename);
}
}
else {
throw new java.lang.IllegalArgumentException("filename null");
}
br = new BufferedReader(new FileReader(f));
return parseReader(br);
}
public float[] getPosition(String nodeName) {
float retval[] = null;
retval = (float[])(positions.get(nodeName));
return retval;
}
public java.awt.Point getPoint(String nodeName) {
//System.out.println("looking for node '"+nodeName+"'");
float p[] = null;
p = (float[])(positions.get(nodeName));
if (p != null) {
return new java.awt.Point((int)p[0],(int)p[1]);
}
else {
return null;
}
}
public static void main(String args[]) throws Exception {
parseFile(args[0]);
}
}
/*
* NodeWidget.java
*
* Created on July 11, 2005, 8:19 AM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
/**
*
* @author david
*/
public class NodeWidget extends Widget {
/**
* Creates a new instance of NodeWidget
*/
public NodeWidget(String title,int x,int y) {
super(title,x,y);
}
public NodeWidget() {
super();
}
}
import java.util.*;
import java.awt.*;
/*
* Widget.java
*
* Created on July 11, 2005, 8:26 AM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
/**
*
* @author david
*/
public class Widget {
protected String title;
private boolean titleVisible;
private Hashtable properties;
private boolean visible;
private int x;
private int y;
public static Color selectedColor = new Color(37,160,231);
/** Creates a new instance of Widget */
public Widget() {
this.properties = new Hashtable();
this.title = null;
this.x = 100;
this.y = 100;
}
public Widget(String title,int x,int y) {
this.properties = new Hashtable();
this.title = title;
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String getTitle() {
return title;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setLocation(java.awt.Point p) {
this.x = p.x;
this.y = p.y;
}
public void setTitle(String title) {
this.title = title;
}
public void setVisible(boolean vis) {
this.visible = vis;
}
public void setTitleVisible(boolean vis) {
this.titleVisible = vis;
}
public Shape getContainingShape() {
return new java.awt.geom.Ellipse2D.Float(x-4,y-4,8,8);
}
public void drawWidget(java.awt.Graphics g,boolean selected) {
if (g instanceof java.awt.Graphics2D) {
Graphics2D g2 = (Graphics2D)g;
java.awt.geom.Ellipse2D e = new java.awt.geom.Ellipse2D.Float(x-4,y-4,8,8);
Color oldColor = g2.getColor();
if (selected) {
g2.setColor(selectedColor);
}
else {
g2.setColor(java.awt.Color.DARK_GRAY);
}
g2.fill(e);
g2.setColor(java.awt.Color.BLACK);
g2.draw(e);
g2.setColor(java.awt.Color.DARK_GRAY);
//g2.rotate(0.52360);
Font oldf = g2.getFont();
Font newf = new Font(oldf.getName(),Font.BOLD,oldf.getSize());
g2.setFont(newf);
int avgCharSize = 6;
int estTitleLen = title.length()*avgCharSize;
g2.drawString(this.title,this.x - estTitleLen/2,this.y - 16);
//g2.rotate(-0.52360);
g2.setFont(oldf);
g2.setColor(oldColor);
}
}
}
/**
*
* This interface must be implemented by anything th
*
*/
public interface WirelessData {
public String[] getNodes();
//public LinkStats[] getSendStats(String srcNode);
//public LinkStats[] getRecvStats(String recvNode);
public int[] getPowerLevels();
// otherwise you have to use these... ick!
public LinkStats[] getSendStatsAtPowerLevel(String srcNode,int powerLevel);
public LinkStats[] getRecvStatsAtPowerLevel(String recvNode,int powerLevel);
public LinkStats[] getAllStatsAtPowerLevel(int powerLevel);
}
This diff is collapsed.
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