コード例 #1
0
 public DeviceNotifyingHandler(BluetoothGatt gatt, GattClientObserver gattObserver)
 {
     _gatt = gatt;
     _gattObserver = gattObserver;
     gattObserver.CharacteristicValueChanged += OnCharacteristicValueChanged;
     gattObserver.DescriptorWritten += OnDescriptorWritten;
 }
コード例 #2
0
 private void OnDescriptorWritten(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status)
 {
     if (status == GattStatus.Success && _onSubscribed != null)
     {
         _onSubscribed(true);
     }
 }
コード例 #3
0
ファイル: Device.cs プロジェクト: fburel/Monkey.Robotics
		public Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, 
			GattCallback gattCallback, int rssi) : base ()
		{
			this._nativeDevice = nativeDevice;
			this._gatt = gatt;
			this._gattCallback = gattCallback;
			this._rssi = rssi;

			// when the services are discovered on the gatt callback, cache them here
			if (this._gattCallback != null) {
				this._gattCallback.ServicesDiscovered += (s, e) => {
					this._services = new List<IService> ();

					try{  
						
						var services = this._gatt.Services;

						foreach (var item in services) {
							this._services.Add (new Service (item, this._gatt, this._gattCallback));
						}
						this.ServicesDiscovered (this, e); 

					} catch { 
					
					} 

				};
			}
		}
コード例 #4
0
 public void Update(BluetoothDevice nativeDevice, BluetoothGatt gatt,
     IGattCallback gattCallback)
 {
     _nativeDevice = nativeDevice;
     _gatt = gatt;
     _gattCallback = gattCallback;
 }
コード例 #5
0
 public Characteristic(BluetoothGattCharacteristic nativeCharacteristic, BluetoothGatt gatt,
     IGattCallback gattCallback)
 {
     _nativeCharacteristic = nativeCharacteristic;
     _gatt = gatt;
     _gattCallback = gattCallback;
 }
コード例 #6
0
 public override void OnReadRemoteRssi(ABluetooth.BluetoothGatt gatt, int rssi, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"ReadRemoteRssi {rssi}");
     _owner.ReadRemoteRssi?.Invoke(_owner, new RssiEventArgs {
         Status = status, Rssi = (short)rssi
     });
 }
コード例 #7
0
		/// <Docs>GATT client</Docs>
		/// <summary>
		/// Raises the connection state change event.
		/// </summary>
		/// <param name="gatt">Gatt.</param>
		/// <param name="status">Status.</param>
		/// <param name="newState">New state.</param>
		public override void OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState)
		{
			base.OnConnectionStateChange(gatt, status, newState);

			if (status != GattStatus.Success)
				return;

            var device = new Device(gatt.Device, gatt, this, 0, null);
            switch (newState)
			{
				case ProfileState.Disconnected:
                    device.State = DeviceState.Disconnected;

                    try
                    {
                        gatt.Close();
                        gatt = null;
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Unable to close connection to gatt. Exception: {0}", ex.Message);
                    }
                    finally
                    {
                        DeviceDisconnected(this, new DeviceConnectionEventArgs(device));
                    }

					break;
				case ProfileState.Connected:
					device.State = DeviceState.Connected;
					
                    DeviceConnected(this, new DeviceConnectionEventArgs(device));   
					break;
			}
		}
コード例 #8
0
 public override void OnCharacteristicChanged(ABluetooth.BluetoothGatt gatt, ABluetooth.BluetoothGattCharacteristic characteristic)
 {
     System.Diagnostics.Debug.WriteLine($"CharacteristicChanged {characteristic.Uuid}");
     _owner.CharacteristicChanged?.Invoke(_owner, new CharacteristicEventArgs {
         Characteristic = characteristic
     });
 }
コード例 #9
0
 public override void OnCharacteristicWrite(ABluetooth.BluetoothGatt gatt, ABluetooth.BluetoothGattCharacteristic characteristic, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"CharacteristicWrite {characteristic.Uuid} {status}");
     _owner.CharacteristicWrite?.Invoke(_owner, new CharacteristicEventArgs {
         Characteristic = characteristic, Status = status
     });
 }
コード例 #10
0
ファイル: GattCallback.cs プロジェクト: yelkrebb/XamTest-
		public override void OnDescriptorRead (BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status)
		{
			base.OnDescriptorRead (gatt, descriptor, status);

			Console.WriteLine ("OnDescriptorRead: " + descriptor.ToString());

		}
コード例 #11
0
 public override void OnDescriptorRead(ABluetooth.BluetoothGatt gatt, ABluetooth.BluetoothGattDescriptor descriptor, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"DescriptorRead {descriptor.Uuid} {status}");
     _owner.DescriptorRead?.Invoke(_owner, new DescriptorEventArgs {
         Descriptor = descriptor, Status = status
     });
 }
コード例 #12
0
 private void GattObserverOnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
 {
     if (_onRead != null)
     {
         _onRead(characteristic.GetValue(), status);
     }
 }
コード例 #13
0
        public Descriptor(BluetoothGattDescriptor nativeDescriptor, BluetoothGatt gatt, IGattCallback gattCallback)
        {
            _gattCallback = gattCallback;
            _gatt = gatt;

            _nativeDescriptor = nativeDescriptor;
        }
コード例 #14
0
ファイル: Device.cs プロジェクト: yelkrebb/Core.BLE.Droid
		public Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, 
			GattCallback gattCallback, int rssi) : base ()
		{
			this._nativeDevice = nativeDevice;
			this._gatt = gatt;
			this._gattCallback = gattCallback;
			this._rssi = rssi;

			// when the services are discovered on the gatt callback, cache them here
			if (this._gattCallback != null) {
				this._gattCallback.ServicesDiscovered += (s, e) => {
					var services = this._gatt.Services;
					this._services = new List<IService> ();
					foreach (var item in services) {
						this._services.Add (new Service (item, this._gatt, this._gattCallback));
						foreach (var itm in item.Characteristics)
						{
							Console.WriteLine("Characteristic: " + itm.Uuid.ToString());
						}
					}
					this.ServicesDiscovered (this, e);
				};


			}
		}
コード例 #15
0
		public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState)
		{
			Console.WriteLine ("OnConnectionStateChange: ");
			base.OnConnectionStateChange (gatt, status, newState);

			//TODO: need to pull the cached RSSI in here, or read it (requires the callback)
			Device device = new Device (gatt.Device, gatt, this, 0);

			switch (newState) {
			// disconnected
			case ProfileState.Disconnected:
				Console.WriteLine ("disconnected");
				this.DeviceDisconnected (this, new DeviceConnectionEventArgs () { Device = device });
				break;
				// connecting
			case ProfileState.Connecting:
				Console.WriteLine ("Connecting");
				break;
				// connected
			case ProfileState.Connected:
				Console.WriteLine ("Connected");
				this.DeviceConnected (this, new DeviceConnectionEventArgs () { Device = device });
				break;
				// disconnecting
			case ProfileState.Disconnecting:
				Console.WriteLine ("Disconnecting");
				break;
			}
		}
コード例 #16
0
        public override void OnServicesDiscovered(bt.BluetoothGatt gatt, [GeneratedEnum] bt.GattStatus status)
        {
            base.OnServicesDiscovered(gatt, status);

            ServicesDiscovered?.Invoke(this, new ServicesDiscoveredEventArgs(gatt, status));

            _servicesDiscovered = true;
        }
コード例 #17
0
ファイル: Device.cs プロジェクト: gabornemeth/Monkey.Robotics
		internal Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, 
			GattCallback gattCallback, int rssi) : base ()
		{
			this._nativeDevice = nativeDevice;
            _gatt = gatt;
            SetGattCallback(gattCallback);
			this._rssi = rssi;
		}
コード例 #18
0
 private void PlatformInit()
 {
     // android default - replaced by callback after request or change
     Mtu           = 20;
     _gattCallback = new GattCallback(this);
     _gatt         = ((ABluetooth.BluetoothDevice)Device).ConnectGatt(Android.App.Application.Context, AutoConnect, _gattCallback, ABluetooth.BluetoothTransports.Le);
     _gatt.RequestMtu(512);
 }
コード例 #19
0
        public Device(BluetoothDevice nativeDevice, BluetoothGatt gatt, IGattCallback gattCallback, int rssi, byte[] advertisementData = null)
            : base()
        {
            Update(nativeDevice, gatt, gattCallback);
            this._rssi = rssi;

            _advertisementData = advertisementData ?? new byte[0];
        }
コード例 #20
0
 public override void OnServicesDiscovered(ABluetooth.BluetoothGatt gatt, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"ServicesDiscovered {status}");
     _owner._servicesDiscovered = true;
     _owner.ServicesDiscovered?.Invoke(_owner, new GattEventArgs {
         Status = status
     });
 }
コード例 #21
0
ファイル: GattCallback.cs プロジェクト: yelkrebb/XamTest-
		public override void OnServicesDiscovered (BluetoothGatt gatt, GattStatus status)
		{
			base.OnServicesDiscovered (gatt, status);

			Console.WriteLine ("OnServicesDiscovered: " + status.ToString ());

			this.ServicesDiscovered (this, new ServicesDiscoveredEventArgs ());
		}
コード例 #22
0
ファイル: Device.cs プロジェクト: xabre/xamarin-bluetooth-le
        public void Update(BluetoothDevice nativeDevice, BluetoothGatt gatt, IGattCallback gattCallback)
        {
            _nativeDevice = nativeDevice;
            _gatt = gatt;
            _gattCallback = gattCallback;

            Id = ParseDeviceId();
            Name = _nativeDevice.Name;
        }
コード例 #23
0
		/// <summary>
		/// Raises the services discovered event.
		/// </summary>
		/// <param name="gatt">Gatt.</param>
		/// <param name="status">Status.</param>
		public override void OnServicesDiscovered(BluetoothGatt gatt, GattStatus status)
		{
			base.OnServicesDiscovered(gatt, status);

			if (status != GattStatus.Success)
				return;

			ServicesDiscovered(this, EventArgs.Empty);
		}
コード例 #24
0
		public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status)
		{
			base.OnDescriptorWrite(gatt, descriptor, status);

			Console.WriteLine("GattCallBack: OnDescriptorWrite: " + descriptor.ToString());
			this.DescriptorWrite(this, new CharacteristicReadEventArgs() 
			{ 
				Characteristic = new Characteristic(descriptor.Characteristic, gatt, this) 
			});
		}
コード例 #25
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BluetoothLE.Droid.Service"/> class.
		/// </summary>
		/// <param name="nativeService">Native service.</param>
		/// <param name="gatt">Native Gatt.</param>
		/// <param name="callback">Callback.</param>
		public Service(BluetoothGattService nativeService, BluetoothGatt gatt, GattCallback callback)
		{
			_nativeService = nativeService;
			_gatt = gatt;
			_callback = callback;

			_id = ServiceIdFromUuid(_nativeService.Uuid);

			Characteristics = new List<ICharacteristic>();
		}
コード例 #26
0
 public override void OnConnectionStateChange(ABluetooth.BluetoothGatt gatt, ABluetooth.GattStatus status, ABluetooth.ProfileState newState)
 {
     System.Diagnostics.Debug.WriteLine($"ConnectionStateChanged {status}");
     if (newState == ABluetooth.ProfileState.Connected)
     {
         _owner._connected = true;
         _owner._connectedHandle.Set();
         gatt.DiscoverServices();
     }
 }
コード例 #27
0
ファイル: GattCallback.cs プロジェクト: yelkrebb/XamTest-
		public override void OnCharacteristicRead (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
		{
			base.OnCharacteristicRead (gatt, characteristic, status);

			Console.WriteLine ("GattCallBack: OnCharacteristicRead: " + characteristic.GetStringValue (0));

			this.CharacteristicValueUpdated (this, new CharacteristicReadEventArgs () { 
				Characteristic = new Characteristic (characteristic, gatt, this) }
			);
		}
コード例 #28
0
        public override void OnConnectionStateChange(bt.BluetoothGatt gatt, [GeneratedEnum] bt.GattStatus status, [GeneratedEnum] bt.ProfileState newState)
        {
            base.OnConnectionStateChange(gatt, status, newState);

            ConnectionStateChange?.Invoke(this, new ConnectionStateChangeEventArgs(gatt, status, newState));

            if (!_servicesDiscovered)
            {
                gatt.DiscoverServices();
            }
        }
コード例 #29
0
		public override void OnCharacteristicChanged (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
		{
			base.OnCharacteristicChanged (gatt, characteristic);

			Console.WriteLine ("OnCharacteristicChanged: " + characteristic.GetStringValue (0));
			var f = new CharacteristicReadEventArgs () { 
				Characteristic = new Characteristic (characteristic, gatt, this)};
			Debug.WriteLine ("OnCharacteristicChanged" + f);

			this.CharacteristicValueUpdated (this, f);
		}
コード例 #30
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BluetoothLE.Droid.Characteristic"/> class.
		/// </summary>
		/// <param name="characteristic">Characteristic.</param>
		/// <param name="gatt">Gatt.</param>
		/// <param name="gattCallback">Gatt callback.</param>
		public Characteristic(BluetoothGattCharacteristic characteristic, BluetoothGatt gatt, GattCallback gattCallback)
		{
			_nativeCharacteristic = characteristic;
			_gatt = gatt;
			_callback = gattCallback;

			if (_callback != null)
			{
				_callback.CharacteristicValueUpdated += CharacteristicValueUpdated;
			}
		}
コード例 #31
0
        public void Connect(bool autoConnect = false)
        {
            var device = Android.Bluetooth.BluetoothAdapter.DefaultAdapter?.GetRemoteDevice(_address);

            if (device == null)
            {
                throw new Exception($"Can not get remote device with address:\"{_address}\".");
            }
            var callback = new AndroidBluetoothGattCallback();

            _gatt = device.ConnectGatt(Android.App.Application.Context, autoConnect, callback);
        }
コード例 #32
0
        private void NotifyOnValueChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
        {
            var hexText = FindViewById<TextView>(Resource.Id.ReceivedNotificationHex);
            var stringText = FindViewById<TextView>(Resource.Id.ReceivedNotificationString);

            var receivedBytes = characteristic.GetValue();

            RunOnUiThread(() =>
            {
                hexText.SetText(BitConverter.ToString(receivedBytes), TextView.BufferType.Normal);
                stringText.SetText(Encoding.ASCII.GetString(receivedBytes), TextView.BufferType.Normal);
            });
        }
コード例 #33
0
ファイル: BleGattCallback.cs プロジェクト: ytabuchi/BleSample
        // �ڑ��󋵂��ω��������ɔ��΂��郁�\�b�h
        public override void OnConnectionStateChange(BluetoothGatt gatt, [GeneratedEnum] GattStatus status, [GeneratedEnum] ProfileState newState)
        {
            base.OnConnectionStateChange(gatt, status, newState);

            if (newState == ProfileState.Connected)
            {
                // �ڑ���ԂɂȂ�����T�[�r�X���������
                // �T�[�r�X�����‚�������OnServicesDiscovered������
                gatt.DiscoverServices();
            }
            else if(newState == ProfileState.Disconnected)
            {
                //�|�b�v�A�b�v�Ȃǂ�o���āA�C�ӂ�Activity�Ɉړ�����Ȃǂ��Ă�������
            }
        }
 public void Dispose()
 {
     try
     {
         if (_gatt != null)
         {
             _gatt.Close();
             _gatt = null;
         }
     }
     catch (Exception exception)
     {
         Xamarin.Forms.Internals.Log.Warning("Dispose::Exception", exception.Message);
     }
 }
コード例 #35
0
 public void Dispose()
 {
     try
     {
         if (_gatt != null)
         {
             _gatt.Close();
             _gatt = null;
         }
     }
     catch (Exception exception)
     {
         Log.Warning("Dispose::Exception", exception.Message);
     }
 }
        public void Connect(bool autoConnect = false)
        {
            var device = AndroidBluetooth.BluetoothAdapter.DefaultAdapter?.GetRemoteDevice(_address);

            if (device == null)
            {
                throw new Exception($"Can not get remote device with address:\"{_address}\".");
            }
            var callback = new AndroidBluetoothGattCallback();

            callback.OnConnectionStateChangeOccured += Callback_OnConnectionStateChangeOccured;
            callback.OnServicesAlreadyDiscovered    += Callback_OnServicesAlreadyDiscovered;
            callback.OnCharacteristicAlreadyChanged += Callback_OnCharacteristicAlreadyChanged;
            _gatt = device.ConnectGatt(Android.App.Application.Context, autoConnect, callback);
        }
コード例 #37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothLE.Droid.Device"/> class.
        /// </summary>
        /// <param name="nativeDevice">Native device.</param>
        /// <param name="gatt">Native Gatt.</param>
        /// <param name="callback">Callback.</param>
        /// <param name="rssi">Rssi.</param>
        /// <param name="scanRecord">scanRecord.</param>
        public Device(BluetoothDevice nativeDevice, BluetoothGatt gatt, GattCallback callback, int rssi, byte[] scanRecord)
        {
            _nativeDevice = nativeDevice;
            _gatt = gatt;
            _callback = callback;
            _scanRecord = scanRecord;
            _rssi = rssi;
            _id = DeviceIdFromAddress(_nativeDevice.Address);

            if (_callback != null)
            {
                _callback.ServicesDiscovered += ServicesDiscovered;
            }

            Services = new List<IService>();
        }
コード例 #38
0
        private void GattCallback_ServicesDiscoveredEvent(BluetoothGatt gatt)
        {
            foreach (var item in gatt.Services)
            {
                gattServices.Add(item.Uuid.ToString());

                System.Diagnostics.Debug.WriteLine($"�yService�zUUID:{item.Uuid}");
            }
            var arry = gattServices.ToArray();

            // Main Thread�ŏ���������B
            RunOnUiThread(() =>
            {
                listView.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, arry);
            });
        }
コード例 #39
0
 public override void OnConnectionStateChange(ABluetooth.BluetoothGatt gatt, ABluetooth.GattStatus status, ABluetooth.ProfileState newState)
 {
     System.Diagnostics.Debug.WriteLine($"ConnectionStateChanged {status} {newState}");
     _owner.ConnectionStateChanged?.Invoke(_owner, new ConnectionStateEventArgs {
         Status = status, State = newState
     });
     if (newState == ABluetooth.ProfileState.Connected)
     {
         if (!_owner._servicesDiscovered)
         {
             gatt.DiscoverServices();
         }
     }
     else
     {
         _owner.Device.OnGattServerDisconnected();
     }
 }
コード例 #40
0
        public override void OnCharacteristicRead(bt.BluetoothGatt gatt, bt.BluetoothGattCharacteristic characteristic, [GeneratedEnum] bt.GattStatus status)
        {
            base.OnCharacteristicRead(gatt, characteristic, status);

            this.CharacteristicRead?.Invoke(this, new CharacteristicValueChangedEventArgs(gatt, characteristic, status));

            byte[] value = characteristic.GetValue();

            var myChar = this.ServicesById[characteristic.Service.Uuid].CharacteristicsById[characteristic.Uuid];

            // If the system architecture is little-endian (that is, little end first),
            // reverse the byte array.
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(value);
            }

            myChar.GetValueCompletionSource?.SetResult(value);
            myChar.GetValueCompletionSource = null;
        }
コード例 #41
0
		public Characteristic (BluetoothGattCharacteristic nativeCharacteristic, BluetoothGatt gatt, GattCallback gattCallback)
		{
			this._nativeCharacteristic = nativeCharacteristic;
			this._gatt = gatt;
			this._gattCallback = gattCallback;

			if (this._gattCallback != null) {
				// wire up the characteristic value updating on the gattcallback
				this._gattCallback.CharacteristicValueUpdated += (object sender, CharacteristicReadEventArgs e) => {
					// it may be other characteristics, so we need to test
					if(e.Characteristic.ID == this.ID) {
						// update our underlying characteristic (this one will have a value)
						//TODO: is this necessary? probably the underlying reference is the same.
						//this._nativeCharacteristic = e.Characteristic;

						this.ValueUpdated (this, e);
					}
				};
			}
		}
コード例 #42
0
        private void GattCallback_CharacteristicReadEvent(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
        {
            System.Diagnostics.Debug.WriteLine($"�yGattCallback_CharacteristicReadEvent�z:{gatt},{characteristic},{status}");

            // �K�v�ɉ����ăX�e�[�^�X�ɂ�菈���𕪊�
            switch (status)
            {
                case GattStatus.ConnectionCongested:
                    break;
                case GattStatus.Failure:
                    break;
                case GattStatus.InsufficientAuthentication:
                    break;
                case GattStatus.InsufficientEncryption:
                    break;
                case GattStatus.InvalidAttributeLength:
                    break;
                case GattStatus.InvalidOffset:
                    break;
                case GattStatus.ReadNotPermitted:
                    break;
                case GattStatus.RequestNotSupported:
                    break;
                case GattStatus.Success:
                    System.Diagnostics.Debug.WriteLine($"�ySuccess�z:{gatt},{characteristic},{status}");

                    var descs = characteristic.Descriptors;
                    foreach (var item in descs)
                    {
                        System.Diagnostics.Debug.WriteLine($"{item.Uuid},{item.Permissions}");
                    }

                    break;
                case GattStatus.WriteNotPermitted:
                    break;
                default:
                    break;
            }
        }
コード例 #43
0
		public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState)
		{
			Console.WriteLine ("OnConnectionStateChange: ");

			//TODO: need to pull the cached RSSI in here, or read it (requires the callback)
            var device = _adapter.DiscoveredDevices.Find(gatt.Device);
            if (device == null)
            {
                Debug.WriteLine(string.Format("Device {0} has not been discovered yet.", gatt.Device.Name));
                device = new Device(gatt.Device, gatt, this, 0);
                _adapter.DiscoveredDevices.Add(device);
            }

            switch (newState)
            {
                // disconnected
                case ProfileState.Disconnected:
                    Console.WriteLine("Disconnected.");
                    device.Disconnect();
                    OnDeviceDisconnected(device);
                    break;
                // connecting
                case ProfileState.Connecting:
                    Console.WriteLine("Connecting");
                    device.SetState(DeviceState.Connecting);
                    break;
                // connected
                case ProfileState.Connected:
                    Console.WriteLine("Connected");
                    device.SetState(DeviceState.Connected);
                    OnDeviceConnected(device);
                    break;
                // disconnecting
                case ProfileState.Disconnecting:
                    Console.WriteLine("Disconnecting");
                    device.SetState(DeviceState.Disconnected);
                    break;
            }
		}
コード例 #44
0
ファイル: GattCallback.cs プロジェクト: yelkrebb/XamTest-
		public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState)
		{
			Console.WriteLine ("OnConnectionStateChange: ");
			base.OnConnectionStateChange (gatt, status, newState);

			//TODO: need to pull the cached RSSI in here, or read it (requires the callback)
			Device device = new Device (gatt.Device, gatt, this, 0);

			switch (newState) {
			// disconnected
			case ProfileState.Disconnected:
				Console.WriteLine ("disconnected");
					if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
				{
					Console.WriteLine("Changing connection priority to balanced");
					gatt.RequestConnectionPriority(BluetoothGatt.ConnectionPriorityBalanced);
				}
				this.DeviceDisconnected (this, new DeviceConnectionEventArgs () { Device = device });
				break;
				// connecting
			case ProfileState.Connecting:
				Console.WriteLine ("Connecting");
				break;
				// connected
			case ProfileState.Connected:
				Console.WriteLine ("Connected");
					if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
				{
					Console.WriteLine("Changing connection priority to high");
					gatt.RequestConnectionPriority(BluetoothGatt.ConnectionPriorityHigh);
				}
				this.DeviceConnected (this, new DeviceConnectionEventArgs () { Device = device });
				break;
				// disconnecting
			case ProfileState.Disconnecting:
				Console.WriteLine ("Disconnecting");
				break;
			}
		}
コード例 #45
0
        private void GattCallback_ServicesDiscoveredEvent(BluetoothGatt gatt)
        {
            // �󂯎����UUID�ɐڑ����ăL�����N�^���X�e�B�b�N��擾
            var service = gatt.GetService(Java.Util.UUID.FromString(serviceUuid));
            var characteristics = service.Characteristics;

            foreach (var item in characteristics)
            {
                gattCharacteristics.Add(new TableItem {
                    Text1 = "CharacteristicName",
                    Text2 = item.Uuid.ToString(),
                    Text3 = item.Properties.ToString(),
                    Text4 = item.WriteType.ToString() });
                //gattCharacteristics.Add(item.Uuid.ToString());
            }
            //var arry = gattCharacteristics.ToArray();

            // Main Thread�ŏ���������B
            RunOnUiThread(() =>
            {
                //listView.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, arry);
                listView.Adapter = new CharacteristicsListAdapter(this, gattCharacteristics);
            });
        }
コード例 #46
0
        public override void OnCharacteristicWrite(bt.BluetoothGatt gatt, bt.BluetoothGattCharacteristic characteristic, [GeneratedEnum] bt.GattStatus status)
        {
            base.OnCharacteristicWrite(gatt, characteristic, status);

            this.CharacteristicWrite?.Invoke(this, new CharacteristicValueChangedEventArgs(gatt, characteristic, status));
        }
