| 1 |
package gatt |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
|
| 6 |
"github.com/paypal/gatt/linux/cmd" |
| 7 |
) |
| 8 |
|
| 9 |
func ExampleLnxDeviceID() { |
| 10 |
NewDevice(LnxDeviceID(-1, true)) |
| 11 |
} |
| 12 |
|
| 13 |
func ExampleLnxMaxConnections() { |
| 14 |
NewDevice(LnxMaxConnections(1)) |
| 15 |
} |
| 16 |
|
| 17 |
func ExampleLnxSetAdvertisingEnable() { |
| 18 |
d, _ := NewDevice() |
| 19 |
d.Option(LnxSetAdvertisingEnable(true)) |
| 20 |
} |
| 21 |
|
| 22 |
func ExampleSetAdvertisingData() { |
| 23 |
|
| 24 |
o := LnxSetAdvertisingData(&cmd.LESetAdvertisingData{ |
| 25 |
AdvertisingDataLength: 6, |
| 26 |
AdvertisingData: [31]byte{0x02, 0x01, 0x06, 0x03, 0x01, 0xFE}, |
| 27 |
}) |
| 28 |
d, _ := NewDevice(o) |
| 29 |
d.Option(o) |
| 30 |
} |
| 31 |
|
| 32 |
func ExampleLnxSetScanResponseData() { |
| 33 |
|
| 34 |
o := LnxSetScanResponseData(&cmd.LESetScanResponseData{ |
| 35 |
ScanResponseDataLength: 8, |
| 36 |
ScanResponseData: [31]byte{0x07, 0x09, 'G', 'o', 'p', 'h', 'e', 'r'}, |
| 37 |
}) |
| 38 |
d, _ := NewDevice(o) |
| 39 |
d.Option(o) |
| 40 |
} |
| 41 |
|
| 42 |
func ExampleLnxSetAdvertisingParameters() { |
| 43 |
o := LnxSetAdvertisingParameters(&cmd.LESetAdvertisingParameters{ |
| 44 |
AdvertisingIntervalMin: 0x800, |
| 45 |
AdvertisingIntervalMax: 0x800, |
| 46 |
AdvertisingType: 0x00, |
| 47 |
OwnAddressType: 0x00, |
| 48 |
DirectAddressType: 0x00, |
| 49 |
DirectAddress: [6]byte{}, |
| 50 |
AdvertisingChannelMap: 0x7, |
| 51 |
AdvertisingFilterPolicy: 0x00, |
| 52 |
}) |
| 53 |
d, _ := NewDevice(o) |
| 54 |
d.Option(o) |
| 55 |
} |
| 56 |
|
| 57 |
func ExampleLnxSendHCIRawCommand_predefinedCommand() { |
| 58 |
|
| 59 |
c := &cmd.LESetScanResponseData{ |
| 60 |
ScanResponseDataLength: 8, |
| 61 |
ScanResponseData: [31]byte{0x07, 0x09, 'G', 'o', 'p', 'h', 'e', 'r'}, |
| 62 |
} |
| 63 |
rsp := bytes.NewBuffer(nil) |
| 64 |
d, _ := NewDevice() |
| 65 |
d.Option(LnxSendHCIRawCommand(c, rsp)) |
| 66 |
|
| 67 |
if rsp.Bytes()[0] != 0x00 { |
| 68 |
|
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
type customCmd struct{ ConnectionHandle uint16 } |
| 74 |
|
| 75 |
func (c customCmd) Opcode() int { return 0xFC01 } |
| 76 |
func (c customCmd) Len() int { return 3 } |
| 77 |
func (c customCmd) Marshal(b []byte) { |
| 78 |
b[0], b[1], b[2] = byte(c.ConnectionHandle), byte(c.ConnectionHandle>>8), 0xff |
| 79 |
} |
| 80 |
|
| 81 |
func ExampleLnxSendHCIRawCommand_customCommand() { |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
c := &customCmd{ConnectionHandle: 0x40} |
| 97 |
d, _ := NewDevice() |
| 98 |
d.Option(LnxSendHCIRawCommand(c, nil)) |
| 99 |
} |