1#[allow(unused)]
2use crate::Adapter;
3use crate::Uuid;
4use std::collections::HashMap;
5
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub struct DeviceId(pub(crate) String);
11
12impl std::fmt::Display for DeviceId {
13 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14 std::fmt::Display::fmt(&self.0, f)
15 }
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
20pub enum AdapterEvent {
21 Available,
23 Unavailable,
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
29pub enum ConnectionEvent {
30 Disconnected,
32 Connected,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct AdvertisingDevice {
39 pub device: crate::Device,
41 pub adv_data: AdvertisementData,
43 pub rssi: Option<i16>,
45}
46
47#[derive(Debug, Clone, PartialEq, Eq)]
49pub struct AdvertisementData {
50 pub local_name: Option<String>,
52 pub manufacturer_data: Option<ManufacturerData>,
54 pub services: Vec<Uuid>,
56 pub service_data: HashMap<Uuid, Vec<u8>>,
58 pub tx_power_level: Option<i16>,
60 pub is_connectable: bool,
62}
63
64#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
68pub struct ManufacturerData {
69 pub company_id: u16,
71 pub data: Vec<u8>,
73}
74
75#[allow(missing_docs)]
79#[non_exhaustive]
80#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
81pub struct CharacteristicProperties {
82 pub broadcast: bool,
83 pub read: bool,
84 pub write_without_response: bool,
85 pub write: bool,
86 pub notify: bool,
87 pub indicate: bool,
88 pub authenticated_signed_writes: bool,
89 pub extended_properties: bool,
90 pub reliable_write: bool,
91 pub writable_auxiliaries: bool,
92}
93
94impl CharacteristicProperties {
95 pub fn from_bits(bits: u32) -> Self {
99 CharacteristicProperties {
100 broadcast: (bits & (1 << 0)) != 0,
101 read: (bits & (1 << 1)) != 0,
102 write_without_response: (bits & (1 << 2)) != 0,
103 write: (bits & (1 << 3)) != 0,
104 notify: (bits & (1 << 4)) != 0,
105 indicate: (bits & (1 << 5)) != 0,
106 authenticated_signed_writes: (bits & (1 << 6)) != 0,
107 extended_properties: (bits & (1 << 7)) != 0,
108 reliable_write: (bits & (1 << 8)) != 0,
109 writable_auxiliaries: (bits & (1 << 9)) != 0,
110 }
111 }
112
113 pub fn to_bits(self) -> u32 {
117 u32::from(self.broadcast)
118 | (u32::from(self.read) << 1)
119 | (u32::from(self.write_without_response) << 2)
120 | (u32::from(self.write) << 3)
121 | (u32::from(self.notify) << 4)
122 | (u32::from(self.indicate) << 5)
123 | (u32::from(self.authenticated_signed_writes) << 6)
124 | (u32::from(self.extended_properties) << 7)
125 | (u32::from(self.reliable_write) << 8)
126 | (u32::from(self.writable_auxiliaries) << 9)
127 }
128}