MYNEWT-729 SensorAPI: Send sensor data over OIC

- Add timestamp in oic sensor payload


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/a6b41a55
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a6b41a55
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a6b41a55

Branch: refs/heads/master
Commit: a6b41a554c4dc5855658b8cca4698ae2576af0cd
Parents: ecf3a28
Author: Vipul Rahane <vipulrah...@apache.org>
Authored: Fri Apr 7 17:06:00 2017 -0700
Committer: Vipul Rahane <vipulrah...@apache.org>
Committed: Mon Apr 17 16:14:20 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/src/bleprph.h | 59 ++++++++++++++++++++++++++++++++++++
 hw/sensor/src/sensor_oic.c      |  6 +++-
 2 files changed, 64 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a6b41a55/apps/sensors_test/src/bleprph.h
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/bleprph.h b/apps/sensors_test/src/bleprph.h
new file mode 100644
index 0000000..2e3f024
--- /dev/null
+++ b/apps/sensors_test/src/bleprph.h
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLEPRPH_
+#define H_BLEPRPH_
+
+#include "log/log.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ble_hs_cfg;
+struct ble_gatt_register_ctxt;
+
+extern struct log bleprph_log;
+
+/* bleprph uses the first "peruser" log module. */
+#define BLEPRPH_LOG_MODULE  (LOG_MODULE_PERUSER + 0)
+
+/* Convenience macro for logging to the bleprph module. */
+#define BLEPRPH_LOG(lvl, ...) \
+    LOG_ ## lvl(&bleprph_log, BLEPRPH_LOG_MODULE, __VA_ARGS__)
+
+/** GATT server. */
+#define GATT_SVR_SVC_ALERT_UUID               0x1811
+#define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID   0x2A47
+#define GATT_SVR_CHR_NEW_ALERT                0x2A46
+#define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID   0x2A48
+#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID      0x2A45
+#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT        0x2A44
+
+void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
+int gatt_svr_init(void);
+
+/** Misc. */
+void print_bytes(const uint8_t *bytes, int len);
+void print_addr(const void *addr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a6b41a55/hw/sensor/src/sensor_oic.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_oic.c b/hw/sensor/src/sensor_oic.c
index ea86122..b30f417 100644
--- a/hw/sensor/src/sensor_oic.c
+++ b/hw/sensor/src/sensor_oic.c
@@ -252,7 +252,7 @@ sensor_oic_encode(struct sensor* sensor, void *arg, void 
*databuf)
             }
             if (((struct sensor_color_data *)(databuf))->scd_cratio_is_valid) {
                 oc_rep_set_double(root, cratio,
-                    ((struct sensor_color_data 
*)(databuf))->scd_cratio_is_valid);
+                    ((struct sensor_color_data *)(databuf))->scd_cratio);
             } else {
                 goto err;
             }
@@ -280,6 +280,10 @@ sensor_oic_encode(struct sensor* sensor, void *arg, void 
*databuf)
             goto err;
     }
 
+    oc_rep_set_uint(root, ts_secs, (long int)sensor->s_sts.st_ostv.tv_sec);
+    oc_rep_set_int(root, ts_usecs, (int)sensor->s_sts.st_ostv.tv_usec);
+    oc_rep_set_uint(root, ts_cputime, (unsigned int)sensor->s_sts.st_cputime);
+
     return 0;
 err:
     return rc;

Reply via email to