Skip to content

Commit

Permalink
feat(vendor GATT command): add Read Multiple Variable Characteristic …
Browse files Browse the repository at this point in the history
…Value command
  • Loading branch information
OueslatiGhaith committed Jan 4, 2024
1 parent ee54737 commit 7bac2f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/vendor/command/gatt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,20 @@ pub trait GattCommands {
handles: &[AttributeHandle],
);

// TODO: read_multiple_car_char_value
/// Starts a procedure to read multiple variable length characteristic values from a server;
///
/// This command must specify the handles of the characteristic values to be read.
///
/// When the procedure is completed, a
/// [GATT ProcedureComplete](crate::vendor::event::VendorEvent::GattProcedureComplete) event
/// is generated, Before procedure completion, the response packets are given through
/// [ATT Read Multiple Response](crate::vendor::event::VendorEvent::AttReadMultipleResponse)
/// event.
async fn read_multiple_variable_characteristic_value(
&mut self,
conn_handle: ConnectionHandle,
handles: &[AttributeHandle],
);
}

impl<T: Controller> GattCommands for T {
Expand Down Expand Up @@ -1259,8 +1272,30 @@ impl<T: Controller> GattCommands for T {
for (idx, handle) in handles.iter().enumerate() {
LittleEndian::write_u16(&mut payload[2 + (idx * 2)..], handle.0);
}
self.controller_write(crate::vendor::opcode::GATT_SEND_MULT_NOTIFICATION, &payload)
.await;
self.controller_write(
crate::vendor::opcode::GATT_SEND_MULT_NOTIFICATION,
&payload[..2 + (handles.len() * 2)],
)
.await;
}

async fn read_multiple_variable_characteristic_value(
&mut self,
conn_handle: ConnectionHandle,
handles: &[AttributeHandle],
) {
let mut payload = [0; 255];
LittleEndian::write_u16(&mut payload[0..], conn_handle.0);
payload[1] = handles.len() as u8;
for (idx, handle) in handles.iter().enumerate() {
LittleEndian::write_u16(&mut payload[2 + (idx * 2)..], handle.0);
}

self.controller_write(
crate::vendor::opcode::GATT_READ_MULTIPLE_VAR_CHAR_VALUE,
&payload[..2 + (handles.len() * 2)],
)
.await;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/vendor/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ vendor_opcodes! {
pub const GATT_SET_ACCESS_PERMISSION = 0x2E;
pub const GATT_STORE_DB = 0x30;
pub const GATT_SEND_MULT_NOTIFICATION = 0x31;
pub const GATT_READ_MULTIPLE_VAR_CHAR_VALUE = 0x32;
}
L2Cap = 0x3;
{
Expand Down

0 comments on commit 7bac2f2

Please sign in to comment.