MOVERIO Pro Developer's Guide - Bluetooth(R) & Power · PDF fileMOVERIO Pro Developer's Guide...
Transcript of MOVERIO Pro Developer's Guide - Bluetooth(R) & Power · PDF fileMOVERIO Pro Developer's Guide...
MOVERIO Pro Developer's Guide (Rev.1.5)
122
8. Bluetooth/BLE
MOVERIO Pro Developer's Guide (Rev.1.5)
123
8.1. Pre-cautions for developing Apps using BLE
BT-2000 is adopting EPSON original BLE control API, so you cannot use BLE control API provided
by Google. Therefore you cannot divert App or source code that is operating with other Android
equipment. For detail limited items, please refer to chapter 8.4.Remarks & Restrictions for BLE
App Development
MOVERIO Pro Developer's Guide (Rev.1.5)
124
8.2. Summary
This chapter explains the Bluetooth/BLE function built into the MOVERIO Pro BT-2000.
The BT-2000 supports Bluetooth 4.0 LE, and in addition to the conventional Bluetooth 3.0+HS
function, it also supports LowEnergy. For convenience, this section describes the Bluetooth
3.0+HS Bluetooth Legacy and the LowEnergy BLE.
8.2.1. Supported specifications
8.2.1.1. Bluetooth Legacy specifications
This describes the Bluetooth Legacy specifications for the BT-2000.
Table 8-1 Bluetooth Legacy module and protocol stack
Item Specifications
Module specifications Bluetooth3.0 + HS (Bluetooth Class2)
Protocol stack specifications Based on Core Spec Version 3.0
Table 8-2 Bluetooth Legacy protocol support
Profile Role Version
Headset Profile(HSP) Audio Gateway 1.1
Advanced Audio Distribution Profile(A2DP) Source 1.2
Human Interface Device(HID) Host 1.0
Object Push Profile(OPP) Client/Server 1.1
Serial Port Profile(SPP) Device A/Device B 1.2
Audio/Video Remote Control Profile(AVRCP) Target 1.0
Audio/Video Control Transport Protocol(AVCTP) Target 1.3
Audio/Video Distribution Transport Protocol(AVDTP) Source/Acceptor/Initiator 1.2
Generic Audio Video Distribution Profile(GAVDP) Acceptor/Initiator 1.0
MOVERIO Pro Developer's Guide (Rev.1.5)
125
8.2.1.2. BLE specifications
This describes the BLE specifications for the BT-2000.
Table 8-3 BLE protocol stack specifications
Item Specifications
Protocol stack specifications Based on Core Spec Version 4.1 (Low Energy Host)
Table 8-4 BLE protocol support
Profile Role Version
Find Me Profile(FMP) Locator 1.0
Proximity Profile(PXP) Monitor 1.0
* New profiles can be supported through applications you develop for the user.
BLE Beacon function
The BLE Beacon function detects Beacon devices within communication range using the
Advertise function for GAP (General Access Profile), not the function described in the BLE
profile.
When the BT-2000 is within the Bluetooth communication area for a Beacon device, the
Beacon device is detected using Advertise data being broadcast by the Beacon device (note 1),
and then calculates the distance from the Beacon device using the strength of the radio waves.
Note 1)
If the Beacon device supports the iBeacon standards, the device can determine Immediate/Near/Far from the
RSSI value. If the device does not support the iBeacon standards, the distance need to be calculated from the
RSSI value.
Figure 8-1 Image of BLE Beacon usage
Bluetooth communication area Beacon
device
Beacon
device
MOVERIO Pro Developer's Guide (Rev.1.5)
126
8.3. Usage method
This section describes how to use Bluetooth Legacy and BLE.
8.3.1. Using Bluetooth Legacy
You can use Bluetooth Legacy for the BT-2000 from [Bluetooth] in the [Settings] app.
Figure 8-2 Bluetooth Legacy Settings screen
8.3.1.1. Turning Bluetooth Legacy ON/OFF
To turn on the Bluetooth Legacy function, move your cursor over the ON/OFF switch (2), and
then press the select button.
8.3.1.2. Searching using Bluetooth Legacy
Press the [Search for Devices] button to search for Bluetooth Legacy devices in the area.
8.3.1.3. Connecting using Bluetooth Legacy
You can select the device you want to connect to in [Available Devices], and then perform
pairing.
8.3.1.4. Disconnecting using Bluetooth Legacy
You can select the device you want to disconnect from in [Paired Devices], and then
disconnect.
ON/OFF switch (1)
ON/OFF switch (2)
MOVERIO Pro Developer's Guide (Rev.1.5)
127
8.3.2. Using BLE
To test the BLE function for the BT-2000, sample BLEBeacon and PXP/FMP applications have
been preinstalled. Refer to these sample applications when developing a BLE application for the
user.
The following explains how to use the sample applications.
8.3.2.1. Using the BLEBeacon sample application
Select the BLEBeacon icon from the app list.
Figure 8-3 BLEBeacon icon
BLE turns on automatically when the app starts, and the BLE icon is displayed in the notification
area.
Figure 8-4 BLEBeacon app screen
Table 8-5 BLEBeacon app screen composition
Item Explanation
Scan Start Starts scanning for the BLE Beacon.
Scan Stop Stops scanning for the BLE Beacon.
Address Displays the Bluetooth Device Address.
Device Name(m/n) Displays the Device Name and the Major/Minor numbers.
* Depends on the Advertise data configuration from the Beacon.
Distance Displays the determined distance and RSSI value. Note 2)
Note 2) Determining distance for the BLEBeacon
You need to perform distance determination for the BT-2000 and the Beacon in the app.
Distance determination is calculated based on the Measured Power included in the Advertise
data by the BLEBeacon app.
Since Measured Power support varies depending on the Beacon manufacturer, you will need to
MOVERIO Pro Developer's Guide (Rev.1.5)
128
decide whether or not ("Use" or "Do not use") to use the distance determination based on
Measured Power supplied by the company identifier in the BLEBeacon app. Distance is
determined from the Measured Power and RSSI value as shown below.
Table 8-6 Determining distance for the BLEBeacon app
Determination result RSSI value (when Measured Power for the Beacon is set to -70)
Immediate 127 to -70 (=Measured Power)
Near -51 to -90 (=Measured Power - 20)
Far -91 to 128
Unknown
Could not receive Advertise data for more than three seconds
Or the company identifier was not Apple (0x004C) or Nordic
(0x0059).
MOVERIO Pro Developer's Guide (Rev.1.5)
129
8.3.2.2. Using the FMP_PXP sample application
Select the FMP_PXP icon from the app list.
*This application still includes some Japanese language. Please reference the following translation notes as your
reference when you use this application.
Figure 8-5 FMP_PXP icon
Check the ON/OFF status for the BLE when the app starts, and then displays a confirmation
dialog if BLE is not ON.
Figure 8-6 BLE confirmation dialog
Bluetooth Low Energy is not enabled.
Do you want to enable Bluetooth Low Energy?
MOVERIO Pro Developer's Guide (Rev.1.5)
130
Figure 8-7 FMP_PXP app Scan screen composition
Table 8-7 FMP_PXP app Scan screen composition
Item Explanation
Scan Start Starts scanning for the BLE device.
Scan Stop Stops scanning for the BLE device.
Connect Starts connecting.
Disconnect Starts disconnecting.
Clear Clears the list.
Authentication method
Select the authentication method.
- Just Works
- Passkey Entry
Select search service
Select the service that you want to use to search from the
services included with the connected device.
- Immediate Alert Service
- Tx Power Service
- Link Loss Service
DiscPriSrvByUUID From the list of services on the connected device, select the
Service you want from [Select search service].
DiscAllPriSrv Displays all services for the connected device.
ProfileActivity Displays ProfileActivity based on information for the
connected device.
Please push “Scan Start” button.
Authentication method
Target connection
device
Target service selection
MOVERIO Pro Developer's Guide (Rev.1.5)
131
Authenticating using Passkey Entry
When connecting to a BLE device that requires password authentication, execute Connect in
Passkey Entry.
One of the following pairing dialogs is displayed depending on the Passkey Entry connection.
Figure 8-8 FMP_PXP app Profile screen composition
Table 8-8 FMP_PXP app Profile screen composition
Item Explanation
Set Alert Level Set one of the following as the BLE Device Alert Level.
No Alert/Mid Alert/High Alert
Select Sub-procedure You can read the value for the selected sub-procedure.
Current Alert Level You can read the value set for the current Alert Level.
Pairing setting request of BLE
If you want to set the PasskeyInput
DeviceName as pairs, please enter the
passkey necessary to the device.
6-digit number (000000-999999) is
acceptable only.
If you want the next device to pair,
PasskeyDisplay DeviceName
Please enter the following passkey to Remote Device.
Alert level setting Current Alert level
Sub-Procedure setting
MOVERIO Pro Developer's Guide (Rev.1.5)
132
8.4. Remarks & Restrictions for BLE App Development
■ BLE interface
The BLE interface for the BT-2000 uses an original API that does not support the standard
Android API.
Therefore, when developing an application that uses BLE, use the SDK and original API
provided by Epson.
■ BLE ON/OFF
BLE differs from Bluetooth Legacy in that the ON/OFF switch is not installed on the system (OS)
in BLE.
In applications that use BLE on the BT-2000, design so that the BLE function can be turned
ON/OFF using EPSON original API.
■ BLE API access from multiple applications
Avoid designs that allow multiple BLE applications to access the BLE API at the same time.
Data may not be exchanged depending on the timing.
■ Using the BLE API
We do not recommend designs in which the BLE API is called in the Advertise notification
callback function (onScanResult).
MOVERIO Pro Developer's Guide (Rev.1.5)
133
8.5. Import module
To use EPSON original BLE control API, use SDK for BT-2000 provided by EPSON, and import the
following modules.
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeChipCode;
import android.bluetooth.BluetoothLeErrorCodeDescription;
import android.bluetooth.BluetoothLeGapCallback;
import android.bluetooth.BluetoothLeGapCallback.AddrType;
import android.bluetooth.BluetoothLeGapCallback.AuthType;
import android.bluetooth.BluetoothLeGapEvtAuthStatus;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
import android.bluetooth.BluetoothLeGattService;
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapCallback.PassKeyType;
MOVERIO Pro Developer's Guide (Rev.1.5)
134
8.6. Application interface list
Tables 8-9, 8-10, and 8-11 provide a list of application interfaces.
Table 8-9 android.bluetooth.BluetoothLeAdapterManager for application interface list
NO. Function name Function summary
1 getInstance Acquires instance.
2 isEnable Acquires enable/disable status for BLE.
3 enable Enables BLE.
4 disable Disables BLE.
5 startScan Starts scanning for the BLE.
6 stopScan Stops scanning for the BLE.
7 getDeviceName Acquires the local device name.
8 getBdAddress Acquires the local BD device.
9 connect Starts connecting to the BLE device.
10 connectCancel Cancels connecting to the BLE device.
11 disconnect Disconnects from the BLE device.
12 setAuthType Sets the authentication type.
13 notifyInputPasskey Sets the Pad Key entry.
14 setGapCallback Registers a callback for the GAP function.
15 discPriSrv(char) Searches for the Primary Service for the BLE device.
16 discChar Searches for the Characteristic for the BLE device.
17 discCharDesc Searches for the Characteristic Description for the BLE device.
18 readGatt Acquires the Characteristic Value and the Characteristic
Descriptor.
19 readUuidGatt Acquires the Characteristic Value for the set UUID.
20 writeWithoutRspGatt Writes the Characteristic Value (without a response)
21 writeGatt Writes the Characteristic Value and the Characteristic
Descriptor.
22 confirmation Executes an Indication response.
23 setGattCallback Registers a callback for the GAP function.
MOVERIO Pro Developer's Guide (Rev.1.5)
135
Table 8-10 android.bluetooth.BluetoothLeGapCallback for application interface list
NO. Callback function
name.
Function summary
24 onScanResult Callback function for scan results (Advertise data)
reception.
25 onConnectResult Callback function for connection results reception.
26 onDisconnectResult Callback function for disconnection results reception.
27 onPasskeyInput Callback function for Pass Key input results reception.
28 onPasskeyDisplay Callback function for Pass Key display results reception.
Table 8-11 android.bluetooth.BluetoothLeGattCallback for application interface list
NO. Callback function name. Function summary
29 onDiscPriSrvResult Callback function for search results reception for Primary
Service.
30 onDiscCharResult Callback function for search results reception for
Characteristic.
31 onDiscCharDescResult Callback function for search results reception for
Characteristic Descriptor.
32 onReadGattResult Callback function for acquisition results reception for
Characteristic Value.
33 onReadUuidGattResult Callback function for acquisition results reception for
Characteristic Value.
34 onWriteGattResult Callback for writing results reception for Characteristic
Value.
35 hvxEvt Callback function for reception of Indication/Notification
MOVERIO Pro Developer's Guide (Rev.1.5)
136
8.7. Supported GATT procedure table
The following shows a list of Bluetooth GATT procedures and supported BLE API procedures.
Table 8-12 Supported GATT procedure for BLE API table
GATT Procedure GATT Sub-Procedure Functions that
support BLE API
Server Configuration Exchange MTU Not supported
Primary Service Discovery
Discover All Primary Services discPriSrv(char)
Discover Primary Services By Service UUID discPriSrv(char,
byte[])
Relationship Discovery Find Included Services Not supported
Characteristic Discovery Discover All Characteristic of a Service discChar
Discover All Characteristic by UUID Not supported
Characteristic Descriptor Discovery Discover All Characteristic Descriptors discCharDesc
Characteristic Value Read
Read Characteristic Value readGatt(char)
Read Using Characteristic UUID readUuidGatt
Read Long Characteristic Values readGatt(char, char)
Read Multiple Characteristic Values Not supported
Characteristic Value Write
Write Without Response writeWithoutRspGat
t
Signed Write Without Response Not supported
Write Characteristic Value writeGatt
Write Long Characteristic Values Not supported
Characteristic Value Reliable Writes Not supported
Characteristic Value Notification Notifications BluetoothLeGattCall
back.hvxEvt
Characteristic Value Indication Indications
BluetoothLeGattCall
back.hvxEvt,
confirmation
Characteristic Descriptor Value
Write
Write Characteristic Descriptors writeGatt
Write Long Characteristic Descriptors Not supported
MOVERIO Pro Developer's Guide (Rev.1.5)
137
8.8. Application interface details 8.8.1. getInstance
Function
Acquire instances in the BluetoothLeAdapterManager class.
Format
Parameters
None
Return value
Model Explanation
BluetoothLeAdapterManager Except for NULL: Instances in the
BluetoothLeAdapterManager class.
NULL: Fails to acquire instance.
8.8.2. isEnable
Function
Acquire BLE status (enabled or disabled).
Format
Parameters
None
Return value
Model Explanation
boolean true: BLE enable
false: BLE disable
BluetoothLeAdapterManager BluetoothLeAdapterManager getInstance(void);
boolean isEnable(void);
MOVERIO Pro Developer's Guide (Rev.1.5)
138
8.8.3. enable
Function
Enable BLE.
Format
Parameters
None
Return value
Model Explanation
boolean true: success
false: fail
8.8.4. disable
Function
Disable BLE.
Format
Parameters
None
Return value
Model Explanation
boolean true: success
false: fail
boolean enable(void);
boolean disable(void);
MOVERIO Pro Developer's Guide (Rev.1.5)
139
8.8.5. startScan
Function
Start the BLE scan (Advertise reception).
Format
Parameters
None
Return value
None
Usage method
To receive scan results (Advertise data), you need to register the callback function in
setGapCallback in advance.
The following callback function sends a notification for received Advertise data.
BluetoothLeGapCallback.onScanResult
8.8.6. stopScan
Function
Stop the BLE scan (Advertise reception).
Format
Parameters
None
Return value
None
void startScan(void);
void stopScan(void);
MOVERIO Pro Developer's Guide (Rev.1.5)
140
8.8.7. getDeviceName
Function
Acquire the local device name.
Format
Parameters
None
Return value
Model Explanation
String Except for NULL: local device name.
NULL: Fail
8.8.8. getBdAddress
Function
Acquire the local BD device.
Format
Parameters
None
Return value
Model Explanation
String Except for NULL: local BD device.
(Text strings that include colons in the
format: ”11:22:33:44:55:66”)
NULL: Fail
String getDeviceName(void);
String getBdAddress (void);
MOVERIO Pro Developer's Guide (Rev.1.5)
141
8.8.9. connect
Function
Specify the partner BD address (remote BD address), connection timeout, and the number
of times to retry, and then connect.
Format
Parameter
Model name Explanation
AddrType addrType Remote BD address classification
*See "BD address classification" for more details
String Remote BD address
int timeout Timeout time (ms)
Set from 120 to 32000 ms in increments of 10 ms.
int retryReconnect Number of retry times
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.BaseError.INVALID_PARAM: invalid parameter
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid remote BD address
BluetoothLeChipCode.BaseError.NO_MEM: maximum connections
BluetoothLeChipCode.BaseError.BUSY: system busy status
Usage method
To receive connection processing results, you need to register the callback function in
setGapCallback in advance.
The following callback function sends a notification for connection processing results.
BluetoothLeGapCallback.onConnectResult
BD address classification
Value Explanation
BluetoothLeGapCallback.AddrType.PUBLIC Public
BluetoothLeGapCallback.AddrType.RANDOM_STATIC Random
BluetoothLeGapCallback.AddrType.RANDOM_PRIVATE_RESOLVABLE
BluetoothLeGapCallback.AddrType.RANDOM_PRIVATE_NON_RESOLVABLE
int connect(AddrType addrType, String addr, int timeout, int retryReconnect);
MOVERIO Pro Developer's Guide (Rev.1.5)
142
8.8.10. connectCancel
Function
Connection canceled while connecting to the BLE device.
Format
Parameter
Model name Explanation
None ―
Return value
Model Explanation
Int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
int connectCancel(void);
MOVERIO Pro Developer's Guide (Rev.1.5)
143
8.8.11. disconnect
Function
Specify the partner BD address (remote BD address), connection timeout, and the number
of times to retry, and then connect.
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
* Specify the connection handle (ConnectedHandle) in the
connected status (connStatus) acquired in onConnectResult.
byte hci_status_code Status code
Normally, the following is specified.
BluetoothLeErrorCodeDescription.SigDefinition.
REMOTE_USER_TERMINATED_CONNECTION
* Specify the following if there is a connection parameter that
is not allowed.
BluetoothLeErrorCodeDescription.SigDefinition.
CONN_INTERVAL_UNACCEPTABLE
Return value
Mode
l
Explanation
Int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_PARAM: invalid parameter
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
Usage method
To receive disconnection processing results, you need to register the callback function in
setGapCallback in advance.
The following callback function sends a notification for disconnection processing results.
BluetoothLeGapCallback.onDisconnectResult
int disconnect(char connectedHandle , byte hci_status_code)
MOVERIO Pro Developer's Guide (Rev.1.5)
144
8.8.12. setAuthType
Function
Set authentication classification.
Format
Parameter
Model name Explanation
AuthType authType Authentication classification
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_PARAM: invalid parameter
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
Authentication classification
Value Explanation
BluetoothLeGapCallback.AuthType.JUSTWORKS Omit pin code
BluetoothLeGapCallback.AuthType.PASSKEYENTRY PIN code authentication
boolean setAuthType(AuthType authType);
MOVERIO Pro Developer's Guide (Rev.1.5)
145
8.8.13. notifyInputPasskey
Function
Register a pass key.
Format
Parameter
Model name Explanation
PassKeyType passKeyType Passkey type
String passKey Key string
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_PARAM: invalid parameter
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
Pass key type
Value Explanation
BluetoothLeGapCallback.PassKeyType.NONE None
BluetoothLeGapCallback.PassKeyType.PASSKEY PIN code
int notifyInputPasskey(PassKeyType passKeyType, String passKey);
MOVERIO Pro Developer's Guide (Rev.1.5)
146
8.8.14. setGapCallback
Function
Register the BluetoothLeGapCallback class where the callback function used for GAP
functions is mounted.
Format
Parameter
Model name Explanation
BluetoothLeGapCallback callback Callback class
Return value
None
Callback function used for GAP functions
See the callback function descriptions in 8.8.24 to 8.8.28 for information on the callback
function for GAP functions that can be registered to the BluetoothLeGapCallback class.
void setGapCallback(BluetoothLeGapCallback callback);
MOVERIO Pro Developer's Guide (Rev.1.5)
147
8.8.15. discPriSrv
Function
Start searching the connected BLE device for a Primary Service.
Use format -2 when specifying a UUID and searching for the Primary Service.
Format -1
Format -2
Parameter
Model name Explanation
char connectedHandle Connection handle
char findStartHandle Handle location for starting the search
byte[] uuid UUID for search target
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_PARAM: invalid parameter
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.BUSY: system busy status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid
connection handle
Usage method
To receive search results, you need to register the callback function in setGattCallback in
advance.
The following callback function sends a notification for search results.
BluetoothLeGattCallback.onDiscPriSrvResult
int discPriSrv(char connectedHandle, char findStartHandle);
int discPriSrv(char connectedHandle, char findStartHandle, byte[] uuid);
MOVERIO Pro Developer's Guide (Rev.1.5)
148
8.8.16. discChar
Function
Start searching the connected BLE device for Characteristics.
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
char startHandle Handle location for starting the search
char endHandle Handle location for ending the search
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.BUSY: system busy status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE:invalid connection
handle
Usage method
To receive search results, you need to register the callback function in setGattCallback in
advance.
The following callback function sends a notification for search results.
BluetoothLeGattCallback.onDiscCharResult
int discChar(char connectedHandle, char startHandle, char endHandle);
MOVERIO Pro Developer's Guide (Rev.1.5)
149
8.8.17. discCharDesc
Function
Start searching the connected BLE device for Characteristic Descriptors.
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
char startHandle Handle location for starting the search
char endHandle Handle location for ending the search
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.BUSY: system busy status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
Usage method
To receive search results, you need to register the callback function in setGattCallback in
advance.
The following callback function sends a notification for search results.
BluetoothLeGattCallback.onDiscCharDescResult
int discCharDesc(char connectedHandle, char startHandle, char endHandle);
MOVERIO Pro Developer's Guide (Rev.1.5)
150
8.8.18. readGatt
Function
Start acquiring Characteristic Values/Characteristic Descriptors for the connected BLE
device.
Use format -2 when handling Characteristic Values/Characteristic Descriptors with a long
data length.
Format -1
Format -2
Parameter
Model name Explanation
char connectedHandle Connection handle
char handle Handle location for Characteristic Value
char offset Reading location for the value
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.BUSY: system busy status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
Usage method
To receive search results, you need to register the callback function in setGattCallback in
advance.
The following callback function sends a notification for search results.
BluetoothLeGattCallback.onReadGattResult
int readGatt(char connectedHandle, char handle);
int readGatt(char connectedHandle, char handle, char offset);
MOVERIO Pro Developer's Guide (Rev.1.5)
151
8.8.19. readUuidGatt
Function
Start acquiring Characteristic Values for the connected BLE device according to the
specified UUID.
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
byte[] uuid UUID for acquisition target Characteristic
char startHandle Handle location for starting the search
char endHandle Handle location for ending the search
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.BUSY: system busy status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
Usage method
To receive search results, you need to register the callback function in setGattCallback in
advance.
The following callback function sends a notification for search results.
BluetoothLeGattCallback.onReadUuidGattResult
int readUuidGatt(char connectedHandle,byte[] uuid, char startHandle,
char endHandle);
MOVERIO Pro Developer's Guide (Rev.1.5)
152
8.8.20. writeWithoutRspGatt
Function
Write to for the Characteristic Value specified with the handle.
No result notification through a callback.
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
char handle Handle location for Characteristic Value
byte[] value Written value
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.BUSY: system busy status
BluetoothLeChipCode.BaseError.INVALID_PARAM: invalid parameter
BluetoothLeChipCode.BaseError.DATA_SIZE: exceeded data size
BluetoothLeChipCode.BaseError.NO_TX_BUFFERS: exceeded buffer capacity
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
int writeWithoutRspGatt(char connectedHandle, char handle, byte[] value);
MOVERIO Pro Developer's Guide (Rev.1.5)
153
8.8.21. writeGatt
Function
Write to for the Characteristic Value specified with the handle.
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
char handle Handle location for Characteristic Value
byte[] value Written value
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_ADDR: invalid memory address
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.BaseError.BUSY: system busy status
BluetoothLeChipCode.BaseError.INVALID_PARAM: invalid parameter
BluetoothLeChipCode.BaseError.DATA_SIZE: exceeded data size
BluetoothLeChipCode.BaseError.NO_TX_BUFFERS: exceeded buffer capacity
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
Usage method
To receive search results, you need to register the callback function in setGattCallback in
advance.
The following callback function sends a notification for search results.
BluetoothLeGattCallback.onWriteGattResult
int writeGatt(char connectedHandle, char handle, byte[] value);
MOVERIO Pro Developer's Guide (Rev.1.5)
154
8.8.22. confirmation
Function
Response to Indication.
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
char handle Handle location for Characteristic Value
Return value
Model Explanation
int BluetoothLeChipCode.SUCCESS: success
BluetoothLeChipCode.BaseError.INVALID_STATE: invalid status
BluetoothLeChipCode.STKError.INVALID_CONN_HANDLE: invalid connection
handle
BluetoothLeChipCode.STKError.INVALID_ATTR_HANDLE: invalid attribute
handle
int confirmation(char connectedHandle, char handle);
MOVERIO Pro Developer's Guide (Rev.1.5)
155
8.8.23. setGattCallback
Function
Register the BluetoothLeGattCallback class where the callback function used for GATT
functions is mounted.
Format
Parameter
Model name Explanation
BluetoothLeGattCallback callback Callback class
Return value
None
Callback function for the GATT function
See the callback function descriptions in 8.8.29 to 8.8.35 for information on the callback
function for GATT functions that can be registered to the BluetoothLeGattCallback.
void setGattCallback(BluetoothLeGattCallback callback);
MOVERIO Pro Developer's Guide (Rev.1.5)
156
8.8.24. BluetoothLeGapCallback.onScanResult
Function
Provide an interface for the callback function to receive scan results (Advertise data).
Use format -2 to acquire the scan response and the advertise type.
Related API: startScan/stopScan
Format -1
Format -2
Parameter
Model name Explanation
AddrType addrType Remote BD address classification
String addr Remote BD address
int rssi Received radio wave strength (dBm)
boolean scan_rsp Scan response data
true: Received PDU is SCAN_RSP
false: Received PDU is anything except for SCAN_RSP
AdvType adv_type Advertise type
AdvType.ADV_IND
AdvType.ADV_DIRECT_IND
AdvType.ADV_SCAN_IND
AdvType.ADV_NONCONN_IND
AdvType.SCAN_RSP
AdvType.UNKNOWN
byte[] adv_data Advertise data (31octet)
void onScanResult(AddrType addrType, String addr, int rssi, byte[] adv_data);
void onScanResult(AddrType addrType, String addr, int rssi, boolean scan_rsp,
AdvType adv_type, byte[] adv_data);
MOVERIO Pro Developer's Guide (Rev.1.5)
157
8.8.25. BluetoothLeGapCallback.onConnectResult
Function
Provide an interface for the callback function to receive connection results for BLE.
Related API: connect
Format
Parameter
Model name Explanation
byte response Connection information
BluetoothLeGapEvtConnected
connStatus
Connection complete status
Since connection fails if a CONNECTION_TIMEOUT
occurs, the value is undefined.
BluetoothLeGapEvtAuthStatus
authStatus
※Not supported. Do not use as value is undefined.
Connection information
Connection information
BluetoothLeErrorCodeDescription.SUCCESS
BluetoothLeErrorCodeDescription.SigDefinition.CONNECTION_TIMEOUT
BluetoothLeErrorCodeDescription.SigDefinition.REMOTE_USER_TERMINATED_CONNECTION
BluetoothLeErrorCodeDescription.SigDefinition.CONNECTION_TERMINATED_BY_LOCAL_HOST
BluetoothLeErrorCodeDescription.SigDefinition.LMP_LL_RESPONSE_TIMEOUT
BluetoothLeErrorCodeDescription.SigDefinition.CONN_INTERVAL_UNACCEPTABLE
BluetoothLeErrorCodeDescription.ChipDefinition.AUTHENTICATE_TIME_OUT
BluetoothLeErrorCodeDescription.ChipDefinition.AUTHENTICATE_PDU_INVALID
BluetoothLeErrorCodeDescription.ChipDefinition.CONNECTION_TIMEOUT
BluetoothLeErrorCodeDescription.ChipDefinition.PASSKEY_ENTRY_FAILED
BluetoothLeErrorCodeDescription.ChipDefinition.OUT_OF_BAND_KEY_NOT_AVAILABLE
BluetoothLeErrorCodeDescription.ChipDefinition.AUTHENTICATION_REQUIREMENTS_NOT_MET
BluetoothLeErrorCodeDescription.ChipDefinition.CONFIRM_VALUE_FAILED
BluetoothLeErrorCodeDescription.ChipDefinition.PAIRING_NOT_SUPPORTED
BluetoothLeErrorCodeDescription.ChipDefinition.ENCRYPTION_KEY_SIZE
BluetoothLeErrorCodeDescription.ChipDefinition.UNSUPPORTED_SMP_COMMAND
BluetoothLeErrorCodeDescription.ChipDefinition.UNSPECIFIED_REASON
BluetoothLeErrorCodeDescription.ChipDefinition.TOO_LITTLE_TIME_ELAPSED_SINCE_LAST_ATTEMPT
BluetoothLeErrorCodeDescription.ChipDefinition.INVALID_PARAMETERS
BluetoothLeErrorCodeDescription.ChipDefinition.AUTHENTICATE_API_CALL_ERROR
BluetoothLeErrorCodeDescription.ChipDefinition.RECEIVED_DISCONNECT_IN_AUTHENTICATING
void onConnectResult(byte response, BluetoothLeGapEvtConnected connStatus,
BluetoothLeGapEvtAuthStatus authStatus);
MOVERIO Pro Developer's Guide (Rev.1.5)
158
Connection complete status (class BluetoothLeGapEvtConnected)
Member's name Explanation
char connectedHandle Connection handle
byte addrType BD address classification
byte[] addr BD address
BleConnectParams params Connection parameter
MOVERIO Pro Developer's Guide (Rev.1.5)
159
8.8.26. BluetoothLeGapCallback.onDisconnectResult
Function
Provide an interface for the callback function to receive disconnection results for BLE.
Related API: disconnect
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
byte response Disconnection reason
boolean reconnecting Flag during reconnecting
true: During reconnecting
false: not reconnecting
Disconnection reason
Disconnection reason
BluetoothLeErrorCodeDescription.SigDefinition.CONNECTION_TIMEOUT
BluetoothLeErrorCodeDescription.SigDefinition.CONNECTION_TERMINATED_BY_LOCAL_HOST
BluetoothLeErrorCodeDescription.SigDefinition.LMP_LL_RESPONSE_TIMEOUT
are the main values.
For details on other values,
see "Specification of the Bluetooth System v4.1, Vol. 2, Part D : Error Code Descriptions"
void onDisconnectResult(char connectedHandle, byte response,
boolean reconnecting);
MOVERIO Pro Developer's Guide (Rev.1.5)
160
8.8.27. BluetoothLeGapCallback.onPasskeyInput
Function
Provide an interface for the callback function to confirm pass key input reception.
Format
Parameter
Model name Explanation
PassKeyType passKeyType Pass key type
Pass key type
Value Explanation
BluetoothLeGapCallback.PassKeyType.NONE None
BluetoothLeGapCallback.PassKeyType.PASSKEY PIN code
8.8.28. BluetoothLeGapCallback.onPasskeyDisplay
Function
Provide an interface for the callback function to display pass key reception.
Format
Parameter
Model name Explanation
String passKey Key string
void onPasskeyInput(PassKeyType passKeyType);
void onPasskeyDisplay(String passKey);
MOVERIO Pro Developer's Guide (Rev.1.5)
161
8.8.29. BluetoothLeGattCallback.onDiscPriSrvResult
Function
Provide an interface for the callback function to receive search results for the Primary
Service.
Related API: discPriSrv
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
int status Search results
* Returns the value defined in
BluetoothLeChipCode.GattStatus
BluetoothLeGattService[] data Service information
Search results
BluetoothLeChipCode.GattStatus definition
public static class GattStatus {
/** Success. */
public static final int BLE_GATT_STATUS_SUCCESS = 0x0000;
/** Unknown or not applicable status. */
public static final int BLE_GATT_STATUS_UNKNOWN = 0x0001;
/** ATT Error: Invalid Error Code. */
public static final int BLE_GATT_STATUS_ATTERR_INVALID = 0x0100;
/** ATT Error: Invalid Attribute Handle. */
public static final int BLE_GATT_STATUS_ATTERR_INVALID_HANDLE = 0x0101;
/** ATT Error: Read not permitted. */
public static final int BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED = 0x0102;
/** ATT Error: Write not permitted. */
public static final int BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED = 0x0103;
/** ATT Error: Used in ATT as Invalid PDU. */
public static final int BLE_GATT_STATUS_ATTERR_INVALID_PDU = 0x0104;
/** ATT Error: Authenticated link required. */
public static final int BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION = 0x0105;
/** ATT Error: Used in ATT as Request Not Supported. */
public static final int BLE_GATT_STATUS_ATTERR_REQUEST_NOT_SUPPORTED = 0x0106;
/** ATT Error: Offset specified was past the end of the attribute. */
public static final int BLE_GATT_STATUS_ATTERR_INVALID_OFFSET = 0x0107;
/** ATT Error: Used in ATT as Insufficient Authorization. */
public static final int BLE_GATT_STATUS_ATTERR_INSUF_AUTHORIZATION = 0x0108;
/** ATT Error: Used in ATT as Prepare Queue Full. */
public static final int BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL = 0x0109;
/** ATT Error: Used in ATT as Attribute not found. */
public static final int BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND = 0x010A;
void onDiscPriSrvResult(char connectedHandle, int status ,
BluetoothLeGattService[] data);
MOVERIO Pro Developer's Guide (Rev.1.5)
162
/** ATT Error: Attribute cannot be read or written using read/write blob requests. */
public static final int BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_LONG = 0x010B;
/** ATT Error: Encryption key size used is insufficient. */
public static final int BLE_GATT_STATUS_ATTERR_INSUF_ENC_KEY_SIZE = 0x010C;
/** ATT Error: Invalid value size. */
public static final int BLE_GATT_STATUS_ATTERR_INVALID_ATT_VAL_LENGTH = 0x010D;
/** ATT Error: Very unlikely error. */
public static final int BLE_GATT_STATUS_ATTERR_UNLIKELY_ERROR = 0x010E;
/** ATT Error: Encrypted link required. */
public static final int BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION = 0x010F;
/** ATT Error: Attribute type is not a supported grouping attribute. */
public static final int BLE_GATT_STATUS_ATTERR_UNSUPPORTED_GROUP_TYPE = 0x0110;
/** ATT Error: Encrypted link required. */
public static final int BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES = 0x0111;
/** ATT Error: Reserved for Future Use range #1 begin. */
public static final int BLE_GATT_STATUS_ATTERR_RFU_RANGE1_BEGIN = 0x0112;
/** ATT Error: Reserved for Future Use range #1 end. */
public static final int BLE_GATT_STATUS_ATTERR_RFU_RANGE1_END = 0x017F;
/** ATT Error: Application range begin. */
public static final int BLE_GATT_STATUS_ATTERR_APP_BEGIN = 0x0180;
/** ATT Error: Application range end. */
public static final int BLE_GATT_STATUS_ATTERR_APP_END = 0x019F;
/** ATT Error: Reserved for Future Use range #2 begin. */
public static final int BLE_GATT_STATUS_ATTERR_RFU_RANGE2_BEGIN = 0x01A0;
/** ATT Error: Reserved for Future Use range #2 end. */
public static final int BLE_GATT_STATUS_ATTERR_RFU_RANGE2_END = 0x01DF;
/** ATT Error: Reserved for Future Use range #3 begin. */
public static final int BLE_GATT_STATUS_ATTERR_RFU_RANGE3_BEGIN = 0x01E0;
/** ATT Error: Reserved for Future Use range #3 end. */
public static final int BLE_GATT_STATUS_ATTERR_RFU_RANGE3_END = 0x01FC;
/** ATT Common Profile and Service Error: Client Characteristic Configuration Descriptor improperly
configured. */
public static final int BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR = 0x01FD;
/** ATT Common Profile and Service Error: Procedure Already in Progress. */
public static final int BLE_GATT_STATUS_ATTERR_CPS_PROC_ALR_IN_PROG = 0x01FE;
/** ATT Common Profile and Service Error: Out Of Range. */
public static final int BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE = 0x01FF;
};
Service information (class BluetoothLeGattService)
Member's name Explanation
byte[] uuid UUID (16bit only)
char startHandle Start handle location
char endHandle End handle location
MOVERIO Pro Developer's Guide (Rev.1.5)
163
8.8.30. BluetoothLeGattCallback.onDiscCharResult
Function
Provide an interface for the callback function to receive search results for the
Characteristic.
Related API: discChar
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
int status Search results
* Returns the value defined in
BluetoothLeChipCode.GattStatus
BluetoothLeGattChar[] data Characteristic information
Characteristic information (class BluetoothLeGattChar)
Member's name Explanation
byte[] uuid UUID (16bit only)
char handleDecl Handle for Characteristic Declaration
char handleValue Handle for Characteristic Value
CharacteristicProperties properties Characteristic setting information
Characteristic setting information (class BluetoothLeGattChar.CharacteristicProperties)
Function name Explanation
boolean IsBrodcast() Determine if anything is broadcast
boolean IsRead() Determine readGatt/readUuidGatt
IsWriteWoResp() Determine writeWithoutRspGatt
IsWrite() Determine writeGatt
IsNofify() Determine Notification
IsIndicate() Determine Indication
void onDiscCharResult(char connectedHandle, int status,
BluetoothLeGattChar[] data);
MOVERIO Pro Developer's Guide (Rev.1.5)
164
8.8.31. BluetoothLeGattCallback.onDiscCharDescResult
Function
Provide an interface for the callback function to receive search results for the Characteristic
Descriptor.
Related API: discCharDesc
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
int status Search results
* Returns the value defined in
BluetoothLeChipCode.GattStatus
BluetoothLeGattDesc[] data Characteristic Descriptor information
Characteristic Descriptor information (class BluetoothLeGattDesc)
Member's name Explanation
byte[] uuid Characteristic Descriptor UUID
char handle Handle for Characteristic Descriptor
void onDiscCharDescResult(char connectedHandle, int status,
BluetoothLeGattDesc[] data);
MOVERIO Pro Developer's Guide (Rev.1.5)
165
8.8.32. BluetoothLeGattCallback.onReadGattResult
Function
Provide an interface for the callback function for acquisition results reception of
Characteristic Value using readGatt API.
Related API: readGatt
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
int status Search results
* Returns the value defined in
BluetoothLeChipCode.GattStatus
BluetoothLeGattEvtReadRsp data Read Response data
Read Response data (class BluetoothLeGattEvtReadRsp)
Member's name Explanation
byte[] data Read Response data
char handle Handle
char offset Data offset
void onReadGattResult(char connectedHandle, int status,
BluetoothLeGattEvtReadRsp data);
MOVERIO Pro Developer's Guide (Rev.1.5)
166
8.8.33. BluetoothLeGattCallback.onReadUuidGattResult
Function
Provide an interface for the callback function for acquisition results reception of
Characteristic Value using readUuidGatt API.
Related API: readUuidGatt
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
int status Search results
* Returns the value defined in
BluetoothLeChipCode.GattStatus
byte[] data Characteristic Value data
void onReadUuidGattResult(char connectedHandle, int status, byte[] data);
MOVERIO Pro Developer's Guide (Rev.1.5)
167
8.8.34. BluetoothLeGattCallback.onWriteGattResult
Function
Provide an interface for the callback function for writing results reception of Characteristic
Value using writeGattRes API.
Related API: writeGattRes
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
int status Search results
* Returns the value defined in
BluetoothLeChipCode.GattStatus
BluetoothLeGattEvtWriteRsp data Write Response data
Write Response data (class BluetoothLeGattEvtWriteRsp)
Member's name Explanation
byte[] data Write data
char handle Handle
char offset Data offset
byte writeOp Write operation code
void onWriteGattResult(char connectedHandle, int status,
BluetoothLeGattEvtWriteRsp data);
MOVERIO Pro Developer's Guide (Rev.1.5)
168
8.8.35. BluetoothLeGattCallback.hvxEvt
Function
Provide an interface for the callback function to receive Indication/Notification using
confirmation API.
Related API: confirmation
Format
Parameter
Model name Explanation
char connectedHandle Connection handle
int status Search results
* Returns the value defined in
BluetoothLeChipCode.GattStatus
hvxEvtType type Indication/Notification classification
byte[] data Characteristic handle value
void hvxEvt(char connectedHandle, int status, char handle,
hvxEvtType type, byte[] data);
MOVERIO Pro Developer's Guide (Rev.1.5)
169
8.9. BLE Processing Sample Code
When developing a BLE app, describe the sample code used in the BLE API.
8.9.1. Enabling BLE
Call isEnable() and acquire the current status.
Since BLE is disabled when this function returns false, call enable() to enable BLE.
// Instance acquisition for the BLE manager class
BluetoothLeAdapterManager mManager = BluetoothLeAdapterManager.getInstance();
if ( ! mManager.isEnable() ) {
// BLE Off
if ( ! mManager.enable() ) {
//Error processing: display error message for BLE-On failure
}
} else {
// BLE On
}
8.9.2. Disabling BLE
Call isEnable() and acquire the current status.
Since BLE is enabled when this function returns true, call disable() to disable BLE.
// Instance acquisition for the BLE manager class
BluetoothLeAdapterManager mManager = BluetoothLeAdapterManager.getInstance();
if ( mManager.isEnable() ) {
// BLE On
if ( ! mManager.disable() ) {
//Error processing: display error message for BLE-Off failure
}
} else {
// BLE Off
}
MOVERIO Pro Developer's Guide (Rev.1.5)
170
8.9.3. Registering scan start and callback
To start the Beacon function, register the callback function using setGapCallback() to receive
Advertise from the Beacon device, and start scanning using startScan().
import android.widget.Toast;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GAP function provided
mManager.setGapCallback(mLeGapCallback);
}
private void scanLe(final boolean enable) {
if ( enable ) {
//Start scanning
mManager.starScan();
} else {
//Stop scanning
mManager.stopScan();
}
}
Receive scan results using the following callback, and output the received signal strength to a
log.
private BluetoothLeGapCallback mLeGapCallback = new BluetoothLeGapCallback(){
@Override
public void onScanResult(AddrType addrType, String addr, int rssi
, byte[] adv_data) {
Log.i(“DEBUG”, “rssi=” + rssi);
}
};
}
MOVERIO Pro Developer's Guide (Rev.1.5)
171
8.9.4. Connecting and Disconnecting BLE
The following provides an example of the processing for connecting and disconnecting BLE.
Connecting: Enable GAP callback registration and scanning before connecting. Connect using
information in (addrType, addr) in the scan results (onScanResult()).
Disconnecting: Disconnect using the connection handle (connStatus.connectedHandle) in the
connection results (onConnectResult()).
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
private boolean mConnectingFlg = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GAP function provided
mManager.setGapCallback (mLeGapCallback);
}
private void connectLe(final boolean enable) {
if ( enable ) {
//BLE connect
//Set the addrType and addr acquired in onScanResult
mManager.connect(addrType, addr, 1000, 0);
} else {
//BLE disconnect
//Set the connection handle ConnectedHandle in connected event status
connStatus acquired in onConnectResult
mManager.disconnect(ConnectedHandle,
REMOTE_USER_TERMINATED_CONNECTION);
}
}
MOVERIO Pro Developer's Guide (Rev.1.5)
172
Use the following callback to output logs when connecting and disconnecting.
private BluetoothLeGapCallback mLeGapCallback = new BluetoothLeGapCallback() {
@Override
public void onConnectResult(byte response,
final BluetoothLeGapEvtConnected connStatus,
BluetoothLeGapEvtAuthStatus authStatus) {
Log.i(“DEBUG”, “connectedHandle=“
+ connStatus.connectedHandle);
};
@Override
public void onDisconnectResult(char connectedHandle,
byte response, boolean reconnecting) {
Log.i(“DEBUG”, “Disconnect“);
};
};
MOVERIO Pro Developer's Guide (Rev.1.5)
173
8.9.5. Searching for Primary Service
You can search for the Primary Service on a connected BLE device by executing the callback
function setGattCallback() and Primary Service search using discPriSrv().
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GATT function provided
mManager.setGattCallback(mLeGattCallback);
//Searching for Primary Service
//Set the connection handle ConnectedHandle in connected event status
connStatus acquired in onConnectResult
mManager.discPriSrv(ConnectedHandle, (char) 1);
}
Use the following callback to output logs when a Primary Service is detected.
private BluetoothLeGattCallback mLeGattCallback =
new BluetoothLeGattCallback() {
@Override
public void onDiscPriSrvResult(char connectedHandle,
int status, BluetoothLeGattService[] data) {
for (int cnt=0; cnt<data.length; cnt++) {
Log.i(“DEBUG”, “startHandle=” +
data[cnt].startHandle + “ endHandle=” +
data[cnt].endHandle);
}
};
};
}
MOVERIO Pro Developer's Guide (Rev.1.5)
174
8.9.6. Searching for Characteristic
You can search for the Characteristics on a connected BLE device by executing the callback
function setGattCallback() and Characteristic search using discChar().
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GATT function provided
mManager.setGattCallback(mLeGattCallback);
//Searching for Characteristic
//Set StartHandle and EndHandle from the Service information
acquired in onDiscPriSrvResult
mManager.discChar (ConnectedHandle, StartHandle, EndHandle);
}
Use the following callback to output logs when a Characteristic is detected.
private BluetoothLeGattCallback mLeGattCallback =
new BluetoothLeGattCallback() {
@Override
public void onDiscCharResult(char connectedHandle,
int status, BluetoothLeGattChar[] data) {
for (int cnt=0; cnt<data.length; cnt++) {
Log.i(“DEBUG”, “HandleValue=” +
data[cnt].handleValue+ “ uuid=” +
data[cnt].uuid);
}
};
};
}
MOVERIO Pro Developer's Guide (Rev.1.5)
175
8.9.7. Searching for Characteristic Descriptor
You can search for the Characteristic Descriptor on a connected BLE device by
executing the callback function setGattCallback() and Characteristic Descriptor search using
discCharDesc().
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GATT function provided
mManager.setGattCallback(mLeGattCallback);
//Searching for Characteristic Descriptor
//Set StartHandle and EndHandle from the acquired onDiscPriSrvResult
mManager.discCharDesc (ConnectedHandle, StartHandle, EndHandle);
}
Use the following callback to output logs when a Characteristic Descriptor is detected.
private BluetoothLeGattCallback mLeGattCallback =
new BluetoothLeGattCallback() {
@Override
public void onDiscCharDescResult (char connectedHandle,
int status, BluetoothLeGattChar[] data) {
for (int cnt=0; cnt<data.length; cnt++) {
Log.i(“DEBUG”, “HandleValue=” + data[cnt].handleValue
+ “ CharacteristicUuid=” + data[cnt].uuid);
}
};
};
}
MOVERIO Pro Developer's Guide (Rev.1.5)
176
8.9.8. Acquiring Characteristic Value by Specifying a Handle
You can acquire the Characteristic Value on a connected BLE device byexecuting the callback
function setGattCallback() and Characteristic Value acquisition using readGatt().
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GATT function provided
mManager.setGattCallback(mLeGattCallback);
//Acquire (READ) Characteristic Value
//Set the handle HandleValue in Characteristic Value from the Characteristic
//information acquired in onDiscCharResult()
mManager.readGatt(ConnectedHandle, HandleValue)
}
Use the following callback to output logs when a Characteristic Value is acquired.
private BluetoothLeGattCallback mLeGattCallback =
new BluetoothLeGattCallback() {
@Override
public void onReadGattResult (
char status, BluetoothLeGattEvtReadRsp data) {
Log.i(“DEBUG”, “Characteristic Value=” + data.data);
}
};
}
MOVERIO Pro Developer's Guide (Rev.1.5)
177
8.9.9. Acquiring Characteristic Value by Specifying a UUID
You can acquire the Characteristic Value on a connected BLE device by specifying a UUID. To do
this execute the callback function registration using setGattCallback() and Characteristic Value
acquisition using readUuidGatt().
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GATT function provided
mManager.setGattCallback(mLeGattCallback);
//Acquire (READ) Characteristic Value
//Set StartHandle and EndHandle from the acquired onDiscPriSrvResult
//Set the UUID for the Characteristic information acquired in
// onDiscCharDescResult
mManager.readUuidGatt(ConnectedHandle, Uuid, StartHandle, EndHandle);
}
Use the following callback to output logs when a Characteristic Value is acquired.
private BluetoothLeGattCallback mLeGattCallback =
new BluetoothLeGattCallback() {
@Override
onReadUuidGattResult(char connectedHandle, int status,
BluetoothLeGattEvtReadUuidRsp[] data) {
Log.i(“DEBUG”, “Characteristic Value=” + data.data);
}
};
}
MOVERIO Pro Developer's Guide (Rev.1.5)
178
8.9.10. Writing a Characteristic Value
You can write the Characteristic Value to a connected BLE device by
executing the callback function setGattCallback() and Characteristic Value writing using
writeGatt().
import android.bluetooth.BluetoothLeAdapterManager;
import android.bluetooth.BluetoothLeGapEvtConnected;
import android.bluetooth.BluetoothLeGattCallback;
public class MainActivity extends Activity {
private BluetoothLeAdapterManager mManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Instance acquisition for the BLE manager class
mManager = BluetoothLeAdapterManager.getInstance();
//Register a callback for the GATT function provided
mManager.setGattCallback(mLeGattCallback);
//Writing a Characteristic Value
//Set the handle HandleValue in Characteristic Value from the Characteristic
// information acquired in onDiscCharResult()
mManager.writeGatt(ConnectedHandle, HandleValue, 0x01);
}
Use the following callback to output logs when a Characteristic Value is written.
private BluetoothLeGattCallback mLeGattCallback =
new BluetoothLeGattCallback() {
@Override
public void onWriteGattResult(char connectedHandle, int status,
BluetoothLeGattEvtWriteRsp data) {
//Since the value written in writeGatt is returned for confirmation,
// no processing is performed
Log.i(“DEBUG”, “write ok”);
}
};
}
MOVERIO Pro Developer's Guide (Rev.1.5)
179
8.10. Recording using Bluetooth headsets
In order to record with the application using the Bluetooth headset, implement the following
process.
■Permission setting
Set the following permissions in AndroidManifest.xml.
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
■Implementation in source code
Implement the next source code in the java file.
private AudioManager mAudioManager;
// do this after pairing is completed
mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
mAudioManager.startBluetoothSco();
mAudioManager.setBluetoothScoOn(true);
■Precaution
Please do the above processing after pairing is completed, otherwise recording is not possible.
MOVERIO Pro Developer's Guide (Rev.1.5)
180
9. Power control
MOVERIO Pro Developer's Guide (Rev.1.5)
181
9.1. Power control summary
You have two batteries in the BT-2000 and acquire power supply information.
■ Power supply information
The following power supply information types are defined in the Android BatteryManager class.
Power supply type Battery
information
type
Constant
Power status Overall status of batteries
A/B
int EXTRA_STATUS
Amount of power
remaining
Amount of power remaining
in batteries A/B [%]
int EXTRA_LEVEL
AC adapter connection Info. on AC adapter
connected/disconnected
int EXTRA_PLUGGED
Battery A status Status String EXTRA_STATUS_A
Battery A installed Battery installed boolean EXTRA_PRESENT_A
Amount of power
remaining in battery A
Power remaining [%] int EXTRA_LEVEL_A
Battery A current Current [mA] int EXTRA_CURRENT_A
Battery A voltage Voltage [mV] int EXTRA_VOLTAGE_A
Battery A temperature Temperature [deg C] int EXTRA_TEMPERATURE_A
Battery B status Status String EXTRA_STATUS_B
Battery B installed Battery installed boolean EXTRA_PRESENT_B
Amount of power
remaining in battery B
Power remaining [%] int EXTRA_LEVEL_B
Battery B current Current [mA] int EXTRA_CURRENT_B
Battery B voltage Voltage [mV] int EXTRA_VOLTAGE_B
Battery B temperature Temperature [deg C] int EXTRA_TEMPERATURE_B
MOVERIO Pro Developer's Guide (Rev.1.5)
182
9.2. Acquiring Battery Information
Use the Filter intent broadcast by the operating system, and acquire the battery information.
Usage examples are displayed below.
■ Register the receiver of the battery information broadcast by the app
IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); registerReceiver(mBroadcastReceiver, filter);
■ Acquire broadcast battery information
Example: Acquiring the amount of power remaining, status, and installation status for battery A
@Override public void onReceive(Context context, Intent intent){ int level_a = intent.getIntExtra(BatteryManager.EXTRA_LEVEL_A, 0); String status_a = intent.getStringExtra(BatteryManager.EXTRA_STATUS_A); boolean present_a = intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT_A, false);