adapter: address
This commit is contained in:
parent
501b0aeecc
commit
7f3b96cff9
@ -6,6 +6,8 @@
|
||||
package bluetooth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/muka/go-bluetooth/api"
|
||||
"github.com/muka/go-bluetooth/bluez/profile/adapter"
|
||||
)
|
||||
@ -41,3 +43,14 @@ func (a *Adapter) Enable() (err error) {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Adapter) Address() (MACAddress, error) {
|
||||
if a.adapter == nil {
|
||||
return MACAddress{}, errors.New("adapter not enabled")
|
||||
}
|
||||
mac, err := ParseMAC(a.adapter.Properties.Address)
|
||||
if err != nil {
|
||||
return MACAddress{}, err
|
||||
}
|
||||
return MACAddress{MAC: mac}, nil
|
||||
}
|
||||
|
@ -106,3 +106,12 @@ func handleEvent() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Adapter) Address() (MACAddress, error) {
|
||||
var addr C.ble_gap_addr_t
|
||||
errCode := C.sd_ble_gap_address_get(&addr)
|
||||
if errCode != 0 {
|
||||
return MACAddress{}, Error(errCode)
|
||||
}
|
||||
return MACAddress{MAC: addr.addr}, nil
|
||||
}
|
||||
|
@ -54,3 +54,12 @@ func (a *Adapter) enable() error {
|
||||
errCode = C.sd_ble_enable(&appRAMBase)
|
||||
return makeError(errCode)
|
||||
}
|
||||
|
||||
func (a *Adapter) Address() (MACAddress, error) {
|
||||
var addr C.ble_gap_addr_t
|
||||
errCode := C.sd_ble_gap_addr_get(&addr)
|
||||
if errCode != 0 {
|
||||
return MACAddress{}, Error(errCode)
|
||||
}
|
||||
return MACAddress{MAC: addr.addr}, nil
|
||||
}
|
||||
|
@ -17,9 +17,10 @@ func main() {
|
||||
must("start adv", adv.Start())
|
||||
|
||||
println("advertising...")
|
||||
address, _ := adapter.Address()
|
||||
for {
|
||||
// Sleep forever.
|
||||
time.Sleep(time.Hour)
|
||||
println("Go Bluetooth /", address.MAC.String())
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user