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

Committer:
sam_grove
Date:
Tue Apr 29 00:41:05 2014 +0000
Revision:
32:7f3f1ef700e3
Parent:
8:f0ecb62bda47
mbed emt node

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 2:7e489126fe7a 1 // GPS resource implementation
bogdanm 2:7e489126fe7a 2
bogdanm 2:7e489126fe7a 3 #include "mbed.h"
bogdanm 2:7e489126fe7a 4 #include "nsdl_support.h"
bogdanm 2:7e489126fe7a 5 #include "relay.h"
bogdanm 2:7e489126fe7a 6 #include "Beep.h"
bogdanm 2:7e489126fe7a 7
zdshelby 8:f0ecb62bda47 8 #define RELAY_RES_ID "306/0/5850"
bogdanm 2:7e489126fe7a 9
bogdanm 2:7e489126fe7a 10 extern Serial pc;
bogdanm 2:7e489126fe7a 11 static Beep buzzer(p26);
bogdanm 2:7e489126fe7a 12
sam_grove 32:7f3f1ef700e3 13 static DigitalOut r(p21);
sam_grove 32:7f3f1ef700e3 14 static DigitalOut b(p22);
sam_grove 32:7f3f1ef700e3 15 static Ticker flash;
sam_grove 32:7f3f1ef700e3 16
sam_grove 32:7f3f1ef700e3 17 void rbHandler(void)
sam_grove 32:7f3f1ef700e3 18 {
sam_grove 32:7f3f1ef700e3 19 r = !r;
sam_grove 32:7f3f1ef700e3 20 b = !b;
sam_grove 32:7f3f1ef700e3 21 buzzer.beep(1000, 0.1f);
sam_grove 32:7f3f1ef700e3 22 }
sam_grove 32:7f3f1ef700e3 23
bogdanm 2:7e489126fe7a 24 /* Only GET and PUT method allowed */
bogdanm 2:7e489126fe7a 25 static uint8_t relay_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
bogdanm 2:7e489126fe7a 26 {
bogdanm 2:7e489126fe7a 27 sn_coap_hdr_s *coap_res_ptr = 0;
bogdanm 2:7e489126fe7a 28 static uint8_t relay_state = '0';
bogdanm 2:7e489126fe7a 29
bogdanm 2:7e489126fe7a 30 pc.printf("relay callback\r\n");
bogdanm 2:7e489126fe7a 31
bogdanm 2:7e489126fe7a 32 if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
bogdanm 2:7e489126fe7a 33 {
bogdanm 2:7e489126fe7a 34 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
bogdanm 2:7e489126fe7a 35
bogdanm 2:7e489126fe7a 36 coap_res_ptr->payload_len = 1;
bogdanm 2:7e489126fe7a 37 coap_res_ptr->payload_ptr = &relay_state;
bogdanm 2:7e489126fe7a 38 sn_nsdl_send_coap_message(address, coap_res_ptr);
bogdanm 2:7e489126fe7a 39 }
bogdanm 2:7e489126fe7a 40 else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
bogdanm 2:7e489126fe7a 41 {
bogdanm 2:7e489126fe7a 42 if(received_coap_ptr->payload_len)
bogdanm 2:7e489126fe7a 43 {
bogdanm 2:7e489126fe7a 44 if(*(received_coap_ptr->payload_ptr) == '1')
bogdanm 2:7e489126fe7a 45 {
sam_grove 32:7f3f1ef700e3 46 flash.attach(&rbHandler, 0.2f);
sam_grove 32:7f3f1ef700e3 47 r = 1;
sam_grove 32:7f3f1ef700e3 48 b = 0;
bogdanm 2:7e489126fe7a 49 relay_state = '1';
bogdanm 2:7e489126fe7a 50
bogdanm 2:7e489126fe7a 51 }
bogdanm 2:7e489126fe7a 52 else if(*(received_coap_ptr->payload_ptr) == '0')
bogdanm 2:7e489126fe7a 53 {
bogdanm 2:7e489126fe7a 54 buzzer.nobeep();
sam_grove 32:7f3f1ef700e3 55 flash.detach();
sam_grove 32:7f3f1ef700e3 56 r = 1;
sam_grove 32:7f3f1ef700e3 57 b = 1;
bogdanm 2:7e489126fe7a 58 relay_state = '0';
bogdanm 2:7e489126fe7a 59 }
bogdanm 2:7e489126fe7a 60 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
bogdanm 2:7e489126fe7a 61 sn_nsdl_send_coap_message(address, coap_res_ptr);
bogdanm 2:7e489126fe7a 62 }
bogdanm 2:7e489126fe7a 63 }
bogdanm 2:7e489126fe7a 64
bogdanm 2:7e489126fe7a 65 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
bogdanm 2:7e489126fe7a 66
bogdanm 2:7e489126fe7a 67 return 0;
bogdanm 2:7e489126fe7a 68 }
bogdanm 2:7e489126fe7a 69
bogdanm 2:7e489126fe7a 70 int create_relay_resource(sn_nsdl_resource_info_s *resource_ptr)
bogdanm 2:7e489126fe7a 71 {
bogdanm 2:7e489126fe7a 72 nsdl_create_dynamic_resource(resource_ptr, sizeof(RELAY_RES_ID)-1, (uint8_t*)RELAY_RES_ID, 0, 0, 0, &relay_resource_cb, (SN_GRS_GET_ALLOWED | SN_GRS_PUT_ALLOWED));
sam_grove 32:7f3f1ef700e3 73 r = 1;
sam_grove 32:7f3f1ef700e3 74 b = 1;
bogdanm 2:7e489126fe7a 75 return 0;
bogdanm 2:7e489126fe7a 76 }