diff options
author | Albert Skog <mail@albertskog.se> | 2021-10-15 12:34:47 +0200 |
---|---|---|
committer | Albert Skog <mail@albertskog.se> | 2021-10-15 12:34:47 +0200 |
commit | 182b9001189deca80e3840b6c989cbc37623991d (patch) | |
tree | 358d1d5ed6f9aaef0a6b622bb9b36f65b4a115d5 /nrf-softdevice | |
parent | fd48489c0ffc58c8ae02d32d9904162a2777df3c (diff) | |
parent | bf4f7a143d38713922d9bd5ff1a983c4c7290c10 (diff) | |
download | nrf-softdevice-182b9001189deca80e3840b6c989cbc37623991d.zip |
Merge branch 'master' into feature/indications
Diffstat (limited to 'nrf-softdevice')
-rw-r--r-- | nrf-softdevice/Cargo.toml | 2 | ||||
-rw-r--r-- | nrf-softdevice/src/ble/gatt_server.rs | 21 |
2 files changed, 18 insertions, 5 deletions
diff --git a/nrf-softdevice/Cargo.toml b/nrf-softdevice/Cargo.toml index 1034aad..143e1d0 100644 --- a/nrf-softdevice/Cargo.toml +++ b/nrf-softdevice/Cargo.toml @@ -43,7 +43,7 @@ critical-section = { version = "0.2.1" } num_enum = { version = "0.5.1", default-features = false } embassy = { version = "0.1.0" } cortex-m = "0.7.2" -cortex-m-rt = "0.6.13" +cortex-m-rt = ">=0.6.15,<0.8" heapless = "0.7.1" fixed = "1.5.0" diff --git a/nrf-softdevice/src/ble/gatt_server.rs b/nrf-softdevice/src/ble/gatt_server.rs index 63c65a6..6c7eb8c 100644 --- a/nrf-softdevice/src/ble/gatt_server.rs +++ b/nrf-softdevice/src/ble/gatt_server.rs @@ -30,8 +30,15 @@ pub struct CharacteristicHandles { pub trait Server: Sized { type Event; + fn register(sd: &Softdevice) -> Result<Self, RegisterError>; + fn on_write(&self, handle: u16, data: &[u8]) -> Option<Self::Event>; +} + +pub trait Service: Sized { + type Event; fn uuid() -> Uuid; + fn register<F>(service_handle: u16, register_char: F) -> Result<Self, RegisterError> where F: FnMut(Characteristic, &[u8]) -> Result<CharacteristicHandles, RegisterError>; @@ -51,12 +58,17 @@ impl From<RawError> for RegisterError { } } -pub fn register<S: Server>(_sd: &Softdevice) -> Result<S, RegisterError> { +pub fn register<S: Server>(sd: &Softdevice) -> Result<S, RegisterError> { + S::register(sd) +} + +pub fn register_service<S: Service>(_sd: &Softdevice) -> Result<S, RegisterError> { + let uuid = S::uuid(); let mut service_handle: u16 = 0; let ret = unsafe { raw::sd_ble_gatts_service_add( raw::BLE_GATTS_SRVC_TYPE_PRIMARY as u8, - S::uuid().as_raw_ptr(), + uuid.as_raw_ptr(), &mut service_handle as _, ) }; @@ -139,9 +151,10 @@ impl From<DisconnectedError> for RunError { } } -pub async fn run<S: Server, F>(conn: &Connection, server: &S, mut f: F) -> Result<(), RunError> +pub async fn run<'m, F, S>(conn: &Connection, server: &S, mut f: F) -> Result<(), RunError> where F: FnMut(S::Event), + S: Server, { let conn_handle = conn.with_state(|state| state.check_connected())?; portal(conn_handle) @@ -163,7 +176,7 @@ where panic!("gatt_server auth_required not yet supported"); } - server.on_write(params.handle, v).map(|e| f(e)); + server.on_write(params.handle, &v).map(|e| f(e)); } _ => {} } |