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 112:c43fab080ce1, committed 2014-03-16
- Comitter:
- ansond
- Date:
- Sun Mar 16 05:59:43 2014 +0000
- Parent:
- 111:e5b1bb31eb63
- Child:
- 113:d2f2bce24b78
- Commit message:
- updates
Changed in this revision
--- a/Definitions.h Sun Mar 16 04:36:40 2014 +0000 +++ b/Definitions.h Sun Mar 16 05:59:43 2014 +0000 @@ -65,7 +65,7 @@ // NSP Configuration #define NSP_NODE_TYPE "Light" // Node type -#define NSP_NODE_LIFETIME "60" // Node lifetime (minutes) +#define NSP_NODE_LIFETIME "160" // Node lifetime (seconds) #define RD_UPDATE_PERIOD 50 // The number of seconds between NSP (re)registration messages // NSP Registration Configuration
--- a/endpoint_core.lib Sun Mar 16 04:36:40 2014 +0000 +++ b/endpoint_core.lib Sun Mar 16 05:59:43 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/ansond/code/endpoint_core/#759dee018363 +http://mbed.org/users/ansond/code/endpoint_core/#e2be56eadda8
--- a/nsp_resources/nsdl_support.cpp Sun Mar 16 04:36:40 2014 +0000 +++ b/nsp_resources/nsdl_support.cpp Sun Mar 16 05:59:43 2014 +0000 @@ -10,6 +10,7 @@ #include "ErrorHandler.h" extern ErrorHandler *error_handler; +Mutex *network_mutex = NULL; Endpoint nsp; UDPSocket server; @@ -93,13 +94,17 @@ } static uint8_t tx_cb(sn_nsdl_capab_e protocol, uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr) { - //if (error_handler != NULL) error_handler->log("NSP: Sending %d bytes", data_len); - - if (server.sendTo(nsp, (char*)data_ptr, data_len) != data_len) { - if (error_handler != NULL) error_handler->log("NSP: send failed"); + //if (error_handler != NULL) error_handler->log("NSP: sending %d bytes...",data_len); + if (network_mutex != NULL) network_mutex->lock(); + int sent = server.sendTo(nsp, (char*)data_ptr, data_len); + if (network_mutex != NULL) network_mutex->unlock(); + //if (error_handler != NULL) error_handler->log("NSP: send done. sent %d bytes...",sent); + if (sent != data_len) { + if (error_handler != NULL) error_handler->log("NSP: send failed!! Attempted: %d Sent: %d", data_len, sent); } - - if (error_handler != NULL) error_handler->blinkTransportTxLED(); + else { + if (error_handler != NULL) error_handler->blinkTransportTxLED(); + } return 1; } @@ -113,7 +118,9 @@ static void register_endpoint() { sn_nsdl_ep_parameters_s *endpoint_ptr = NULL; endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)_endpoint_name, _ep_type, _lifetime_ptr); + if (network_mutex != NULL) network_mutex->lock(); sn_nsdl_register_endpoint(endpoint_ptr); + if (network_mutex != NULL) network_mutex->unlock(); nsdl_clean_register_endpoint(&endpoint_ptr); if (error_handler != NULL) error_handler->blinkTransportTxLED(); } @@ -131,6 +138,7 @@ ++count; if (count%val == 0) { count = 0; + //if (error_handler != NULL) error_handler->log("Re-registering Endpoint..."); register_endpoint(); } else { @@ -142,6 +150,10 @@ void nsdl_init() { sn_nsdl_mem_s memory_cbs; uint8_t nsp_addr[4]; + + // initialize our network mutex + if (network_mutex == NULL) network_mutex = new Mutex(); + if (network_mutex != NULL) network_mutex->unlock(); /* Initialize libNsdl */ memset(&memory_cbs,0,sizeof(memory_cbs)); @@ -178,8 +190,13 @@ memset(&received_packet_address, 0, sizeof(sn_nsdl_addr_s)); memset(nsp_received_address, 0, sizeof(nsp_received_address)); received_packet_address.addr_ptr = nsp_received_address; + //if (error_handler != NULL) error_handler->log("NSP: waiting for data..."); + if (network_mutex != NULL) network_mutex->lock(); int n = server.receiveFrom(from,nsp_buffer,sizeof(nsp_buffer)); + if (network_mutex != NULL) network_mutex->unlock(); + //if (error_handler != NULL) error_handler->log("NSP: received %d bytes... processing...",n); if (n > 0) sn_nsdl_process_coap((uint8_t*)nsp_buffer, n, &received_packet_address); + //if (error_handler != NULL) error_handler->log("NSP: done processing %d bytes...",n); if (error_handler != NULL) error_handler->blinkTransportRxLED(); } } \ No newline at end of file
--- a/nsp_resources/nsp_get.cpp Sun Mar 16 04:36:40 2014 +0000 +++ b/nsp_resources/nsp_get.cpp Sun Mar 16 05:59:43 2014 +0000 @@ -6,15 +6,16 @@ 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) { if (error_handler != NULL) error_handler->log_memory("NSP GET MEMORY CHECK(begin)"); #ifdef NSP_ENABLE_GET - if (error_handler != NULL) error_handler->log("NSP: %s requested",tag); + //if (error_handler != NULL) error_handler->log("NSP: %s requested",tag); sn_coap_hdr_s *coap_res_ptr = NULL; coap_res_ptr = sn_coap_build_response(received_coap_ptr,COAP_MSG_CODE_RESPONSE_CONTENT); - if (coap_res_ptr != NULL && io != NULL && io->stringValue() != NULL) { + if (coap_res_ptr != NULL && io != NULL && io->stringValue() != NULL) { // io->stringValue() refreshes the value coap_res_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - coap_res_ptr->payload_len = strlen(io->stringValue()); - coap_res_ptr->payload_ptr = (uint8_t*)io->stringValue(); + 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()); sn_nsdl_send_coap_message(address, coap_res_ptr); - if (error_handler != NULL) error_handler->log("NSP: %s: %s...",tag,io->stringValue()); + if (error_handler != NULL) error_handler->log("NSP: Sent %s = %s...",tag,io->resource()->getValuePointer()); } else if (coap_res_ptr == NULL) { if (error_handler != NULL) error_handler->log("NSP: %s request: coap_res_ptr is NULL!",tag);
--- a/nsp_resources/nsp_getput.cpp Sun Mar 16 04:36:40 2014 +0000 +++ b/nsp_resources/nsp_getput.cpp Sun Mar 16 05:59:43 2014 +0000 @@ -8,17 +8,17 @@ #ifdef NSP_ENABLE_GETPUT sn_coap_hdr_s *coap_res_ptr = NULL; - if (error_handler != NULL) error_handler->log("NSP: %s callback...",tag); - if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) { + //if (error_handler != NULL) error_handler->log("NSP: %s requested",tag); coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); - if (coap_res_ptr != NULL && io != NULL && io->stringValue() != NULL) { + if (coap_res_ptr != NULL && io != NULL && io->stringValue() != NULL) { // io->stringValue() refreshes the value coap_res_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; - coap_res_ptr->payload_len = strlen(io->stringValue()); - coap_res_ptr->payload_ptr = (uint8_t*)io->stringValue(); + 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()); sn_nsdl_send_coap_message(address, coap_res_ptr); - if (error_handler != NULL) error_handler->log("NSP: %s: %s...",tag,io->stringValue()); + if (error_handler != NULL) error_handler->log("NSP: Sent %s = %s...",tag,io->resource()->getValuePointer()); } else if (coap_res_ptr == NULL) { if (error_handler != NULL) error_handler->log("NSP: %s location request: coap_res_ptr is NULL!",tag); @@ -28,11 +28,11 @@ } } else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) - { + { //if (error_handler != NULL) error_handler->log("NSP: setting %s",tag); // copy the new value if (io->resource() != NULL && received_coap_ptr->payload_ptr != NULL && received_coap_ptr->payload_len > 0) { io->resource()->setValue((char *)received_coap_ptr->payload_ptr,received_coap_ptr->payload_len); - if (error_handler != NULL) error_handler->log("NSP: setting %s to %s...",tag,io->resource()->getValuePointer()); + if (error_handler != NULL) error_handler->log("NSP: set %s to %s...",tag,io->resource()->getValuePointer()); } else { if (error_handler != NULL) error_handler->log("NSP: %s resource pointer is NULL",tag);