cellular port

Dependencies:   Beep C027_Support C12832 LM75B MMA7660 mbed-rtos mbed nsdl_lib

This is a port of the NSDL HelloWorld for cellular.

To run the example you need a C027 and the ARM mbed application shield. The example uses cellular instead of ethernet and takes the true position from the GPS instead of using a fixed position.

Committer:
mazgch
Date:
Fri Jun 20 12:11:44 2014 +0000
Revision:
12:2799b212c729
Parent:
11:fa12b9f50538
update libraries and make it more portable for shields

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 11:fa12b9f50538 1 // GPS resource implementation
mazgch 11:fa12b9f50538 2
mazgch 11:fa12b9f50538 3 #include "mbed.h"
mazgch 11:fa12b9f50538 4 #include "rtos.h"
mazgch 11:fa12b9f50538 5 #include "nsdl_support.h"
mazgch 11:fa12b9f50538 6 #include "gps_res.h"
mazgch 11:fa12b9f50538 7
mazgch 11:fa12b9f50538 8 #define GPS_RES_ID "gps/loc"
mazgch 11:fa12b9f50538 9
mazgch 11:fa12b9f50538 10 static Mutex mutex;
mazgch 11:fa12b9f50538 11 static char res_gps_val[32] = "";
mazgch 11:fa12b9f50538 12
mazgch 11:fa12b9f50538 13 void gps_resource_set(double lat, double lon)
mazgch 11:fa12b9f50538 14 {
mazgch 11:fa12b9f50538 15 mutex.lock();
mazgch 11:fa12b9f50538 16 sprintf(res_gps_val,"%8.6f,%8.6f", lat, lon);
mazgch 11:fa12b9f50538 17 mutex.unlock();
mazgch 11:fa12b9f50538 18 }
mazgch 11:fa12b9f50538 19
mazgch 11:fa12b9f50538 20 /* Only GET method allowed */
mazgch 11:fa12b9f50538 21 static uint8_t gps_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
mazgch 11:fa12b9f50538 22 {
mazgch 11:fa12b9f50538 23 sn_coap_hdr_s *coap_res_ptr = 0;
mazgch 12:2799b212c729 24 char gps_val[sizeof(res_gps_val)];
mazgch 11:fa12b9f50538 25
mazgch 11:fa12b9f50538 26 printf("gps callback\r\n");
mazgch 11:fa12b9f50538 27
mazgch 11:fa12b9f50538 28 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
mazgch 11:fa12b9f50538 29 mutex.lock();
mazgch 12:2799b212c729 30 strcpy(gps_val, res_gps_val);
mazgch 11:fa12b9f50538 31 mutex.unlock();
mazgch 12:2799b212c729 32 coap_res_ptr->payload_ptr = (uint8_t*)gps_val;
mazgch 12:2799b212c729 33 coap_res_ptr->payload_len = strlen(gps_val);
mazgch 11:fa12b9f50538 34
mazgch 11:fa12b9f50538 35 sn_nsdl_send_coap_message(address, coap_res_ptr);
mazgch 11:fa12b9f50538 36 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
mazgch 11:fa12b9f50538 37
mazgch 11:fa12b9f50538 38 return 0;
mazgch 11:fa12b9f50538 39 }
mazgch 11:fa12b9f50538 40
mazgch 11:fa12b9f50538 41 int create_gps_resource(sn_nsdl_resource_info_s *resource_ptr)
mazgch 11:fa12b9f50538 42 {
mazgch 11:fa12b9f50538 43 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);
mazgch 11:fa12b9f50538 44 return 0;
mazgch 11:fa12b9f50538 45 }
mazgch 11:fa12b9f50538 46