Skip to content

Commit 3cedc43

Browse files
committed
faster api 21
1 parent 6616d28 commit 3cedc43

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion '22.0.0'
66

77
defaultConfig {
8-
minSdkVersion 19
8+
minSdkVersion 21
99
targetSdkVersion 22
1010
}
1111

src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:versionName="1.0" >
55

66
<uses-sdk
7-
android:minSdkVersion="18"
7+
android:minSdkVersion="21"
88
android:targetSdkVersion="21" />
99
<uses-permission android:name="android.permission.BLUETOOTH" />
1010
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

src/main/java/org/microbit/android/partialflashing/PartialFlashingBaseService.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
204204
break;
205205
}
206206
case FLASH_COMMAND: {
207-
Log.v(TAG, "Packet Acknowledged: " + notificationValue[1]);
208207
packetState = notificationValue[1];
209208
}
210209
}
@@ -283,25 +282,6 @@ public Boolean attemptPartialFlash(String filePath) {
283282
// Check if EOF
284283
if(hex.getRecordTypeFromIndex(magicIndex + lineCount) != 0) break;
285284

286-
// Log record being written
287-
Log.v(TAG, "Hex Data : " + hexData);
288-
Log.v(TAG, "Hex Offset: " + Integer.toHexString(hex.getRecordAddressFromIndex(magicIndex + lineCount)));
289-
290-
// If Hex Data is Embedded Source Magic
291-
if(hexData.length() == 32) {
292-
if (hexData.substring(0, 15).equals("41140E2FB82FA2B"))
293-
{
294-
// Start of embedded source
295-
Log.v(TAG, "Reached embedded source");
296-
// Time execution
297-
long endTime = SystemClock.elapsedRealtime();
298-
long elapsedMilliSeconds = endTime - startTime;
299-
double elapsedSeconds = elapsedMilliSeconds / 1000.0;
300-
Log.v(TAG, "Flash Time (No Embedded Source): " + Float.toString((float) elapsedSeconds) + " seconds");
301-
break;
302-
}
303-
}
304-
305285
// Split into bytes
306286
int offsetToSend = 0;
307287
if(count == 0) {
@@ -312,43 +292,44 @@ public Boolean attemptPartialFlash(String filePath) {
312292
offsetToSend = hex.getSegmentAddress(magicIndex + lineCount);
313293
}
314294

315-
Log.v(TAG, "OFFSET_TO_SEND: " + offsetToSend);
316295
byte chunk[] = recordToByteArray(hexData, offsetToSend, packetNum);
317296

318297
// Write without response
319298
// Wait for previous write to complete
320299
boolean writeStatus = writePartialFlash(chunk);
321-
Log.v(TAG, "Hex Write: " + Boolean.toString(writeStatus));
322300

323301
// Sleep after 4 packets
324302
count++;
325303
if(count == 4){
326304
count = 0;
305+
327306
// Wait for notification
307+
Log.v(TAG, "Wait for notification");
308+
309+
// Send broadcast while waiting
310+
int percent = Math.round((float)100 * ((float)(lineCount) / (float)(numOfLines)));
311+
sendProgressBroadcast(percent);
312+
328313
while(packetState == PACKET_STATE_WAITING);
314+
Log.v(TAG, "/Wait for notification");
329315

330316
// Reset to waiting state
331317
packetState = PACKET_STATE_WAITING;
332318

333319
} else {
334-
Thread.sleep(5);
320+
Thread.sleep(3);
335321
}
336322

337323
// If notification is retransmit -> retransmit last block.
338324
// Else set start of new block
339325
if(packetState == PACKET_STATE_RETRANSMIT) {
340326
lineCount = lineCount - 4;
341327
} else {
342-
// Send progress update
343-
Log.v(TAG, "LC: " + lineCount + ", NL: " + numOfLines);
344-
int percent = Math.round((float)100 * ((float)(lineCount) / (float)(numOfLines)));
345-
sendProgressBroadcast(percent);
346-
347328
// Next line
348329
lineCount = lineCount + 1;
349330
}
350331

351-
// Increment packet #
332+
// Always increment packet #
352333
packetNum = packetNum + 1;
353334

354335
}
@@ -449,6 +430,13 @@ private boolean initialize(String deviceId) {
449430
Log.v(TAG, "Notifications enabled");
450431
}
451432

433+
// Set up BLE priority
434+
if(mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH)){
435+
Log.e(TAG, "Failed to set up priority");
436+
} else {
437+
Log.v(TAG, "High priority");
438+
}
439+
452440
BluetoothGattDescriptor descriptor = partialFlashCharacteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
453441
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
454442

0 commit comments

Comments
 (0)