-
Notifications
You must be signed in to change notification settings - Fork 0
/
EvtGetInfoResponse.cs
150 lines (129 loc) · 5.36 KB
/
EvtGetInfoResponse.cs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FlicSharp
{
public class EvtGetInfoResponse
{
public BluetoothControllerState BLUETOOTH_CONTROLLER_STATE { get; set; }
public BluetoothAddress HCI_CONTROLLER_BLUETOOTH_ADDRESS { get; set; }
public BdAddrType BD_ADDR_TYPE { get; set; }
public byte MAX_PENDING_CONNECTIONS { get; set; }
public Int16 MAX_CONCURRENTLY_CONNECTED_BUTTONS { get; set; }
public byte CURRENT_PENDING_CONNECTIONS { get; set; }
public bool CURRENTLY_NO_SPACE_FOR_NEW_CONNECTIONS { get; set; }
public UInt16 NUMBER_OF_VERIFIED_BUTTONS { get; set; }
public List<BluetoothAddress> VERIFIED_FLIC_BUTTONS { get; set; }
public EvtGetInfoResponse(byte[] data_buffer)
{
//Bluetooth Controller State
switch (data_buffer[1])
{
case 0: BLUETOOTH_CONTROLLER_STATE = BluetoothControllerState.Detached; break;
case 1: BLUETOOTH_CONTROLLER_STATE = BluetoothControllerState.Resetting; break;
case 2: BLUETOOTH_CONTROLLER_STATE = BluetoothControllerState.Attached; break;
default: throw new Exception("Unknown BluetoothControllerState value");
}
//HCI Bluetooth Device Address
string mac_address = "";
for (int i = 7; i > 1; i--)
{
mac_address += String.Format("{0:X}", data_buffer[i]);
if (i != 2)
{
mac_address += ":";
}
}
HCI_CONTROLLER_BLUETOOTH_ADDRESS = BluetoothAddress.Parse(mac_address);
//BD Address Type
switch (data_buffer[8])
{
case 0: BD_ADDR_TYPE = BdAddrType.PublicBdAddrType; break;
case 1: BD_ADDR_TYPE = BdAddrType.RandomBdAddrType; break;
default: throw new Exception("Unknown BdAddrType value");
}
//Max pending connections
MAX_PENDING_CONNECTIONS = data_buffer[9];
//Max Concurrently Connected Buttons
MAX_CONCURRENTLY_CONNECTED_BUTTONS = BitConverter.ToInt16(data_buffer, 10);
//Current Pending Connections
CURRENT_PENDING_CONNECTIONS = data_buffer[12];
//Currently No Space For New Connection
CURRENTLY_NO_SPACE_FOR_NEW_CONNECTIONS = BitConverter.ToBoolean(data_buffer, 13);
//Number Of Verified Buttons
NUMBER_OF_VERIFIED_BUTTONS = BitConverter.ToUInt16(data_buffer, 14);
//Verified Buttons
if (NUMBER_OF_VERIFIED_BUTTONS == 0)
{
VERIFIED_FLIC_BUTTONS = null;
}
else
{
VERIFIED_FLIC_BUTTONS = new List<BluetoothAddress>();
for (int i = 0; i < NUMBER_OF_VERIFIED_BUTTONS; i++)
{
mac_address = "";
byte[] mac_address_buffer = new byte[6];
int k = 0;
for (int j = i * 6 + 21; j > i * 6 + 15; j--)
{
mac_address_buffer[k++] = data_buffer[j];
}
VERIFIED_FLIC_BUTTONS.Add(new BluetoothAddress(mac_address_buffer));
}
}
}
public override string ToString()
{
string info = "";
//Bluetooth Controller State
info = "Bluetooth Controller State: ";
info += BLUETOOTH_CONTROLLER_STATE;
info += "\n";
//HCI Bluetooth Device Address
info += "MAC Address: ";
info += HCI_CONTROLLER_BLUETOOTH_ADDRESS;
info += "\n";
//BD Address Type
info += "Bluetooth Address Type: ";
info += BD_ADDR_TYPE;
info += "\n";
//Max pending connections
info += "Max Pending Connections: ";
info += MAX_PENDING_CONNECTIONS;
info += "\n";
//Max Concurrently Connected Buttons
info += "Max Concurrently Connected Buttons: ";
info += MAX_CONCURRENTLY_CONNECTED_BUTTONS;
info += "\n";
//Current Pending Connections
info += "Current Pending Connections: ";
info += CURRENT_PENDING_CONNECTIONS;
info += "\n";
//Currently No Space For New Connection
info += "Currently No Space For New Connection: ";
info += CURRENTLY_NO_SPACE_FOR_NEW_CONNECTIONS;
info += "\n";
//Number Of Verified Buttons
info += "Number Of Verified Buttons: ";
info += NUMBER_OF_VERIFIED_BUTTONS;
info += "\n";
//Verified Buttons
info += "Verified Buttons:\n";
if (NUMBER_OF_VERIFIED_BUTTONS == 0)
{
info += "\tNo Verfified Buttons";
}
else
{
foreach (BluetoothAddress ba in VERIFIED_FLIC_BUTTONS)
{
info += "\t" + ba.ToString() + "\n";
}
}
return info;
}
}
}