zephyr/subsys
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
..
bindesc everywhere: replace #if IS_ENABLED() as per docs 2024-06-28 07:20:32 -04:00
bluetooth Bluetooth: Samples: Use string printing functions for error codes 2024-07-31 12:56:11 +02:00
canbus canbus: isotp: use proper CAN ID masks 2024-04-24 09:53:06 +02:00
console
dap kconfig: replace known integer constants with variables 2024-07-27 20:49:15 +03:00
debug debug: thread_analyzer: Option to analyze threads on each core separately 2024-07-30 18:25:40 +01:00
demand_paging demand_paging: LRU eviction: remove restriction on PF index 0 2024-07-03 15:07:03 -04:00
dfu dfu/mcuboot: Use flash_area_flatten instead of flash_area_erase 2024-06-04 08:00:46 +02:00
disk drivers: disk: add DISK_IOCTL_CTRL_DEINIT command to supported IOCTLs 2024-06-07 18:16:01 +01:00
dsp
emul emul: Support UART device emulation 2024-07-30 18:28:17 +01:00
fb fb: cfb: Fix CID 394240 2024-07-05 18:39:22 +02:00
fs fs: nvs: Allow application to switch sector to get free space 2024-07-28 07:31:44 +03:00
input input: longpress, keymap: use an explicit callback name 2024-07-31 12:55:11 +02:00
ipc kconfig: replace known integer constants with variables 2024-07-27 20:49:15 +03:00
jwt jwt: add missing PSA_WANT dependencies to RSA signature 2024-06-13 09:22:20 +02:00
llext doc: llext: improve Doxygen comments 2024-07-11 16:17:52 +02:00
logging logging: backend: swo: add Kconfig option for SWO protocol 2024-07-29 14:17:33 +02:00
lorawan everywhere: replace double words 2024-06-25 06:05:35 -04:00
mem_mgmt
mgmt kconfig: replace known integer constants with variables 2024-07-27 20:49:15 +03:00
modbus modbus_serial: Disable rx interrupt if buffer fills up 2024-06-13 16:48:05 -04:00
modem modem: pipe: Add explicit timeout to sync APIs 2024-07-29 14:14:42 +02:00
net net: if: No need to join mcast groups if interface IPv6 is disabled 2024-07-31 12:40:32 +02:00
pm pm: Do not select deprecated symbol 2024-07-22 03:28:54 -04:00
portability kconfig: replace known integer constants with variables 2024-07-27 20:49:15 +03:00
random everywhere: replace double words 2024-06-25 06:05:35 -04:00
retention
rtio rtio: workq: Initialize Work item before using it 2024-07-13 10:27:58 -04:00
sd sd: sd_ops: fix DISK_IOCTL_CTRL_SYNC return code 2024-05-29 07:31:39 +02:00
sensing sensors: Submit call returns void 2024-06-14 19:13:02 +02:00
settings kconfig: replace known integer constants with variables 2024-07-27 20:49:15 +03:00
shell shell: introduce shell_xxx_impl wrapper functions for output macros 2024-07-27 20:50:12 +03:00
sip_svc everywhere: replace double words 2024-06-22 05:40:22 -04:00
stats
storage everywhere: replace #if IS_ENABLED() as per docs 2024-06-28 07:20:32 -04:00
task_wdt task_wdt: Feed hardware watchdog only when its started 2024-06-06 00:40:53 -07:00
testsuite ztest: shell: Fix compilation error for NEWLIB_LIBC 2024-07-27 15:08:14 +03:00
timing
tracing Revert "net: sockets: move poll implementation to zvfs" 2024-07-03 15:03:05 -04:00
usb usb: device_next: introduce UDC_BUF_POOL_*_DEFINE macros 2024-07-30 18:26:04 +01:00
zbus zbus: Use section iterator for observations 2024-07-09 14:03:33 +02:00
CMakeLists.txt dap: add CMSIS-DAP compatible controller 2024-06-14 11:14:17 +02:00
Kconfig dap: add CMSIS-DAP compatible controller 2024-06-14 11:14:17 +02:00