Skip to content

Commit 4ca632e

Browse files
committed
Version 1.16.1
DFU Library imported from jcenter. Few other changes.
1 parent 3ed75c5 commit 4ca632e

File tree

16 files changed

+130
-88
lines changed

16 files changed

+130
-88
lines changed

.idea/gradle.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.iml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@
7171
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
7272
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
7373
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
74-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
75-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.0.1/jars" />
76-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.8.0/jars" />
77-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wearable/7.8.0/jars" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/jars" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.1.0/jars" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.0/jars" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.0/jars" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/8.3.0/jars" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.3.0/jars" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wearable/8.3.0/jars" />
7881
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/no.nordicsemi.android.support.v18/scanner/0.1.1/jars" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/no.nordicsemi.android/dfu/0.6/jars" />
7983
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/no.nordicsemi.android/log/2.0.0/jars" />
8084
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
8185
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
@@ -94,19 +98,21 @@
9498
</content>
9599
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
96100
<orderEntry type="sourceFolder" forTests="false" />
101+
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
102+
<orderEntry type="library" exported="" name="design-23.1.0" level="project" />
103+
<orderEntry type="library" exported="" name="play-services-wearable-8.3.0" level="project" />
104+
<orderEntry type="library" exported="" name="log-2.0.0" level="project" />
97105
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
98-
<orderEntry type="library" exported="" name="design-23.0.1" level="project" />
99-
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
106+
<orderEntry type="library" exported="" name="dfu-0.6" level="project" />
107+
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.0" level="project" />
100108
<orderEntry type="library" exported="" name="stax-1.2.0" level="project" />
101-
<orderEntry type="library" exported="" name="play-services-wearable-7.8.0" level="project" />
109+
<orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
110+
<orderEntry type="library" exported="" name="play-services-base-8.3.0" level="project" />
102111
<orderEntry type="library" exported="" name="scanner-0.1.1" level="project" />
103112
<orderEntry type="library" exported="" name="achartengine-1.1.0" level="project" />
104113
<orderEntry type="library" exported="" name="simple-xml-2.7.1" level="project" />
105-
<orderEntry type="library" exported="" name="log-2.0.0" level="project" />
106-
<orderEntry type="library" exported="" name="play-services-base-7.8.0" level="project" />
107-
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
108-
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
114+
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
115+
<orderEntry type="library" exported="" name="play-services-basement-8.3.0" level="project" />
109116
<orderEntry type="module" module-name="common" exported="" />
110-
<orderEntry type="module" module-name="dfu" exported="" />
111117
</component>
112118
</module>

app/build.gradle

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "no.nordicsemi.android.nrftoolbox"
99
minSdkVersion 18
1010
targetSdkVersion 23
11-
versionCode 39
12-
versionName "1.16.0"
11+
versionCode 40
12+
versionName "1.16.1"
1313
}
1414
buildTypes {
1515
release {
@@ -21,17 +21,25 @@ android {
2121

2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
compile 'com.google.android.gms:play-services-wearable:7.8.0'
25-
compile 'com.android.support:appcompat-v7:23.0.1'
26-
compile 'com.android.support:design:23.0.1'
24+
compile 'com.google.android.gms:play-services-wearable:8.3.0'
25+
compile 'com.android.support:appcompat-v7:23.1.0'
26+
compile 'com.android.support:design:23.1.0'
2727
compile 'no.nordicsemi.android.support.v18:scanner:0.1.1'
2828
compile 'no.nordicsemi.android:log:2.0.0'
2929
compile('org.simpleframework:simple-xml:2.7.1') {
3030
exclude group: 'stax', module: 'stax-api'
3131
exclude group: 'xpp3', module: 'xpp3'
3232
}
3333
compile files('libs/achartengine-1.1.0.jar')
34-
compile project(':dfu')
3534
compile project(':common')
3635
wearApp project(':wear')
36+
37+
// The DFU Library is imported automatically from jcenter.
38+
compile 'no.nordicsemi.android:dfu:0.6'
39+
// If you want to make some changes in the DFU Library, clone the https://github.com/NordicSemiconductor/Android-DFU-Library project into DFULibrary folder,
40+
// add it as a module in Project Structure and uncomment the following line:
41+
42+
// compile project(':dfu')
43+
44+
// Also uncomment selected lines in settings.gradle
3745
}

app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManager.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -862,24 +862,6 @@ private void nextRequest() {
862862
}
863863
}
864864
}
865-
866-
/**
867-
* Converts the connection state to String value
868-
* @param state the connection state
869-
* @return state as String
870-
*/
871-
private String stateToString(final int state) {
872-
switch (state) {
873-
case BluetoothProfile.STATE_CONNECTED:
874-
return "CONNECTED";
875-
case BluetoothProfile.STATE_CONNECTING:
876-
return "CONNECTING";
877-
case BluetoothProfile.STATE_DISCONNECTING:
878-
return "DISCONNECTING";
879-
default:
880-
return "DISCONNECTED";
881-
}
882-
}
883865
}
884866

