Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix split peripheral lost #241

Merged
merged 1 commit into from
Jan 6, 2025
Merged
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
10 changes: 5 additions & 5 deletions rmk/src/split/nrf/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub(crate) async fn run_ble_client(
BleSplitCentralClientEvent::MessageToCentralNotification(message) => {
match postcard::from_bytes(&message) {
Ok(split_message) => {
info!("Received split message from peripheral: {}", split_message);
if let Err(e) = receive_sender.try_send(split_message) {
error!("BLE_SYNC_CHANNEL send message error: {:?}", e);
}
Expand Down Expand Up @@ -187,13 +188,12 @@ impl<'a> SplitReader for BleSplitCentralDriver<'a> {
impl SplitWriter for BleSplitCentralDriver<'_> {
async fn write(&mut self, message: &SplitMessage) -> Result<usize, SplitDriverError> {
if let SplitMessage::ConnectionState(state) = message {
// Check if the connection state is changed
if self.connection_state == *state {
return Ok(SPLIT_MESSAGE_MAX_SIZE);
}
// ConnectionState changed, update cached state and notify peripheral
self.connection_state = *state;
if self.connection_state != *state {
self.connection_state = *state;
}
}
// Always sync the connection state to peripheral since central doesn't know the CONNECTION_STATE of the peripheral.
self.sender.send(message.clone()).await;
Ok(SPLIT_MESSAGE_MAX_SIZE)
}
Expand Down
Loading