Exemplo n.º 1
0
        /// <summary>
        ///  Add a service (and it's included services, characteristics, and descriptors) to the lists
        /// </summary>
        /// <param name="service">The service to add</param>
        private async Task AddService(GattDeviceService service)
        {
            if (!serviceObjects.Contains(service))
            {
                GattDeviceServicesResult res = await service.GetIncludedServicesAsync();

                if (res.Status == GattCommunicationStatus.Success)
                {
                    foreach (GattDeviceService s in res.Services)
                    {
                        await AddService(s);
                    }
                }
                GattCharacteristicsResult charRes = await service.GetCharacteristicsAsync();

                if (charRes.Status == GattCommunicationStatus.Success)
                {
                    foreach (GattCharacteristic c in charRes.Characteristics)
                    {
                        GattDescriptorsResult descRes = await c.GetDescriptorsAsync();

                        if (descRes.Status == GattCommunicationStatus.Success)
                        {
                            foreach (GattDescriptor d in descRes.Descriptors)
                            {
                                descriptorObjects.Add(d);
                            }
                        }
                        characteristicObjects.Add(c);
                    }
                }
                serviceObjects.Add(service);
            }
        }
        private async Task GetAllIncludedServices()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("ObservableGattDeviceService::getAllIncludedServices: ");
            sb.Append(name);

            try
            {
                var result = await service.GetIncludedServicesAsync(Services.SettingsServices.SettingsService.Instance.UseCaching?BluetoothCacheMode.Cached : BluetoothCacheMode.Uncached);

                if (result.Status == GattCommunicationStatus.Success)
                {
                    sb.Append(" - getAllIncludedServices found ");
                    sb.Append(result.Services.Count());
                    sb.Append(" services");
                    Debug.WriteLine(sb);
                }
                else if (result.Status == GattCommunicationStatus.Unreachable)
                {
                    sb.Append(" - getAllIncludedServices failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
                else if (result.Status == GattCommunicationStatus.ProtocolError)
                {
                    sb.Append(" - getAllIncludedServices failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("getAllIncludedServices: Exception - {0}" + ex.Message);
                Name += " - Exception: " + ex.Message;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the list of the GATT services included in a specific GATT service
        /// </summary>
        /// <returns>List of the included GATT services</returns>
        public async Task <IList <BleGattService> > GetServicesAsync(BleGattService service)
        {
            List <BleGattService> services = new List <BleGattService>();

            GattDeviceService        gatt_service = service.Context as GattDeviceService;
            GattDeviceServicesResult result       = await gatt_service.GetIncludedServicesAsync(BluetoothCacheMode.Uncached);

            foreach (GattDeviceService included_service in result.Services)
            {
                BleGattService ble_service = new BleGattService();
                ble_service.Name    = "";
                ble_service.Guid    = gatt_service.Uuid;
                ble_service.Context = included_service;

                services.Add(ble_service);
            }

            return(services);
        }