all: unify UUID16 creation for all platforms
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
0b701c55ca
commit
79285321af
3 changed files with 14 additions and 33 deletions
14
uuid.go
14
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.
|
||||
|
|
18
uuid16.go
18
uuid16.go
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue