コード例 #1
0
		private void FindAttributes (BlePeripheralService service)
		{
			byte[] findInfo = Ble.Lib.BLECommandATTClientFindInformation (this.Connection, service.StartHandle, service.EndHandle);

			FindInformationFoundEventHandler infoHandler = (sender, e) => this.AttributeFound (service, e);
				
			Ble.Lib.BLEEventATTClientFindInformationFound += infoHandler;

			ProcedureCompletedEventArgs procedureResponse = null;
			ProcedureCompletedEventHandler handler = (sender, e) => {
				procedureResponse = e;
			};
			Ble.Lib.BLEEventATTClientProcedureCompleted += handler;

			Ble.SendCommand (this.Port, findInfo);

			this.WaitEvent (() => procedureResponse != null);

			Ble.Lib.BLEEventATTClientFindInformationFound -= infoHandler;
			Ble.Lib.BLEEventATTClientProcedureCompleted -= handler;
		}
コード例 #2
0
		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);
					}
				}
			}
		}
コード例 #3
0
		private void AttributeFound (BlePeripheralService service, FindInformationFoundEventArgs e)
		{
			service.Attributes.Add (new BlePeripheralAttribute (e.uuid, e.chrhandle));
		}