2022-02-22 13:04:20 +03:00
|
|
|
//go:build softdevice
|
2020-03-06 14:49:05 +03:00
|
|
|
// +build softdevice
|
2019-06-02 20:12:36 +03:00
|
|
|
|
|
|
|
package bluetooth
|
|
|
|
|
|
|
|
/*
|
2020-03-06 14:49:05 +03:00
|
|
|
#include "ble.h"
|
2019-06-02 20:12:36 +03:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import "unsafe"
|
|
|
|
|
2020-09-13 21:21:38 +03:00
|
|
|
type shortUUID C.ble_uuid_t
|
|
|
|
|
2019-06-02 20:12:36 +03:00
|
|
|
func (uuid UUID) shortUUID() (C.ble_uuid_t, uint32) {
|
|
|
|
var short C.ble_uuid_t
|
|
|
|
short.uuid = uint16(uuid[3])
|
|
|
|
if uuid.Is16Bit() {
|
|
|
|
short._type = C.BLE_UUID_TYPE_BLE
|
|
|
|
return short, 0
|
|
|
|
}
|
|
|
|
errCode := C.sd_ble_uuid_vs_add((*C.ble_uuid128_t)(unsafe.Pointer(&uuid[0])), &short._type)
|
|
|
|
return short, errCode
|
|
|
|
}
|
2020-09-13 21:21:38 +03:00
|
|
|
|
|
|
|
// UUID returns the full length UUID for this short UUID.
|
|
|
|
func (s shortUUID) UUID() UUID {
|
|
|
|
if s._type == C.BLE_UUID_TYPE_BLE {
|
|
|
|
return New16BitUUID(s.uuid)
|
|
|
|
}
|
|
|
|
var outLen C.uint8_t
|
|
|
|
var outUUID UUID
|
|
|
|
C.sd_ble_uuid_encode(((*C.ble_uuid_t)(unsafe.Pointer(&s))), &outLen, ((*C.uint8_t)(unsafe.Pointer(&outUUID))))
|
|
|
|
return outUUID
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsIn checks the passed in slice of short UUIDs to see if this uuid is in it.
|
|
|
|
func (s shortUUID) IsIn(uuids []C.ble_uuid_t) bool {
|
|
|
|
for _, u := range uuids {
|
2022-04-13 19:02:17 +03:00
|
|
|
if shortUUID(u) == s {
|
2020-09-13 21:21:38 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|