This repository has been archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
IBluetoothLeGatt.cs
66 lines (62 loc) · 2.73 KB
/
IBluetoothLeGatt.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
using System;
using System.Threading.Tasks;
namespace MbientLab.MetaWear.Impl.Platform {
/// <summary>
/// GATT characteristic write types
/// </summary>
public enum GattCharWriteType {
WRITE_WITH_RESPONSE,
WRITE_WITHOUT_RESPONSE
}
/// <summary>
/// Bluetooth GATT operations used by the API, must be implemented by the target platform.
/// <para>Before interacting with any of the characteristics, users must first call <see cref="DiscoverServicesAsync"/></para>
/// </summary>
public interface IBluetoothLeGatt {
/// <summary>
/// Device's mac address, as an unsigned long
/// </summary>
ulong BluetoothAddress { get; }
/// <summary>
/// Handler to process disconnect events
/// </summary>
Action OnDisconnect { get; set; }
/// <summary>
/// Discover GATT services and characteristics avaiable on the remote device
/// </summary>
/// <returns>Null when discovery is completed</returns>
Task DiscoverServicesAsync();
/// <summary>
/// Checks if a GATT service exists
/// </summary>
/// <param name="serviceGuid">UUID identifying the service to lookup</param>
/// <returns>True if service exists, false if not</returns>
Task<bool> ServiceExistsAsync(Guid serviceGuid);
/// <summary>
/// Reads the requested characteristic's value
/// </summary>
/// <param name="gattChar">Characteristic to read</param>
/// <returns>Characteristic's value</returns>
Task<byte[]> ReadCharacteristicAsync(Tuple<Guid, Guid> gattChar);
/// <summary>
/// Writes a GATT characteristic and its value to the remote device
/// </summary>
/// <param name="gattChar">GATT characteristic to write</param>
/// <param name="writeType">Type of GATT write to use</param>
/// <param name="value">Value to be written</param>
/// <returns>Null when the task is completed</returns>
Task WriteCharacteristicAsync(Tuple<Guid, Guid> gattChar, GattCharWriteType writeType, byte[] value);
/// <summary>
/// Enable notifications for the characteristic
/// </summary>
/// <param name="gattChar">Characteristic to enable notifications for</param>
/// <param name="handler">Listener for handling characteristic notifications</param>
/// <returns>Null when the task is completed</returns>
Task EnableNotificationsAsync(Tuple<Guid, Guid> gattChar, Action<byte[]> handler);
/// <summary>
/// Closes the Bluetooth LE connection
/// </summary>
/// <returns>Null when connection is lost</returns>
Task DisconnectAsync();
}
}