Skip to content

Commit 22dca86

Browse files
Thirsrinrzr
authored andcommitted
UIC-3435:Base skeleton code for schedule entry lock CC
Merge in UIC/uic from feature/UIC-3435-Base-Skeleton-Code-Schedule-Entry-Lock-CC to feature/UIC-3271-Schedule-Entry-Lock-CC
1 parent d55edd0 commit 22dca86

File tree

3 files changed

+285
-0
lines changed

3 files changed

+285
-0
lines changed
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
/******************************************************************************
2+
* # License
3+
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
4+
******************************************************************************
5+
* The licensor of this software is Silicon Laboratories Inc. Your use of this
6+
* software is governed by the terms of Silicon Labs Master Software License
7+
* Agreement (MSLA) available at
8+
* www.silabs.com/about-us/legal/master-software-license-agreement. This
9+
* software is distributed to you in Source Code format and is governed by the
10+
* sections of the MSLA applicable to Source Code.
11+
*
12+
*****************************************************************************/
13+
// Includes from this component
14+
#include "zwave_command_class_schedule_entry_lock.h"
15+
#include "zwave_command_classes_utils.h"
16+
17+
// Generic includes
18+
#include <stdlib.h>
19+
#include <assert.h>
20+
21+
// Includes from other ZPC Components
22+
#include "zwave_command_class_indices.h"
23+
#include "zwave_command_handler.h"
24+
#include "zpc_attribute_store_network_helper.h"
25+
#include "attribute_store_defined_attribute_types.h"
26+
#include "ZW_classcmd.h"
27+
#include "zpc_attribute_resolver.h"
28+
29+
// Includes from other Unify Components
30+
#include "dotdot_mqtt.h"
31+
#include "dotdot_mqtt_generated_commands.h"
32+
#include "attribute_store_helper.h"
33+
#include "attribute_resolver.h"
34+
#include "attribute_timeouts.h"
35+
#include "sl_log.h"
36+
37+
// Cpp include
38+
#include "attribute.hpp"
39+
#include "zwave_frame_generator.hpp"
40+
#include "zwave_frame_parser.hpp"
41+
42+
// Attribute macro, shortening those long defines for attribute types:
43+
#define ATTRIBUTE(type) ATTRIBUTE_COMMAND_CLASS_SCHEDULE_ENTRY_LOCK_##type
44+
45+
// Log tag
46+
constexpr char LOG_TAG[] = "zwave_command_class_schedule_entry_lock";
47+
48+
49+
// Cpp helpers
50+
namespace
51+
{
52+
const zwave_frame_generator frame_generator(COMMAND_CLASS_SCHEDULE_ENTRY_LOCK); //NOSONAR - false positive since it is warped in a namespace
53+
}
54+
55+
///////////////////////////////////////////////////////////////////////////////
56+
// Helper functions
57+
///////////////////////////////////////////////////////////////////////////////
58+
zwave_cc_version_t get_current_schedule_entry_lock_version(attribute_store_node_t node)
59+
{
60+
zwave_cc_version_t version
61+
= zwave_command_class_get_version_from_node(node, COMMAND_CLASS_SCHEDULE_ENTRY_LOCK);
62+
63+
if (version == 0) {
64+
sl_log_error(LOG_TAG, "schedule_entry_lock Command Class Version not found");
65+
}
66+
67+
return version;
68+
}
69+
///////////////////////////////////////////////////////////////////////////////
70+
// Resolution functions
71+
///////////////////////////////////////////////////////////////////////////////
72+
//static sl_status_t zwave_command_class_schedule_entry_lock_get(
73+
// attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
74+
//{
75+
// return frame_generator.generate_no_args_frame(schedule_entry_lock_GET,
76+
// frame,
77+
// frame_length);
78+
//}
79+
80+
// static sl_status_t zwave_command_class_schedule_entry_lock_set(
81+
// attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
82+
// {
83+
// try {
84+
// attribute_store::attribute value_node(node);
85+
// auto current_version = get_current_schedule_entry_lock_version(node);
86+
//
87+
// // Compute expected size for set frame
88+
// const uint8_t expected_frame_size = 12;
89+
//
90+
// // Creating the frame
91+
// frame_generator.initialize_frame(schedule_entry_lock_SET,
92+
// frame,
93+
// expected_frame_size);
94+
// frame_generator.add_value(value_node, DESIRED_OR_REPORTED_ATTRIBUTE);
95+
// frame_generator.validate_frame(frame_length);
96+
// } catch (const std::exception &e) {
97+
// sl_log_error(LOG_TAG,
98+
// "Error while generating schedule_entry_lock Set frame : %s",
99+
// e.what());
100+
// return SL_STATUS_FAIL;
101+
// }
102+
//
103+
// return SL_STATUS_OK;
104+
//}
105+
106+
///////////////////////////////////////////////////////////////////////////////
107+
// Frame parsing functions
108+
///////////////////////////////////////////////////////////////////////////////
109+
//static sl_status_t zwave_command_class_schedule_entry_lock_handle_report(
110+
// const zwave_controller_connection_info_t *connection_info,
111+
// const uint8_t *frame_data,
112+
// uint16_t frame_length)
113+
//{
114+
// // Setup
115+
// attribute_store::attribute endpoint_node(
116+
// zwave_command_class_get_endpoint_node(connection_info));
117+
// auto current_version = get_current_schedule_entry_lock_version(endpoint_node);
118+
//
119+
// sl_log_debug(LOG_TAG, "schedule_entry_lock Report frame received");
120+
//
121+
// // Compute expected size for report frame
122+
// const uint8_t expected_size = 12;
123+
124+
// // Parse the frame
125+
// try {
126+
// zwave_frame_parser parser(frame_data, frame_length);
127+
128+
// if (!parser.is_frame_size_valid(expected_size)) {
129+
// sl_log_error(LOG_TAG,
130+
// "Invalid frame size for schedule_entry_lock Report frame");
131+
// return SL_STATUS_FAIL;
132+
// }
133+
134+
// } catch (const std::exception &e) {
135+
// sl_log_error(LOG_TAG,
136+
// "Error while parsing schedule_entry_lock Report frame : %s",
137+
// e.what());
138+
// return SL_STATUS_FAIL;
139+
// }
140+
// return SL_STATUS_OK;
141+
//}
142+
143+
///////////////////////////////////////////////////////////////////////////////
144+
// Incoming commands handler
145+
///////////////////////////////////////////////////////////////////////////////
146+
sl_status_t zwave_command_class_schedule_entry_lock_control_handler(
147+
const zwave_controller_connection_info_t *connection_info,
148+
const uint8_t *frame_data,
149+
uint16_t frame_length)
150+
{
151+
// Frame too short, it should have not come here.
152+
if (frame_length <= COMMAND_INDEX) {
153+
return SL_STATUS_NOT_SUPPORTED;
154+
}
155+
156+
switch (frame_data[COMMAND_INDEX]) {
157+
// case schedule_entry_lock_REPORT:
158+
// return zwave_command_class_schedule_entry_lock_handle_report(connection_info,
159+
// frame_data,
160+
// frame_length);
161+
default:
162+
return SL_STATUS_NOT_SUPPORTED;
163+
}
164+
}
165+
166+
///////////////////////////////////////////////////////////////////////////////
167+
// Attribute Store callback functions
168+
///////////////////////////////////////////////////////////////////////////////
169+
static void zwave_command_class_schedule_entry_lock_on_version_attribute_update(
170+
attribute_store_node_t updated_node, attribute_store_change_t change)
171+
{
172+
if (change == ATTRIBUTE_DELETED) {
173+
return;
174+
}
175+
176+
// Confirm that we have a version attribute update
177+
assert(ATTRIBUTE(VERSION) == attribute_store_get_node_type(updated_node));
178+
179+
attribute_store::attribute version_node(updated_node);
180+
// Do not create the attributes until we are sure of the version
181+
zwave_cc_version_t supporting_node_version = 0;
182+
183+
// Wait for the version
184+
if (!version_node.reported_exists()) {
185+
return;
186+
}
187+
supporting_node_version = version_node.reported<uint8_t>();
188+
189+
// Now we know we have a schedule_entry_lock supporting endpoint.
190+
attribute_store::attribute endpoint_node
191+
= version_node.first_parent(ATTRIBUTE_ENDPOINT_ID);
192+
193+
// Create the schedule_entry_lock attributes
194+
attribute_store::attribute userid_node = endpoint_node.emplace_node(ATTRIBUTE(USER_IDENTIFIER));
195+
196+
userid_node.emplace_node(ATTRIBUTE(ENABLED));
197+
198+
endpoint_node.emplace_node(ATTRIBUTE(ENABLE_ALL));
199+
200+
userid_node.emplace_node(ATTRIBUTE(SLOTS_WEEK_DAY));
201+
202+
if (supporting_node_version >= 2) {
203+
endpoint_node.emplace_node(ATTRIBUTE(HOUR_TZO));
204+
}
205+
206+
}
207+
208+
///////////////////////////////////////////////////////////////////////////////
209+
// Public interface functions
210+
///////////////////////////////////////////////////////////////////////////////
211+
sl_status_t zwave_command_class_schedule_entry_lock_init()
212+
{
213+
// Attribute store callbacks
214+
attribute_store_register_callback_by_type(
215+
zwave_command_class_schedule_entry_lock_on_version_attribute_update,
216+
ATTRIBUTE(VERSION));
217+
218+
// Attribute resolver rules
219+
// attribute_resolver_register_rule(ATTRIBUTE(SLOTS_WEEK_DAY), NULL, &schedule_entry_lock_supported_get);
220+
// attribute_resolver_register_rule(ATTRIBUTE(HOUR_TZO), &schedule_entry_lock_time_offset_set, &schedule_entry_lock_time_offset_get);
221+
// attribute_resolver_register_rule(ATTRIBUTE(ENABLED), &schedule_entry_lock_enable_set, NULL);
222+
// attribute_resolver_register_rule(ATTRIBUTE(ENABLE_ALL), &schedule_entry_lock_enable_set, NULL);
223+
224+
// The support side of things: Register our handler to the Z-Wave CC framework:
225+
zwave_command_handler_t handler = {};
226+
handler.support_handler = NULL;
227+
handler.control_handler = &zwave_command_class_schedule_entry_lock_control_handler;
228+
// Not supported, so this does not really matter
229+
handler.minimal_scheme = ZWAVE_CONTROLLER_ENCAPSULATION_NETWORK_SCHEME;
230+
handler.manual_security_validation = false;
231+
handler.command_class = COMMAND_CLASS_SCHEDULE_ENTRY_LOCK;
232+
handler.version = SCHEDULE_ENTRY_LOCK_VERSION_V3;
233+
handler.command_class_name = "schedule_entry_lock";
234+
handler.comments = "";
235+
236+
zwave_command_handler_register_handler(handler);
237+
238+
return SL_STATUS_OK;
239+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/******************************************************************************
2+
* # License
3+
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
4+
******************************************************************************
5+
* The licensor of this software is Silicon Laboratories Inc. Your use of this
6+
* software is governed by the terms of Silicon Labs Master Software License
7+
* Agreement (MSLA) available at
8+
* www.silabs.com/about-us/legal/master-software-license-agreement. This
9+
* software is distributed to you in Source Code format and is governed by the
10+
* sections of the MSLA applicable to Source Code.
11+
*
12+
*****************************************************************************/
13+
14+
/**
15+
* @defgroup zwave_command_class_schedule_entry_lock
16+
* @brief TODO: Write brief for zwave_command_class_schedule_entry_lock
17+
*
18+
* TODO: Write component description for zwave_command_class_schedule_entry_lock
19+
*
20+
* @{
21+
*/
22+
23+
#ifndef ZWAVE_COMMAND_CLASS_SCHEDULE_ENTRY_LOCK_H
24+
#define ZWAVE_COMMAND_CLASS_SCHEDULE_ENTRY_LOCK_H
25+
26+
#include "sl_status.h"
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
/**
33+
* @brief This function initialize the schedule Entry Lock Command Class handler
34+
*
35+
* @return SL_STATUS_OK on success, any other error code for an error.
36+
*/
37+
sl_status_t zwave_command_class_schedule_entry_lock_init();
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#endif //ZWAVE_COMMAND_CLASS_SCHEDULE_ENTRY_LOCK_H
44+
/** @} end zwave_command_class_schedule_entry_lock */

applications/zpc/components/zwave_command_classes/src/zwave_command_classes_fixt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "zwave_command_class_indicator_control.h"
6060
#include "zwave_command_class_manufacturer_specific_control.h"
6161
#include "zwave_command_class_humidity_control_mode.h"
62+
#include "zwave_command_class_schedule_entry_lock.h"
6263
#include "zwave_command_class_protocol.h"
6364

6465
// Generic includes
@@ -114,6 +115,7 @@ sl_status_t zwave_command_classes_init()
114115
status |= zwave_command_class_scene_controller_configuration_control_init();
115116
status |= zwave_command_class_security_0_init();
116117
status |= zwave_command_class_security_2_init();
118+
status |= zwave_command_class_schedule_entry_lock_init();
117119
status |= zwave_command_class_sound_switch_init();
118120
status |= zwave_command_class_supervision_init();
119121
status |= zwave_command_class_switch_color_init();

0 commit comments

Comments
 (0)