Search in sources :

Example 11 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleDescribeEndpointCommand method printClusters.

private void printClusters(final ZigBeeEndpoint endpoint, final boolean input, final PrintStream out) {
    Collection<Integer> clusters;
    if (input) {
        clusters = endpoint.getInputClusterIds();
    } else {
        clusters = endpoint.getOutputClusterIds();
    }
    Map<Integer, ZclCluster> clusterTree = new TreeMap<Integer, ZclCluster>();
    for (Integer clusterId : clusters) {
        ZclCluster cluster;
        if (input) {
            cluster = endpoint.getInputCluster(clusterId);
        } else {
            cluster = endpoint.getOutputCluster(clusterId);
        }
        clusterTree.put(cluster.getClusterId(), cluster);
    }
    for (ZclCluster cluster : clusterTree.values()) {
        out.println(printClusterId(cluster.getClusterId()) + " " + cluster.getClusterName());
        printAttributes(cluster, out);
    }
}
Also used : ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) TreeMap(java.util.TreeMap)

Example 12 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeEndpoint method getDao.

/**
 * Gets a {@link ZigBeeEndpointDao} used for serialisation of the {@link ZigBeeEndpoint}
 *
 * @return the {@link ZigBeeEndpointDao}
 */
public ZigBeeEndpointDao getDao() {
    ZigBeeEndpointDao dao = new ZigBeeEndpointDao();
    dao.setEndpointId(endpointId);
    dao.setProfileId(profileId);
    List<ZclClusterDao> clusters;
    clusters = new ArrayList<ZclClusterDao>();
    for (ZclCluster cluster : inputClusters.values()) {
        clusters.add(cluster.getDao());
    }
    dao.setInputClusters(clusters);
    clusters = new ArrayList<ZclClusterDao>();
    for (ZclCluster cluster : outputClusters.values()) {
        clusters.add(cluster.getDao());
    }
    dao.setOutputClusters(clusters);
    return dao;
}
Also used : ZclClusterDao(com.zsmartsystems.zigbee.dao.ZclClusterDao) ZigBeeEndpointDao(com.zsmartsystems.zigbee.dao.ZigBeeEndpointDao) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster)

Example 13 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeEndpoint method getClusterClass.

private ZclCluster getClusterClass(int clusterId) {
    ZclClusterType clusterType = ZclClusterType.getValueById(clusterId);
    if (clusterType == null) {
        // Unsupported cluster
        logger.debug("{}: Unsupported cluster {}", getEndpointAddress(), clusterId);
        return null;
    }
    // Create a cluster class
    ZclCluster cluster = null;
    Constructor<? extends ZclCluster> constructor;
    // try {
    try {
        constructor = clusterType.getClusterClass().getConstructor(ZigBeeNetworkManager.class, ZigBeeEndpoint.class);
        cluster = constructor.newInstance(networkManager, this);
    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        logger.debug("{}: Error instantiating cluster {}", getEndpointAddress(), clusterType);
        return null;
    }
    return cluster;
}
Also used : ZclClusterType(com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 14 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeEndpoint method updateClusters.

private void updateClusters(Map<Integer, ZclCluster> clusters, List<Integer> newList, boolean isInput) {
    // Get a list any clusters that are no longer in the list
    List<Integer> removeIds = new ArrayList<Integer>();
    for (ZclCluster cluster : clusters.values()) {
        if (newList.contains(cluster.getClusterId())) {
            // The existing cluster is in the new list, so no need to remove it
            continue;
        }
        removeIds.add(cluster.getClusterId());
    }
    // Remove clusters no longer in use
    for (int id : removeIds) {
        logger.debug("{}: Removing cluster {}", getEndpointAddress(), id);
        clusters.remove(id);
    }
    // Add any missing clusters into the list
    for (int id : newList) {
        if (!clusters.containsKey(id)) {
            // Get the cluster type
            ZclCluster clusterClass = getClusterClass(id);
            if (clusterClass == null) {
                continue;
            }
            if (isInput) {
                logger.debug("{}: Setting cluster {} as server", getEndpointAddress(), ZclClusterType.getValueById(id));
                clusterClass.setServer();
            } else {
                logger.debug("{}: Setting cluster {} as client", getEndpointAddress(), ZclClusterType.getValueById(id));
                clusterClass.setClient();
            }
            // Add to our list of clusters
            clusters.put(id, clusterClass);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster)

Example 15 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeEndpoint method addApplication.

/**
 * Adds an application and makes it available to this endpoint.
 * The cluster used by the server must be in the output clusters list and this will be passed to the
 * {@link ZclApplication#serverStartup()) method to start the application.
 *
 * @param application the new {@link ZigBeeApplication}
 */
public void addApplication(ZigBeeApplication application) {
    applications.put(application.getClusterId(), application);
    ZclCluster cluster = outputClusters.get(application.getClusterId());
    if (cluster == null) {
        cluster = inputClusters.get(application.getClusterId());
    }
    application.appStartup(cluster);
}
Also used : ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster)

Aggregations

ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)15 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)8 CommandResult (com.zsmartsystems.zigbee.CommandResult)7 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)6 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)5 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)3 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)2 ZclClusterDao (com.zsmartsystems.zigbee.dao.ZclClusterDao)2 ConfigureReportingResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)2 ZigBeeApplication (com.zsmartsystems.zigbee.app.ZigBeeApplication)1 ZigBeeEndpointDao (com.zsmartsystems.zigbee.dao.ZigBeeEndpointDao)1 ReportAttributesCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReportAttributesCommand)1 WriteAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse)1 ZclClusterType (com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1