Skip to content

Commit 647aac3

Browse files
su-shankarzr
authored andcommitted
uic: zpc: Pull request #2853: UIC-3504: Updated Notification CC to support Alarm CC v1 and v2
(cherry picked from commit 82c13e1e65a7337aa6b0ef59291712c7154b33c7) Forwarded: #11 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent c2b9399 commit 647aac3

File tree

2 files changed

+341
-3
lines changed

2 files changed

+341
-3
lines changed

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

+75-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
#define ATTRIBUTE(type) ATTRIBUTE_COMMAND_CLASS_NOTIFICATION_##type
4444

4545
// Log tag
46-
static constexpr char LOG_TAG[] = "zwave_command_class_notification";
46+
static constexpr char LOG_TAG[] = "zwave_command_class_notification";
47+
static constexpr char NOTIFICATION_TAG[] = "NOTIFICATION";
4748
static constexpr unsigned int MAX_SUPPORTED_NOTIFICATION_TYPES = 24;
4849
static constexpr unsigned int MAX_SUPPORTED_NOTIFICATION_STATES = 256;
4950
static constexpr unsigned int NOTIFICATION_REPORT_EVENT_STATE_PARAMETER_OFFSET
@@ -63,16 +64,38 @@ static sl_status_t zwave_command_class_notification_update_state_event(
6364
if (notification_event == 0xFE) {
6465
notification_event = 0;
6566
}
67+
auto version_node = notification_type_node.parent().child_by_type(ATTRIBUTE(VERSION));
68+
zwave_cc_version_t version = version_node.reported<uint8_t>();
6669

67-
attribute notification_event_node
70+
attribute notification_event_node;
71+
if (version > 2)
72+
{
73+
notification_event_node
6874
= attribute_store_get_node_child_by_value(notification_type_node,
6975
ATTRIBUTE(STATE),
7076
REPORTED_ATTRIBUTE,
7177
&state,
7278
sizeof(state),
7379
0);
74-
notification_event_node
80+
notification_event_node
7581
= notification_event_node.child_by_type(ATTRIBUTE(EVENT), 0);
82+
sl_log_info(NOTIFICATION_TAG,
83+
"<zwAlarm Type: %u> State: %u Event: %u",
84+
notification_type_node.reported<uint8_t>(),
85+
state,
86+
notification_event);
87+
}
88+
else
89+
{
90+
// version 1 and 2 do not have a concept of state hence it will be a dummy parent node
91+
auto state_node = notification_type_node.child_by_type(ATTRIBUTE(STATE));
92+
notification_event_node = state_node.emplace_node(ATTRIBUTE(EVENT));
93+
sl_log_info(NOTIFICATION_TAG,
94+
"<zwAlarm Type: %u> Event: %u",
95+
notification_type_node.reported<uint8_t>(),
96+
notification_event);
97+
}
98+
7699

77100
if (!notification_event_node.is_valid()) {
78101
sl_log_debug(LOG_TAG,
@@ -84,6 +107,7 @@ static sl_status_t zwave_command_class_notification_update_state_event(
84107
}
85108
notification_event_node.set_reported(notification_event);
86109

110+
87111
uint8_t state_event_param_len
88112
= frame->properties1
89113
& NOTIFICATION_REPORT_PROPERTIES1_EVENT_PARAMETERS_LENGTH_MASK_V4;
@@ -103,6 +127,10 @@ static sl_status_t zwave_command_class_notification_update_state_event(
103127
// Length (state_event_param_len) is zero (attribute back to undefined)
104128
int32_t state_event = frame->eventParameter1;
105129
notification_event_param.set_reported(state_event);
130+
sl_log_info(NOTIFICATION_TAG,
131+
"Event: %u Param: %u",
132+
notification_event,
133+
state_event);
106134
} else {
107135
// No Event/state parameter byte added to the payload, we just undefine the
108136
// value again.
@@ -160,6 +188,10 @@ static sl_status_t zwave_command_class_notification_report_cmd_handler(
160188
= v1_alarm_type_node.add_node(ATTRIBUTE(V1_ALARM_LEVEL));
161189
vl_alarm_level_node.set_reported(frame->v1AlarmLevel);
162190
}
191+
sl_log_info(NOTIFICATION_TAG,
192+
"<V1 Type: %u> level: %u",
193+
v1_alarm_type,
194+
frame->v1AlarmLevel);
163195
}
164196

165197
const uint8_t notification_type = frame->notificationType;
@@ -417,6 +449,10 @@ static sl_status_t
417449
attribute_store_add_node(ATTRIBUTE(SUPPORTED_STATES_OR_EVENTS),
418450
notification_type);
419451
}
452+
else if (version > 1)
453+
{
454+
attribute_store_add_node(ATTRIBUTE(STATE), notification_type);
455+
}
420456
}
421457
}
422458

@@ -698,6 +734,39 @@ void zwave_command_class_notification_on_version_attribute_update(
698734
}
699735
}
700736

737+
static sl_status_t zwave_command_class_alarm_get(
738+
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_len)
739+
{
740+
auto alarm_get_frame
741+
= reinterpret_cast<ZW_ALARM_GET_V2_FRAME *>(frame);
742+
743+
attribute_store::attribute ep_node
744+
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE_ENDPOINT_ID);
745+
auto version_node = ep_node.child_by_type(ATTRIBUTE(VERSION));
746+
zwave_cc_version_t version = version_node.reported<zwave_cc_version_t>();
747+
748+
if (version > 2)
749+
{
750+
sl_log_error(LOG_TAG, "Should not be called for versions > v2");
751+
return SL_STATUS_FAIL;
752+
}
753+
alarm_get_frame->cmdClass = COMMAND_CLASS_NOTIFICATION_V8;
754+
alarm_get_frame->cmd = NOTIFICATION_GET_V8;
755+
alarm_get_frame->alarmType = 0x00; //v1 AlarmType
756+
// read the Notification type
757+
attribute_store_node_t type_node
758+
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE(TYPE));
759+
uint8_t notification_type;
760+
attribute_store_get_reported(type_node,
761+
&notification_type,
762+
sizeof(notification_type));
763+
alarm_get_frame->zwaveAlarmType = notification_type;
764+
765+
*frame_len = sizeof(ZW_ALARM_GET_V2_FRAME);
766+
767+
return SL_STATUS_OK;
768+
}
769+
701770
static sl_status_t zwave_command_class_notification_get(
702771
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_len)
703772
{
@@ -790,6 +859,9 @@ sl_status_t zwave_command_class_notification_init()
790859
ATTRIBUTE(SUPPORTED_NOTIFICATION_TYPES),
791860
nullptr,
792861
zwave_command_class_supported_notification_types_get);
862+
attribute_resolver_register_rule(ATTRIBUTE(STATE),
863+
nullptr,
864+
zwave_command_class_alarm_get);
793865
attribute_resolver_register_rule(ATTRIBUTE(EVENT),
794866
nullptr,
795867
zwave_command_class_notification_get);

0 commit comments

Comments
 (0)