Skip to content

Commit

Permalink
Refactor to remove ZclCommandType enumeration
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson committed Mar 3, 2019
1 parent cbfddb7 commit 1b00b84
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 2,999 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ public static void main(final String[] args) {
new ZigBeeZclConstantGenerator(zclClusters, generatedDate, zclTypes);
new ZigBeeZclStructureGenerator(zclClusters, generatedDate, zclTypes);
new ZigBeeZclClusterTypeGenerator(zclClusters, generatedDate, zclTypes);
new ZigBeeZclCommandTypeGenerator(zclClusters, generatedDate, zclTypes);
new ZigBeeZclDataTypeGenerator(dataTypes, generatedDate);

new ZigBeeZclCommandGenerator(zdoClusters, generatedDate, zclTypes);

new ZigBeeZdoClusterGenerator(zdoClusters, generatedDate, zclTypes);

zclParser = new ZigBeeXmlParser();
zclParser.addFile("src/main/resources/zigbee_constants.xml");
ZigBeeXmlGlobal globals = zclParser.parseGlobalConfiguration();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.zsmartsystems.zigbee.ZigBeeNetworkManager;
import com.zsmartsystems.zigbee.zcl.ZclCluster;
import com.zsmartsystems.zigbee.zcl.ZclCommand;
import com.zsmartsystems.zigbee.zcl.ZclFrameType;

/**
* Console command that prints the commands that are supported by a given cluster.
Expand Down Expand Up @@ -81,7 +82,7 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
private void printCommands(PrintStream out, ZclCluster cluster, Set<Integer> commandIds) {
out.println("CommandId Command");
for (Integer commandId : commandIds) {
ZclCommand command = cluster.getCommandFromId(commandId);
ZclCommand command = cluster.getCommandFromId(ZclFrameType.CLUSTER_SPECIFIC_COMMAND, commandId);
String commandName = (command != null) ? command.getClass().getSimpleName() : "unknown";
out.println(String.format("%8d %s", commandId, commandName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@
import com.zsmartsystems.zigbee.transport.ZigBeeTransportReceive;
import com.zsmartsystems.zigbee.transport.ZigBeeTransportState;
import com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit;
import com.zsmartsystems.zigbee.zcl.ZclCluster;
import com.zsmartsystems.zigbee.zcl.ZclCommand;
import com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer;
import com.zsmartsystems.zigbee.zcl.ZclFieldSerializer;
import com.zsmartsystems.zigbee.zcl.ZclFrameType;
import com.zsmartsystems.zigbee.zcl.ZclHeader;
import com.zsmartsystems.zigbee.zcl.ZclTransactionMatcher;
import com.zsmartsystems.zigbee.zcl.protocol.ZclCommandType;
import com.zsmartsystems.zigbee.zcl.protocol.ZclCommandDirection;
import com.zsmartsystems.zigbee.zdo.ZdoCommand;
import com.zsmartsystems.zigbee.zdo.ZdoCommandType;
import com.zsmartsystems.zigbee.zdo.command.ManagementLeaveRequest;
Expand Down Expand Up @@ -787,6 +788,8 @@ private ZigBeeCommand receiveZdoCommand(final ZclFieldDeserializer fieldDeserial
final ZigBeeApsFrame apsFrame) {
ZdoCommandType commandType = ZdoCommandType.getValueById(apsFrame.getCluster());
if (commandType == null) {
logger.debug("Error instantiating ZDO command: Unknown cluster {}",
String.format("%04X", apsFrame.getCluster()));
return null;
}

Expand All @@ -813,25 +816,36 @@ private ZigBeeCommand receiveZclCommand(final ZclFieldDeserializer fieldDeserial
ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
logger.debug("RX ZCL: {}", zclHeader);

// Get the command type
ZclCommandType commandType = null;
if (zclHeader.getFrameType() == ZclFrameType.ENTIRE_PROFILE_COMMAND) {
commandType = ZclCommandType.getGeneric(zclHeader.getCommandId());
} else {
commandType = ZclCommandType.getCommandType(apsFrame.getCluster(), zclHeader.getCommandId(),
zclHeader.getDirection());
ZigBeeNode node = getNode(apsFrame.getSourceAddress());
if (node == null) {
logger.debug("Unknown node {}", apsFrame.getSourceAddress());
return null;
}

if (commandType == null) {
logger.debug("No command type found for {}, cluster={}, command={}, direction={}", zclHeader.getFrameType(),
apsFrame.getCluster(), zclHeader.getCommandId(), zclHeader.getDirection());
ZigBeeEndpoint endpoint = node.getEndpoint(apsFrame.getSourceEndpoint());
if (endpoint == null) {
logger.debug("Unknown endpoint {}", apsFrame.getSourceEndpoint());
return null;
}

ZclCommand command = commandType.instantiateCommand();
ZclCommand command;
if (zclHeader.getDirection() == ZclCommandDirection.SERVER_TO_CLIENT) {
ZclCluster cluster = endpoint.getInputCluster(apsFrame.getCluster());
if (cluster == null) {
logger.debug("Unknown input cluster {}", apsFrame.getCluster());
return null;
}
command = cluster.getCommandFromId(zclHeader.getFrameType(), zclHeader.getCommandId());
} else {
ZclCluster cluster = endpoint.getOutputCluster(apsFrame.getCluster());
if (cluster == null) {
logger.debug("Unknown output cluster {}", apsFrame.getCluster());
return null;
}
command = cluster.getResponseFromId(zclHeader.getFrameType(), zclHeader.getCommandId());
}
if (command == null) {
logger.debug("No command found for {}, cluster={}, command={}", zclHeader.getFrameType(),
apsFrame.getCluster(), zclHeader.getCommandId());
logger.debug("Unknown command {}", zclHeader.getCommandId());
return null;
}

Expand Down
Loading

0 comments on commit 1b00b84

Please sign in to comment.