@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(); } }
.fail((device, status) -> log(Log.WARN, "Intermediate Cuff Pressure characteristic not found")) .enqueue();
.fail((device, status) -> log(Log.WARN, "Failed to enable Continuous Glucose Measurement notifications (" + status + ")")) .enqueue(); enableIndications(mCGMSpecificOpsControlPointCharacteristic) .fail((device, status) -> log(Log.WARN, "Failed to enable CGM Specific Ops Control Point indications notifications (" + status + ")")) .enqueue(); enableIndications(mRecordAccessControlPointCharacteristic) .fail((device, status) -> log(Log.WARN, "Failed to enabled Record Access Control Point indications (error " + status + ")")) .enqueue(); writeCharacteristic(mCGMSpecificOpsControlPointCharacteristic, CGMSpecificOpsControlPointData.startSession(mSecured)) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(data) + "\" sent")) .fail((device, status) -> log(LogContract.Log.Level.ERROR, "Failed to start session (error " + status + ")")) .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(); } }
enableNotifications(mGlucoseMeasurementContextCharacteristic).enqueue(); enableIndications(mRecordAccessControlPointCharacteristic) .fail((device, status) -> log(Log.WARN, "Failed to enabled Record Access Control Point indications (error " + status + ")")) .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(); }
.fail((device, status) -> log(Log.WARN, "Failed to enable notifications")) .enqueue();