@@ -204,7 +204,6 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
204
204
break ;
205
205
}
206
206
case FLASH_COMMAND : {
207
- Log .v (TAG , "Packet Acknowledged: " + notificationValue [1 ]);
208
207
packetState = notificationValue [1 ];
209
208
}
210
209
}
@@ -283,25 +282,6 @@ public Boolean attemptPartialFlash(String filePath) {
283
282
// Check if EOF
284
283
if (hex .getRecordTypeFromIndex (magicIndex + lineCount ) != 0 ) break ;
285
284
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
-
305
285
// Split into bytes
306
286
int offsetToSend = 0 ;
307
287
if (count == 0 ) {
@@ -312,43 +292,44 @@ public Boolean attemptPartialFlash(String filePath) {
312
292
offsetToSend = hex .getSegmentAddress (magicIndex + lineCount );
313
293
}
314
294
315
- Log .v (TAG , "OFFSET_TO_SEND: " + offsetToSend );
316
295
byte chunk [] = recordToByteArray (hexData , offsetToSend , packetNum );
317
296
318
297
// Write without response
319
298
// Wait for previous write to complete
320
299
boolean writeStatus = writePartialFlash (chunk );
321
- Log .v (TAG , "Hex Write: " + Boolean .toString (writeStatus ));
322
300
323
301
// Sleep after 4 packets
324
302
count ++;
325
303
if (count == 4 ){
326
304
count = 0 ;
305
+
327
306
// 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
+
328
313
while (packetState == PACKET_STATE_WAITING );
314
+ Log .v (TAG , "/Wait for notification" );
329
315
330
316
// Reset to waiting state
331
317
packetState = PACKET_STATE_WAITING ;
332
318
333
319
} else {
334
- Thread .sleep (5 );
320
+ Thread .sleep (3 );
335
321
}
336
322
337
323
// If notification is retransmit -> retransmit last block.
338
324
// Else set start of new block
339
325
if (packetState == PACKET_STATE_RETRANSMIT ) {
340
326
lineCount = lineCount - 4 ;
341
327
} 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
-
347
328
// Next line
348
329
lineCount = lineCount + 1 ;
349
330
}
350
331
351
- // Increment packet #
332
+ // Always increment packet #
352
333
packetNum = packetNum + 1 ;
353
334
354
335
}
@@ -449,6 +430,13 @@ private boolean initialize(String deviceId) {
449
430
Log .v (TAG , "Notifications enabled" );
450
431
}
451
432
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
+
452
440
BluetoothGattDescriptor descriptor = partialFlashCharacteristic .getDescriptor (CLIENT_CHARACTERISTIC_CONFIG );
453
441
descriptor .setValue (BluetoothGattDescriptor .ENABLE_NOTIFICATION_VALUE );
454
442
0 commit comments