Added radio sensor.
This commit is contained in:
parent
17aafb9daa
commit
b7459a12c1
|
@ -49,6 +49,10 @@
|
||||||
|
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
|
#include "dev/radio-sensor.h"
|
||||||
|
#include "dev/sensor-common.h"
|
||||||
|
|
||||||
|
#include "st-lib.h"
|
||||||
|
|
||||||
#ifdef COMPILE_SENSORS
|
#ifdef COMPILE_SENSORS
|
||||||
#include "dev/temperature-sensor.h"
|
#include "dev/temperature-sensor.h"
|
||||||
|
@ -72,12 +76,15 @@ PROCESS_THREAD(sensor_demo_process, ev, data)
|
||||||
{
|
{
|
||||||
static struct etimer etimer;
|
static struct etimer etimer;
|
||||||
static unsigned long _button_pressed;
|
static unsigned long _button_pressed;
|
||||||
|
static int sensor_value = 0;
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
PROCESS_PAUSE();
|
PROCESS_PAUSE();
|
||||||
|
|
||||||
SENSORS_ACTIVATE(button_sensor);
|
SENSORS_ACTIVATE(button_sensor);
|
||||||
|
|
||||||
|
SENSORS_ACTIVATE(radio_sensor);
|
||||||
|
|
||||||
#ifdef COMPILE_SENSORS
|
#ifdef COMPILE_SENSORS
|
||||||
SENSORS_ACTIVATE(temperature_sensor);
|
SENSORS_ACTIVATE(temperature_sensor);
|
||||||
SENSORS_ACTIVATE(humidity_sensor);
|
SENSORS_ACTIVATE(humidity_sensor);
|
||||||
|
@ -110,13 +117,19 @@ PROCESS_THREAD(sensor_demo_process, ev, data)
|
||||||
printf("LEDs status:\tRED:%s GREEN:%s\n", leds_get()&LEDS_RED?"on":"off",
|
printf("LEDs status:\tRED:%s GREEN:%s\n", leds_get()&LEDS_RED?"on":"off",
|
||||||
leds_get()&LEDS_GREEN?"on":"off");
|
leds_get()&LEDS_GREEN?"on":"off");
|
||||||
#endif /*COMPILE_SENSORS*/
|
#endif /*COMPILE_SENSORS*/
|
||||||
|
sensor_value = radio_sensor.value(RADIO_SENSOR_LAST_PACKET);
|
||||||
|
printf("Radio (RSSI):\t%d.%d dBm\n", sensor_value/10, ABS_VALUE(sensor_value)%10);
|
||||||
|
printf("Radio (LQI):\t%d\n", radio_sensor.value(RADIO_SENSOR_LAST_VALUE));
|
||||||
|
|
||||||
#ifdef COMPILE_SENSORS
|
#ifdef COMPILE_SENSORS
|
||||||
printf("Temperature:\t%d.%d C\n", temperature_sensor.value(0)/10, temperature_sensor.value(0)%10);
|
sensor_value = temperature_sensor.value(0);
|
||||||
|
printf("Temperature:\t%d.%d C\n", sensor_value/10, ABS_VALUE(sensor_value)%10);
|
||||||
|
|
||||||
printf("Humidity:\t%d.%d rH\n", humidity_sensor.value(0)/10, humidity_sensor.value(0)%10);
|
sensor_value = humidity_sensor.value(0);
|
||||||
|
printf("Humidity:\t%d.%d rH\n", sensor_value/10, ABS_VALUE(sensor_value)%10);
|
||||||
|
|
||||||
printf("Pressure:\t%d.%d mbar\n", pressure_sensor.value(0)/10, pressure_sensor.value(0)%10);
|
sensor_value = pressure_sensor.value(0);
|
||||||
|
printf("Pressure:\t%d.%d mbar\n", sensor_value/10, ABS_VALUE(sensor_value)%10);
|
||||||
|
|
||||||
printf("Magneto:\t%d/%d/%d (X/Y/Z) mgauss\n", magneto_sensor.value(X_AXIS),
|
printf("Magneto:\t%d/%d/%d (X/Y/Z) mgauss\n", magneto_sensor.value(X_AXIS),
|
||||||
magneto_sensor.value(Y_AXIS),
|
magneto_sensor.value(Y_AXIS),
|
||||||
|
|
|
@ -48,7 +48,7 @@ CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/sensors/hts221 stm32cube-lib/driver
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
ARCH_DEV = button-sensor.c leds-arch.c
|
ARCH_DEV = button-sensor.c leds-arch.c radio-sensor.c
|
||||||
|
|
||||||
ARCH_DEV_SENSORS = temperature-sensor.c humidity-sensor.c pressure-sensor.c magneto-sensor.c acceleration-sensor.c gyroscope-sensor.c
|
ARCH_DEV_SENSORS = temperature-sensor.c humidity-sensor.c pressure-sensor.c magneto-sensor.c acceleration-sensor.c gyroscope-sensor.c
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
#include "hw-config.h"
|
#include "hw-config.h"
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
|
#include "dev/radio-sensor.h"
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#if NETSTACK_CONF_WITH_IPV6
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
#include "net/ipv6/uip-ds6.h"
|
#include "net/ipv6/uip-ds6.h"
|
||||||
|
@ -80,6 +81,7 @@ extern const struct sensors_sensor magneto_sensor;
|
||||||
extern const struct sensors_sensor acceleration_sensor;
|
extern const struct sensors_sensor acceleration_sensor;
|
||||||
extern const struct sensors_sensor gyroscope_sensor;
|
extern const struct sensors_sensor gyroscope_sensor;
|
||||||
SENSORS(&button_sensor,
|
SENSORS(&button_sensor,
|
||||||
|
&radio_sensor,
|
||||||
&temperature_sensor,
|
&temperature_sensor,
|
||||||
&humidity_sensor,
|
&humidity_sensor,
|
||||||
&pressure_sensor,
|
&pressure_sensor,
|
||||||
|
@ -87,7 +89,8 @@ SENSORS(&button_sensor,
|
||||||
&acceleration_sensor,
|
&acceleration_sensor,
|
||||||
&gyroscope_sensor);
|
&gyroscope_sensor);
|
||||||
#else /*COMPILE_SENSORS*/
|
#else /*COMPILE_SENSORS*/
|
||||||
SENSORS(&button_sensor);
|
SENSORS(&button_sensor,
|
||||||
|
&radio_sensor);
|
||||||
#endif /*COMPILE_SENSORS*/
|
#endif /*COMPILE_SENSORS*/
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
extern unsigned char node_mac[8];
|
extern unsigned char node_mac[8];
|
||||||
|
|
125
platform/stm32nucleo-spirit1/dev/radio-sensor.c
Normal file
125
platform/stm32nucleo-spirit1/dev/radio-sensor.c
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file platform/stm32nucleo-spirit1/dev/radio-sensor.c
|
||||||
|
* @author System LAB
|
||||||
|
* @version V1.0.0
|
||||||
|
* @date 7-September-2015
|
||||||
|
* @brief Enable radio sensor functionality
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
|
||||||
|
*
|
||||||
|
* 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 STMicroelectronics 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \file
|
||||||
|
* Driver for the stm32nucleo-spirit1 Radio Sensor (RSSI, LQI, ...)
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#include "dev/radio-sensor.h"
|
||||||
|
#include "dev/sensor-common.h"
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "net/packetbuf.h"
|
||||||
|
#include "st-lib.h"
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int _active;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void init(void)
|
||||||
|
{
|
||||||
|
/*Nothing to do at the moment, can be used in the future.*/
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void activate(void)
|
||||||
|
{
|
||||||
|
_active = 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void deactivate(void)
|
||||||
|
{
|
||||||
|
_active = 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int active(void)
|
||||||
|
{
|
||||||
|
return _active;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int value(int type)
|
||||||
|
{
|
||||||
|
int32_t radio_sensor;
|
||||||
|
float radio_sensor_value;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case RADIO_SENSOR_LAST_PACKET:
|
||||||
|
/*TODO: check which method of getting these value is more appropriate */
|
||||||
|
radio_sensor_value = DBM_VALUE(packetbuf_attr(PACKETBUF_ATTR_RSSI));
|
||||||
|
//radio_sensor_value = st_lib_spirit_qi_get_rssi_dbm();
|
||||||
|
radio_sensor = (int32_t) (radio_sensor_value * 10);
|
||||||
|
break;
|
||||||
|
case RADIO_SENSOR_LAST_VALUE:
|
||||||
|
default:
|
||||||
|
/*TODO: check which method of getting these value is more appropriate */
|
||||||
|
radio_sensor = packetbuf_attr(PACKETBUF_ATTR_LINK_QUALITY);
|
||||||
|
//radio_sensor = (int32_t) st_lib_spirit_qi_get_lqi();
|
||||||
|
}
|
||||||
|
|
||||||
|
return radio_sensor;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int configure(int type, int value)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_HW_INIT:
|
||||||
|
init();
|
||||||
|
return 1;
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if(value) {
|
||||||
|
activate();
|
||||||
|
} else {
|
||||||
|
deactivate();
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_READY:
|
||||||
|
return active();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR, value, configure, status);
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/** @} */
|
|
@ -50,6 +50,9 @@
|
||||||
#define X_AXIS 0x00
|
#define X_AXIS 0x00
|
||||||
#define Y_AXIS 0x01
|
#define Y_AXIS 0x01
|
||||||
#define Z_AXIS 0x02
|
#define Z_AXIS 0x02
|
||||||
|
|
||||||
|
#define ABS_VALUE(x) (((x)>0)?(x):(-(x)))
|
||||||
|
#define DBM_VALUE(x) (-120.0+((float)((x)-20))/2)
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#endif /*SENSOR_COMMON_H_*/
|
#endif /*SENSOR_COMMON_H_*/
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#define PLATFORM_HAS_LEDS 1
|
#define PLATFORM_HAS_LEDS 1
|
||||||
#define PLATFORM_HAS_BUTTON 1
|
#define PLATFORM_HAS_BUTTON 1
|
||||||
|
#define PLATFORM_HAS_RADIO 1
|
||||||
|
|
||||||
#define LEDS_GREEN 1 /*Nucleo LED*/
|
#define LEDS_GREEN 1 /*Nucleo LED*/
|
||||||
#define LEDS_RED 2 /*SPIRIT1 LED*/
|
#define LEDS_RED 2 /*SPIRIT1 LED*/
|
||||||
|
|
|
@ -81,6 +81,8 @@ extern volatile st_lib_spirit_flag_status rx_timeout;
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static volatile unsigned int spirit_on = OFF;
|
static volatile unsigned int spirit_on = OFF;
|
||||||
static volatile uint8_t receiving_packet = 0;
|
static volatile uint8_t receiving_packet = 0;
|
||||||
|
static packetbuf_attr_t last_rssi = 0 ; //MGR
|
||||||
|
static packetbuf_attr_t last_lqi = 0 ; //MGR
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
* The buffers which hold incoming data.
|
* The buffers which hold incoming data.
|
||||||
|
@ -407,6 +409,8 @@ static int spirit_radio_read(void *buf, unsigned short bufsize)
|
||||||
/* Copies the packet received */
|
/* Copies the packet received */
|
||||||
memcpy(buf, spirit_rxbuf + 1, spirit_rxbuf[0]);
|
memcpy(buf, spirit_rxbuf + 1, spirit_rxbuf[0]);
|
||||||
|
|
||||||
|
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, last_rssi); //MGR
|
||||||
|
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, last_lqi); //MGR
|
||||||
bufsize = spirit_rxbuf[0];
|
bufsize = spirit_rxbuf[0];
|
||||||
CLEAR_RXBUF();
|
CLEAR_RXBUF();
|
||||||
|
|
||||||
|
@ -685,6 +689,9 @@ spirit1_interrupt_callback(void)
|
||||||
|
|
||||||
process_poll(&spirit_radio_process);
|
process_poll(&spirit_radio_process);
|
||||||
|
|
||||||
|
last_rssi = (packetbuf_attr_t) st_lib_spirit_qi_get_rssi(); //MGR
|
||||||
|
last_lqi = (packetbuf_attr_t) st_lib_spirit_qi_get_lqi(); //MGR
|
||||||
|
|
||||||
receiving_packet = 0;
|
receiving_packet = 0;
|
||||||
|
|
||||||
#if NULLRDC_CONF_802154_AUTOACK
|
#if NULLRDC_CONF_802154_AUTOACK
|
||||||
|
|
Loading…
Reference in a new issue