forked from currantlabs/ble
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadv.go
More file actions
111 lines (91 loc) · 2.98 KB
/
Copy pathadv.go
File metadata and controls
111 lines (91 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package bled
import (
"github.com/currantlabs/ble"
pb "github.com/currantlabs/ble/bled/proto"
)
// RandomAddress is a Random Device Address.
type RandomAddress struct {
ble.Addr
}
// [Vol 6, Part B, 4.4.2] [Vol 3, Part C, 11]
const (
evtTypAdvInd = 0x00 // Connectable undirected advertising (ADV_IND).
evtTypAdvDirectInd = 0x01 // Connectable directed advertising (ADV_DIRECT_IND).
evtTypAdvScanInd = 0x02 // Scannable undirected advertising (ADV_SCAN_IND).
evtTypAdvNonconnInd = 0x03 // Non connectable undirected advertising (ADV_NONCONN_IND).
evtTypScanRsp = 0x04 // Scan Response (SCAN_RSP).
)
// Advertisement implements ble.Advertisement and other functions that are only
// available on Linux.
type Advertisement struct {
*pb.Advertisement
}
// LocalName returns the LocalName of the remote peripheral.
func (a *Advertisement) LocalName() string {
return a.Advertisement.LocalName
}
// ManufacturerData returns the ManufacturerData of the advertisement.
func (a *Advertisement) ManufacturerData() []byte {
return a.Advertisement.ManufacturerData
}
// ServiceData returns the service data of the advertisement.
func (a *Advertisement) ServiceData() []ble.ServiceData {
// return a.Advertisement.ServiceData
return nil
}
// Services returns the service UUIDs of the advertisement.
func (a *Advertisement) Services() []ble.UUID {
var uu []ble.UUID
for _, u := range a.Advertisement.Services {
uu = append(uu, ble.UUID(u.UUID))
}
return uu
}
// OverflowService returns the UUIDs of overflowed service.
func (a *Advertisement) OverflowService() []ble.UUID {
// return a.Advertisement.OverflowService
return nil
}
// TxPowerLevel returns the tx power level of the remote peripheral.
func (a *Advertisement) TxPowerLevel() int {
return int(a.Advertisement.TxPowerLevel)
}
// SolicitedService returns UUIDs of solicited services.
func (a *Advertisement) SolicitedService() []ble.UUID {
// return a.Advertisement.GetSolicitedService()
return nil
}
// Connectable indicates weather the remote peripheral is connectable.
func (a *Advertisement) Connectable() bool {
return true
}
// RSSI returns RSSI signal strength.
func (a *Advertisement) RSSI() int {
return int(a.Advertisement.RSSI)
}
type addr string
func (a addr) String() string { return string(a) }
// Address returns the address of the remote peripheral.
func (a *Advertisement) Address() ble.Addr {
return addr(a.Advertisement.Address)
}
// EventType returns the event type of Advertisement.
// This is linux sepcific.
func (a *Advertisement) EventType() uint8 {
return 0
}
// AddressType returns the address type of the Advertisement.
// This is linux sepcific.
func (a *Advertisement) AddressType() uint8 {
return 0
}
// Data returns the advertising data of the packet.
// This is linux sepcific.
// func (a *Advertisement) Data() []byte {
// return nil
// }
// ScanResponse returns the scan response of the packet, if it presents.
// This is linux sepcific.
func (a *Advertisement) ScanResponse() []byte {
return nil
}