embassy-rs / nrf-softdevice

Apache License 2.0
269 stars 80 forks source link

Added Security Modes and improved Error Handling in GATT macros #177

Closed Yandrik closed 1 year ago

Yandrik commented 1 year ago

Security Modes work like this:

#[nrf_softdevice::gatt_service(uuid = "180f")]
struct BatteryService {
    #[characteristic(uuid = "2a19", read, notify, security = "JustWorks")]
    battery_level: u8,
    #[characteristic(uuid = "something-else", read, notify, security = "NoAccess")]
    other_characteristic: u8,
    #[characteristic(uuid = "something-else", read)]
    no_mode_means_default: u8,
}
Yandrik commented 1 year ago

All modes from nrf_softdevice::ble::SecurityMode are supported, and will be set for write and read.

Yandrik commented 1 year ago

Here's an example error to demonstrate the nicer error handling:

error: Parsing characteristics was unsuccessful: Invalid UUID (must be a 16-bit or 128-bit UUID) at uuid
  --> src/bin/ble-basics.rs:39:29
   |
39 |     #[characteristic(uuid = "something-else", read)]
   |                             ^^^^^^^^^^^^^^^^