Skip to content

Commit 558d857

Browse files
su-shankarzr
authored andcommitted
SwitchAll: Pull request #2842: Report callback for Switch All CC
Relate-to: #145 Signed-off-by: Philippe Coval <[email protected]>
1 parent 432b6bc commit 558d857

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

applications/zpc/components/zwave_command_classes/src/zwave_command_class_switch_all.cpp

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ static sl_status_t zwave_command_class_switch_all_set_on_off(
108108
}
109109
if (!send_command) {
110110
sl_log_debug(LOG_TAG,
111-
"Not sending command %d since mode is %d",
112-
zwave_command_id,
113-
mode);
111+
"Not sending command %d since mode is %d",
112+
zwave_command_id,
113+
mode);
114114
return SL_STATUS_OK;
115115
}
116116
return frame_generator.generate_no_args_frame(zwave_command_id,
@@ -162,39 +162,41 @@ static sl_status_t zwave_command_class_switch_all_set(
162162
///////////////////////////////////////////////////////////////////////////////
163163
// Frame parsing functions
164164
///////////////////////////////////////////////////////////////////////////////
165-
//static sl_status_t zwave_command_class_switch_all_handle_report(
166-
// const zwave_controller_connection_info_t *connection_info,
167-
// const uint8_t *frame_data,
168-
// uint16_t frame_length)
169-
//{
170-
// // Setup
171-
// attribute_store::attribute endpoint_node(
172-
// zwave_command_class_get_endpoint_node(connection_info));
173-
// auto current_version = get_current_switch_all_version(endpoint_node);
174-
//
175-
// sl_log_debug(LOG_TAG, "switch_all Report frame received");
176-
//
177-
// // Compute expected size for report frame
178-
// const uint8_t expected_size = 12;
179-
180-
// // Parse the frame
181-
// try {
182-
// zwave_frame_parser parser(frame_data, frame_length);
183-
184-
// if (!parser.is_frame_size_valid(expected_size)) {
185-
// sl_log_error(LOG_TAG,
186-
// "Invalid frame size for switch_all Report frame");
187-
// return SL_STATUS_FAIL;
188-
// }
189-
190-
// } catch (const std::exception &e) {
191-
// sl_log_error(LOG_TAG,
192-
// "Error while parsing switch_all Report frame : %s",
193-
// e.what());
194-
// return SL_STATUS_FAIL;
195-
// }
196-
// return SL_STATUS_OK;
197-
//}
165+
static sl_status_t zwave_command_class_switch_all_handle_report(
166+
const zwave_controller_connection_info_t *connection_info,
167+
const uint8_t *frame_data,
168+
uint16_t frame_length)
169+
{
170+
// Setup
171+
attribute_store::attribute endpoint_node(
172+
zwave_command_class_get_endpoint_node(connection_info));
173+
174+
sl_log_debug(LOG_TAG, "Switch All Report frame received");
175+
176+
// Compute expected size for report frame
177+
const uint8_t expected_size = 3;
178+
179+
// Parse the frame
180+
try {
181+
zwave_frame_parser parser(frame_data, frame_length);
182+
183+
if (!parser.is_frame_size_valid(expected_size)) {
184+
sl_log_error(LOG_TAG, "Invalid frame size for switch_all Report frame");
185+
return SL_STATUS_FAIL;
186+
}
187+
188+
attribute_store::attribute mode
189+
= endpoint_node.child_by_type(ATTRIBUTE(MODE));
190+
parser.read_byte(mode);
191+
192+
} catch (const std::exception &e) {
193+
sl_log_error(LOG_TAG,
194+
"Error while parsing switch_all Report frame : %s",
195+
e.what());
196+
return SL_STATUS_FAIL;
197+
}
198+
return SL_STATUS_OK;
199+
}
198200

199201
///////////////////////////////////////////////////////////////////////////////
200202
// Incoming commands handler
@@ -210,10 +212,10 @@ sl_status_t zwave_command_class_switch_all_control_handler(
210212
}
211213

212214
switch (frame_data[COMMAND_INDEX]) {
213-
// case switch_all_REPORT:
214-
// return zwave_command_class_switch_all_handle_report(connection_info,
215-
// frame_data,
216-
// frame_length);
215+
case SWITCH_ALL_REPORT:
216+
return zwave_command_class_switch_all_handle_report(connection_info,
217+
frame_data,
218+
frame_length);
217219
default:
218220
return SL_STATUS_NOT_SUPPORTED;
219221
}

0 commit comments

Comments
 (0)