From 4f744d858ae58a3a5f399d7d0949814701b77ab3 Mon Sep 17 00:00:00 2001 From: Antonio Lignan Date: Tue, 4 Nov 2014 00:37:11 +0100 Subject: [PATCH] Fixed rssi scanner application and moved into single example --- examples/rssi-scanner/Makefile | 23 ++++ .../ViewRSSI.java | 12 +- .../ViewRSSI3D.java | 2 +- .../project-conf.h | 0 .../rssi-scanner-cc2420.c} | 24 ++-- examples/sky/Makefile | 6 - examples/sky/ViewRSSI.java | 105 ------------------ examples/sky/rssi-scanner.c | 94 ---------------- examples/z1/rssi_scanner/Makefile | 33 ------ 9 files changed, 48 insertions(+), 251 deletions(-) create mode 100644 examples/rssi-scanner/Makefile rename examples/{z1/rssi_scanner => rssi-scanner}/ViewRSSI.java (94%) rename examples/{z1/rssi_scanner => rssi-scanner}/ViewRSSI3D.java (98%) rename examples/{z1/rssi_scanner => rssi-scanner}/project-conf.h (100%) rename examples/{z1/rssi_scanner/rssi-scanner.c => rssi-scanner/rssi-scanner-cc2420.c} (86%) delete mode 100644 examples/sky/ViewRSSI.java delete mode 100644 examples/sky/rssi-scanner.c delete mode 100644 examples/z1/rssi_scanner/Makefile diff --git a/examples/rssi-scanner/Makefile b/examples/rssi-scanner/Makefile new file mode 100644 index 000000000..2513eba11 --- /dev/null +++ b/examples/rssi-scanner/Makefile @@ -0,0 +1,23 @@ +DEFINES=PROJECT_CONF_H=\"project-conf.h\" + +ifndef TARGET +TARGET = z1 +endif + +CONTIKI = ../.. + +CONTIKI_PROJECT = rssi-scanner-cc2420 + +all: $(CONTIKI_PROJECT) + +%.class: %.java + javac $(basename $<).java + +viewrssi3d: ViewRSSI3D.class + make login | java ViewRSSI3D + +viewrssi: ViewRSSI.class + make login | java ViewRSSI + +include $(CONTIKI)/Makefile.include + diff --git a/examples/z1/rssi_scanner/ViewRSSI.java b/examples/rssi-scanner/ViewRSSI.java similarity index 94% rename from examples/z1/rssi_scanner/ViewRSSI.java rename to examples/rssi-scanner/ViewRSSI.java index e768594b6..0b881ef7e 100644 --- a/examples/z1/rssi_scanner/ViewRSSI.java +++ b/examples/rssi-scanner/ViewRSSI.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2007, Swedish Institute of Computer Science. * Copyright (c) 2010, University of Luebeck, Germany. * All rights reserved. * @@ -25,9 +26,14 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * Author: Carlo Alberto Boano , Joakim Eriksson, - * + */ + +/** + * \file + * ViewRSSI java application + * \author + * Joakim Eriksson + * Carlo Alberto Boano */ import javax.swing.*; diff --git a/examples/z1/rssi_scanner/ViewRSSI3D.java b/examples/rssi-scanner/ViewRSSI3D.java similarity index 98% rename from examples/z1/rssi_scanner/ViewRSSI3D.java rename to examples/rssi-scanner/ViewRSSI3D.java index 425d1a276..2defe6bcb 100644 --- a/examples/z1/rssi_scanner/ViewRSSI3D.java +++ b/examples/rssi-scanner/ViewRSSI3D.java @@ -1,7 +1,7 @@ /** * 3D RSSI Viewer - view RSSI values of 802.15.4 channels * --------------------------------------------------- - * Note: run the rssi-scanner on a Sky or sentilla node connected to USB + * Note: run the rssi-scanner on a Sky, Z1 or sentilla node connected to USB * then start with * make login | java ViewRSSI3D * diff --git a/examples/z1/rssi_scanner/project-conf.h b/examples/rssi-scanner/project-conf.h similarity index 100% rename from examples/z1/rssi_scanner/project-conf.h rename to examples/rssi-scanner/project-conf.h diff --git a/examples/z1/rssi_scanner/rssi-scanner.c b/examples/rssi-scanner/rssi-scanner-cc2420.c similarity index 86% rename from examples/z1/rssi_scanner/rssi-scanner.c rename to examples/rssi-scanner/rssi-scanner-cc2420.c index bbca9cdb6..fbbfddf00 100644 --- a/examples/z1/rssi_scanner/rssi-scanner.c +++ b/examples/rssi-scanner/rssi-scanner-cc2420.c @@ -54,15 +54,22 @@ static void set_frq(int c) { int f; - // We can read even other channels with CC2420! - // Fc = 2048 + FSCTRL ; Fc = 2405 + 5(k-11) MHz, k=11,12, ... , 26 - f = c + 352; // Start from 2400 MHz to 2485 MHz, - //FASTSPI_SETREG(CC2420_FSCTRL, f); - //FASTSPI_STROBE(CC2420_SRXON); - CC2420_WRITE_REG(CC2420_FSCTRL, f); - CC2420_STROBE(CC2420_SRXON); -} + /* We can read even other channels with CC2420! */ + /* Fc = 2048 + FSCTRL ; Fc = 2405 + 5(k-11) MHz, k=11,12, ... , 26 */ + f = c + 352; /* Start from 2400 MHz to 2485 MHz, */ + /* Write the new channel value */ + CC2420_SPI_ENABLE(); + SPI_WRITE_FAST(CC2420_FSCTRL); + SPI_WRITE_FAST((uint8_t)(f >> 8)); + SPI_WRITE_FAST((uint8_t)(f & 0xff)); + SPI_WAITFORTx_ENDED(); + SPI_WRITE(0); + + /* Send the strobe */ + SPI_WRITE(CC2420_SRXON); + CC2420_SPI_DISABLE(); +} static void do_rssi(void) { @@ -74,7 +81,6 @@ do_rssi(void) } printf("\n"); } - /*---------------------------------------------------------------------------*/ PROCESS(scanner_process, "RSSI Scanner"); AUTOSTART_PROCESSES(&scanner_process); diff --git a/examples/sky/Makefile b/examples/sky/Makefile index f66dff5a1..aba2bb3a1 100644 --- a/examples/sky/Makefile +++ b/examples/sky/Makefile @@ -11,10 +11,4 @@ all: blink sky-collect #rt-leds test-button test-cfs tcprudolph0 echo $(basename $<)/$(basename $<).ihex 600 > $(basename $<)/runfile ; \ tar czf $@ $(basename $<) -%.class: %.java - javac $(basename $<).java - -viewrssi: ViewRSSI.class - make login | java ViewRSSI - include $(CONTIKI)/Makefile.include diff --git a/examples/sky/ViewRSSI.java b/examples/sky/ViewRSSI.java deleted file mode 100644 index 53d6e4603..000000000 --- a/examples/sky/ViewRSSI.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * RSSI Viewer - view RSSI values of 802.15.4 channels - * --------------------------------------------------- - * 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 - * @version 1.0 - */ -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; - - 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; - - 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); - - 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); - g2d.drawString(Integer.toString(rssiMax[i] + DELTA), (int)xpos,h - 20 - rssi - 5 ); - xpos += sSpacing; - } - - - 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; - } - } - - 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(); - } -} diff --git a/examples/sky/rssi-scanner.c b/examples/sky/rssi-scanner.c deleted file mode 100644 index 92da5aa3e..000000000 --- a/examples/sky/rssi-scanner.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2007, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - */ - -/** - * \file - * Scanning 2.4 GHz radio frequencies using CC2420 and prints - * the values - * \author - * Joakim Eriksson, joakime@sics.se - */ - -#include "contiki.h" -#include "net/rime/rime.h" -#include "net/netstack.h" - -#include "dev/leds.h" -#include "cc2420.h" -#include "cc2420_const.h" -#include "dev/spi.h" -#include - -/*---------------------------------------------------------------------------*/ -/* This assumes that the CC2420 is always on and "stable" */ -static void -set_frq(int c) -{ - int f; - /* fine graied channel - can we even read other channels with CC2420 ? */ - f = c + 302 + 0x4000; - - CC2420_WRITE_REG(CC2420_FSCTRL, f); - CC2420_STROBE(CC2420_SRXON); -} - -static void -do_rssi(void) -{ - int channel; - printf("RSSI:"); - for(channel = 0; channel <= 79; ++channel) { - set_frq(channel + 55); - printf("%d ", cc2420_rssi() + 55); - } - printf("\n"); -} - -/*---------------------------------------------------------------------------*/ -PROCESS(scanner_process, "RSSI Scanner"); -AUTOSTART_PROCESSES(&scanner_process); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(scanner_process, ev, data) -{ - PROCESS_BEGIN(); - /* switch mac layer off, and turn radio on */ - NETSTACK_MAC.off(0); - cc2420_on(); - - while(1) { - do_rssi(); - PROCESS_PAUSE(); - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/z1/rssi_scanner/Makefile b/examples/z1/rssi_scanner/Makefile deleted file mode 100644 index 2e66213f5..000000000 --- a/examples/z1/rssi_scanner/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -DEFINES=PROJECT_CONF_H=\"project-conf.h\" - -# Define the target platform -ifndef TARGET -TARGET=z1 -endif - -CONTIKI_SOURCEFILES += cc2420-arch.c sensors.c sht11.c -PROJECT_SOURCEFILES = i2cmaster.c tmp102.c adxl345.c battery-sensor.c sky-sensors.c #potentiometer-sensor.c - -# Give a name to your project -CONTIKI = ../../../../contiki-2.x/ -CONTIKI_PROJECT = rssi-scanner - -# Compile project typing "make" -all: $(CONTIKI_PROJECT) - -# Upload project typing "make upload" -upload: $(CONTIKI_PROJECT).upload - -%.class: %.java - javac $(basename $<).java - -viewrssi3d: ViewRSSI3D.class - make login | java ViewRSSI3D - -viewrssi: ViewRSSI.class - make login | java ViewRSSI - -# ContikiProjects: including the makefile -#include ../../../Makefile.projects -include $(CONTIKI)/Makefile.include -