gap: switch to use MACAddress struct when possible for shared implementation
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
parent
dc738f9c47
commit
ea7ed874af
22
gap.go
22
gap.go
@ -11,6 +11,28 @@ var (
|
|||||||
errAdvertisementPacketTooBig = errors.New("bluetooth: advertisement packet overflows")
|
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
|
// AdvertisementOptions configures an advertisement instance. More options may
|
||||||
// be added over time.
|
// be added over time.
|
||||||
type AdvertisementOptions struct {
|
type AdvertisementOptions struct {
|
||||||
|
@ -8,8 +8,7 @@ import (
|
|||||||
"github.com/JuulLabs-OSS/cbgo"
|
"github.com/JuulLabs-OSS/cbgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Address contains a Bluetooth address, which on macOS instead of a MAC address
|
// Address contains a Bluetooth address which on macOS is a UUID.
|
||||||
// is instead a UUID.
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
// UUID since this is macOS.
|
// UUID since this is macOS.
|
||||||
UUID
|
UUID
|
||||||
|
33
gap_linux.go
33
gap_linux.go
@ -11,27 +11,9 @@ import (
|
|||||||
"github.com/muka/go-bluetooth/bluez/profile/device"
|
"github.com/muka/go-bluetooth/bluez/profile/device"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Address contains a Bluetooth address, which is a MAC address plus some extra
|
// Address contains a Bluetooth MAC address.
|
||||||
// information.
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
// The MAC address of a Bluetooth device.
|
MACAddress
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advertisement encapsulates a single advertisement instance.
|
// Advertisement encapsulates a single advertisement instance.
|
||||||
@ -237,12 +219,13 @@ func makeScanResult(props *device.Device1Properties) ScanResult {
|
|||||||
serviceUUIDs = append(serviceUUIDs, parsedUUID)
|
serviceUUIDs = append(serviceUUIDs, parsedUUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a := Address{}
|
||||||
|
a.Set(addr)
|
||||||
|
a.SetRandom(props.AddressType == "random")
|
||||||
|
|
||||||
return ScanResult{
|
return ScanResult{
|
||||||
RSSI: props.RSSI,
|
RSSI: props.RSSI,
|
||||||
Address: Address{
|
Address: a,
|
||||||
MAC: addr,
|
|
||||||
isRandom: props.AddressType == "random",
|
|
||||||
},
|
|
||||||
AdvertisementPayload: &advertisementFields{
|
AdvertisementPayload: &advertisementFields{
|
||||||
AdvertisementFields{
|
AdvertisementFields{
|
||||||
LocalName: props.Name,
|
LocalName: props.Name,
|
||||||
|
22
gap_nrf51.go
22
gap_nrf51.go
@ -16,27 +16,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Address contains a Bluetooth address, which is a MAC address plus some extra
|
// Address contains a Bluetooth MAC address.
|
||||||
// information.
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
// The MAC address of a Bluetooth device.
|
MACAddress
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advertisement encapsulates a single advertisement instance.
|
// Advertisement encapsulates a single advertisement instance.
|
||||||
|
@ -27,27 +27,9 @@ var (
|
|||||||
globalScanResult ScanResult
|
globalScanResult ScanResult
|
||||||
)
|
)
|
||||||
|
|
||||||
// Address contains a Bluetooth address, which is a MAC address plus some extra
|
// Address contains a Bluetooth MAC address.
|
||||||
// information.
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
// The MAC address of a Bluetooth device.
|
MACAddress
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advertisement encapsulates a single advertisement instance.
|
// Advertisement encapsulates a single advertisement instance.
|
||||||
|
@ -4,27 +4,9 @@ import (
|
|||||||
"github.com/tinygo-org/bluetooth/winbt"
|
"github.com/tinygo-org/bluetooth/winbt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Address contains a Bluetooth address, which is a MAC address plus some extra
|
// Address contains a Bluetooth MAC address.
|
||||||
// information.
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
// The MAC address of a Bluetooth device.
|
MACAddress
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan starts a BLE scan. It is stopped by a call to StopScan. A common pattern
|
// Scan starts a BLE scan. It is stopped by a call to StopScan. A common pattern
|
||||||
|
Loading…
Reference in New Issue
Block a user