/** * Handles Multi Instance Encapsulation message. Decapsulates an Application Command message and * handles it using the right instance. * * @param serialMessage the serial message to process. * @param offset the offset at which to start procesing. * @throws ZWaveSerialMessageException */ private void handleMultiInstanceEncapResponse(SerialMessage serialMessage, int offset) throws ZWaveSerialMessageException { logger.trace("Process Multi-instance Encapsulation"); int instance = serialMessage.getMessagePayloadByte(offset); int commandClassCode = serialMessage.getMessagePayloadByte(offset + 1); CommandClass commandClass = CommandClass.getCommandClass(commandClassCode); if (commandClass == null) { logger.error( String.format( "NODE %d: Unsupported command class 0x%02x", this.getNode().getNodeId(), commandClassCode)); return; } logger.debug( String.format( "NODE %d: Requested Command Class = %s (0x%02x)", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode)); ZWaveCommandClass zwaveCommandClass = null; // first get command class from endpoint, if supported if (this.getVersion() >= 2) { ZWaveEndpoint endpoint = this.endpoints.get(instance); if (endpoint != null) { zwaveCommandClass = endpoint.getCommandClass(commandClass); if (zwaveCommandClass == null) { logger.warn( String.format( "NODE %d: CommandClass %s (0x%02x) not implemented by endpoint %d, fallback to main node.", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode, instance)); } } } if (zwaveCommandClass == null) { zwaveCommandClass = this.getNode().getCommandClass(commandClass); } if (zwaveCommandClass == null) { logger.error( String.format( "NODE %d: Unsupported command class %s (0x%02x)", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode)); return; } logger.debug( "NODE {}: Instance = {}, calling handleApplicationCommandRequest.", this.getNode().getNodeId(), instance); zwaveCommandClass.handleApplicationCommandRequest(serialMessage, offset + 2, instance); }
/** * Handles Multi Instance Report message. Handles Report on the number of instances for the * command class. This is for Version 1 of the command class. * * @param serialMessage the serial message to process. * @param offset the offset at which to start processing. * @throws ZWaveSerialMessageException */ private void handleMultiInstanceReportResponse(SerialMessage serialMessage, int offset) throws ZWaveSerialMessageException { logger.trace("Process Multi-instance Report"); int commandClassCode = serialMessage.getMessagePayloadByte(offset); int instances = serialMessage.getMessagePayloadByte(offset + 1); CommandClass commandClass = CommandClass.getCommandClass(commandClassCode); if (commandClass == null) { logger.error( String.format( "NODE %d: Unsupported command class 0x%02x", this.getNode().getNodeId(), commandClassCode)); return; } logger.debug( "NODE {}: Requested Command Class = {}", this.getNode().getNodeId(), commandClass.getLabel()); ZWaveCommandClass zwaveCommandClass = this.getNode().getCommandClass(commandClass); if (zwaveCommandClass == null) { logger.error( String.format( "NODE %d: Unsupported command class %s (0x%02x)", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode)); return; } if (instances == 0) { logger.debug("NODE {}: Instances = 0. Setting to 1.", this.getNode().getNodeId()); instances = 1; } zwaveCommandClass.setInstances(instances); logger.debug( "NODE {}: Command class {}, has {} instance(s).", this.getNode().getNodeId(), commandClass.getLabel(), instances); }
/** * Handles Multi Channel Encapsulation message. Decapsulates an Application Command message and * handles it using the right endpoint. * * @param serialMessage the serial message to process. * @param offset the offset at which to start processing. */ private void handleMultiChannelEncapResponse(SerialMessage serialMessage, int offset) { logger.trace("Process Multi-channel Encapsulation"); if (serialMessage.getMessagePayload().length < offset + 2) { logger.error( "NODE {}: Invalid data length ({}/{})", this.getNode().getNodeId(), serialMessage.getMessagePayload().length, offset); return; } CommandClass commandClass; ZWaveCommandClass zwaveCommandClass; int endpointId = serialMessage.getMessagePayloadByte(offset); int commandClassCode = serialMessage.getMessagePayloadByte(offset + 2); commandClass = CommandClass.getCommandClass(commandClassCode); if (commandClass == null) { logger.error( String.format( "NODE %d: Unsupported command class 0x%02x", this.getNode().getNodeId(), commandClassCode)); return; } logger.debug( String.format( "NODE %d: Requested Command Class = %s (0x%02x)", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode)); ZWaveEndpoint endpoint = this.endpoints.get(endpointId); if (endpoint == null) { logger.error( "NODE {}: Endpoint {} not found. Cannot set command classes.", this.getNode().getNodeId(), endpointId); return; } zwaveCommandClass = endpoint.getCommandClass(commandClass); if (zwaveCommandClass == null) { logger.warn( String.format( "NODE %d: CommandClass %s (0x%02x) not implemented by endpoint %d, fallback to main node.", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode, endpointId)); zwaveCommandClass = this.getNode().getCommandClass(commandClass); } if (zwaveCommandClass == null) { logger.error( String.format( "NODE %d: CommandClass %s (0x%02x) not implemented.", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode)); return; } logger.debug( "NODE {}: Endpoint = {}, calling handleApplicationCommandRequest.", this.getNode().getNodeId(), endpointId); zwaveCommandClass.handleApplicationCommandRequest(serialMessage, offset + 3, endpointId); }
/** * Handles Multi Channel Encapsulation message. Decapsulates an Application Command message and * handles it using the right endpoint. * * @param serialMessage the serial message to process. * @param offset the offset at which to start processing. * @throws ZWaveSerialMessageException */ private void handleMultiChannelEncapResponse(SerialMessage serialMessage, int offset) throws ZWaveSerialMessageException { logger.trace("Process Multi-channel Encapsulation"); if (serialMessage.getMessagePayload().length < offset + 2) { logger.error("NODE {}: Invalid data length", this.getNode().getNodeId()); return; } CommandClass commandClass; ZWaveCommandClass zwaveCommandClass; int originatingEndpointId = serialMessage.getMessagePayloadByte(offset); { int destinationEndpointId = serialMessage.getMessagePayloadByte(offset + 1); if (destinationEndpointId != 1 && originatingEndpointId == 1) { logger.debug( "NODE {}: Controller has no endpoints. Probably originating ({}) and destination ({}) endpoints should be swapped.", this.getNode().getNodeId(), originatingEndpointId, destinationEndpointId); // not a full swap. Do not use destinationEndpointId after this line // and leave scope intact. originatingEndpointId = destinationEndpointId; } } int commandClassCode = serialMessage.getMessagePayloadByte(offset + 2); commandClass = CommandClass.getCommandClass(commandClassCode); if (commandClass == null) { logger.error( String.format( "NODE %d: Unsupported command class 0x%02x", this.getNode().getNodeId(), commandClassCode)); return; } logger.debug( String.format( "NODE %d: Requested Command Class = %s (0x%02x)", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode)); ZWaveEndpoint endpoint = this.endpoints.get(originatingEndpointId); if (endpoint == null) { logger.error( "NODE {}: Endpoint {} not found. Cannot set command classes.", this.getNode().getNodeId(), originatingEndpointId); return; } zwaveCommandClass = endpoint.getCommandClass(commandClass); if (zwaveCommandClass == null) { logger.warn( String.format( "NODE %d: CommandClass %s (0x%02x) not implemented by endpoint %d, fallback to main node.", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode, originatingEndpointId)); zwaveCommandClass = this.getNode().getCommandClass(commandClass); } if (zwaveCommandClass == null) { logger.error( String.format( "NODE %d: CommandClass %s (0x%02x) not implemented.", this.getNode().getNodeId(), commandClass.getLabel(), commandClassCode)); return; } logger.debug( "NODE {}: Endpoint = {}, calling handleApplicationCommandRequest.", this.getNode().getNodeId(), originatingEndpointId); zwaveCommandClass.handleApplicationCommandRequest( serialMessage, offset + 3, originatingEndpointId); }