sjanc commented on a change in pull request #796:
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r447559672



##########
File path: apps/central/src/main.c
##########
@@ -0,0 +1,196 @@
+/*
+ * 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 "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+
+static void
+ble_app_set_addr(void)
+{
+    ble_addr_t addr;
+    int rc;
+
+    /* generate new non-resolvable private address */
+    rc = ble_hs_id_gen_rnd(0, &addr);
+    assert(rc == 0);
+
+    /* set generated address */
+    rc = ble_hs_id_set_rnd(addr.val);
+    assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+    int rc;
+
+    switch (event->type) {
+    case BLE_GAP_EVENT_CONNECT:
+        if (event->connect.status == 0) {
+            MODLOG_DFLT(INFO,"Connection was established\n");
+            ble_gap_terminate(event->connect.conn_handle, 0x13);
+        } else {
+            MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
+                event->connect.status);
+        }
+        break;
+    case BLE_GAP_EVENT_DISCONNECT:
+        MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
+        event->disconnect.reason);
+        scan();
+        break;
+    case BLE_GAP_EVENT_CONN_UPDATE_REQ:
+        MODLOG_DFLT(INFO,"Connection update request received\n");
+        break;
+    case BLE_GAP_EVENT_CONN_UPDATE:
+        if (event->conn_update.status == 0) {
+            MODLOG_DFLT(INFO,"Connection update successful\n");
+        } else {
+            MODLOG_DFLT(INFO,"Connection update failed; reson: %d\n",
+                        event->conn_update.status);
+        }
+        break;
+    default:
+        MODLOG_DFLT(INFO,"Connection event type not supported, %d\n",
+                    event->type);
+        break;
+    }
+    return 0;
+}
+
+static int
+scan_event(struct ble_gap_event *event, void *arg)
+{
+    /* predef_uuid stores information about UUID of device,
+       that we connect to */
+    const uint8_t predef_uuid[16] = {

Review comment:
       why not make this ble_uuid and use stuf from ble_uuid.h to handle uuid 
operations?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to