exportable FindField func ^.^
This commit is contained in:
parent
5b57e9d6ce
commit
15e8ac6877
@ -34,14 +34,14 @@ func Scanners() {
|
|||||||
|
|
||||||
projVars.ScanAdapter.Scan(func(scanAdapter *bluetooth.Adapter, device bluetooth.ScanResult) {
|
projVars.ScanAdapter.Scan(func(scanAdapter *bluetooth.Adapter, device bluetooth.ScanResult) {
|
||||||
|
|
||||||
|
//target := device.
|
||||||
lname := device.LocalName()
|
lname := device.LocalName()
|
||||||
adbytes := device.AdvertisementPayload.Bytes()
|
adbytes := device.AdvertisementPayload.Bytes()
|
||||||
rssi := device.RSSI
|
rssi := device.RSSI
|
||||||
|
|
||||||
//Trying to extract the service UUIDs from advertisment packets
|
//Trying to extract the service UUIDs from advertisment packet
|
||||||
//srvcPld := projVars.ScanAdapter.SetConnectHandler(c func)
|
|
||||||
|
|
||||||
srvcPld := device.AdvertisementPayload.HasServiceUUID(projVars.SonosScanTest)
|
//srvcPld := device.AdvertisementPayload.HasServiceUUID(projVars.SonosScanTest)
|
||||||
// ** List of common Service UUIDS to search for **
|
// ** List of common Service UUIDS to search for **
|
||||||
//bluetooth.ServiceUUIDDeviceInformation
|
//bluetooth.ServiceUUIDDeviceInformation
|
||||||
//bluetooth.ServiceUUIDGenericAttribute
|
//bluetooth.ServiceUUIDGenericAttribute
|
||||||
@ -56,7 +56,7 @@ func Scanners() {
|
|||||||
log.Info().Str("address", device.Address.String()).
|
log.Info().Str("address", device.Address.String()).
|
||||||
Str("LocalName", lname).
|
Str("LocalName", lname).
|
||||||
Int16("RSSI", rssi).
|
Int16("RSSI", rssi).
|
||||||
Bool("Service UUID", srvcPld).
|
//Bool("Service UUID", srvcPld).
|
||||||
//Str("Device: ", ).
|
//Str("Device: ", ).
|
||||||
Msg("new_device")
|
Msg("new_device")
|
||||||
|
|
||||||
|
14
vendor/tinygo.org/x/bluetooth/gap.go
generated
vendored
14
vendor/tinygo.org/x/bluetooth/gap.go
generated
vendored
@ -188,7 +188,7 @@ func (buf *rawAdvertisementPayload) Bytes() []byte {
|
|||||||
//
|
//
|
||||||
// See this list of field types:
|
// See this list of field types:
|
||||||
// https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/
|
// https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/
|
||||||
func (buf *rawAdvertisementPayload) findField(fieldType byte) []byte {
|
func (buf *rawAdvertisementPayload) FindField(fieldType byte) []byte {
|
||||||
data := buf.Bytes()
|
data := buf.Bytes()
|
||||||
for len(data) >= 2 {
|
for len(data) >= 2 {
|
||||||
fieldLength := data[0]
|
fieldLength := data[0]
|
||||||
@ -207,11 +207,11 @@ func (buf *rawAdvertisementPayload) findField(fieldType byte) []byte {
|
|||||||
// LocalName returns the local name (complete or shortened) in the advertisement
|
// LocalName returns the local name (complete or shortened) in the advertisement
|
||||||
// payload.
|
// payload.
|
||||||
func (buf *rawAdvertisementPayload) LocalName() string {
|
func (buf *rawAdvertisementPayload) LocalName() string {
|
||||||
b := buf.findField(9) // Complete Local Name
|
b := buf.FindField(9) // Complete Local Name
|
||||||
if len(b) != 0 {
|
if len(b) != 0 {
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
b = buf.findField(8) // Shortened Local Name
|
b = buf.FindField(8) // Shortened Local Name
|
||||||
if len(b) != 0 {
|
if len(b) != 0 {
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
@ -223,9 +223,9 @@ func (buf *rawAdvertisementPayload) LocalName() string {
|
|||||||
// and 128-bit UUIDs.
|
// and 128-bit UUIDs.
|
||||||
func (buf *rawAdvertisementPayload) HasServiceUUID(uuid UUID) bool {
|
func (buf *rawAdvertisementPayload) HasServiceUUID(uuid UUID) bool {
|
||||||
if uuid.Is16Bit() {
|
if uuid.Is16Bit() {
|
||||||
b := buf.findField(0x03) // Complete List of 16-bit Service Class UUIDs
|
b := buf.FindField(0x03) // Complete List of 16-bit Service Class UUIDs
|
||||||
if len(b) == 0 {
|
if len(b) == 0 {
|
||||||
b = buf.findField(0x02) // Incomplete List of 16-bit Service Class UUIDs
|
b = buf.FindField(0x02) // Incomplete List of 16-bit Service Class UUIDs
|
||||||
}
|
}
|
||||||
uuid := uuid.Get16Bit()
|
uuid := uuid.Get16Bit()
|
||||||
for i := 0; i < len(b)/2; i++ {
|
for i := 0; i < len(b)/2; i++ {
|
||||||
@ -236,9 +236,9 @@ func (buf *rawAdvertisementPayload) HasServiceUUID(uuid UUID) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
b := buf.findField(0x07) // Complete List of 128-bit Service Class UUIDs
|
b := buf.FindField(0x07) // Complete List of 128-bit Service Class UUIDs
|
||||||
if len(b) == 0 {
|
if len(b) == 0 {
|
||||||
b = buf.findField(0x06) // Incomplete List of 128-bit Service Class UUIDs
|
b = buf.FindField(0x06) // Incomplete List of 128-bit Service Class UUIDs
|
||||||
}
|
}
|
||||||
uuidBuf1 := uuid.Bytes()
|
uuidBuf1 := uuid.Bytes()
|
||||||
for i := 0; i < len(b)/16; i++ {
|
for i := 0; i < len(b)/16; i++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user