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:
sam_grove
Date:
Mon Apr 28 22:49:53 2014 +0000
Parent:
28:3c25f2f62cd3
Child:
31:7ce5bef2d369
Commit message:
firehouse starting point;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
resources/light.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Apr 27 17:08:08 2014 +0000
+++ b/main.cpp	Mon Apr 28 22:49:53 2014 +0000
@@ -122,7 +122,7 @@
 
     // Static resources
     nsdl_create_static_resource(resource_ptr, sizeof("3/0/0")-1, (uint8_t*) "3/0/0", 0, 0,  (uint8_t*) "ARM", sizeof("ARM")-1);
-    nsdl_create_static_resource(resource_ptr, sizeof("3/0/1")-1, (uint8_t*) "3/0/1", 0, 0,  (uint8_t*) "LPC1768 mbed house", sizeof("LPC1768 mbed house")-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("3/0/1")-1, (uint8_t*) "3/0/1", 0, 0,  (uint8_t*) "LPC1768 mbed lafd", sizeof("LPC1768 mbed lafd")-1);
     nsdl_create_static_resource(resource_ptr, sizeof("3/0/2")-1, (uint8_t*) "3/0/2", 0, 0,  (uint8_t*) mbed_uid, sizeof(mbed_uid)-1);
     nsdl_create_static_resource(resource_ptr, sizeof("3/0/3")-1, (uint8_t*) "3/0/3", 0, 0,  (uint8_t*) FIRMWARE_VER, strlen(FIRMWARE_VER));
    #ifdef DHCP
--- a/mbed.bld	Sun Apr 27 17:08:08 2014 +0000
+++ b/mbed.bld	Mon Apr 28 22:49:53 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file
--- a/resources/light.cpp	Sun Apr 27 17:08:08 2014 +0000
+++ b/resources/light.cpp	Mon Apr 28 22:49:53 2014 +0000
@@ -5,11 +5,19 @@
 #include "light.h"
 
 #define LIGHT_RES_ID    "311/0/5851"
+#define LIGHT_FLASH_ID  "311/0/5850"
 
 extern Serial pc;
 static PwmOut led2(LED2);
 static PwmOut led3(LED3);
 
+static DigitalOut out1(LED1);
+static Ticker flash;
+
+static void flashHandler(void)
+{
+    out1 = !out1;
+}
 
 /* Only GET and PUT method allowed */
 static uint8_t light_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
@@ -19,10 +27,9 @@
     int led_state = 0;
     char led_dimm_temp[4];
 
-    pc.printf("light callback\r\n");
+    pc.printf("light dimmer callback\r\n");
 
-    if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
-    {
+    if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) {
         coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
 
         led_state = led_dimm * 100;
@@ -31,9 +38,7 @@
         coap_res_ptr->payload_len = strlen(led_dimm_temp);
         coap_res_ptr->payload_ptr = (uint8_t*)led_dimm_temp;
         sn_nsdl_send_coap_message(address, coap_res_ptr);
-    }
-    else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
-    {
+    } else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) {
         memcpy(led_dimm_temp, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len);
 
         led_dimm_temp[received_coap_ptr->payload_len] = '\0';
@@ -52,8 +57,52 @@
     return 0;
 }
 
+
+/* Only GET and PUT method allowed */
+static uint8_t light_flash_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
+{
+    sn_coap_hdr_s *coap_res_ptr = 0;
+    static uint8_t flash_state = '0';
+
+    pc.printf("flash callback\r\n");
+
+    if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
+    {
+        coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
+
+        coap_res_ptr->payload_len = 1;
+        coap_res_ptr->payload_ptr = &flash_state;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+    else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
+    {
+        if(received_coap_ptr->payload_len)
+        {
+            if(*(received_coap_ptr->payload_ptr) == '1')
+            {
+                flash.attach(&flashHandler, 1.0f);
+                flash_state = '1';
+                
+            }
+            else if(*(received_coap_ptr->payload_ptr) == '0')
+            {
+                out1 = 0;
+                flash.detach();
+                flash_state = '0';
+            }
+            coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
+            sn_nsdl_send_coap_message(address, coap_res_ptr);
+        }
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+
+    return 0;
+}
+
 int create_light_resource(sn_nsdl_resource_info_s *resource_ptr)
 {
     nsdl_create_dynamic_resource(resource_ptr, sizeof(LIGHT_RES_ID)-1, (uint8_t*)LIGHT_RES_ID, 0, 0, 0, &light_resource_cb, (SN_GRS_GET_ALLOWED | SN_GRS_PUT_ALLOWED));
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(LIGHT_FLASH_ID)-1, (uint8_t*)LIGHT_FLASH_ID, 0, 0, 0, &light_flash_resource_cb, (SN_GRS_GET_ALLOWED | SN_GRS_PUT_ALLOWED));
     return 0;
 }
\ No newline at end of file