Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
forks
ble
Commits
d80cab11
Commit
d80cab11
authored
Oct 17, 2017
by
Kevin Seidel
Browse files
Rename Address() to Addr()
parent
04f14af9
Changes
13
Hide whitespace changes
Inline
Side-by-side
adv.go
View file @
d80cab11
...
...
@@ -18,7 +18,7 @@ type Advertisement interface {
SolicitedService
()
[]
UUID
RSSI
()
int
Addr
ess
()
Addr
Addr
()
Addr
}
// ServiceData ...
...
...
client.go
View file @
d80cab11
...
...
@@ -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.
Addr
ess
()
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.
...
...
darwin/adv.go
View file @
d80cab11
...
...
@@ -68,6 +68,6 @@ func (a *adv) RSSI() int {
return
a
.
args
.
GetInt
(
"kCBMsgArgRssi"
,
0
)
}
func
(
a
*
adv
)
Addr
ess
()
ble
.
Addr
{
func
(
a
*
adv
)
Addr
()
ble
.
Addr
{
return
xpc
.
UUID
(
a
.
args
.
MustGetUUID
(
"kCBMsgArgDeviceUUID"
))
}
darwin/client.go
View file @
d80cab11
...
...
@@ -24,8 +24,8 @@ func NewClient(c ble.Conn) (*Client, error) {
},
nil
}
// Addr
ess
returns UUID of the remote peripheral.
func
(
cln
*
Client
)
Addr
ess
()
ble
.
Addr
{
// Addr returns UUID of the remote peripheral.
func
(
cln
*
Client
)
Addr
()
ble
.
Addr
{
return
cln
.
conn
.
RemoteAddr
()
}
...
...
examples/basic/explorer/main.go
View file @
d80cab11
...
...
@@ -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
.
Addr
ess
()
.
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
.
Addr
ess
())
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
.
Addr
ess
())
fmt
.
Printf
(
"Disconnecting [ %s ]... (this might take up to few seconds on OS X)
\n
"
,
cln
.
Addr
())
cln
.
CancelConnection
()
<-
done
...
...
examples/basic/scanner/main.go
View file @
d80cab11
...
...
@@ -36,9 +36,9 @@ func main() {
func
advHandler
(
a
ble
.
Advertisement
)
{
if
a
.
Connectable
()
{
fmt
.
Printf
(
"[%s] C %3d:"
,
a
.
Addr
ess
(),
a
.
RSSI
())
fmt
.
Printf
(
"[%s] C %3d:"
,
a
.
Addr
(),
a
.
RSSI
())
}
else
{
fmt
.
Printf
(
"[%s] N %3d:"
,
a
.
Addr
ess
(),
a
.
RSSI
())
fmt
.
Printf
(
"[%s] N %3d:"
,
a
.
Addr
(),
a
.
RSSI
())
}
comma
:=
""
if
len
(
a
.
LocalName
())
>
0
{
...
...
examples/blesh/adv.go
View file @
d80cab11
...
...
@@ -7,11 +7,11 @@ import (
)
func
advHandler
(
a
ble
.
Advertisement
)
{
curr
.
addr
=
a
.
Addr
ess
()
curr
.
addr
=
a
.
Addr
()
if
a
.
Connectable
()
{
fmt
.
Printf
(
"[%s] C %3d:"
,
a
.
Addr
ess
(),
a
.
RSSI
())
fmt
.
Printf
(
"[%s] C %3d:"
,
a
.
Addr
(),
a
.
RSSI
())
}
else
{
fmt
.
Printf
(
"[%s] N %3d:"
,
a
.
Addr
ess
(),
a
.
RSSI
())
fmt
.
Printf
(
"[%s] N %3d:"
,
a
.
Addr
(),
a
.
RSSI
())
}
comma
:=
""
if
len
(
a
.
LocalName
())
>
0
{
...
...
examples/blesh/filter.go
View file @
d80cab11
...
...
@@ -15,7 +15,7 @@ func filter(c *cli.Context) ble.AdvFilter {
}
if
c
.
String
(
"addr"
)
!=
""
{
return
func
(
a
ble
.
Advertisement
)
bool
{
return
a
.
Addr
ess
()
.
String
()
==
strings
.
ToLower
(
c
.
String
(
"addr"
))
return
a
.
Addr
()
.
String
()
==
strings
.
ToLower
(
c
.
String
(
"addr"
))
}
}
if
svc
:=
strings
.
ToLower
(
c
.
String
(
"svc"
));
svc
!=
""
{
...
...
examples/blesh/main.go
View file @
d80cab11
...
...
@@ -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
.
Addr
ess
()
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
.
Addr
ess
()
.
String
()]
=
cln
curr
.
clients
[
cln
.
Addr
()
.
String
()]
=
cln
}
go
func
()
{
<-
cln
.
Disconnected
()
delete
(
curr
.
clients
,
cln
.
Addr
ess
()
.
String
())
delete
(
curr
.
clients
,
cln
.
Addr
()
.
String
())
curr
.
client
=
nil
fmt
.
Printf
(
"
\n
%s disconnected
\n
"
,
cln
.
Addr
ess
()
.
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
.
Addr
ess
()
.
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
.
Addr
ess
())
fmt
.
Printf
(
"Disconnecting [ %s ]... (this might take up to few seconds on OS X)
\n
"
,
curr
.
client
.
Addr
())
return
curr
.
client
.
CancelConnection
()
}
...
...
gatt.go
View file @
d80cab11
...
...
@@ -144,7 +144,7 @@ func Connect(ctx context.Context, f AdvFilter) (Client, error) {
}
}
cln
,
err
:=
Dial
(
ctx
,
(
<-
ch
)
.
Addr
ess
())
cln
,
err
:=
Dial
(
ctx
,
(
<-
ch
)
.
Addr
())
return
cln
,
errors
.
Wrap
(
err
,
"can't dial"
)
}
...
...
linux/gatt/client.go
View file @
d80cab11
...
...
@@ -38,8 +38,8 @@ type Client struct {
conn
ble
.
Conn
}
// Addr
ess
returns the address of the client.
func
(
p
*
Client
)
Addr
ess
()
ble
.
Addr
{
// Addr returns the address of the client.
func
(
p
*
Client
)
Addr
()
ble
.
Addr
{
p
.
RLock
()
defer
p
.
RUnlock
()
return
p
.
conn
.
RemoteAddr
()
...
...
linux/hci/adv.go
View file @
d80cab11
...
...
@@ -97,8 +97,8 @@ func (a *Advertisement) RSSI() int {
return
int
(
a
.
e
.
RSSI
(
a
.
i
))
}
// Addr
ess
returns the address of the remote peripheral.
func
(
a
*
Advertisement
)
Addr
ess
()
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
{
...
...
linux/hci/hci.go
View file @
d80cab11
...
...
@@ -375,7 +375,7 @@ func (h *HCI) handleLEAdvertisingReport(b []byte) error {
if
h
.
adHist
[
idx
]
==
nil
{
break
}
if
h
.
adHist
[
idx
]
.
Addr
ess
()
.
String
()
==
sr
.
Addr
ess
()
.
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
.
Addr
ess
())
return
fmt
.
Errorf
(
"recieved scan response %s with no associated Advertising Data packet"
,
sr
.
Addr
())
}
default
:
a
=
newAdvertisement
(
e
,
i
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment