示例#1
0
 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)));
     }
 }
示例#2
0
 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);
     }
 }
示例#3
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);
         }
     }
 }
示例#4
0
        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);
             * }*/
        }
示例#5
0
 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));
     }
 }
示例#6
0
        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);
                }
            }
        }
示例#7
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");
            }
        }