Demonstration of the GAP profile. It shows advertising, scanning and connecting. The demo will cycle through several modes and print over the serial connection information about current activity.

GAP - Advertising, Scanning, Connecting

Demonstration of GAP API usage. It shows advertising, scanning and connecting. The demo will cycle through several modes and print over the serial connection information about current activity.

Running the application

Requirements

The sample application can be seen on any BLE scanner on a smartphone. If you don't have a scanner on your phone, please install :

- nRF Master Control Panel for Android.

- LightBlue for iPhone.

Information about activity is printed over the serial connection - please have a client open. You may use:

- Tera Term

Hardware requirements are in the main readme.

Building instructions

Building instructions for all samples are in the main readme.

Revision:
21:59235cb6afd2
Parent:
16:4dd4ecbc8efb
--- a/source/main.cpp	Wed Feb 27 13:01:18 2019 +0000
+++ b/source/main.cpp	Tue Jul 23 12:02:24 2019 +0100
@@ -86,7 +86,7 @@
 
 /* helper that gets the number of items in arrays */
 template<class T, size_t N>
-size_t size(const T (&)[N])
+size_t arraysize(const T (&)[N])
 {
     return N;
 }
@@ -107,7 +107,7 @@
         _on_duration_end_id(0),
         _scan_count(0),
         _blink_event(0) {
-        for (uint8_t i = 0; i < size(_adv_handles); ++i) {
+        for (uint8_t i = 0; i < arraysize(_adv_handles); ++i) {
             _adv_handles[i] = ble::INVALID_ADVERTISING_HANDLE;
         }
     }
@@ -268,7 +268,7 @@
         /* how many sets */
         uint8_t max_adv_set = std::min(
             _gap.getMaxAdvertisingSetNumber(),
-            (uint8_t) size(_adv_handles)
+            (uint8_t) arraysize(_adv_handles)
         );
 
         /* one advertising set is reserved for legacy advertising */
@@ -315,7 +315,7 @@
             /* set different name for each set */
             MBED_ASSERT(i < 9);
             char device_name[] = "Advertiser x";
-            snprintf(device_name, size(device_name), "Advertiser %d", i%10);
+            snprintf(device_name, arraysize(device_name), "Advertiser %d", i%10);
             error = adv_data_builder.setName(device_name);
             if (error) {
                 print_error(error, "AdvertisingDataBuilder::setName() failed");
@@ -568,6 +568,24 @@
         }
     }
 
+    /**
+     * Implementation of Gap::EventHandler::onDataLengthChange
+     */
+    virtual void onDataLengthChange(
+        ble::connection_handle_t connectionHandle,
+        uint16_t txSize,
+        uint16_t rxSize
+    ) {
+        printf(
+            "Data length changed on the connection %d.\r\n"
+            "Maximum sizes for over the air packets are:\r\n"
+            "%d octets for transmit and %d octets for receive.\r\n",
+            connectionHandle,
+            txSize,
+            rxSize
+        );
+    }
+
 private:
 
     /** Clean up internal state after last run, cycle to the next mode and launch it */
@@ -583,7 +601,7 @@
 
         /* switch between advertising and scanning when we go
          * through all the params in the array */
-        if (_set_index >= (_is_in_scanning_mode ? size(scanning_params) : size(advertising_params))) {
+        if (_set_index >= (_is_in_scanning_mode ? arraysize(scanning_params) : arraysize(advertising_params))) {
             _set_index = 0;
             _is_in_scanning_mode = !_is_in_scanning_mode;
         }
@@ -618,7 +636,7 @@
     void end_extended_advertising()
     {
         /* iterate over the advertising handles */
-        for (uint8_t i = 0; i < size(_adv_handles); ++i) {
+        for (uint8_t i = 0; i < arraysize(_adv_handles); ++i) {
             /* check if the set has been sucesfully created */
             if (_adv_handles[i] == ble::INVALID_ADVERTISING_HANDLE) {
                 continue;
@@ -673,7 +691,7 @@
         uint16_t duration_ms = _demo_duration.read_ms();
         uint8_t number_of_active_sets = 0;
 
-        for (uint8_t i = 0; i < size(_adv_handles); ++i) {
+        for (uint8_t i = 0; i < arraysize(_adv_handles); ++i) {
             if (_adv_handles[i] != ble::INVALID_ADVERTISING_HANDLE) {
                 if (_gap.isAdvertisingActive(_adv_handles[i])) {
                     number_of_active_sets++;