Debian Codegraph @

option_linux_test.go

raw symbols SCIP
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)) // Can only be used with NewDevice.
11 }
12
13 func ExampleLnxMaxConnections() {
14 NewDevice(LnxMaxConnections(1)) // Can only be used with NewDevice.
15 }
16
17 func ExampleLnxSetAdvertisingEnable() {
18 d, _ := NewDevice()
19 d.Option(LnxSetAdvertisingEnable(true)) // Can only be used with Option.
20 }
21
22 func ExampleSetAdvertisingData() {
23 // Manually crafting an advertising packet with a type field, and a service uuid - 0xFE01.
24 o := LnxSetAdvertisingData(&cmd.LESetAdvertisingData{
25 AdvertisingDataLength: 6,
26 AdvertisingData: [31]byte{0x02, 0x01, 0x06, 0x03, 0x01, 0xFE},
27 })
28 d, _ := NewDevice(o) // Can be used with NewDevice.
29 d.Option(o) // Or dynamically with Option.
30 }
31
32 func ExampleLnxSetScanResponseData() {
33 // Manually crafting a scan response data packet with a name field.
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, // [0x0800]: 0.625 ms * 0x0800 = 1280.0 ms
45 AdvertisingIntervalMax: 0x800, // [0x0800]: 0.625 ms * 0x0800 = 1280.0 ms
46 AdvertisingType: 0x00, // [0x00]: ADV_IND, 0x01: DIRECT(HIGH), 0x02: SCAN, 0x03: NONCONN, 0x04: DIRECT(LOW)
47 OwnAddressType: 0x00, // [0x00]: public, 0x01: random
48 DirectAddressType: 0x00, // [0x00]: public, 0x01: random
49 DirectAddress: [6]byte{}, // Public or Random Address of the device to be connected
50 AdvertisingChannelMap: 0x7, // [0x07] 0x01: ch37, 0x02: ch38, 0x04: ch39
51 AdvertisingFilterPolicy: 0x00,
52 })
53 d, _ := NewDevice(o) // Can be used with NewDevice.
54 d.Option(o) // Or dynamically with Option.
55 }
56
57 func ExampleLnxSendHCIRawCommand_predefinedCommand() {
58 // Send a predefined command of cmd package.
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)) // Can only be used with Option
66 // Check the return status
67 if rsp.Bytes()[0] != 0x00 {
68 // Handle errors
69 }
70 }
71
72 // customCmd implements cmd.CmdParam as a fake vendor command.
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 // customCmd implements cmd.CmdParam as a fake vendor command.
83 //
84 // type customCmd struct{ ConnectionHandle uint16 }
85 //
86 // func (c customCmd) Opcode() int { return 0xFC01 }
87 // func (c customCmd) Len() int { return 3 }
88 // func (c customCmd) Marshal(b []byte) {
89 // []byte{
90 // byte(c.ConnectionHandle),
91 // byte(c.ConnectionHandle >> 8),
92 // 0xff,
93 // }
94 // }
95 // Send a custom vendor command without checking response.
96 c := &customCmd{ConnectionHandle: 0x40}
97 d, _ := NewDevice()
98 d.Option(LnxSendHCIRawCommand(c, nil)) // Can only be used with Option
99 }