NanoService Example for u-blox Cellular modems

Dependencies:   Beep LM75B MMA7660 mbed nsdl_lib

Fork of NSDL_HelloWorld by Sensinode

Committer:
zdshelby
Date:
Wed Oct 30 00:46:59 2013 +0000
Revision:
10:4cb556c7845e
Parent:
9:ccb9e53d5471
Child:
11:3b7ae478dcd1
- Removed last of pc. debug

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 "gps.h"
bogdanm 2:7e489126fe7a 6
bogdanm 2:7e489126fe7a 7 #define GPS_RES_ID "gps/loc"
bogdanm 2:7e489126fe7a 8
bogdanm 2:7e489126fe7a 9 static uint8_t res_gps_val[] = {"52.182382,0.178849"};
bogdanm 2:7e489126fe7a 10
bogdanm 2:7e489126fe7a 11 /* Only GET method allowed */
bogdanm 2:7e489126fe7a 12 static uint8_t gps_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
bogdanm 2:7e489126fe7a 13 {
bogdanm 2:7e489126fe7a 14 sn_coap_hdr_s *coap_res_ptr = 0;
bogdanm 2:7e489126fe7a 15 static float led_dimm = 0;
bogdanm 2:7e489126fe7a 16 int led_state = 0;
bogdanm 2:7e489126fe7a 17 char led_dimm_temp[4];
bogdanm 2:7e489126fe7a 18
zdshelby 9:ccb9e53d5471 19 printf("gps callback\r\n");
bogdanm 2:7e489126fe7a 20
bogdanm 2:7e489126fe7a 21 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
bogdanm 2:7e489126fe7a 22
bogdanm 2:7e489126fe7a 23 led_state = led_dimm * 100;
bogdanm 2:7e489126fe7a 24 sprintf(led_dimm_temp, "%d", led_state);
bogdanm 2:7e489126fe7a 25
bogdanm 2:7e489126fe7a 26 coap_res_ptr->payload_len = sizeof(res_gps_val)-1;
bogdanm 2:7e489126fe7a 27 coap_res_ptr->payload_ptr = (uint8_t*)res_gps_val;
bogdanm 2:7e489126fe7a 28
bogdanm 2:7e489126fe7a 29 sn_nsdl_send_coap_message(address, coap_res_ptr);
bogdanm 2:7e489126fe7a 30
bogdanm 2:7e489126fe7a 31 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
bogdanm 2:7e489126fe7a 32
bogdanm 2:7e489126fe7a 33 return 0;
bogdanm 2:7e489126fe7a 34 }
bogdanm 2:7e489126fe7a 35
bogdanm 2:7e489126fe7a 36 int create_gps_resource(sn_nsdl_resource_info_s *resource_ptr)
bogdanm 2:7e489126fe7a 37 {
bogdanm 2:7e489126fe7a 38 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);
bogdanm 2:7e489126fe7a 39 return 0;
bogdanm 2:7e489126fe7a 40 }