zephyr/samples/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
canbus samples/subsys: Use hwmv2 native targets identifiers 2024-03-15 16:13:12 +01:00
console hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
dap samples: debug: add CMSIS DAP sample using USB as interface 2024-06-14 11:14:17 +02:00
debug arch posix fuzzing: Move kconfig options to sample 2024-05-02 20:46:03 +03:00
display samples: subsys: display: lvgl: Remove kscan pointer check 2024-06-21 11:54:11 -04:00
edac
fs samples: subsys: fs: littlefs: add ke17z littlefs test support 2024-07-27 10:39:32 +03:00
input boards: rename and update esp32 related conf and overlay files 2024-04-23 15:36:13 +02:00
ipc samples: ipc: icmsg: fix unbalanced nRF53 cpunet enable calls 2024-07-12 09:15:06 -04:00
llext llext: rework test and sample coverage 2024-06-25 21:25:33 -04:00
logging Bluetooth: Samples: Use string printing functions for error codes 2024-07-31 12:56:11 +02:00
lorawan samples: subsys: lorawan: class_a: remove clock sync and multicast 2024-05-02 16:54:43 +02:00
mgmt Bluetooth: Samples: Use string printing functions for error codes 2024-07-31 12:56:11 +02:00
modbus docs: modbus: Update PyModbus GitHub project URL 2024-05-28 18:57:02 +02:00
nvs samples: subsys: nvs fix hard fault when running on stm32 targets 2024-04-11 09:08:52 +02:00
pm hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
portability hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
rtio/sensor_batch_processing rtio: Remove builtin iodev mpsc queue 2024-06-12 21:12:54 -04:00
sensing samples: subsys: fix sensing/simple compile 2024-05-24 18:03:44 -04:00
settings samples: subsys: settings: Run sample on nrf54h20 2024-05-14 15:52:42 +02:00
shell scripts: west robot & simulation: Fix OOT 2024-07-01 16:10:35 -04:00
sip_svc
smf Samples: SMF: Add sample for SMF framework 2024-05-10 18:13:08 -04:00
task_wdt samples: subsys: task_wdt on the IWDG of the stm32f4 2024-06-14 19:34:58 +02:00
testsuite
tracing everywhere: reindent .overlay files with tabs 2024-06-26 15:59:44 +02:00
usb input: add a user_data pointer to the callback 2024-07-31 12:55:11 +02:00
usb_c
video doc: update documentation to use the --shield west build command arg 2024-07-04 13:25:00 +02:00
zbus samples: zbus: work_queue: Enable synchronous printk 2024-07-30 18:27:40 +01:00
subsys.rst