Removed obsolete radio-sensor API

This commit is contained in:
Niclas Finne 2017-10-13 01:06:47 +02:00
parent 91b8ee860e
commit 358385b450
5 changed files with 19 additions and 145 deletions

View File

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

View File

@ -1,75 +0,0 @@
/*
* 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);

View File

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

View File

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

View File

@ -1,46 +0,0 @@
/*
* 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_ */