Exemplo n.º 1
0
 internal GattService(CBPeripheral peripheral, PeripheralDelegate @delegate, Peripheral parent, CBService service)
 {
     this.peripheral = peripheral;
     this.@delegate  = @delegate;
     Peripheral      = parent;
     this.service    = service;
 }
Exemplo n.º 2
0
        public override void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
        {
            lock (_lock)
            {
                try
                {
                    if (error == null)
                    {
                        var characteristics = new List <GattCharacteristic>();
                        if (service.Characteristics != null)
                        {
                            foreach (var characteristic in service.Characteristics)
                            {
                                characteristics.Add(new GattCharacteristic(characteristic));
                            }
                        }

                        _discoverCompletionSource?.SetResult(characteristics);
                    }
                    else
                    {
                        _discoverCompletionSource?.SetResult(null);
                    }
                }
                catch (Exception)
                {
                    _discoverCompletionSource?.SetResult(null);
                }
            }
        }
Exemplo n.º 3
0
            public override void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
            {
                var descriptor = peripheral.ToDeviceDescriptor();

                if (error != null)
                {
                    _deviceManager.HandleDeviceCommunicationDiscoveredCharacteristicError(descriptor, error.LocalizedFailureReason, (d) =>
                    {
                        _centralManager.CancelPeripheralConnection(peripheral);
                    });
                    return;
                }

                var characteristic = service.Characteristics?.FirstOrDefault();

                if (characteristic != null)
                {
                    _deviceManager.HandleDeviceCommunicationDiscoveredCharacteristic(descriptor, (d) =>
                    {
                        peripheral.ReadValue(characteristic);
                    });
                }
                else
                {
                    _deviceManager.HandleIncorrectDevice(descriptor);
                    _centralManager.CancelPeripheralConnection(peripheral);
                }
            }
Exemplo n.º 4
0
 public Service(CBService service, IDevice device, CBCentralManager centralManager)
     : base(device)
 {
     _service        = service;
     _device         = device.NativeDevice as CBPeripheral;
     _centralManager = centralManager;
 }
Exemplo n.º 5
0
		public void SetPeripheralAndService (CBPeripheral peripheral, CBService service)
		{
			this._connectedPeripheral = peripheral;
			this._currentService = service;

			// discover the charactersistics
			this._connectedPeripheral.DiscoverCharacteristics(service);

			// should be named "DiscoveredCharacteristic"
			this._connectedPeripheral.DiscoverCharacteristic += (object sender, CBServiceEventArgs e) => {
				Console.WriteLine ("Discovered Characteristic.");
				foreach (CBService srv in ((CBPeripheral)sender).Services) {

					// if the service has characteristics yet
					if(srv.Characteristics != null) {
						foreach (var characteristic in service.Characteristics) {
							Console.WriteLine("Characteristic: " + characteristic.Description);

							this._characteristics.Add (characteristic);
							this.CharacteristicsTable.ReloadData();
						}
					}
				}
			};

			// when a descriptor is dicovered, reload the table.
			this._connectedPeripheral.DiscoveredDescriptor += (object sender, CBCharacteristicEventArgs e) => {
				foreach (var descriptor in e.Characteristic.Descriptors) {
					Console.WriteLine ("Characteristic: " + e.Characteristic.Value + " Discovered Descriptor: " + descriptor);	
				}
				// reload the table
				this.CharacteristicsTable.ReloadData();
			};

		}
Exemplo n.º 6
0
        internal BLEService(BLECBPeripheralWrapper peripheral, CBService service)
        {
            _peripheralReference = new WeakReference(peripheral);
            _service             = service;

            PeripheralWrapper.DiscoveredCharacteristic += OnDiscoveredCharacteristic;
        }
        internal Service(CBService nativeService, Device device, IBleCentralManagerDelegate bleCentralManagerDelegate) : this(device)
        {
            NativeService = nativeService;

            _device = device.NativeDevice as CBPeripheral;
            _bleCentralManagerDelegate = bleCentralManagerDelegate;
        }
Exemplo n.º 8
0
		public Service (CBService nativeService, CBPeripheral parentDevice )
		{
			this._nativeService = nativeService;
			this._parentDevice = parentDevice;


		}
Exemplo n.º 9
0
        public void Shutdown()
        {
            StopScanning();

            if (_service != null)
            {
                _service.Dispose();
                _service = null;
            }

            if (_peripheral != null)
            {
                _peripheral.Dispose();
                _peripheral = null;
            }

            if (_centralManager != null)
            {
                _centralManager.Dispose();
                _centralManager = null;
            }

            if (_dispatchQueue != null)
            {
                _dispatchQueue.Dispose();
                _dispatchQueue = null;
            }
        }
Exemplo n.º 10
0
 public Service(CBService service, IDevice device, IBleCentralManagerDelegate bleCentralManagerDelegate)
     : base(device)
 {
     _service = service;
     _device  = device.NativeDevice as CBPeripheral;
     _bleCentralManagerDelegate = bleCentralManagerDelegate;
 }
Exemplo n.º 11
0
    public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
    {
        CBService service = this._services [indexPath.Row];

        this.ServiceSelected(this, new ServiceSelectedEventArgs(service));
        tableView.DeselectRow(indexPath, true);
    }
Exemplo n.º 12
0
            public override void DiscoveredCharacteristic(CBPeripheral peripheral,
                                                          CBService service, NSError error)
            {
                if (monitor.disposed)
                {
                    return;
                }

                foreach (var characteristic in service.Characteristics)
                {
                    if (characteristic.UUID == HeartRateMeasurementCharacteristicUUID)
                    {
                        service.Peripheral.SetNotifyValue(true, characteristic);
                    }
                    else if (characteristic.UUID == BodySensorLocationCharacteristicUUID)
                    {
                        service.Peripheral.ReadValue(characteristic);
                    }
                    else if (characteristic.UUID == HeartRateControlPointCharacteristicUUID)
                    {
                        service.Peripheral.WriteValue(NSData.FromBytes((IntPtr)1, 1),
                                                      characteristic, CBCharacteristicWriteType.WithResponse);
                    }
                }
            }
Exemplo n.º 13
0
        public BLEService(CBService nativeService)
        {
            characteristics = new List <IBLECharacteristic> ();

            this.nativeService = nativeService;

            uuid = new UUID(nativeService.UUID.ToString(true));
        }
Exemplo n.º 14
0
 public override void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
 {
     System.Console.WriteLine ("Discovered characteristics of " + peripheral);
     foreach (var c in service.Characteristics) {
         Console.WriteLine (c.ToString ());
         peripheral.ReadValue (c);
     }
 }
Exemplo n.º 15
0
 public override void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
 {
     // Discover the Descriptors of the characteristics contained in service.Characteristics
     foreach (var characteristic in service.Characteristics)
     {
         peripheral.DiscoverDescriptors(characteristic);
     }
 }
Exemplo n.º 16
0
 public override void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
 {
     System.Console.WriteLine("Discovered characteristics of " + peripheral);
     foreach (var c in service.Characteristics)
     {
         Console.WriteLine(c.ToString());
         peripheral.ReadValue(c);
     }
 }
Exemplo n.º 17
0
        public Service(Guid uuid, bool isPrimary)
        {
            this.uuid     = uuid;
            NativeService = new CBMutableService(CBUUID.FromString(uuid.ToString()), isPrimary);

            var characteristics = new ObservableCollection <ICharacteristic>();

            characteristics.CollectionChanged += CharacteristicsOnCollectionChanged;
            Characteristics = characteristics;
        }
Exemplo n.º 18
0
 protected bool ServiceExists(CBService service)
 {
     foreach (var s in _services)
     {
         if (s.ID == Service.ServiceUuidToGuid(service.UUID))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 19
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BluetoothLE.iOS.Service"/> class.
		/// </summary>
		/// <param name="peripheral">The native peripheral.</param>
		/// <param name="service">The native service.</param>
		public Service(CBPeripheral peripheral, CBService service)
		{
			_peripheral = peripheral;
			_nativeService = service;

			_id = service.UUID.ToString().ToGuid();

			_peripheral.DiscoveredCharacteristic += DiscoveredCharacteristic;

			Characteristics = new List<ICharacteristic>();
		}
Exemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothLE.iOS.Service"/> class.
        /// </summary>
        /// <param name="peripheral">The native peripheral.</param>
        /// <param name="service">The native service.</param>
        public Service(CBPeripheral peripheral, CBService service)
        {
            _peripheral   = peripheral;
            NativeService = service;

            _id = service.UUID.ToString().ToGuid();

            _peripheral.DiscoveredCharacteristic += DiscoveredCharacteristic;

            Characteristics = new List <ICharacteristic>();
        }
Exemplo n.º 21
0
        protected bool ServiceExists(CBService service)
        {
            foreach (var s in _services)
            {
                if (s.ID == service.UUID.ToString().GuidFromAssignedNumber())
                {
                    return(true);
                }
            }

            return(false);
        }
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell(cellID);

            cell = cell ?? new UITableViewCell(UITableViewCellStyle.Default, cellID);

            CBService service = Services [indexPath.Row];

            cell.TextLabel.Text = service.Description;

            return(cell);
        }
Exemplo n.º 23
0
    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        UITableViewCell cell    = tableView.DequeueReusableCell(cellID);
        CBService       service = this._services [indexPath.Row];

        if (cell == null)
        {
            cell = new UITableViewCell(UITableViewCellStyle.Subtitle, cellID);
        }
        //TODO: Populate the cell with data from _services and/or _uuids.
        return(cell);
    }
        public void SetPeripheralAndService(CBPeripheral peripheral, CBService service)
        {
            connectedPeripheral = peripheral;

            connectedPeripheral.DiscoveredCharacteristic += (sender, e) => {
                HandleDiscoveredCharacteristic((CBPeripheral)sender, service);
            };

            // when a descriptor is dicovered, reload the table.
            connectedPeripheral.DiscoveredDescriptor += HandleDiscoveredDescriptor;

            // discover the charactersistics
            connectedPeripheral.DiscoverCharacteristics(service);
        }
Exemplo n.º 25
0
        bool ServiceEquals(CBService service)
        {
            if (!this.Service.UUID.Equals(service.UUID))
            {
                return(false);
            }

            if (!this.Peripherial.Identifier.Equals(service.Peripheral.Identifier))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 26
0
		public void SetPeripheralAndService (CBPeripheral peripheral, CBService service)
		{
			connectedPeripheral = peripheral;

			connectedPeripheral.DiscoveredCharacteristic += (sender, e) => {
				HandleDiscoveredCharacteristic((CBPeripheral)sender, service);
			};

			// when a descriptor is dicovered, reload the table.
			connectedPeripheral.DiscoveredDescriptor += HandleDiscoveredDescriptor;

			// discover the charactersistics
			connectedPeripheral.DiscoverCharacteristics(service);
		}
Exemplo n.º 27
0
        public BLEService(CBService nativeService)
        {
            _nativeService  = nativeService;
            Characteristics = new List <IBLECharacteristic>();

            Guid      = Guid.Parse(_nativeService.UUID.ToString());
            IsPrimary = _nativeService.Primary;

            foreach (var item in _nativeService.Characteristics)
            {
                var characteristic = new BLECharacteristic(item);
                Characteristics.Add(characteristic);
            }
        }
Exemplo n.º 28
0
		void HandleDiscoveredCharacteristic (CBPeripheral peripheral, CBService service)
		{
			Console.WriteLine ("Discovered Characteristic.");
			foreach (CBService srv in peripheral.Services) {
				// if the service has characteristics yet
				if (srv.Characteristics == null)
					continue;

				foreach (var characteristic in service.Characteristics) {
					Console.WriteLine("Characteristic: {0}", characteristic.Description);
					characteristics.Add (characteristic);
				}
				CharacteristicsTable.ReloadData();
			}
		}
Exemplo n.º 29
0
 public override void DiscoveredIncludedService(CBPeripheral peripheral, CBService service, NSError error)
 {
     client.completedInc += 1;
     peripheral.Delegate  = this;
     if (service.IncludedServices != null)
     {
         client.serviceObjects.AddRange(service.IncludedServices);
         client.charCallCount += service.IncludedServices.Count();
         foreach (var s in service.IncludedServices)
         {
             peripheral.DiscoverCharacteristics(null, s);
         }
     }
     client.allDiscovered();
 }
Exemplo n.º 30
0
 public override void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
 {
     client.completedChar += 1;
     peripheral.Delegate   = this;
     if (service.Characteristics != null)
     {
         client.descCallCount += service.Characteristics.Count();
         foreach (var characteristic in service.Characteristics)
         {
             client.characteristicObjects.Add(characteristic);
             peripheral.DiscoverDescriptors(characteristic);
         }
     }
     client.allDiscovered();
 }
Exemplo n.º 31
0
        //TODO Submit Bug to change the methid name to "DiscoveredCharacteristics" as this method will fire only when all the Characteristics are discovered
        public override void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
        {
            base.DiscoveredCharacteristic(peripheral, service, error);

            foreach (var item in service.Characteristics)
            {
                var characteristic = new BLECharacteristic(item);

                if (peripheral.Delegate == null)
                {
                    peripheral.Delegate = this;
                }

                characteristicList.Add(characteristic);
            }

            _deviceTaskCompletitionSource.CharacteristicDiscoveryTCS.SetResult(characteristicList);
        }
        void HandleDiscoveredCharacteristic(CBPeripheral peripheral, CBService service)
        {
            Console.WriteLine("Discovered Characteristic.");
            foreach (CBService srv in peripheral.Services)
            {
                // if the service has characteristics yet
                if (srv.Characteristics == null)
                {
                    continue;
                }

                foreach (var characteristic in service.Characteristics)
                {
                    Console.WriteLine("Characteristic: {0}", characteristic.Description);
                    characteristics.Add(characteristic);
                }
                CharacteristicsTable.ReloadData();
            }
        }
        public override void ServiceAdded(CBPeripheralManager peripheral, CBService service, NSError error)
        {
            if (error == null)
            {
                SensusServiceHelper.Get().Logger.Log("Added service.", LoggingLevel.Normal, GetType());

                try
                {
                    peripheral.StartAdvertising(new NSDictionary(CBAdvertisement.DataServiceUUIDsKey, NSArray.FromObjects(_probe.DeviceIdService.UUID)));
                }
                catch (Exception ex)
                {
                    SensusServiceHelper.Get().Logger.Log("Exception while starting advertising:  " + ex.Message, LoggingLevel.Normal, GetType());
                }
            }
            else
            {
                SensusServiceHelper.Get().Logger.Log("Error adding service:  " + error, LoggingLevel.Normal, GetType());
            }
        }
Exemplo n.º 34
0
            /// <summary>
            /// Occurs when a new characteristic is discovered for  aservice
            /// </summary>
            /// <param name="peripheral">Peripheral.</param>
            /// <param name="service">Service.</param>
            /// <param name="error">Error.</param>
            public override void DiscoveredCharacteristic(CBPeripheral peripheral,
                                                          CBService service, NSError error)
            {
                if (monitor.disposed)
                {
                    return;
                }

                foreach (var characteristic in service.Characteristics)
                {
                    Console.WriteLine($"discovered characteristic: {characteristic.UUID}");

                    // Right now limited to POC and Zephyr hear rate characteristics
                    if (characteristic.UUID == BluetoothIdentifiers.POCHeartRateMeasurementCharacteristicUUID ||
                        characteristic.UUID == BluetoothIdentifiers.ZephyrHeartRateCharacteristicUUID)
                    {
                        service.Peripheral.SetNotifyValue(true, characteristic);
                    }
                }
            }
Exemplo n.º 35
0
        public void DiscoveredCharacteristic(CBPeripheral peripheral, CBService service, NSError error)
        {
            Debug.WriteLine("Peripheral_DiscoveredCharacteristic");
            //var cbuuid = CBUUID.FromString(characteristicGuid);
            foreach (var characteristic in _service.Characteristics)
            {
                if (_characteristics.ContainsKey(characteristic.UUID))
                {
                    _characteristics[characteristic.UUID] = characteristic;
                }
                else
                {
                    _characteristics.Add(characteristic.UUID, characteristic);
                }
            }

            _connectionCompletionSource.SetResult(true);

            //BoardConnected?.Invoke(null);
            //BoardConnected?.Invoke(new OWBoard(_board));
        }
Exemplo n.º 36
0
        public void DiscoveredService(CBPeripheral peripheral, NSError error)
        {
            Debug.WriteLine($"Peripheral_DiscoveredService: {peripheral.Name}");

            CBService foundService = null;

            foreach (var service in peripheral.Services)
            {
                if (service.UUID == OWBoard.ServiceUUID.ToCBUUID())
                {
                    foundService = service;
                    break;
                }
            }

            if (foundService != null)
            {
                _service = foundService;
                _peripheral.DiscoverCharacteristics(_service);
            }
        }
Exemplo n.º 37
0
		protected bool ServiceExists(CBService service)
		{
			foreach (var s in this._services) {
				if (s.ID == Service.ServiceUuidToGuid(service.UUID))
					return true;
			}
			return false;
		}
Exemplo n.º 38
0
 public Service(CBService nativeService, CBPeripheral parentDevice)
 {
     NativeService = nativeService;
     ParentDevice = parentDevice;
 }
		public ServiceSelectedEventArgs (CBService service)
		{
			Service = service;
		}
Exemplo n.º 40
0
 public Service(CBService service, CBPeripheral device)
 {
     _service = service;
     _device = device;
 }
Exemplo n.º 41
0
		public override void DiscoveredCharacteristic (CBPeripheral peripheral, CBService service, NSError error)
		{
			if (disposed) {
				return;
			}

			foreach (var characteristic in service.Characteristics) {
				if (characteristic.UUID == HeartRateMeasurementCharacteristicUUID) {
					service.Peripheral.SetNotifyValue (true, characteristic);
				} else if (characteristic.UUID == BodySensorLocationCharacteristicUUID) {
					service.Peripheral.ReadValue (characteristic);
				} else if (characteristic.UUID == HeartRateControlPointCharacteristicUUID) {
					service.Peripheral.WriteValue (NSData.FromBytes ((IntPtr)1, 1),
						characteristic, CBCharacteristicWriteType.WithResponse);
				}
			}
		}