Android Wear support added to UART profile

This commit is contained in:
Aleksander Nowakowski
2015-09-17 14:09:48 +02:00
parent a0837c8192
commit 981f8d487c
111 changed files with 4757 additions and 147 deletions

View File

@@ -0,0 +1,28 @@
<!--
~ 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.
-->
<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>

View File

@@ -0,0 +1,150 @@
/*************************************************************************************************************************************************
* 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 + ")";
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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.utility;
import android.util.Log;
import no.nordicsemi.android.nrftoolbox.common.BuildConfig;
public class DebugLogger {
public static void v(final String tag, final String text) {
if (BuildConfig.DEBUG)
Log.v(tag, text);
}
public static void d(final String tag, final String text) {
if (BuildConfig.DEBUG) {
Log.d(tag, text);
}
}
public static void i(final String tag, final String text) {
if (BuildConfig.DEBUG)
Log.i(tag, text);
}
public static void w(final String tag, final String text) {
if (BuildConfig.DEBUG) {
Log.w(tag, text);
}
}
public static void e(final String tag, final String text) {
if (BuildConfig.DEBUG)
Log.e(tag, text);
}
public static void e(final String tag, final String text, final Throwable e) {
if (BuildConfig.DEBUG)
Log.e(tag, text, e);
}
public static void wtf(final String tag, final String text) {
if (BuildConfig.DEBUG) {
Log.wtf(tag, text);
}
}
public static void wtf(final String tag, final String text, final Throwable e) {
if (BuildConfig.DEBUG) {
Log.wtf(tag, text, e);
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.wearable.common;
/**
* Constants used for exchanging data and messages between handheld and Android Wear devices.
*/
public final class Constants {
/** Base path for all messages between the handheld and wearable. */
private static final String BASE_PATH = "/nrftoolbox";
/** Action sent from a wearable to disconnect from a device. It must have the profile name set as data. */
public static final String ACTION_DISCONNECT = BASE_PATH + "/disconnect";
/**
* Constants for the UART profile.
*/
public static final class UART {
/** The profile name. */
public static final String PROFILE = "uart";
/** Base path for UART messages between the handheld and wearable. */
private static final String PROFILE_PATH = BASE_PATH + "/uart";
/** An UART device is connected. */
public static final String DEVICE_CONNECTED = PROFILE_PATH + "/connected";
/** An UART device is disconnected. */
public static final String DEVICE_DISCONNECTED = PROFILE_PATH + "/disconnected";
/** An UART device is disconnected due to a link loss. */
public static final String DEVICE_LINKLOSS = PROFILE_PATH + "/link_loss";
/** Path used for syncing UART configurations. */
public static final String CONFIGURATIONS = PROFILE_PATH + "/configurations";
/** An action with a command was clicked. */
public static final String COMMAND = PROFILE_PATH + "/command";
public static final class Configuration {
public static final String NAME = "name";
public static final String COMMANDS = "commands";
public static final class Command {
public static final String ICON_ID = "icon_id";
public static final String MESSAGE = "message";
}
}
}
}

View File

@@ -0,0 +1,26 @@
<!--
~ 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.
-->
<resources>
<string name="bonding">Bonding with the device&#8230;</string>
<string name="bonded">The device is now bonded.</string>
</resources>