NanoService Device Library Hello World
Dependencies: Beep C12832_lcd EthernetInterface LM75B MMA7660 mbed-rtos mbed nsdl_lib
gps.cpp
00001 // GPS resource implementation 00002 00003 #include "mbed.h" 00004 #include "nsdl_support.h" 00005 #include "gps.h" 00006 00007 #define GPS_RES_ID "gps/loc" 00008 00009 extern Serial pc; 00010 static uint8_t res_gps_val[] = {"52.182382,0.178849"}; 00011 00012 /* Only GET method allowed */ 00013 static uint8_t gps_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) 00014 { 00015 sn_coap_hdr_s *coap_res_ptr = 0; 00016 static float led_dimm = 0; 00017 int led_state = 0; 00018 char led_dimm_temp[4]; 00019 00020 pc.printf("gps callback\r\n"); 00021 00022 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); 00023 00024 led_state = led_dimm * 100; 00025 sprintf(led_dimm_temp, "%d", led_state); 00026 00027 coap_res_ptr->payload_len = sizeof(res_gps_val)-1; 00028 coap_res_ptr->payload_ptr = (uint8_t*)res_gps_val; 00029 00030 sn_nsdl_send_coap_message(address, coap_res_ptr); 00031 00032 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); 00033 00034 return 0; 00035 } 00036 00037 int create_gps_resource(sn_nsdl_resource_info_s *resource_ptr) 00038 { 00039 nsdl_create_dynamic_resource(resource_ptr, sizeof(GPS_RES_ID)-1, (uint8_t*)GPS_RES_ID, 0, 0, 0, &gps_resource_cb, SN_GRS_GET_ALLOWED); 00040 return 0; 00041 }
Generated on Wed Jul 13 2022 06:16:52 by 1.7.2