3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * Copyright (c) 2020 Silicon Labs
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
26 * http://www.apache.org/licenses/LICENSE-2.0
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 /****************************************************************************
36 * @brief Routines for the Scenes Client plugin, which
37 *implements the client side of the Scenes cluster.
38 *******************************************************************************
39 ******************************************************************************/
41 #include "scenes-client.h"
42 #include <app/util/af.h>
44 #include "gen/command-id.h"
48 bool emberAfScenesClusterAddSceneResponseCallback(uint8_t status, GroupId groupId, uint8_t sceneId)
50 return emberAfPluginScenesClientParseAddSceneResponse(emberAfCurrentCommand(), status, groupId, sceneId);
53 bool emberAfScenesClusterViewSceneResponseCallback(uint8_t status, GroupId groupId, uint8_t sceneId, uint16_t transitionTime,
54 uint8_t * sceneName, uint8_t * extensionFieldSets)
56 return emberAfPluginScenesClientParseViewSceneResponse(emberAfCurrentCommand(), status, groupId, sceneId, transitionTime,
57 sceneName, extensionFieldSets);
60 bool emberAfScenesClusterRemoveSceneResponseCallback(uint8_t status, GroupId groupId, uint8_t sceneId)
62 emberAfScenesClusterPrintln("RX: RemoveSceneResponse 0x%x, 0x%2x, 0x%x", status, groupId, sceneId);
63 emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
67 bool emberAfScenesClusterRemoveAllScenesResponseCallback(uint8_t status, GroupId groupId)
69 emberAfScenesClusterPrintln("RX: RemoveAllScenesResponse 0x%x, 0x%2x", status, groupId);
70 emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
74 bool emberAfScenesClusterStoreSceneResponseCallback(uint8_t status, GroupId groupId, uint8_t sceneId)
76 emberAfScenesClusterPrintln("RX: StoreSceneResponse 0x%x, 0x%2x, 0x%x", status, groupId, sceneId);
77 emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
81 bool emberAfScenesClusterGetSceneMembershipResponseCallback(uint8_t status, uint8_t capacity, GroupId groupId, uint8_t sceneCount,
84 emberAfScenesClusterPrint("RX: GetSceneMembershipResponse 0x%x, 0x%x, 0x%2x", status, capacity, groupId);
86 // Scene count and the scene list only appear in the payload if the status is
88 if (status == EMBER_ZCL_STATUS_SUCCESS)
91 emberAfScenesClusterPrint(", 0x%x,", sceneCount);
92 for (i = 0; i < sceneCount; i++)
94 emberAfScenesClusterPrint(" [0x%x]", sceneList[i]);
98 emberAfScenesClusterPrintln("");
99 emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
103 bool emberAfPluginScenesClientParseAddSceneResponse(const EmberAfClusterCommand * cmd, uint8_t status, GroupId groupId,
106 bool enhanced = (cmd->commandId == ZCL_ENHANCED_ADD_SCENE_COMMAND_ID);
107 emberAfScenesClusterPrintln("RX: %pAddSceneResponse 0x%x, 0x%2x, 0x%x", (enhanced ? "Enhanced" : ""), status, groupId, sceneId);
108 emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS);
112 bool emberAfPluginScenesClientParseViewSceneResponse(const EmberAfClusterCommand * cmd, uint8_t status, GroupId groupId,
113 uint8_t sceneId, uint16_t transitionTime, const uint8_t * sceneName,
114 const uint8_t * extensionFieldSets)
116 bool enhanced = (cmd->commandId == ZCL_ENHANCED_VIEW_SCENE_COMMAND_ID);
118 emberAfScenesClusterPrint("RX: %pViewSceneResponse 0x%x, 0x%2x, 0x%x", (enhanced ? "Enhanced" : ""), status, groupId, sceneId);
120 // Transition time, scene name, and the extension field sets only appear in
121 // the payload if the status is SUCCESS.
122 if (status == EMBER_ZCL_STATUS_SUCCESS)
124 uint16_t extensionFieldSetsLen =
125 static_cast<uint16_t>(emberAfCurrentCommand()->bufLen -
126 (emberAfCurrentCommand()->payloadStartIndex + sizeof(status) + sizeof(groupId) + sizeof(sceneId) +
127 sizeof(transitionTime) + emberAfStringLength(sceneName) + 1));
128 uint16_t extensionFieldSetsIndex = 0;
130 emberAfScenesClusterPrint(", 0x%2x, \"", transitionTime);
131 emberAfScenesClusterPrintString(sceneName);
132 emberAfScenesClusterPrint("\",");
134 // Each extension field set contains at least a two-byte cluster id and a
136 while (extensionFieldSetsIndex + 3 <= extensionFieldSetsLen)
140 clusterId = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
141 extensionFieldSetsIndex = static_cast<uint16_t>(extensionFieldSetsIndex + 2);
142 length = emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
143 extensionFieldSetsIndex++;
144 emberAfScenesClusterPrint(" [0x%2x 0x%x ", clusterId, length);
145 if (extensionFieldSetsIndex + length <= extensionFieldSetsLen)
147 emberAfScenesClusterPrintBuffer(extensionFieldSets + extensionFieldSetsIndex, length, false);
149 emberAfScenesClusterPrint("]");
150 emberAfScenesClusterFlush();
151 extensionFieldSetsIndex = static_cast<uint16_t>(extensionFieldSetsIndex + length);
155 emberAfScenesClusterPrintln("");
156 emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS);