protected static void DumpServices(BluetoothGatt gatt)
 {
     foreach (BluetoothGattService service in gatt.Services)
     {
         Log.Debug(TAG, string.Format("UUID: '0x{0:X}'", BlutoothService.GetAssignedNumber(service.Uuid)));
     }
 }
 public void ReadNextCharacteristic()
 {
     index++;
     if (index < nCharacteristics)
     {
         BluetoothGattCharacteristic characteristic = service.Characteristics[index];
         Log.Debug(TAG, "ReadNextCharacteristic(0x{0:X})", BlutoothService.GetAssignedNumber(characteristic.Uuid));
         gatt.ReadCharacteristic(characteristic);
     }
     else
     {
         device.ReadNextService(gatt);
     }
 }
 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);
         }
     }
 }
        public override void OnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
        {
            Log.Debug(TAG, "OnCharacteristicRead(0x{0:X})", BlutoothService.GetAssignedNumber(characteristic.Uuid));
            if (sampleService != null)
            {
                sampleService.ReadCharacteristic(characteristic);
                sampleService.ReadNextCharacteristic();
            }

            /*if (BlutoothService.GetAssignedNumber(characteristic.Service.Uuid) == 0x1800)   //org.bluetooth.service.generic_access
             * {
             *  if (genericAccess != null)
             *      genericAccess.ReadCharacteristic(characteristic);
             * }*/
        }
 public void ReadCharacteristic(BluetoothGattCharacteristic characteristic)
 {
     byte[] value = characteristic.GetValue();
     if (value != null)
     {
         Log.Debug(TAG,
                   "service '0x{0:X}' - characteristic '0x{1:X}' - '{2}'",
                   BlutoothService.GetAssignedNumber(service.Uuid),
                   BlutoothService.GetAssignedNumber(characteristic.Uuid),
                   BitConverter.ToString(value));
     }
     else
     {
         Log.Debug(TAG,
                   "service '0x{0:X}' - characteristic '0x{1:X}' - 'empty'",
                   BlutoothService.GetAssignedNumber(service.Uuid),
                   BlutoothService.GetAssignedNumber(characteristic.Uuid));
     }
 }
        public void ReadCharacteristic(BluetoothGattCharacteristic characteristic)
        {
            if (BlutoothService.GetAssignedNumber(characteristic.Uuid) == 0x2A00)   //org.bluetooth.characteristic.gap.device_name
            {
                byte[] value = characteristic.GetValue();
                if (value != null)
                {
                    deviceName = BitConverter.ToString(value);
                }
            }

            if (BlutoothService.GetAssignedNumber(characteristic.Uuid) == 0x2A01)   //org.bluetooth.characteristic.gap.appearance
            {
                byte[] value = characteristic.GetValue();
                if (value != null)
                {
                    appearance = BitConverter.ToInt16(value, 0);
                }
            }
        }
        public virtual void ReadNextService(BluetoothGatt gatt)
        {
            index++;
            Log.Debug(TAG, "ReadNextService({0})", index);
            if (index < gatt.Services.Count)
            {
                BluetoothGattService service = gatt.Services[index];
                if (service != null)
                {
                    BlutoothService.Dump(service, gattServerName);

                    if (sampleService != null)
                    {
                        sampleService = null;
                    }

                    sampleService = new SampleService(gatt, service, this);
                }
            }
            else
            {
                Log.Debug(TAG, "ReadNextService finished");
            }
        }