gap: switch to use MACAddress struct when possible for shared implementation

Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
Ron Evans 2020-08-29 14:43:11 +02:00
parent dc738f9c47
commit ea7ed874af
6 changed files with 37 additions and 87 deletions

22
gap.go

@ -11,6 +11,28 @@ var (
errAdvertisementPacketTooBig = errors.New("bluetooth: advertisement packet overflows")
)
// MACAddress contains a Bluetooth address which is a MAC address.
type MACAddress struct {
// MAC address of the Bluetooth device.
MAC
isRandom bool
}
// IsRandom if the address is randomly created.
func (mac MACAddress) IsRandom() bool {
return mac.isRandom
}
// SetRandom if is a random address.
func (mac MACAddress) SetRandom(val bool) {
mac.isRandom = val
}
// Set the address
func (mac MACAddress) Set(val interface{}) {
mac.MAC = val.(MAC)
}
// AdvertisementOptions configures an advertisement instance. More options may
// be added over time.
type AdvertisementOptions struct {

@ -8,8 +8,7 @@ import (
"github.com/JuulLabs-OSS/cbgo"
)
// Address contains a Bluetooth address, which on macOS instead of a MAC address
// is instead a UUID.
// Address contains a Bluetooth address which on macOS is a UUID.
type Address struct {
// UUID since this is macOS.
UUID

@ -11,27 +11,9 @@ import (
"github.com/muka/go-bluetooth/bluez/profile/device"
)
// Address contains a Bluetooth address, which is a MAC address plus some extra
// information.
// Address contains a Bluetooth MAC address.
type Address struct {
// The MAC address of a Bluetooth device.
MAC
isRandom bool
}
// IsRandom if the address is randomly created.
func (ad Address) IsRandom() bool {
return ad.isRandom
}
// SetRandom if is a random address.
func (ad Address) SetRandom(val bool) {
ad.isRandom = val
}
// Set the address
func (ad Address) Set(val interface{}) {
ad.MAC = val.(MAC)
MACAddress
}
// Advertisement encapsulates a single advertisement instance.
@ -237,12 +219,13 @@ func makeScanResult(props *device.Device1Properties) ScanResult {
serviceUUIDs = append(serviceUUIDs, parsedUUID)
}
a := Address{}
a.Set(addr)
a.SetRandom(props.AddressType == "random")
return ScanResult{
RSSI: props.RSSI,
Address: Address{
MAC: addr,
isRandom: props.AddressType == "random",
},
RSSI: props.RSSI,
Address: a,
AdvertisementPayload: &advertisementFields{
AdvertisementFields{
LocalName: props.Name,

@ -16,27 +16,9 @@ import (
"time"
)
// Address contains a Bluetooth address, which is a MAC address plus some extra
// information.
// Address contains a Bluetooth MAC address.
type Address struct {
// The MAC address of a Bluetooth device.
MAC
isRandom bool
}
// IsRandom if the address is randomly created.
func (ad Address) IsRandom() bool {
return ad.isRandom
}
// SetRandom if is a random address.
func (ad Address) SetRandom(val bool) {
ad.isRandom = val
}
// Set the address
func (ad Address) Set(val interface{}) {
ad.MAC = val.(MAC)
MACAddress
}
// Advertisement encapsulates a single advertisement instance.

@ -27,27 +27,9 @@ var (
globalScanResult ScanResult
)
// Address contains a Bluetooth address, which is a MAC address plus some extra
// information.
// Address contains a Bluetooth MAC address.
type Address struct {
// The MAC address of a Bluetooth device.
MAC
isRandom bool
}
// IsRandom if the address is randomly created.
func (ad Address) IsRandom() bool {
return ad.isRandom
}
// SetRandom if is a random address.
func (ad Address) SetRandom(val bool) {
ad.isRandom = val
}
// Set the address
func (ad Address) Set(val interface{}) {
ad.MAC = val.(MAC)
MACAddress
}
// Advertisement encapsulates a single advertisement instance.

@ -4,27 +4,9 @@ import (
"github.com/tinygo-org/bluetooth/winbt"
)
// Address contains a Bluetooth address, which is a MAC address plus some extra
// information.
// Address contains a Bluetooth MAC address.
type Address struct {
// The MAC address of a Bluetooth device.
MAC
isRandom bool
}
// IsRandom if the address is randomly created.
func (ad Address) IsRandom() bool {
return ad.isRandom
}
// SetRandom if is a random address.
func (ad Address) SetRandom(val bool) {
ad.isRandom = val
}
// Set the address
func (ad Address) Set(val interface{}) {
ad.MAC = val.(MAC)
MACAddress
}
// Scan starts a BLE scan. It is stopped by a call to StopScan. A common pattern