()
| 472 | } |
| 473 | |
| 474 | pub async fn test_configurable_notification_payload() { |
| 475 | use futures::StreamExt; |
| 476 | use std::time::Duration; |
| 477 | use tokio::time; |
| 478 | |
| 479 | let peripheral = peripheral_finder::find_and_connect().await; |
| 480 | peripheral_finder::reset_peripheral(&peripheral).await; |
| 481 | let config_char = |
| 482 | peripheral_finder::find_characteristic(&peripheral, gatt_uuids::CONFIGURABLE_NOTIFY); |
| 483 | let control_point = |
| 484 | peripheral_finder::find_characteristic(&peripheral, gatt_uuids::CONTROL_POINT); |
| 485 | |
| 486 | let mut cmd = vec![gatt_uuids::CMD_SET_NOTIFICATION_PAYLOAD]; |
| 487 | cmd.extend_from_slice(&[0xCA, 0xFE, 0xBA, 0xBE]); |
| 488 | peripheral |
| 489 | .write(&control_point, &cmd, btleplug::api::WriteType::WithResponse) |
| 490 | .await |
| 491 | .unwrap(); |
| 492 | |
| 493 | let mut stream = peripheral.notifications().await.unwrap(); |
| 494 | peripheral.subscribe(&config_char).await.unwrap(); |
| 495 | peripheral_finder::send_control_command(&peripheral, gatt_uuids::CMD_START_NOTIFICATIONS).await; |
| 496 | |
| 497 | let timeout = time::sleep(Duration::from_secs(5)); |
| 498 | tokio::pin!(timeout); |
| 499 | let mut matching = false; |
| 500 | |
| 501 | loop { |
| 502 | tokio::select! { |
| 503 | Some(n) = stream.next() => { |
| 504 | if n.uuid == gatt_uuids::CONFIGURABLE_NOTIFY |
| 505 | && n.value == vec![0xCA, 0xFE, 0xBA, 0xBE] |
| 506 | { |
| 507 | matching = true; |
| 508 | break; |
| 509 | } |
| 510 | } |
| 511 | _ = &mut timeout => break, |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | peripheral_finder::send_control_command(&peripheral, gatt_uuids::CMD_STOP_NOTIFICATIONS).await; |
| 516 | peripheral.unsubscribe(&config_char).await.unwrap(); |
| 517 | assert!( |
| 518 | matching, |
| 519 | "Should receive notification with custom payload [0xCA, 0xFE, 0xBA, 0xBE]" |
| 520 | ); |
| 521 | peripheral.disconnect().await.unwrap(); |
| 522 | } |
| 523 | |
| 524 | // ── Descriptors ───────────────────────────────────────────────────── |
| 525 |
nothing calls this directly
no test coverage detected