You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2017/04/17 23:46:13 UTC

[10/11] incubator-mynewt-core git commit: MYNEWT-729 SensorAPI: Send sensor data over OIC

MYNEWT-729 SensorAPI: Send sensor data over OIC

- Addressing review comments by @mkiiskila
- Move private apis from include/bno055.h to bno055/bno055_priv.h


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

Branch: refs/heads/master
Commit: e301553f5eaaa2af8f3e5f622d29fd2d5cbc6971
Parents: 5c641d1
Author: Vipul Rahane <vi...@apache.org>
Authored: Mon Apr 17 16:08:37 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Mon Apr 17 16:31:44 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/pkg.yml                       |  4 +-
 apps/sensors_test/src/gatt_svr.c                |  2 +-
 apps/sensors_test/src/main.c                    | 33 ++++++-----
 apps/sensors_test/src/misc.c                    | 43 ++++++++++++++
 apps/sensors_test/syscfg.yml                    | 13 ++++-
 .../sensors/bno055/include/bno055/bno055.h      | 33 -----------
 hw/drivers/sensors/bno055/src/bno055_priv.h     | 34 +++++++++++
 hw/sensor/include/sensor/sensor.h               |  2 +-
 hw/sensor/pkg.yml                               |  8 ++-
 hw/sensor/src/bleprph.h                         | 59 --------------------
 hw/sensor/src/misc.c                            | 43 --------------
 hw/sensor/src/sensor_oic.c                      |  3 +-
 hw/sensor/syscfg.yml                            | 11 +---
 13 files changed, 122 insertions(+), 166 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/apps/sensors_test/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/sensors_test/pkg.yml b/apps/sensors_test/pkg.yml
index 39250ae..4f8e25c 100644
--- a/apps/sensors_test/pkg.yml
+++ b/apps/sensors_test/pkg.yml
@@ -44,8 +44,10 @@ pkg.deps:
     - mgmt/imgmgr
     #- mgmt/newtmgr
 
-pkg.deps.SENSOR_BLE_OIC:
+pkg.deps.SENSOR_OIC:
     - mgmt/oicmgr
+
+pkg.deps.SENSOR_BLE:
     - net/nimble/controller
     - net/nimble/host
     - net/nimble/host/services/gap

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/apps/sensors_test/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/gatt_svr.c b/apps/sensors_test/src/gatt_svr.c
index e29f007..0e2e004 100644
--- a/apps/sensors_test/src/gatt_svr.c
+++ b/apps/sensors_test/src/gatt_svr.c
@@ -17,7 +17,7 @@
  * under the License.
  */
 #include <syscfg/syscfg.h>
-#if MYNEWT_VAL(SENSOR_BLE_OIC)
+#if MYNEWT_VAL(SENSOR_BLE)
 
 #include <assert.h>
 #include <stdio.h>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index 322b83b..09f3e40 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -47,17 +47,25 @@
 #include <flash_test/flash_test.h>
 #include <reboot/log_reboot.h>
 #include <id/id.h>
+#include <os/os_time.h>
+
+#if MYNEWT_VAL(SENSOR_OIC)
+#include <oic/oc_api.h>
+#include <oic/oc_gatt.h>
+
+extern int oc_stack_errno;
+
+static const oc_handler_t sensor_oic_handler = {
+    .init = sensor_oic_init,
+};
+
+#endif
 
-#if MYNEWT_VAL(SENSOR_BLE_OIC)
+#if MYNEWT_VAL(SENSOR_BLE)
 /* BLE */
 #include <nimble/ble.h>
 #include <host/ble_hs.h>
 #include <services/gap/ble_svc_gap.h>
-
-#include <os/os_time.h>
-#include <oic/oc_api.h>
-#include <oic/oc_gatt.h>
-
 /* Application-specified header. */
 #include "bleprph.h"
 
@@ -123,12 +131,7 @@ static char test_str[32];
 static uint32_t cbmem_buf[MAX_CBMEM_BUF];
 static struct cbmem cbmem;
 
-#if MYNEWT_VAL(SENSOR_BLE_OIC)
-extern int oc_stack_errno;
-
-static const oc_handler_t sensor_oic_handler = {
-    .init = sensor_oic_init,
-};
+#if MYNEWT_VAL(SENSOR_OIC) && MYNEWT_VAL(SENSOR_BLE)
 
 /**
  * Logs information about a connection to the console.
@@ -632,7 +635,7 @@ sensors_dev_shell_init(void)
 static void
 sensor_ble_oic_server_init(void)
 {
-#if MYNEWT_VAL(SENSOR_BLE_OIC)
+#if MYNEWT_VAL(SENSOR_BLE) && MYNEWT_VAL(SENSOR_OIC)
     int rc;
 
     /* Set initial BLE device address. */
