/
connection_complete.ex
90 lines (77 loc) · 2.55 KB
/
connection_complete.ex
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
defmodule BlueHeron.HCI.Event.LEMeta.ConnectionComplete do
use BlueHeron.HCI.Event.LEMeta, subevent_code: 0x01
@moduledoc """
The HCI_LE_Connection_Complete event indicates to both of the Hosts forming
the connection that a new connection has been created.
Upon the creation of the connection a Connection_Handle shall be assigned by
the Controller, and passed to the Host in this event. If the connection
creation fails this event shall be provided to the Host that had issued the
HCI_LE_Create_Connection command.
This event indicates to the Host which issued an HCI_LE_Create_Connection
command and received an HCI_Command_Status event if the connection creation
failed or was successful.
The Master_Clock_Accuracy parameter is only valid for a slave. On a master,
this parameter shall be set to 0x00.
Note: This event is not sent if the HCI_LE_Enhanced_Connection_Complete event
(see Section 7.7.65.10) is unmasked.
Reference: Version 5.2, Vol 4, Part E, 7.7.65.1
"""
defparameters [
:status,
:connection_handle,
:role,
:peer_address_type,
:peer_address,
:connection_interval,
:connection_latency,
:supervision_timeout,
:master_clock_accuracy,
:subevent_code
]
defimpl BlueHeron.HCI.Serializable do
def serialize(cc) do
bin = <<
cc.subevent_code,
cc.status,
cc.connection_handle::little-16,
cc.role,
cc.peer_address_type,
cc.peer_address::little-48,
cc.connection_interval::little-16,
cc.connection_latency::little-16,
cc.supervision_timeout::little-16,
cc.master_clock_accuracy
>>
size = byte_size(bin)
<<cc.code, size, bin::binary>>
end
end
@impl BlueHeron.HCI.Event
def deserialize(<<@code, _size, @subevent_code, bin::binary>>) do
<<
status,
connection_handle::little-12,
_::4,
role,
peer_address_type,
peer_address::little-48,
connection_interval::little-16,
connection_latency::little-16,
supervision_timeout::little-16,
master_clock_accuracy
>> = bin
%__MODULE__{
subevent_code: @subevent_code,
status: status,
connection_handle: connection_handle,
role: role,
peer_address_type: peer_address_type,
peer_address: peer_address,
connection_interval: connection_interval,
connection_latency: connection_latency,
supervision_timeout: supervision_timeout,
master_clock_accuracy: master_clock_accuracy
}
end
def deserialize(bin), do: {:error, bin}
end