Skip to content

Commit 8bd495d

Browse files
su-shankarzr
authored andcommitted
SwitchAll: Pull request #2832: UIC-3411: Base skeleton for ZPC Switch All CC handler
Merge in UIC/uic from feature/uic-3411-base-code-all-switch-cc to feature/UIC-3276-all-switch-cc Relate-to: #145 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent 1e85bde commit 8bd495d

File tree

4 files changed

+275
-0
lines changed

4 files changed

+275
-0
lines changed

applications/zpc/components/zwave_command_classes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ add_library(
4646
src/zwave_command_class_supervision.c
4747
src/zwave_command_class_supervision_process.cpp
4848
src/zwave_command_class_sound_switch.c
49+
src/zwave_command_class_switch_all.cpp
4950
src/zwave_command_class_switch_color.cpp
5051
src/zwave_command_class_switch_multilevel.c
5152
src/zwave_command_class_thermostat_mode.c
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
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_switch_all.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_SWITCH_ALL_##type
44+
45+
// Log tag
46+
constexpr char LOG_TAG[] = "zwave_command_class_switch_all";
47+
48+
49+
namespace
50+
{
51+
zwave_frame_generator frame_generator(COMMAND_CLASS_SWITCH_ALL);
52+
}
53+
54+
///////////////////////////////////////////////////////////////////////////////
55+
// Helper functions
56+
///////////////////////////////////////////////////////////////////////////////
57+
zwave_cc_version_t get_current_switch_all_version(attribute_store_node_t node)
58+
{
59+
zwave_cc_version_t version
60+
= zwave_command_class_get_version_from_node(node, COMMAND_CLASS_SWITCH_ALL);
61+
62+
if (version == 0) {
63+
sl_log_error(LOG_TAG, "switch_all Command Class Version not found");
64+
}
65+
66+
return version;
67+
}
68+
///////////////////////////////////////////////////////////////////////////////
69+
// Resolution functions
70+
///////////////////////////////////////////////////////////////////////////////
71+
//static sl_status_t zwave_command_class_switch_all_get(
72+
// attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
73+
//{
74+
// return frame_generator.generate_no_args_frame(switch_all_GET,
75+
// frame,
76+
// frame_length);
77+
//}
78+
79+
// static sl_status_t zwave_command_class_switch_all_set(
80+
// attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
81+
// {
82+
// try {
83+
// attribute_store::attribute value_node(node);
84+
// auto current_version = get_current_switch_all_version(node);
85+
//
86+
// // Compute expected size for set frame
87+
// const uint8_t expected_frame_size = 12;
88+
//
89+
// // Creating the frame
90+
// frame_generator.initialize_frame(switch_all_SET,
91+
// frame,
92+
// expected_frame_size);
93+
// frame_generator.add_value(value_node, DESIRED_OR_REPORTED_ATTRIBUTE);
94+
// frame_generator.validate_frame(frame_length);
95+
// } catch (const std::exception &e) {
96+
// sl_log_error(LOG_TAG,
97+
// "Error while generating switch_all Set frame : %s",
98+
// e.what());
99+
// return SL_STATUS_FAIL;
100+
// }
101+
//
102+
// return SL_STATUS_OK;
103+
//}
104+
105+
///////////////////////////////////////////////////////////////////////////////
106+
// Frame parsing functions
107+
///////////////////////////////////////////////////////////////////////////////
108+
//static sl_status_t zwave_command_class_switch_all_handle_report(
109+
// const zwave_controller_connection_info_t *connection_info,
110+
// const uint8_t *frame_data,
111+
// uint16_t frame_length)
112+
//{
113+
// // Setup
114+
// attribute_store::attribute endpoint_node(
115+
// zwave_command_class_get_endpoint_node(connection_info));
116+
// auto current_version = get_current_switch_all_version(endpoint_node);
117+
//
118+
// sl_log_debug(LOG_TAG, "switch_all Report frame received");
119+
//
120+
// // Compute expected size for report frame
121+
// const uint8_t expected_size = 12;
122+
123+
// // Parse the frame
124+
// try {
125+
// zwave_frame_parser parser(frame_data, frame_length);
126+
127+
// if (!parser.is_frame_size_valid(expected_size)) {
128+
// sl_log_error(LOG_TAG,
129+
// "Invalid frame size for switch_all Report frame");
130+
// return SL_STATUS_FAIL;
131+
// }
132+
133+
// } catch (const std::exception &e) {
134+
// sl_log_error(LOG_TAG,
135+
// "Error while parsing switch_all Report frame : %s",
136+
// e.what());
137+
// return SL_STATUS_FAIL;
138+
// }
139+
// return SL_STATUS_OK;
140+
//}
141+
142+
///////////////////////////////////////////////////////////////////////////////
143+
// Incoming commands handler
144+
///////////////////////////////////////////////////////////////////////////////
145+
sl_status_t zwave_command_class_switch_all_control_handler(
146+
const zwave_controller_connection_info_t *connection_info,
147+
const uint8_t *frame_data,
148+
uint16_t frame_length)
149+
{
150+
// Frame too short, it should have not come here.
151+
if (frame_length <= COMMAND_INDEX) {
152+
return SL_STATUS_NOT_SUPPORTED;
153+
}
154+
155+
switch (frame_data[COMMAND_INDEX]) {
156+
// case switch_all_REPORT:
157+
// return zwave_command_class_switch_all_handle_report(connection_info,
158+
// frame_data,
159+
// frame_length);
160+
default:
161+
return SL_STATUS_NOT_SUPPORTED;
162+
}
163+
}
164+
165+
///////////////////////////////////////////////////////////////////////////////
166+
// Attribute Store callback functions
167+
///////////////////////////////////////////////////////////////////////////////
168+
static void zwave_command_class_switch_all_on_version_attribute_update(
169+
attribute_store_node_t updated_node, attribute_store_change_t change)
170+
{
171+
if (change == ATTRIBUTE_DELETED) {
172+
return;
173+
}
174+
175+
// Confirm that we have a version attribute update
176+
assert(ATTRIBUTE(VERSION) == attribute_store_get_node_type(updated_node));
177+
178+
attribute_store::attribute version_node(updated_node);
179+
// Do not create the attributes until we are sure of the version
180+
//zwave_cc_version_t supporting_node_version = 0;
181+
182+
// Wait for the version
183+
if (!version_node.reported_exists()) {
184+
return;
185+
}
186+
//supporting_node_version = version_node.reported<uint8_t>();
187+
188+
// Now we know we have a switch_all supporting endpoint.
189+
attribute_store::attribute endpoint_node
190+
= version_node.first_parent(ATTRIBUTE_ENDPOINT_ID);
191+
192+
// Create the switch_all attributes
193+
endpoint_node.emplace_node(ATTRIBUTE(MODE));
194+
195+
endpoint_node.first_parent(ATTRIBUTE_HOME_ID).emplace_node(ATTRIBUTE(ON_OFF));
196+
197+
}
198+
199+
///////////////////////////////////////////////////////////////////////////////
200+
// Public interface functions
201+
///////////////////////////////////////////////////////////////////////////////
202+
sl_status_t zwave_command_class_switch_all_init()
203+
{
204+
// Attribute store callbacks
205+
attribute_store_register_callback_by_type(
206+
zwave_command_class_switch_all_on_version_attribute_update,
207+
ATTRIBUTE(VERSION));
208+
209+
// Attribute resolver rules
210+
// attribute_resolver_register_rule(ATTRIBUTE(MODE),
211+
// zwave_command_class_switch_all_set,
212+
// zwave_command_class_switch_all_get);
213+
// attribute_resolver_register_rule(ATTRIBUTE(ON_OFF),
214+
// zwave_command_class_switch_all_set,
215+
// nullptr);
216+
217+
// The support side of things: Register our handler to the Z-Wave CC framework:
218+
zwave_command_handler_t handler = {};
219+
handler.support_handler = NULL;
220+
handler.control_handler = &zwave_command_class_switch_all_control_handler;
221+
// Not supported, so this does not really matter
222+
handler.minimal_scheme = ZWAVE_CONTROLLER_ENCAPSULATION_NETWORK_SCHEME;
223+
handler.manual_security_validation = false;
224+
handler.command_class = COMMAND_CLASS_SWITCH_ALL;
225+
handler.version = SWITCH_ALL_VERSION;
226+
handler.command_class_name = "switch_all";
227+
handler.comments = "";
228+
229+
zwave_command_handler_register_handler(handler);
230+
231+
return SL_STATUS_OK;
232+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_switch_all
16+
* @brief TODO: Switch All Command Class handlers and control function
17+
*
18+
* This module implement some of the functions to control the
19+
* Switch All Command Class
20+
*
21+
* @{
22+
*/
23+
24+
#ifndef ZWAVE_COMMAND_CLASS_SWITCH_ALL_H
25+
#define ZWAVE_COMMAND_CLASS_SWITCH_ALL_H
26+
27+
#include "sl_status.h"
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
sl_status_t zwave_command_class_switch_all_init();
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
39+
#endif //ZWAVE_COMMAND_CLASS_SWITCH_ALL_H
40+
/** @} end zwave_command_class_switch_all */

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_switch_all.h"
6263
#include "zwave_command_class_protocol.h"
6364

6465
// Generic includes
@@ -116,6 +117,7 @@ sl_status_t zwave_command_classes_init()
116117
status |= zwave_command_class_security_2_init();
117118
status |= zwave_command_class_sound_switch_init();
118119
status |= zwave_command_class_supervision_init();
120+
status |= zwave_command_class_switch_all_init();
119121
status |= zwave_command_class_switch_color_init();
120122
status |= zwave_command_class_switch_multilevel_init();
121123
status |= zwave_command_class_thermostat_mode_init();

0 commit comments

Comments
 (0)