diff --git a/host/src/types/uuid.rs b/host/src/types/uuid.rs index 1a5fa88d..23214975 100644 --- a/host/src/types/uuid.rs +++ b/host/src/types/uuid.rs @@ -15,8 +15,32 @@ pub enum Uuid { } impl From for Uuid { - fn from(val: bt_hci::uuid::BluetoothUuid16) -> Self { - Uuid::Uuid16(val.into()) + fn from(data: bt_hci::uuid::BluetoothUuid16) -> Self { + Uuid::Uuid16(data.into()) + } +} + +impl From for Uuid { + fn from(data: u128) -> Self { + Uuid::Uuid128(data.to_le_bytes()) + } +} + +impl From<[u8; 16]> for Uuid { + fn from(data: [u8; 16]) -> Self { + Uuid::Uuid128(data) + } +} + +impl From<[u8; 2]> for Uuid { + fn from(data: [u8; 2]) -> Self { + Uuid::Uuid16(data) + } +} + +impl From for Uuid { + fn from(data: u16) -> Self { + Uuid::Uuid16(data.to_le_bytes()) } } @@ -71,12 +95,6 @@ impl Uuid { } } -impl From for Uuid { - fn from(data: u16) -> Self { - Uuid::Uuid16(data.to_le_bytes()) - } -} - impl TryFrom<&[u8]> for Uuid { type Error = crate::Error; diff --git a/host/tests/gatt.rs b/host/tests/gatt.rs index 6e3b48b8..7d12d128 100644 --- a/host/tests/gatt.rs +++ b/host/tests/gatt.rs @@ -48,13 +48,13 @@ async fn gatt_client_server() { let mut expected = value.wrapping_add(1); let mut table: AttributeTable<'_, NoopRawMutex, 10> = AttributeTable::new(); - let mut svc = table.add_service(Service::new(0x1800)); - let _ = svc.add_characteristic_ro(0x2a00, id); - let _ = svc.add_characteristic_ro(0x2a01, &appearance); + let mut svc = table.add_service(Service::new(0x1800u16)); + let _ = svc.add_characteristic_ro(0x2a00u16, id); + let _ = svc.add_characteristic_ro(0x2a01u16, &appearance); svc.build(); // Generic attribute service (mandatory) - table.add_service(Service::new(0x1801)); + table.add_service(Service::new(0x1801u16)); // Custom service let _handle: Characteristic = table.add_service(Service::new(SERVICE_UUID.clone())) diff --git a/host/tests/gatt_derive.rs b/host/tests/gatt_derive.rs index 2b989bfc..301b8202 100644 --- a/host/tests/gatt_derive.rs +++ b/host/tests/gatt_derive.rs @@ -23,13 +23,15 @@ struct Server { bas: BatteryService, } +const UUID_U128: u128 = 0x408813df_5dd4_1f87_ec11_cdb000100000; + #[gatt_service(uuid = "408813df-5dd4-1f87-ec11-cdb000100000")] struct CustomService { #[descriptor(uuid = "2b20", value = "Read Only Descriptor", read)] #[characteristic(uuid = "408813df-5dd4-1f87-ec11-cdb001100000", value = 42, read, write, notify)] #[descriptor(uuid = "2b21", value = [0x01,0x02,0x03], read)] pub value: u8, - #[characteristic(uuid = "408814df-5dd4-1f87-ec11-cdb001100000", value = 123.321, read, write, notify)] + #[characteristic(uuid = UUID_U128, value = 123.321, read, write, notify)] /// Order doesn't matter #[descriptor(uuid = "2b20", read, value = 42u16.to_le_bytes())] // empty descriptor pub second: f32,