Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into no-transport
  • Loading branch information
bgiori committed Aug 10, 2018
2 parents 9af6858 + 465ad94 commit 11d713d
Showing 1 changed file with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ public synchronized void start(@NonNull byte[] imageData) throws McuMgrException

@Override
public synchronized void cancel() {
if (mState.isInProgress()) {
cancelPrivate();
if (mState == State.UPLOAD) {
mImageManager.cancelUpload();
mPaused = false;
}
}

Expand Down Expand Up @@ -318,16 +319,9 @@ private synchronized void success() {

private synchronized void fail(McuMgrException error) {
State failedState = mState;
cancelPrivate();
mInternalCallback.onUpgradeFailed(failedState, error);
}

private synchronized void cancelPrivate() {
if (mState == State.UPLOAD) {
mImageManager.cancelUpload();
}
mState = State.NONE;
mPaused = false;
mInternalCallback.onUpgradeFailed(failedState, error);
}

//******************************************************************
Expand Down Expand Up @@ -394,7 +388,7 @@ public void onResponse(@NonNull final McuMgrImageStateResponse response) {
}

// If image was already confirmed, reset (if confirm was planned), or fail.
if (images[1].permanent || images[1].confirmed) {
if (images[1].permanent) {
switch (mMode) {
case CONFIRM_ONLY:
case TEST_AND_CONFIRM:
Expand All @@ -421,6 +415,17 @@ public void onResponse(@NonNull final McuMgrImageStateResponse response) {
return;
}

// If the image in slot 1 is confirmed (we are in test mode)
// we won't be able to erase the slot. A No Memory error
// would be thrown. We have to reset the device and return
// from test mode before firmware upgrade begins.
if (images.length > 1 && images[1].confirmed) {
// Send reset command without changing state.
mDefaultManager.getTransporter().addObserver(mResetObserver);
mDefaultManager.reset(mResetCallback);
return;
}

// Validation successful, begin image upload.
upload();
}
Expand Down Expand Up @@ -478,15 +483,23 @@ public void onDisconnected() {
// Device has reset.
mDefaultManager.getTransporter().removeObserver(this);
Log.v(TAG, "Reset successful");
switch (mMode) {
case TEST_AND_CONFIRM:
// The device reconnected after testing.
verify();
switch (mState) {
case VALIDATE:
// The device has exited test mode. Slot 1 can now be erased.
validate();
break;
case TEST_ONLY:
case CONFIRM_ONLY:
// The device has been tested or confirmed.
success();
case RESET:
switch (mMode) {
case TEST_AND_CONFIRM:
// The device reconnected after testing.
verify();
break;
case TEST_ONLY:
case CONFIRM_ONLY:
// The device has been tested or confirmed.
success();
break;
}
break;
}
}
Expand Down Expand Up @@ -637,7 +650,7 @@ public void onProgressChanged(int bytesSent, int imageSize, long timestamp) {

@Override
public void onUploadFailed(@NonNull McuMgrException error) {
mInternalCallback.onUpgradeFailed(mState, error);
fail(error);
}

@Override
Expand Down

0 comments on commit 11d713d

Please sign in to comment.