Skip to content

Commit

Permalink
ble: updates so macOS works
Browse files Browse the repository at this point in the history
Signed-off-by: Ron Evans <[email protected]>
  • Loading branch information
deadprogram committed Nov 27, 2020
1 parent c0122b1 commit b92f942
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
25 changes: 1 addition & 24 deletions platforms/ble/ble_client_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ble
import (
"fmt"
"log"
"strconv"
"sync"

"github.com/pkg/errors"
Expand Down Expand Up @@ -87,7 +86,7 @@ func (b *ClientAdaptor) Connect() (err error) {
b.addr.Set(b.Address())

// scan for the address
ch := make(chan bluetooth.ScanResult, 1)
ch := make(chan bluetooth.ScanResult)
err = b.adpt.Scan(func(adapter *bluetooth.Adapter, result bluetooth.ScanResult) {
if result.Address.String() == b.Address() {
b.adpt.StopScan()
Expand Down Expand Up @@ -224,25 +223,3 @@ func getBLEAdapter(impl string) (*bluetooth.Adapter, error) {

return currentAdapter, nil
}

func convertUUID(cUUID string) string {
switch len(cUUID) {
case 4:
// convert to full uuid from "22bb"
uid, e := strconv.ParseUint("0x"+cUUID, 0, 16)
if e != nil {
return ""
}

uuid := bluetooth.New16BitUUID(uint16(uid))
return uuid.String()

case 32:
// convert "22bb746f2bbd75542d6f726568705327"
// to "00001234-0000-1000-8000-00805f9b34fb"
return fmt.Sprintf("%s-%s-%s-%s-%s", cUUID[:8], cUUID[8:12], cUUID[12:16], cUUID[16:20],
cUUID[20:32])
}

return cUUID
}
22 changes: 22 additions & 0 deletions platforms/ble/uuid_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ble

import (
"fmt"
)

func convertUUID(cUUID string) string {
switch len(cUUID) {
case 4:
// 2a270000-0000-0000-0000-000000000000
// convert "22bb"
// to "22bb0000-0000-0000-0000-000000000000"
return fmt.Sprintf("%s0000-0000-0000-0000-000000000000", cUUID)
case 32:
// convert "22bb746f2bbd75542d6f726568705327"
// to "22bb746f-2bbd-7554-2d6f-726568705327"
return fmt.Sprintf("%s-%s-%s-%s-%s", cUUID[:8], cUUID[8:12], cUUID[12:16], cUUID[16:20],
cUUID[20:32])
}

return cUUID
}
30 changes: 30 additions & 0 deletions platforms/ble/uuid_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ble

import (
"fmt"
"strconv"

"tinygo.org/x/bluetooth"
)

func convertUUID(cUUID string) string {
switch len(cUUID) {
case 4:
// convert to full uuid from "22bb"
uid, e := strconv.ParseUint("0x"+cUUID, 0, 16)
if e != nil {
return ""
}

uuid := bluetooth.New16BitUUID(uint16(uid))
return uuid.String()

case 32:
// convert "22bb746f2bbd75542d6f726568705327"
// to "22bb746f-2bbd-7554-2d6f-726568705327"
return fmt.Sprintf("%s-%s-%s-%s-%s", cUUID[:8], cUUID[8:12], cUUID[12:16], cUUID[16:20],
cUUID[20:32])
}

return cUUID
}

0 comments on commit b92f942

Please sign in to comment.