@@ -1837,14 +1837,12 @@ public void run() {
1837
1837
return true ;
1838
1838
} else {
1839
1839
logger .trace ("{}: Refresh Node notifyListener LATCH Timeout, remaining = {}" ,
1840
- currentNode .getIeeeAddress (),
1841
- latch .getCount ());
1840
+ currentNode .getIeeeAddress (), latch .getCount ());
1842
1841
return false ;
1843
1842
}
1844
1843
} catch (InterruptedException e ) {
1845
1844
logger .trace ("{}: Refresh Node notifyListener LATCH Interrupted, remaining = {}" ,
1846
- currentNode .getIeeeAddress (),
1847
- latch .getCount ());
1845
+ currentNode .getIeeeAddress (), latch .getCount ());
1848
1846
return false ;
1849
1847
}
1850
1848
});
@@ -2088,9 +2086,10 @@ public UUID createBackup() {
2088
2086
public ZigBeeStatus restoreBackup (UUID uuid ) {
2089
2087
ZigBeeNetworkBackupDao backup = databaseManager .readBackup (uuid );
2090
2088
if (backup == null ) {
2091
- logger .debug ("Unable to restore from backup {}" , uuid );
2089
+ logger .debug ("RestoreBackup: Failed to read {}" , uuid );
2092
2090
return ZigBeeStatus .INVALID_ARGUMENTS ;
2093
2091
}
2092
+ logger .debug ("RestoreBackup: Backup read from {}" , uuid );
2094
2093
2095
2094
switch (getNetworkState ()) {
2096
2095
case UNINITIALISED :
@@ -2107,6 +2106,8 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
2107
2106
break ;
2108
2107
}
2109
2108
2109
+ logger .debug ("RestoreBackup: Taking network down" );
2110
+
2110
2111
// Take the network offline for reconfiguration
2111
2112
transport .setNetworkState (ZigBeeNetworkState .UNINITIALISED );
2112
2113
@@ -2125,12 +2126,26 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
2125
2126
}
2126
2127
}
2127
2128
2129
+ logger .debug ("RestoreBackup: Coordinator {}found {}" , coordinator == null ? "not " : "" ,
2130
+ coordinator == null ? "" : coordinator .getIeeeAddress ());
2131
+
2128
2132
// Set the coordinator address
2129
2133
if (coordinator != null ) {
2130
2134
transport .setIeeeAddress (coordinator .getIeeeAddress ());
2131
2135
transport .setNwkAddress (coordinator .getNetworkAddress ());
2132
2136
}
2133
2137
2138
+ long secondsSince = new Date ().getTime () - backup .getDate ().getTime ();
2139
+ ZigBeeKey key = backup .getNetworkKey ();
2140
+
2141
+ // Frame counters need to be incremented
2142
+ if (key .hasIncomingFrameCounter ()) {
2143
+ key .setIncomingFrameCounter ((int ) (key .getIncomingFrameCounter () + secondsSince * 5 ));
2144
+ }
2145
+ if (key .hasOutgoingFrameCounter ()) {
2146
+ key .setOutgoingFrameCounter ((int ) (key .getOutgoingFrameCounter () + secondsSince * 5 ));
2147
+ }
2148
+
2134
2149
// Set the network configuration
2135
2150
setZigBeePanId (backup .getPan ());
2136
2151
setZigBeeExtendedPanId (backup .getEpan ());
@@ -2140,6 +2155,7 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
2140
2155
2141
2156
// Remove all existing nodes
2142
2157
for (ZigBeeNode node : networkNodes .values ()) {
2158
+ logger .debug ("RestoreBackup: Removing node {} [{}]" , node .getIeeeAddress (), node .getNetworkAddress ());
2143
2159
removeNode (node );
2144
2160
}
2145
2161
@@ -2150,11 +2166,22 @@ public ZigBeeStatus restoreBackup(UUID uuid) {
2150
2166
for (ZigBeeNodeDao nodeDao : backup .getNodes ()) {
2151
2167
ZigBeeNode node = new ZigBeeNode (this , nodeDao .getIeeeAddress ());
2152
2168
node .setDao (nodeDao );
2153
- logger .debug ("{}: Data store : Node was restored from backup." , node .getIeeeAddress ());
2169
+ logger .debug ("{}: RestoreBackup : Node was restored from backup." , node .getIeeeAddress ());
2154
2170
updateNode (node );
2155
2171
}
2156
2172
2157
- return startup (true );
2173
+ groupManager .initialize ();
2174
+
2175
+ // Start the transport layer
2176
+ ZigBeeStatus status = transport .startup (true );
2177
+ if (status != ZigBeeStatus .SUCCESS ) {
2178
+ setNetworkState (ZigBeeNetworkState .OFFLINE );
2179
+ } else {
2180
+ setNetworkState (ZigBeeNetworkState .ONLINE );
2181
+ }
2182
+ logger .debug ("RestoreBackup: Completed from {} with state {}" , uuid , status );
2183
+
2184
+ return status ;
2158
2185
}
2159
2186
2160
2187
/**
0 commit comments