This commit is contained in:
Aleksander Nowakowski 2014-11-26 10:24:43 +01:00
parent 33098ae3fc
commit 8528f363e5
1 changed files with 13 additions and 7 deletions

View File

@ -59,7 +59,7 @@ import android.util.Log;
/** /**
* The DFU Service provides full support for Over-the-Air (OTA) Device Firmware Update by Nordic Semiconductor.<br /> * The DFU Service provides full support for Over-the-Air (OTA) Device Firmware Update by Nordic Semiconductor.<br />
* With the Soft Device 7.0.0+ it allows to upload a new Soft Device, new Bootloader and a new Application. For older soft devices only the Application update is supported. * With the Soft Device 7.0.0+ it allows to upload a new Soft Device, new Bootloader and a new Application (marked here as DFU v2.0). For older soft devices only the Application update is supported.
* <p> * <p>
* To run the service to your application inherit it and overwrite the missing method. Remember to it to the AndroidManifest.xml file. Start the service with the following parameters: * To run the service to your application inherit it and overwrite the missing method. Remember to it to the AndroidManifest.xml file. Start the service with the following parameters:
* *
@ -71,6 +71,10 @@ import android.util.Log;
* service.putExtra(DfuService.EXTRA_FILE_TYPE, mFileType); * service.putExtra(DfuService.EXTRA_FILE_TYPE, mFileType);
* service.putExtra(DfuService.EXTRA_FILE_PATH, mFilePath); * service.putExtra(DfuService.EXTRA_FILE_PATH, mFilePath);
* service.putExtra(DfuService.EXTRA_FILE_URI, mFileStreamUri); * service.putExtra(DfuService.EXTRA_FILE_URI, mFileStreamUri);
* // optionally
* service.putExtra(DfuService.EXTRA_INIT_FILE_PATH, mInitFilePath);
* service.putExtra(DfuService.EXTRA_INIT_FILE_URI, mInitFileStreamUri);
* service.putExtra(DfuService.EXTRA_RESTORE_BOND, mRestoreBond);
* startService(service); * startService(service);
* </pre> * </pre>
* *
@ -78,7 +82,7 @@ import android.util.Log;
* previous versions. * previous versions.
* </p> * </p>
* <p> * <p>
* The service will show its progress in the notifications bar and will send local broadcasts the the application. * The service will show its progress in the notifications bar and will send local broadcasts to the application.
* </p> * </p>
*/ */
public abstract class DfuBaseService extends IntentService { public abstract class DfuBaseService extends IntentService {
@ -212,7 +216,7 @@ public abstract class DfuBaseService extends IntentService {
* </li> * </li>
* <li>An error code with {@link #ERROR_MASK} if initialization error occurred</li> * <li>An error code with {@link #ERROR_MASK} if initialization error occurred</li>
* <li>An error code with {@link #ERROR_REMOTE_MASK} if remote DFU target returned an error</li> * <li>An error code with {@link #ERROR_REMOTE_MASK} if remote DFU target returned an error</li>
* <li>An error code with {@link #ERROR_CONNECTION_MASK} if connection error occurred (f.e. Gatt error (133) or Internal Gatt Error (129))</li> * <li>An error code with {@link #ERROR_CONNECTION_MASK} if connection error occurred (f.e. GATT error (133) or Internal GATT Error (129))</li>
* </ul> * </ul>
* To check if error occurred use:<br /> * To check if error occurred use:<br />
* {@code boolean error = progressValue >= DfuBaseService.ERROR_MASK;} * {@code boolean error = progressValue >= DfuBaseService.ERROR_MASK;}
@ -1233,6 +1237,9 @@ public abstract class DfuBaseService extends IntentService {
// If user wants to send soft device and/or bootloader + application we may try to send the Soft Device/Bootloader files first, // If user wants to send soft device and/or bootloader + application we may try to send the Soft Device/Bootloader files first,
// and then reconnect and send the application // and then reconnect and send the application
if ((fileType & TYPE_APPLICATION) > 0 && (fileType & (TYPE_SOFT_DEVICE | TYPE_BOOTLOADER)) > 0) { if ((fileType & TYPE_APPLICATION) > 0 && (fileType & (TYPE_SOFT_DEVICE | TYPE_BOOTLOADER)) > 0) {
// Clear the remote error flag
mRemoteErrorOccured = false;
logw("DFU target does not support (SD/BL)+App update"); logw("DFU target does not support (SD/BL)+App update");
sendLogBroadcast(Level.WARNING, "DFU target does not support (SD/BL)+App update"); sendLogBroadcast(Level.WARNING, "DFU target does not support (SD/BL)+App update");
@ -1276,6 +1283,9 @@ public abstract class DfuBaseService extends IntentService {
// If operation is not supported by DFU target we may try to upload application with legacy mode, using DFU v.1 // If operation is not supported by DFU target we may try to upload application with legacy mode, using DFU v.1
if (fileType == TYPE_APPLICATION) { if (fileType == TYPE_APPLICATION) {
// Clear the remote error flag
mRemoteErrorOccured = false;
// The DFU target does not support DFU v.2 protocol // The DFU target does not support DFU v.2 protocol
logw("DFU target does not support DFU v.2"); logw("DFU target does not support DFU v.2");
sendLogBroadcast(Level.WARNING, "DFU target does not support DFU v.2"); sendLogBroadcast(Level.WARNING, "DFU target does not support DFU v.2");
@ -1945,7 +1955,6 @@ public abstract class DfuBaseService extends IntentService {
*/ */
private void writeImageSize(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int imageSize) throws DeviceDisconnectedException, DfuException, private void writeImageSize(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int imageSize) throws DeviceDisconnectedException, DfuException,
UploadAbortedException { UploadAbortedException {
mRemoteErrorOccured = false;
mReceivedData = null; mReceivedData = null;
mError = 0; mError = 0;
mImageSizeSent = false; mImageSizeSent = false;
@ -2000,7 +2009,6 @@ public abstract class DfuBaseService extends IntentService {
*/ */
private void writeImageSize(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int softDeviceImageSize, final int bootloaderImageSize, final int appImageSize) private void writeImageSize(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int softDeviceImageSize, final int bootloaderImageSize, final int appImageSize)
throws DeviceDisconnectedException, DfuException, UploadAbortedException { throws DeviceDisconnectedException, DfuException, UploadAbortedException {
mRemoteErrorOccured = false;
mReceivedData = null; mReceivedData = null;
mError = 0; mError = 0;
mImageSizeSent = false; mImageSizeSent = false;
@ -2052,7 +2060,6 @@ public abstract class DfuBaseService extends IntentService {
locBuffer = new byte[size]; locBuffer = new byte[size];
System.arraycopy(buffer, 0, locBuffer, 0, size); System.arraycopy(buffer, 0, locBuffer, 0, size);
} }
mRemoteErrorOccured = false;
mReceivedData = null; mReceivedData = null;
mError = 0; mError = 0;
mInitPacketSent = false; mInitPacketSent = false;
@ -2098,7 +2105,6 @@ public abstract class DfuBaseService extends IntentService {
*/ */
private byte[] uploadFirmwareImage(final BluetoothGatt gatt, final BluetoothGattCharacteristic packetCharacteristic, final InputStream inputStream) throws DeviceDisconnectedException, private byte[] uploadFirmwareImage(final BluetoothGatt gatt, final BluetoothGattCharacteristic packetCharacteristic, final InputStream inputStream) throws DeviceDisconnectedException,
DfuException, UploadAbortedException { DfuException, UploadAbortedException {
mRemoteErrorOccured = false;
mReceivedData = null; mReceivedData = null;
mError = 0; mError = 0;