public void UInt64Test() { UInt64 data = 42; Assert.AreEqual(data, GattConvert.ToUInt16(GattConvert.ToIBuffer(data))); Assert.AreNotEqual(data - 1, GattConvert.ToUInt64(GattConvert.ToIBuffer(data))); }
/// <summary> /// This sets the value based on the input string with regard to the characteristics first presentation format /// </summary> /// <param name="value">value to set</param> /// <param name="isHexString">is the passed in string a hex byte array</param> public void SetValueFromString(string value, bool isHexString = false) { if (isHexString == true) { Characteristic.Value = GattConvert.ToIBufferFromHexString(value); return; } if (Characteristic.Characteristic.PresentationFormats.Count > 0) { byte format = Characteristic.Characteristic.PresentationFormats[0].FormatType; // Check our supported formats to convert a string to this Characteristics Value if (!((format != GattPresentationFormatTypes.SInt32) || (format != GattPresentationFormatTypes.Utf8))) { throw new NotImplementedException("Only SInt32 and UTF8 are supported"); } //TODO: Support more presentation types if (format == GattPresentationFormatTypes.SInt32) { Characteristic.Value = GattConvert.ToIBuffer(Convert.ToInt32(value)); } else if (format == GattPresentationFormatTypes.Utf8) { Characteristic.Value = GattConvert.ToIBuffer(value); } } }
public void Int64Test2() { Int16 data = 42; Assert.IsTrue(data == GattConvert.ToInt64(GattConvert.ToIBuffer(data))); Assert.IsFalse((data - 1) == GattConvert.ToInt64(GattConvert.ToIBuffer(data))); }
public void Int32Test() { Int32 data = 42; Assert.AreEqual(data, GattConvert.ToInt32(GattConvert.ToIBuffer(data))); Assert.AreNotEqual(data - 1, GattConvert.ToInt32(GattConvert.ToIBuffer(data))); }
public void Int16Test2() { byte[] input = { 0, 42, 0, 42, 0, 42, 0 }; byte[] expected = { 0, 42 }; Assert.AreEqual(BitConverter.ToInt16(expected, 0), GattConvert.ToInt16(GattConvert.ToIBuffer(input))); }
public void IntTest1() { int data = 42; IBuffer buf = GattConvert.ToIBuffer(data); Assert.AreEqual(data, GattConvert.ToInt32(buf)); Assert.AreNotEqual(43, GattConvert.ToInt32(buf)); }
public void Int16Test() { Int16 data = 42; Int64 wrong = Int64.MaxValue; Assert.AreEqual(data, GattConvert.ToInt32(GattConvert.ToIBuffer(data))); Assert.AreNotEqual(data - 1, GattConvert.ToInt16(GattConvert.ToIBuffer(data))); Assert.AreNotEqual(wrong, GattConvert.ToInt16(GattConvert.ToIBuffer(wrong))); }
private void SetHeartRate() { // Heart rate service starts with flags, then the value. I combine them here then set the characterstic value byte[] flags = { 0x07 }; byte[] heartRate = BitConverter.GetBytes(currentHeartRate); byte[] value = flags.Concat(heartRate).ToArray(); Value = GattConvert.ToIBuffer(value); NotifyValue(); }
public void IBufferTest1() { byte[] correct = { 0x48, 0x65, 0x6C, 0x6C, 0x6F }; byte[] incorrect = { 0x42, 0x42, 0x42, 0x42, 0x42 }; byte[] result; CryptographicBuffer.CopyToByteArray(GattConvert.ToIBuffer("Hello"), out result); Assert.IsTrue(StructuralComparisons.StructuralEqualityComparer.Equals(correct, result)); Assert.IsFalse(StructuralComparisons.StructuralEqualityComparer.Equals(incorrect, result)); }
public /*async*/ void NotifyImmediatelyForCategory(AlertCategoryId categoryId) { if ((categoryId != AlertCategoryId.SimpleAlert) && (categoryId != AlertCategoryId.All)) { return; } var service = base.ParentService as AlertNotificationService; var value = new byte[] { (byte)AlertCategoryId.SimpleAlert, Convert.ToByte(service.UnreadCount) }; Value = GattConvert.ToIBuffer(value); base.NotifyValue(); }
private void updateBloodPressure(Object state) { // Create random blood pressure between 100-160 over 60-100 Systolic = (Int16)rand.Next(100, 160); Diastolic = (Int16)rand.Next(60, 100); UInt16 MAP = (UInt16)(((2 * Diastolic) + Systolic) / 3); // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.blood_pressure_measurement.xml byte[] flags = { 0 }; byte[] value = flags.Concat( BitConverter.GetBytes(Systolic)).Concat( BitConverter.GetBytes(Diastolic)).Concat( BitConverter.GetBytes(MAP)).ToArray(); Value = GattConvert.ToIBuffer(value); NotifyValue(); }
/// <summary> /// Initializes a new instance of the <see cref="BloodPressureMeasurementCharacteristic" /> class. /// </summary> /// <param name="characteristic">Characteristic this wraps</param> public BloodPressureFeatureCharacteristic(GattLocalCharacteristic characteristic, GenericGattService service) : base(characteristic, service) { // Supports no extra features - required per spec // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.blood_pressure_feature.xml Value = GattConvert.ToIBuffer((Int16)0); }