nsp resources for the mbed nsp lighting endpoint
Dependencies: nsdl_lib
Dependents: mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet mbed_nsp_endpoint_nxp
nsp_get.cpp@3:30c96bd77160, 2014-09-26 (annotated)
- Committer:
- ansond
- Date:
- Fri Sep 26 05:55:55 2014 +0000
- Revision:
- 3:30c96bd77160
- Parent:
- 0:b26c3526ee89
updates for new logger
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:b26c3526ee89 | 1 | #include "nsp_get.h" |
ansond | 0:b26c3526ee89 | 2 | |
ansond | 0:b26c3526ee89 | 3 | extern char *strdup(char *str); |
ansond | 0:b26c3526ee89 | 4 | |
ansond | 0:b26c3526ee89 | 5 | // NSP Get Method |
ansond | 0:b26c3526ee89 | 6 | uint8_t nsp_get(char *tag,MBEDio *io,sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto) { return nsp_get(tag,io,received_coap_ptr,address,proto,NULL); } |
ansond | 0:b26c3526ee89 | 7 | uint8_t nsp_get(char *tag,MBEDio *io,sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto,sn_update_observation_t observer) { |
ansond | 3:30c96bd77160 | 8 | if (m_logger != NULL) m_logger->log_memory("NSP GET MEMORY CHECK(begin)"); |
ansond | 0:b26c3526ee89 | 9 | #ifdef NSP_ENABLE_GET |
ansond | 3:30c96bd77160 | 10 | //if (m_logger != NULL) m_logger->log("NSP: %s requested",tag); |
ansond | 0:b26c3526ee89 | 11 | sn_coap_hdr_s *coap_res_ptr = NULL; |
ansond | 0:b26c3526ee89 | 12 | coap_res_ptr = sn_coap_build_response(received_coap_ptr,COAP_MSG_CODE_RESPONSE_CONTENT); |
ansond | 0:b26c3526ee89 | 13 | if (coap_res_ptr != NULL && io != NULL && io->stringValue() != NULL) { // io->stringValue() refreshes the value |
ansond | 0:b26c3526ee89 | 14 | coap_res_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; |
ansond | 0:b26c3526ee89 | 15 | coap_res_ptr->payload_len = strlen(io->resource()->getValuePointer()); |
ansond | 0:b26c3526ee89 | 16 | coap_res_ptr->payload_ptr = (uint8_t*)io->resource()->getValuePointer(); |
ansond | 3:30c96bd77160 | 17 | //if (m_logger != NULL) m_logger->log("NSP: Sending %s = %s...",tag,io->resource()->getValuePointer()); |
ansond | 0:b26c3526ee89 | 18 | if (observer != NULL) (observer)(received_coap_ptr,coap_res_ptr); |
ansond | 0:b26c3526ee89 | 19 | sn_nsdl_send_coap_message(address, coap_res_ptr); |
ansond | 3:30c96bd77160 | 20 | if (m_logger != NULL) m_logger->log("NSP: Sent %s = %s...",tag,io->resource()->getValuePointer()); |
ansond | 0:b26c3526ee89 | 21 | } |
ansond | 0:b26c3526ee89 | 22 | else if (coap_res_ptr == NULL) { |
ansond | 3:30c96bd77160 | 23 | if (m_logger != NULL) m_logger->log("NSP: %s request: coap_res_ptr is NULL!",tag); |
ansond | 0:b26c3526ee89 | 24 | } |
ansond | 0:b26c3526ee89 | 25 | else { |
ansond | 3:30c96bd77160 | 26 | if (m_logger != NULL) m_logger->log("NSP: %s request: MBEDio is NULL!",tag); |
ansond | 0:b26c3526ee89 | 27 | } |
ansond | 0:b26c3526ee89 | 28 | if (coap_res_ptr != NULL && coap_res_ptr->options_list_ptr != NULL) coap_res_ptr->options_list_ptr->observe_ptr = NULL; |
ansond | 0:b26c3526ee89 | 29 | if (coap_res_ptr != NULL) sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); |
ansond | 3:30c96bd77160 | 30 | if (m_logger != NULL) m_logger->log_memory("NSP GET MEMORY CHECK(done)"); |
ansond | 0:b26c3526ee89 | 31 | return 0; |
ansond | 0:b26c3526ee89 | 32 | #else |
ansond | 3:30c96bd77160 | 33 | if (m_logger != NULL) m_logger->log("NSP Get() functions disabled for %s",tag); |
ansond | 3:30c96bd77160 | 34 | if (m_logger != NULL) m_logger->log_memory("NSP GET MEMORY CHECK(off)"); |
ansond | 0:b26c3526ee89 | 35 | return 0; |
ansond | 0:b26c3526ee89 | 36 | #endif |
ansond | 0:b26c3526ee89 | 37 | } |