mynewt-nimble icon indicating copy to clipboard operation
mynewt-nimble copied to clipboard

apps: Add exteneded scanner sample

Open m-gorecki opened this issue 2 years ago • 1 comments

Sample application showing how to configure extended scanning.

m-gorecki avatar Sep 26 '22 11:09 m-gorecki

Style check summary

Our coding style is here!

apps/ext_scanner/src/main.c

@@ -129,58 +129,58 @@
     if (desc->props & BLE_HCI_ADV_LEGACY_MASK) {
 
 
-    console_printf("Legacy PDU type %d", desc->legacy_event_type);
-    if (desc->legacy_event_type == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
-    directed = 1;
-    }
-    goto common_data;
+        console_printf("Legacy PDU type %d", desc->legacy_event_type);
+        if (desc->legacy_event_type == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
+            directed = 1;
+        }
+        goto common_data;
     }
 
     console_printf("Extended adv: ");
     if (desc->props & BLE_HCI_ADV_CONN_MASK) {
-    console_printf("'conn' ");
+        console_printf("'conn' ");
     }
     if (desc->props & BLE_HCI_ADV_SCAN_MASK) {
-    console_printf("'scan' ");
+        console_printf("'scan' ");
     }
     if (desc->props & BLE_HCI_ADV_DIRECT_MASK) {
-    console_printf("'dir' ");
-    directed = 1;
+        console_printf("'dir' ");
+        directed = 1;
     }
 
     if (desc->props & BLE_HCI_ADV_SCAN_RSP_MASK) {
-    console_printf("'scan rsp' ");
-    }
-
-    switch(desc->data_status) {
+        console_printf("'scan rsp' ");
+    }
+
+    switch (desc->data_status) {
     case BLE_GAP_EXT_ADV_DATA_STATUS_COMPLETE:
-    console_printf("complete");
-    break;
+        console_printf("complete");
+        break;
     case BLE_GAP_EXT_ADV_DATA_STATUS_INCOMPLETE:
-    console_printf("incomplete");
-    break;
+        console_printf("incomplete");
+        break;
     case BLE_GAP_EXT_ADV_DATA_STATUS_TRUNCATED:
-    console_printf("truncated");
-    break;
+        console_printf("truncated");
+        break;
     default:
-    console_printf("reserved %d", desc->data_status);
-    break;
-    }
-
-    common_data:
+        console_printf("reserved %d", desc->data_status);
+        break;
+    }
+
+common_data:
     console_printf(" rssi=%d txpower=%d, pphy=%d, sphy=%d, sid=%d,"
     " periodic_adv_itvl=%u, addr_type=%d addr=",
     desc->rssi, desc->tx_power, desc->prim_phy, desc->sec_phy,
     desc->sid, desc->periodic_adv_itvl, desc->addr.type);
     print_addr(desc->addr.val);
     if (directed) {
-    console_printf(" init_addr_type=%d inita=", desc->direct_addr.type);
-    print_addr(desc->direct_addr.val);
+        console_printf(" init_addr_type=%d inita=", desc->direct_addr.type);
+        print_addr(desc->direct_addr.val);
     }
 
     console_printf("\n");
 
-    if(!desc->length_data) {
+    if (!desc->length_data) {
         return;
     }
 
@@ -193,19 +193,19 @@
     switch (event->type) {
     /* advertising report has been received during discovery procedure */
     case BLE_GAP_EVENT_EXT_DISC:
-        switch(current_scan_mode) {
-            case 0:
-                console_printf("Legacy scan advertising report received!\n");
-                break;
-            case 1:
-                console_printf("Uncoded scan advertising report received!\n");
-                break;
-            case 2:
-                console_printf("Coded scan advertising report received!\n");
-                break;
-            case 3:
-                console_printf("Uncoded/coded scan advertising report received!\n");
-                break;
+        switch (current_scan_mode) {
+        case 0:
+            console_printf("Legacy scan advertising report received!\n");
+            break;
+        case 1:
+            console_printf("Uncoded scan advertising report received!\n");
+            break;
+        case 2:
+            console_printf("Coded scan advertising report received!\n");
+            break;
+        case 3:
+            console_printf("Uncoded/coded scan advertising report received!\n");
+            break;
         }
         decode_event_type(&event->ext_disc);
         return 0;
@@ -215,23 +215,23 @@
         MODLOG_DFLT(INFO, "Discovery completed, terminaton code: %d\n",
                     event->disc_complete.reason);
 
-        switch(current_scan_mode) {
-            case BOTH_SCAN:
-                console_printf("START LEGACY SCAN\n");
-                legacy_scan();
-                return 0;
-            case LEGACY_SCAN:
-                console_printf("START UNCODED SCAN\n");
-                ext_scan_uncoded();
-                return 0;
-            case UNCODED_SCAN:
-                console_printf("START CODED SCAN\n");
-                ext_scan_coded();
-                return 0;
-            case CODED_SCAN:
-                console_printf("START BOTH SCAN\n");
-                ext_scan_both();
-                return 0;
+        switch (current_scan_mode) {
+        case BOTH_SCAN:
+            console_printf("START LEGACY SCAN\n");
+            legacy_scan();
+            return 0;
+        case LEGACY_SCAN:
+            console_printf("START UNCODED SCAN\n");
+            ext_scan_uncoded();
+            return 0;
+        case UNCODED_SCAN:
+            console_printf("START CODED SCAN\n");
+            ext_scan_coded();
+            return 0;
+        case CODED_SCAN:
+            console_printf("START BOTH SCAN\n");
+            ext_scan_both();
+            return 0;
         }
     default:
 

apache-mynewt-bot avatar Sep 27 '22 12:09 apache-mynewt-bot