From fae6c530de728b1c8c6fb10c726cd5fd1572be70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Wed, 14 Aug 2013 16:27:05 +0200 Subject: [PATCH 1/4] Fix indention of ViewRSSI.java --- examples/sky/ViewRSSI.java | 144 +++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/examples/sky/ViewRSSI.java b/examples/sky/ViewRSSI.java index 019dc2d18..d7703e1b1 100644 --- a/examples/sky/ViewRSSI.java +++ b/examples/sky/ViewRSSI.java @@ -13,77 +13,79 @@ import javax.swing.*; import java.awt.*; import java.io.*; + + public class ViewRSSI extends JPanel { - - private int[] rssi = new int[80]; - private int[] rssiMax = new int[80]; - - /* this is the max value of the RSSI from the cc2420 */ - private static final int RSSI_MAX_VALUE = 200; - - public ViewRSSI() { - } - - public void paint(Graphics g) { - int h = getHeight(); - int w = getWidth(); - double factor = (h - 20.0) / RSSI_MAX_VALUE; - double sSpacing = (w - 15 ) / 80.0; - int sWidth = (int) (sSpacing - 1); - if (sWidth == 0) sWidth = 1; - - g.setColor(Color.white); - g.fillRect(0, 0, w, h); - - g.setColor(Color.gray); - double xpos = 10; - for (int i = 0, n = rssi.length; i < n; i++) { - int rssi = (int) (rssiMax[i] * factor); - g.fillRect((int) xpos, h - 20 - rssi, - sWidth, rssi + 1); - xpos += sSpacing; - } - - g.setColor(Color.black); - xpos = 10; - for (int i = 0, n = rssi.length; i < n; i++) { - int rssiVal = (int) (rssi[i] * factor); - g.fillRect((int) xpos, h - 20 - rssiVal, - sWidth, rssiVal + 1); - xpos += sSpacing; - } - } - - private void handleInput() throws IOException { - BufferedReader reader = - new BufferedReader(new InputStreamReader(System.in)); - while(true) { - String line = reader.readLine(); - if (line.startsWith("RSSI:")) { - try { - String[] parts = line.substring(5).split(" "); - for (int i = 0, n = parts.length; i < n; i++) { - rssi[i] = 3 * Integer.parseInt(parts[i]); - if (rssi[i] > rssiMax[i]) rssiMax[i] = rssi[i]; - else if (rssiMax[i] > 0) rssiMax[i]--; - } - } catch (Exception e) { - /* report but do not fail... */ - e.printStackTrace(); + + private int[] rssi = new int[80]; + private int[] rssiMax = new int[80]; + + /* this is the max value of the RSSI from the cc2420 */ + private static final int RSSI_MAX_VALUE = 200; + + public ViewRSSI() { + } + + public void paint(Graphics g) { + int h = getHeight(); + int w = getWidth(); + double factor = (h - 20.0) / RSSI_MAX_VALUE; + double sSpacing = (w - 15) / 80.0; + int sWidth = (int) (sSpacing - 1); + if (sWidth == 0) + sWidth = 1; + + g.setColor(Color.white); + g.fillRect(0, 0, w, h); + + g.setColor(Color.gray); + double xpos = 10; + for (int i = 0, n = rssi.length; i < n; i++) { + int rssi = (int) (rssiMax[i] * factor); + g.fillRect((int) xpos, h - 20 - rssi, sWidth, rssi + 1); + xpos += sSpacing; + } + + g.setColor(Color.black); + xpos = 10; + for (int i = 0, n = rssi.length; i < n; i++) { + int rssiVal = (int) (rssi[i] * factor); + g.fillRect((int) xpos, h - 20 - rssiVal, sWidth, rssiVal + 1); + xpos += sSpacing; + } + } + + private void handleInput() throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + while (true) { + String line = reader.readLine(); + if (line.startsWith("RSSI:")) { + try { + String[] parts = line.substring(5).split(" "); + for (int i = 0, n = parts.length; i < n; i++) { + rssi[i] = 3 * Integer.parseInt(parts[i]); + if (rssi[i] > rssiMax[i]) + rssiMax[i] = rssi[i]; + else if (rssiMax[i] > 0) + rssiMax[i]--; + } + } catch (Exception e) { + /* report but do not fail... */ + e.printStackTrace(); + } + repaint(); + } + } + } + + public static void main(String[] args) throws IOException { + JFrame win = new JFrame("RSSI Viewer"); + ViewRSSI panel; + win.setBounds(10, 10, 300, 300); + win.getContentPane().add(panel = new ViewRSSI()); + win.setVisible(true); + win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + panel.handleInput(); } - repaint(); - } - } - } - - public static void main(String[] args) throws IOException { - JFrame win = new JFrame("RSSI Viewer"); - ViewRSSI panel; - win.setBounds(10, 10, 300, 300); - win.getContentPane().add(panel = new ViewRSSI()); - win.setVisible(true); - win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - panel.handleInput(); - } } From f407dea8ff21056b6c40140318e26a40756a550f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Wed, 14 Aug 2013 16:28:23 +0200 Subject: [PATCH 2/4] Update documentation in ViewRSSI.java --- examples/sky/ViewRSSI.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/sky/ViewRSSI.java b/examples/sky/ViewRSSI.java index d7703e1b1..a91ff103e 100644 --- a/examples/sky/ViewRSSI.java +++ b/examples/sky/ViewRSSI.java @@ -3,8 +3,11 @@ * --------------------------------------------------- * Note: run the rssi-scanner on a Sky or sentilla node connected to USB * then start with + * make ViewRSSI.class * make login | java ViewRSSI - * + * or + * make viewrssi + * * Created: Fri Apr 24 00:40:01 2009, Joakim Eriksson * * @author Joakim Eriksson, SICS From 244b06f25df6f2ecb6c9defc14f74aaea3c1026d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Wed, 14 Aug 2013 16:33:55 +0200 Subject: [PATCH 3/4] Fix calculation of the maximum RSSI value --- examples/sky/ViewRSSI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sky/ViewRSSI.java b/examples/sky/ViewRSSI.java index a91ff103e..91f69be5b 100644 --- a/examples/sky/ViewRSSI.java +++ b/examples/sky/ViewRSSI.java @@ -67,7 +67,7 @@ public class ViewRSSI extends JPanel { String[] parts = line.substring(5).split(" "); for (int i = 0, n = parts.length; i < n; i++) { rssi[i] = 3 * Integer.parseInt(parts[i]); - if (rssi[i] > rssiMax[i]) + if (rssi[i] >= rssiMax[i]) rssiMax[i] = rssi[i]; else if (rssiMax[i] > 0) rssiMax[i]--; From e292d31640a3ebfc9116f11221b0eba299188aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Wed, 14 Aug 2013 16:36:43 +0200 Subject: [PATCH 4/4] Add channel numbers and RSSI-Values --- examples/sky/ViewRSSI.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/sky/ViewRSSI.java b/examples/sky/ViewRSSI.java index 91f69be5b..1226921d9 100644 --- a/examples/sky/ViewRSSI.java +++ b/examples/sky/ViewRSSI.java @@ -17,11 +17,12 @@ import javax.swing.*; import java.awt.*; import java.io.*; - public class ViewRSSI extends JPanel { private int[] rssi = new int[80]; private int[] rssiMax = new int[80]; + /* 55 is added by the scanner. 45 is the offset of the CC2420 */ + private final int DELTA = -55 -45 /* this is the max value of the RSSI from the cc2420 */ private static final int RSSI_MAX_VALUE = 200; @@ -30,6 +31,7 @@ public class ViewRSSI extends JPanel { } public void paint(Graphics g) { + int h = getHeight(); int w = getWidth(); double factor = (h - 20.0) / RSSI_MAX_VALUE; @@ -38,6 +40,10 @@ public class ViewRSSI extends JPanel { if (sWidth == 0) sWidth = 1; + Graphics2D g2d=(Graphics2D)g; + Font myFont=new Font("Arial", Font.PLAIN, 8); + g2d.setFont( myFont ); + g.setColor(Color.white); g.fillRect(0, 0, w, h); @@ -46,14 +52,19 @@ public class ViewRSSI extends JPanel { for (int i = 0, n = rssi.length; i < n; i++) { int rssi = (int) (rssiMax[i] * factor); g.fillRect((int) xpos, h - 20 - rssi, sWidth, rssi + 1); + g2d.drawString(Integer.toString(rssiMax[i] + DELTA), (int)xpos,h - 20 - rssi - 5 ); xpos += sSpacing; } - g.setColor(Color.black); + xpos = 10; for (int i = 0, n = rssi.length; i < n; i++) { + g.setColor(Color.black); int rssiVal = (int) (rssi[i] * factor); g.fillRect((int) xpos, h - 20 - rssiVal, sWidth, rssiVal + 1); + g2d.drawString(Integer.toString(rssi[i] + DELTA), (int)xpos,h - 20 - rssiVal - 8 ); + g.setColor(Color.white); + g2d.drawString(Float.toString((float)i / 5 + (float)56/5), (int)xpos,h - 20 - 5 ); xpos += sSpacing; } }