in GattServicesLibrary/GattServicesLibrary/Services/MicrosoftService.cs [199:337]
public override async Task Init()
{
var serviceData = new byte[] {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
};
ServiceData = WindowsRuntimeBuffer.Create(serviceData, 0, serviceData.Length, serviceData.Length);
await CreateServiceProvider(MSFTServiceUuid);
GattLocalCharacteristicResult result = null;
// Prepare the Read Characteristic
GattLocalCharacteristicParameters readParam = PlainReadParameter;
readParam.UserDescription = "Microsoft Read characteristic";
// Add presentation format - 16-bit integer, with exponent 0, the unit is percentage, defined per Bluetooth SIG with Microsoft as descriptor
readParam.PresentationFormats.Add(
GattPresentationFormat.FromParts(
Convert.ToByte(PresentationFormats.FormatTypes.Signed32BitInteger),
PresentationFormats.Exponent,
Convert.ToUInt16(PresentationFormats.Units.Unitless),
Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber),
PresentationFormats.Description));
GattLocalCharacteristic baseReadChar = null;
result = await ServiceProvider.Service.CreateCharacteristicAsync(MSFTReadChar, readParam);
GattServicesHelper.GetCharacteristicsFromResult(result, ref baseReadChar);
if (baseReadChar != null)
{
ReadCharacteristic = new Characteristics.MicrosoftReadCharacteristic(baseReadChar, this);
}
result = null;
// Prepare the Write Characteristic
GattLocalCharacteristicParameters writeParam = PlainWriteOrWriteWithoutRespondsParameter;
writeParam.UserDescription = "Microsoft Write characteristic";
// Add presentation format - 16-bit integer, with exponent 0, the unit is percentage, defined per Bluetooth SIG with Microsoft as descriptor
writeParam.PresentationFormats.Add(
GattPresentationFormat.FromParts(
Convert.ToByte(PresentationFormats.FormatTypes.UTF8String),
PresentationFormats.Exponent,
Convert.ToUInt16(PresentationFormats.Units.Unitless),
Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber),
PresentationFormats.Description));
GattLocalCharacteristic baseWriteChar = null;
result = await ServiceProvider.Service.CreateCharacteristicAsync(MSFTWriteChar, writeParam);
GattServicesHelper.GetCharacteristicsFromResult(result, ref baseWriteChar);
if (baseWriteChar != null)
{
WriteCharacteristic = new Characteristics.MicrosoftWriteCharacteristic(baseWriteChar, this);
}
result = null;
// Prepare the Notify Characteristic
GattLocalCharacteristicParameters notifyParam = PlainReadNotifyParameters;
notifyParam.UserDescription = "Microsoft Notify characteristic";
// Add presentation format - string, the unit is percentage, defined per Bluetooth SIG with Microsoft as descriptor
notifyParam.PresentationFormats.Add(
GattPresentationFormat.FromParts(
Convert.ToByte(PresentationFormats.FormatTypes.UTF8String),
PresentationFormats.Exponent,
Convert.ToUInt16(PresentationFormats.Units.Unitless),
Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber),
PresentationFormats.Description));
GattLocalCharacteristic baseNotifyChar = null;
result = await ServiceProvider.Service.CreateCharacteristicAsync(MSFTNotifyChar, notifyParam);
GattServicesHelper.GetCharacteristicsFromResult(result, ref baseNotifyChar);
if (baseNotifyChar != null)
{
NotifyCharacteristic = new Characteristics.MicrosoftNotifyCharacteristic(baseNotifyChar, this);
}
result = null;
// Prepare the Indicate Characteristic
GattLocalCharacteristicParameters indicateParam = new GattLocalCharacteristicParameters
{
CharacteristicProperties = GattCharacteristicProperties.Read | GattCharacteristicProperties.Indicate,
WriteProtectionLevel = GattProtectionLevel.Plain,
ReadProtectionLevel = GattProtectionLevel.Plain
};
indicateParam.UserDescription = "Microsoft Indicate characteristic";
// Add presentation format - 16-bit integer, with exponent 0, the unit is percentage, defined per Bluetooth SIG with Microsoft as descriptor
indicateParam.PresentationFormats.Add(
GattPresentationFormat.FromParts(
Convert.ToByte(PresentationFormats.FormatTypes.UTF8String),
PresentationFormats.Exponent,
Convert.ToUInt16(PresentationFormats.Units.Unitless),
Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber),
PresentationFormats.Description));
GattLocalCharacteristic baseIndicateChar = null;
result = await ServiceProvider.Service.CreateCharacteristicAsync(MSFTIndicateChar, indicateParam);
GattServicesHelper.GetCharacteristicsFromResult(result, ref baseIndicateChar);
if (baseIndicateChar != null)
{
IndicateCharacteristic = new Characteristics.MicrosoftNotifyCharacteristic(baseIndicateChar, this);
}
result = null;
// Prepare the Read Long Characteristic
GattLocalCharacteristicParameters longParam = new GattLocalCharacteristicParameters
{
CharacteristicProperties = GattCharacteristicProperties.Read,
WriteProtectionLevel = GattProtectionLevel.Plain,
ReadProtectionLevel = GattProtectionLevel.Plain
};
longParam.UserDescription = "Microsoft Read Long characteristic";
// Add presentation format - 16-bit integer, with exponent 0, the unit is percentage, defined per Bluetooth SIG with Microsoft as descriptor
longParam.PresentationFormats.Add(
GattPresentationFormat.FromParts(
Convert.ToByte(PresentationFormats.FormatTypes.OpaqueStructure),
PresentationFormats.Exponent,
Convert.ToUInt16(PresentationFormats.Units.Unitless),
Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber),
PresentationFormats.Description));
GattLocalCharacteristic baseLongReadChar = null;
result = await ServiceProvider.Service.CreateCharacteristicAsync(MSFTLongChar, longParam);
GattServicesHelper.GetCharacteristicsFromResult(result, ref baseLongReadChar);
if (baseLongReadChar != null)
{
ReadLongCharacteristic = new Characteristics.MicrosoftReadLongCharacteristic(baseLongReadChar, this);
}
result = null;
}