Commit 7af63c74 authored by Joakim Eriksson's avatar Joakim Eriksson Committed by GitHub
Browse files

Merge pull request #96 from sics-iot/contrib/remove-radio-sensor

Removed obsolete radio-sensor API
parents 8f765152 358385b4
......@@ -2,7 +2,7 @@
CONTIKI_TARGET_SOURCEFILES += contiki-sky-platform.c \
sht11.c sht11-sensor.c light-sensor.c battery-sensor.c \
button-sensor.c radio-sensor.c
button-sensor.c
include $(CONTIKI)/arch/platform/sky/Makefile.common
......
/*
* Copyright (c) 2005, 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.
*
*/
#include "lib/sensors.h"
#include "cc2420.h"
#include "dev/radio-sensor.h"
const struct sensors_sensor radio_sensor;
static int active;
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
switch(type) {
case RADIO_SENSOR_LAST_PACKET:
return cc2420_last_correlation;
case RADIO_SENSOR_LAST_VALUE:
default:
return cc2420_last_rssi;
}
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
if(type == SENSORS_ACTIVE) {
active = c;
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return active;
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
value, configure, status);
......@@ -91,7 +91,6 @@ extern resource_t res_temperature;
extern resource_t res_battery;
#endif
#if PLATFORM_HAS_RADIO
#include "dev/radio-sensor.h"
extern resource_t res_radio;
#endif
#if PLATFORM_HAS_SHT11
......@@ -157,8 +156,7 @@ PROCESS_THREAD(er_example_server, ev, data)
#endif
/*
#if PLATFORM_HAS_RADIO
rest_activate_resource(&res_radio, "sensors/radio");
SENSORS_ACTIVATE(radio_sensor);
rest_activate_resource(&res_radio, "sensors/radio");
#endif
#if PLATFORM_HAS_SHT11
rest_activate_resource(&res_sht11, "sensors/sht11");
......
......@@ -42,13 +42,13 @@
#include <string.h>
#include "rest-engine.h"
#include "dev/radio-sensor.h"
#include "net/netstack.h"
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
/* A simple getter example. Returns the reading of the rssi/lqi from radio sensor */
RESOURCE(res_radio,
"title=\"RADIO: ?p=lqi|rssi\";rt=\"RadioSensor\"",
"title=\"RADIO: ?p=rssi\";rt=\"RadioSensor\"",
res_get_handler,
NULL,
NULL,
......@@ -59,36 +59,33 @@ res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferr
{
size_t len = 0;
const char *p = NULL;
uint8_t param = 0;
int success = 1;
radio_value_t value;
int8_t rssi = 0;
int success = 0;
unsigned int accept = -1;
REST.get_header_accept(request, &accept);
if((len = REST.get_query_variable(request, "p", &p))) {
if(strncmp(p, "lqi", len) == 0) {
param = RADIO_SENSOR_LAST_VALUE;
} else if(strncmp(p, "rssi", len) == 0) {
param = RADIO_SENSOR_LAST_PACKET;
} else {
success = 0;
if(strncmp(p, "rssi", len) == 0) {
if(NETSTACK_RADIO.get_value(RADIO_PARAM_RSSI, &value) ==
RADIO_RESULT_OK) {
success = 1;
rssi = (int8_t)value;
}
}
} else {
success = 0;
} if(success) {
}
if(success) {
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", radio_sensor.value(param));
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", rssi);
REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer));
} else if(accept == REST.type.APPLICATION_JSON) {
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
if(param == RADIO_SENSOR_LAST_VALUE) {
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'lqi':%d}", radio_sensor.value(param));
} else if(param == RADIO_SENSOR_LAST_PACKET) {
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'rssi':%d}", radio_sensor.value(param));
}
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'rssi':%d}", rssi);
REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else {
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
......
/*
* Copyright (c) 2005, 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.
*
*/
#ifndef RADIO_SENSOR_H_
#define RADIO_SENSOR_H_
#include "lib/sensors.h"
extern const struct sensors_sensor radio_sensor;
#define RADIO_SENSOR_LAST_VALUE 0
#define RADIO_SENSOR_LAST_PACKET 1
#define RADIO_SENSOR "Radio"
extern unsigned int radio_sensor_signal;
#endif /* RADIO_SENSOR_H_ */
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