Search in sources :

Example 1 with ZigBeeApplication

use of com.zsmartsystems.zigbee.app.ZigBeeApplication in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeEndpoint method commandReceived.

/**
 * Incoming command handler. The endpoint will process any commands addressed to this endpoint ID and pass o
 * clusters and applications
 *
 * @param command the {@link ZclCommand} received
 */
public void commandReceived(ZclCommand command) {
    if (!command.getSourceAddress().equals(getEndpointAddress())) {
        return;
    }
    // Pass all commands received from this endpoint to any registered applications
    synchronized (applications) {
        for (ZigBeeApplication application : applications.values()) {
            application.commandReceived(command);
        }
    }
    // Get the cluster
    ZclCluster cluster = getReceiveCluster(command.getClusterId(), command.getCommandDirection());
    if (cluster == null) {
        logger.debug("{}: Cluster {} not found for attribute response", getEndpointAddress(), command.getClusterId());
        return;
    }
    if (command instanceof ReportAttributesCommand) {
        ReportAttributesCommand attributeCommand = (ReportAttributesCommand) command;
        // Pass the reports to the cluster
        cluster.handleAttributeReport(attributeCommand.getReports());
        return;
    }
    if (command instanceof ReadAttributesResponse) {
        ReadAttributesResponse attributeCommand = (ReadAttributesResponse) command;
        // Pass the reports to the cluster
        cluster.handleAttributeStatus(attributeCommand.getRecords());
        return;
    }
    // If this is a specific cluster command, pass the command to the cluster command handler
    if (!command.isGenericCommand()) {
        cluster.handleCommand(command);
    }
}
Also used : ZigBeeApplication(com.zsmartsystems.zigbee.app.ZigBeeApplication) ReportAttributesCommand(com.zsmartsystems.zigbee.zcl.clusters.general.ReportAttributesCommand) ReadAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster)

Aggregations

ZigBeeApplication (com.zsmartsystems.zigbee.app.ZigBeeApplication)1 ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)1 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)1 ReportAttributesCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReportAttributesCommand)1