You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/07/28 00:18:58 UTC

[19/28] incubator-mynewt-core git commit: BLEuart app modifications as per changed API

BLEuart app modifications as per changed API


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

Branch: refs/heads/sterly_refactor
Commit: db99fcd6216dc3e761764d488e7d9153c3e603f3
Parents: a4494fe
Author: Vipul Rahane <vi...@runtime.io>
Authored: Wed Jul 27 12:52:38 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Jul 27 17:18:28 2016 -0700

----------------------------------------------------------------------
 apps/bleuart/src/main.c    | 19 ++----------------
 libs/bleuart/src/bleuart.c | 44 ++++++++++++++++++++---------------------
 2 files changed, 24 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/db99fcd6/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index 8cae471..e27ad13 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -96,15 +96,13 @@ bleuart_advertise(void)
 {
     struct ble_gap_adv_params adv_params;
     struct ble_hs_adv_fields fields;
-    //const char *name;
     int rc;
 
-    /**
+    /*
      *  Set the advertisement data included in our advertisements:
      *     o Flags (indicates advertisement type and other general info).
      *     o Advertising tx power.
-     *     o Device name.
-     *     o 16-bit service UUIDs (alert notifications).
+     *     o 128 bit UUID
      */
 
     memset(&fields, 0, sizeof fields);
@@ -326,24 +324,11 @@ main(void)
     /* Register GATT attributes (services, characteristics, and
      * descriptors).
      */
-    rc = ble_svc_gap_register();
-    assert(rc == 0);
-
-    rc = ble_svc_gatt_register();
-    assert(rc == 0);
 
     /* Set the default device name. */
     rc = ble_svc_gap_device_name_set("Mynewt_BLEuart");
     assert(rc == 0);
 
-    /* Nmgr ble GATT server initialization */
-    rc = nmgr_ble_svc_register();
-    assert(rc == 0);
-
-    /* bleuart GATT server initialization */
-    rc = bleuart_svc_register();
-    assert(rc == 0);
-
     /* Start the OS */
     os_start();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/db99fcd6/libs/bleuart/src/bleuart.c
----------------------------------------------------------------------
diff --git a/libs/bleuart/src/bleuart.c b/libs/bleuart/src/bleuart.c
index 07b0855..ae0673d 100644
--- a/libs/bleuart/src/bleuart.c
+++ b/libs/bleuart/src/bleuart.c
@@ -40,10 +40,11 @@ uint16_t console_max_input;
 uint16_t g_console_conn_handle;
 /**
  * The vendor specific "bleuart" service consists of one write no-rsp characteristic
- *     o "write no-rsp": a single-byte characteristic that can always be read, but
- *       can only be written over an encrypted connection.
- *     o "read": a single-byte characteristic taht can always be read but can
- *       only be written over an encrypted connection
+ * and one notification only read charateristic
+ *     o "write no-rsp": a single-byte characteristic that can be written only
+ *       over a non-encrypted connection
+ *     o "read": a single-byte characteristic that can always be read only via
+ *       notifications
  */
 
 /* {6E400001-B5A3-F393-E0A9-E50E24DCCA9E} */
@@ -99,9 +100,13 @@ static int
 gatt_svr_chr_access_uart_write(uint16_t conn_handle, uint16_t attr_handle,
                                struct ble_gatt_access_ctxt *ctxt, void *arg)
 {
+    struct os_mbuf *om = ctxt->om;
     switch (ctxt->op) {
         case BLE_GATT_ACCESS_OP_WRITE_CHR:
-              console_write(ctxt->att->write.data, ctxt->att->write.len);
+              while(om) {
+                  console_write((char *)om->om_data, om->om_len);
+                  om = SLIST_NEXT(om, om_next);
+              }
               console_write("\n", 1);
               return 0;
         default:
@@ -126,23 +131,13 @@ bleuart_gatt_svr_init(struct ble_hs_cfg *cfg)
         goto err;
     }
 
-err:
-    return rc;
-}
-
-/**
- * Register ble uart service
- *
- * @return 0 on success; non-zero on failure
- */
-int
-bleuart_svc_register(void)
-{
+    rc = ble_gatts_add_svcs(gatt_svr_svcs);
+    if (rc != 0) {
+        return rc;
+    }
 
-    int rc;
-    rc = ble_gatts_register_svcs(gatt_svr_svcs, NULL, NULL);
+err:
     return rc;
-
 }
 
 /**
@@ -154,6 +149,7 @@ bleuart_uart_read(void)
     int rc;
     int off;
     int full_line;
+    struct os_mbuf *om;
 
     off = 0;
     while (1) {
@@ -167,8 +163,12 @@ bleuart_uart_read(void)
             continue;
         }
 
-        ble_gattc_notify_custom(g_console_conn_handle, g_bleuart_attr_read_handle,
-                                console_buf, off);
+        om = ble_hs_mbuf_from_flat(console_buf, off);
+        if (!om) {
+            return;
+        }
+        ble_gattc_notify_custom(g_console_conn_handle,
+                                g_bleuart_attr_read_handle, &om);
         off = 0;
         break;
     }