Skip to content

Commit

Permalink
Inform application of MTU when reading
Browse files Browse the repository at this point in the history
Contributes-To: dfrankland#46
  • Loading branch information
chrysn committed Aug 3, 2022
1 parent aa886ad commit 19ddf89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gatt/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ pub enum Event {
}

#[derive(Debug)]
#[non_exhaustive]
pub struct ReadRequest {
pub offset: u16,
pub response: ResponseSender,
pub mtu: u16,
}

#[derive(Debug)]
Expand Down
3 changes: 3 additions & 0 deletions src/peripheral/bluez/gatt/characteristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ impl Characteristic {
("value",),
|mut ctx, cr, (options,): (OptionsMap,)| {
let offset = options.get("offset").and_then(RefArg::as_u64).unwrap_or(0) as u16;
let mtu = options.get("mtu").and_then(RefArg::as_u64).unwrap_or(23) as u16;

let characteristic = cr
.data_mut::<GattDataType>(ctx.path())
.unwrap()
Expand All @@ -93,6 +95,7 @@ impl Characteristic {
.send(gatt::event::Event::ReadRequest(gatt::event::ReadRequest {
offset,
response: sender,
mtu,
}))
.await
.map_err(|_| MethodErr::from((BLUEZ_ERROR_FAILED, "")))?;
Expand Down
2 changes: 2 additions & 0 deletions src/peripheral/bluez/gatt/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl Descriptor {
("value",),
|mut ctx, cr, (options,): (OptionsMap,)| {
let offset = options.get("offset").and_then(RefArg::as_u64).unwrap_or(0) as u16;
let mtu = options.get("mtu").and_then(RefArg::as_u64).unwrap_or(23) as u16;
let descriptor = cr
.data_mut::<GattDataType>(ctx.path())
.unwrap()
Expand All @@ -54,6 +55,7 @@ impl Descriptor {
.send(gatt::event::Event::ReadRequest(gatt::event::ReadRequest {
offset,
response: sender,
mtu,
}))
.await
.map_err(|_| MethodErr::from((BLUEZ_ERROR_FAILED, "")))?;
Expand Down

0 comments on commit 19ddf89

Please sign in to comment.