4949import com .zsmartsystems .zigbee .transport .ZigBeeTransportReceive ;
5050import com .zsmartsystems .zigbee .transport .ZigBeeTransportState ;
5151import com .zsmartsystems .zigbee .transport .ZigBeeTransportTransmit ;
52+ import com .zsmartsystems .zigbee .zcl .ZclCluster ;
5253import com .zsmartsystems .zigbee .zcl .ZclCommand ;
5354import com .zsmartsystems .zigbee .zcl .ZclFieldDeserializer ;
5455import com .zsmartsystems .zigbee .zcl .ZclFieldSerializer ;
5556import com .zsmartsystems .zigbee .zcl .ZclFrameType ;
5657import com .zsmartsystems .zigbee .zcl .ZclHeader ;
5758import com .zsmartsystems .zigbee .zcl .ZclTransactionMatcher ;
58- import com .zsmartsystems .zigbee .zcl .protocol .ZclCommandType ;
59+ import com .zsmartsystems .zigbee .zcl .protocol .ZclCommandDirection ;
5960import com .zsmartsystems .zigbee .zdo .ZdoCommand ;
6061import com .zsmartsystems .zigbee .zdo .ZdoCommandType ;
6162import com .zsmartsystems .zigbee .zdo .command .ManagementLeaveRequest ;
@@ -789,6 +790,8 @@ private ZigBeeCommand receiveZdoCommand(final ZclFieldDeserializer fieldDeserial
789790 final ZigBeeApsFrame apsFrame ) {
790791 ZdoCommandType commandType = ZdoCommandType .getValueById (apsFrame .getCluster ());
791792 if (commandType == null ) {
793+ logger .debug ("Error instantiating ZDO command: Unknown cluster {}" ,
794+ String .format ("%04X" , apsFrame .getCluster ()));
792795 return null ;
793796 }
794797
@@ -815,25 +818,36 @@ private ZigBeeCommand receiveZclCommand(final ZclFieldDeserializer fieldDeserial
815818 ZclHeader zclHeader = new ZclHeader (fieldDeserializer );
816819 logger .debug ("RX ZCL: {}" , zclHeader );
817820
818- // Get the command type
819- ZclCommandType commandType = null ;
820- if (zclHeader .getFrameType () == ZclFrameType .ENTIRE_PROFILE_COMMAND ) {
821- commandType = ZclCommandType .getGeneric (zclHeader .getCommandId ());
822- } else {
823- commandType = ZclCommandType .getCommandType (apsFrame .getCluster (), zclHeader .getCommandId (),
824- zclHeader .getDirection ());
821+ ZigBeeNode node = getNode (apsFrame .getSourceAddress ());
822+ if (node == null ) {
823+ logger .debug ("Unknown node {}" , apsFrame .getSourceAddress ());
824+ return null ;
825825 }
826826
827- if ( commandType == null ) {
828- logger . debug ( "No command type found for {}, cluster={}, command={}, direction={}" , zclHeader . getFrameType (),
829- apsFrame . getCluster (), zclHeader . getCommandId (), zclHeader . getDirection ());
827+ ZigBeeEndpoint endpoint = node . getEndpoint ( apsFrame . getSourceEndpoint ());
828+ if ( endpoint == null ) {
829+ logger . debug ( "Unknown endpoint {}" , apsFrame . getSourceEndpoint ());
830830 return null ;
831831 }
832832
833- ZclCommand command = commandType .instantiateCommand ();
833+ ZclCommand command ;
834+ if (zclHeader .getDirection () == ZclCommandDirection .SERVER_TO_CLIENT ) {
835+ ZclCluster cluster = endpoint .getInputCluster (apsFrame .getCluster ());
836+ if (cluster == null ) {
837+ logger .debug ("Unknown input cluster {}" , apsFrame .getCluster ());
838+ return null ;
839+ }
840+ command = cluster .getCommandFromId (zclHeader .getFrameType (), zclHeader .getCommandId ());
841+ } else {
842+ ZclCluster cluster = endpoint .getOutputCluster (apsFrame .getCluster ());
843+ if (cluster == null ) {
844+ logger .debug ("Unknown output cluster {}" , apsFrame .getCluster ());
845+ return null ;
846+ }
847+ command = cluster .getResponseFromId (zclHeader .getFrameType (), zclHeader .getCommandId ());
848+ }
834849 if (command == null ) {
835- logger .debug ("No command found for {}, cluster={}, command={}" , zclHeader .getFrameType (),
836- apsFrame .getCluster (), zclHeader .getCommandId ());
850+ logger .debug ("Unknown command {}" , zclHeader .getCommandId ());
837851 return null ;
838852 }
839853
0 commit comments