File tree Expand file tree Collapse file tree 4 files changed +34
-2
lines changed Expand file tree Collapse file tree 4 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 6
6
package bluetooth
7
7
8
8
import (
9
+ "errors"
10
+
9
11
"github.com/muka/go-bluetooth/api"
10
12
"github.com/muka/go-bluetooth/bluez/profile/adapter"
11
13
)
@@ -41,3 +43,14 @@ func (a *Adapter) Enable() (err error) {
41
43
}
42
44
return nil
43
45
}
46
+
47
+ func (a * Adapter ) Address () (MACAddress , error ) {
48
+ if a .adapter == nil {
49
+ return MACAddress {}, errors .New ("adapter not enabled" )
50
+ }
51
+ mac , err := ParseMAC (a .adapter .Properties .Address )
52
+ if err != nil {
53
+ return MACAddress {}, err
54
+ }
55
+ return MACAddress {MAC : mac }, nil
56
+ }
Original file line number Diff line number Diff line change @@ -106,3 +106,12 @@ func handleEvent() {
106
106
}
107
107
}
108
108
}
109
+
110
+ func (a * Adapter ) Address () (MACAddress , error ) {
111
+ var addr C.ble_gap_addr_t
112
+ errCode := C .sd_ble_gap_address_get (& addr )
113
+ if errCode != 0 {
114
+ return MACAddress {}, Error (errCode )
115
+ }
116
+ return MACAddress {MAC : addr .addr }, nil
117
+ }
Original file line number Diff line number Diff line change @@ -54,3 +54,12 @@ func (a *Adapter) enable() error {
54
54
errCode = C .sd_ble_enable (& appRAMBase )
55
55
return makeError (errCode )
56
56
}
57
+
58
+ func (a * Adapter ) Address () (MACAddress , error ) {
59
+ var addr C.ble_gap_addr_t
60
+ errCode := C .sd_ble_gap_addr_get (& addr )
61
+ if errCode != 0 {
62
+ return MACAddress {}, Error (errCode )
63
+ }
64
+ return MACAddress {MAC : addr .addr }, nil
65
+ }
Original file line number Diff line number Diff line change @@ -17,9 +17,10 @@ func main() {
17
17
must ("start adv" , adv .Start ())
18
18
19
19
println ("advertising..." )
20
+ address , _ := adapter .Address ()
20
21
for {
21
- // Sleep forever.
22
- time .Sleep (time .Hour )
22
+ println ( "Go Bluetooth /" , address . MAC . String ())
23
+ time .Sleep (time .Second )
23
24
}
24
25
}
25
26
You can’t perform that action at this time.
0 commit comments