Skip to content

Commit

Permalink
Wait for network to go offline before reconfiguring backup
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson committed Dec 15, 2024
1 parent 4105312 commit 8011766
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ public ZigBeeStatus startup(boolean reinitialize) {
ncp.sendManyToOneRouteRequest(concentratorType, radius);
}

ncp.getConfiguration(EzspConfigId.EZSP_CONFIG_PACKET_BUFFER_COUNT);
return joinedNetwork ? ZigBeeStatus.SUCCESS : ZigBeeStatus.BAD_RESPONSE;
}

Expand Down Expand Up @@ -763,7 +762,27 @@ public ZigBeeStatus setNetworkState(ZigBeeNetworkState networkState) {
// token area once - subsequent writes will fail, and therefore changing IEEE address (eg from a
// backup/restore) may fail.
ncp.tokenFactoryReset(false, false);
return ncp.leaveNetwork() == EmberStatus.EMBER_SUCCESS ? ZigBeeStatus.SUCCESS : ZigBeeStatus.FAILURE;
if (ncp.leaveNetwork() != EmberStatus.EMBER_SUCCESS) {
return ZigBeeStatus.FAILURE;
}

// Wait for the notification from the NCP that it is offline.
// This comes through the EzspStackStatusHandler which is processed elsewhere
// and sets networkStateUp to false
long timer = System.currentTimeMillis() + WAIT_FOR_ONLINE;
do {
if (!networkStateUp) {
return ZigBeeStatus.SUCCESS;
}

try {
Thread.sleep(250);
} catch (InterruptedException e) {
break;
}
} while (timer > System.currentTimeMillis());

return ZigBeeStatus.INVALID_STATE;
case ONLINE:
return ncp.networkInit() == EmberStatus.EMBER_SUCCESS ? ZigBeeStatus.SUCCESS : ZigBeeStatus.FAILURE;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,11 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
logger.debug("RestoreBackup: Backup read from {}", uuid);

// Take the network offline for reconfiguration
transport.setNetworkState(ZigBeeNetworkState.UNINITIALISED);
ZigBeeStatus offlineResponse = transport.setNetworkState(ZigBeeNetworkState.UNINITIALISED);
if (offlineResponse != ZigBeeStatus.SUCCESS) {
logger.error("RestoreBackup: Failed to set network to UNINITIALISED with response {}", offlineResponse);
return ZigBeeStatus.INVALID_STATE;
}

// To properly re-add nodes, we must be INITIALIZING
// To call startup, we must be INITIALIZING
Expand Down

0 comments on commit 8011766

Please sign in to comment.