public GattDescriptor(IGattCharacteristic characteristic, GattContext context, BluetoothGattDescriptor native) : base(characteristic, native.Uuid.ToGuid()) { this.context = context; this.native = native; }
public GattServer() { this.manager = (BluetoothManager)Application.Context.GetSystemService(Context.BluetoothService); this.adCallbacks = new AdvertisementCallbacks(); this.context = new GattContext(); this.runningSubj = new Subject <bool>(); }
public GattService(GattContext context, IGattServer server, Guid uuid, bool primary) : base(server, uuid, primary) { this.context = context; this.Native = new BluetoothGattService( UUID.FromString(uuid.ToString()), primary ? GattServiceType.Primary : GattServiceType.Secondary ); }
public GattService(IDevice device, GattContext context, BluetoothGattService native) : base(device, native.Uuid.ToGuid(), native.Type == GattServiceType.Primary) { this.context = context; this.native = native; }
public GattCharacteristic(IGattService service, GattContext context, BluetoothGattCharacteristic native) : base(service, native.Uuid.ToGuid(), (CharacteristicProperties)(int)native.Properties) { this.context = context; this.native = native; }
public Device(BluetoothManager manager, BluetoothDevice native, GattCallbacks callbacks) : base(native.Name, ToDeviceId(native.Address)) { this.context = new GattContext(native, callbacks); this.manager = manager; this.connSubject = new Subject <ConnectionStatus>(); }
public Device(BluetoothManager manager, BluetoothDevice native, GattCallbacks callbacks, TaskScheduler scheduler) : base(native.Name, ToDeviceId(native.Address)) { this.context = new GattContext(native, callbacks); this.manager = manager; this.scheduler = scheduler; // this is the thread that the device was scanned on (required by some devices) this.connSubject = new Subject <ConnectionStatus>(); }
public GattCharacteristic(GattContext context, IGattService service, Guid uuid, CharacteristicProperties properties, GattPermissions permissions) : base(service, uuid, properties, permissions) { this.context = context; this.subscribers = new Dictionary <string, IDevice>(); this.Native = new BluetoothGattCharacteristic( uuid.ToUuid(), properties.ToNative(), permissions.ToNative() ); this.NotificationDescriptor = new BluetoothGattDescriptor( NotifyDescriptorId.ToUuid(), GattDescriptorPermission.Write | GattDescriptorPermission.Read ); this.Native.AddDescriptor(this.NotificationDescriptor); }
public override IObservable<object> Connect() { return Observable.Create<object>(ob => { var cancelSrc = new CancellationTokenSource(); IDisposable connected = null; if (this.Status == ConnectionStatus.Connected) { ob.Respond(null); } else { connected = this .WhenStatusChanged() .Take(1) .Where(x => x == ConnectionStatus.Connected) .Subscribe(_ => ob.Respond(null)); if (this.Status != ConnectionStatus.Connecting) { try { ob.OnNext(ConnectionStatus.Connecting); var conn = this.native.ConnectGatt(Application.Context, false, this.callbacks); this.context = new GattContext(conn, this.callbacks); switch (AndroidConfig.ConnectionThread) { case ConnectionThread.MainThread: Application.SynchronizationContext.Post(_ => { conn.Connect(); }, null); break; case ConnectionThread.ScanThread: Task.Factory.StartNew( () => conn.Connect(), // TODO: if this crashes, need to junk out the observable // this could still fire even if we cancel it thereby tying up the connection cancelSrc.Token, TaskCreationOptions.None, this.scheduler ); break; case ConnectionThread.Default: default: conn.Connect(); break; } } catch (Exception ex) { ob.OnNext(ConnectionStatus.Disconnected); ob.OnError(ex); } } } return () => { connected?.Dispose(); cancelSrc.Dispose(); }; }); }
public GattReliableWriteTransaction(GattContext context) { this.context = context; this.context.Gatt.BeginReliableWrite(); }