diff --git a/uuid.go b/uuid.go index b632fbc..3deb378 100644 --- a/uuid.go +++ b/uuid.go @@ -24,6 +24,20 @@ func NewUUID(uuid [16]byte) UUID { return u } +// New16BitUUID returns a new 128-bit UUID based on a 16-bit UUID. +// +// Note: only use registered UUIDs. See +// https://www.bluetooth.com/specifications/gatt/services/ for a list. +func New16BitUUID(shortUUID uint16) UUID { + // https://stackoverflow.com/questions/36212020/how-can-i-convert-a-bluetooth-16-bit-service-uuid-into-a-128-bit-uuid + var uuid UUID + uuid[0] = 0x5F9B34FB + uuid[1] = 0x80000080 + uuid[2] = 0x00001000 + uuid[3] = uint32(shortUUID) + return uuid +} + // Replace16BitComponent returns a new UUID where bits 16..32 have been replaced // with the bits given in the argument. These bits are the same bits that vary // in the 16-bit compressed UUID form. diff --git a/uuid16.go b/uuid16.go deleted file mode 100644 index fb8972f..0000000 --- a/uuid16.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build !darwin -// +build !darwin - -package bluetooth - -// New16BitUUID returns a new 128-bit UUID based on a 16-bit UUID. -// -// Note: only use registered UUIDs. See -// https://www.bluetooth.com/specifications/gatt/services/ for a list. -func New16BitUUID(shortUUID uint16) UUID { - // https://stackoverflow.com/questions/36212020/how-can-i-convert-a-bluetooth-16-bit-service-uuid-into-a-128-bit-uuid - var uuid UUID - uuid[0] = 0x5F9B34FB - uuid[1] = 0x80000080 - uuid[2] = 0x00001000 - uuid[3] = uint32(shortUUID) - return uuid -} diff --git a/uuid16_darwin.go b/uuid16_darwin.go deleted file mode 100644 index b5eaaa7..0000000 --- a/uuid16_darwin.go +++ /dev/null @@ -1,15 +0,0 @@ -package bluetooth - -// New16BitUUID returns a new 128-bit UUID based on a 16-bit UUID. -// -// Note: only use registered UUIDs. See -// https://www.bluetooth.com/specifications/gatt/services/ for a list. -func New16BitUUID(shortUUID uint16) UUID { - // mac OS uses a unique format for UUID. - var uuid UUID - uuid[0] = 0x5F9B34FB - uuid[1] = 0x80000080 - uuid[2] = 0x00001000 - uuid[3] = uint32(shortUUID) << 16 - return uuid -}