Fixed rssi scanner application and moved into single example

ico
Antonio Lignan 2014-11-04 00:37:11 +01:00
parent ce49276e80
commit 4f744d858a
9 changed files with 48 additions and 251 deletions

View File

@ -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

View File

@ -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 <cboano@iti.uni-luebeck.de>, Joakim Eriksson, <joakime@sics.se>
*
*/
/**
* \file
* ViewRSSI java application
* \author
* Joakim Eriksson <joakime@sics.se>
* Carlo Alberto Boano <cboano@iti.uni-luebeck.de>
*/
import javax.swing.*;

View File

@ -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
*

View File

@ -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);

View File

@ -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

View File

@ -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();
}
}

View File

@ -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 <stdio.h>
/*---------------------------------------------------------------------------*/
/* 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();
}
/*---------------------------------------------------------------------------*/

View File

@ -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