com.polidea.rxandroidble2.RxBleConnection Java Examples
The following examples show how to use
com.polidea.rxandroidble2.RxBleConnection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java From Mi365Locker with GNU General Public License v3.0 | 9 votes |
@Override public void onScanResult(int callbackType, ScanResult result) { super.onScanResult(callbackType, result); BluetoothDevice newDevice = result.getDevice(); int newRssi = result.getRssi(); String device_name = newDevice.getName(); String device_address = newDevice.getAddress(); if(device_name == null) { return; } DeviceConnection dev = devices_connections.get(device_address); if(dev != null) { devicesAdapter.update(newDevice, newRssi, dev.getState()); } else { devicesAdapter.update(newDevice, newRssi, RxBleConnection.RxBleConnectionState.DISCONNECTED); } String mDeviceAddress = newDevice.getAddress(); add_device_to_attack(mDeviceAddress); }
Example #2
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 6 votes |
private static void glucoseRxCommon(final BaseGlucoseRxMessage glucose, final Ob1G5CollectionService parent, final RxBleConnection connection) { if (JoH.ratelimit("ob1-g5-also-read-raw", 20)) { //if (FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) { enqueueUniqueCommand(new SensorTxMessage(), "Also read raw"); // } } if (JoH.pratelimit("g5-tx-time-since", 7200) || glucose.calibrationState().warmingUp() || !DexSessionKeeper.isStarted()) { if (JoH.ratelimit("g5-tx-time-governer", 30)) { enqueueUniqueCommand(new TimeTxMessage(), "Periodic Query Time"); } } // TODO check firmware version if (glucose.calibrationState().readyForBackfill() && !parent.getBatteryStatusNow) { backFillIfNeeded(parent, connection); } processGlucoseRxMessage(parent, glucose); parent.updateLast(tsl()); parent.clearErrors(); }
Example #3
Source File: PendiqService.java From xDrip with GNU General Public License v3.0 | 6 votes |
private synchronized void onConnectionStateChange(RxBleConnection.RxBleConnectionState newState) { String connection_state = "Unknown"; switch (newState) { case CONNECTING: connection_state = "Connecting"; // connecting_time = JoH.tsl(); break; case CONNECTED: connection_state = "Connected"; break; case DISCONNECTING: connection_state = "Disconnecting"; break; case DISCONNECTED: connection_state = "Disconnected"; // JoH.releaseWakeLock(floatingWakeLock); break; } UserError.Log.d(TAG, connection_state); //static_connection_state = connection_state; // UserError.Log.d(TAG, "Bluetooth connection: " + static_connection_state); if (connection_state.equals("Disconnecting")) { //tryGattRefresh(); } }
Example #4
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 6 votes |
@SuppressLint("CheckResult") public static boolean doReset(Ob1G5CollectionService parent, RxBleConnection connection) { if (connection == null) return false; parent.msg("Hard Resetting Transmitter"); connection.writeCharacteristic(Control, nn(new ResetTxMessage().byteSequence)) .subscribe(characteristicValue -> { if (d) UserError.Log.d(TAG, "Wrote ResetTxMessage request!!"); parent.msg("Hard Reset Sent"); }, throwable -> { parent.msg("Hard Reset maybe Failed"); UserError.Log.e(TAG, "Failed to write ResetTxMessage: " + throwable); if (throwable instanceof BleGattCharacteristicException) { final int status = ((BleGattCharacteristicException) throwable).getStatus(); UserError.Log.e(TAG, "Got status message: " + getStatusName(status)); } }); return true; }
Example #5
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 6 votes |
private static void monitorBackFill(Ob1G5CollectionService parent, RxBleConnection connection) { if (d) UserError.Log.d(TAG, "monitor backfill enter"); final BackFillStream backfill = new BackFillStream(); connection.setupNotification(ProbablyBackfill) .timeout(15, TimeUnit.SECONDS) // WARN .observeOn(Schedulers.newThread()) .flatMap(notificationObservable -> notificationObservable) .subscribe(bytes -> { UserError.Log.d(TAG, "Received backfill notification bytes: " + JoH.bytesToHex(bytes)); backfill.push(bytes); inevitableDisconnect(parent, connection); Inevitable.task("Process G5 backfill", 3000, () -> processBacksies(backfill.decode())); }, throwable -> { UserError.Log.d(TAG, "backfill throwable: " + throwable); } ); if (d) UserError.Log.d(TAG, "monitor backfill exit"); }
Example #6
Source File: MiBandService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private void setNightMode() { if (d) UserError.Log.d(TAG, "Restore night mode"); Date start = null, end = null; DisplayControllMessageMiband3_4.NightMode nightMode = DisplayControllMessageMiband3_4.NightMode.Off; if (MiBandEntry.isNightModeEnabled()) { nightMode = DisplayControllMessageMiband3_4.NightMode.Sheduled; start = MiBandEntry.getNightModeStart(); end = MiBandEntry.getNightModeEnd(); } RxBleConnection connection = I.connection; DisplayControllMessageMiband3_4 dispControl = new DisplayControllMessageMiband3_4(); connection.writeCharacteristic(dispControl.getCharacteristicUUID(), dispControl.setNightModeCmd(nightMode, start, end)) .subscribe(valB -> { if (d) UserError.Log.d(TAG, "Wrote nightmode"); isNeedToRestoreNightMode = false; }, throwable -> { if (d) UserError.Log.e(TAG, "Could not write nightmode: " + throwable); } ); }
Example #7
Source File: ConnectionSharingAdapter.java From RxAndroidBle with Apache License 2.0 | 6 votes |
@Override public ObservableSource<RxBleConnection> apply(Observable<RxBleConnection> upstream) { synchronized (connectionObservable) { final Observable<RxBleConnection> rxBleConnectionObservable = connectionObservable.get(); if (rxBleConnectionObservable != null) { return rxBleConnectionObservable; } final Observable<RxBleConnection> newConnectionObservable = upstream .doFinally(new Action() { @Override public void run() { connectionObservable.set(null); } }) .replay(1) .refCount(); connectionObservable.set(newConnectionObservable); return newConnectionObservable; } }
Example #8
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@SuppressLint("CheckResult") public synchronized static void doKeepAlive(Ob1G5CollectionService parent, RxBleConnection connection, Runnable runnable) { if (connection == null) return; connection.writeCharacteristic(Authentication, nn(new KeepAliveTxMessage(60).byteSequence)) .timeout(2, TimeUnit.SECONDS) .subscribe( characteristicValue -> { UserError.Log.d(TAG, "Sent keep-alive " + ((runnable != null) ? "Running runnable chain" : "")); if (runnable != null) { runnable.run(); } throw new OperationSuccess("keep-alive runnable complete"); }, throwable -> { if (!(throwable instanceof OperationSuccess)) { UserError.Log.e(TAG, "Got error sending keepalive: " + throwable); } }); }
Example #9
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@SuppressLint("CheckResult") public synchronized static void doKeepAlive(Ob1G5CollectionService parent, RxBleConnection connection, Runnable runnable) { if (connection == null) return; connection.writeCharacteristic(Authentication, nn(new KeepAliveTxMessage(60).byteSequence)) .timeout(2, TimeUnit.SECONDS) .subscribe( characteristicValue -> { UserError.Log.d(TAG, "Sent keep-alive " + ((runnable != null) ? "Running runnable chain" : "")); if (runnable != null) { runnable.run(); } throw new OperationSuccess("keep-alive runnable complete"); }, throwable -> { if (!(throwable instanceof OperationSuccess)) { UserError.Log.e(TAG, "Got error sending keepalive: " + throwable); } }); }
Example #10
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@SuppressLint("CheckResult") public static boolean doReset(Ob1G5CollectionService parent, RxBleConnection connection) { if (connection == null) return false; parent.msg("Hard Resetting Transmitter"); connection.writeCharacteristic(Control, nn(new ResetTxMessage().byteSequence)) .subscribe(characteristicValue -> { if (d) UserError.Log.d(TAG, "Wrote ResetTxMessage request!!"); parent.msg("Hard Reset Sent"); }, throwable -> { parent.msg("Hard Reset maybe Failed"); UserError.Log.e(TAG, "Failed to write ResetTxMessage: " + throwable); if (throwable instanceof BleGattCharacteristicException) { final int status = ((BleGattCharacteristicException) throwable).getStatus(); UserError.Log.e(TAG, "Got status message: " + getStatusName(status)); } }); return true; }
Example #11
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@SuppressLint("CheckResult") public static boolean doReset(Ob1G5CollectionService parent, RxBleConnection connection) { if (connection == null) return false; parent.msg("Hard Resetting Transmitter"); connection.writeCharacteristic(Control, nn(new ResetTxMessage().byteSequence)) .subscribe(characteristicValue -> { if (d) UserError.Log.d(TAG, "Wrote ResetTxMessage request!!"); parent.msg("Hard Reset Sent"); }, throwable -> { parent.msg("Hard Reset maybe Failed"); UserError.Log.e(TAG, "Failed to write ResetTxMessage: " + throwable); if (throwable instanceof BleGattCharacteristicException) { final int status = ((BleGattCharacteristicException) throwable).getStatus(); UserError.Log.e(TAG, "Got status message: " + getStatusName(status)); } }); return true; }
Example #12
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 6 votes |
@SuppressLint("CheckResult") public synchronized static void doKeepAlive(Ob1G5CollectionService parent, RxBleConnection connection, Runnable runnable) { if (connection == null) return; connection.writeCharacteristic(Authentication, nn(new KeepAliveTxMessage(60).byteSequence)) .timeout(2, TimeUnit.SECONDS) .subscribe( characteristicValue -> { UserError.Log.d(TAG, "Sent keep-alive " + ((runnable != null) ? "Running runnable chain" : "")); if (runnable != null) { runnable.run(); } throw new OperationSuccess("keep-alive runnable complete"); }, throwable -> { if (!(throwable instanceof OperationSuccess)) { UserError.Log.e(TAG, "Got error sending keepalive: " + throwable); } }); }
Example #13
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 6 votes |
@SuppressLint("CheckResult") public static boolean doReset(Ob1G5CollectionService parent, RxBleConnection connection) { if (connection == null) return false; parent.msg("Hard Resetting Transmitter"); connection.writeCharacteristic(Control, nn(new ResetTxMessage().byteSequence)) .subscribe(characteristicValue -> { if (d) UserError.Log.d(TAG, "Wrote ResetTxMessage request!!"); parent.msg("Hard Reset Sent"); }, throwable -> { parent.msg("Hard Reset maybe Failed"); UserError.Log.e(TAG, "Failed to write ResetTxMessage: " + throwable); if (throwable instanceof BleGattCharacteristicException) { final int status = ((BleGattCharacteristicException) throwable).getStatus(); UserError.Log.e(TAG, "Got status message: " + getStatusName(status)); } }); return true; }
Example #14
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 6 votes |
private static void glucoseRxCommon(final BaseGlucoseRxMessage glucose, final Ob1G5CollectionService parent, final RxBleConnection connection) { if (JoH.ratelimit("ob1-g5-also-read-raw", 20)) { //if (FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) { enqueueUniqueCommand(new SensorTxMessage(), "Also read raw"); // } } if (JoH.pratelimit("g5-tx-time-since", 7200) || glucose.calibrationState().warmingUp() || !DexSessionKeeper.isStarted()) { if (JoH.ratelimit("g5-tx-time-governer", 30)) { enqueueUniqueCommand(new TimeTxMessage(), "Periodic Query Time"); } } // TODO check firmware version if (glucose.calibrationState().readyForBackfill() && !parent.getBatteryStatusNow) { backFillIfNeeded(parent, connection); } processGlucoseRxMessage(parent, glucose); parent.updateLast(tsl()); parent.clearErrors(); }
Example #15
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private static void glucoseRxCommon(final BaseGlucoseRxMessage glucose, final Ob1G5CollectionService parent, final RxBleConnection connection) { if (JoH.ratelimit("ob1-g5-also-read-raw", 20)) { //if (FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) { enqueueUniqueCommand(new SensorTxMessage(), "Also read raw"); // } } if (JoH.pratelimit("g5-tx-time-since", 7200) || glucose.calibrationState().warmingUp() || !DexSessionKeeper.isStarted()) { if (JoH.ratelimit("g5-tx-time-governer", 30)) { enqueueUniqueCommand(new TimeTxMessage(), "Periodic Query Time"); } } // TODO check firmware version if (glucose.calibrationState().readyForBackfill() && !parent.getBatteryStatusNow) { backFillIfNeeded(parent, connection); } processGlucoseRxMessage(parent, glucose); parent.updateLast(tsl()); parent.clearErrors(); }
Example #16
Source File: DeviceActivity.java From M365-Power with GNU General Public License v3.0 | 5 votes |
private void onConnectionReceived(RxBleConnection connection) { fillCheckFirstList(); Toast.makeText(DeviceActivity.this, "Starting preliminary activities", Toast.LENGTH_LONG).show(); this.connection = connection; this.time.setText("connected"); handler1.post(process); checkFirst(); }
Example #17
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private static boolean queued(Ob1G5CollectionService parent, RxBleConnection connection) { if (!commandQueue.isEmpty()) { processQueueCommand(parent, connection); return true; } return false; }
Example #18
Source File: DeviceConnection.java From Mi365Locker with GNU General Public License v3.0 | 5 votes |
public void runNextCommand() { if(this.device.getConnectionState() == RxBleConnection.RxBleConnectionState.CONNECTED && this.connection != null) { IRequest command = this.command_to_execute.remove(); if(command != null) { this.sendCommand(command); } } }
Example #19
Source File: RxBleDeviceImpl.java From RxAndroidBle with Apache License 2.0 | 5 votes |
@Override public Observable<RxBleConnection> establishConnection(final boolean autoConnect, final Timeout timeout) { ConnectionSetup options = new ConnectionSetup.Builder() .setAutoConnect(autoConnect) .setOperationTimeout(timeout) .setSuppressIllegalOperationCheck(true) .build(); return establishConnection(options); }
Example #20
Source File: DeviceAdapter.java From Mi365Locker with GNU General Public License v3.0 | 5 votes |
public void updateDeviceConnection(String address, RxBleConnection.RxBleConnectionState state) { Device device = getDeviceByAddress(address); if(device != null) { device.setState(state); notifyDataSetChanged(); } return; }
Example #21
Source File: PendiqService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void onConnectionReceived(RxBleConnection this_connection) { //msg("Connected"); // static_last_connected = JoH.tsl(); // TODO check connection already exists - close etc? if (connection_linger != null) JoH.releaseWakeLock(connection_linger); connection = this_connection; if (ratelimit("pendiq-to-discover", 1)) { changeState(DISCOVER); } }
Example #22
Source File: MedtrumCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void onConnectionReceived(final RxBleConnection this_connection) { listen_connected = true; status("Connected"); // TODO close off existing connection? connection = this_connection; if (this_connection != null) { changeState(ENABLE); } else { UserError.Log.d(TAG, "New connection null!"); changeState(CLOSE); } }
Example #23
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@SuppressLint("CheckResult") private static void disconnectNow(Ob1G5CollectionService parent, RxBleConnection connection) { // tell device to disconnect now UserError.Log.d(TAG, "Disconnect NOW: " + JoH.dateTimeText(tsl())); speakSlowly(); connection.writeCharacteristic(Control, nn(new DisconnectTxMessage().byteSequence)) .timeout(2, TimeUnit.SECONDS) // .observeOn(Schedulers.newThread()) // .subscribeOn(Schedulers.newThread()) .subscribe(disconnectValue -> { if (d) UserError.Log.d(TAG, "Wrote disconnect request"); parent.changeState(Ob1G5CollectionService.STATE.CLOSE); throw new OperationSuccess("Requested Disconnect"); }, throwable -> { if (!(throwable instanceof OperationSuccess)) { UserError.Log.d(TAG, "Disconnect NOW failure: " + JoH.dateTimeText(tsl())); if (throwable instanceof BleDisconnectedException) { UserError.Log.d(TAG, "Failed to write DisconnectTxMessage as already disconnected: " + throwable); } else { UserError.Log.e(TAG, "Failed to write DisconnectTxMessage: " + throwable); } parent.changeState(Ob1G5CollectionService.STATE.CLOSE); } }); UserError.Log.d(TAG, "Disconnect NOW exit: " + JoH.dateTimeText(tsl())); }
Example #24
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static boolean queued(Ob1G5CollectionService parent, RxBleConnection connection) { if (!commandQueue.isEmpty()) { processQueueCommand(parent, connection); return true; } return false; }
Example #25
Source File: MedtrumCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private synchronized void onConnectionStateChange(RxBleConnection.RxBleConnectionState newState) { String connection_state = "Unknown"; switch (newState) { case CONNECTING: connection_state = "Connecting"; // connecting_time = JoH.tsl(); break; case CONNECTED: connection_state = "Connected"; retry_backoff = 0; break; case DISCONNECTING: connection_state = "Disconnecting"; break; case DISCONNECTED: connection_state = "Disconnected"; status("Disconnected"); changeState(CLOSE); break; } status(connection_state); if (connection_state.equals("Disconnecting")) { tryGattRefresh(connection); } }
Example #26
Source File: JamBaseBluetoothSequencer.java From xDrip with GNU General Public License v3.0 | 5 votes |
protected synchronized void onConnectionStateChange(final RxBleConnection.RxBleConnectionState newState) { String connection_state = "Unknown"; switch (newState) { case CONNECTING: connection_state = "Connecting"; // connecting_time = JoH.tsl(); break; case CONNECTED: I.isConnected = true; I.retry_backoff = 0; // reset counter connection_state = "Connected"; break; case DISCONNECTING: I.isConnected = false; connection_state = "Disconnecting"; break; case DISCONNECTED: stopConnect(I.address); //I.isConnected = false; connection_state = "Disconnected"; changeState(CLOSE); break; } UserError.Log.d(TAG, "Connection state changed to: " + connection_state); }
Example #27
Source File: RxBleDeviceMock.java From RxAndroidBle with Apache License 2.0 | 5 votes |
@Override public Observable<RxBleConnection> establishConnection(boolean autoConnect) { return Observable.defer(new Callable<Observable<RxBleConnection>>() { @Override public Observable<RxBleConnection> call() { if (isConnected.compareAndSet(false, true)) { return RxBleDeviceMock.this.emitConnectionWithoutCompleting() .doOnSubscribe(new Consumer<Disposable>() { @Override public void accept(Disposable disposable) throws Exception { connectionStateBehaviorSubject.onNext(CONNECTING); } }) .doOnNext(new Consumer<RxBleConnection>() { @Override public void accept(RxBleConnection rxBleConnection) throws Exception { connectionStateBehaviorSubject.onNext(CONNECTED); } }) .doFinally(new Action() { @Override public void run() { connectionStateBehaviorSubject.onNext(DISCONNECTED); isConnected.set(false); } }); } else { return Observable.error(new BleAlreadyConnectedException(macAddress)); } } }); }
Example #28
Source File: Ob1G5StateMachine.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@SuppressLint("CheckResult") private static void disconnectNow(Ob1G5CollectionService parent, RxBleConnection connection) { // tell device to disconnect now UserError.Log.d(TAG, "Disconnect NOW: " + JoH.dateTimeText(tsl())); speakSlowly(); connection.writeCharacteristic(Control, nn(new DisconnectTxMessage().byteSequence)) .timeout(2, TimeUnit.SECONDS) // .observeOn(Schedulers.newThread()) // .subscribeOn(Schedulers.newThread()) .subscribe(disconnectValue -> { if (d) UserError.Log.d(TAG, "Wrote disconnect request"); parent.changeState(Ob1G5CollectionService.STATE.CLOSE); throw new OperationSuccess("Requested Disconnect"); }, throwable -> { if (!(throwable instanceof OperationSuccess)) { UserError.Log.d(TAG, "Disconnect NOW failure: " + JoH.dateTimeText(tsl())); if (throwable instanceof BleDisconnectedException) { UserError.Log.d(TAG, "Failed to write DisconnectTxMessage as already disconnected: " + throwable); } else { UserError.Log.e(TAG, "Failed to write DisconnectTxMessage: " + throwable); } parent.changeState(Ob1G5CollectionService.STATE.CLOSE); } }); UserError.Log.d(TAG, "Disconnect NOW exit: " + JoH.dateTimeText(tsl())); }
Example #29
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static boolean queued(Ob1G5CollectionService parent, RxBleConnection connection) { if (!commandQueue.isEmpty()) { processQueueCommand(parent, connection); return true; } return false; }
Example #30
Source File: Device.java From Mi365Locker with GNU General Public License v3.0 | 5 votes |
public Device(BluetoothDevice device, int rssi) { if (device == null) { throw new IllegalArgumentException("BluetoothDevice is null"); } mDevice = device; mDisplayName = device.getName(); if ((mDisplayName == null) || (mDisplayName.length() == 0)) { mDisplayName = UNKNOWN; } mRssi = rssi; this.state = RxBleConnection.RxBleConnectionState.DISCONNECTED; }