MBED NanoService Lighting Endpoint for NXP Ublox (Ethernet enabled)

Dependencies:   C027 C12832 EthernetInterface StatusReporter LM75B endpoint_core endpoint_nsp mbed-rtos mbed nsp_resources

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Sat Mar 15 06:57:02 2014 +0000
Parent:
106:4f7323a01fb8
Child:
108:4a90997bac6c
Commit message:
updates

Changed in this revision

Definitions.h Show annotated file Show diff for this revision Revisions of this file
nsp_resources/nsdl_support.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Definitions.h	Sat Mar 15 05:57:28 2014 +0000
+++ b/Definitions.h	Sat Mar 15 06:57:02 2014 +0000
@@ -61,8 +61,8 @@
 
 // NSP Configuration
 #define NSP_NODE_TYPE       "Light"                // Node type
-#define NSP_NODE_LIFETIME   "90"                   // Node lifetime
-#define RD_UPDATE_PERIOD    60                     // The number of seconds between NSP (re)registration messages
+#define NSP_NODE_LIFETIME   "60"                   // Node lifetime (minutes)
+#define RD_UPDATE_PERIOD     50                    // The number of seconds between NSP (re)registration messages
 
 // NSP Registration Configuration
 #define NSP_RESOURCES_OBSERVABLE    1               // 1 - all resources will be registered as observable, 0 - not observable
--- a/nsp_resources/nsdl_support.cpp	Sat Mar 15 05:57:28 2014 +0000
+++ b/nsp_resources/nsdl_support.cpp	Sat Mar 15 06:57:02 2014 +0000
@@ -11,8 +11,6 @@
 
 extern ErrorHandler *error_handler;
 
-Mutex *nsp_mutex = NULL;
-
 Endpoint nsp;
 UDPSocket server;
 char _endpoint_name[LIGHT_NAME_LEN+1];
@@ -20,8 +18,10 @@
 uint8_t _lifetime_ptr[] = { NSP_NODE_LIFETIME };
 
 void *nsdl_alloc(uint16_t size) {
-    if (size > 0) return malloc(size);
-    return NULL;
+    void *chunk = NULL;
+    if (size > 0) chunk = malloc(size);
+    if (chunk != NULL && size > 0) memset(chunk,0,size);
+    return chunk;
 }
 
 void nsdl_free(void* ptr_to_free) {
@@ -116,19 +116,18 @@
     int val = RD_UPDATE_PERIOD*4;
     while(true) {
         wait_ms(250);
-        if (error_handler != NULL) error_handler->blinkTransportRxLED();
         ++count;
         if (count%val == 0) {
             count = 0;
-            //nsp_mutex->lock();
             endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)_endpoint_name, _ep_type, _lifetime_ptr);
             sn_nsdl_register_endpoint(endpoint_ptr);
             nsdl_clean_register_endpoint(&endpoint_ptr);
-            //nsp_mutex->unlock();
             endpoint_ptr = NULL;
             if (error_handler != NULL) error_handler->blinkTransportTxLED();
         }
-        if (error_handler != NULL) error_handler->checkForExit();
+        else {
+            if (error_handler != NULL) error_handler->checkForExit();
+        }
     }
 }
 
@@ -153,10 +152,7 @@
 }
 
     
-void nsdl_event_loop() {
-    if (nsp_mutex == NULL) nsp_mutex = new Mutex();
-    nsp_mutex->unlock();
-    
+void nsdl_event_loop() {    
     // start the registration update thread
     Thread registration_thread(registration_update_thread);
     
@@ -164,18 +160,15 @@
     Endpoint from;
     uint8_t nsp_received_address[4];
     char nsp_buffer[1024];
-
-    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;
     
     while(true) {
+        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("Reading from socket...");
-        //nsp_mutex->lock();
         int n = server.receiveFrom(from,nsp_buffer,sizeof(nsp_buffer));
         if (n > 0) sn_nsdl_process_coap((uint8_t*)nsp_buffer, n, &received_packet_address);
-        //nsp_mutex->unlock();
         if (error_handler != NULL) error_handler->blinkTransportRxLED();
         //if (error_handler != NULL) error_handler->log("DONE Reading from socket...");
     }