public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState) { Console.WriteLine ("OnConnectionStateChange: "); base.OnConnectionStateChange (gatt, status, newState); //TODO: need to pull the cached RSSI in here, or read it (requires the callback) Device device = new Device (gatt.Device, gatt, this, 0); switch (newState) { // disconnected case ProfileState.Disconnected: Console.WriteLine ("disconnected"); this.DeviceDisconnected (this, new DeviceConnectionEventArgs () { Device = device }); break; // connecting case ProfileState.Connecting: Console.WriteLine ("Connecting"); break; // connected case ProfileState.Connected: Console.WriteLine ("Connected"); this.DeviceConnected (this, new DeviceConnectionEventArgs () { Device = device }); break; // disconnecting case ProfileState.Disconnecting: Console.WriteLine ("Disconnecting"); break; } }
private void GattObserverOnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { if (_onRead != null) { _onRead(characteristic.GetValue(), status); } }
/// <Docs>GATT client</Docs> /// <summary> /// Raises the connection state change event. /// </summary> /// <param name="gatt">Gatt.</param> /// <param name="status">Status.</param> /// <param name="newState">New state.</param> public override void OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState) { base.OnConnectionStateChange(gatt, status, newState); if (status != GattStatus.Success) return; var device = new Device(gatt.Device, gatt, this, 0, null); switch (newState) { case ProfileState.Disconnected: device.State = DeviceState.Disconnected; try { gatt.Close(); gatt = null; } catch (Exception ex) { Debug.WriteLine("Unable to close connection to gatt. Exception: {0}", ex.Message); } finally { DeviceDisconnected(this, new DeviceConnectionEventArgs(device)); } break; case ProfileState.Connected: device.State = DeviceState.Connected; DeviceConnected(this, new DeviceConnectionEventArgs(device)); break; } }
public override void OnDescriptorRead (BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { base.OnDescriptorRead (gatt, descriptor, status); Console.WriteLine ("OnDescriptorRead: " + descriptor.ToString()); }
private void OnDescriptorWritten(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { if (status == GattStatus.Success && _onSubscribed != null) { _onSubscribed(true); } }
public override void OnServicesDiscovered (BluetoothGatt gatt, GattStatus status) { base.OnServicesDiscovered (gatt, status); Console.WriteLine ("OnServicesDiscovered: " + status.ToString ()); this.ServicesDiscovered (this, new ServicesDiscoveredEventArgs ()); }
/// <summary> /// Raises the services discovered event. /// </summary> /// <param name="gatt">Gatt.</param> /// <param name="status">Status.</param> public override void OnServicesDiscovered(BluetoothGatt gatt, GattStatus status) { base.OnServicesDiscovered(gatt, status); if (status != GattStatus.Success) return; ServicesDiscovered(this, EventArgs.Empty); }
public override void OnNotificationSent(BluetoothDevice device, GattStatus status) { base.OnNotificationSent(device, status); if (NotificationSent != null) { NotificationSent(this, new BleEventArgs() { Device = device }); } }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { base.OnDescriptorWrite(gatt, descriptor, status); Console.WriteLine("GattCallBack: OnDescriptorWrite: " + descriptor.ToString()); this.DescriptorWrite(this, new CharacteristicReadEventArgs() { Characteristic = new Characteristic(descriptor.Characteristic, gatt, this) }); }
public override void OnCharacteristicRead (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { base.OnCharacteristicRead (gatt, characteristic, status); Console.WriteLine ("GattCallBack: OnCharacteristicRead: " + characteristic.GetStringValue (0)); this.CharacteristicValueUpdated (this, new CharacteristicReadEventArgs () { Characteristic = new Characteristic (characteristic, gatt, this) } ); }
private void GattCallback_CharacteristicReadEvent(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { System.Diagnostics.Debug.WriteLine($"�yGattCallback_CharacteristicReadEvent�z:{gatt},{characteristic},{status}"); // �K�v�ɉ����ăX�e�[�^�X�ɂ�菈���� switch (status) { case GattStatus.ConnectionCongested: break; case GattStatus.Failure: break; case GattStatus.InsufficientAuthentication: break; case GattStatus.InsufficientEncryption: break; case GattStatus.InvalidAttributeLength: break; case GattStatus.InvalidOffset: break; case GattStatus.ReadNotPermitted: break; case GattStatus.RequestNotSupported: break; case GattStatus.Success: System.Diagnostics.Debug.WriteLine($"�ySuccess�z:{gatt},{characteristic},{status}"); var descs = characteristic.Descriptors; foreach (var item in descs) { System.Diagnostics.Debug.WriteLine($"{item.Uuid},{item.Permissions}"); } break; case GattStatus.WriteNotPermitted: break; default: break; } }
public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState) { Console.WriteLine ("OnConnectionStateChange: "); //TODO: need to pull the cached RSSI in here, or read it (requires the callback) var device = _adapter.DiscoveredDevices.Find(gatt.Device); if (device == null) { Debug.WriteLine(string.Format("Device {0} has not been discovered yet.", gatt.Device.Name)); device = new Device(gatt.Device, gatt, this, 0); _adapter.DiscoveredDevices.Add(device); } switch (newState) { // disconnected case ProfileState.Disconnected: Console.WriteLine("Disconnected."); device.Disconnect(); OnDeviceDisconnected(device); break; // connecting case ProfileState.Connecting: Console.WriteLine("Connecting"); device.SetState(DeviceState.Connecting); break; // connected case ProfileState.Connected: Console.WriteLine("Connected"); device.SetState(DeviceState.Connected); OnDeviceConnected(device); break; // disconnecting case ProfileState.Disconnecting: Console.WriteLine("Disconnecting"); device.SetState(DeviceState.Disconnected); break; } }
public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState) { Console.WriteLine ("OnConnectionStateChange: "); base.OnConnectionStateChange (gatt, status, newState); //TODO: need to pull the cached RSSI in here, or read it (requires the callback) Device device = new Device (gatt.Device, gatt, this, 0); switch (newState) { // disconnected case ProfileState.Disconnected: Console.WriteLine ("disconnected"); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Console.WriteLine("Changing connection priority to balanced"); gatt.RequestConnectionPriority(BluetoothGatt.ConnectionPriorityBalanced); } this.DeviceDisconnected (this, new DeviceConnectionEventArgs () { Device = device }); break; // connecting case ProfileState.Connecting: Console.WriteLine ("Connecting"); break; // connected case ProfileState.Connected: Console.WriteLine ("Connected"); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Console.WriteLine("Changing connection priority to high"); gatt.RequestConnectionPriority(BluetoothGatt.ConnectionPriorityHigh); } this.DeviceConnected (this, new DeviceConnectionEventArgs () { Device = device }); break; // disconnecting case ProfileState.Disconnecting: Console.WriteLine ("Disconnecting"); break; } }
public override void OnReliableWriteCompleted(BluetoothGatt gatt, GattStatus status) => this.ReliableWriteCompleted.OnNext(new GattEventArgs(gatt, status));
public override void OnServicesDiscovered(BluetoothGatt gatt, GattStatus status) { var handler = ServicesDiscovered; if (handler != null) handler(gatt, status); }
private void OnServicesDiscovered(BluetoothGatt gatt, GattStatus status) { Debug.WriteLine(status != GattStatus.Success ? "Failed to discover device services" : "Successfully discovered device services"); _onServiceDiscovery(status); }
public override void OnServicesDiscovered (BluetoothGatt gatt, GattStatus status) { base.OnServicesDiscovered (gatt, status); Console.WriteLine ("OnServicesDiscovered: " + status.ToString ()); //TODO: somehow, we need to tie this directly to the device, rather than for all // google's API deisgners are children. //TODO: not sure if this gets called after all services have been enumerated or not if(!this._parent._services.ContainsKey(gatt.Device)) this._parent.Services.Add(gatt.Device, this._parent._connectedDevices [gatt.Device].Services); else this._parent._services[gatt.Device] = this._parent._connectedDevices [gatt.Device].Services; this._parent.ServiceDiscovered (this, new ServiceDiscoveredEventArgs () { Gatt = gatt }); }
public override void OnReadRemoteRssi(BluetoothGatt gatt, int rssi, GattStatus status) => this.ReadRemoteRssi.OnNext(new GattRssiEventArgs(gatt, rssi, status));
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) => this.DescriptorWrite.OnNext(new GattDescriptorEventArgs(gatt, descriptor, status));
public override void OnServicesDiscovered (BluetoothGatt gatt, GattStatus status) { if (status == GattStatus.Success) { service.BroadcastUpdate (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED); } else { Log.Warn (BluetoothLeService.TAG, "onServicesDiscovered received: " + status); } }
public override void OnCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { base.OnCharacteristicWrite(gatt, characteristic, status); string hex = BitConverter.ToString(characteristic.GetValue()); Console.WriteLine("GattCallBack: OnCharacteristicWrite: " + hex.Replace("-", "")); }
public override void OnCharacteristicWrite (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { base.OnCharacteristicWrite (gatt, characteristic, status); if (null != this.CharacteristicValueWritten) { this.CharacteristicValueWritten(this, new CharacteristicReadEventArgs () { Characteristic = new Characteristic (characteristic, gatt, this) } ); } }
private void OnReceivedWriteResponce(BluetoothGattCharacteristic characteristic, GattStatus status) { ShowDialog(status != GattStatus.Success ? "Failed to write" : "Write success!"); }
private void OnConnectionStateChanged(BluetoothGatt gatt, GattStatus status, ProfileState newState) { switch (newState) { case ProfileState.Connected: Debug.WriteLine("Connected peripheral: " + gatt.Device.Name); _onConnection(ProfileState.Connected); break; case ProfileState.Disconnected: Debug.WriteLine("Disconnected peripheral: " + gatt.Device.Name); OnDisconnection(); break; case ProfileState.Connecting: Debug.WriteLine("Connecting peripheral: " + gatt.Device.Name); break; case ProfileState.Disconnecting: Debug.WriteLine("Disconnecting peripheral: " + gatt.Device.Name); break; } }
/// <summary> /// Raises the characteristic read event. /// </summary> /// <param name="gatt">Gatt.</param> /// <param name="characteristic">Characteristic.</param> /// <param name="status">Status.</param> public override void OnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { base.OnCharacteristicRead(gatt, characteristic, status); if (status != GattStatus.Success) return; var iChar = new Characteristic(characteristic, gatt, this); CharacteristicValueUpdated(this, new CharacteristicReadEventArgs(iChar)); }
public override void OnReliableWriteCompleted(BluetoothGatt gatt, GattStatus status) { base.OnReliableWriteCompleted(gatt, status); Mvx.Trace("OnReliableWriteCompleted: {0}", status); }
public override void OnCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { var handler = CharacteristicWritten; if (handler != null) handler(gatt, characteristic, status); }
public override void OnMtuChanged(BluetoothGatt gatt, int mtu, GattStatus status) => this.MtuChanged.OnNext(new MtuChangedEventArgs(mtu, gatt, status));
public override void OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState) { var handler = ConnectionStateChanged; if (handler != null) handler(gatt, status, newState); }
public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState) { Console.WriteLine ("OnConnectionStateChange: "); base.OnConnectionStateChange (gatt, status, newState); switch (newState) { // disconnected case ProfileState.Disconnected: Console.WriteLine ("disconnected"); //TODO/BUG: Need to remove this, but can't remove the key (uncomment and see bug on disconnect) // if (this._parent._connectedDevices.ContainsKey (gatt.Device)) // this._parent._connectedDevices.Remove (gatt.Device); this._parent.DeviceDisconnected (this, new DeviceConnectionEventArgs () { Device = gatt.Device }); break; // connecting case ProfileState.Connecting: Console.WriteLine ("Connecting"); break; // connected case ProfileState.Connected: Console.WriteLine ("Connected"); //TODO/BUGBUG: need to remove this when disconnected this._parent._connectedDevices.Add (gatt.Device, gatt); this._parent.DeviceConnected (this, new DeviceConnectionEventArgs () { Device = gatt.Device }); break; // disconnecting case ProfileState.Disconnecting: Console.WriteLine ("Disconnecting"); break; } }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { var handler = DescriptorWritten; if (handler != null) handler(gatt, descriptor, status); }
public override void OnConnectionStateChange (BluetoothGatt gatt, GattStatus status, ProfileState newState) { String intentAction; if (newState == ProfileState.Connected) { intentAction = BluetoothLeService.ACTION_GATT_CONNECTED; BluetoothLeService.mConnectionState = State.Connected; service.BroadcastUpdate (intentAction); Log.Info (BluetoothLeService.TAG, "Connected to GATT server."); // Attempts to discover services after successful connection. Log.Info (BluetoothLeService.TAG, "Attempting to start service discovery:" + BluetoothLeService.mBluetoothGatt.DiscoverServices ()); } else if (newState == ProfileState.Disconnected) { intentAction = BluetoothLeService.ACTION_GATT_DISCONNECTED; BluetoothLeService.mConnectionState = State.Disconnected; Log.Info (BluetoothLeService.TAG, "Disconnected from GATT server."); service.BroadcastUpdate (intentAction); } }
public override void OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState) { base.OnConnectionStateChange(gatt, status, newState); IDevice device = null; if (status != GattStatus.Success) { Mvx.TaggedError("OnConnectionStateChange", "GattCallback error: {0}", status); DeviceConnectionError(this, new DeviceConnectionEventArgs(){ Device = device }); // We don't return. Allowing to fall-through to the SWITCH, which will assume a disconnect, close GATT and clean up. // The above error event handles the case where the error happened during a Connect call, which will close out any waiting asyncs. } else { Mvx.Trace("GattCallback state: {0}", newState.ToString()); } switch (newState) { // disconnected case ProfileState.Disconnected: if (DeviceOperationRegistry.TryGetValue(gatt.Device.Address, out device)) { Mvx.Trace("Disconnected by user"); //Found so we can remove it DeviceOperationRegistry.Remove(gatt.Device.Address); ConnectedDeviceRegistry.Remove(gatt.Device.Address); gatt.Close(); DeviceDisconnected(this, new DeviceConnectionEventArgs { Device = device }); break; } //connection must have been lost, bacause our device was not found in the registry but was still connected if (ConnectedDeviceRegistry.TryGetValue(gatt.Device.Address, out device)) { Mvx.Trace("Disconnected by lost connection"); ConnectedDeviceRegistry.Remove(gatt.Device.Address); gatt.Close(); DeviceConnectionLost(this, new DeviceConnectionEventArgs() { Device = device }); break; } gatt.Close(); // Close GATT regardless, else we can accumulate zombie gatts. Mvx.Trace("Disconnect. Device not found in registry. Not raising disconnect/lost event."); break; // connecting case ProfileState.Connecting: Mvx.Trace("Connecting"); break; // connected case ProfileState.Connected: Mvx.Trace("Connected"); //Try to find the device in the registry so that the same instance is updated if (DeviceOperationRegistry.TryGetValue(gatt.Device.Address, out device)) { ((Device)device).Update(gatt.Device, gatt, this); //Found so we can remove it DeviceOperationRegistry.Remove(gatt.Device.Address); } else { //only for on auto-reconnect (device is not in operation registry) device = new Device(gatt.Device, gatt, this, 0); } ConnectedDeviceRegistry[gatt.Device.Address] = device; DeviceConnected(this, new DeviceConnectionEventArgs() { Device = device }); break; // disconnecting case ProfileState.Disconnecting: Mvx.Trace("Disconnecting"); break; } }
public override void OnCharacteristicRead (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { if (status == GattStatus.Success) { service.BroadcastUpdate (BluetoothLeService.ACTION_DATA_AVAILABLE, characteristic); } }
public override void OnCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) => this.CharacteristicWrite.OnNext(new GattCharacteristicEventArgs(gatt, characteristic, status));