diff --git a/arch/platform/sky/Makefile.sky b/arch/platform/sky/Makefile.sky index 5f1a5aa99..9f86b6499 100644 --- a/arch/platform/sky/Makefile.sky +++ b/arch/platform/sky/Makefile.sky @@ -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 diff --git a/arch/platform/sky/dev/radio-sensor.c b/arch/platform/sky/dev/radio-sensor.c deleted file mode 100644 index cf2b60ec4..000000000 --- a/arch/platform/sky/dev/radio-sensor.c +++ /dev/null @@ -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); diff --git a/examples/ipv6/coap-example/coap-example-server.c b/examples/ipv6/coap-example/coap-example-server.c index d8e1c79b2..79c25d501 100644 --- a/examples/ipv6/coap-example/coap-example-server.c +++ b/examples/ipv6/coap-example/coap-example-server.c @@ -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"); diff --git a/examples/ipv6/coap-example/resources/res-radio.c b/examples/ipv6/coap-example/resources/res-radio.c index ac09319a3..b33bf703a 100644 --- a/examples/ipv6/coap-example/resources/res-radio.c +++ b/examples/ipv6/coap-example/resources/res-radio.c @@ -42,13 +42,13 @@ #include #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); diff --git a/os/dev/radio-sensor.h b/os/dev/radio-sensor.h deleted file mode 100644 index 601f129cf..000000000 --- a/os/dev/radio-sensor.h +++ /dev/null @@ -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_ */