
The MCR20A Wireless UART application functions as an wireless UART bridge between two (one-to-one) or several (one to many) boards. The application can be used with both a TERM, or with software that is capable of opening a serial port and writing to or reading from it. The characters sent or received are not necessarily ASCII printable characters.
Dependencies: fsl_phy_mcr20a fsl_smac mbed-rtos mbed
Fork of mcr20_wireless_uart by
By default, the application uses broadcast addresses for OTA communication. This way, the application can be directly downloaded and run without any user intervention. The following use case assumes no changes have been done to the project.
- Two (or more) MCR20A platforms (plugged into the FRDM-K64F Freescale Freedom Development platform) have to be connected to the PC using the mini/micro-USB cables.
- The code must be downloaded on the platforms via CMSIS-DAP (or other means).
- After that, two or more TERM applications must be opened, and the serial ports must be configured with the same baud rate as the one in the project (default baud rate is 115200). Other necessary serial configurations are 8 bit, no parity, and 1 stop bit.
- To start the setup, each platform must be reset, and one of the (user) push buttons found on the MCR20A platform must be pressed. The user can press any of the non-reset buttons on the FRDM-K64F Freescale Freedom Development platform as well. *This initiates the state machine of the application so user can start.
Documentation
SMAC Demo Applications User Guide
Revision 3:a38ad504a18c, committed 2015-03-05
- Comitter:
- sam_grove
- Date:
- Thu Mar 05 16:37:54 2015 +0000
- Parent:
- 2:3e7685cfb2a7
- Child:
- 4:d47832caea44
- Child:
- 5:69f1634cd40b
- Commit message:
- Delete multi use functions and update mbed library - exporters for IAR now working again
Changed in this revision
--- a/BMP085.lib Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/okini3939/code/BMP085/#5e2b1f3c0a6a
--- a/NSDL/nsdl_run.cpp Thu Mar 05 15:47:08 2015 +0000 +++ b/NSDL/nsdl_run.cpp Thu Mar 05 16:37:54 2015 +0000 @@ -6,14 +6,6 @@ #include "rgb.h" #include "battery.h" -#include "light.h" -#include "HVAC.h" -#include "door.h" -#include "pressure.h" -#include "temperature.h" -#include "moisture.h" -#include "hcho.h" -#include "UVsensor.h" // ****************************************************************************
--- a/Resources/HVAC.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -#include "mbed.h" -#include "nsdl_support.h" -#include "HVAC.h" - -#include "node_cfg.h" - -#define HVAC_RES_ID "/306/0/5853" -#define HVAC_RES_RT "HVAC Control" - -#if NODE_HOME -extern uint8_t motion_disable; -extern DigitalOut fan; -extern DigitalOut fire; - -/* GET and PUT method allowed */ -static uint8_t HVAC_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - - printf("HVAC callback\r\n"); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - uint8_t var[7]; - - if (fan) { - coap_res_ptr->payload_len = 7; - memcpy(var,"COOLING", 7); - }else if (fire) { - coap_res_ptr->payload_len = 7; - memcpy(var,"HEATING", 7); - }else { - coap_res_ptr->payload_len = 3; - memcpy(var,"OFF", 3); - } - coap_res_ptr->payload_ptr = var; - sn_nsdl_send_coap_message(address, coap_res_ptr); - } - else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) - { - if(received_coap_ptr->payload_len) - { - if(*(received_coap_ptr->payload_ptr) == 'O') // OFF - { - fan = 0; - fire = 0; - } - else if(*(received_coap_ptr->payload_ptr) == 'C') // COOLING - { - fan = 1; - fire = 0; - } - else if(*(received_coap_ptr->payload_ptr) == 'H') // HEATING - { - fan = 0; - fire = 1; - } - motion_disable = 1; - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED); - sn_nsdl_send_coap_message(address, coap_res_ptr); - } - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - - -int create_HVAC_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(HVAC_RES_ID)-1, (uint8_t*)HVAC_RES_ID, sizeof(HVAC_RES_RT)-1, (uint8_t*)HVAC_RES_RT, 0, &HVAC_resource_cb, (SN_GRS_GET_ALLOWED | SN_GRS_PUT_ALLOWED)); - return 0; -} -#endif \ No newline at end of file
--- a/Resources/HVAC.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#ifndef HVAC_H -#define HVAC_H - -#include "nsdl_support.h" - -int create_HVAC_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif // HVAC
--- a/Resources/UVsensor.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -// UV sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" - -#include "node_cfg.h" - -#define UV_SENSOR_RES_ID "/uv/value" -#define UV_SENSOR_RES_RT "UV Sensor" - -#if NODE_SENSOR_STATION -extern AnalogIn UVsensor; -char uv[6]; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -/* Only GET method allowed */ -static uint8_t UVsensor_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - sprintf(uv,"%3.2f", (float)UVsensor*100); - printf("UV sensor callback\r\n"); - printf("UV sensor: %s\r\n", uv); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - coap_res_ptr->payload_len = strlen(uv); - coap_res_ptr->payload_ptr = (uint8_t*)uv; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s)); - if(!coap_res_ptr->options_list_ptr) - { - printf("cant alloc option list for max-age\r\n"); - coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover - } - memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->max_age_ptr = &max_age; - coap_res_ptr->options_list_ptr->max_age_len = sizeof(max_age); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_UVsensor_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(UV_SENSOR_RES_ID)-1, (uint8_t*)UV_SENSOR_RES_ID, sizeof(UV_SENSOR_RES_RT)-1, (uint8_t*)UV_SENSOR_RES_RT, 0, &UVsensor_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/UVsensor.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// UV sensor resource implementation - -#ifndef UV_SENSOR_H -#define UV_SENSOR_H - -#include "nsdl_support.h" - -int create_UVsensor_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif // UV_SENSOR
--- a/Resources/door.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -// Door switch resource implementation - -#include "mbed.h" -#include "nsdl_support.h" - -#include "node_cfg.h" - -#define DOOR_RES_ID "/door/state" -#define DOOR_RES_RT "Door state" - -#if NODE_HOME -extern DigitalIn door; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -/* GET method allowed */ -static uint8_t door_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - - printf("door callback\r\n"); - - printf("Door state %d\r\n", (uint32_t)door); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - uint8_t var[7]; - if (door) { - coap_res_ptr->payload_len = 4; - memcpy(var,"Open", 4); - }else{ - coap_res_ptr->payload_len = 5; - memcpy(var,"Close", 5); - } - coap_res_ptr->payload_ptr = var; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s)); - if(!coap_res_ptr->options_list_ptr) - { - printf("cant alloc option list for max-age\r\n"); - coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover - } - memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->max_age_ptr = &max_age; - coap_res_ptr->options_list_ptr->max_age_len = sizeof(max_age); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_door_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(DOOR_RES_ID)-1, (uint8_t*)DOOR_RES_ID, sizeof(DOOR_RES_RT)-1, (uint8_t*)DOOR_RES_RT, 0, &door_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif -
--- a/Resources/door.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Door sensor resource implementation - -#ifndef DOOR_SWITCH_H -#define DOOR_SWITCH_H - -#include "nsdl_support.h" - -int create_door_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif \ No newline at end of file
--- a/Resources/hcho.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -// HCHO (formaldehyde) sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" - -#include "node_cfg.h" - -#define HCHO_RES_ID "hcho/value" -#define HCHO_RES_RT "HCHO" - -#if NODE_SENSOR_STATION -extern AnalogIn HCHO; -char hcho[6]; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -/* Only GET method allowed */ -static uint8_t hcho_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - sprintf(hcho,"%3.2f", (float)HCHO*100); - printf("HCHO callback\r\n"); - printf("HCHO: %s Percent\r\n", hcho); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - coap_res_ptr->payload_len = strlen(hcho); - coap_res_ptr->payload_ptr = (uint8_t*)hcho; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s)); - if(!coap_res_ptr->options_list_ptr) - { - printf("cant alloc option list for max-age\r\n"); - coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover - } - memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->max_age_ptr = &max_age; - coap_res_ptr->options_list_ptr->max_age_len = sizeof(max_age); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_hcho_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(HCHO_RES_ID)-1, (uint8_t*)HCHO_RES_ID, sizeof(HCHO_RES_RT)-1, (uint8_t*)HCHO_RES_RT, 0, &hcho_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/hcho.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -// HCHO sensor resource implementation - -#ifndef HCHO_H -#define HCHO_H - -#include "nsdl_support.h" - -int create_hcho_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif // HCHO -
--- a/Resources/light.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -#include "mbed.h" -#include "nsdl_support.h" -#include "light.h" - -#include "node_cfg.h" - -#define LIGHT_RES_ID "311/0/5850" -#define LIGHT_RES_RT "Light" - -#if NODE_HOME -extern DigitalOut light; -extern uint8_t motion_disable; - -/* GET and PUT method allowed */ -static uint8_t light_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - - printf("light callback\r\n"); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - uint8_t var[3]; - if (light) { - coap_res_ptr->payload_len = 2; - memcpy(var,"On", 2); - }else{ - coap_res_ptr->payload_len = 3; - memcpy(var,"Off", 3); - } - coap_res_ptr->payload_ptr = var; - sn_nsdl_send_coap_message(address, coap_res_ptr); - } - else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) - { - if(received_coap_ptr->payload_len) - { - if(*(received_coap_ptr->payload_ptr+1) == 'n') - { - light = 1; - - } - else if(*(received_coap_ptr->payload_ptr+1) == 'f') - { - light = 0; - } - motion_disable = 1; - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED); - sn_nsdl_send_coap_message(address, coap_res_ptr); - } - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_light_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(LIGHT_RES_ID)-1, (uint8_t*)LIGHT_RES_ID, sizeof(LIGHT_RES_RT)-1, (uint8_t*)LIGHT_RES_RT, 0, &light_resource_cb, (SN_GRS_GET_ALLOWED | SN_GRS_PUT_ALLOWED)); - return 0; -} -#endif
--- a/Resources/light.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#ifndef LIGHT_H -#define LIGHT_H - -#include "nsdl_support.h" - -int create_light_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif // LIGHT
--- a/Resources/moisture.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -// moisture sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" - -#include "node_cfg.h" - -#define MOISTURE_RES_ID "3304/0/5700" -#define MOISTURE_RES_RT "Moisture" - -#if NODE_SENSOR_STATION -extern AnalogIn moisture; -char moist[6]; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -/* Only GET method allowed */ -static uint8_t moisture_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - sprintf(moist,"%2.2f", (float)moisture*100); - printf("moisture callback\r\n"); - printf("moisture: %s\r\n", moist); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - coap_res_ptr->payload_len = strlen(moist); - coap_res_ptr->payload_ptr = (uint8_t*)moist; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s)); - if(!coap_res_ptr->options_list_ptr) - { - printf("cant alloc option list for max-age\r\n"); - coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover - } - memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->max_age_ptr = &max_age; - coap_res_ptr->options_list_ptr->max_age_len = sizeof(max_age); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_moisture_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(MOISTURE_RES_ID)-1, (uint8_t*)MOISTURE_RES_ID, sizeof(MOISTURE_RES_RT)-1, (uint8_t*)MOISTURE_RES_RT, 0, &moisture_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/moisture.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -// Moisture sensor resource implementation - -#ifndef MOISTURE_H -#define MOISTURE_H - -#include "nsdl_support.h" - -int create_moisture_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif // MOISTURE -
--- a/Resources/pressure.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -// barometer sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" - -#include "node_cfg.h" - -#include "BMP085.h" - -#define PRESSURE_RES_ID "3315/0/5700" -#define PRESSURE_RES_RT "Barometer" - -#if NODE_SENSOR_STATION -extern BMP085 barometer; -float pressure; -char press[7]; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -/* Only GET method allowed */ -static uint8_t pressure_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - barometer.update(); - pressure = barometer.get_pressure(); - sprintf(press,"%6.2f", pressure); - printf("pressure callback\r\n"); - printf("pressure: %s\r\n", press); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - coap_res_ptr->payload_len = strlen(press); - coap_res_ptr->payload_ptr = (uint8_t*)press; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s)); - if(!coap_res_ptr->options_list_ptr) - { - printf("cant alloc option list for max-age\r\n"); - coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover - } - memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->max_age_ptr = &max_age; - coap_res_ptr->options_list_ptr->max_age_len = sizeof(max_age); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_pressure_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(PRESSURE_RES_ID)-1, (uint8_t*)PRESSURE_RES_ID, sizeof(PRESSURE_RES_RT)-1, (uint8_t*)PRESSURE_RES_RT, 0, &pressure_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif -
--- a/Resources/pressure.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Barometer sensor resource implementation - -#ifndef PRESSURE_H -#define PRESSURE_H - -#include "nsdl_support.h" - -int create_pressure_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif // PRESSURE
--- a/Resources/temperature.cpp Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -// temperature (from barometer) sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" - -#include "node_cfg.h" - -#include "BMP085.h" - -#define TEMPERATURE_RES_ID "3303/0/5700" -#define TEMPERATURE_RES_RT "Temperature" - -#if NODE_SENSOR_STATION -extern BMP085 barometer; -float temperature; -char temp[7]; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -/* Only GET method allowed */ -static uint8_t temperature_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) -{ - sn_coap_hdr_s *coap_res_ptr = 0; - barometer.update(); - temperature = barometer.get_temperature(); - sprintf(temp,"%6.2f", temperature); - printf("temperature callback\r\n"); - printf("temperature: %s\r\n", temp); - - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { - coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - - coap_res_ptr->payload_len = strlen(temp); - coap_res_ptr->payload_ptr = (uint8_t*)temp; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s)); - if(!coap_res_ptr->options_list_ptr) - { - printf("cant alloc option list for max-age\r\n"); - coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover - } - memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->max_age_ptr = &max_age; - coap_res_ptr->options_list_ptr->max_age_len = sizeof(max_age); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_temperature_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - nsdl_create_dynamic_resource(resource_ptr, sizeof(TEMPERATURE_RES_ID)-1, (uint8_t*)TEMPERATURE_RES_ID, sizeof(TEMPERATURE_RES_RT)-1, (uint8_t*)TEMPERATURE_RES_RT, 0, &temperature_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/temperature.h Thu Mar 05 15:47:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -// Temperature (from Barometer) sensor resource implementation - -#ifndef TEMPERATURE_H -#define TEMPERATURE_H - -#include "nsdl_support.h" - -int create_temperature_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif // TEMPERATURE -
--- a/main.cpp Thu Mar 05 15:47:08 2015 +0000 +++ b/main.cpp Thu Mar 05 16:37:54 2015 +0000 @@ -1,7 +1,6 @@ #include "mbed.h" #include "driverDebug.h" - #include "socket_api.h" #include "net_interface.h" #include "system_event.h" @@ -16,19 +15,11 @@ #include "common_functions.h" #include "driverRFPhy.h" #include "driverAtmelRFInterface.h" - #include "nsdl_support.h" #include "node_cfg.h" -#if NODE_SENSOR_STATION -// #include "DHT.h" - #include "BMP085.h" -#endif - - /*** DEBUG ******/ #define DEBUG 1 - #if DEBUG #define debug printf #else @@ -43,22 +34,6 @@ InterruptIn TAP_INT(PTC6); // INT1 from FXOS8700Q #endif -#if NODE_HOME -DigitalOut light(D2); -DigitalOut fire(D3); -DigitalOut fan(D4); -InterruptIn motion(D6); -DigitalIn door(D8); -#endif - -#if NODE_SENSOR_STATION -//DHT sensor(D2, DHT11); -BMP085 barometer(D14, D15); -AnalogIn moisture(A0); -AnalogIn HCHO(A1); -AnalogIn UVsensor(A2); -#endif - /******* Timers Definitions ************/ #define RETRY_TIMER 1 #define NSP_REGISTRATION_TIMER 2 @@ -69,17 +44,14 @@ #define DOOR_CHECK_TIMER 4 #endif - void app_heap_error_handler(heap_fail_t event); void tasklet_main(arm_event_s *event); void button_main(arm_event_s *event); - #define APP_DEV_HEAP_SIZE 6000 static uint8_t app_defined_stack_heap[APP_DEV_HEAP_SIZE]; static int8_t main_tasklet_id = -1; - static const uint8_t app_MAC_address[8] = NODE_MAC_ADDRESS; static int8_t rf_phy_device_register_id = -1; static int8_t net_6lowpan_id = -1; @@ -87,12 +59,12 @@ int8_t coap_udp_socket = -1; -#define AUDP_SOCKET_PORT 61630 +#define AUDP_SOCKET_PORT 61630 #define RECV_CTRL_UDP_PORT 1050 // receive #define SEND_CTRL_UDP_PORT 1060 // send /** Used for Receive Data source Address store*/ -static ns_address_t app_src; +static ns_address_t app_src; static sn_nsdl_addr_s sn_addr_s; static int access_point_status = 0; @@ -116,19 +88,6 @@ /* #defines, definitions and declarations according node profile */ -#if NODE_HOME -#define DOOR_CHECK_TIME 1000 -uint8_t door_last_state = 0; -/* Since the PIR Motion detector throws a (false) trigger everytime the -other sensors/actuators change (possibly an interference), we will need -to disable it for 1s. So every time the sensors/actuators change, we set a variable -which is reset in the DOOR_CHECK_TIMER. This variable needs to be cleared to -consider a real motion detection */ -uint8_t motion_disable = 0; -int8_t ctrl_udp_socket = -1; -void ctrl_udp_receive(void * cb); -void ctrl_udp_send(uint8_t cmd); -#endif #if NODE_CONTROLLER int8_t ctrl_udp_socket = -1; @@ -362,20 +321,6 @@ } #endif -#if NODE_HOME -void motion_handler(void) -{ - if (motion_disable) - return; - printf("***************Motion Detected!**********************\r\n"); - if (door) - ctrl_udp_send('O'); - else - ctrl_udp_send('C'); -} -#endif - - int main() { #if NODE_CONTROLLER @@ -385,11 +330,6 @@ TAP_INT.rise(&tap_detector_handler); #endif -#if NODE_HOME - light = 0; - motion.rise(&motion_handler); -#endif - debug("\r\nApplication Start\r\n"); ns_dyn_mem_init(app_defined_stack_heap, APP_DEV_HEAP_SIZE, app_heap_error_handler,0); rf_set_mac_address(app_MAC_address); @@ -594,13 +534,6 @@ timer_sys_event(ACCELEROMETER_TIMER, ACCEL_SAMPLE_TIME); #endif multicast_set_parameters(10,0,20,3,75 ); - -#if NODE_HOME - /* open a socket to support control from NODE_CONTROLLER */ - ctrl_udp_socket = socket_open(SOCKET_UDP, RECV_CTRL_UDP_PORT, ctrl_udp_receive); - /* init a timer to check door state */ - timer_sys_event(DOOR_CHECK_TIMER, DOOR_CHECK_TIME); -#endif #if NODE_CONTROLLER /* open a socket to support control for REMOTE_NODE */ @@ -693,19 +626,7 @@ timer_sys_event(ACCELEROMETER_TIMER, ACCEL_SAMPLE_TIME); } #endif -#if NODE_HOME - else if (event->event_id == DOOR_CHECK_TIMER) - { - uint8_t door_state = door.read(); - if (door_state != door_last_state) - { - door_last_state = door_state; - printf("Door state %d\r\n", door_state); - } - motion_disable = 0; - timer_sys_event(DOOR_CHECK_TIMER, DOOR_CHECK_TIME); - } -#endif + break; default: @@ -773,112 +694,6 @@ #endif } -#if NODE_HOME -/****** Control UDP Socket Receive *******/ -void ctrl_udp_receive(void * cb) -{ - socket_callback_t * cb_res =0; - int16_t length; - cb_res = (socket_callback_t *) cb; - - if(cb_res->event_type == SOCKET_DATA) - { - uint8_t *payload = 0; - /*Read Data*/ - if ( cb_res->d_len > 0) - { - /*Read data to the RX buffer*/ - payload = (uint8_t *) ns_dyn_mem_alloc(cb_res->d_len); - if(payload) - { - /*Read data to the RX buffer*/ - length = socket_read(cb_res->socket_id, &app_src, payload, cb_res->d_len); - if(length) - { - uint8_t * ptr = payload ; - /*Handles data received in UDP socket*/ - debug("UDP Data From: "); - printf_ipv6_address(&(app_src.address[0])); //REVIEW - - if(app_src.identifier == SEND_CTRL_UDP_PORT) // check source port to avoid interference - { - debug("Data: "); - printf("%s\r\n",ptr); - switch(payload[0]) { - case 'R': - fire = !fire; - fan = 0; - break; - case 'G': - light = !light; - break; - case 'B': - fan = !fan; - fire = 0; - break; - } - motion_disable = 1; - } - } - ns_dyn_mem_free(payload); - } - } - else - { - debug("No Data\r\n"); - socket_read(cb_res->socket_id, &app_src, NULL, 0); - } - } - else if(cb_res->event_type == SOCKET_TX_DONE) - { - debug("UDP TX Done\r\n"); - } - /* No Route to Packet Destination Address */ - else if(cb_res->event_type == SOCKET_NO_ROUTE) - { - debug("ND/RPL not ready\r\n"); - } - /* Link Layer TX Fail for socket packet */ - else if(cb_res->event_type == SOCKET_TX_FAIL) - { - debug("Link Layer Tx fail\r\n"); - } -} - -void ctrl_udp_send(uint8_t cmd) -{ - uint8_t * payload = 0; - ns_address_t address; - /*SET UDP echo Port*/ - address.identifier = ALARM_CTRL_UDP_PORT; - - uint8_t node_address[16] = ALARM_IP_ADDRESS; - - payload = (uint8_t *) ns_dyn_mem_alloc(1); - if(payload) - { - uint8_t *ptr = payload; - - memcpy(address.address,node_address,16); - address.type = ADDRESS_IPV6; - *ptr = cmd; - if(socket_sendto(ctrl_udp_socket, &address, payload, (1)) != 0) - { - debug("Ctrl UDP Failed\r\n"); - } - else - { - debug("Ctrl UDP Ok\r\n"); - } - ns_dyn_mem_free(payload); - } - else - { - debug("No Heap for Ctrl UDP\r\n"); - } -} -#endif - #if NODE_CONTROLLER void ctrl_udp_send(uint8_t cmd) {
--- a/mbed.bld Thu Mar 05 15:47:08 2015 +0000 +++ b/mbed.bld Thu Mar 05 16:37:54 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf \ No newline at end of file