Skip to content

Commit

Permalink
Update following testing
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
  • Loading branch information
cdjackson committed Oct 12, 2024
1 parent 5d07e9f commit e93cc35
Showing 1 changed file with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1837,14 +1837,12 @@ public void run() {
return true;
} else {
logger.trace("{}: Refresh Node notifyListener LATCH Timeout, remaining = {}",
currentNode.getIeeeAddress(),
latch.getCount());
currentNode.getIeeeAddress(), latch.getCount());
return false;
}
} catch (InterruptedException e) {
logger.trace("{}: Refresh Node notifyListener LATCH Interrupted, remaining = {}",
currentNode.getIeeeAddress(),
latch.getCount());
currentNode.getIeeeAddress(), latch.getCount());
return false;
}
});
Expand Down Expand Up @@ -2088,9 +2086,10 @@ public UUID createBackup() {
public ZigBeeStatus restoreBackup(UUID uuid) {
ZigBeeNetworkBackupDao backup = databaseManager.readBackup(uuid);
if (backup == null) {
logger.debug("Unable to restore from backup {}", uuid);
logger.debug("RestoreBackup: Failed to read {}", uuid);
return ZigBeeStatus.INVALID_ARGUMENTS;
}
logger.debug("RestoreBackup: Backup read from {}", uuid);

switch (getNetworkState()) {
case UNINITIALISED:
Expand All @@ -2107,6 +2106,8 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
break;
}

logger.debug("RestoreBackup: Taking network down");

// Take the network offline for reconfiguration
transport.setNetworkState(ZigBeeNetworkState.UNINITIALISED);

Expand All @@ -2125,12 +2126,26 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
}
}

logger.debug("RestoreBackup: Coordinator {}found {}", coordinator == null ? "not " : "",
coordinator == null ? "" : coordinator.getIeeeAddress());

// Set the coordinator address
if (coordinator != null) {
transport.setIeeeAddress(coordinator.getIeeeAddress());
transport.setNwkAddress(coordinator.getNetworkAddress());
}

long secondsSince = new Date().getTime() - backup.getDate().getTime();
ZigBeeKey key = backup.getNetworkKey();

// Frame counters need to be incremented
if (key.hasIncomingFrameCounter()) {
key.setIncomingFrameCounter((int) (key.getIncomingFrameCounter() + secondsSince * 5));
}
if (key.hasOutgoingFrameCounter()) {
key.setOutgoingFrameCounter((int) (key.getOutgoingFrameCounter() + secondsSince * 5));
}

// Set the network configuration
setZigBeePanId(backup.getPan());
setZigBeeExtendedPanId(backup.getEpan());
Expand All @@ -2140,6 +2155,7 @@ public ZigBeeStatus restoreBackup(UUID uuid) {

// Remove all existing nodes
for (ZigBeeNode node : networkNodes.values()) {
logger.debug("RestoreBackup: Removing node {} [{}]", node.getIeeeAddress(), node.getNetworkAddress());
removeNode(node);
}

Expand All @@ -2150,11 +2166,22 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
for (ZigBeeNodeDao nodeDao : backup.getNodes()) {
ZigBeeNode node = new ZigBeeNode(this, nodeDao.getIeeeAddress());
node.setDao(nodeDao);
logger.debug("{}: Data store: Node was restored from backup.", node.getIeeeAddress());
logger.debug("{}: RestoreBackup: Node was restored from backup.", node.getIeeeAddress());
updateNode(node);
}

return startup(true);
groupManager.initialize();

// Start the transport layer
ZigBeeStatus status = transport.startup(true);
if (status != ZigBeeStatus.SUCCESS) {
setNetworkState(ZigBeeNetworkState.OFFLINE);
} else {
setNetworkState(ZigBeeNetworkState.ONLINE);
}
logger.debug("RestoreBackup: Completed from {} with state {}", uuid, status);

return status;
}

/**
Expand Down

0 comments on commit e93cc35

Please sign in to comment.