Search in sources :

Example 1 with EmberNetworkInitialisation

use of com.zsmartsystems.zigbee.dongle.ember.internal.EmberNetworkInitialisation in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleEzsp method startup.

@Override
public boolean startup(boolean reinitialize) {
    logger.debug("EZSP dongle startup.");
    // If ashHandler is null then the serial port didn't initialise
    if (ashHandler == null) {
        logger.error("Initialising Ember Dongle but low level handle is not initialised.");
        return false;
    }
    EmberNcp ncp = new EmberNcp(ashHandler);
    // Check if the network is initialised
    EmberNetworkStatus networkState = ncp.getNetworkState();
    logger.debug("EZSP networkStateResponse {}", networkState);
    // If we want to reinitialize the network, then go...
    if (reinitialize) {
        logger.debug("Reinitialising Ember NCP and forming network.");
        EmberNetworkInitialisation netInitialiser = new EmberNetworkInitialisation(ashHandler);
        netInitialiser.formNetwork(networkParameters, networkKey);
        ncp.getNetworkParameters();
    }
    // Check if the network is now up
    networkState = ncp.getNetworkState();
    logger.debug("EZSP networkStateResponse {}", networkState);
    if (networkState == EmberNetworkStatus.EMBER_JOINED_NETWORK) {
        zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.ONLINE);
    }
    // Get the security state - mainly for debug
    EmberCurrentSecurityState currentSecurityState = ncp.getCurrentSecurityState();
    logger.debug("Current Security State = {}", currentSecurityState);
    EzspGetParentChildParametersResponse childParametersResponse = ncp.getChildParameters();
    logger.debug("Current Parent Child Information = {}", childParametersResponse);
    for (int childId = 0; childId < childParametersResponse.getChildCount(); childId++) {
        ncp.getChildInformation(childId);
    }
    logger.debug("EZSP dongle startup done.");
    return true;
}
Also used : EmberNetworkInitialisation(com.zsmartsystems.zigbee.dongle.ember.internal.EmberNetworkInitialisation) EzspGetParentChildParametersResponse(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspGetParentChildParametersResponse) EmberNetworkStatus(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberNetworkStatus) EmberCurrentSecurityState(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberCurrentSecurityState)

Aggregations

EmberNetworkInitialisation (com.zsmartsystems.zigbee.dongle.ember.internal.EmberNetworkInitialisation)1 EzspGetParentChildParametersResponse (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspGetParentChildParametersResponse)1 EmberCurrentSecurityState (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberCurrentSecurityState)1 EmberNetworkStatus (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberNetworkStatus)1