Skip to content

Commit

Permalink
applications: nrf5340_audio: Utilize <err>_to_str() APIs
Browse files Browse the repository at this point in the history
When developing Bluetooth applications,
you typically run into some errors.
If you are an experienced Bluetooth developer,
you would typically know how to translate the error codes into
string representations. Others might not.

This commit starts using `bt_hci_err_to_str()` and
`bt_security_err_to_str()`.

To enable string printing, enable `CONFIG_BT_HCI_ERR_TO_STR`
and `CONFIG_BT_SECURITY_ERR_TO_STR`.

The format used is equal to the one added in
zephyrproject-rtos/zephyr#75442.

Signed-off-by: Rubin Gerritsen <[email protected]>
  • Loading branch information
rugeGerritsen authored and rlubos committed Aug 6, 2024
1 parent bbf36f5 commit d4d0688
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ static void connected_cb(struct bt_conn *conn, uint8_t err)
if (err == BT_HCI_ERR_UNKNOWN_CONN_ID) {
LOG_WRN("ACL connection to addr: %s timed out, will try again", addr);
} else {
LOG_ERR("ACL connection to addr: %s, conn: %p, failed, error %d", addr,
(void *)conn, err);
LOG_ERR("ACL connection to addr: %s, conn: %p, failed, error %d %s", addr,
(void *)conn, err, bt_hci_err_to_str(err));
}

bt_conn_unref(conn);
Expand Down Expand Up @@ -133,7 +133,7 @@ static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

/* NOTE: The string below is used by the Nordic CI system */
LOG_INF("Disconnected: %s (reason 0x%02x)", addr, reason);
LOG_INF("Disconnected: %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));

if (IS_ENABLED(CONFIG_BT_CENTRAL)) {
bt_conn_unref(conn);
Expand Down Expand Up @@ -172,7 +172,8 @@ static void security_changed_cb(struct bt_conn *conn, bt_security_t level, enum
struct bt_mgmt_msg msg;

if (err) {
LOG_WRN("Security failed: level %d err %d", level, err);
LOG_WRN("Security failed: level %d err %d %s", level, err,
bt_security_err_to_str(err));
ret = bt_conn_disconnect(conn, BT_HCI_ERR_AUTH_FAIL);
if (ret) {
LOG_WRN("Failed to disconnect %d", ret);
Expand Down

0 comments on commit d4d0688

Please sign in to comment.