MCPcopy Create free account
hub / github.com/deviceplug/btleplug / test_configurable_notification_payload

Function test_configurable_notification_payload

tests/common/test_cases.rs:474–522  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

472}
473
474pub 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

Callers

nothing calls this directly

Calls 9

find_and_connectFunction · 0.85
reset_peripheralFunction · 0.85
find_characteristicFunction · 0.85
send_control_commandFunction · 0.85
writeMethod · 0.45
notificationsMethod · 0.45
subscribeMethod · 0.45
unsubscribeMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected