Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for network to go offline before reconfiguring backup #1453

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading