Gatt callback to handle Gatt events.
Inheritance: Android.Bluetooth.BluetoothGattCallback
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothLE.Droid.Adapter"/> class.
        /// </summary>
        public Adapter()
        {
            var appContext = Android.App.Application.Context;

            _manager = (BluetoothManager)appContext.GetSystemService(Context.BluetoothService);
            _adapter = _manager.Adapter;

            _callback = new GattCallback();
            _callback.DeviceConnected    += BluetoothGatt_DeviceConnected;
            _callback.DeviceDisconnected += BluetoothGatt_DeviceDisconnected;

            _advertiseCallback = new AdvertiseCallback();
            _advertiseCallback.AdvertiseStartFailed  += BluetoothGatt_AdvertiseStartFailed;
            _advertiseCallback.AdvertiseStartSuccess += Bluetooth_AdvertiseStartSuccess;

            var callback = new GattServerCallback();

            _gattServer        = _manager.OpenGattServer(appContext, callback);
            callback.Server    = _gattServer;
            _broadcastListener = new BroadcastListener();

            CharacteristicsFactory = new CharacteristicsFactory();
            ServiceFactory         = new ServiceFactory();

            PeripheralStateChanged = _broadcastListener.StateUpdatedSubject.Select(state =>
            {
                if (state == ManagerState.PoweredOn)
                {
                    if (_adapter.BluetoothLeAdvertiser == null)
                    {
                        return(ManagerState.Unsupported);
                    }
                    if (!_adapter.IsMultipleAdvertisementSupported)
                    {
                        return(ManagerState.PartialSupport);
                    }
                }
                return(state);
            }).AsObservable();

            CentralStateChanged = _broadcastListener.StateUpdatedSubject.Select(state =>
            {
                if (state == ManagerState.PoweredOn)
                {
                    if (_adapter.BluetoothLeScanner == null)
                    {
                        return(ManagerState.Unsupported);
                    }
                    if (!(_adapter.IsOffloadedFilteringSupported && _adapter.IsOffloadedScanBatchingSupported))
                    {
                        return(ManagerState.PartialSupport);
                    }
                }

                return(state);
            }).AsObservable();

            _peripheralStateDisposable = PeripheralStateChanged.Subscribe(state => _peripheralState = state);
            _centralStateDisposable    = CentralStateChanged.Subscribe(state => _centralState = state);
        }
Exemple #2
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 ObservableCollection <ICharacteristic>();
        }
        /// <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>();
        }
		/// <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>();
		}
        /// <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;
            }
        }
		/// <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;
			}
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothLE.Droid.Adapter"/> class.
        /// </summary>
        public Adapter()
        {
            var appContext = Android.App.Application.Context;
            _manager = (BluetoothManager)appContext.GetSystemService("bluetooth");
            _adapter = _manager.Adapter;

            _callback = new GattCallback();
            _callback.DeviceConnected += BluetoothGatt_DeviceConnected;
            _callback.DeviceDisconnected += BluetoothGatt_DeviceDisconnected;

            ConnectedDevices = new List<IDevice>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothLE.Droid.Adapter"/> class.
        /// </summary>
        public Adapter()
        {
            var appContext = Android.App.Application.Context;

            _manager = (BluetoothManager)appContext.GetSystemService("bluetooth");
            _adapter = _manager.Adapter;

            _callback = new GattCallback();
            _callback.DeviceConnected    += BluetoothGatt_DeviceConnected;
            _callback.DeviceDisconnected += BluetoothGatt_DeviceDisconnected;

            ConnectedDevices = new List <IDevice>();
        }
Exemple #9
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  += OnCharacteristicValueUpdated;
                _callback.CharacteristicWriteComplete += OnCharacteristicWriteComplete;
                _callback.DescriptorWriteComplete     += OnDescriptorWriteComplete;
            }
        }
Exemple #10
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>
        public Device(BluetoothDevice nativeDevice, BluetoothGatt gatt, GattCallback callback, int rssi)
        {
            _nativeDevice = nativeDevice;
            _gatt         = gatt;
            _callback     = callback;

            _rssi = rssi;
            _id   = DeviceIdFromAddress(_nativeDevice.Address);

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

            Services = new List <IService>();
        }
        /// <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>();
        }
Exemple #12
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>
        public Device(BluetoothDevice nativeDevice, BluetoothGatt gatt, GattCallback callback, int rssi)
        {
            _nativeDevice = nativeDevice;
            _gatt         = gatt;
            _callback     = callback;

            Rssi = rssi;
            Id   = DeviceIdFromAddress(_nativeDevice.Address);

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

            _advertismentData = new Dictionary <Guid, byte[]>();
            Services          = new List <IService>();
        }