/// <summary> /// Starts the Heart rate service /// </summary> public override async Task Init() { await CreateServiceProvider(GattServiceUuids.HeartRate); // Preparing the Blood pressure characteristics var heartRateCharacteristics = PlainNotifyParameters; heartRateCharacteristics.UserDescription = "Heart Rates in Beats per Minute"; heartRateCharacteristics.PresentationFormats.Add( GattPresentationFormat.FromParts( Convert.ToByte(PresentationFormats.FormatTypes.Unsigned16BitInteger), PresentationFormats.Exponent, Convert.ToUInt16(PresentationFormats.Units.PeriodBeatsPerMinute), Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber), PresentationFormats.Description)); // Create the heart rate characteristic for the service GattLocalCharacteristicResult result = await ServiceProvider.Service.CreateCharacteristicAsync( GattCharacteristicUuids.HeartRateMeasurement, PlainNotifyParameters); // Grab the characterist object from the service set it to the HeartRate property which is of a specfic Characteristic type GattLocalCharacteristic baseHeartRateMeasurement = null; GattServicesHelper.GetCharacteristicsFromResult(result, ref baseHeartRateMeasurement); if (baseHeartRateMeasurement != null) { HeartRateMeasurement = new Characteristics.HeartRateMeasurementCharacteristic(baseHeartRateMeasurement, this); } }
/// <summary> /// Asynchronous initialization /// </summary> /// <returns>Initialization Task</returns> public override async Task Init() { await CreateServiceProvider(GattServiceUuids.Battery); // Preparing the Battery Level characteristics GattLocalCharacteristicParameters batteryCharacteristicsParameters = PlainReadNotifyParameters; // Set the user descriptions batteryCharacteristicsParameters.UserDescription = "Battery Level percentage remaining"; // Add presentation format - 16-bit integer, with exponent 0, the unit is percentage, defined per Bluetooth SIG with Microsoft as descriptor batteryCharacteristicsParameters.PresentationFormats.Add( GattPresentationFormat.FromParts( Convert.ToByte(PresentationFormats.FormatTypes.Unsigned8BitInteger), PresentationFormats.Exponent, Convert.ToUInt16(PresentationFormats.Units.Percentage), Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber), PresentationFormats.Description)); // Create the characteristic for the service GattLocalCharacteristicResult result = await ServiceProvider.Service.CreateCharacteristicAsync( GattCharacteristicUuids.BatteryLevel, batteryCharacteristicsParameters); // Grab the characterist object from the service set it to the BatteryLevel property which is of a specfic Characteristic type GattLocalCharacteristic baseBatteryLevel = null; GattServicesHelper.GetCharacteristicsFromResult(result, ref baseBatteryLevel); if (baseBatteryLevel != null) { BatteryLevel = new Characteristics.BatteryLevelCharacteristic(baseBatteryLevel, this); } }
/// <summary> /// Initializes a new instance of the <see cref="GenericGattCharacteristicViewModel" /> class. /// </summary> /// <param name="characteristic"></param> public GenericGattCharacteristicViewModel(GenericGattCharacteristic characteristic) { this.characteristic = characteristic; userDescription = Characteristic.Characteristic.UserDescription; HasReadDescriptor = Characteristic.Characteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Read); HasWriteDescriptor = Characteristic.Characteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Write); HasWriteWithoutResponseDescriptor = Characteristic.Characteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.WriteWithoutResponse); HasNotifyDescriptor = Characteristic.Characteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Notify); HasIndicateDescriptor = Characteristic.Characteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Indicate); }
/// <summary> /// Asynchronous initialization /// </summary> /// <returns>Initialization Task</returns> public override async Task Init() { await CreateServiceProvider(GattServiceUuids.CurrentTime); GattLocalCharacteristicResult result = await ServiceProvider.Service.CreateCharacteristicAsync( GattCharacteristicUuids.CurrentTime, PlainReadNotifyParameters); GattLocalCharacteristic currentTimeCharacterisitic = null; GattServicesHelper.GetCharacteristicsFromResult(result, ref currentTimeCharacterisitic); if (currentTimeCharacterisitic != null) { CurrentTime = new Characteristics.CurrentTimeCharacteristic(currentTimeCharacterisitic, this); } }
/// <summary> /// Converts GenericGattCharacteristic.Value to a string based on the presentation format /// </summary> /// <param name="characteristic"></param> /// <returns>value as a string</returns> public static string ConvertGattCharacteristicValueToString(GenericGattCharacteristic characteristic) { if (characteristic.Value == null) { return(String.Empty); } GattPresentationFormat format = null; if (characteristic.Characteristic.PresentationFormats.Count > 0) { format = characteristic.Characteristic.PresentationFormats[0]; } return(ConvertValueBufferToString(characteristic.Value, format)); }
/// <summary> /// Asynchronous initialization /// </summary> /// <returns>Initialization Task</returns> public override async Task Init() { await CreateServiceProvider(GattServiceUuids.BloodPressure); // Preparing the Blood pressure characteristics var bloodPressureCharacteristics = PlainIndicateParameters; bloodPressureCharacteristics.UserDescription = "Blood Pressure in mm Hg"; bloodPressureCharacteristics.PresentationFormats.Add( GattPresentationFormat.FromParts( Convert.ToByte(PresentationFormats.FormatTypes.OpaqueStructure), PresentationFormats.Exponent, Convert.ToUInt16(PresentationFormats.Units.PressureMilliMetreofmercury), Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber), PresentationFormats.Description)); // Create the blood pressure measurement characteristic for the service GattLocalCharacteristicResult result = await ServiceProvider.Service.CreateCharacteristicAsync( GattCharacteristicUuids.BloodPressureMeasurement, bloodPressureCharacteristics); // Grab the characterist object from the service GattLocalCharacteristic baseBloodPressureMeasurement = null; GattServicesHelper.GetCharacteristicsFromResult(result, ref baseBloodPressureMeasurement); if (baseBloodPressureMeasurement != null) { BloodPressureMeasurement = new Characteristics.BloodPressureMeasurementCharacteristic(baseBloodPressureMeasurement, this); } result = null; // Preparing the Blood pressure feature characteristics var bloodPressureFeatureCharacteristics = PlainReadParameter; bloodPressureFeatureCharacteristics.UserDescription = "The Blood Pressure Feature characteristic is used to describe the supported features of the Blood Pressure Sensor."; bloodPressureFeatureCharacteristics.PresentationFormats.Add( GattPresentationFormat.FromParts( Convert.ToByte(PresentationFormats.FormatTypes.Unsigned16BitInteger), PresentationFormats.Exponent, Convert.ToUInt16(PresentationFormats.Units.Unitless), Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber), PresentationFormats.Description)); // Create the blood pressure measurement characteristic for the service result = await ServiceProvider.Service.CreateCharacteristicAsync( GattCharacteristicUuids.BloodPressureFeature, bloodPressureFeatureCharacteristics); // Grab the characterist object from the service GattLocalCharacteristic baseBloodPressureFeature = null; GattServicesHelper.GetCharacteristicsFromResult(result, ref baseBloodPressureFeature); if (baseBloodPressureFeature != null) { BloodPressureFeature = new Characteristics.BloodPressureFeatureCharacteristic(baseBloodPressureFeature, this); } }
/// <summary> /// Asynchronous initialization /// </summary> /// <returns>Initialization Task</returns> 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; }