MBED NanoService Lighting Endpoint for NXP Ublox (Ethernet enabled)
Dependencies: C027 C12832 EthernetInterface StatusReporter LM75B endpoint_core endpoint_nsp mbed-rtos mbed nsp_resources
Revision 144:b0c44be7fe5b, committed 2014-03-25
- Comitter:
- ansond
- Date:
- Tue Mar 25 03:21:09 2014 +0000
- Parent:
- 143:0698dbcf58f5
- Child:
- 145:617ba2d71359
- Commit message:
- updates
Changed in this revision
--- a/NSPResourceFactory.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/NSPResourceFactory.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -35,6 +35,9 @@ // MBED supports GPS location observation #include "gps.h" + // MBED supports RSSI observation + #include "rssi.h" + // MBED supports Temperature Sensing #include "temperature.h" @@ -44,6 +47,9 @@ // MBED supports Voltage Emulation #include "voltage.h" + // MBED supports Wattage Emulation + #include "wattage.h" + // MBED support Current Emulation #include "current.h" @@ -105,13 +111,13 @@ this->createResource("/nw/eripaddr","N/A","core#s","ns:v4addr"); this->createResource(ep_name,"/lt/0/on","1",(void *)&switch_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED),(void *)&init_switch,(char *)NULL,"ipso:lt-on"); // Action: light on/off //this->createResource(ep_name,"/lt/0/ctr","1",(void *)&switch_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED),(void *)&init_switch,(char *)NULL,"ns:boolean"); // Action: light on/off - this->createResource("/dev/mdl","Sensinode MBED Light",(char *)NULL,"ipso:dev-mdl"); - this->createResource("/dev/mfg","NXP MBED",(char *)NULL,"ipso:dev-mdl"); - this->createResource("/gps/int","0","core#s","ns:counter"); + this->createResource("/dev/mdl","Sensinode MBED Light","core#s","ipso:dev-mdl"); + this->createResource("/dev/mfg","NXP MBED","core#s","ipso:dev-mfg"); + this->createResource("/gps/int","60","core#s","ns:counter"); this->createResource("/gps/fix","1","core#s","ns:boolean"); this->createResource("/nw/pipaddr","N/A","core#s","ns:v4addr"); - this->createResource("/nw/prssi","-75","core#s","ns:rssi"); - this->createResource("/dev/W","0.1",(char *)NULL,"ucum:W"); + this->createResource(ep_name,"/nw/prssi","-75",(void *)&rssi_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_rssi,"core#s","ns:rssi"); + this->createResource(ep_name,"/dev/W","0.1",(void *)&wattage_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_wattage,(char *)NULL,"ucum:W"); this->createResource(ep_name,"/sen/temp","10.0",(void *)&temp_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_temp,(char *)NULL,"ucum:Cel"); this->createResource(ep_name,"/dev/t","10.0",(void *)&temp_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_temp,(char *)NULL,"ucum:Cel"); this->createResource(ep_name,"/sen/V","5.0",(void *)&voltage_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_voltage,(char *)NULL,"ucum:V"); @@ -131,7 +137,7 @@ //this->createResource("/lt/0/sched_elem","0"); //this->createResource("/lt/0/totKwh","6.23"); //this->createResource("/nw/utlz","0.01"); - this->createResource("/dev/panic","0","core#s","ns:panic"); + this->createResource(ep_name,"/dev/panic","0",(void *)&switch_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED),(void *)&init_switch,"core#s","ns:panic"); #ifdef MAC_ADDRESS extern char fmt_mac[RESOURCE_VALUE_LEN+1];
--- a/endpoint_core.lib Mon Mar 24 19:53:20 2014 +0000 +++ b/endpoint_core.lib Tue Mar 25 03:21:09 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/ansond/code/endpoint_core/#979332edc1c2 +http://mbed.org/users/ansond/code/endpoint_core/#3e63174bcbc6
--- a/nsp_resources/addldata.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/addldata.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -16,8 +16,10 @@ // send our addldata observation void send_addldata_observation() { - if (addldata_obs_token_ptr != NULL && addldata_obs_number != 0) + if (addldata_obs_token_ptr != NULL && addldata_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (addldata): %s",addldata->resource()->getValuePointer()); sn_nsdl_send_observation_notification(addldata_obs_token_ptr,addldata_obs_token_len,(uint8_t*)addldata->resource()->getValuePointer(),strlen(addldata->resource()->getValuePointer()),&addldata_obs_number,sizeof(addldata_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init addldata @@ -27,24 +29,23 @@ // update our addldata observation void update_addldata_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(addldata_obs_token_ptr) { - free(addldata_obs_token_ptr); - addldata_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (addldata)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (addldata_obs_token_ptr != NULL) free(addldata_obs_token_ptr); addldata_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(addldata_obs_token_ptr) { + if(addldata_obs_token_ptr != NULL) { memcpy(addldata_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); addldata_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(addldata_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; addldata_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (addldata)...done"); } /* Only GET and PUT method allowed */
--- a/nsp_resources/battery.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/battery.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -15,8 +15,10 @@ // send our battery observation void send_battery_observation() { - if (battery_obs_token_ptr != NULL && battery_obs_number != 0) + if (battery_obs_token_ptr != NULL && battery_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (battery): %s",battery->resource()->getValuePointer()); sn_nsdl_send_observation_notification(battery_obs_token_ptr,battery_obs_token_len,(uint8_t*)battery->resource()->getValuePointer(),strlen(battery->resource()->getValuePointer()),&battery_obs_number,sizeof(battery_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init battery @@ -26,24 +28,23 @@ // update our battery observation void update_battery_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(battery_obs_token_ptr) { - free(battery_obs_token_ptr); - battery_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (batter)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (battery_obs_token_ptr != NULL) free(battery_obs_token_ptr); battery_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(battery_obs_token_ptr) { + if(battery_obs_token_ptr != NULL) { memcpy(battery_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); battery_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(battery_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; battery_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (battery)...done"); } /* Only GET method allowed */
--- a/nsp_resources/current.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/current.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -15,8 +15,10 @@ // send our current observation void send_current_observation() { - if (current_obs_token_ptr != NULL && current_obs_number != 0) + if (current_obs_token_ptr != NULL && current_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (current): %s",current->resource()->getValuePointer()); sn_nsdl_send_observation_notification(current_obs_token_ptr,current_obs_token_len,(uint8_t*)current->resource()->getValuePointer(),strlen(current->resource()->getValuePointer()),¤t_obs_number,sizeof(current_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init current @@ -26,24 +28,23 @@ // update our current observation void update_current_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(current_obs_token_ptr) { - free(current_obs_token_ptr); - current_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (current)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (current_obs_token_ptr != NULL) free(current_obs_token_ptr); current_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(current_obs_token_ptr) { + if(current_obs_token_ptr != NULL) { memcpy(current_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); current_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(current_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; current_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (current)...done"); } /* Only GET method allowed */
--- a/nsp_resources/dimmer.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/dimmer.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -18,8 +18,10 @@ // send our dimmer observation void send_dimmer_observation() { - if (dimmer_obs_token_ptr != NULL && dimmer_obs_number != 0) + if (dimmer_obs_token_ptr != NULL && dimmer_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (dimmer): %s",dimmer->resource()->getValuePointer()); sn_nsdl_send_observation_notification(dimmer_obs_token_ptr,dimmer_obs_token_len,(uint8_t*)dimmer->resource()->getValuePointer(),strlen(dimmer->resource()->getValuePointer()),&dimmer_obs_number,sizeof(dimmer_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init dimmer @@ -29,24 +31,23 @@ // update our dimmer observation void update_dimmer_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(dimmer_obs_token_ptr) { - free(dimmer_obs_token_ptr); - dimmer_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (dimmer)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (dimmer_obs_token_ptr != NULL) free(dimmer_obs_token_ptr); dimmer_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(dimmer_obs_token_ptr) { + if(dimmer_obs_token_ptr != NULL) { memcpy(dimmer_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); dimmer_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(dimmer_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; dimmer_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (dimmer)...done"); } /* Only GET and PUT method allowed */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nsp_resources/fixedtext.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -0,0 +1,52 @@ +// fixedtext resource implementation + +#include "fixedtext.h" + +#include "NSPio.h" + +extern ErrorHandler *error_handler; +NSPio *fixedtext = NULL; + +// observation support +static uint8_t fixedtext_obs_number = 0; +static uint8_t *fixedtext_obs_token_ptr = NULL; +static uint8_t fixedtext_obs_token_len = 0; + +// send our fixedtext observation +void send_fixedtext_observation() { + if (fixedtext_obs_token_ptr != NULL && fixedtext_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (fixedtext): %s",fixedtext->resource()->getValuePointer()); + sn_nsdl_send_observation_notification(fixedtext_obs_token_ptr,fixedtext_obs_token_len,(uint8_t*)fixedtext->resource()->getValuePointer(),strlen(fixedtext->resource()->getValuePointer()),&fixedtext_obs_number,sizeof(fixedtext_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } +} + +// init fixedtext +void init_fixedtext(Resource *resource) { + if (fixedtext == NULL && resource != NULL) fixedtext = new NSPio(error_handler,resource,&send_fixedtext_observation); +} + +// update our fixedtext observation +void update_fixedtext_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { + //if (error_handler != NULL) error_handler->log("Updating Observation (fixedtext)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (fixedtext_obs_token_ptr != NULL) free(fixedtext_obs_token_ptr); + fixedtext_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); + if(fixedtext_obs_token_ptr != NULL) { + memcpy(fixedtext_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); + fixedtext_obs_token_len = received_coap_ptr->token_len; + } + } + if (received_coap_ptr->options_list_ptr->observe != NULL) { + coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); + memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); + coap_res_ptr->options_list_ptr->observe_ptr = &(fixedtext_obs_number); + coap_res_ptr->options_list_ptr->observe_len = 1; + fixedtext_obs_number++; + } + //if (error_handler != NULL) error_handler->log("Updating Observation (fixedtext)...done"); +} + +/* Only GET method allowed */ +uint8_t fixedtext_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto) { + return nsp_get("fixedtext",fixedtext,received_coap_ptr,address,proto,&update_fixedtext_observation); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nsp_resources/fixedtext.h Tue Mar 25 03:21:09 2014 +0000 @@ -0,0 +1,14 @@ +// fixed text resource implementation + +#ifndef FIXED_TEXT_H +#define FIXED_TEXT_H + +#include "nsp_get.h" + +// initialize MBED fixed text resource +void init_fixedtext(Resource *resource); + +// NSP supports FIXED_TEXT observation +extern uint8_t fixedtext_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto); + +#endif
--- a/nsp_resources/gps.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/gps.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -15,8 +15,10 @@ // send our gps observation void send_gps_observation() { - if (gps_obs_token_ptr != NULL && gps_obs_number != 0) + if (gps_obs_token_ptr != NULL && gps_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (gps): %s",gps->resource()->getValuePointer()); sn_nsdl_send_observation_notification(gps_obs_token_ptr,gps_obs_token_len,(uint8_t*)gps->resource()->getValuePointer(),strlen(gps->resource()->getValuePointer()),&gps_obs_number,sizeof(gps_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init gps @@ -26,24 +28,23 @@ // update our gps observation void update_gps_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(gps_obs_token_ptr) { - free(gps_obs_token_ptr); - gps_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (gps)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (gps_obs_token_ptr != NULL) free(gps_obs_token_ptr); gps_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(gps_obs_token_ptr) { + if(gps_obs_token_ptr != NULL) { memcpy(gps_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); gps_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(gps_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; gps_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (gps)...done"); } /* Only GET method allowed */
--- a/nsp_resources/nsdl_support.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/nsdl_support.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -141,11 +141,11 @@ ++count; if (count%val == 0) { count = 0; - //if (error_handler != NULL) error_handler->log("Re-registering Endpoint..."); + if (error_handler != NULL) error_handler->log("Re-registering Endpoint..."); register_endpoint(); } else { - //if (count%4 == 0 && endpoint != NULL) endpoint->sendObservations(); + if (count%90 == 0 && endpoint != NULL) endpoint->sendObservations(); // once every 45 seconds if (error_handler != NULL) error_handler->checkForExit(); } if (error_handler != NULL) error_handler->blinkTransportRxLED();
--- a/nsp_resources/nsp_get.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/nsp_get.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -15,7 +15,7 @@ coap_res_ptr->payload_len = strlen(io->resource()->getValuePointer()); coap_res_ptr->payload_ptr = (uint8_t*)io->resource()->getValuePointer(); //if (error_handler != NULL) error_handler->log("NSP: Sending %s = %s...",tag,io->resource()->getValuePointer()); - //if (observer != NULL) (observer)(received_coap_ptr,coap_res_ptr); + if (observer != NULL) (observer)(received_coap_ptr,coap_res_ptr); sn_nsdl_send_coap_message(address, coap_res_ptr); if (error_handler != NULL) error_handler->log("NSP: Sent %s = %s...",tag,io->resource()->getValuePointer()); } @@ -25,6 +25,7 @@ else { if (error_handler != NULL) error_handler->log("NSP: %s request: MBEDio is NULL!",tag); } + if (coap_res_ptr != NULL && coap_res_ptr->options_list_ptr != NULL) coap_res_ptr->options_list_ptr->observe_ptr = NULL; if (coap_res_ptr != NULL) sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); if (error_handler != NULL) error_handler->log_memory("NSP GET MEMORY CHECK(done)"); return 0;
--- a/nsp_resources/nsp_getput.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/nsp_getput.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -8,6 +8,7 @@ if (error_handler != NULL) error_handler->log_memory("NSP GETPUT MEMORY CHECK(begin)"); #ifdef NSP_ENABLE_GETPUT sn_coap_hdr_s *coap_res_ptr = NULL; + bool is_get = false; if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) { @@ -18,7 +19,7 @@ coap_res_ptr->payload_len = strlen(io->resource()->getValuePointer()); coap_res_ptr->payload_ptr = (uint8_t*)io->resource()->getValuePointer(); //if (error_handler != NULL) error_handler->log("NSP: Sending %s = %s...",tag,io->resource()->getValuePointer()); - //if (observer != NULL) (observer)(received_coap_ptr,coap_res_ptr); + if (observer != NULL) (observer)(received_coap_ptr,coap_res_ptr); sn_nsdl_send_coap_message(address, coap_res_ptr); if (error_handler != NULL) error_handler->log("NSP: Sent %s = %s...",tag,io->resource()->getValuePointer()); } @@ -28,6 +29,7 @@ else { if (error_handler != NULL) error_handler->log("NSP: %s location request: NSPio is NULL!",tag); } + is_get = true; } else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) { //if (error_handler != NULL) error_handler->log("NSP: setting %s",tag); @@ -44,7 +46,7 @@ coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED); sn_nsdl_send_coap_message(address, coap_res_ptr); } - + if (is_get && coap_res_ptr != NULL && coap_res_ptr->options_list_ptr != NULL) coap_res_ptr->options_list_ptr->observe_ptr = NULL; if (coap_res_ptr != NULL) sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); if (error_handler != NULL) error_handler->log_memory("NSP GETPUT MEMORY CHECK(done)"); return 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nsp_resources/rssi.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -0,0 +1,53 @@ +// rssi resource implementation + +#include "rssi.h" + +#include "NSPio.h" +#include "MBEDrssi.h" + +extern ErrorHandler *error_handler; +NSPio *rssi = NULL; + +// observation support +static uint8_t rssi_obs_number = 0; +static uint8_t *rssi_obs_token_ptr = NULL; +static uint8_t rssi_obs_token_len = 0; + +// send our rssi observation +void send_rssi_observation() { + if (rssi_obs_token_ptr != NULL && rssi_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (rssi): %s",rssi->resource()->getValuePointer()); + sn_nsdl_send_observation_notification(rssi_obs_token_ptr,rssi_obs_token_len,(uint8_t*)rssi->resource()->getValuePointer(),strlen(rssi->resource()->getValuePointer()),&rssi_obs_number,sizeof(rssi_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } +} + +// init rssi +void init_rssi(Resource *resource) { + if (rssi == NULL && resource != NULL) rssi = new NSPio(new MBEDrssi(error_handler,resource),&send_rssi_observation); +} + +// update our rssi observation +void update_rssi_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { + //if (error_handler != NULL) error_handler->log("Updating Observation (rssi)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (rssi_obs_token_ptr != NULL) free(rssi_obs_token_ptr); + rssi_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); + if(rssi_obs_token_ptr != NULL) { + memcpy(rssi_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); + rssi_obs_token_len = received_coap_ptr->token_len; + } + } + if (received_coap_ptr->options_list_ptr->observe != NULL) { + coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); + memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); + coap_res_ptr->options_list_ptr->observe_ptr = &(rssi_obs_number); + coap_res_ptr->options_list_ptr->observe_len = 1; + rssi_obs_number++; + } + //if (error_handler != NULL) error_handler->log("Updating Observation (rssi)...done"); +} + +/* Only GET method allowed */ +uint8_t rssi_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto) { + return nsp_get("rssi",rssi,received_coap_ptr,address,proto,&update_rssi_observation); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nsp_resources/rssi.h Tue Mar 25 03:21:09 2014 +0000 @@ -0,0 +1,14 @@ +// RSSI resource implementation + +#ifndef RSSI_H +#define RSSI_H + +#include "nsp_get.h" + +// initialize MBED rssi Emulator +void init_rssi(Resource *resource); + +// NSP supports RSSI observation +extern uint8_t rssi_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto); + +#endif
--- a/nsp_resources/switch.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/switch.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -18,8 +18,10 @@ // send our light_sw observation void send_light_sw_observation() { - if (light_sw_obs_token_ptr != NULL && light_sw_obs_number != 0) + if (light_sw_obs_token_ptr != NULL && light_sw_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (switch): %s",light_sw->resource()->getValuePointer()); sn_nsdl_send_observation_notification(light_sw_obs_token_ptr,light_sw_obs_token_len,(uint8_t*)light_sw->resource()->getValuePointer(),strlen(light_sw->resource()->getValuePointer()),&light_sw_obs_number,sizeof(light_sw_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init light switch @@ -30,24 +32,23 @@ // update our light_sw observation void update_light_sw_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(light_sw_obs_token_ptr) { - free(light_sw_obs_token_ptr); - light_sw_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (switch)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (light_sw_obs_token_ptr != NULL) free(light_sw_obs_token_ptr); light_sw_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(light_sw_obs_token_ptr) { + if(light_sw_obs_token_ptr != NULL) { memcpy(light_sw_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); light_sw_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(light_sw_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; light_sw_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (switch)...done"); } /* Only GET and PUT method allowed */
--- a/nsp_resources/temperature.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/temperature.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -16,8 +16,10 @@ // send our temp observation void send_temp_observation() { - if (temp_obs_token_ptr != NULL && temp_obs_number != 0) + if (temp_obs_token_ptr != NULL && temp_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (temp): %s",temp->resource()->getValuePointer()); sn_nsdl_send_observation_notification(temp_obs_token_ptr,temp_obs_token_len,(uint8_t*)temp->resource()->getValuePointer(),strlen(temp->resource()->getValuePointer()),&temp_obs_number,sizeof(temp_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init temp @@ -27,24 +29,23 @@ // update our temp observation void update_temp_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(temp_obs_token_ptr) { - free(temp_obs_token_ptr); - temp_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (temp)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (temp_obs_token_ptr != NULL) free(temp_obs_token_ptr); temp_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(temp_obs_token_ptr) { + if(temp_obs_token_ptr != NULL) { memcpy(temp_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); temp_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(temp_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; temp_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (temp)...done"); } /* Only GET method allowed */
--- a/nsp_resources/voltage.cpp Mon Mar 24 19:53:20 2014 +0000 +++ b/nsp_resources/voltage.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -16,8 +16,10 @@ // send our voltage observation void send_voltage_observation() { - if (voltage_obs_token_ptr != NULL && voltage_obs_number != 0) + if (voltage_obs_token_ptr != NULL && voltage_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (voltage): %s",voltage->resource()->getValuePointer()); sn_nsdl_send_observation_notification(voltage_obs_token_ptr,voltage_obs_token_len,(uint8_t*)voltage->resource()->getValuePointer(),strlen(voltage->resource()->getValuePointer()),&voltage_obs_number,sizeof(voltage_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } } // init voltage @@ -27,24 +29,23 @@ // update our voltage observation void update_voltage_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { - if (received_coap_ptr->token_ptr) { - if(voltage_obs_token_ptr) { - free(voltage_obs_token_ptr); - voltage_obs_token_ptr = NULL; - } + //if (error_handler != NULL) error_handler->log("Updating Observation (voltage)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (voltage_obs_token_ptr != NULL) free(voltage_obs_token_ptr); voltage_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); - if(voltage_obs_token_ptr) { + if(voltage_obs_token_ptr != NULL) { memcpy(voltage_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); voltage_obs_token_len = received_coap_ptr->token_len; } } - if (received_coap_ptr->options_list_ptr->observe) { + if (received_coap_ptr->options_list_ptr->observe != NULL) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &(voltage_obs_number); coap_res_ptr->options_list_ptr->observe_len = 1; voltage_obs_number++; } + //if (error_handler != NULL) error_handler->log("Updating Observation (voltage)...done"); } /* Only GET method allowed */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nsp_resources/wattage.cpp Tue Mar 25 03:21:09 2014 +0000 @@ -0,0 +1,54 @@ +// Voltage resource implementation + +#include "wattage.h" + +#include "NSPio.h" +#include "MBEDWattage.h" + +extern ErrorHandler *error_handler; + +NSPio *wattage = NULL; + +// observation support +static uint8_t wattage_obs_number = 0; +static uint8_t *wattage_obs_token_ptr = NULL; +static uint8_t wattage_obs_token_len = 0; + +// send our wattage observation +void send_wattage_observation() { + if (wattage_obs_token_ptr != NULL && wattage_obs_number != 0) { + //if (error_handler != NULL) error_handler->log("Sending Observation (wattage): %s",wattage->resource()->getValuePointer()); + sn_nsdl_send_observation_notification(wattage_obs_token_ptr,wattage_obs_token_len,(uint8_t*)wattage->resource()->getValuePointer(),strlen(wattage->resource()->getValuePointer()),&wattage_obs_number,sizeof(wattage_obs_number),COAP_MSG_TYPE_NON_CONFIRMABLE, 0); + } +} + +// init wattage +void init_wattage(Resource *resource) { + if (wattage == NULL && resource != NULL) wattage = new NSPio(new MBEDWattage(error_handler,resource),&send_wattage_observation); +} + +// update our wattage observation +void update_wattage_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { + //if (error_handler != NULL) error_handler->log("Updating Observation (wattage)...starting"); + if (received_coap_ptr->token_ptr != NULL) { + if (wattage_obs_token_ptr != NULL) free(wattage_obs_token_ptr); + wattage_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); + if(wattage_obs_token_ptr != NULL) { + memcpy(wattage_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); + wattage_obs_token_len = received_coap_ptr->token_len; + } + } + if (received_coap_ptr->options_list_ptr->observe != NULL) { + coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); + memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); + coap_res_ptr->options_list_ptr->observe_ptr = &(wattage_obs_number); + coap_res_ptr->options_list_ptr->observe_len = 1; + wattage_obs_number++; + } + //if (error_handler != NULL) error_handler->log("Updating Observation (wattage)...done"); +} + +/* Only GET method allowed */ +uint8_t wattage_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto) { + return nsp_get("wattage",wattage,received_coap_ptr,address,proto,&update_wattage_observation); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nsp_resources/wattage.h Tue Mar 25 03:21:09 2014 +0000 @@ -0,0 +1,14 @@ +// Wattage resource implementation + +#ifndef WATTAGE_H +#define WATTAGE_H + +#include "nsp_get.h" + +// initialize MBED Wattage Emulator +void init_wattage(Resource *resource); + +// MBED supports Wattage Emulation +extern uint8_t wattage_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto); + +#endif