Skip to content

Commit

Permalink
Merge pull request #4 from Thomasdjb/feature-DoorLock-GetAllPINCodes
Browse files Browse the repository at this point in the history
Patchs integration and feature
  • Loading branch information
nkljajic committed Jan 23, 2024
2 parents e7f155e + 306e06c commit 6985a1d
Show file tree
Hide file tree
Showing 26 changed files with 277 additions and 131 deletions.
Expand Up @@ -316,14 +316,14 @@ static void zigpc_command_mapper_publish_door_lock_getpin_code_response(
) {
std::string unid(zigpc_ucl::mqtt::build_unid(zigbee_eui64_to_uint(eui64)));

uic_mqtt_dotdot_door_lock_command_getpin_code_response_fields_t fields = {
uic_mqtt_dotdot_door_lock_command_get_pin_code_response_fields_t fields = {
(uint16_t) data->door_lock_getpin_code_response.userid,
(DrlkUserStatus) data->door_lock_getpin_code_response.user_status,
(DrlkUserType) data->door_lock_getpin_code_response.user_type,
(const char*) data->door_lock_getpin_code_response.code
};

uic_mqtt_dotdot_door_lock_publish_generated_getpin_code_response_command(
uic_mqtt_dotdot_door_lock_publish_generated_get_pin_code_response_command(
unid.c_str(),
endpoint_id,
&fields
Expand Down
Expand Up @@ -2269,6 +2269,30 @@ void zigpc_command_mapper_bygroup_door_lock_clear_allrfid_codes_handler(
0,
nullptr
);
/**
* @brief DotDot MQTT by-group handler for DoorLock/GetAllPINCodes command.
*
* @param group_id UCL group identifier.
*/
void zigpc_command_mapper_bygroup_door_lock_get_all_pin_codes_handler(
const dotdot_group_id_t group_id
) {




zigpc_command_mapper_send_multicast(
group_id,
ZIGPC_ZCL_FRAME_TYPE_CMD_TO_SERVER,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK_COMMAND_GET_ALL_PIN_CODES,
0,
nullptr
);

}


}

Expand Down Expand Up @@ -4076,6 +4100,7 @@ sl_status_t zigpc_command_mapper_mqtt_bygroup_handlers_init(void)
uic_mqtt_dotdot_by_group_door_lock_clearrfid_code_callback_set(zigpc_command_mapper_bygroup_door_lock_clearrfid_code_handler);
uic_mqtt_dotdot_by_group_door_lock_clear_allrfid_codes_callback_set(zigpc_command_mapper_bygroup_door_lock_clear_allrfid_codes_handler);
uic_mqtt_dotdot_by_group_door_lock_get_allpin_codes_callback_set(zigpc_command_mapper_bygroup_door_lock_get_allpin_codes_handler);
uic_mqtt_dotdot_by_group_door_lock_get_all_pin_codes_callback_set(zigpc_command_mapper_bygroup_door_lock_get_all_pin_codes_handler);
uic_mqtt_dotdot_by_group_thermostat_write_attributes_callback_set(zigpc_command_mapper_bygroup_thermostat_write_attributes_handler);
uic_mqtt_dotdot_by_group_thermostat_setpoint_raise_or_lower_callback_set(zigpc_command_mapper_bygroup_thermostat_setpoint_raise_or_lower_handler);
uic_mqtt_dotdot_by_group_thermostat_set_weekly_schedule_callback_set(zigpc_command_mapper_bygroup_thermostat_set_weekly_schedule_handler);
Expand Down
Expand Up @@ -4231,6 +4231,50 @@ sl_status_t zigpc_command_mapper_door_lock_clear_allrfid_codes_handler(
status = SL_STATUS_NOT_AVAILABLE;
}
return status;
* @brief DotDot MQTT translator handler for DoorLock/GetAllPINCodes command.
*
* @param unid Unify device identifier string
* @param endpoint Unify device endpoint identifier
* @param callback_type Callback type
* @return SL_STATUS_OK if callback_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_NORMAL and call is successful
* @return SL_STATUS_OK if callback_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK and command is supported by the unid/endpoint
* @return SL_STATUS_NOT_AVAILABLE if callback_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK and command is not supported by the unid/endpoint
*/
sl_status_t zigpc_command_mapper_door_lock_get_all_pin_codes_handler(
const dotdot_unid_t unid,
const dotdot_endpoint_id_t endpoint,
uic_mqtt_dotdot_callback_call_type_t callback_type
) {
sl_status_t status = SL_STATUS_NOT_AVAILABLE;

if (callback_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK) {
status = zigpc_command_mapper_cluster_support_check(unid, endpoint, ZIGPC_ZCL_CLUSTER_DOOR_LOCK);
if (status != SL_STATUS_OK) {
status = SL_STATUS_NOT_AVAILABLE;
}
return status;
}




if (status == SL_STATUS_OK) {
zigpc_command_mapper_send_unicast(
unid,
endpoint,
ZIGPC_ZCL_FRAME_TYPE_CMD_TO_SERVER,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK_COMMAND_get_all_pin_CODES,
0,
nullptr
);
}

// Always return SL_STATUS_OK if being called normally.
return status;
}

/**
}
Expand Down Expand Up @@ -8101,6 +8145,9 @@ sl_status_t zigpc_command_mapper_register_dotdot_mqtt_handlers(void)
uic_mqtt_dotdot_door_lock_get_allpin_codes_callback_set(
zigpc_command_mapper_door_lock_get_allpin_codes_handler
);
);
uic_mqtt_dotdot_door_lock_get_all_pin_codes_callback_set(
zigpc_command_mapper_door_lock_get_all_pin_codes_handler
uic_mqtt_dotdot_set_thermostat_write_attributes_callback(
zigpc_command_mapper_thermostat_write_attributes_handler
);
Expand Down
Expand Up @@ -479,7 +479,7 @@ typedef enum {
ZIGPC_ZCL_CLUSTER_DOOR_LOCK_COMMAND_CLEAR_ALLRFID_CODES_RESPONSE = 0x19,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK_COMMAND_OPERATING_EVENT_NOTIFICATION = 0x20,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK_COMMAND_PROGRAMMING_EVENT_NOTIFICATION = 0x21,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK_COMMAND_GET_ALLPIN_CODES = 0x80,
ZIGPC_ZCL_CLUSTER_DOOR_LOCK_COMMAND_GET_ALL_PIN_CODES = 0x80,
} zigpc_zcl_door_lock_command_type_t;

/*****************************************************************
Expand Down
Expand Up @@ -383,7 +383,7 @@ sl_status_t user_code_cluster_server_init()
// Register the callback for handling commands from IoT service
uic_mqtt_dotdot_door_lock_setpin_code_callback_set(&set_pin_code_command);
uic_mqtt_dotdot_door_lock_getpin_code_callback_set(&get_pin_code_command);
uic_mqtt_dotdot_door_lock_get_allpin_codes_callback_set(&get_all_pin_codes_command);
uic_mqtt_dotdot_door_lock_get_all_pin_codes_callback_set(&get_all_pin_codes_command);
uic_mqtt_dotdot_door_lock_clearpin_code_callback_set(&clear_pin_code_command);
uic_mqtt_dotdot_door_lock_clear_allpin_codes_callback_set(
&clear_all_pin_codes_command);
Expand Down
Expand Up @@ -326,13 +326,38 @@ static bool is_mucr_supported(attribute_store_node_t endpoint_node)
static sl_status_t zwave_command_class_user_code_number_get(
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
{
(void)node; // unused.
attribute_store_node_t endpoint_node
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE_ENDPOINT_ID);
attribute_store_node_t version_node
= attribute_store_get_first_child_by_type(endpoint_node,
ATTRIBUTE(VERSION));
// We need to check the version of the supporting node:
zwave_cc_version_t supporting_node_version = 0;
attribute_store_get_reported(version_node,
&supporting_node_version,
sizeof(supporting_node_version));

if (supporting_node_version == 0) {
// Wait to know the supporting node version
*frame_length = 0;
return SL_STATUS_IS_WAITING;
}

if (supporting_node_version == 1) {
ZW_USERS_NUMBER_GET_FRAME *get_frame
= (ZW_USERS_NUMBER_GET_FRAME *)frame;
get_frame->cmdClass = COMMAND_CLASS_USER_CODE;
get_frame->cmd = USERS_NUMBER_GET;
*frame_length = sizeof(ZW_USERS_NUMBER_GET_FRAME);
}
else {
// This is a static payload.
ZW_USERS_NUMBER_GET_V2_FRAME *get_frame
= (ZW_USERS_NUMBER_GET_V2_FRAME *)frame;
get_frame->cmdClass = COMMAND_CLASS_USER_CODE_V2;
get_frame->cmd = USERS_NUMBER_GET_V2;
*frame_length = sizeof(ZW_USERS_NUMBER_GET_V2_FRAME);
}
return SL_STATUS_OK;
}

Expand Down Expand Up @@ -378,8 +403,8 @@ static sl_status_t zwave_command_class_user_code_get(
*frame_length = 0;
return SL_STATUS_ALREADY_EXISTS;
}
frame[0] = COMMAND_CLASS_USER_CODE_V2;
frame[1] = USER_CODE_GET_V2;
frame[0] = COMMAND_CLASS_USER_CODE;
frame[1] = USER_CODE_GET;
frame[2] = (uint8_t)user_id;
*frame_length = 3;
return SL_STATUS_OK;
Expand Down Expand Up @@ -540,7 +565,30 @@ static sl_status_t zwave_command_class_user_code_admin_code_get(
static sl_status_t zwave_command_class_user_code_keypad_mode_get(
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
{
(void)node; // unused.
attribute_store_node_t endpoint_node
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE_ENDPOINT_ID);
attribute_store_node_t version_node
= attribute_store_get_first_child_by_type(endpoint_node,
ATTRIBUTE(VERSION));
// We need to check the version of the supporting node:
zwave_cc_version_t supporting_node_version = 0;
attribute_store_get_reported(version_node,
&supporting_node_version,
sizeof(supporting_node_version));

if (supporting_node_version == 0) {
// Wait to know the supporting node version
*frame_length = 0;
return SL_STATUS_IS_WAITING;
}

if (supporting_node_version == 1) {
sl_log_warning(LOG_TAG, "Keypad Mode attribute found for v1 node. Deleting");
attribute_store_delete_node(node);
*frame_length = 0;
return SL_STATUS_ALREADY_EXISTS;
}

zwave_minimum_frame_t *get_frame = (zwave_minimum_frame_t *)frame;
get_frame->command_class = COMMAND_CLASS_USER_CODE_V2;
get_frame->command = USER_CODE_KEYPAD_MODE_GET_V2;
Expand All @@ -560,6 +608,30 @@ static sl_status_t zwave_command_class_user_code_keypad_mode_get(
static sl_status_t zwave_command_class_user_code_keypad_mode_set(
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
{
attribute_store_node_t endpoint_node
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE_ENDPOINT_ID);
attribute_store_node_t version_node
= attribute_store_get_first_child_by_type(endpoint_node,
ATTRIBUTE(VERSION));
// We need to check the version of the supporting node:
zwave_cc_version_t supporting_node_version = 0;
attribute_store_get_reported(version_node,
&supporting_node_version,
sizeof(supporting_node_version));

if (supporting_node_version == 0) {
// Wait to know the supporting node version
*frame_length = 0;
return SL_STATUS_IS_WAITING;
}

if (supporting_node_version == 1) {
sl_log_warning(LOG_TAG, "Keypad mode attribute found for v1 node. Deleting");
attribute_store_delete_node(node);
*frame_length = 0;
return SL_STATUS_ALREADY_EXISTS;
}

ZW_USER_CODE_KEYPAD_MODE_SET_V2_FRAME *set_frame
= (ZW_USER_CODE_KEYPAD_MODE_SET_V2_FRAME *)frame;
set_frame->cmdClass = COMMAND_CLASS_USER_CODE_V2;
Expand Down Expand Up @@ -653,8 +725,8 @@ static sl_status_t zwave_command_class_user_code_set(
&user_id_status,
sizeof(user_id_status));

frame[0] = COMMAND_CLASS_USER_CODE_V2;
frame[1] = USER_CODE_SET_V2;
frame[0] = COMMAND_CLASS_USER_CODE;
frame[1] = USER_CODE_SET;
frame[2] = (uint8_t)user_id;
frame[3] = user_id_status;
if (user_id_status == 0) {
Expand All @@ -670,6 +742,8 @@ static sl_status_t zwave_command_class_user_code_set(
}

*frame_length = 4 + user_code_size;
attribute_store_undefine_desired(user_code_node);
attribute_store_undefine_reported(user_code_node);
return SL_STATUS_OK;
}

Expand Down Expand Up @@ -786,8 +860,8 @@ static sl_status_t zwave_command_class_user_code_delete_all(
if (supporting_node_version == 1) {
ZW_USER_CODE_SET_4BYTE_FRAME *set_frame
= (ZW_USER_CODE_SET_4BYTE_FRAME *)frame;
set_frame->cmdClass = COMMAND_CLASS_USER_CODE_V2;
set_frame->cmd = USER_CODE_SET_V2;
set_frame->cmdClass = COMMAND_CLASS_USER_CODE;
set_frame->cmd = USER_CODE_SET;
set_frame->userIdentifier = 0;
set_frame->userIdStatus = 0;
set_frame->userCode1 = 0;
Expand Down Expand Up @@ -980,15 +1054,15 @@ static void zwave_command_class_user_code_on_code_update(
}

if (attribute_store_is_desired_defined(updated_node) == false) {
uic_mqtt_dotdot_door_lock_command_getpin_code_response_fields_t fields =
uic_mqtt_dotdot_door_lock_command_get_pin_code_response_fields_t fields =
{
.userid = (DrlkPINUserID) user_id,
.user_status = (DrlkUserStatus) user_status,
.user_type = (DrlkUserType) ZCL_DRLK_USER_TYPE_UNRESTRICTED_USER,
.code = pin_code
};

uic_mqtt_dotdot_door_lock_publish_generated_getpin_code_response_command(
uic_mqtt_dotdot_door_lock_publish_generated_get_pin_code_response_command(
node_unid, endpoint_id, &fields);
}
}
Expand Down
10 changes: 5 additions & 5 deletions components/uic_dotdot/dotdot-xml/DoorLock.xml
@@ -1,9 +1,9 @@
<?xml version="1.0"?>
<!--
Zigbee Alliance owns the copyright to the text and content displayed or
included in this document (including in PDF, XML files and other formats) in
all forms of media, which copyright is protected by the copyright laws of the
United States and by international treaties. Full text of licensing terms
<!--
Zigbee Alliance owns the copyright to the text and content displayed or
included in this document (including in PDF, XML files and other formats) in
all forms of media, which copyright is protected by the copyright laws of the
United States and by international treaties. Full text of licensing terms
applicable to this document can be found in the LICENSE.md file.
-->
<zcl:cluster xmlns:zcl="http://zigbee.org/zcl/clusters"
Expand Down
Expand Up @@ -189,7 +189,7 @@
#define DOTDOT_DOOR_LOCK_CLEAR_ALLRFID_CODES_RESPONSE_COMMAND_ID (0x19)
#define DOTDOT_DOOR_LOCK_OPERATING_EVENT_NOTIFICATION_COMMAND_ID (0x20)
#define DOTDOT_DOOR_LOCK_PROGRAMMING_EVENT_NOTIFICATION_COMMAND_ID (0x21)
#define DOTDOT_DOOR_LOCK_GET_ALLPIN_CODES_COMMAND_ID (0x80)
#define DOTDOT_DOOR_LOCK_GET_ALL_PIN_CODES_COMMAND_ID (0x80)

// Commands for cluster: WindowCovering
#define DOTDOT_WINDOW_COVERING_UP_OR_OPEN_COMMAND_ID (0x0)
Expand Down
Expand Up @@ -16706,7 +16706,7 @@ mosquitto_sub -t 'ucl/by-unid/<UNID>/<EP>/DoorLock/GeneratedCommands/Programming

<br><br>

\subsection door_lock_get_allpin_codes_cmd DoorLock/GetAllPINCodes Command
\subsection door_lock_get_all_pin_codes_cmd DoorLock/GetAllPINCodes Command

**MQTT Topic Pattern:**

Expand Down

0 comments on commit 6985a1d

Please sign in to comment.