Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion rmk/src/split/ble/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ impl<'stack, 'server, 'c, P: PacketPool> SplitReader for BleSplitPeripheralDrive
return Err(SplitDriverError::Disconnected);
}
GattConnectionEvent::Gatt { event: gatt_event } => {
#[cfg(feature = "dfu_split")]
let split_notifications_cccd_written = matches!(
&gatt_event,
GattEvent::Write(event)
if Some(event.handle()) == self.message_to_central.cccd_handle
);
match &gatt_event {
GattEvent::Read(event) => {
info!("Gatt read event: {:?}", event.handle());
Expand Down Expand Up @@ -96,6 +102,14 @@ impl<'stack, 'server, 'c, P: PacketPool> SplitReader for BleSplitPeripheralDrive
Ok(r) => r.send().await,
Err(e) => warn!("[gatt] error sending response: {:?}", e),
}
// Accepting the CCCD write updates TrouBLE's subscription state.
// Announce only when this write enabled notifications.
#[cfg(feature = "dfu_split")]
if split_notifications_cccd_written && self.message_to_central.should_notify(self.conn) {
let hash = crate::dfu::read_embedded_firmware_hash();
info!("dfu_split: notifications enabled, announcing hash {:#x}", hash);
self.write(&SplitMessage::FirmwareHashResponse(hash)).await.ok();
}
}
GattConnectionEvent::ConnectionParamsUpdated {
conn_interval,
Expand Down Expand Up @@ -131,7 +145,11 @@ impl<'stack, 'server, 'c, P: PacketPool> SplitWriter for BleSplitPeripheralDrive
.notify(self.conn, &buf, true)
.await
.map_err(|e| {
error!("BLE notify error: {:?}", e);
if e == Error::NotSubscribed {
debug!("Central has not subscribed to split notifications yet");
} else {
error!("BLE notify error: {:?}", e);
}
SplitDriverError::BleError(1)
})?;
Ok(buf.len())
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/split/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<S: SplitWriter + SplitReader> SplitPeripheral<S> {
pub(crate) async fn run(&mut self) {
// Proactively announce our firmware hash so the central can detect
// us even when it booted first and already gave up waiting for a query response.
#[cfg(feature = "dfu_split")]
#[cfg(all(feature = "dfu_split", not(feature = "_ble")))]
{
let hash = crate::dfu::read_embedded_firmware_hash();
self.split_driver
Expand Down