public BluetoothLEAdvertisementBytePattern GetBytePattern() { var pattern = new BluetoothLEAdvertisementBytePattern(); pattern.DataType = SectionType; pattern.Offset = SectionOffset; if (SectionDataString != null && SectionDataString.Length > 0) { if (sectionDataFormat == DataFormatType.Hex) { // pad the value if we've received odd number of bytes if (SectionDataString.Length % 2 == 1) { pattern.Data = GattConvert.ToIBufferFromHexString("0" + SectionDataString); } else { pattern.Data = GattConvert.ToIBufferFromHexString(SectionDataString); } } else if (sectionDataFormat == DataFormatType.String) { pattern.Data = CryptographicBuffer.ConvertStringToBinary(SectionDataString, BinaryStringEncoding.Utf8); } } return(pattern); }
/// <summary> /// Converts the given UUID string to BluetoothLEAdvertisementBytePattern. /// </summary> /// <param name="hexString"></param> /// <returns></returns> private BluetoothLEAdvertisementBytePattern BEACONIDToAdvertisementBytePattern(string BEACONID) { if (BEACONID.Length % 2 != 0) { BEACONID = BEACONID.Remove(BEACONID.Length - 1); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(CommonConstants.ManufacturerCompanyIdAsString); stringBuilder.Append(CommonConstants.DefaultBeaconTypeAndDataLengthAsString); stringBuilder.Append(BEACONID.ToUpper()); byte[] data = HexStringToByteArray(stringBuilder.ToString()); BluetoothLEAdvertisementBytePattern pattern = new BluetoothLEAdvertisementBytePattern(); pattern.DataType = CommonConstants.DataSectionDataType; pattern.Offset = 0; pattern.Data = data.AsBuffer(); return(pattern); }
/// <summary> /// Constructs a BluetoothLEAdvertisementBytePattern instance from the given UUID. /// UUID doesn't have to be full 32 hex digits, but length needs to be even. /// </summary> /// <param name="uuid">The UUID.</param> /// <param name="manufacturerId">The manufacturer ID.</param> /// <param name="beaconCode">The beacon code.</param> /// <returns>BluetoothLEAdvertisementBytePattern.</returns> public static BluetoothLEAdvertisementBytePattern UuidToAdvertisementBytePattern( string uuid, ushort manufacturerId, ushort beaconCode) { if (uuid.Length % 2 != 0) { uuid = uuid.Remove(uuid.Length - 1); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(ManufacturerIdToString(manufacturerId)); stringBuilder.Append(BeaconCodeToString(beaconCode)); stringBuilder.Append(uuid.ToUpper()); byte[] data = HexStringToByteArray(stringBuilder.ToString()); BluetoothLEAdvertisementBytePattern pattern = new BluetoothLEAdvertisementBytePattern(); pattern.DataType = SecondBeaconDataSectionDataType; pattern.Offset = 0; pattern.Data = data.AsBuffer(); return(pattern); }
/// <summary> /// Constructs a BluetoothLEAdvertisementBytePattern instance from the given UUID. /// UUID doesn't have to be full 32 hex digits, but length needs to be even. /// </summary> /// <param name="uuid">The UUID.</param> /// <param name="manufacturerId">The manufacturer ID.</param> /// <param name="beaconCode">The beacon code.</param> /// <returns>BluetoothLEAdvertisementBytePattern.</returns> public static BluetoothLEAdvertisementBytePattern UuidToAdvertisementBytePattern( string uuid, ushort manufacturerId, ushort beaconCode) { if (uuid.Length % 2 != 0) { uuid = uuid.Remove(uuid.Length - 1); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(ManufacturerIdToString(manufacturerId)); stringBuilder.Append(BeaconCodeToString(beaconCode)); stringBuilder.Append(uuid.ToUpper()); byte[] data = HexStringToByteArray(stringBuilder.ToString()); BluetoothLEAdvertisementBytePattern pattern = new BluetoothLEAdvertisementBytePattern(); pattern.DataType = SecondBeaconDataSectionDataType; pattern.Offset = 0; pattern.Data = data.AsBuffer(); return pattern; }
/// <summary> /// Converts the given UUID string to BluetoothLEAdvertisementBytePattern. /// </summary> /// <param name="hexString"></param> /// <returns></returns> private BluetoothLEAdvertisementBytePattern BEACONIDToAdvertisementBytePattern(string BEACONID) { if (BEACONID.Length % 2 != 0) { BEACONID = BEACONID.Remove(BEACONID.Length - 1); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(CommonConstants.ManufacturerCompanyIdAsString); stringBuilder.Append(CommonConstants.DefaultBeaconTypeAndDataLengthAsString); stringBuilder.Append(BEACONID.ToUpper()); byte[] data = HexStringToByteArray(stringBuilder.ToString()); BluetoothLEAdvertisementBytePattern pattern = new BluetoothLEAdvertisementBytePattern(); pattern.DataType = CommonConstants.DataSectionDataType; pattern.Offset = 0; pattern.Data = data.AsBuffer(); return pattern; }