From b5ec1fb81e0b3a5874a0b70accbf60b0a99a4b49 Mon Sep 17 00:00:00 2001 From: "Yabe.Kazuhiro" Date: Sun, 29 Nov 2020 10:17:53 +0900 Subject: [PATCH] feat: Support winrt-rs v0.7 (tentative #1) --- Cargo.toml | 4 +- src/winrtble/adapter.rs | 4 +- src/winrtble/bindings.rs | 47 +++++++++++ src/winrtble/ble/characteristic.rs | 53 ++++++------ src/winrtble/ble/device.rs | 130 +++++++++++++++-------------- src/winrtble/ble/watcher.rs | 18 ++-- src/winrtble/manager.rs | 20 ++--- src/winrtble/mod.rs | 1 + src/winrtble/peripheral.rs | 29 +++---- src/winrtble/utils.rs | 45 ++++------ 10 files changed, 192 insertions(+), 159 deletions(-) create mode 100644 src/winrtble/bindings.rs diff --git a/Cargo.toml b/Cargo.toml index 3762bc48..252295dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,9 +39,7 @@ futures = "0.3.12" parking_lot = "0.11.1" [dependencies.winrt] -# This is stuck at 0.6 until we update the UWP core -version = "^0.6" -features = ["windows-devices", "windows-storage"] +version = "0.7" [target.'cfg(target_os = "linux")'.dependencies] dbus = "0.9.1" diff --git a/src/winrtble/adapter.rs b/src/winrtble/adapter.rs index aaceedfc..7379bd5d 100644 --- a/src/winrtble/adapter.rs +++ b/src/winrtble/adapter.rs @@ -41,12 +41,12 @@ impl Central for Adapter { let watcher = self.watcher.lock().unwrap(); let manager = self.manager.clone(); watcher.start(Box::new(move |args| { - let bluetooth_address = args.get_bluetooth_address().unwrap(); + let bluetooth_address = args.bluetooth_address().unwrap(); let address = utils::to_addr(bluetooth_address); let peripheral = manager .peripheral(address) .unwrap_or_else(|| Peripheral::new(manager.clone(), address)); - peripheral.update_properties(&args); + peripheral.update_properties(args); if !manager.has_peripheral(&address) { manager.add_peripheral(address, peripheral); manager.emit(CentralEvent::DeviceDiscovered(address)); diff --git a/src/winrtble/bindings.rs b/src/winrtble/bindings.rs new file mode 100644 index 00000000..b095e368 --- /dev/null +++ b/src/winrtble/bindings.rs @@ -0,0 +1,47 @@ +// btleplug Source Code File +// +// Copyright 2020 Nonpolynomial Labs LLC. All rights reserved. +// +// Licensed under the BSD 3-Clause license. See LICENSE file in the project root +// for full license information. +// +// Some portions of this file are taken and/or modified from Rumble +// (https://github.com/mwylde/rumble), using a dual MIT/Apache License under the +// following copyright: +// +// Copyright (c) 2014 The Rust Project Developers + +use winrt::*; + +import!( + dependencies + os + types + windows::devices::bluetooth::generic_attribute_profile::{ + GattCharacteristic, + GattCharacteristicProperties, + GattClientCharacteristicConfigurationDescriptorValue, + GattCommunicationStatus, + GattDeviceService, + GattDeviceServicesResult, + GattValueChangedEventArgs, + } + windows::devices::bluetooth::advertisement::* + windows::devices::bluetooth::{ + BluetoothConnectionStatus, + BluetoothLEDevice, + } + windows::devices::radios::{ + Radio, + RadioKind + } + windows::foundation::{ + EventRegistrationToken, + TypedEventHandler, + } + windows::storage::streams::{ + DataReader, + DataWriter, + } +); + diff --git a/src/winrtble/ble/characteristic.rs b/src/winrtble/ble/characteristic.rs index 49c876b7..f566ae57 100644 --- a/src/winrtble/ble/characteristic.rs +++ b/src/winrtble/ble/characteristic.rs @@ -12,20 +12,19 @@ // Copyright (c) 2014 The Rust Project Developers use crate::{Error, Result}; -use winrt::{ - windows::devices::bluetooth::genericattributeprofile::{ +use super::super::bindings; + +use bindings::windows::devices::bluetooth::generic_attribute_profile::{ GattCharacteristic, GattClientCharacteristicConfigurationDescriptorValue, GattCommunicationStatus, GattValueChangedEventArgs, - }, - windows::foundation::{EventRegistrationToken, TypedEventHandler}, - windows::storage::streams::{DataReader, DataWriter}, - ComPtr, RtAsyncOperation, RtDefaultConstructible, }; +use bindings::windows::foundation::{EventRegistrationToken, TypedEventHandler}; +use bindings::windows::storage::streams::{DataReader, DataWriter}; pub type NotifiyEventHandler = Box) + Send>; pub struct BLECharacteristic { - characteristic: ComPtr, + characteristic: GattCharacteristic, notify_token: Option, } @@ -33,7 +32,7 @@ unsafe impl Send for BLECharacteristic {} unsafe impl Sync for BLECharacteristic {} impl BLECharacteristic { - pub fn new(characteristic: ComPtr) -> Self { + pub fn new(characteristic: GattCharacteristic) -> Self { BLECharacteristic { characteristic, notify_token: None, @@ -41,14 +40,14 @@ impl BLECharacteristic { } pub fn write_value(&self, data: &[u8]) -> Result<()> { - let writer = DataWriter::new(); + let writer = DataWriter::new().unwrap(); writer.write_bytes(data).unwrap(); - let buffer = writer.detach_buffer().unwrap().unwrap(); + let buffer = writer.detach_buffer().unwrap(); let result = self .characteristic .write_value_async(&buffer) .unwrap() - .blocking_get() + .get() .unwrap(); if result == GattCommunicationStatus::Success { Ok(()) @@ -62,13 +61,12 @@ impl BLECharacteristic { .characteristic .read_value_async() .unwrap() - .blocking_get() - .unwrap() + .get() .unwrap(); - if result.get_status().unwrap() == GattCommunicationStatus::Success { - let value = result.get_value().unwrap().unwrap(); - let reader = DataReader::from_buffer(&value).unwrap().unwrap(); - let len = reader.get_unconsumed_buffer_length().unwrap() as usize; + if result.status().unwrap() == GattCommunicationStatus::Success { + let value = result.value().unwrap(); + let reader = DataReader::from_buffer(&value).unwrap(); + let len = reader.unconsumed_buffer_length().unwrap() as usize; let mut input = vec![0u8; len]; reader.read_bytes(&mut input[0..len]).unwrap(); Ok(input) @@ -79,11 +77,12 @@ impl BLECharacteristic { pub fn subscribe(&mut self, on_value_changed: NotifiyEventHandler) -> Result<()> { let value_handler = TypedEventHandler::new( - move |_: *mut GattCharacteristic, args: *mut GattValueChangedEventArgs| { - let args = unsafe { &*args }; - let value = args.get_characteristic_value().unwrap().unwrap(); - let reader = DataReader::from_buffer(&value).unwrap().unwrap(); - let len = reader.get_unconsumed_buffer_length().unwrap() as usize; + move |_: &GattCharacteristic, args: &GattValueChangedEventArgs| { + //let args = unsafe { &*args }; + let args = &*args; + let value = args.characteristic_value().unwrap(); + let reader = DataReader::from_buffer(&value).unwrap(); + let len = reader.unconsumed_buffer_length().unwrap() as usize; let mut input = vec![0u8; len]; reader.read_bytes(&mut input[0..len]).unwrap(); info!("changed {:?}", input); @@ -93,7 +92,7 @@ impl BLECharacteristic { ); let token = self .characteristic - .add_value_changed(&value_handler) + .value_changed(&value_handler) .unwrap(); self.notify_token = Some(token); let config = GattClientCharacteristicConfigurationDescriptorValue::Notify; @@ -101,14 +100,14 @@ impl BLECharacteristic { .characteristic .write_client_characteristic_configuration_descriptor_async(config) .unwrap() - .blocking_get() + .get() .unwrap(); info!("subscribe {:?}", status); Ok(()) } pub fn unsubscribe(&mut self) -> Result<()> { - if let Some(token) = self.notify_token { + if let Some(token) = &self.notify_token { self.characteristic.remove_value_changed(token).unwrap(); } self.notify_token = None; @@ -117,7 +116,7 @@ impl BLECharacteristic { .characteristic .write_client_characteristic_configuration_descriptor_async(config) .unwrap() - .blocking_get() + .get() .unwrap(); info!("unsubscribe {:?}", status); Ok(()) @@ -126,7 +125,7 @@ impl BLECharacteristic { impl Drop for BLECharacteristic { fn drop(&mut self) { - if let Some(token) = self.notify_token { + if let Some(token) = &self.notify_token { let result = self.characteristic.remove_value_changed(token); if let Err(err) = result { info!("Drop:remove_connection_status_changed {:?}", err); diff --git a/src/winrtble/ble/device.rs b/src/winrtble/ble/device.rs index 3c71bb91..0018eeab 100644 --- a/src/winrtble/ble/device.rs +++ b/src/winrtble/ble/device.rs @@ -12,22 +12,19 @@ // Copyright (c) 2014 The Rust Project Developers use crate::{api::BDAddr, winrtble::utils, Error, Result}; -use winrt::{ - windows::devices::bluetooth::genericattributeprofile::{ - GattCharacteristic, GattCommunicationStatus, GattDeviceService, GattDeviceServicesResult, - IGattDeviceService3, - }, - windows::devices::bluetooth::{ - BluetoothConnectionStatus, BluetoothLEDevice, IBluetoothLEDevice3, - }, - windows::foundation::{EventRegistrationToken, TypedEventHandler}, - ComPtr, IInspectable, RtAsyncOperation, -}; +use super::super::bindings; +use bindings::windows::devices::bluetooth::generic_attribute_profile::{ + GattCharacteristic, GattCommunicationStatus, GattDeviceService, GattDeviceServicesResult, + }; +use bindings::windows::devices::bluetooth::{ + BluetoothConnectionStatus, BluetoothLEDevice, + }; +use bindings::windows::foundation::{EventRegistrationToken, TypedEventHandler}; pub type ConnectedEventHandler = Box; pub struct BLEDevice { - device: ComPtr, + device: BluetoothLEDevice, connection_token: EventRegistrationToken, } @@ -39,23 +36,24 @@ impl BLEDevice { let async_op = BluetoothLEDevice::from_bluetooth_address_async(utils::to_address(address)) .map_err(|_| Error::DeviceNotFound)?; let device = async_op - .blocking_get() - .map_err(|_| Error::DeviceNotFound)? - .ok_or(Error::DeviceNotFound)?; + .get() + .map_err(|_| Error::DeviceNotFound)?; + // .ok_or(Error::DeviceNotFound)?; let connection_status_handler = TypedEventHandler::new( - move |sender: *mut BluetoothLEDevice, _: *mut IInspectable| { - let sender = unsafe { &*sender }; + move |sender: &BluetoothLEDevice, _: &winrt::Object| { + //let sender = unsafe { &*sender }; + let sender = &*sender; let is_connected = sender - .get_connection_status() + .connection_status() .ok() .map_or(false, |v| v == BluetoothConnectionStatus::Connected); connection_status_changed(is_connected); - info!("state {:?}", sender.get_connection_status()); + info!("state {:?}", sender.connection_status()); Ok(()) }, ); let connection_token = device - .add_connection_status_changed(&connection_status_handler) + .connection_status_changed(&connection_status_handler) .map_err(|_| Error::Other("Could not add connection status handler".into()))?; Ok(BLEDevice { @@ -64,55 +62,59 @@ impl BLEDevice { }) } - fn get_gatt_services(&self) -> Result> { + fn get_gatt_services(&self) -> Result { let winrt_error = |e| Error::Other(format!("{:?}", e)); - let device3 = self - .device - .query_interface::() - .ok_or_else(|| Error::NotSupported("Interface not implemented".into()))?; + let device3 = &self + .device; + //.query_interface::() + //.ok_or_else(|| Error::NotSupported("Interface not implemented".into()))?; let async_op = device3.get_gatt_services_async().map_err(winrt_error)?; let service_result = async_op - .blocking_get() - .map_err(winrt_error)? - .ok_or_else(|| Error::NotSupported("Interface not implemented".into()))?; + .get() + .map_err(winrt_error)?; + // .ok_or_else(|| Error::NotSupported("Interface not implemented".into()))?; Ok(service_result) } pub fn connect(&self) -> Result<()> { let service_result = self.get_gatt_services()?; let status = service_result - .get_status() + .status() .map_err(|_| Error::DeviceNotFound)?; utils::to_error(status) } fn get_characteristics( &self, - service: &ComPtr, - ) -> Vec> { + service: &GattDeviceService, + ) -> Vec { let mut characteristics = Vec::new(); - let service3 = service.query_interface::(); - if let Some(service3) = service3 { + // let service3 = service.query_interface::(); + let service3 = service; + // if let Some(service3) = service3 { let async_result = service3 .get_characteristics_async() - .and_then(|ao| ao.blocking_get()); + .and_then(|ao| ao.get()); match async_result { - Ok(Some(async_result)) => match async_result.get_status() { + //Ok(Some(async_result)) => match async_result.get_status() { + Ok(async_result) => match async_result.status() { Ok(GattCommunicationStatus::Success) => { - match async_result.get_characteristics() { - Ok(Some(results)) => { - info!("characteristics {:?}", results.get_size()); + match async_result.characteristics() { + // Ok(Some(results)) => { + Ok(results) => { + info!("characteristics {:?}", results.size()); for characteristic in &results { - if let Some(characteristic) = characteristic { - characteristics.push(characteristic); - } else { - info!("null pointer for characteristic"); - } + characteristics.push(characteristic); + // if let Some(characteristic) = characteristic { + // characteristics.push(characteristic); + // } else { + // info!("null pointer for characteristic"); + // } } } - Ok(None) => { - info!("null pointer from get_characteristics"); - } + // Ok(None) => { + // info!("null pointer from get_characteristics"); + // } Err(error) => { info!("get_characteristics {:?}", error); } @@ -122,35 +124,37 @@ impl BLEDevice { info!("get_status {:?}", rest); } }, - Ok(None) => { - info!("null pointer from get_characteristics"); - } + // Ok(None) => { + // info!("null pointer from get_characteristics"); + // } Err(error) => { info!("get_characteristics_async {:?}", error); } } - } + // } characteristics } - pub fn discover_characteristics(&self) -> Result>> { + pub fn discover_characteristics(&self) -> Result> { let winrt_error = |e| Error::Other(format!("{:?}", e)); let service_result = self.get_gatt_services()?; - let status = service_result.get_status().map_err(winrt_error)?; + let status = service_result.status().map_err(winrt_error)?; if status == GattCommunicationStatus::Success { let mut characteristics = Vec::new(); - if let Some(services) = service_result.get_services().map_err(winrt_error)? { - info!("services {:?}", services.get_size()); + // if let Some(services) = service_result.services().map_err(winrt_error)? { + let services = service_result.services().map_err(winrt_error)?; + info!("services {:?}", services.size()); for service in &services { - if let Some(service) = service { - characteristics.append(&mut self.get_characteristics(&service)); - } else { - info!("null pointer for service"); - } + characteristics.append(&mut self.get_characteristics(&service)); + // if let Some(service) = service { + // characteristics.append(&mut self.get_characteristics(&service)); + // } else { + // info!("null pointer for service"); + // } } - } else { - info!("null pointer from get_services()"); - } + // } else { + // info!("null pointer from get_services()"); + // } return Ok(characteristics); } Ok(Vec::new()) @@ -161,7 +165,7 @@ impl Drop for BLEDevice { fn drop(&mut self) { let result = self .device - .remove_connection_status_changed(self.connection_token); + .remove_connection_status_changed(&self.connection_token); if let Err(err) = result { info!("Drop:remove_connection_status_changed {:?}", err); } diff --git a/src/winrtble/ble/watcher.rs b/src/winrtble/ble/watcher.rs index cfde64f4..b318f709 100644 --- a/src/winrtble/ble/watcher.rs +++ b/src/winrtble/ble/watcher.rs @@ -12,15 +12,14 @@ // Copyright (c) 2014 The Rust Project Developers use crate::Result; -use winrt::{ - windows::devices::bluetooth::advertisement::*, windows::foundation::TypedEventHandler, ComPtr, - RtDefaultConstructible, -}; +use super::super::bindings; +use bindings::windows::devices::bluetooth::advertisement::*; +use bindings::windows::foundation::TypedEventHandler; pub type AdvertismentEventHandler = Box; pub struct BLEWatcher { - watcher: ComPtr, + watcher: BluetoothLEAdvertisementWatcher, } unsafe impl Send for BLEWatcher {} @@ -28,7 +27,7 @@ unsafe impl Sync for BLEWatcher {} impl BLEWatcher { pub fn new() -> Self { - let ad = BluetoothLEAdvertisementFilter::new(); + let ad = BluetoothLEAdvertisementFilter::new().unwrap(); let watcher = BluetoothLEAdvertisementWatcher::create(&ad).unwrap(); BLEWatcher { watcher } } @@ -38,13 +37,14 @@ impl BLEWatcher { .set_scanning_mode(BluetoothLEScanningMode::Active) .unwrap(); let handler = TypedEventHandler::new( - move |_sender, args: *mut BluetoothLEAdvertisementReceivedEventArgs| { - let args = unsafe { &*args }; + move |_sender, args: &BluetoothLEAdvertisementReceivedEventArgs| { + // let args = unsafe { &args }; + let args = &args; on_received(args); Ok(()) }, ); - self.watcher.add_received(&handler).unwrap(); + self.watcher.received(&handler).unwrap(); self.watcher.start().unwrap(); Ok(()) } diff --git a/src/winrtble/manager.rs b/src/winrtble/manager.rs index 7f819644..304c5368 100644 --- a/src/winrtble/manager.rs +++ b/src/winrtble/manager.rs @@ -11,13 +11,11 @@ // // Copyright (c) 2014 The Rust Project Developers -use super::adapter::Adapter; +use super::{adapter::Adapter, bindings}; #[allow(unused_imports)] use crate::{Error, Result}; -use winrt::{ - windows::devices::radios::{Radio, RadioKind}, - RtAsyncOperation, -}; + +use bindings::windows::devices::radios::{Radio, RadioKind}; #[derive(Debug)] pub struct Manager {} @@ -31,19 +29,19 @@ impl Manager { let mut result: Vec = vec![]; let radios = Radio::get_radios_async() .unwrap() - .blocking_get() - .unwrap() + .get() .unwrap(); for radio in &radios { - if let Some(radio) = radio { - if let Ok(kind) = radio.get_kind() { + // if let radio = radio { + // if let kind = radio.kind().unwrap() { + let kind = radio.kind().unwrap(); if kind == RadioKind::Bluetooth { // try create BLE adapter result.push(Adapter::new()); } - } - } + // } + // } } return Ok(result); } diff --git a/src/winrtble/mod.rs b/src/winrtble/mod.rs index 7c91b5b7..e46802df 100644 --- a/src/winrtble/mod.rs +++ b/src/winrtble/mod.rs @@ -16,3 +16,4 @@ mod ble; pub mod manager; pub mod peripheral; pub mod utils; +pub mod bindings; diff --git a/src/winrtble/peripheral.rs b/src/winrtble/peripheral.rs index 708005a5..d75a1e65 100644 --- a/src/winrtble/peripheral.rs +++ b/src/winrtble/peripheral.rs @@ -11,7 +11,7 @@ // // Copyright (c) 2014 The Rust Project Developers -use super::{ble::characteristic::BLECharacteristic, ble::device::BLEDevice, utils}; +use super::{ble::characteristic::BLECharacteristic, ble::device::BLEDevice, utils, bindings}; use crate::{ api::{ AdapterManager, AddressType, BDAddr, CentralEvent, Characteristic, CommandCallback, @@ -28,7 +28,8 @@ use std::{ sync::atomic::{AtomicBool, Ordering}, sync::{Arc, Mutex}, }; -use winrt::windows::{devices::bluetooth::advertisement::*, storage::streams::DataReader}; + +use bindings::windows::{devices::bluetooth::advertisement::*, storage::streams::DataReader}; #[derive(Clone)] pub struct Peripheral { @@ -66,24 +67,24 @@ impl Peripheral { pub fn update_properties(&self, args: &BluetoothLEAdvertisementReceivedEventArgs) { let mut properties = self.properties.lock().unwrap(); - let advertisement = args.get_advertisement().unwrap().unwrap(); + let advertisement = args.advertisement().unwrap(); properties.discovery_count += 1; // Advertisements are cumulative: set/replace data only if it's set - if let Ok(name) = advertisement.get_local_name() { + if let Ok(name) = advertisement.local_name() { if !name.is_empty() { properties.local_name = Some(name.to_string()); } } - if let Ok(Some(manufacturer_data)) = advertisement.get_manufacturer_data() { + if let Ok(manufacturer_data) = advertisement.manufacturer_data() { let mut data = Vec::new(); for i in &manufacturer_data { - let d = i.unwrap(); - let company_id = d.get_company_id().unwrap(); - let buffer = d.get_data().unwrap().unwrap(); - let reader = DataReader::from_buffer(&buffer).unwrap().unwrap(); - let len = reader.get_unconsumed_buffer_length().unwrap() as usize; + let d = i; + let company_id = d.company_id().unwrap(); + let buffer = d.data().unwrap(); + let reader = DataReader::from_buffer(&buffer).unwrap(); + let len = reader.unconsumed_buffer_length().unwrap() as usize; let mut input = vec![0u8; len + 2]; reader.read_bytes(&mut input[2..(len + 2)]).unwrap(); input[0] = company_id as u8; @@ -97,9 +98,9 @@ impl Peripheral { // https://social.msdn.microsoft.com/Forums/en-US/c71d51a2-56a1-425a-9063-de44fda48766/bluetooth-address-public-or-random?forum=wdk properties.address_type = AddressType::default(); properties.has_scan_response = - args.get_advertisement_type().unwrap() == BluetoothLEAdvertisementType::ScanResponse; + args.advertisement_type().unwrap() == BluetoothLEAdvertisementType::ScanResponse; properties.tx_power_level = args - .get_raw_signal_strength_in_dbm() + .raw_signal_strength_in_dbm() .ok() .map(|rssi| rssi as i8); } @@ -210,9 +211,9 @@ impl ApiPeripheral for Peripheral { let mut characteristics_result = vec![]; let characteristics = device.discover_characteristics()?; for characteristic in characteristics { - let uuid = utils::to_uuid(&characteristic.get_uuid().unwrap()); + let uuid = utils::to_uuid(&characteristic.uuid().unwrap()); let properties = - utils::to_char_props(&characteristic.get_characteristic_properties().unwrap()); + utils::to_char_props(&characteristic.characteristic_properties().unwrap()); let chara = Characteristic { uuid, start_handle: 0, diff --git a/src/winrtble/utils.rs b/src/winrtble/utils.rs index 3d1b9348..a431277f 100644 --- a/src/winrtble/utils.rs +++ b/src/winrtble/utils.rs @@ -11,11 +11,13 @@ // // Copyright (c) 2014 The Rust Project Developers +use std::str::FromStr; use crate::{ api::{BDAddr, CharPropFlags, UUID}, Error, Result, }; -use winrt::windows::devices::bluetooth::genericattributeprofile::{ +use super::bindings; +use bindings::windows::devices::bluetooth::generic_attribute_profile::{ GattCharacteristicProperties, GattCommunicationStatus, }; use winrt::Guid; @@ -28,7 +30,7 @@ pub fn to_error(status: GattCommunicationStatus) -> Result<()> { GattCommunicationStatus::ProtocolError => { Err(Error::NotSupported("ProtocolError".to_string())) } - GattCommunicationStatus(a) => Err(Error::Other(format!("Communication Error: {}", a))), + _ => Err(Error::Other(format!("Communication Error:"))) } } @@ -50,20 +52,8 @@ pub fn to_address(addr: BDAddr) -> u64 { // If we want to get this into Bluez format, we've got to flip everything into a U128. pub fn to_uuid(uuid: &Guid) -> UUID { - let mut array = [0u8; 16]; - for i in 0..4 { - array[i + 12] = (uuid.Data1 >> (8 * i)) as u8; - } - for i in 0..2 { - array[i + 10] = (uuid.Data2 >> (8 * i)) as u8; - } - for i in 0..2 { - array[i + 8] = (uuid.Data3 >> (8 * i)) as u8; - } - for i in 0..8 { - array[i] = uuid.Data4[7 - i]; - } - UUID::B128(array) + let guid_s = format!("{:?}", uuid); + UUID::from_str(&guid_s).unwrap() } pub fn to_guid(uuid: &UUID) -> Guid { @@ -85,24 +75,19 @@ pub fn to_guid(uuid: &UUID) -> Guid { for i in 0..8 { data4[i] = a[i + 8]; } - Guid { - Data1: data1, - Data2: data2, - Data3: data3, - Data4: data4, - } + Guid::from_values( + data1, + data2, + data3, + data4, + ) } - UUID::B16(_) => Guid { - Data1: 0, - Data2: 0, - Data3: 0, - Data4: [0; 8], - }, + UUID::B16(_) => Guid::zeroed() } } -pub fn to_char_props(properties: &GattCharacteristicProperties) -> CharPropFlags { - CharPropFlags::from_bits_truncate(properties.0 as u8) +pub fn to_char_props(_: &GattCharacteristicProperties) -> CharPropFlags { + CharPropFlags::from_bits_truncate(0 as u8) } #[cfg(test)]