Skip to content

Commit 2eb8eb3

Browse files
committed
Refactor to remove ZclCommandType enumeration
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
1 parent 591c4ac commit 2eb8eb3

File tree

15 files changed

+175
-2999
lines changed

15 files changed

+175
-2999
lines changed

com.zsmartsystems.zigbee.autocode/src/main/java/com/zsmartsystems/zigbee/autocode/ZigBeeCodeGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ public static void main(final String[] args) {
119119
new ZigBeeZclConstantGenerator(zclClusters, generatedDate, zclTypes);
120120
new ZigBeeZclStructureGenerator(zclClusters, generatedDate, zclTypes);
121121
new ZigBeeZclClusterTypeGenerator(zclClusters, generatedDate, zclTypes);
122-
new ZigBeeZclCommandTypeGenerator(zclClusters, generatedDate, zclTypes);
123122
new ZigBeeZclDataTypeGenerator(dataTypes, generatedDate);
124123

125124
new ZigBeeZclCommandGenerator(zdoClusters, generatedDate, zclTypes);
126125

126+
new ZigBeeZdoClusterGenerator(zdoClusters, generatedDate, zclTypes);
127+
127128
zclParser = new ZigBeeXmlParser();
128129
zclParser.addFile("src/main/resources/zigbee_constants.xml");
129130
ZigBeeXmlGlobal globals = zclParser.parseGlobalConfiguration();

com.zsmartsystems.zigbee.autocode/src/main/java/com/zsmartsystems/zigbee/autocode/ZigBeeZclCommandTypeGenerator.java

Lines changed: 0 additions & 188 deletions
This file was deleted.

com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleCommandsSupportedCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.zsmartsystems.zigbee.ZigBeeNetworkManager;
1616
import com.zsmartsystems.zigbee.zcl.ZclCluster;
1717
import com.zsmartsystems.zigbee.zcl.ZclCommand;
18+
import com.zsmartsystems.zigbee.zcl.ZclFrameType;
1819

1920
/**
2021
* Console command that prints the commands that are supported by a given cluster.
@@ -81,7 +82,7 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
8182
private void printCommands(PrintStream out, ZclCluster cluster, Set<Integer> commandIds) {
8283
out.println("CommandId Command");
8384
for (Integer commandId : commandIds) {
84-
ZclCommand command = cluster.getCommandFromId(commandId);
85+
ZclCommand command = cluster.getCommandFromId(ZclFrameType.CLUSTER_SPECIFIC_COMMAND, commandId);
8586
String commandName = (command != null) ? command.getClass().getSimpleName() : "unknown";
8687
out.println(String.format("%8d %s", commandId, commandName));
8788
}

com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/ZigBeeNetworkManager.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@
4949
import com.zsmartsystems.zigbee.transport.ZigBeeTransportReceive;
5050
import com.zsmartsystems.zigbee.transport.ZigBeeTransportState;
5151
import com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit;
52+
import com.zsmartsystems.zigbee.zcl.ZclCluster;
5253
import com.zsmartsystems.zigbee.zcl.ZclCommand;
5354
import com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer;
5455
import com.zsmartsystems.zigbee.zcl.ZclFieldSerializer;
5556
import com.zsmartsystems.zigbee.zcl.ZclFrameType;
5657
import com.zsmartsystems.zigbee.zcl.ZclHeader;
5758
import com.zsmartsystems.zigbee.zcl.ZclTransactionMatcher;
58-
import com.zsmartsystems.zigbee.zcl.protocol.ZclCommandType;
59+
import com.zsmartsystems.zigbee.zcl.protocol.ZclCommandDirection;
5960
import com.zsmartsystems.zigbee.zdo.ZdoCommand;
6061
import com.zsmartsystems.zigbee.zdo.ZdoCommandType;
6162
import 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

Comments
 (0)