use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspNetworkInitRequest in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeDongleEzsp method initialize.
@Override
public ZigBeeInitializeResponse initialize() {
logger.debug("EZSP dongle initialize.");
zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.UNINITIALISED);
if (!initialiseEzspProtocol()) {
return ZigBeeInitializeResponse.FAILED;
}
// Perform any stack configuration
EmberStackConfiguration stackConfigurer = new EmberStackConfiguration(ashHandler);
Map<EzspConfigId, Integer> configuration = stackConfigurer.getConfiguration(stackConfiguration.keySet());
for (Entry<EzspConfigId, Integer> config : configuration.entrySet()) {
logger.debug("Configuration state {} = {}", config.getKey(), config.getValue());
}
Map<EzspPolicyId, EzspDecisionId> policies = stackConfigurer.getPolicy(stackPolicies.keySet());
for (Entry<EzspPolicyId, EzspDecisionId> policy : policies.entrySet()) {
logger.debug("Policy state {} = {}", policy.getKey(), policy.getValue());
}
stackConfigurer.setConfiguration(stackConfiguration);
configuration = stackConfigurer.getConfiguration(stackConfiguration.keySet());
for (Entry<EzspConfigId, Integer> config : configuration.entrySet()) {
logger.debug("Configuration state {} = {}", config.getKey(), config.getValue());
}
stackConfigurer.setPolicy(stackPolicies);
policies = stackConfigurer.getPolicy(stackPolicies.keySet());
for (Entry<EzspPolicyId, EzspDecisionId> policy : policies.entrySet()) {
logger.debug("Policy state {} = {}", policy.getKey(), policy.getValue());
}
EmberNcp ncp = new EmberNcp(ashHandler);
ncp.getNetworkParameters();
// Add the endpoint
ncp.addEndpoint(1, 0, ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getId(), new int[] { 0 }, new int[] { 0 });
// Now initialise the network
EzspNetworkInitRequest networkInitRequest = new EzspNetworkInitRequest();
EzspTransaction networkInitTransaction = ashHandler.sendEzspTransaction(new EzspSingleResponseTransaction(networkInitRequest, EzspNetworkInitResponse.class));
EzspNetworkInitResponse networkInitResponse = (EzspNetworkInitResponse) networkInitTransaction.getResponse();
logger.debug(networkInitResponse.toString());
networkParameters = ncp.getNetworkParameters();
ncp.getCurrentSecurityState();
zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.INITIALISING);
logger.debug("EZSP dongle initialize done: Initialised {}", networkInitResponse.getStatus() == EmberStatus.EMBER_NOT_JOINED);
// Check if the network is initialised or if we're yet to join
if (networkInitResponse.getStatus() == EmberStatus.EMBER_NOT_JOINED) {
return ZigBeeInitializeResponse.NOT_JOINED;
}
return ZigBeeInitializeResponse.JOINED;
}
Aggregations