extern crate bluetooth_hci as hci;
extern crate byteorder;
extern crate embedded_hal as hal;
extern crate nb;
use byteorder::{ByteOrder, LittleEndian};
use hci::types::{ConnectionInterval, ExpectedConnectionLength};
pub trait Commands {
type Error;
fn connection_parameter_update_request(
&mut self,
params: &ConnectionParameterUpdateRequest,
) -> nb::Result<(), Self::Error>;
fn connection_parameter_update_response(
&mut self,
params: &ConnectionParameterUpdateResponse,
) -> nb::Result<(), Self::Error>;
}
impl<'bnrg, 'spi, 'dbuf, SPI, OutputPin1, OutputPin2, InputPin, SpiError, GpioError> Commands
for crate::ActiveBlueNRG<'bnrg, 'spi, 'dbuf, SPI, OutputPin1, OutputPin2, InputPin, GpioError>
where
SPI: hal::blocking::spi::Transfer<u8, Error = SpiError>
+ hal::blocking::spi::Write<u8, Error = SpiError>,
OutputPin1: hal::digital::v2::OutputPin<Error = GpioError>,
OutputPin2: hal::digital::v2::OutputPin<Error = GpioError>,
InputPin: hal::digital::v2::InputPin<Error = GpioError>,
{
type Error = crate::Error<SpiError, GpioError>;
impl_params!(
connection_parameter_update_request,
ConnectionParameterUpdateRequest,
crate::opcode::L2CAP_CONN_PARAM_UPDATE_REQ
);
impl_params!(
connection_parameter_update_response,
ConnectionParameterUpdateResponse,
crate::opcode::L2CAP_CONN_PARAM_UPDATE_RESP
);
}
pub struct ConnectionParameterUpdateRequest {
pub conn_handle: hci::ConnectionHandle,
pub conn_interval: ConnectionInterval,
}
impl ConnectionParameterUpdateRequest {
const LENGTH: usize = 10;
fn copy_into_slice(&self, bytes: &mut [u8]) {
assert_eq!(bytes.len(), Self::LENGTH);
LittleEndian::write_u16(&mut bytes[0..], self.conn_handle.0);
self.conn_interval.copy_into_slice(&mut bytes[2..10]);
}
}
pub struct ConnectionParameterUpdateResponse {
pub conn_handle: hci::ConnectionHandle,
pub conn_interval: ConnectionInterval,
pub expected_connection_length_range: ExpectedConnectionLength,
pub identifier: u8,
pub accepted: bool,
}
impl ConnectionParameterUpdateResponse {
const LENGTH: usize = 16;
fn copy_into_slice(&self, bytes: &mut [u8]) {
assert_eq!(bytes.len(), Self::LENGTH);
LittleEndian::write_u16(&mut bytes[0..], self.conn_handle.0);
self.conn_interval.copy_into_slice(&mut bytes[2..10]);
self.expected_connection_length_range
.copy_into_slice(&mut bytes[10..14]);
bytes[14] = self.identifier;
bytes[15] = self.accepted as u8;
}
}