Skip to content

Commit 563cda0

Browse files
authored
Wait for network to go offline before reconfiguring backup (#1453)
Signed-off-by: Chris Jackson <[email protected]>
1 parent 4105312 commit 563cda0

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ public ZigBeeStatus startup(boolean reinitialize) {
575575
ncp.sendManyToOneRouteRequest(concentratorType, radius);
576576
}
577577

578-
ncp.getConfiguration(EzspConfigId.EZSP_CONFIG_PACKET_BUFFER_COUNT);
579578
return joinedNetwork ? ZigBeeStatus.SUCCESS : ZigBeeStatus.BAD_RESPONSE;
580579
}
581580

@@ -763,7 +762,27 @@ public ZigBeeStatus setNetworkState(ZigBeeNetworkState networkState) {
763762
// token area once - subsequent writes will fail, and therefore changing IEEE address (eg from a
764763
// backup/restore) may fail.
765764
ncp.tokenFactoryReset(false, false);
766-
return ncp.leaveNetwork() == EmberStatus.EMBER_SUCCESS ? ZigBeeStatus.SUCCESS : ZigBeeStatus.FAILURE;
765+
if (ncp.leaveNetwork() != EmberStatus.EMBER_SUCCESS) {
766+
return ZigBeeStatus.FAILURE;
767+
}
768+
769+
// Wait for the notification from the NCP that it is offline.
770+
// This comes through the EzspStackStatusHandler which is processed elsewhere
771+
// and sets networkStateUp to false
772+
long timer = System.currentTimeMillis() + WAIT_FOR_ONLINE;
773+
do {
774+
if (!networkStateUp) {
775+
return ZigBeeStatus.SUCCESS;
776+
}
777+
778+
try {
779+
Thread.sleep(250);
780+
} catch (InterruptedException e) {
781+
break;
782+
}
783+
} while (timer > System.currentTimeMillis());
784+
785+
return ZigBeeStatus.INVALID_STATE;
767786
case ONLINE:
768787
return ncp.networkInit() == EmberStatus.EMBER_SUCCESS ? ZigBeeStatus.SUCCESS : ZigBeeStatus.FAILURE;
769788
default:

com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/ZigBeeNetworkManager.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,11 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
20922092
logger.debug("RestoreBackup: Backup read from {}", uuid);
20932093

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

20972101
// To properly re-add nodes, we must be INITIALIZING
20982102
// To call startup, we must be INITIALIZING

0 commit comments

Comments
 (0)