示例#1
0
		public bool FindCharacteristicByHandle (ushort handle, out BlePeripheralCharacteristic characteristic)
		{
            return HandleMap.TryGetValue(handle, out characteristic);
		}
示例#2
0
 public bool FindCharacteristicByHandle(ushort handle, out BlePeripheralCharacteristic characteristic)
 {
     return(HandleMap.TryGetValue(handle, out characteristic));
 }
		private void ConvertAttributesToCharacteristics (BlePeripheralService service)
		{
			#region Example attr table

//			*=== Service: 42 48 12 4a 7f 2c 48 47 b9 de 04 a9 02 00 06 d5 
//			*====== Att: 26 - 00 28 
//			*====== Att: 27 - 03 28 
//			*====== Att: 28 - 42 48 12 4a 7f 2c 48 47 b9 de 04 a9 02 04 06 d5 
//			*====== Att: 29 - 02 29 
//			*====== Att: 30 - 03 28 
//			*====== Att: 31 - 42 48 12 4a 7f 2c 48 47 b9 de 04 a9 02 05 06 d5 
//			*====== Att: 32 - 02 29 

			#endregion

			BlePeripheralCharacteristic current = null;
			bool createCharacteristic = false;

			foreach (BlePeripheralAttribute attr in service.Attributes)
			{
				if (attr.AttributeUUID.Equals (BlePeripheralAttribute.SERVICE_UUID))
				{
					// defines service - do nothing
				}
				else if (attr.AttributeUUID.Equals (BlePeripheralAttribute.CHARACTERISTIC_UUID))
				{
					// finish previous characteristic
					current = null;

					// crete characteristic from next attribute
					createCharacteristic = true;
				}
				else if (attr.AttributeUUID.Equals (BlePeripheralAttribute.CHARACTERISTIC_CCC_UUID))
				{
					// add ccc capabilities to characteristic
					current.SetCCCHandle (attr.Handle);
				}
				else
				{
					// if new characteristic begins - create it else skip and do nothing
					if (createCharacteristic)
					{
						current = new BlePeripheralCharacteristic (attr.AttributeUUID, attr.Handle);
						createCharacteristic = false;

						service.Characteristics.Add (current);
					}
				}
			}
		}