zephyr/samples
Rubin Gerritsen a4e43d013c Bluetooth: Samples: Use string printing functions for error codes
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 to adds string printing of error codes for all
samples to make them more user-friendly.

Several formatting alternatives were considered. The chosen alternative
balances code readability and FLASH size (with and without string
printing).

Example output from the peripheral_hids sample when the
peer rejects pairing:

```
Bluetooth initialized
Bluetooth authentication callbacks registered.
Advertising successfully started
Connected 5E:67:02:D3:1C:DB (random)
Security failed: 5E:67:02:D3:1C:DB (random) \
level 1 err 6 BT_SECURITY_ERR_PAIR_NOT_ALLOWED
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason 0x13 BT_HCI_ERR_REMOTE_USER_TERM_CONN
```

Other alternatives that were considered:

- Use of parantheses:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err BT_SECURITY_ERR_PAIR_NOT_ALLOWED(6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
BT_HCI_ERR_REMOTE_USER_TERM_CONN(0x13)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err (6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason (0x13)
```

- Spaces and parantheses:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err BT_SECURITY_ERR_PAIR_NOT_ALLOWED (6)
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason BT_HCI_ERR_REMOTE_USER_TERM_CONN (0x13)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err  (6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason  (0x13)
```

- Parantheses around everything:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err (BT_SECURITY_ERR_PAIR_NOT_ALLOWED(6))
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason (BT_HCI_ERR_REMOTE_USER_TERM_CONN(0x13))
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err ((6))
Disconnected from 5E:67:02:D3:1C:DB (random), reason ((0x13))
```

- Error code first, then string representation:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err 6 (BT_SECURITY_ERR_PAIR_NOT_ALLOWED)
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
0x13 (BT_HCI_ERR_REMOTE_USER_TERM_CONN)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err 6 ()
Disconnected from 5E:67:02:D3:1C:DB (random), reason 0x13 ()
```

- Apostrophes around error printing:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err "BT_SECURITY_ERR_PAIR_NOT_ALLOWED (6)"
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
"BT_HCI_ERR_REMOTE_USER_TERM_CONN (0x13)"
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err " (6)"
Disconnected from 5E:67:02:D3:1C:DB (random), reason " (0x13)"
```

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-31 12:56:11 +02:00
..
application_development samples: external_lib: Include --target in exported build flags 2024-07-31 10:08:33 +02:00
arch samples: pktqueue: remove main.h 2024-05-21 20:54:13 -04:00
basic samples: button: add a note about the input subsystem and samples 2024-07-30 18:29:50 +01:00
bluetooth Bluetooth: Samples: Use string printing functions for error codes 2024-07-31 12:56:11 +02:00
boards Bluetooth: Samples: Use string printing functions for error codes 2024-07-31 12:56:11 +02:00
compression
cpp
drivers samples: drivers: flash_shell: allow run on stm32h745i_disco/stm32h745xx/m4 2024-07-30 18:26:20 +01:00
fuel_gauge Samples: max17048: added units to output 2024-07-10 11:36:28 +02:00
hello_world
kernel arch: move arch_interface.h under zephyr/arch 2024-03-25 09:58:35 +00:00
modules doc: Revamp sensor docs 2024-07-16 16:49:24 -04:00
net samples: net: zperf: Start DHCPv4 when needed 2024-07-28 07:30:12 +03:00
philosophers doc: samples: philosophers: fix formatting and spelling 2024-05-31 03:08:52 -07:00
posix samples: env_posix: fix regex in sample test 2024-07-12 09:18:56 -04:00
sensor samples: accel_polling: set sampling frequency when necessary 2024-07-29 14:21:24 +02:00
shields samples/shields: x-nucleo-iks4a1: Add lsm6dsv16x temp display 2024-07-27 10:37:11 +03:00
subsys Bluetooth: Samples: Use string printing functions for error codes 2024-07-31 12:56:11 +02:00
synchronization samples/synchronization: fix thread b pinning 2024-07-30 18:30:30 +01:00
sysbuild samples: sysbuild: hello_world: Add support for nrf54l15pdk 2024-07-29 14:13:48 +02:00
tfm_integration samples: tfm_integration: tfm_ipc: update readme 2024-07-29 14:13:02 +02:00
userspace doc: samples: userspace: add cross reference to C functions 2024-06-20 14:07:32 -04:00
classic.rst
index.rst samples: move with_mcuboot sample to samples/sysbuild 2024-05-13 16:09:01 -04:00
sample_definition_and_criteria.rst