You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2017/04/26 22:40:53 UTC

[05/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-729 SensorAPI: Send sensor data over OIC

MYNEWT-729 SensorAPI: Send sensor data over OIC

- use valid URIs as per spec


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/54533236
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/54533236
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/54533236

Branch: refs/heads/bluetooth5
Commit: 5453323642458eccb8691f450302220d76d6f93d
Parents: 2300485
Author: Vipul Rahane <vi...@apache.org>
Authored: Fri Apr 14 11:37:55 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Mon Apr 17 16:14:20 2017 -0700

----------------------------------------------------------------------
 hw/sensor/src/sensor_oic.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/54533236/hw/sensor/src/sensor_oic.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_oic.c b/hw/sensor/src/sensor_oic.c
index ab296a7..27edafd 100644
--- a/hw/sensor/src/sensor_oic.c
+++ b/hw/sensor/src/sensor_oic.c
@@ -44,6 +44,8 @@
 #include <oic/oc_ri.h>
 #include <oic/oc_api.h>
 
+static const char g_s_oic_dn[] = "x.mynewt.sensors.r.";
+
 static int
 sensor_oic_encode(struct sensor* sensor, void *arg, void *databuf)
 {
@@ -456,19 +458,13 @@ sensor_oic_get_data(oc_request_t *request, oc_interface_mask_t interface)
     int rc;
     struct sensor *sensor;
     struct sensor_listener listener;
-    char *devname;
+    char devname[COAP_MAX_URI] = {0};
     char *typename;
     sensor_type_t type;
-    const char s[2] = "/";
-    char tmpstr[COAP_MAX_URI];
 
-    memcpy(tmpstr, (char *)&(request->resource->uri.os_str[1]),
+    memcpy(devname, (char *)&(request->resource->uri.os_str[1]),
            request->resource->uri.os_sz - 1);
 
-    /* Parse the sensor device name from the uri  */
-    devname = strtok(tmpstr, s);
-    typename = strtok(NULL, s);
-
     /* Look up sensor by name */
     sensor = sensor_mgr_find_next_bydevname(devname, NULL);
     if (!sensor) {
@@ -476,6 +472,11 @@ sensor_oic_get_data(oc_request_t *request, oc_interface_mask_t interface)
         goto err;
     }
 
+    if (memcmp(g_s_oic_dn, request->resource->types.oa_arr.s,
+               sizeof(g_s_oic_dn) - 1)) {
+        goto err;
+    }
+
     oc_rep_start_root_object();
 
     switch (interface) {
@@ -485,6 +486,8 @@ sensor_oic_get_data(oc_request_t *request, oc_interface_mask_t interface)
         /* Register a listener and then trigger/read a bunch of samples */
         memset(&listener, 0, sizeof(listener));
 
+        typename =
+            &(request->resource->types.oa_arr.s[sizeof(g_s_oic_dn) - 1]);
         rc = sensor_typename_to_type(typename, &type, sensor);
         if (rc) {
             /* Type either not supported by sensor or not found */
@@ -561,15 +564,13 @@ sensor_oic_init(void)
                 }
 
                 memset(tmpstr, 0, sizeof(tmpstr));
-                snprintf(tmpstr, sizeof(tmpstr), "/%s/%s",
-                         sensor->s_dev->od_name, typename);
+                snprintf(tmpstr, sizeof(tmpstr), "/%s", sensor->s_dev->od_name);
+
                 res = oc_new_resource(tmpstr, 1, 0);
 
                 memset(tmpstr, 0, sizeof(tmpstr));
-                snprintf(tmpstr, sizeof(tmpstr), "sensors.r.%s", sensor->s_dev->od_name);
-
+                snprintf(tmpstr, sizeof(tmpstr), "x.mynewt.sensors.r.%s", typename);
                 oc_resource_bind_resource_type(res, tmpstr);
-
                 oc_resource_bind_resource_interface(res, OC_IF_R);
                 oc_resource_set_default_interface(res, OC_IF_R);