Introduction
The Windows BLE Communications interface will provide a set of interfaces and abstract classes that enable developers to communicate with bluetooth devices, facilitating communication with VictoR devices in the VictoR Core library. An abstract device class will be created to provide a means to read, write, connect, and disconnect from bluetooth devices, while refraining from direct references to core VictoR concepts.
Requirements
Constraints
Performance
Similar to other interfaces dealing with communications to the VictoR device, asynchronous Read/Write calls will be made available from the interface..
OS Requirements
The interface will target Windows 10 platforms.
Ease of Use
The process of connecting, disconnecting, reading, and writing to a Bluetooth device often requires multiple steps. To help soften the workflow when dealing with this process, the aim for each of the abstract classes is to wrap this behavior in single call functions.
Detailed Design
The Windows BLE Communications Interface will enable communication with a BLE device by wrapping functionality within the Windows BLE library in an abstract class. This class will provide the ability to connect to and disconnect from a device. A BLEVictorDevice VictorBleDevice will derive from this abstract class to define how users can read from and write to specific characteristics. These calls will be handled asynchronously to allow for the continued execution of code while the device performs the requested action and reports back the success of the read or write operation. Subscription functionality is also defined in the BLEVictorDevice VictorBleDevice class to raise events when a characteristic’s value has changed, as long as the characteristic in question supports notifications. The A BluetoothLEDevice object within the BLEVictorDevice VictorBleDevice class is what allows for the communication with a VictoR device connected through bluetoothBLE. The BluetoothLEDevice will be hidden from the user, only allowing modifications to be made to the device through the available functions within the BLEVictorDevice VictorBleDevice class. A device manager will contain a dictionary of devices (both Bluetooth and USB) to allow for the management of these devices, and ensuring the user does not need to retain their own collection of devices within their application.
...
VictorDeviceManager
Connect
Given the user has completed a scan for devices
Create a BluetoothLEDevice using the desired deviceID
Add device to a hashed collection in DeviceManager
Disconnect
Dispose the BluetoothLEDevice
GetConnectedDeviceIDs
Return list of IDs from DeviceManager’s connected device hashed collection
ScanForDevices
Create a DeviceWatcher
Use a device selector to filter the devices you want the DeviceWatcher to notify you of
Register event handlers for devices being added, removed, or updated according to the Device Watcher
Register event handler for EnumerationCompleted and Stopped events
Start a scan with the DeviceWatcher
Add any devices found matching the DeviceWatcher criteria to a list of scanned devices
Once the EnumerationCompleted event is raised, Stop the DeviceWatcher’s scan
Subscribe
Retrieve desired device from DeviceManager’s hashed collection of connected devices
A list or dictionary of supported services from device should be available in DeviceManager
A list or dictionary of supported characteristics from each service
Write to the Client Characteristic Configuration Descriptor for the characteristic
Add callback to ValueChanged event for characteristic
Unsubscribe
A list or dictionary of supported services from device should be available in DeviceManager
A list or dictionary of supported characteristics from each service
Write to the Client Characteristic Configuration Descriptor for the characteristic
Remove callback from ValueChanged event for characteristic
ReadAsync
Ensure characteristic supports read operation
Read value if read is supported
WriteAsync
Ensure characteristic supports write operation
Write value if write is supported
ConnectionStatusChanged
Add callback to BluetoothLEDevice’s ConnectionStatusChanged event
System Interaction
Any requests to read and write data to and from a device will be managed through the VictorDeviceManager class. Users will not be interfacing with a Device class directly. Instead, the VictorDeviceManager will expose general read/write/subscription functionality and handle the nuances between connecting to devices of different typescommunicating with the device directly. The below example demonstrates a quick sequence diagram of how users will interface with both the Device and the VictorDeviceManager classesinterfaces.
...