-
Notifications
You must be signed in to change notification settings - Fork 22
/
connreq.go
59 lines (46 loc) · 1.1 KB
/
connreq.go
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
package ble
import (
"github.com/digital-dream-labs/vector-bluetooth/rts"
)
func handleRtsConnRequest(v *VectorBLE, msg interface{}) (data []byte, cont bool, err error) {
var cr *rts.RtsConnRequest
switch v.ble.Version() {
case rtsV2:
t, ok := msg.(*rts.RtsConnection_2)
if !ok {
return handlerUnsupportedTypeError()
}
cr = t.GetRtsConnRequest()
case rtsV3:
t, ok := msg.(*rts.RtsConnection_3)
if !ok {
return handlerUnsupportedTypeError()
}
cr = t.GetRtsConnRequest()
case rtsV4:
t, ok := msg.(*rts.RtsConnection_4)
if !ok {
return handlerUnsupportedTypeError()
}
cr = t.GetRtsConnRequest()
case rtsV5:
t, ok := msg.(*rts.RtsConnection_5)
if !ok {
return handlerUnsupportedTypeError()
}
cr = t.GetRtsConnRequest()
default:
return handlerUnsupportedVersionError()
}
if err := v.ble.SetRemotePublicKey(cr); err != nil {
return nil, false, err
}
b, err := rts.GetConnResponse(v.ble.Version(), v.ble.GetRemotePublicKey())
if err != nil {
return nil, false, err
}
if err := v.ble.Send(b); err != nil {
return nil, false, err
}
return nil, true, nil
}