Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterfaceUpdate mbed-rtos mbed nanoservice_client_1_12_X
Revision 3:12c28025d4a4, committed 2015-04-13
- Comitter:
- michaeljkoster
- Date:
- Mon Apr 13 22:13:56 2015 +0000
- Parent:
- 2:d758d2248748
- Commit message:
- updated NSDL-C
Changed in this revision
--- a/mbed-rtos.lib Sun Jan 18 18:38:37 2015 +0000 +++ b/mbed-rtos.lib Mon Apr 13 22:13:56 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#9387d4c49609 +http://mbed.org/users/mbed_official/code/mbed-rtos/#83895f30f8f2
--- a/mbed.bld Sun Jan 18 18:38:37 2015 +0000 +++ b/mbed.bld Mon Apr 13 22:13:56 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file
--- a/nanoservice_client_1_12_X.lib Sun Jan 18 18:38:37 2015 +0000 +++ b/nanoservice_client_1_12_X.lib Mon Apr 13 22:13:56 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/michaeljkoster/code/nanoservice_client_1_12_X/#2b79bf135ec2 +http://mbed.org/users/michaeljkoster/code/nanoservice_client_1_12_X/#b5ecd6660d71
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/IPSO_illuminance.cpp Mon Apr 13 22:13:56 2015 +0000
@@ -0,0 +1,62 @@
+// IPSO Illuminance sensor resource implementation
+
+#include "mbed.h"
+#include "nsdl_support.h"
+
+#define ILLUM_RES_ID "3301/0/5700"
+#define ILLUM_RES_RT "urn:X-ipso:illuminance"
+
+extern Serial pc;
+uint8_t illum_max_age = 0;
+uint8_t illum_content_type = 50;
+
+AnalogIn illumSensor(A1);
+int illum_percent;
+char illumPctString[5];
+
+/* Only GET method allowed */
+static uint8_t illuminance_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;
+ illum_percent = illumSensor.read() * 100;
+ sprintf(illumPctString,"%d", illum_percent);
+ pc.printf("illum callback\r\n");
+ pc.printf("illum percent %s\r\n", illumPctString);
+
+ 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 = strlen(illumPctString);
+ coap_res_ptr->payload_ptr = (uint8_t*)illumPctString;
+
+ coap_res_ptr->content_type_ptr = &illum_content_type;
+ coap_res_ptr->content_type_len = sizeof(illum_content_type);
+
+ coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s));
+ if(!coap_res_ptr->options_list_ptr)
+ {
+ pc.printf("cant alloc option list for max-age\r\n");
+ coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover
+ }
+ memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s));
+ coap_res_ptr->options_list_ptr->max_age_ptr = &illum_max_age;
+ coap_res_ptr->options_list_ptr->max_age_len = sizeof(illum_max_age);
+
+ sn_nsdl_send_coap_message(address, coap_res_ptr);
+ nsdl_free(coap_res_ptr->options_list_ptr);
+ coap_res_ptr->options_list_ptr = NULL;
+ coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory
+
+ }
+
+ sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+
+ return 0;
+}
+
+int create_IPSO_illuminance_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+ nsdl_create_dynamic_resource(resource_ptr, sizeof(ILLUM_RES_ID)-1, (uint8_t*)ILLUM_RES_ID, sizeof(ILLUM_RES_RT)-1, (uint8_t*)ILLUM_RES_RT, 0, &illuminance_resource_cb, (SN_GRS_GET_ALLOWED));
+ return 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/IPSO_illuminance.h Mon Apr 13 22:13:56 2015 +0000 @@ -0,0 +1,10 @@ +// IPSO Illuminance Sensor implementation + +#ifndef IPSO_ILLUM_H +#define IPSO_ILLUM_H + +#include "nsdl_support.h" + +int create_IPSO_illuminance_resource(sn_nsdl_resource_info_s *resource_ptr); + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/IPSO_presence.cpp Mon Apr 13 22:13:56 2015 +0000
@@ -0,0 +1,113 @@
+// IPSO Presence sensor resource implementation
+
+#include "mbed.h"
+#include "rtos.h"
+#include "nsdl_support.h"
+
+#define PRESENCE_RES_ID "3302/0/5500"
+#define PRESENCE_RES_RT "urn:X-ipso:presence"
+
+extern Serial pc;
+uint8_t presence_max_age = 0;
+uint8_t presence_content_type = 50;
+
+static uint8_t pres_obs_number = 0;
+static uint8_t *pres_obs_token_ptr = NULL;
+static uint8_t pres_obs_token_len = 0;
+
+DigitalIn presenceSensor(D2);
+uint8_t presence = 0;
+uint8_t last_presence = 0;
+char presenceString[1];
+
+static void pres_observe_thread(void const *args)
+ {
+ while (true)
+ {
+ wait(.1);
+ presence = presenceSensor.read();
+ if((presence != last_presence) && pres_obs_number != 0 && pres_obs_token_ptr != NULL)
+ {
+ last_presence = presence;
+ pc.printf("presence: %d\r\n", presence);
+ pres_obs_number++;
+ sprintf(presenceString,"%d", presence);
+ if(sn_nsdl_send_observation_notification(pres_obs_token_ptr, pres_obs_token_len, (uint8_t*)presenceString, strlen(presenceString), &pres_obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0)
+ pc.printf("Presence observation sending failed\r\n");
+ else
+ pc.printf("Presence observation\r\n");
+ }
+ }
+ }
+
+
+/* Only GET method allowed */
+static uint8_t presence_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;
+ presence = presenceSensor.read();
+ sprintf(presenceString,"%d", presence);
+ pc.printf("presence callback\r\n");
+ pc.printf("presence state %s\r\n", presenceString);
+
+ 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 = strlen(presenceString);
+ coap_res_ptr->payload_ptr = (uint8_t*)presenceString;
+
+ coap_res_ptr->content_type_ptr = &presence_content_type;
+ coap_res_ptr->content_type_len = sizeof(presence_content_type);
+
+ coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s));
+ if(!coap_res_ptr->options_list_ptr)
+ {
+ pc.printf("cant alloc option list\r\n");
+ coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover
+ }
+ memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s));
+ coap_res_ptr->options_list_ptr->max_age_ptr = &presence_max_age;
+ coap_res_ptr->options_list_ptr->max_age_len = sizeof(presence_max_age);
+
+ if(received_coap_ptr->token_ptr)
+ {
+ pc.printf("Token included\r\n");
+ if(pres_obs_token_ptr)
+ {
+ free(pres_obs_token_ptr);
+ pres_obs_token_ptr = 0;
+ }
+ pres_obs_token_ptr = (uint8_t*)malloc(received_coap_ptr->token_len);
+ if(pres_obs_token_ptr)
+ {
+ memcpy(pres_obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len);
+ pres_obs_token_len = received_coap_ptr->token_len;
+ }
+ }
+
+ if(received_coap_ptr->options_list_ptr->observe)
+ {
+ coap_res_ptr->options_list_ptr->observe_ptr = &pres_obs_number;
+ coap_res_ptr->options_list_ptr->observe_len = 1;
+ pres_obs_number++;
+ }
+
+ sn_nsdl_send_coap_message(address, coap_res_ptr);
+ nsdl_free(coap_res_ptr->options_list_ptr);
+ coap_res_ptr->options_list_ptr = NULL;
+ coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory
+ }
+
+ sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+
+ return 0;
+}
+
+int create_IPSO_presence_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+ static Thread exec_thread(pres_observe_thread);
+
+ nsdl_create_dynamic_resource(resource_ptr, sizeof(PRESENCE_RES_ID)-1, (uint8_t*)PRESENCE_RES_ID, sizeof(PRESENCE_RES_RT)-1, (uint8_t*)PRESENCE_RES_RT, 1, &presence_resource_cb, (SN_GRS_GET_ALLOWED));
+ return 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/IPSO_presence.h Mon Apr 13 22:13:56 2015 +0000 @@ -0,0 +1,10 @@ +// IPSO Presence Sensor implementation + +#ifndef IPSO_PRESENCE_H +#define IPSO_PRESENCE_H + +#include "nsdl_support.h" + +int create_IPSO_presence_resource(sn_nsdl_resource_info_s *resource_ptr); + +#endif