/** * 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(); } } }
/** * 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(); }
/** * 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(); }
/** * 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 refreshRecords() { if (mRecordAccessControlPointCharacteristic == null) return; if (mRecords.size() == 0) { getAllRecords(); } else { mCallbacks.onOperationStarted(getBluetoothDevice()); // Obtain the last sequence number final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1; mRecordAccessRequestInProgress = true; writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportStoredRecordsGreaterThenOrEqualTo(sequenceNumber)) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); // Info: // Operators OPERATOR_GREATER_THEN_OR_EQUAL, OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by the CGMS sample from SDK // The "Operation not supported" response will be received } }
/** * Sends the request to obtain from the glucose device all records newer than the newest one * from local storage. 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. * <p> * Refresh button will not download records older than the oldest in the local memory. * E.g. if you have pressed Last and then Refresh, than it will try to get only newer records. * However if there are no records, it will download all existing (using {@link #getAllRecords()}). */ public void refreshRecords() { if (mRecordAccessControlPointCharacteristic == null) return; if (mRecords.size() == 0) { getAllRecords(); } else { mCallbacks.onOperationStarted(getBluetoothDevice()); // obtain the last sequence number final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1; writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportStoredRecordsGreaterThenOrEqualTo(sequenceNumber)) .with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent")) .enqueue(); // Info: // Operators OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by Nordic Semiconductor Glucose Service in SDK 4.4.2. } }
/** * 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 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 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 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(); }
.with((device, data) -> log(Log.DEBUG, "Data sent: " + data))
.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();