mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-22 08:54:21 +01:00
BleManager extracted to a standalone module
This commit is contained in:
@@ -54,6 +54,9 @@ dependencies {
|
||||
// add it as a module into the project structure and uncomment the following line (and also the according lines in the settings.gradle):
|
||||
// implementation project(':dfu')
|
||||
|
||||
// Import the BLE Library
|
||||
implementation project(':ble')
|
||||
|
||||
implementation('org.simpleframework:simple-xml:2.7.1') {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
exclude group: 'xpp3', module: 'xpp3'
|
||||
|
||||
@@ -23,7 +23,6 @@ package no.nordicsemi.android.nrftoolbox;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
@@ -28,8 +28,8 @@ import android.widget.TextView;
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileActivity;
|
||||
|
||||
// TODO The BPMActivity should be rewritten to use the service approach, like other do.
|
||||
|
||||
@@ -31,10 +31,10 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.BloodPressureMeasurementParser;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.IntermediateCuffPressureParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
|
||||
public class BPMManager extends BleManager<BPMManagerCallbacks> {
|
||||
/** Blood Pressure service UUID */
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface BPMManagerCallbacks extends BleManagerCallbacks {
|
||||
int UNIT_mmHG = 0;
|
||||
|
||||
@@ -32,11 +32,11 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.CGMMeasurementParser;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.CGMSpecificOpsControlPointParser;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.RecordAccessControlPointParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
|
||||
public class CGMSManager extends BleManager<CGMSManagerCallbacks> {
|
||||
|
||||
@@ -24,7 +24,7 @@ package no.nordicsemi.android.nrftoolbox.cgms;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface CGMSManagerCallbacks extends BleManagerCallbacks {
|
||||
/**
|
||||
|
||||
@@ -12,11 +12,11 @@ import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
|
||||
public class CGMService extends BleProfileService implements CGMSManagerCallbacks {
|
||||
|
||||
@@ -38,9 +38,9 @@ import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.csc.settings.SettingsActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.csc.settings.SettingsFragment;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileServiceReadyActivity;
|
||||
|
||||
public class CSCActivity extends BleProfileServiceReadyActivity<CSCService.CSCBinder> {
|
||||
|
||||
@@ -31,9 +31,9 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.CSCMeasurementParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
|
||||
public class CSCManager extends BleManager<CSCManagerCallbacks> {
|
||||
/** Cycling Speed and Cadence service UUID */
|
||||
|
||||
@@ -23,7 +23,7 @@ package no.nordicsemi.android.nrftoolbox.csc;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface CSCManagerCallbacks extends BleManagerCallbacks {
|
||||
int NOT_AVAILABLE = -1;
|
||||
|
||||
@@ -32,16 +32,16 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.csc.settings.SettingsFragment;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
|
||||
public class CSCService extends BleProfileService implements CSCManagerCallbacks {
|
||||
private static final String TAG = "CSCService";
|
||||
|
||||
@@ -31,7 +31,6 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
import android.content.Context;
|
||||
import android.content.CursorLoader;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
@@ -33,8 +33,8 @@ import android.widget.TextView;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileExpandableListActivity;
|
||||
|
||||
// TODO The GlucoseActivity should be rewritten to use the service approach, like other do.
|
||||
|
||||
@@ -33,11 +33,11 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.GlucoseMeasurementContextParser;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.GlucoseMeasurementParser;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.RecordAccessControlPointParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -23,7 +23,7 @@ package no.nordicsemi.android.nrftoolbox.gls;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface GlucoseManagerCallbacks extends BleManagerCallbacks {
|
||||
void onOperationStarted(final BluetoothDevice device);
|
||||
|
||||
@@ -35,9 +35,9 @@ import org.achartengine.GraphicalView;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileActivity;
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,11 +30,11 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.BodySensorLocationParser;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.HeartRateMeasurementParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
|
||||
/**
|
||||
* HRSManager class performs BluetoothGatt operations for connection, service discovery, enabling notification and reading characteristics. All operations required to connect to device with BLE HR
|
||||
|
||||
@@ -23,7 +23,7 @@ package no.nordicsemi.android.nrftoolbox.hrs;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface HRSManagerCallbacks extends BleManagerCallbacks {
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ import java.text.DecimalFormat;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.hts.settings.SettingsActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.hts.settings.SettingsFragment;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileServiceReadyActivity;
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,9 +30,9 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.TemperatureMeasurementParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ package no.nordicsemi.android.nrftoolbox.hts;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
/**
|
||||
* Interface {@link HTSManagerCallbacks} must be implemented by {@link HTSActivity} in order to receive callbacks from {@link HTSManager}
|
||||
|
||||
@@ -33,11 +33,11 @@ import android.content.IntentFilter;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
|
||||
public class HTSService extends BleProfileService implements HTSManagerCallbacks {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Nordic Semiconductor
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.profile;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCallback;
|
||||
|
||||
/**
|
||||
* DO NOT EDIT THIS FILE UNLESS NECESSARY!
|
||||
* The BleManagerCallbacks should be overridden in your app and all the 'high level' callbacks should be added there.
|
||||
* Keeping this file as is (and {@link BleManager} as well) will allow to quickly update it when an update is posted here.
|
||||
* @see no.nordicsemi.android.nrftoolbox.rsc.RSCManagerCallbacks
|
||||
*/
|
||||
public interface BleManagerCallbacks {
|
||||
|
||||
/**
|
||||
* Called when the Android device started connecting to given device.
|
||||
* The {@link #onDeviceConnected(BluetoothDevice)} will be called when the device is connected,
|
||||
* or {@link #onError(BluetoothDevice, String, int)} in case of error.
|
||||
* @param device the device that got connected
|
||||
*/
|
||||
void onDeviceConnecting(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Called when the device has been connected. This does not mean that the application may start communication.
|
||||
* A service discovery will be handled automatically after this call. Service discovery
|
||||
* may ends up with calling {@link #onServicesDiscovered(BluetoothDevice, boolean)} or
|
||||
* {@link #onDeviceNotSupported(BluetoothDevice)} if required services have not been found.
|
||||
* @param device the device that got connected
|
||||
*/
|
||||
void onDeviceConnected(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Called when user initialized disconnection.
|
||||
* @param device the device that gets disconnecting
|
||||
*/
|
||||
void onDeviceDisconnecting(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Called when the device has disconnected (when the callback returned
|
||||
* {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} with state DISCONNECTED),
|
||||
* but ONLY if the {@link BleManager#shouldAutoConnect()} method returned false for this device when it was connecting.
|
||||
* Otherwise the {@link #onLinklossOccur(BluetoothDevice)} method will be called instead.
|
||||
* @param device the device that got disconnected
|
||||
*/
|
||||
void onDeviceDisconnected(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* This callback is invoked when the Ble Manager lost connection to a device that has been connected
|
||||
* with autoConnect option (see {@link BleManager#shouldAutoConnect()}.
|
||||
* Otherwise a {@link #onDeviceDisconnected(BluetoothDevice)} method will be called on such event.
|
||||
* @param device the device that got disconnected due to a link loss
|
||||
*/
|
||||
void onLinklossOccur(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Called when service discovery has finished and primary services has been found.
|
||||
* This method is not called if the primary, mandatory services were not found during service discovery.
|
||||
* For example in the Blood Pressure Monitor, a Blood Pressure service is a primary service and
|
||||
* Intermediate Cuff Pressure service is a optional secondary service.
|
||||
* Existence of battery service is not notified by this call.
|
||||
* <p>After successful service discovery the service will initialize all services.
|
||||
* The {@link #onDeviceReady(BluetoothDevice)} method will be called when the initialization is complete.</p>
|
||||
*
|
||||
* @param device the device which services got disconnected
|
||||
* @param optionalServicesFound
|
||||
* if <code>true</code> the secondary services were also found on the device.
|
||||
*/
|
||||
void onServicesDiscovered(final BluetoothDevice device, final boolean optionalServicesFound);
|
||||
|
||||
/**
|
||||
* Method called when all initialization requests has been completed.
|
||||
* @param device the device that get ready
|
||||
*/
|
||||
void onDeviceReady(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* This method should return true if Battery Level notifications should be enabled on the target device.
|
||||
* If there is no Battery Service, or the Battery Level characteristic does not have NOTIFY property,
|
||||
* this method will not be called for this device.
|
||||
* <p>This method may return true only if an activity is bound to the service (to display the information
|
||||
* to the user), always (e.g. if critical battery level is reported using notifications) or never, if
|
||||
* such information is not important or the manager wants to control Battery Level notifications on its own.</p>
|
||||
* @param device target device
|
||||
* @return true to enabled battery level notifications after connecting to the device, false otherwise
|
||||
*/
|
||||
boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Called when battery value has been received from the device.
|
||||
*
|
||||
* @param value
|
||||
* the battery value in percent
|
||||
* @param device the device frm which the battery value has changed
|
||||
*/
|
||||
void onBatteryValueReceived(final BluetoothDevice device, final int value);
|
||||
|
||||
/**
|
||||
* Called when an {@link BluetoothGatt#GATT_INSUFFICIENT_AUTHENTICATION} error occurred and the device bond state is NOT_BONDED
|
||||
* @param device the device that requires bonding
|
||||
*/
|
||||
void onBondingRequired(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Called when the device has been successfully bonded.
|
||||
* @param device the device that got bonded
|
||||
*/
|
||||
void onBonded(final BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Called when a BLE error has occurred
|
||||
*
|
||||
* @param message
|
||||
* the error message
|
||||
* @param errorCode
|
||||
* the error code
|
||||
* @param device the device that caused an error
|
||||
*/
|
||||
void onError(final BluetoothDevice device, final String message, final int errorCode);
|
||||
|
||||
/**
|
||||
* Called when service discovery has finished but the main services were not found on the device.
|
||||
* @param device the device that failed to connect due to lack of required services
|
||||
*/
|
||||
void onDeviceNotSupported(final BluetoothDevice device);
|
||||
}
|
||||
@@ -41,6 +41,8 @@ import android.widget.Toast;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.log.ILogSession;
|
||||
import no.nordicsemi.android.log.LocalLogSession;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
|
||||
@@ -40,6 +40,8 @@ import android.widget.Toast;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.log.ILogSession;
|
||||
import no.nordicsemi.android.log.LocalLogSession;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
|
||||
@@ -38,6 +38,9 @@ import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.utils.ILogger;
|
||||
import no.nordicsemi.android.log.ILogSession;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
|
||||
@@ -48,6 +48,7 @@ import android.widget.Toast;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.log.ILogSession;
|
||||
import no.nordicsemi.android.log.LocalLogSession;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nordic Semiconductor
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.profile;
|
||||
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
public interface ILogger {
|
||||
|
||||
/**
|
||||
* Logs the given message with given log level into the all managed devices' log session.
|
||||
* @param level the log level
|
||||
* @param message the message to be logged
|
||||
*/
|
||||
void log(final int level, final String message);
|
||||
|
||||
/**
|
||||
* Logs the given message with given log level into the all managed devices' log session.
|
||||
* @param level the log level
|
||||
* @param messageRes string resource id
|
||||
* @param params additional (optional) parameters used to fill the message
|
||||
*/
|
||||
void log(final int level, @StringRes final int messageRes, final Object... params);
|
||||
}
|
||||
@@ -41,11 +41,11 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.utils.ILogger;
|
||||
import no.nordicsemi.android.log.ILogSession;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.ILogger;
|
||||
|
||||
public abstract class BleMulticonnectProfileService extends Service implements BleManagerCallbacks {
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -48,13 +48,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.log.ILogSession;
|
||||
import no.nordicsemi.android.log.LocalLogSession;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.AppHelpFragment;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.nrftoolbox.scanner.ScannerFragment;
|
||||
import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.AlertLevelParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
|
||||
public class ProximityManager extends BleManager<ProximityManagerCallbacks> {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.proximity;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface ProximityManagerCallbacks extends BleManagerCallbacks {
|
||||
// No additional methods
|
||||
|
||||
@@ -23,7 +23,7 @@ package no.nordicsemi.android.nrftoolbox.proximity;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface ProximityServerManagerCallbacks extends BleManagerCallbacks {
|
||||
void onAlarmTriggered(final BluetoothDevice device);
|
||||
|
||||
@@ -34,9 +34,9 @@ import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -44,11 +44,11 @@ import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.multiconnect.BleMulticonnectProfileService;
|
||||
|
||||
public class ProximityService extends BleMulticonnectProfileService implements ProximityManagerCallbacks, ProximityServerManagerCallbacks {
|
||||
|
||||
@@ -31,9 +31,9 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.RSCMeasurementParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
|
||||
public class RSCManager extends BleManager<RSCManagerCallbacks> {
|
||||
private static final byte INSTANTANEOUS_STRIDE_LENGTH_PRESENT = 0x01; // 1 bit
|
||||
|
||||
@@ -23,7 +23,7 @@ package no.nordicsemi.android.nrftoolbox.rsc;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface RSCManagerCallbacks extends BleManagerCallbacks {
|
||||
int NOT_AVAILABLE = -1;
|
||||
|
||||
@@ -31,14 +31,14 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
|
||||
public class RSCService extends BleProfileService implements RSCManagerCallbacks {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DeviceListAdapter extends BaseAdapter {
|
||||
private final ArrayList<ExtendedBluetoothDevice> mListValues = new ArrayList<>();
|
||||
private final Context mContext;
|
||||
|
||||
public DeviceListAdapter(Context context) {
|
||||
public DeviceListAdapter(final Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -30,9 +30,9 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.TemplateParser;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
|
||||
/**
|
||||
* Modify to template manager to match your requirements.
|
||||
|
||||
@@ -23,7 +23,7 @@ package no.nordicsemi.android.nrftoolbox.template;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
/**
|
||||
* Interface {@link TemplateManagerCallbacks} must be implemented by {@link TemplateActivity} in order to receive callbacks from {@link TemplateManager}
|
||||
|
||||
@@ -30,14 +30,14 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
|
||||
public class TemplateService extends BleProfileService implements TemplateManagerCallbacks {
|
||||
|
||||
@@ -33,7 +33,6 @@ import android.app.PendingIntent;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -89,8 +88,8 @@ import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.dfu.adapter.FileBrowserAppsAdapter;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileServiceReadyActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.uart.database.DatabaseHelper;
|
||||
import no.nordicsemi.android.nrftoolbox.uart.domain.Command;
|
||||
|
||||
@@ -34,7 +34,6 @@ import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -46,7 +45,6 @@ import android.widget.Button;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import no.nordicsemi.android.log.ILogSession;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
|
||||
@@ -33,8 +33,8 @@ import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
|
||||
public class UARTManager extends BleManager<UARTManagerCallbacks> {
|
||||
/** Nordic UART Service UUID */
|
||||
|
||||
@@ -24,7 +24,7 @@ package no.nordicsemi.android.nrftoolbox.uart;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManagerCallbacks;
|
||||
import no.nordicsemi.android.ble.BleManagerCallbacks;
|
||||
|
||||
public interface UARTManagerCallbacks extends BleManagerCallbacks {
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -42,11 +42,11 @@ import com.google.android.gms.wearable.Node;
|
||||
import com.google.android.gms.wearable.NodeApi;
|
||||
import com.google.android.gms.wearable.Wearable;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.log.Logger;
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.ToolboxApplication;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
import no.nordicsemi.android.nrftoolbox.wearable.common.Constants;
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ import com.google.android.gms.wearable.Wearable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.wearable.common.Constants;
|
||||
import no.nordicsemi.android.nrftoolbox.uart.domain.Command;
|
||||
import no.nordicsemi.android.nrftoolbox.uart.domain.UartConfiguration;
|
||||
import no.nordicsemi.android.nrftoolbox.wearable.common.Constants;
|
||||
|
||||
public class UARTConfigurationSynchronizer {
|
||||
private static final String WEAR_URI_PREFIX = "wear:"; // no / at the end as the path already has it
|
||||
|
||||
@@ -22,35 +22,7 @@
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.utility;
|
||||
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
|
||||
public class ParserUtils {
|
||||
final private static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
|
||||
public static String parse(final BluetoothGattCharacteristic characteristic) {
|
||||
return parse(characteristic.getValue());
|
||||
}
|
||||
|
||||
public static String parse(final BluetoothGattDescriptor descriptor) {
|
||||
return parse(descriptor.getValue());
|
||||
}
|
||||
|
||||
public static String parse(final byte[] data) {
|
||||
if (data == null || data.length == 0)
|
||||
return "";
|
||||
|
||||
final char[] out = new char[data.length * 3 - 1];
|
||||
for (int j = 0; j < data.length; j++) {
|
||||
int v = data[j] & 0xFF;
|
||||
out[j * 3] = HEX_ARRAY[v >>> 4];
|
||||
out[j * 3 + 1] = HEX_ARRAY[v & 0x0F];
|
||||
if (j != data.length - 1)
|
||||
out[j * 3 + 2] = '-';
|
||||
}
|
||||
return "(0x) " + new String(out);
|
||||
}
|
||||
public class ParserUtils extends no.nordicsemi.android.ble.utils.ParserUtils {
|
||||
|
||||
public static String parseDebug(final byte[] data) {
|
||||
if (data == null || data.length == 0)
|
||||
|
||||
@@ -27,8 +27,8 @@ import android.content.Intent;
|
||||
import com.google.android.gms.wearable.MessageEvent;
|
||||
import com.google.android.gms.wearable.WearableListenerService;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.wearable.common.Constants;
|
||||
import no.nordicsemi.android.nrftoolbox.uart.UARTService;
|
||||
import no.nordicsemi.android.nrftoolbox.wearable.common.Constants;
|
||||
|
||||
/**
|
||||
* The main listener for messages from Wearable devices. There may be only one such service per application so it has to handle messages from all profiles.
|
||||
|
||||
@@ -24,7 +24,6 @@ package no.nordicsemi.android.nrftoolbox.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Spinner;
|
||||
|
||||
public class ClosableSpinner extends android.support.v7.widget.AppCompatSpinner {
|
||||
public ClosableSpinner(Context context, AttributeSet attrs) {
|
||||
|
||||
@@ -24,7 +24,6 @@ package no.nordicsemi.android.nrftoolbox.widget;
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ package no.nordicsemi.android.nrftoolbox.widget;
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
|
||||
@@ -21,10 +21,6 @@
|
||||
-->
|
||||
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="no.nordicsemi.android.nrftoolbox.common">
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
/*************************************************************************************************************************************************
|
||||
* Copyright (c) 2015, Nordic Semiconductor
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************************************************************************************/
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.error;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
|
||||
/**
|
||||
* Parses the error numbers according to the <b>gatt_api.h</b> file from bluedroid stack.
|
||||
* See: https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h (and other versions) for details.
|
||||
*/
|
||||
public class GattError {
|
||||
|
||||
// Starts at line 106 of gatt_api.h file
|
||||
/**
|
||||
* Converts the connection status given by the {@link android.bluetooth.BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)} to error name.
|
||||
* @param error the status number
|
||||
* @return the error name as stated in the gatt_api.h file
|
||||
*/
|
||||
public static String parseConnectionError(final int error) {
|
||||
switch (error) {
|
||||
case BluetoothGatt.GATT_SUCCESS:
|
||||
return "SUCCESS";
|
||||
case 0x01:
|
||||
return "GATT CONN L2C FAILURE";
|
||||
case 0x08:
|
||||
return "GATT CONN TIMEOUT";
|
||||
case 0x13:
|
||||
return "GATT CONN TERMINATE PEER USER";
|
||||
case 0x16:
|
||||
return "GATT CONN TERMINATE LOCAL HOST";
|
||||
case 0x3E:
|
||||
return "GATT CONN FAIL ESTABLISH";
|
||||
case 0x22:
|
||||
return "GATT CONN LMP TIMEOUT";
|
||||
case 0x0100:
|
||||
return "GATT CONN CANCEL ";
|
||||
case 0x0085:
|
||||
return "GATT ERROR"; // Device not reachable
|
||||
default:
|
||||
return "UNKNOWN (" + error + ")";
|
||||
}
|
||||
}
|
||||
|
||||
// Starts at line 29 of the gatt_api.h file
|
||||
/**
|
||||
* Converts the bluetooth communication status given by other BluetoothGattCallbacks to error name. It also parses the DFU errors.
|
||||
* @param error the status number
|
||||
* @return the error name as stated in the gatt_api.h file
|
||||
*/
|
||||
public static String parse(final int error) {
|
||||
switch (error) {
|
||||
case 0x0001:
|
||||
return "GATT INVALID HANDLE";
|
||||
case 0x0002:
|
||||
return "GATT READ NOT PERMIT";
|
||||
case 0x0003:
|
||||
return "GATT WRITE NOT PERMIT";
|
||||
case 0x0004:
|
||||
return "GATT INVALID PDU";
|
||||
case 0x0005:
|
||||
return "GATT INSUF AUTHENTICATION";
|
||||
case 0x0006:
|
||||
return "GATT REQ NOT SUPPORTED";
|
||||
case 0x0007:
|
||||
return "GATT INVALID OFFSET";
|
||||
case 0x0008:
|
||||
return "GATT INSUF AUTHORIZATION";
|
||||
case 0x0009:
|
||||
return "GATT PREPARE Q FULL";
|
||||
case 0x000a:
|
||||
return "GATT NOT FOUND";
|
||||
case 0x000b:
|
||||
return "GATT NOT LONG";
|
||||
case 0x000c:
|
||||
return "GATT INSUF KEY SIZE";
|
||||
case 0x000d:
|
||||
return "GATT INVALID ATTR LEN";
|
||||
case 0x000e:
|
||||
return "GATT ERR UNLIKELY";
|
||||
case 0x000f:
|
||||
return "GATT INSUF ENCRYPTION";
|
||||
case 0x0010:
|
||||
return "GATT UNSUPPORT GRP TYPE";
|
||||
case 0x0011:
|
||||
return "GATT INSUF RESOURCE";
|
||||
case 0x0087:
|
||||
return "GATT ILLEGAL PARAMETER";
|
||||
case 0x0080:
|
||||
return "GATT NO RESOURCES";
|
||||
case 0x0081:
|
||||
return "GATT INTERNAL ERROR";
|
||||
case 0x0082:
|
||||
return "GATT WRONG STATE";
|
||||
case 0x0083:
|
||||
return "GATT DB FULL";
|
||||
case 0x0084:
|
||||
return "GATT BUSY";
|
||||
case 0x0085:
|
||||
return "GATT ERROR";
|
||||
case 0x0086:
|
||||
return "GATT CMD STARTED";
|
||||
case 0x0088:
|
||||
return "GATT PENDING";
|
||||
case 0x0089:
|
||||
return "GATT AUTH FAIL";
|
||||
case 0x008a:
|
||||
return "GATT MORE";
|
||||
case 0x008b:
|
||||
return "GATT INVALID CFG";
|
||||
case 0x008c:
|
||||
return "GATT SERVICE STARTED";
|
||||
case 0x008d:
|
||||
return "GATT ENCRYPTED NO MITM";
|
||||
case 0x008e:
|
||||
return "GATT NOT ENCRYPTED";
|
||||
case 0x008f:
|
||||
return "GATT CONGESTED";
|
||||
case 0x00FD:
|
||||
return "GATT CCCD CFG ERROR";
|
||||
case 0x00FE:
|
||||
return "GATT PROCEDURE IN PROGRESS";
|
||||
case 0x00FF:
|
||||
return "GATT VALUE OUT OF RANGE";
|
||||
case 0x0101:
|
||||
return "TOO MANY OPEN CONNECTIONS";
|
||||
default:
|
||||
return "UNKNOWN (" + error + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
@@ -573,6 +574,34 @@ public class BleManager implements BleProfileApi {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean requestMtu(final int mtu) {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && enqueue(Request.newMtuRequest(mtu));
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
private boolean internalRequestMtu(final int mtu) {
|
||||
final BluetoothGatt gatt = mBluetoothGatt;
|
||||
if (gatt == null)
|
||||
return false;
|
||||
|
||||
return gatt.requestMtu(mtu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean requestConnectionPriority(final int priority) {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && enqueue(Request.newConnectionPriorityRequest(priority));
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
private boolean internalRequestConnectionPriority(final int priority) {
|
||||
final BluetoothGatt gatt = mBluetoothGatt;
|
||||
if (gatt == null)
|
||||
return false;
|
||||
|
||||
return gatt.requestConnectionPriority(priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enqueue(final Request request) {
|
||||
if (mGattCallback != null) {
|
||||
@@ -592,11 +621,21 @@ public class BleManager implements BleProfileApi {
|
||||
private final static String ERROR_WRITE_CHARACTERISTIC = "Error on writing characteristic";
|
||||
private final static String ERROR_READ_DESCRIPTOR = "Error on reading descriptor";
|
||||
private final static String ERROR_WRITE_DESCRIPTOR = "Error on writing descriptor";
|
||||
private final static String ERROR_MTU_REQUEST = "Error on mtu request";
|
||||
private final static String ERROR_CONNECTION_PRIORITY_REQUEST = "Error on connection priority request";
|
||||
|
||||
private final Queue<Request> mTaskQueue = new LinkedList<>();
|
||||
private Deque<Request> mInitQueue;
|
||||
private boolean mInitInProgress;
|
||||
private boolean mOperationInProgress = true;
|
||||
/**
|
||||
* This flag is required to resume operations after the connection priority request was made.
|
||||
* It is used only on Android Oreo and newer, as only there there is onConnectionUpdated callback.
|
||||
* However, as this callback is triggered every time the connection parameters change, even
|
||||
* when such request wasn't made, this flag ensures the nextRequest() method won't be called
|
||||
* during another operation.
|
||||
*/
|
||||
private boolean mConnectionPriorityOperationInProgress = false;
|
||||
|
||||
private void notifyDeviceDisconnected(final BluetoothDevice device) {
|
||||
mConnected = false;
|
||||
@@ -814,6 +853,48 @@ public class BleManager implements BleProfileApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMtuChanged(final BluetoothGatt gatt, final int mtu, final int status) {
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
mProfile.onMtuChanged(mtu);
|
||||
} else {
|
||||
DebugLogger.e(TAG, "onMtuChanged error: " + status + ", mtu: " + mtu);
|
||||
onError(gatt.getDevice(), ERROR_MTU_REQUEST, status);
|
||||
}
|
||||
mOperationInProgress = false;
|
||||
nextRequest();
|
||||
}
|
||||
|
||||
// @Override
|
||||
/**
|
||||
* Callback indicating the connection parameters were updated. Works on Android 8+.
|
||||
*
|
||||
* @param gatt GATT client involved
|
||||
* @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from
|
||||
* 6 (7.5ms) to 3200 (4000ms).
|
||||
* @param latency Slave latency for the connection in number of connection events. Valid range
|
||||
* is from 0 to 499
|
||||
* @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
|
||||
* (0.1s) to 3200 (32s)
|
||||
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
|
||||
* successfully
|
||||
*/
|
||||
public void onConnectionUpdated(final BluetoothGatt gatt, final int interval, final int latency, final int timeout, final int status) {
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
mProfile.onConnectionUpdated(interval, latency, timeout);
|
||||
} else if (status == 0x3b) { // HCI_ERR_UNACCEPT_CONN_INTERVAL
|
||||
DebugLogger.e(TAG, "onConnectionUpdated received status: Unacceptable connection interval, interval: " + interval + ", latency: " + latency + ", timeout: " + timeout);
|
||||
} else {
|
||||
DebugLogger.e(TAG, "onConnectionUpdated received status: " + status + ", interval: " + interval + ", latency: " + latency + ", timeout: " + timeout);
|
||||
mCallbacks.onError(gatt.getDevice(), ERROR_CONNECTION_PRIORITY_REQUEST, status);
|
||||
}
|
||||
if (mConnectionPriorityOperationInProgress) {
|
||||
mConnectionPriorityOperationInProgress = false;
|
||||
mOperationInProgress = false;
|
||||
nextRequest();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the next request. If the last element from the initialization queue has been executed
|
||||
* the {@link BleManagerCallbacks#onDeviceReady(BluetoothDevice)} callback is called.
|
||||
@@ -853,7 +934,7 @@ public class BleManager implements BleProfileApi {
|
||||
}
|
||||
case WRITE: {
|
||||
final BluetoothGattCharacteristic characteristic = request.characteristic;
|
||||
characteristic.setValue(request.value);
|
||||
characteristic.setValue(request.data);
|
||||
characteristic.setWriteType(request.writeType);
|
||||
result = internalWriteCharacteristic(characteristic);
|
||||
break;
|
||||
@@ -864,7 +945,7 @@ public class BleManager implements BleProfileApi {
|
||||
}
|
||||
case WRITE_DESCRIPTOR: {
|
||||
final BluetoothGattDescriptor descriptor = request.descriptor;
|
||||
descriptor.setValue(request.value);
|
||||
descriptor.setValue(request.data);
|
||||
result = internalWriteDescriptor(descriptor);
|
||||
break;
|
||||
}
|
||||
@@ -892,10 +973,32 @@ public class BleManager implements BleProfileApi {
|
||||
result = ensureServiceChangedEnabled();
|
||||
break;
|
||||
}
|
||||
case REQUEST_MTU: {
|
||||
result = internalRequestMtu(request.value);
|
||||
break;
|
||||
}
|
||||
case REQUEST_CONNECTION_PRIORITY: {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
mConnectionPriorityOperationInProgress = true;
|
||||
result = internalRequestConnectionPriority(request.value);
|
||||
} else {
|
||||
result = internalRequestConnectionPriority(request.value);
|
||||
// There is no callback for requestConnectionPriority(...) before Android Oreo.\
|
||||
// Let's give it some time to finish as the request is an asynchronous operation.
|
||||
if (result) {
|
||||
mHandler.postDelayed(() -> {
|
||||
mOperationInProgress = false;
|
||||
nextRequest();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// The result may be false if given characteristic or descriptor were not found on the device.
|
||||
// In that case, proceed with next operation and ignore the one that failed.
|
||||
if (!result) {
|
||||
mConnectionPriorityOperationInProgress = false;
|
||||
mOperationInProgress = false;
|
||||
nextRequest();
|
||||
}
|
||||
|
||||
@@ -22,10 +22,12 @@
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.ble;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.Deque;
|
||||
|
||||
@@ -147,6 +149,30 @@ public abstract class BleProfile {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called when the MTU request has finished with success. The MTU value may
|
||||
* be different than requested one.
|
||||
* @param mtu the new MTU (Maximum Transfer Unit)
|
||||
*/
|
||||
protected void onMtuChanged(final int mtu) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback indicating the connection parameters were updated. Works on Android 8+.
|
||||
*
|
||||
* @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from
|
||||
* 6 (7.5ms) to 3200 (4000ms).
|
||||
* @param latency Slave latency for the connection in number of connection events. Valid range
|
||||
* is from 0 to 499
|
||||
* @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
|
||||
* (0.1s) to 3200 (32s)
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
protected void onConnectionUpdated(final int interval, final int latency, final int timeout) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a BLE error has occurred
|
||||
* @param message the error message
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.ble;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
import android.content.Context;
|
||||
@@ -48,52 +49,69 @@ public interface BleProfileApi {
|
||||
ENABLE_BATTERY_LEVEL_NOTIFICATIONS,
|
||||
DISABLE_BATTERY_LEVEL_NOTIFICATIONS,
|
||||
ENABLE_SERVICE_CHANGED_INDICATIONS,
|
||||
REQUEST_MTU,
|
||||
REQUEST_CONNECTION_PRIORITY,
|
||||
}
|
||||
|
||||
final Type type;
|
||||
final BluetoothGattCharacteristic characteristic;
|
||||
final BluetoothGattDescriptor descriptor;
|
||||
final byte[] value;
|
||||
final byte[] data;
|
||||
final int writeType;
|
||||
final int value;
|
||||
|
||||
private Request(final Type type) {
|
||||
this.type = type;
|
||||
this.characteristic = null;
|
||||
this.descriptor = null;
|
||||
this.value = null;
|
||||
this.data = null;
|
||||
this.writeType = 0;
|
||||
this.value = 0;
|
||||
}
|
||||
|
||||
private Request(final Type type, final int value) {
|
||||
this.type = type;
|
||||
this.characteristic = null;
|
||||
this.descriptor = null;
|
||||
this.data = null;
|
||||
this.writeType = 0;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private Request(final Type type, final BluetoothGattCharacteristic characteristic) {
|
||||
this.type = type;
|
||||
this.characteristic = characteristic;
|
||||
this.descriptor = null;
|
||||
this.value = null;
|
||||
this.data = null;
|
||||
this.writeType = 0;
|
||||
this.value = 0;
|
||||
}
|
||||
|
||||
private Request(final Type type, final BluetoothGattCharacteristic characteristic, final int writeType, final byte[] value, final int offset, final int length) {
|
||||
private Request(final Type type, final BluetoothGattCharacteristic characteristic, final int writeType, final byte[] data, final int offset, final int length) {
|
||||
this.type = type;
|
||||
this.characteristic = characteristic;
|
||||
this.descriptor = null;
|
||||
this.value = copy(value, offset, length);
|
||||
this.data = copy(data, offset, length);
|
||||
this.writeType = writeType;
|
||||
this.value = 0;
|
||||
}
|
||||
|
||||
private Request(final Type type, final BluetoothGattDescriptor descriptor) {
|
||||
this.type = type;
|
||||
this.characteristic = null;
|
||||
this.descriptor = descriptor;
|
||||
this.value = null;
|
||||
this.data = null;
|
||||
this.writeType = 0;
|
||||
this.value = 0;
|
||||
}
|
||||
|
||||
private Request(final Type type, final BluetoothGattDescriptor descriptor, final byte[] value, final int offset, final int length) {
|
||||
private Request(final Type type, final BluetoothGattDescriptor descriptor, final byte[] data, final int offset, final int length) {
|
||||
this.type = type;
|
||||
this.characteristic = null;
|
||||
this.descriptor = descriptor;
|
||||
this.value = copy(value, offset, length);
|
||||
this.data = copy(data, offset, length);
|
||||
this.writeType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
|
||||
this.value = 0;
|
||||
}
|
||||
|
||||
private static byte[] copy(final byte[] value, final int offset, final int length) {
|
||||
@@ -127,50 +145,50 @@ public interface BleProfileApi {
|
||||
* Creates new Write Characteristic request. The request will not be executed if given characteristic
|
||||
* is null or does not have WRITE property. After the operation is complete a proper callback will be invoked.
|
||||
* @param characteristic characteristic to be written
|
||||
* @param value value to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param data data to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] value) {
|
||||
return new Request(Type.WRITE, characteristic, characteristic.getWriteType(), value, 0, value != null ? value.length : 0);
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] data) {
|
||||
return new Request(Type.WRITE, characteristic, characteristic.getWriteType(), data, 0, data != null ? data.length : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new Write Characteristic request. The request will not be executed if given characteristic
|
||||
* is null or does not have WRITE property. After the operation is complete a proper callback will be invoked.
|
||||
* @param characteristic characteristic to be written
|
||||
* @param value value to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param data data to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param writeType write type to be used, one of {@link BluetoothGattCharacteristic#WRITE_TYPE_DEFAULT}, {@link BluetoothGattCharacteristic#WRITE_TYPE_NO_RESPONSE}.
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] value, final int writeType) {
|
||||
return new Request(Type.WRITE, characteristic, writeType, value, 0, value != null ? value.length : 0);
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] data, final int writeType) {
|
||||
return new Request(Type.WRITE, characteristic, writeType, data, 0, data != null ? data.length : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new Write Characteristic request. The request will not be executed if given characteristic
|
||||
* is null or does not have WRITE property. After the operation is complete a proper callback will be invoked.
|
||||
* @param characteristic characteristic to be written
|
||||
* @param value value to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param offset the offset from which value has to be copied
|
||||
* @param length number of bytes to be copied from the value buffer
|
||||
* @param data data to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param offset the offset from which data has to be copied
|
||||
* @param length number of bytes to be copied from the data buffer
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] value, final int offset, final int length) {
|
||||
return new Request(Type.WRITE, characteristic, characteristic.getWriteType(), value, offset, length);
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] data, final int offset, final int length) {
|
||||
return new Request(Type.WRITE, characteristic, characteristic.getWriteType(), data, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new Write Characteristic request. The request will not be executed if given characteristic
|
||||
* is null or does not have WRITE property. After the operation is complete a proper callback will be invoked.
|
||||
* @param characteristic characteristic to be written
|
||||
* @param value value to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param offset the offset from which value has to be copied
|
||||
* @param length number of bytes to be copied from the value buffer
|
||||
* @param data data to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param offset the offset from which data has to be copied
|
||||
* @param length number of bytes to be copied from the data buffer
|
||||
* @param writeType write type to be used, one of {@link BluetoothGattCharacteristic#WRITE_TYPE_DEFAULT}, {@link BluetoothGattCharacteristic#WRITE_TYPE_NO_RESPONSE}.
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] value, final int offset, final int length, final int writeType) {
|
||||
return new Request(Type.WRITE, characteristic, writeType, value, offset, length);
|
||||
public static Request newWriteRequest(final BluetoothGattCharacteristic characteristic, final byte[] data, final int offset, final int length, final int writeType) {
|
||||
return new Request(Type.WRITE, characteristic, writeType, data, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,24 +205,24 @@ public interface BleProfileApi {
|
||||
* Creates new Write Descriptor request. The request will not be executed if given descriptor
|
||||
* is null. After the operation is complete a proper callback will be invoked.
|
||||
* @param descriptor descriptor to be written
|
||||
* @param value value to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param data data to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
public static Request newWriteRequest(final BluetoothGattDescriptor descriptor, final byte[] value) {
|
||||
return new Request(Type.WRITE_DESCRIPTOR, descriptor, value, 0, value != null ? value.length : 0);
|
||||
public static Request newWriteRequest(final BluetoothGattDescriptor descriptor, final byte[] data) {
|
||||
return new Request(Type.WRITE_DESCRIPTOR, descriptor, data, 0, data != null ? data.length : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new Write Descriptor request. The request will not be executed if given descriptor
|
||||
* is null. After the operation is complete a proper callback will be invoked.
|
||||
* @param descriptor descriptor to be written
|
||||
* @param value value to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param offset the offset from which value has to be copied
|
||||
* @param length number of bytes to be copied from the value buffer
|
||||
* @param data data to be written. The array is copied into another buffer so it's safe to reuse the array again.
|
||||
* @param offset the offset from which data has to be copied
|
||||
* @param length number of bytes to be copied from the data buffer
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
public static Request newWriteRequest(final BluetoothGattDescriptor descriptor, final byte[] value, final int offset, final int length) {
|
||||
return new Request(Type.WRITE_DESCRIPTOR, descriptor, value, offset, length);
|
||||
public static Request newWriteRequest(final BluetoothGattDescriptor descriptor, final byte[] data, final int offset, final int length) {
|
||||
return new Request(Type.WRITE_DESCRIPTOR, descriptor, data, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,6 +281,38 @@ public interface BleProfileApi {
|
||||
static Request newEnableServiceChangedIndicationsRequest() {
|
||||
return new Request(Type.ENABLE_SERVICE_CHANGED_INDICATIONS); // the only Service Changed char is used (if such exists)
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests new MTU (Maximum Transfer Unit). This is only supported on Android Lollipop or newer.
|
||||
* The target device may reject requested data and set smalled MTU.
|
||||
* @param mtu the new MTU. Acceptable values are <23, 517>.
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
static Request newMtuRequest(int mtu) {
|
||||
if (mtu < 23)
|
||||
mtu = 23;
|
||||
if (mtu > 517)
|
||||
mtu = 517;
|
||||
return new Request(Type.REQUEST_MTU, mtu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the new connection priority. Acceptable values are:
|
||||
* <ol>
|
||||
* <li>{@link BluetoothGatt#CONNECTION_PRIORITY_HIGH} - Interval: 11.25 -15 ms, latency: 0, supervision timeout: 20 sec,</li>
|
||||
* <li>{@link BluetoothGatt#CONNECTION_PRIORITY_BALANCED} - Interval: 30 - 50 ms, latency: 0, supervision timeout: 20 sec,</li>
|
||||
* <li>{@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER} - Interval: 100 - 125 ms, latency: 2, supervision timeout: 20 sec.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param priority one of: {@link BluetoothGatt#CONNECTION_PRIORITY_HIGH}, {@link BluetoothGatt#CONNECTION_PRIORITY_BALANCED},
|
||||
* {@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER}.
|
||||
* @return the new request that can be enqueued using {@link #enqueue(Request)} method.
|
||||
*/
|
||||
static Request newConnectionPriorityRequest(int priority) {
|
||||
if (priority < 0 || priority > 2)
|
||||
priority = 0; // Balanced
|
||||
return new Request(Type.REQUEST_CONNECTION_PRIORITY, priority);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,6 +387,28 @@ public interface BleProfileApi {
|
||||
*/
|
||||
boolean setBatteryNotifications(final boolean enable);
|
||||
|
||||
/**
|
||||
* Requests new MTU. On Android 4.3 and 4.4.x returns false.
|
||||
*
|
||||
* @return true if request has been enqueued
|
||||
*/
|
||||
boolean requestMtu(final int mtu);
|
||||
|
||||
/**
|
||||
* Requests the new connection priority. Acceptable values are:
|
||||
* <ol>
|
||||
* <li>{@link BluetoothGatt#CONNECTION_PRIORITY_HIGH} - Interval: 11.25 -15 ms, latency: 0, supervision timeout: 20 sec,</li>
|
||||
* <li>{@link BluetoothGatt#CONNECTION_PRIORITY_BALANCED} - Interval: 30 - 50 ms, latency: 0, supervision timeout: 20 sec,</li>
|
||||
* <li>{@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER} - Interval: 100 - 125 ms, latency: 2, supervision timeout: 20 sec.</li>
|
||||
* </ol>
|
||||
* On Android 4.3 and 4.4.x returns false.
|
||||
*
|
||||
* @param priority one of: {@link BluetoothGatt#CONNECTION_PRIORITY_HIGH}, {@link BluetoothGatt#CONNECTION_PRIORITY_BALANCED},
|
||||
* {@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER}.
|
||||
* @return true if request has been enqueued
|
||||
*/
|
||||
boolean requestConnectionPriority(final int priority);
|
||||
|
||||
/**
|
||||
* Enqueues a new request. The request will be handled immediately if there is no operation in progress,
|
||||
* or automatically after the last enqueued one will finish.
|
||||
|
||||
Reference in New Issue
Block a user