Skip to content

Commit

Permalink
examples/ble: Follow the connect_status_changed() callback I/F change
Browse files Browse the repository at this point in the history
Follow the connect_status_changed() callback I/F change to
print the reason of the connection status change.
  • Loading branch information
SPRESENSE committed Jul 12, 2023
1 parent 8e76946 commit 1de5379
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions examples/bluetooth_le_central/bluetooth_le_central_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
/* Connection status change */

static void on_le_connect_status_change(struct ble_state_s *ble_state,
bool connected);
bool connected, uint8_t reason);

/* Device name change */

Expand Down Expand Up @@ -161,19 +161,20 @@ static BLE_UUID g_target_char_uuid;
****************************************************************************/

static void on_le_connect_status_change(struct ble_state_s *ble_state,
bool connected)
bool connected, uint8_t reason)
{
BT_ADDR addr = ble_state->bt_target_addr;

/* If receive connected status data, this function will call. */

printf("[BLE_GATT] Connect status ADDR:%02X:%02X:%02X:%02X:%02X:%02X, "
"status:%s\n",
"status:%s, reason: 0x%02x\n",
addr.address[5], addr.address[4], addr.address[3],
addr.address[2], addr.address[1], addr.address[0],
connected ? "Connected" : "Disconnected");
connected ? "Connected" : "Disconnected", reason);

s_ble_state = ble_state;

}

static void on_connected_device_nameresp(const char *name)
Expand Down
13 changes: 7 additions & 6 deletions examples/bluetooth_le_peripheral/bluetooth_le_peripheral_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
/* Connection status change */

static void onLeConnectStatusChanged(struct ble_state_s *ble_state,
bool connected);
bool connected, uint8_t reason);

/* Device name change */

Expand Down Expand Up @@ -175,16 +175,17 @@ static struct ble_cccd_s **g_cccd = NULL;
****************************************************************************/

static void onLeConnectStatusChanged(struct ble_state_s *ble_state,
bool connected)
bool connected, uint8_t reason)
{
BT_ADDR addr = ble_state->bt_target_addr;

/* If receive connected status data, this function will call. */

printf("[BLE_GATT] Connect status ADDR:%02X:%02X:%02X:%02X:%02X:%02X, status:%s\n",
addr.address[0], addr.address[1], addr.address[2],
addr.address[3], addr.address[4], addr.address[5],
connected ? "Connected" : "Disconnected");
printf("[BLE_GATT] Connect status ADDR:%02X:%02X:%02X:%02X:%02X:%02X, "
"status: %s, reason: 0x%02x\n",
addr.address[5], addr.address[4], addr.address[3],
addr.address[2], addr.address[1], addr.address[0],
connected ? "Connected" : "Disconnected", reason);

ble_conn_handle = ble_state->ble_connect_handle;
ble_is_connected = connected;
Expand Down

0 comments on commit 1de5379

Please sign in to comment.