Task <GattService> DoGetPrimaryService(BluetoothUuid service)
        {
            _servicesDiscoveredHandle.WaitOne();
            ABluetooth.BluetoothGattService nativeService = NativeGatt.GetService(service);

            return(Task.FromResult(nativeService is null ? null : new GattService(Device, nativeService)));
        }
예제 #2
0
        async Task <GattService> PlatformGetPrimaryService(BluetoothUuid service)
        {
            await WaitForServiceDiscovery();

            ABluetooth.BluetoothGattService nativeService = _gatt.GetService(service);

            return(nativeService is null ? null : new GattService(Device, nativeService));
        }
예제 #3
0
        internal GattService(BluetoothDevice device, ABluetooth.BluetoothGattService service) : this(device)
        {
            if (service is null)
            {
                throw new ArgumentNullException("service");
            }

            NativeService = service;
        }
        public BluetoothGattService CreateService()
        {
            var serviceUuid = UUID.FromString(ServiceUuid);
            var service = new BluetoothGattService(serviceUuid, GattServiceType.Primary);

            service.AddCharacteristic(new BluetoothGattCharacteristic(UUID.FromString(WriteCharacteristic),
                GattProperty.WriteNoResponse, GattPermission.Write));

            return service;
        }
예제 #5
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>();
		}
예제 #6
0
        public BluetoothService(bt.BluetoothGattService gattService, BluetoothDevice device)
        {
            this.GattService = gattService;
            this.Device      = device;

            Guid id = new Guid(GattService.Uuid.ToString());

            this.Id = id;

            BluetoothCharacteristic characteristic;

            foreach (var gattCharacteristic in gattService.Characteristics)
            {
                characteristic = new BluetoothCharacteristic(gattCharacteristic, this);

                CharacteristicsById[gattCharacteristic.Uuid] = characteristic;
            }
        }
예제 #7
0
        public BleServer(Context ctx)
        {
            _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);
            _bluetoothAdapter = _bluetoothManager.Adapter;

            _bluettothServerCallback = new BleGattServerCallback();
            _bluetoothServer = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback);

            var service = new BluetoothGattService(UUID.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"),
                GattServiceType.Primary);
            _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f2"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);
            _characteristic.AddDescriptor(new BluetoothGattDescriptor(UUID.FromString("28765900-7498-4bd4-aa9e-46c4a4fb7b07"),
                    GattDescriptorPermission.Read | GattDescriptorPermission.Write));

            service.AddCharacteristic(_characteristic);

            _bluetoothServer.AddService(service);

            _bluettothServerCallback.CharacteristicReadRequest += _bluettothServerCallback_CharacteristicReadRequest;
            _bluettothServerCallback.NotificationSent += _bluettothServerCallback_NotificationSent;

            Console.WriteLine("Server created!");

            BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser;

            var builder = new AdvertiseSettings.Builder();
            builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
            builder.SetConnectable(true);
            builder.SetTimeout(0);
            builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);
            AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
            dataBuilder.SetIncludeDeviceName(true);
            //dataBuilder.AddServiceUuid(ParcelUuid.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"));
            dataBuilder.SetIncludeTxPowerLevel(true);

            myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback());
        }
 public override void OnServiceAdded(ProfileState status, BluetoothGattService service)
 {
     Debug.WriteLine("Added service " + service.Uuid);
     var handler = ServiceAdded;
     if (handler != null) handler(status, service);
 }
예제 #9
0
		public Service (BluetoothGattService nativeService, BluetoothGatt gatt, GattCallback _gattCallback)
		{
			this._nativeService = nativeService;
			this._gatt = gatt;
			this._gattCallback = _gattCallback;
		}
예제 #10
0
 public Service(BluetoothGattService nativeService, BluetoothGatt gatt, IGattCallback gattCallback)
 {
     _nativeService = nativeService;
     _gatt = gatt;
     _gattCallback = gattCallback;
 }