Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: nsdl_lib
Dependents: mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet mbed_nsp_endpoint_nxp
addldata.cpp
00001 // addldata resource implementation 00002 00003 #include "mbed.h" 00004 #include "nsdl_support.h" 00005 #include "addldata.h" 00006 #include "NSPio.h" 00007 00008 extern Logger *logger; 00009 00010 NSPio *addldata = NULL; 00011 00012 // observation support 00013 static uint8_t addldata_obs_number = 0; 00014 static uint8_t *addldata_obs_token_ptr = NULL; 00015 static uint8_t addldata_obs_token_len = 0; 00016 00017 // send our addldata observation 00018 void send_addldata_observation() { 00019 if (addldata_obs_token_ptr != NULL && addldata_obs_number != 0) { 00020 //if (m_logger != NULL) m_logger->log("Sending Observation (addldata): %s",addldata->resource()->getValuePointer()); 00021 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); 00022 } 00023 } 00024 00025 // init addldata 00026 void init_addldata(Resource *resource) { 00027 if (addldata == NULL && resource != NULL) addldata = new NSPio(m_logger,resource,&send_addldata_observation); 00028 } 00029 00030 // update our addldata observation 00031 void update_addldata_observation(sn_coap_hdr_s *received_coap_ptr,sn_coap_hdr_s *coap_res_ptr) { 00032 //if (m_logger != NULL) m_logger->log("Updating Observation (addldata)...starting"); 00033 if (received_coap_ptr->token_ptr != NULL) { 00034 if (addldata_obs_token_ptr != NULL) free(addldata_obs_token_ptr); 00035 addldata_obs_token_ptr = (uint8_t *)malloc(received_coap_ptr->token_len); 00036 if(addldata_obs_token_ptr != NULL) { 00037 memcpy(addldata_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len); 00038 addldata_obs_token_len = received_coap_ptr->token_len; 00039 } 00040 } 00041 if (received_coap_ptr->options_list_ptr->observe != NULL) { 00042 coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 00043 memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 00044 coap_res_ptr->options_list_ptr->observe_ptr = &(addldata_obs_number); 00045 coap_res_ptr->options_list_ptr->observe_len = 1; 00046 addldata_obs_number++; 00047 } 00048 //if (m_logger != NULL) m_logger->log("Updating Observation (addldata)...done"); 00049 } 00050 00051 /* Only GET and PUT method allowed */ 00052 uint8_t addldata_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) { 00053 return nsp_getput("addldata",addldata,received_coap_ptr,address,proto,&update_addldata_observation); 00054 }
Generated on Tue Jul 12 2022 21:44:18 by
1.7.2