// Save the XML file. This serialises the data we've just updated
// (neighbors etc)
healing.node.setHealState(this.getNodeState(healing.node.getNodeId()));
ZWaveNodeSerializer nodeSerializer = new ZWaveNodeSerializer();
nodeSerializer.SerializeNode(healing.node);
return;
}
// Set the timeout
networkHealNextTime = System.currentTimeMillis() + HEAL_TIMEOUT_PERIOD;
switch (healing.state) {
case WAITING:
logger.debug("NODE {}: NETWORK HEAL - STARTING", healing.nodeId);
// Reset the resend count.
// This also resets the time so that we cycle through all the nodes
healing.node.resetResendCount();
case PING:
if (healing.nodeId != zController.getOwnNodeId()) {
healing.state = HealState.PING;
ZWaveNoOperationCommandClass zwaveCommandClass = (ZWaveNoOperationCommandClass) healing.node
.getCommandClass(CommandClass.NO_OPERATION);
if (zwaveCommandClass != null) {
zController.sendData(zwaveCommandClass.getNoOperationMessage());
healing.stateNext = HealState.SETSUCROUTE;
break;
}
}
healing.state = HealState.SETSUCROUTE;
case SETSUCROUTE:
// Only set the route if this is not the controller and there is an SUC in the network
if (healing.nodeId != zController.getOwnNodeId() && zController.getSucId() != 0) {
// Update the route to the controller
logger.debug("NODE {}: Heal is setting SUC route.", healing.nodeId);
healing.event = ZWaveNetworkEvent.Type.AssignSucReturnRoute;
healing.stateNext = HealState.UPDATENEIGHBORS;
zController.requestAssignSucReturnRoute(healing.nodeId);
break;
}
healing.state = HealState.UPDATENEIGHBORS;
case UPDATENEIGHBORS:
logger.debug("NODE {}: Heal is updating node neighbors.", healing.nodeId);
healing.event = ZWaveNetworkEvent.Type.NodeNeighborUpdate;
healing.stateNext = HealState.GETASSOCIATIONS;
zController.requestNodeNeighborUpdate(healing.nodeId);
break;
case GETASSOCIATIONS:
// Check if this node supports associations
ZWaveAssociationCommandClass associationCommandClass = (ZWaveAssociationCommandClass) healing.node
.getCommandClass(CommandClass.ASSOCIATION);
if (associationCommandClass != null) {
logger.debug("NODE {}: Heal is requesting device associations.", healing.nodeId);
healing.stateNext = HealState.UPDATEROUTES;
healing.event = ZWaveNetworkEvent.Type.AssociationUpdate;
associationCommandClass.getAllAssociations();
break;
}
case UPDATEROUTES:
// Get the list of routes for this node
healing.routeList = healing.node.getRoutingList();
if (healing.routeList != null && healing.routeList.size() != 0) {
// Delete all the return routes for the node
logger.debug("NODE {}: Heal is deleting routes.", healing.nodeId);
healing.event = ZWaveNetworkEvent.Type.DeleteReturnRoute;
healing.stateNext = HealState.UPDATEROUTESNEXT;
zController.requestDeleteAllReturnRoutes(healing.nodeId);
break;
}
case UPDATEROUTESNEXT:
if (healing.routeList != null && healing.routeList.size() != 0) {
// Loop through all the nodes and set the return route
logger.debug("NODE {}: Adding return route to {}", healing.nodeId, healing.routeList.get(0));
healing.stateNext = HealState.GETNEIGHBORS;
healing.event = ZWaveNetworkEvent.Type.AssignReturnRoute;
zController.requestAssignReturnRoute(healing.nodeId, healing.routeList.get(0));
break;
}
case GETNEIGHBORS:
healing.event = ZWaveNetworkEvent.Type.NodeRoutingInfo;
healing.stateNext = HealState.PINGEND;
logger.debug("NODE {}: Heal is requesting node neighbor info.", healing.nodeId);
zController.requestNodeRoutingInfo(healing.nodeId);
break;
case PINGEND:
if (healing.nodeId != zController.getOwnNodeId()) {
ZWaveNoOperationCommandClass zwaveCommandClass = (ZWaveNoOperationCommandClass) healing.node
.getCommandClass(CommandClass.NO_OPERATION);
if (zwaveCommandClass == null)
break;
zController.sendData(zwaveCommandClass.getNoOperationMessage());
healing.stateNext = HealState.SAVE;
break;
}
case SAVE:
logger.debug("NODE {}: Heal is complete - saving XML.", healing.nodeId);
healing.state = HealState.DONE;
networkHealNextTime = System.currentTimeMillis() + HEAL_DELAY_PERIOD;
// Save the XML file. This serialises the data we've just updated
// (neighbors etc)
healing.node.setHealState(this.getNodeState(healing.node.getNodeId()));
ZWaveNodeSerializer nodeSerializer = new ZWaveNodeSerializer();
nodeSerializer.SerializeNode(healing.node);
break;
default:
break;
}
healing.node.setHealState(this.getNodeState(healing.node.getNodeId()));