Commit d80cab11 authored by Kevin Seidel's avatar Kevin Seidel
Browse files

Rename Address() to Addr()

parent 04f14af9
......@@ -18,7 +18,7 @@ type Advertisement interface {
SolicitedService() []UUID
RSSI() int
Address() Addr
Addr() Addr
}
// ServiceData ...
......
......@@ -3,7 +3,7 @@ package ble
// A Client is a GATT client.
type Client interface {
// Address returns platform specific unique ID of the remote peripheral, e.g. MAC on Linux, Client UUID on OS X.
Address() Addr
Addr() Addr
// Name returns the name of the remote peripheral.
// This can be the advertised name, if exists, or the GAP device name, which takes priority.
......
......@@ -68,6 +68,6 @@ func (a *adv) RSSI() int {
return a.args.GetInt("kCBMsgArgRssi", 0)
}
func (a *adv) Address() ble.Addr {
func (a *adv) Addr() ble.Addr {
return xpc.UUID(a.args.MustGetUUID("kCBMsgArgDeviceUUID"))
}
......@@ -24,8 +24,8 @@ func NewClient(c ble.Conn) (*Client, error) {
}, nil
}
// Address returns UUID of the remote peripheral.
func (cln *Client) Address() ble.Addr {
// Addr returns UUID of the remote peripheral.
func (cln *Client) Addr() ble.Addr {
return cln.conn.RemoteAddr()
}
......
......@@ -39,7 +39,7 @@ func main() {
// If addr is specified, search for addr instead.
if len(*addr) != 0 {
filter = func(a ble.Advertisement) bool {
return strings.ToUpper(a.Address().String()) == strings.ToUpper(*addr)
return strings.ToUpper(a.Addr().String()) == strings.ToUpper(*addr)
}
}
......@@ -58,7 +58,7 @@ func main() {
// So we wait(detect) the disconnection in the go routine.
go func() {
<-cln.Disconnected()
fmt.Printf("[ %s ] is disconnected \n", cln.Address())
fmt.Printf("[ %s ] is disconnected \n", cln.Addr())
close(done)
}()
......@@ -72,7 +72,7 @@ func main() {
explore(cln, p)
// Disconnect the connection. (On OS X, this might take a while.)
fmt.Printf("Disconnecting [ %s ]... (this might take up to few seconds on OS X)\n", cln.Address())
fmt.Printf("Disconnecting [ %s ]... (this might take up to few seconds on OS X)\n", cln.Addr())
cln.CancelConnection()
<-done
......
......@@ -36,9 +36,9 @@ func main() {
func advHandler(a ble.Advertisement) {
if a.Connectable() {
fmt.Printf("[%s] C %3d:", a.Address(), a.RSSI())
fmt.Printf("[%s] C %3d:", a.Addr(), a.RSSI())
} else {
fmt.Printf("[%s] N %3d:", a.Address(), a.RSSI())
fmt.Printf("[%s] N %3d:", a.Addr(), a.RSSI())
}
comma := ""
if len(a.LocalName()) > 0 {
......
......@@ -7,11 +7,11 @@ import (
)
func advHandler(a ble.Advertisement) {
curr.addr = a.Address()
curr.addr = a.Addr()
if a.Connectable() {
fmt.Printf("[%s] C %3d:", a.Address(), a.RSSI())
fmt.Printf("[%s] C %3d:", a.Addr(), a.RSSI())
} else {
fmt.Printf("[%s] N %3d:", a.Address(), a.RSSI())
fmt.Printf("[%s] N %3d:", a.Addr(), a.RSSI())
}
comma := ""
if len(a.LocalName()) > 0 {
......
......@@ -15,7 +15,7 @@ func filter(c *cli.Context) ble.AdvFilter {
}
if c.String("addr") != "" {
return func(a ble.Advertisement) bool {
return a.Address().String() == strings.ToLower(c.String("addr"))
return a.Addr().String() == strings.ToLower(c.String("addr"))
}
}
if svc := strings.ToLower(c.String("svc")); svc != "" {
......
......@@ -242,7 +242,7 @@ func cmdConnect(c *cli.Context) error {
} else if filter(c) != nil {
fmt.Printf("Scanning with filter...\n")
if cln, err = ble.Connect(ctx, filter(c)); err == nil {
curr.addr = cln.Address()
curr.addr = cln.Addr()
fmt.Printf("Connected to %s\n", curr.addr)
}
......@@ -254,13 +254,13 @@ func cmdConnect(c *cli.Context) error {
}
if err == nil {
curr.client = cln
curr.clients[cln.Address().String()] = cln
curr.clients[cln.Addr().String()] = cln
}
go func() {
<-cln.Disconnected()
delete(curr.clients, cln.Address().String())
delete(curr.clients, cln.Addr().String())
curr.client = nil
fmt.Printf("\n%s disconnected\n", cln.Address().String())
fmt.Printf("\n%s disconnected\n", cln.Addr().String())
}()
return err
}
......@@ -273,12 +273,12 @@ func cmdDisconnect(c *cli.Context) error {
return errNotConnected
}
defer func() {
delete(curr.clients, curr.client.Address().String())
delete(curr.clients, curr.client.Addr().String())
curr.client = nil
curr.profile = nil
}()
fmt.Printf("Disconnecting [ %s ]... (this might take up to few seconds on OS X)\n", curr.client.Address())
fmt.Printf("Disconnecting [ %s ]... (this might take up to few seconds on OS X)\n", curr.client.Addr())
return curr.client.CancelConnection()
}
......
......@@ -144,7 +144,7 @@ func Connect(ctx context.Context, f AdvFilter) (Client, error) {
}
}
cln, err := Dial(ctx, (<-ch).Address())
cln, err := Dial(ctx, (<-ch).Addr())
return cln, errors.Wrap(err, "can't dial")
}
......
......@@ -38,8 +38,8 @@ type Client struct {
conn ble.Conn
}
// Address returns the address of the client.
func (p *Client) Address() ble.Addr {
// Addr returns the address of the client.
func (p *Client) Addr() ble.Addr {
p.RLock()
defer p.RUnlock()
return p.conn.RemoteAddr()
......
......@@ -97,8 +97,8 @@ func (a *Advertisement) RSSI() int {
return int(a.e.RSSI(a.i))
}
// Address returns the address of the remote peripheral.
func (a *Advertisement) Address() ble.Addr {
// Addr returns the address of the remote peripheral.
func (a *Advertisement) Addr() ble.Addr {
b := a.e.Address(a.i)
addr := net.HardwareAddr([]byte{b[5], b[4], b[3], b[2], b[1], b[0]})
if a.e.AddressType(a.i) == 1 {
......
......@@ -375,7 +375,7 @@ func (h *HCI) handleLEAdvertisingReport(b []byte) error {
if h.adHist[idx] == nil {
break
}
if h.adHist[idx].Address().String() == sr.Address().String() {
if h.adHist[idx].Addr().String() == sr.Addr().String() {
h.adHist[idx].setScanResponse(sr)
a = h.adHist[idx]
break
......@@ -383,7 +383,7 @@ func (h *HCI) handleLEAdvertisingReport(b []byte) error {
}
// Got a SR without having recieved an associated AD before?
if a == nil {
return fmt.Errorf("recieved scan response %s with no associated Advertising Data packet", sr.Address())
return fmt.Errorf("recieved scan response %s with no associated Advertising Data packet", sr.Addr())
}
default:
a = newAdvertisement(e, i)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment