@Override protected void initialize() { super.initialize(); setIndicationCallback(mHTCharacteristic) .with(new TemperatureMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { log(LogContract.Log.Level.APPLICATION, "\"" + TemperatureMeasurementParser.parse(data) + "\" received"); super.onDataReceived(device, data); } @Override public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device, final float temperature, final int unit, @Nullable final Calendar calendar, @Nullable final Integer type) { mCallbacks.onTemperatureMeasurementReceived(device, temperature, unit, calendar, type); } }); enableIndications(mHTCharacteristic).enqueue(); }
@Override protected void initialize() { super.initialize(); setNotificationCallback(mRSCMeasurementCharacteristic) .with(new RunningSpeedAndCadenceMeasurementDataCallback() { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { log(LogContract.Log.Level.APPLICATION, "\"" + RSCMeasurementParser.parse(data) + "\" received"); super.onDataReceived(device, data); } @Override public void onRSCMeasurementReceived(@NonNull final BluetoothDevice device, final boolean running, final float instantaneousSpeed, final int instantaneousCadence, @Nullable final Integer strideLength, @Nullable final Long totalDistance) { mCallbacks.onRSCMeasurementReceived(device, running, instantaneousSpeed, instantaneousCadence, strideLength, totalDistance); } }); enableNotifications(mRSCMeasurementCharacteristic).enqueue(); }
/** * This method disables notifications on the Battery Level characteristic. * * @deprecated Use {@link #disableNotifications(BluetoothGattCharacteristic)} instead. */ @Deprecated protected void disableBatteryLevelNotifications() { Request.newDisableBatteryLevelNotificationsRequest().setManager(this) .done(device -> log(Log.INFO, "Battery Level notifications disabled")) .enqueue(); }
/** * Sends the given text to RX characteristic. * @param text the text to be sent */ public void send(final String text) { // Are we connected? if (mRXCharacteristic == null) return; if (!TextUtils.isEmpty(text)) { final WriteRequest request = writeCharacteristic(mRXCharacteristic, text.getBytes()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + data.getStringValue(0) + "\" sent")); if (!mUseLongWrite) { // This will automatically split the long data into MTU-3-byte long packets. request.split(); } request.enqueue(); } } }
/** * Disables Battery Level notifications on the Server. */ public void disableBatteryLevelCharacteristicNotifications() { if (isConnected()) { disableNotifications(mBatteryLevelCharacteristic) .done(device -> log(Log.INFO, "Battery Level notifications disabled")) .enqueue(); } }
/** * Sends abort operation signal to the device. */ public void abort() { if (mRecordAccessControlPointCharacteristic == null) return; writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.abortOperation()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
@Override protected void initialize() { setNotificationCallback(mTXCharacteristic) .with((device, data) -> { final String text = data.getStringValue(0); log(LogContract.Log.Level.APPLICATION, "\"" + text + "\" received"); mCallbacks.onDataReceived(device, text); }); requestMtu(260).enqueue(); enableNotifications(mTXCharacteristic).enqueue(); }
/** * Sends abort operation signal to the device. */ public void abort() { if (mRecordAccessControlPointCharacteristic == null) return; writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.abortOperation()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
@Override protected void initialize() { super.initialize(); writeCharacteristic(mLinkLossCharacteristic, AlertLevelData.highAlert()) .done(device -> log(Log.INFO, "Link loss alert level set")) .fail((device, status) -> log(Log.WARN, "Failed to set link loss level: " + status)) .enqueue(); }
public void enableBatteryLevelCharacteristicNotifications() { if (isConnected()) { // If the Battery Level characteristic is null, the request will be ignored setNotificationCallback(mBatteryLevelCharacteristic) .with(mBatteryLevelDataCallback); enableNotifications(mBatteryLevelCharacteristic) .done(device -> log(Log.INFO, "Battery Level notifications enabled")) .fail((device, status) -> log(Log.WARN, "Battery Level characteristic not found")) .enqueue(); } }
/** * Sends the request to obtain the last (most recent) record from glucose device. The data will * be returned to Glucose Measurement characteristic as a notification followed by Record Access * Control Point indication with status code Success or other in case of error. */ public void getLastRecord() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportLastStoredRecord()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
/** * Sends the request to obtain all records from glucose device. Initially we want to notify user * about the number of the records so the 'Report Number of Stored Records' is send. The data * will be returned to Glucose Measurement characteristic as a notification followed by * Record Access Control Point indication with status code Success or other in case of error. */ public void getAllRecords() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportNumberOfAllStoredRecords()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
/** * Sends the request to remove all stored records from the Continuous Glucose Monitor device. * This feature is not supported by the CGMS sample from the SDK, so monitor will answer with * the Op Code Not Supported error. */ public void deleteAllRecords() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.deleteAllStoredRecords()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); } }
/** * Sends the request to obtain the last (most recent) record from glucose device. * The data will be returned to Glucose Measurement characteristic as a notification followed by * Record Access Control Point indication with status code Success or other in case of error. */ public void getLastRecord() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); mRecordAccessRequestInProgress = true; writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportLastStoredRecord()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
/** * Sends the request to obtain the first (oldest) record from glucose device. The data will be * returned to Glucose Measurement characteristic as a notification followed by Record Access * Control Point indication with status code Success or other in case of error. */ public void getFirstRecord() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportFirstStoredRecord()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
/** * Sends the request to delete all data from the device. A Record Access Control Point * indication with status code Success (or other in case of error) will be send. */ public void deleteAllRecords() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.deleteAllStoredRecords()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); } }
/** * Sends the request to obtain the first (oldest) record from glucose device. * The data will be returned to Glucose Measurement characteristic as a notification followed by * Record Access Control Point indication with status code Success or other in case of error. */ public void getFirstRecord() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); mRecordAccessRequestInProgress = true; writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportFirstStoredRecord()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
/** * Sends the request to obtain all records from glucose device. Initially we want to notify the * user about the number of the records so the Report Number of Stored Records request is send. * The data will be returned to Glucose Measurement characteristic as a notification followed by * Record Access Control Point indication with status code Success or other in case of error. */ public void getAllRecords() { if (mRecordAccessControlPointCharacteristic == null) return; clear(); mCallbacks.onOperationStarted(getBluetoothDevice()); mRecordAccessRequestInProgress = true; writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportNumberOfAllStoredRecords()) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); }
/** * This method will write important data to the device. * * @param parameter parameter to be written. */ void performAction(final String parameter) { log(Log.VERBOSE, "Changing device name to \"" + parameter + "\""); // Write some data to the characteristic. writeCharacteristic(mDeviceNameCharacteristic, Data.from(parameter)) // If data are longer than MTU-3, they will be chunked into multiple packets. // Check out other split options, with .split(...). .split() // Callback called when data were sent, or added to outgoing queue in case // Write Without Request type was used. .with((device, data) -> log(Log.DEBUG, data.size() + " bytes were sent")) // Callback called when data were sent, or added to outgoing queue in case // Write Without Request type was used. This is called after .with(...) callback. .done(device -> log(LogContract.Log.Level.APPLICATION, "Device name set to \"" + parameter + "\"")) // Callback called when write has failed. .fail((device, status) -> log(Log.WARN, "Failed to change device name")) .enqueue(); } }
/** * Writes the HIGH ALERT or NO ALERT command to the target device. * * @param on true to enable the alarm on proximity tag, false to disable it. */ public void writeImmediateAlert(final boolean on) { if (!isConnected()) return; writeCharacteristic(mAlertLevelCharacteristic, on ? AlertLevelData.highAlert() : AlertLevelData.noAlert()) .before(device -> log(Log.VERBOSE, on ? "Setting alarm to HIGH..." : "Disabling alarm...")) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + AlertLevelParser.parse(data) + "\" sent")) .done(device -> { mAlertOn = on; mCallbacks.onRemoteAlarmSwitched(device, on); }) .fail((device, status) -> log(Log.WARN, status == FailCallback.REASON_NULL_ATTRIBUTE ? "Alert Level characteristic not found" : GattError.parse(status))) .enqueue(); }