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 Door Lock Server plugin.
37 *******************************************************************************
38 ******************************************************************************/
41 #include "door-lock-server.h"
43 #include "gen/attribute-id.h"
44 #include "gen/attribute-type.h"
45 #include "gen/cluster-id.h"
47 static void setActuatorEnable(void)
49 // The Door Lock cluster test spec expects this attribute set to be true by
52 EmberAfStatus status =
53 emberAfWriteServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID, ZCL_ACTUATOR_ENABLED_ATTRIBUTE_ID,
54 (uint8_t *) &troo, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
55 if (status != EMBER_ZCL_STATUS_SUCCESS)
57 emberAfDoorLockClusterPrintln("Failed to write ActuatorEnabled attribute: 0x%X", status);
61 static void setDoorState(void)
63 uint8_t state = EMBER_ZCL_DOOR_STATE_ERROR_UNSPECIFIED;
64 EmberAfStatus status = emberAfWriteServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID,
65 ZCL_DOOR_STATE_ATTRIBUTE_ID, (uint8_t *) &state, ZCL_ENUM8_ATTRIBUTE_TYPE);
66 if (status != EMBER_ZCL_STATUS_SUCCESS)
68 emberAfDoorLockClusterPrintln("Failed to write DoorState attribute: 0x%X", status);
72 static void setLanguage(void)
74 uint8_t englishString[] = { 0x02, 'e', 'n' };
75 EmberAfStatus status = emberAfWriteServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID,
76 ZCL_LANGUAGE_ATTRIBUTE_ID, englishString, ZCL_CHAR_STRING_ATTRIBUTE_TYPE);
77 if (status != EMBER_ZCL_STATUS_SUCCESS)
79 emberAfDoorLockClusterPrintln("Failed to write Language attribute: 0x%X", status);
83 void emberAfPluginDoorLockServerInitCallback(void)
85 emAfPluginDoorLockServerInitUser();
86 emAfPluginDoorLockServerInitSchedule();
93 void emAfPluginDoorLockServerWriteAttributes(const EmAfPluginDoorLockServerAttributeData * data, uint8_t dataLength,
94 const char * description)
96 for (uint8_t i = 0; i < dataLength; i++)
98 EmberAfStatus status = emberAfWriteServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID, data[i].id,
99 (uint8_t *) &data[i].value, ZCL_INT16U_ATTRIBUTE_TYPE);
100 if (status != EMBER_ZCL_STATUS_SUCCESS)
102 emberAfDoorLockClusterPrintln("Failed to write %s attribute 0x%2X: 0x%X", data[i].id, status, description);
107 EmberAfStatus emAfPluginDoorLockServerNoteDoorStateChanged(EmberAfDoorState state)
109 EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
111 #ifdef ZCL_USING_DOOR_LOCK_CLUSTER_DOOR_STATE_ATTRIBUTE
112 status = emberAfWriteServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID, ZCL_DOOR_STATE_ATTRIBUTE_ID,
113 (uint8_t *) &state, ZCL_ENUM8_ATTRIBUTE_TYPE);
114 if (status != EMBER_ZCL_STATUS_SUCCESS)
120 #if defined(ZCL_USING_DOOR_LOCK_CLUSTER_DOOR_OPEN_EVENTS_ATTRIBUTE) || \
121 defined(ZCL_USING_DOOR_LOCK_CLUSTER_DOOR_CLOSED_EVENTS_ATTRIBUTE)
122 if (state == EMBER_ZCL_DOOR_STATE_OPEN || state == EMBER_ZCL_DOOR_STATE_CLOSED)
124 AttributeId attributeId =
125 (state == EMBER_ZCL_DOOR_STATE_OPEN ? ZCL_DOOR_OPEN_EVENTS_ATTRIBUTE_ID : ZCL_DOOR_CLOSED_EVENTS_ATTRIBUTE_ID);
127 status = emberAfReadServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID, attributeId, (uint8_t *) &events,
129 if (status == EMBER_ZCL_STATUS_SUCCESS)
132 status = emberAfWriteServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID, attributeId,
133 (uint8_t *) &events, ZCL_INT32U_ATTRIBUTE_TYPE);