Beispiel #1
0
 public SampleService(BluetoothGatt gatt, BluetoothGattService service, GattDevice device) : base(gatt, service, device)
 {
     index = 0;
     Log.Debug(TAG, "SampleService(0x{0:X})", BlutoothService.GetAssignedNumber(service.Uuid));
     if (service != null)
     {
         nCharacteristics = service.Characteristics.Count;
         if (nCharacteristics > 0)
         {
             BluetoothGattCharacteristic characteristic = service.Characteristics[0];
             Log.Debug(TAG, "ReadCharacteristic(0x{0:X})", BlutoothService.GetAssignedNumber(characteristic.Uuid));
             gatt.ReadCharacteristic(characteristic);
         }
     }
 }
Beispiel #2
0
        public void EnumServices(Context ctx, string identifer)
        {
            BluetoothDevice device = mapDevices[identifer];

            if (device != null)
            {
                GattDevice gattdevice = new GattDevice(ctx, identifer);
                if (gatt != null)
                {
                    //gatt.Disconnect();
                    gatt.Close();   //or gatt.Connect() to re-connect to device
                    gatt.Dispose();
                }

                gatt = device.ConnectGatt(ctx, false, gattdevice);  //-> OnConnectionStateChange() -> DiscoverServices() -> OnServicesDiscovered() -> GattDevice.Initialize()
                if (gatt == null)
                {
                    Log.Error(TAG, string.Format("failed to connect to GATT server '{0}'", identifer));
                }
            }
        }
Beispiel #3
0
        protected static Java.Util.UUID CHAR_APPEARANCE  = Java.Util.UUID.FromString("00002A01-0000-1000-8000-00805f9b34fb");   //org.bluetooth.characteristic.gap.appearance

        public GenericAccessService(BluetoothGatt gatt, BluetoothGattService service, GattDevice device) : base(gatt, service, device)
        {
            if (service != null)
            {
                BluetoothGattCharacteristic characteristic = service.GetCharacteristic(CHAR_DEVICE_NAME);
                if (characteristic != null)
                {
                    gatt.ReadCharacteristic(characteristic);
                }
            }
        }
Beispiel #4
0
 public BlutoothService(BluetoothGatt gatt, BluetoothGattService service, GattDevice device)
 {
     this.gatt    = gatt;
     this.service = service;
     this.device  = device;
 }