@@ -661,7 +664,7 @@ sensor_ble_oic_server_init(void)
 static void
 ble_oic_log_init(void)
 {
-#if MYNEWT_VAL(SENSOR_BLE_OIC)
+#if MYNEWT_VAL(SENSOR_BLE)
     /* Initialize the bleprph log. */
     log_register("bleprph", &bleprph_log, &log_console_handler, NULL,
                  LOG_SYSLEVEL);
@@ -669,7 +672,9 @@ ble_oic_log_init(void)
     /* Initialize the NimBLE host configuration. */
     log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
                  LOG_SYSLEVEL);
+#endif
 
+#if MYNEWT_VAL(SENSOR_OIC)
     /* Initialize the OIC  */
     log_register("oic", &oc_log, &log_console_handler, NULL, LOG_SYSLEVEL);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/apps/sensors_test/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/misc.c b/apps/sensors_test/src/misc.c
new file mode 100644
index 0000000..8ec785e
--- /dev/null
+++ b/apps/sensors_test/src/misc.c
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#include "bleprph.h"
+
+/**
+ * Utility function to log an array of bytes.
+ */
+void
+print_bytes(const uint8_t *bytes, int len)
+{
+    int i;
+
+    for (i = 0; i < len; i++) {
+        BLEPRPH_LOG(INFO, "%s0x%02x", i != 0 ? ":" : "", bytes[i]);
+    }
+}
+
+void
+print_addr(const void *addr)
+{
+    const uint8_t *u8p;
+
+    u8p = addr;
+    BLEPRPH_LOG(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",
+                u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/apps/sensors_test/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/sensors_test/syscfg.yml b/apps/sensors_test/syscfg.yml
index 8623667..81876bc 100644
--- a/apps/sensors_test/syscfg.yml
+++ b/apps/sensors_test/syscfg.yml
@@ -44,10 +44,13 @@ syscfg.vals:
     TSL2561_CLI: 0
     BNO055_CLI: 1
     TCS34725_CLI: 1
-    SENSOR_BLE_OIC: 1
+
+    # Setup Sensor BLE OIC GATT Server
+    SENSOR_OIC: 1
     BLE_ROLE_CENTRAL: 0
     BLE_ROLE_OBSERVER: 0
     OC_SERVER: 1
+
     OC_TRANSPORT_GATT: 1
     OC_APP_RESOURCES : 20
 
@@ -69,3 +72,11 @@ syscfg.defs:
     SIM_ACCEL_PRESENT:
         description: 'SIM ACCEL is present'
         value : 0
+    SENSOR_BLE:
+        description: 'BLE transport is used for sensor data'
+        value : 1
+        restrictions:
+        - BLE_ROLE_BROADCASTER
+        - '!BLE_ROLE_CENTRAL'
+        - '!BLE_ROLE_OBSERVER'
+        - BLE_ROLE_PERIPHERAL

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/hw/drivers/sensors/bno055/include/bno055/bno055.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/include/bno055/bno055.h b/hw/drivers/sensors/bno055/include/bno055/bno055.h
index c8bd5c6..af1c836 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -226,39 +226,6 @@ int
 bno055_get_temp(int8_t *temp);
 
 /**
- * Reads a single byte from the specified register
- *
- * @param The register address to read from
- * @param Pointer to where the register value should be written
- *
- * @return 0 on success, non-zero error on failure.
- */
-int
-bno055_read8(uint8_t reg, uint8_t *value);
-
-/**
- * Writes a single byte to the specified register
- *
- * @param The register address to write to
- * @param The value to write
- *
- * @return 0 on success, non-zero error on failure.
- */
-int
-bno055_write8(uint8_t reg, uint8_t value);
-
-/**
- * Writes a multiple bytes to the specified register
- *
- * @param The register address to write to
- * @param The data buffer to write from
- *
- * @return 0 on success, non-zero error on failure.
- */
-int
-bno055_writelen(uint8_t reg, uint8_t *buffer, uint8_t len);
-
-/**
  * Gets current calibration status
  *
  * @param Calibration info structure to fill up calib state

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/hw/drivers/sensors/bno055/src/bno055_priv.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_priv.h b/hw/drivers/sensors/bno055/src/bno055_priv.h
index 5e78b51..e25671c 100644
--- a/hw/drivers/sensors/bno055/src/bno055_priv.h
+++ b/hw/drivers/sensors/bno055/src/bno055_priv.h
@@ -260,3 +260,37 @@
 #define BNO055_INT_ACC_SM                                         32
 
 #define BNO055_ID                                               0xA0
+
+/**
+ * Reads a single byte from the specified register
+ *
+ * @param The register address to read from
+ * @param Pointer to where the register value should be written
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bno055_read8(uint8_t reg, uint8_t *value);
+
+/**
+ * Writes a single byte to the specified register
+ *
+ * @param The register address to write to
+ * @param The value to write
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bno055_write8(uint8_t reg, uint8_t value);
+
+/**
+ * Writes a multiple bytes to the specified register
+ *
+ * @param The register address to write to
+ * @param The data buffer to write from
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bno055_writelen(uint8_t reg, uint8_t *buffer, uint8_t len);
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/hw/sensor/include/sensor/sensor.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index 9435106..fb5bf2d 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -343,7 +343,7 @@ int
 sensor_shell_stol(char *param_val, long min, long max, long *output);
 #endif
 
-#if MYNEWT_VAL(SENSOR_BLE_OIC)
+#if MYNEWT_VAL(SENSOR_OIC)
 void sensor_oic_init(void);
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/hw/sensor/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/sensor/pkg.yml b/hw/sensor/pkg.yml
index bdd0e0b..369b85d 100644
--- a/hw/sensor/pkg.yml
+++ b/hw/sensor/pkg.yml
@@ -24,10 +24,14 @@ pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
 pkg.deps:
+    - kernel/os
+
+pkg.deps.SENSOR_OIC:
+    - net/oic
+
+pkg.deps.SENSOR_CLI:
     - sys/shell
     - sys/console/full
-    - sys/log/full
-    - sys/stats/full
 
 pkg.init:
     sensor_pkg_init: 501

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/hw/sensor/src/bleprph.h
----------------------------------------------------------------------
diff --git a/hw/sensor/src/bleprph.h b/hw/sensor/src/bleprph.h
deleted file mode 100644
index 2e3f024..0000000
--- a/hw/sensor/src/bleprph.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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/e301553f/hw/sensor/src/misc.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/misc.c b/hw/sensor/src/misc.c
deleted file mode 100644
index 8ec785e..0000000
--- a/hw/sensor/src/misc.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- */
-
-#include "bleprph.h"
-
-/**
- * Utility function to log an array of bytes.
- */
-void
-print_bytes(const uint8_t *bytes, int len)
-{
-    int i;
-
-    for (i = 0; i < len; i++) {
-        BLEPRPH_LOG(INFO, "%s0x%02x", i != 0 ? ":" : "", bytes[i]);
-    }
-}
-
-void
-print_addr(const void *addr)
-{
-    const uint8_t *u8p;
-
-    u8p = addr;
-    BLEPRPH_LOG(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",
-                u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/hw/sensor/src/sensor_oic.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_oic.c b/hw/sensor/src/sensor_oic.c
index 27edafd..de9e65a 100644
--- a/hw/sensor/src/sensor_oic.c
+++ b/hw/sensor/src/sensor_oic.c
@@ -19,7 +19,7 @@
 
 #include "syscfg/syscfg.h"
 
-#if MYNEWT_VAL(SENSOR_BLE_OIC)
+#if MYNEWT_VAL(SENSOR_OIC)
 
 #include <string.h>
 #include <stdio.h>
@@ -37,7 +37,6 @@
 #include "sensor/quat.h"
 #include "sensor/euler.h"
 #include "sensor/color.h"
-#include "console/console.h"
 
 /* OIC */
 #include <oic/oc_rep.h>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e301553f/hw/sensor/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/sensor/syscfg.yml b/hw/sensor/syscfg.yml
index abe193e..3495534 100644
--- a/hw/sensor/syscfg.yml
+++ b/hw/sensor/syscfg.yml
@@ -27,15 +27,8 @@ syscfg.defs:
         description: 'Whether or not to enable the sensor shell support'
         value: 1
 
-    SENSOR_BLE_OIC:
-        description: 'Enable/Disable the OIC sensor gatt svr'
+    SENSOR_OIC:
+        description: 'Enable/Disable the OIC sensor server'
         value: 1
         restrictions:
-            # Disable central and observer roles.
-            - BLE_ROLE_BROADCASTER
-            - '!BLE_ROLE_CENTRAL'
-            - '!BLE_ROLE_OBSERVER'
-            - BLE_ROLE_PERIPHERAL
-            # OC server, with bluetooth transport.
             - OC_SERVER
-            - OC_TRANSPORT_GATT