コード例 #47
0
 public override void OnDescriptorRead(ABluetooth.BluetoothGatt gatt, ABluetooth.BluetoothGattDescriptor descriptor, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"DescriptorRead {descriptor.Uuid} {status}");
     _owner._descriptorReadHandle.Set();
 }
コード例 #48
0
 public override void OnCharacteristicChanged(ABluetooth.BluetoothGatt gatt, ABluetooth.BluetoothGattCharacteristic characteristic)
 {
     System.Diagnostics.Debug.WriteLine($"CharacteristicChanged {characteristic.Uuid}");
     _owner.CharacteristicChanged?.Invoke(this, characteristic.Uuid);
 }
コード例 #49
0
 public override void OnCharacteristicWrite(ABluetooth.BluetoothGatt gatt, ABluetooth.BluetoothGattCharacteristic characteristic, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"CharacteristicWrite {characteristic.Uuid} {status}");
     _owner._characteristicWriteHandle.Set();
 }
コード例 #50
0
 private void PlatformInit()
 {
     _gattCallback = new GattCallback(this);
     _gatt         = ((ABluetooth.BluetoothDevice)Device).ConnectGatt(Android.App.Application.Context, true, _gattCallback, ABluetooth.BluetoothTransports.Le);
 }
コード例 #51
0
 public override void OnMtuChanged(ABluetooth.BluetoothGatt gatt, int mtu, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"OnMtuChanged Status:{status} Size:{mtu}");
     _owner.Mtu = mtu;
     base.OnMtuChanged(gatt, mtu, status);
 }
コード例 #52
0
 public ConnectionStateChangeEventArgs(bt.BluetoothGatt gatt, bt.GattStatus status, bt.ProfileState newState)
 {
     Gatt     = gatt;
     Status   = status;
     NewState = newState;
 }
コード例 #53
0
 public override void OnPhyUpdate(ABluetooth.BluetoothGatt gatt, ABluetooth.LE.ScanSettingsPhy txPhy, ABluetooth.LE.ScanSettingsPhy rxPhy, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"PhyUpdate TX:{txPhy} RX:{rxPhy} Status:{status}");
 }
コード例 #54
0
 public CharacteristicChangedEventArgs(bt.BluetoothGatt gatt, bt.BluetoothGattCharacteristic characteristic)
 {
     this.Gatt           = gatt;
     this.Characteristic = characteristic;
 }
コード例 #55
0
 public ServicesDiscoveredEventArgs(bt.BluetoothGatt gatt, bt.GattStatus status)
 {
     Gatt   = gatt;
     Status = status;
 }
コード例 #56
0
        public override void OnCharacteristicChanged(bt.BluetoothGatt gatt, bt.BluetoothGattCharacteristic characteristic)
        {
            base.OnCharacteristicChanged(gatt, characteristic);

            CharacteristicChanged?.Invoke(this, new CharacteristicChangedEventArgs(gatt, characteristic));
        }
コード例 #57
0
 public override void OnServicesDiscovered(ABluetooth.BluetoothGatt gatt, ABluetooth.GattStatus status)
 {
     System.Diagnostics.Debug.WriteLine($"ServicesDiscovered {status}");
     _owner._servicesDiscoveredHandle.Set();
 }
コード例 #58
0
 internal BluetoothRemoteGATTServer(BluetoothDevice device, ABluetooth.BluetoothDevice bluetoothDevice) : this(device)
 {
     _gattCallback = new GattCallback(this);
     NativeGatt    = bluetoothDevice.ConnectGatt(Android.App.Application.Context, false, _gattCallback);
 }
コード例 #59
0
 private void PlatformInit()
 {
     _gattCallback = new GattCallback(this);
     _gatt         = ((ABluetooth.BluetoothDevice)Device).ConnectGatt(Android.App.Application.Context, false, _gattCallback);
 }
コード例 #60
0
 public CharacteristicValueChangedEventArgs(bt.BluetoothGatt gatt, bt.BluetoothGattCharacteristic characteristic, bt.GattStatus status)
 {
     this.Gatt           = gatt;
     this.Characteristic = characteristic;
     this.Status         = status;
 }