Legacy DFU fixed.

This commit is contained in:
Aleksander Nowakowski 2016-06-13 16:42:52 +02:00
parent 095c3681e9
commit 8a9ab93868
3 changed files with 8 additions and 9 deletions

View File

@ -138,7 +138,6 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
if (available < 20) if (available < 20)
buffer = new byte[available]; buffer = new byte[available];
final int size = mFirmwareStream.read(buffer); final int size = mFirmwareStream.read(buffer);
logi("Writing packet from onCharacteristicWrite"); // TODO remove
writePacket(gatt, characteristic, buffer, size); writePacket(gatt, characteristic, buffer, size);
return; return;
} catch (final HexFileValidationException e) { } catch (final HexFileValidationException e) {
@ -205,7 +204,6 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
if (available < 20) if (available < 20)
buffer = new byte[available]; buffer = new byte[available];
final int size = mFirmwareStream.read(buffer); final int size = mFirmwareStream.read(buffer);
logi("Writing packet from handlePacketReceiptNotification"); // TODO remove
writePacket(gatt, packetCharacteristic, buffer, size); writePacket(gatt, packetCharacteristic, buffer, size);
} catch (final HexFileValidationException e) { } catch (final HexFileValidationException e) {
loge("Invalid HEX file"); loge("Invalid HEX file");
@ -322,12 +320,11 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
* If connection state will change, or an error will occur, an exception will be thrown. * If connection state will change, or an error will occur, an exception will be thrown.
* *
* @param packetCharacteristic the characteristic to write file content to. Must be the DFU PACKET * @param packetCharacteristic the characteristic to write file content to. Must be the DFU PACKET
* @return The response value received from notification with Op Code = 3 when all bytes will be uploaded successfully.
* @throws DeviceDisconnectedException Thrown when the device will disconnect in the middle of the transmission. * @throws DeviceDisconnectedException Thrown when the device will disconnect in the middle of the transmission.
* @throws DfuException Thrown if DFU error occur * @throws DfuException Thrown if DFU error occur
* @throws UploadAbortedException * @throws UploadAbortedException
*/ */
protected byte[] uploadFirmwareImage(final BluetoothGattCharacteristic packetCharacteristic) throws DeviceDisconnectedException, protected void uploadFirmwareImage(final BluetoothGattCharacteristic packetCharacteristic) throws DeviceDisconnectedException,
DfuException, UploadAbortedException { DfuException, UploadAbortedException {
mReceivedData = null; mReceivedData = null;
mError = 0; mError = 0;
@ -338,7 +335,6 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
try { try {
final int size = mFirmwareStream.read(buffer); final int size = mFirmwareStream.read(buffer);
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_VERBOSE, "Sending firmware to characteristic " + packetCharacteristic.getUuid() + "..."); mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_VERBOSE, "Sending firmware to characteristic " + packetCharacteristic.getUuid() + "...");
logi("Writing packet from uploadFirmwareImage"); // TODO remove
writePacket(mGatt, packetCharacteristic, buffer, size); writePacket(mGatt, packetCharacteristic, buffer, size);
} catch (final HexFileValidationException e) { } catch (final HexFileValidationException e) {
throw new DfuException("HEX file not valid", DfuBaseService.ERROR_FILE_INVALID); throw new DfuException("HEX file not valid", DfuBaseService.ERROR_FILE_INVALID);
@ -361,8 +357,6 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
throw new DfuException("Uploading Firmware Image failed", mError); throw new DfuException("Uploading Firmware Image failed", mError);
if (!mConnected) if (!mConnected)
throw new DeviceDisconnectedException("Uploading Firmware Image failed: device disconnected"); throw new DeviceDisconnectedException("Uploading Firmware Image failed: device disconnected");
return mReceivedData;
} }
/** /**

View File

@ -555,7 +555,7 @@ import no.nordicsemi.android.error.LegacyDfuError;
try { try {
logi("Uploading firmware..."); logi("Uploading firmware...");
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Uploading firmware..."); mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Uploading firmware...");
response = uploadFirmwareImage(mPacketCharacteristic); uploadFirmwareImage(mPacketCharacteristic);
} catch (final DeviceDisconnectedException e) { } catch (final DeviceDisconnectedException e) {
loge("Disconnected while sending data"); loge("Disconnected while sending data");
throw e; throw e;
@ -564,6 +564,7 @@ import no.nordicsemi.android.error.LegacyDfuError;
final long endTime = SystemClock.elapsedRealtime(); final long endTime = SystemClock.elapsedRealtime();
// Check the result of the operation // Check the result of the operation
response = readNotificationResponse();
status = getStatusCode(response, OP_CODE_RECEIVE_FIRMWARE_IMAGE_KEY); status = getStatusCode(response, OP_CODE_RECEIVE_FIRMWARE_IMAGE_KEY);
logi("Response received. Op Code: " + response[0] + " Req Op Code = " + response[1] + ", Status = " + response[2]); logi("Response received. Op Code: " + response[0] + " Req Op Code = " + response[1] + ", Status = " + response[2]);
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Response received (Op Code = " + response[1] + ", Status = " + status + ")"); mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Response received (Op Code = " + response[1] + ", Status = " + status + ")");

View File

@ -394,7 +394,11 @@ import no.nordicsemi.android.error.SecureDfuError;
* This method does the following: * This method does the following:
* <ol> * <ol>
* <li>Sets the Packet Receipt Notification to a value specified in the settings.</li> * <li>Sets the Packet Receipt Notification to a value specified in the settings.</li>
* <li></li> * <li>Selects the Data object - this returns maximum single object size and the offset and CRC of the data already saved.</li>
* <li>If the offset received is greater than 0 it will calculate the CRC of the same number of bytes of the firmware to be sent.
* If the CRC match it will continue sending data. Otherwise, it will go back to the beginning of the last chunk, or to the beginning
* of the previous chunk assuming the last one was not executed before, and continue sending data from there.</li>
* <li>If the CRC and offset received match and the offset is equal to the firmware size, it will only send the Execute command.</li>
* </ol> * </ol>
* @param gatt the target GATT device * @param gatt the target GATT device
* @throws RemoteDfuException * @throws RemoteDfuException