You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2020/03/30 07:41:07 UTC

[GitHub] [mynewt-nimble] sjanc commented on a change in pull request #778: apps: scanner added

sjanc commented on a change in pull request #778: apps: scanner added
URL: https://github.com/apache/mynewt-nimble/pull/778#discussion_r399984760
 
 

 ##########
 File path: apps/scanner/src/main.c
 ##########
 @@ -0,0 +1,116 @@
+/*
+ * 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"
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan();
+
+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(1, &addr);
+    assert(rc == 0);
+
+    /* set generated address */
+    rc = ble_hs_id_set_rnd(addr.val);
+    assert(rc == 0);
+}
+
+static int
+scan_event(struct ble_gap_event *event, void *arg)
+{
+    switch (event->type) {
+    /* advertising report has been received during discovery procedure */
+    case BLE_GAP_EVENT_DISC:
+        MODLOG_DFLT(INFO, "Advertising report was received! Contents:\n");
+        MODLOG_DFLT(INFO, " event type: %u\n",event->disc.event_type);
+        MODLOG_DFLT(INFO, " data packet length: %u\n",
+                    event->disc.length_data);
+        MODLOG_DFLT(INFO, " advertiser address: %u\n",
+                    event->disc.addr.val);
+        MODLOG_DFLT(INFO, " received signal RSSI: %i\n",
+                    event->disc.rssi);
+        MODLOG_DFLT(INFO, " received data: %u\n",
+                    &(event->disc.data));
+        return 0;
+    /* discovery procedure has terminated */
+    case BLE_GAP_EVENT_DISC_COMPLETE:
+        MODLOG_DFLT(INFO, "Discovery completed, terminaton code: %d\n",
+                    event->disc_complete.reason);
+        scan();
+        return 0;
+    default:
+        MODLOG_DFLT(ERROR, "Discovery event not handled\n");
+        return 0;
+    }
+}
+
+static void
+scan()
+{
+    /* set scan parameters */
+    const struct ble_gap_disc_params scan_params = {500, 16, 0, 0, 1, 0};
 
 Review comment:
   use    .foo = 100   style initialization (with comments for non-obvious settings)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services