Bluetooth Data Access
Processor Information
The payload processing must be declared in a processor information within the device info file.
{
...
"TaskProcessors": [
{
"Id": "DABEA01B-CDA0-4DCD-9135-0FE1C17A46AE",
"Name": "MainTaskProcessor",
"ScriptFile": "TTestPayload.cs"
}
]
}
The payload script is typically placed in the folder:
$(ConfigPath)\HumanOS.UHAL.BluetoothDeviceDriver
Communication
The Bluetooth device driver connects and communicates in the following way:
Make sure that:
- The devices are paired
- The "partner" device is running and listening to incoming requests with the "partner" service UUID
- HumanOS® Bluetooth device driver uses the same service UUID and knows the name of the "partner" device (which is given through pairing)
Requests
The device driver supports requests for an action. The following requests are taken:
Request | Action | Format |
---|---|---|
Write | Writes data to another device | dynamic |
Request | Request data from another device | dynamic |
The action executed by this request and the format is generic and needs additional scripting.
Scripting
The script file implements the protocol specific reading and writing operations. The complete communication must be implemented here.
The script is placed in the folder:
$(ConfigPath)\HumanOS.UHAL.BluetoothDeviceDriver\
The script object must be derived from TAbstractStreamScriptObject. Following methods can be overwritten:
Method | Action |
---|---|
handleStream | Handles the stream in a cyclic manner. This method MUST be implemented. Arguments: (Kernel: HumanOS® Kernel access; Logger: Logger instance of the driver; DeviceInfo: device info file; DataStream: stream interface to Bluetooth socket) |
connectToDevice | This method is called after successful connection to the device. Place the code for initialization and connection preamble. Arguments: Same as handleStream() |
disconnectFromDevice | This method is called after successful disconnection from the device. Place the code for clean-up. Arguments: Same as handleStream() |
onDataReceived | Not supported for Bluetooth devices |
Example
/// <summary>
/// Test payload for script
/// </summary>
public class TTestPayload : TAbstractStreamScriptObject
{
///<see cref="TAbstractStreamScriptObject"/>
public override void handleStream(IKernelAccess Kernel,
ILogger Logger,
TDeviceInfo DeviceInfo,
IDataStream DataStream)
{
byte[] aui8Buffer = new byte[4];
DataStream.read(aui8Buffer, 0, 4);
aui8Buffer[0] = 0x11;
aui8Buffer[1] = 0x21;
aui8Buffer[2] = 0x31;
aui8Buffer[3] = 0x41;
DataStream.write(aui8Buffer, 0, 4);
}
}