885867
private static final int PAIRING_VARIANT_PIN = 0;
@@ -890,7 +872,7 @@ private String stateToString(final int state) {
890872
private static final int PAIRING_VARIANT_DISPLAY_PIN = 5;
891873
private static final int PAIRING_VARIANT_OOB_CONSENT = 6;
892874

893-
private String pairingVariantToString(final int variant) {
875+
protected String pairingVariantToString(final int variant) {
894876
switch (variant) {
895877
case PAIRING_VARIANT_PIN:
896878
return "PAIRING_VARIANT_PIN";
@@ -911,7 +893,7 @@ private String pairingVariantToString(final int variant) {
911893
}
912894
}
913895

914-
private String bondStateToString(final int state) {
896+
protected String bondStateToString(final int state) {
915897
switch (state) {
916898
case BluetoothDevice.BOND_NONE:
917899
return "BOND_NONE";
@@ -924,7 +906,7 @@ private String bondStateToString(final int state) {
924906
}
925907
}
926908

927-
private String getWriteType(final int type) {
909+
protected String getWriteType(final int type) {
928910
switch (type) {
929911
case BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT:
930912
return "WRITE REQUEST";
@@ -936,4 +918,22 @@ private String getWriteType(final int type) {
936918
return "UNKNOWN: " + type;
937919
}
938920
}
921+
922+
/**
923+
* Converts the connection state to String value
924+
* @param state the connection state
925+
* @return state as String
926+
*/
927+
protected String stateToString(final int state) {
928+
switch (state) {
929+
case BluetoothProfile.STATE_CONNECTED:
930+
return "CONNECTED";
931+
case BluetoothProfile.STATE_CONNECTING:
932+
return "CONNECTING";
933+
case BluetoothProfile.STATE_DISCONNECTING:
934+
return "DISCONNECTING";
935+
default:
936+
return "DISCONNECTED";
937+
}
938+
}
939939
}

app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityManager.java

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Queue;
4040
import java.util.UUID;
4141

42+
import no.nordicsemi.android.error.GattError;
4243
import no.nordicsemi.android.log.Logger;
4344
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
4445
import no.nordicsemi.android.nrftoolbox.parser.AlertLevelParser;
@@ -102,7 +103,7 @@ private void addLinklossService() {
102103
* This method must be called in UI thread. It works fine on Nexus devices but if called from other thread (f.e. from onServiceAdded in gatt server callback) it hangs the app.
103104
*/
104105
final BluetoothGattCharacteristic linklossAlertLevel = new BluetoothGattCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID, BluetoothGattCharacteristic.PROPERTY_WRITE
105-
| BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_WRITE);
106+
| BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_WRITE | BluetoothGattCharacteristic.PERMISSION_READ);
106107
linklossAlertLevel.setValue(HIGH_ALERT);
107108
final BluetoothGattService linklossService = new BluetoothGattService(LINKLOSS_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
108109
linklossService.addCharacteristic(linklossAlertLevel);
@@ -122,7 +123,7 @@ public void run() {
122123
if (IMMEDIATE_ALERT_SERVICE_UUID.equals(service.getUuid()))
123124
addLinklossService();
124125
else {
125-
Logger.i(mLogSession, "[Proximity Server] Gatt server started");
126+
Logger.i(mLogSession, "[Server] Gatt server started");
126127
ProximityManager.super.connect(mDeviceToConnect);
127128
mDeviceToConnect = null;
128129
}
@@ -132,32 +133,56 @@ public void run() {
132133

133134
@Override
134135
public void onConnectionStateChange(final BluetoothDevice device, final int status, final int newState) {
135-
if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothGatt.STATE_CONNECTED) {
136-
Logger.i(mLogSession, "[Server] Device with address " + device.getAddress() + " connected");
137-
} else {
138-
if (newState == BluetoothGatt.STATE_DISCONNECTED) {
139-
Logger.i(mLogSession, "[Server] Device disconnected");
136+
Logger.d(mLogSession, "[Server callback] Connection state changed with status: " + status + " and new state: " + stateToString(newState) + " (" + newState + ")");
137+
if (status == BluetoothGatt.GATT_SUCCESS) {
138+
if (newState == BluetoothGatt.STATE_CONNECTED) {
139+
Logger.i(mLogSession, "[Server] Device with address " + device.getAddress() + " connected");
140140
} else {
141-
Logger.e(mLogSession, "[Server] Connection state changed with error " + status);
141+
Logger.i(mLogSession, "[Server] Device disconnected");
142142
}
143+
} else {
144+
Logger.e(mLogSession, "[Server] Error " + status + " (0x" + Integer.toHexString(status) + "): " + GattError.parseConnectionError(status));
143145
}
144146
}
145147

146148
@Override
147149
public void onCharacteristicReadRequest(final BluetoothDevice device, final int requestId, final int offset, final BluetoothGattCharacteristic characteristic) {
148-
Logger.i(mLogSession, "[Server] Read request for characteristic " + characteristic.getUuid() + " (requestId = " + requestId + ", offset = " + offset + ")");
149-
Logger.v(mLogSession, "[Server] Sending response: SUCCESS");
150-
Logger.d(mLogSession, "[Server] sendResponse(GATT_SUCCESS, " + ParserUtils.parse(characteristic.getValue()) + ")");
151-
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, characteristic.getValue());
150+
Logger.d(mLogSession, "[Server callback] Read request for characteristic " + characteristic.getUuid() + " (requestId=" + requestId + ", offset=" + offset + ")");
151+
Logger.i(mLogSession, "[Server] READ request for characteristic " + characteristic.getUuid() + " received");
152+
153+
byte[] value = characteristic.getValue();
154+
if (value != null && offset > 0) {
155+
byte[] offsetValue = new byte[value.length - offset];
156+
System.arraycopy(value, offset, offsetValue, 0, offsetValue.length);
157+
value = offsetValue;
158+
}
159+
if (value != null)
160+
Logger.d(mLogSession, "server.sendResponse(GATT_SUCCESS, value=" + ParserUtils.parse(value) + ")");
161+
else
162+
Logger.d(mLogSession, "server.sendResponse(GATT_SUCCESS, value=null)");
163+
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value);
164+
Logger.v(mLogSession, "[Server] Response sent");
152165
}
153166

154167
@Override
155168
public void onCharacteristicWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattCharacteristic characteristic, final boolean preparedWrite,
156169
final boolean responseNeeded, final int offset, final byte[] value) {
157-
Logger.i(mLogSession, "[Server] Write request to characteristic " + characteristic.getUuid() + " (requestId = " + requestId + ", value = " + ParserUtils.parse(value) + ", offset = " + offset + ")");
158-
characteristic.setValue(value);
170+
Logger.d(mLogSession, "[Server callback] Write request to characteristic " + characteristic.getUuid()
171+
+ " (requestId=" + requestId + ", prepareWrite=" + preparedWrite + ", responseNeeded=" + responseNeeded + ", offset=" + offset + ", value=" + ParserUtils.parse(value) + ")");
172+
final String writeType = !responseNeeded ? "WRITE NO RESPONSE" : "WRITE COMMAND";
173+
Logger.i(mLogSession, "[Server] " + writeType + " request for characteristic " + characteristic.getUuid() + " received, value: " + ParserUtils.parse(value));
159174

160-
if (value != null && value.length == 1) { // small validation
175+
if (offset == 0) {
176+
characteristic.setValue(value);
177+
} else {
178+
final byte[] currentValue = characteristic.getValue();
179+
final byte[] newValue = new byte[currentValue.length + value.length];
180+
System.arraycopy(currentValue, 0, newValue, 0, currentValue.length);
181+
System.arraycopy(value, 0, newValue, offset, value.length);
182+
characteristic.setValue(newValue);
183+
}
184+
185+
if (!preparedWrite && value != null && value.length == 1) { // small validation
161186
if (value[0] != NO_ALERT[0]) {
162187
Logger.a(mLogSession, "[Server] Immediate alarm request received: " + AlertLevelParser.parse(characteristic));
163188
mCallbacks.onAlarmTriggered();
@@ -166,39 +191,44 @@ public void onCharacteristicWriteRequest(final BluetoothDevice device, final int
166191
mCallbacks.onAlarmStopped();
167192
}
168193
}
169-
if (responseNeeded) {
170-
Logger.v(mLogSession, "[Server] Sending response: SUCCESS");
171-
Logger.d(mLogSession, "[Server] sendResponse(GATT_SUCCESS)");
172-
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, null);
173-
}
194+
195+
Logger.d(mLogSession, "server.sendResponse(GATT_SUCCESS, offset=" + offset + ", value=" + ParserUtils.parse(value) + ")");
196+
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, null);
197+
Logger.v(mLogSession, "[Server] Response sent");
174198
}
175199

176200
@Override
177201
public void onDescriptorReadRequest(final BluetoothDevice device, final int requestId, final int offset, final BluetoothGattDescriptor descriptor) {
178-
Logger.i(mLogSession, "[Server] Write request to descriptor " + descriptor.getUuid() + " (requestId = " + requestId + ", offset = " + offset + ")");
202+
Logger.d(mLogSession, "[Server callback] Write request to descriptor " + descriptor.getUuid() + " (requestId=" + requestId + ", offset=" + offset + ")");
203+
Logger.i(mLogSession, "[Server] READ request for descriptor " + descriptor.getUuid() + " received");
179204
// This method is not supported
180-
Logger.v(mLogSession, "[Server] Sending response: REQUEST_NOT_SUPPORTED");
181-
Logger.d(mLogSession, "[Server] sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
205+
Logger.w(mLogSession, "[Server] Operation not supported");
206+
Logger.d(mLogSession, "[Server] server.sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
182207
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED, offset, null);
208+
Logger.v(mLogSession, "[Server] Response sent");
183209
}
184210

185211
@Override
186212
public void onDescriptorWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattDescriptor descriptor, final boolean preparedWrite,
187213
final boolean responseNeeded, final int offset, final byte[] value) {
188-
Logger.i(mLogSession, "[Server] Write request to descriptor " + descriptor.getUuid() + " (requestId = " + requestId + ", value = " + ParserUtils.parse(value) + ", offset = " + offset + ")");
214+
Logger.d(mLogSession, "[Server callback] Write request to descriptor " + descriptor.getUuid()
215+
+ " (requestId=" + requestId + ", prepareWrite=" + preparedWrite + ", responseNeeded=" + responseNeeded + ", offset=" + offset + ", value=" + ParserUtils.parse(value) + ")");
216+
Logger.i(mLogSession, "[Server] READ request for descriptor " + descriptor.getUuid() + " received");
189217
// This method is not supported
190-
Logger.v(mLogSession, "[Server] Sending response: REQUEST_NOT_SUPPORTED");
191-
Logger.d(mLogSession, "[Server] sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
218+
Logger.w(mLogSession, "[Server] Operation not supported");
219+
Logger.d(mLogSession, "[Server] server.sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
192220
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED, offset, null);
221+
Logger.v(mLogSession, "[Server] Response sent");
193222
}
194223

195224
@Override
196225
public void onExecuteWrite(final BluetoothDevice device, final int requestId, final boolean execute) {
197-
Logger.i(mLogSession, "[Server] Execute write request (requestId = " + requestId + ")");
226+
Logger.d(mLogSession, "[Server callback] Execute write request (requestId=" + requestId + ", execute=" + execute + ")");
198227
// This method is not supported
199-
Logger.v(mLogSession, "[Server] Sending response: REQUEST_NOT_SUPPORTED");
200-
Logger.d(mLogSession, "[Server] sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
228+
Logger.w(mLogSession, "[Server] Operation not supported");
229+
Logger.d(mLogSession, "[Server] server.sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
201230
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED, 0, null);
231+
Logger.v(mLogSession, "[Server] Response sent");
202232
}
203233
};
204234

-4.41 KB
Binary file not shown.
12.5 KB
Loading

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.3.0'
8+
classpath 'com.android.tools.build:gradle:1.3.1'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files

common/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ android {
4242

4343
dependencies {
4444
compile fileTree(dir: 'libs', include: ['*.jar'])
45-
compile 'com.android.support:support-v4:23.0.1'
45+
compile 'com.android.support:support-v4:23.1.0'
4646
}

0 commit comments

Comments
 (0)