Red Hat Summit NanoService Demo for LPC1768 App Board using OMA Lightweight Objects

Dependencies:   Beep C12832_lcd EthernetInterface LM75B MMA7660 mbed-rtos mbed nsdl_lib

Fork of LWM2M_NanoService_Ethernet by MBED_DEMOS

Files at this revision

API Documentation at this revision

Comitter:
bogdanm
Date:
Tue Oct 15 15:48:23 2013 +0000
Parent:
2:7e489126fe7a
Child:
4:15690450a797
Commit message:
Fixes buffer overflows, invalid server address and other issues.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
nsdl_support.cpp Show annotated file Show diff for this revision Revisions of this file
resources/temperature.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Oct 15 12:45:46 2013 +0000
+++ b/main.cpp	Tue Oct 15 15:48:23 2013 +0000
@@ -26,9 +26,9 @@
 
 // NSP configuration
 /* Change this IP address to that of your NanoService Platform installation */
-static const char* NSP_ADDRESS = "217.140.101.40"; /* internal NSP*/
+static const char* NSP_ADDRESS = "217.140.101.20"; /* internal NSP*/
 static const int NSP_PORT = 5683;
-char endpoint_name[15] = "MyMbedexam";
+char endpoint_name[16] = "refactored";
 uint8_t ep_type[] = {"mbed_device"};
 uint8_t lifetime_ptr[] = {"1200"};
 
@@ -53,7 +53,7 @@
 
     mbed_interface_uid(mbed_uid);
     mbed_uid[32] = '\0';
-    memcpy(&endpoint_name[10], &mbed_uid[27], 5);
+    memcpy(&endpoint_name[10], &mbed_uid[27], 6);
 
     lcd.locate(0,11);
     lcd.printf("IP:%s", eth.getIPAddress());
@@ -78,7 +78,7 @@
     NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
 
     lcd.locate(0,22);
-    lcd.printf("EP name:%s", endpoint_name);
+    lcd.printf("EP name:%s\n", endpoint_name);
 }
 
 // ****************************************************************************
@@ -121,7 +121,6 @@
         pc.printf("NSP registering failed\r\n");
     else
         pc.printf("NSP registering OK\r\n");
-
     nsdl_clean_register_endpoint(&endpoint_ptr);
 
     nsdl_free(resource_ptr->resource_parameters_ptr);
--- a/nsdl_support.cpp	Tue Oct 15 12:45:46 2013 +0000
+++ b/nsdl_support.cpp	Tue Oct 15 15:48:23 2013 +0000
@@ -10,7 +10,7 @@
 extern EthernetInterface eth;
 extern Endpoint nsp;
 extern UDPSocket server;
-extern char endpoint_name[15];
+extern char endpoint_name[16];
 extern uint8_t ep_type[];
 extern uint8_t lifetime_ptr[];
 
@@ -71,9 +71,9 @@
         endpoint_structure->endpoint_name_ptr = name;
         endpoint_structure->endpoint_name_len = 15;
         endpoint_structure->type_ptr = typename_ptr;
-        endpoint_structure->type_len =  sizeof(typename_ptr)-1;
+        endpoint_structure->type_len =  strlen((char*)typename_ptr);
         endpoint_structure->lifetime_ptr = lifetime_ptr;
-        endpoint_structure->lifetime_len =  sizeof(lifetime_ptr)-1;
+        endpoint_structure->lifetime_len =  strlen((char*)lifetime_ptr);
     }
     return endpoint_structure;
 }
@@ -89,7 +89,7 @@
 
 static uint8_t tx_cb(sn_nsdl_capab_e protocol, uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr)
 {
-    pc.printf("TX callback!\n\rSending %d bytes:\r\n", data_len);
+    pc.printf("TX callback!\n\rSending %d bytes\r\n", data_len);
 
     if(server.sendTo(nsp, (char*)data_ptr, data_len) != data_len)
         pc.printf("sending failed\n\r");
--- a/resources/temperature.cpp	Tue Oct 15 12:45:46 2013 +0000
+++ b/resources/temperature.cpp	Tue Oct 15 15:48:23 2013 +0000
@@ -11,7 +11,7 @@
 static LM75B tmp(p28,p27);
 /* stored data for observable resource */
 static uint8_t obs_number = 0;
-static uint8_t *obs_token_ptr = 0;
+static uint8_t *obs_token_ptr = NULL;
 static uint8_t obs_token_len = 0;
 static char temp_val[5];
 extern Serial pc;
@@ -26,7 +26,7 @@
         wait(1);
         time++;
         sn_nsdl_exec(time);
-        if((!(time % 10)) && obs_number != 0)
+        if((!(time % 10)) && obs_number != 0 && obs_token_ptr != NULL)
         {
             obs_number++;
             sprintf(temp_val,"%2.2f" ,tmp.read());
@@ -45,7 +45,7 @@
     sprintf(temp_val,"%2.2f" ,tmp.read());
     sn_coap_hdr_s *coap_res_ptr = 0;
 
-    //pc.printf("temp callback\r\n");
+    pc.printf("temp callback\r\n");
     coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
 
     coap_res_ptr->payload_len = 5;
@@ -85,7 +85,7 @@
 
 int create_temperature_resource(sn_nsdl_resource_info_s *resource_ptr)
 {
-    Thread exec_thread(exec_call_thread);
+    static Thread exec_thread(exec_call_thread);
     
     nsdl_create_dynamic_resource(resource_ptr, sizeof(TEMP_RES_ID)-1, (uint8_t*)TEMP_RES_ID, 0, 0, 1, &temp_resource_cb, SN_GRS_GET_ALLOWED);    
     return 0;