43
43
#define ATTRIBUTE (type ) ATTRIBUTE_COMMAND_CLASS_NOTIFICATION_##type
44
44
45
45
// 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" ;
47
48
static constexpr unsigned int MAX_SUPPORTED_NOTIFICATION_TYPES = 24 ;
48
49
static constexpr unsigned int MAX_SUPPORTED_NOTIFICATION_STATES = 256 ;
49
50
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(
63
64
if (notification_event == 0xFE ) {
64
65
notification_event = 0 ;
65
66
}
67
+ auto version_node = notification_type_node.parent ().child_by_type (ATTRIBUTE (VERSION));
68
+ zwave_cc_version_t version = version_node.reported <uint8_t >();
66
69
67
- attribute notification_event_node
70
+ attribute notification_event_node;
71
+ if (version > 2 )
72
+ {
73
+ notification_event_node
68
74
= attribute_store_get_node_child_by_value (notification_type_node,
69
75
ATTRIBUTE (STATE),
70
76
REPORTED_ATTRIBUTE,
71
77
&state,
72
78
sizeof (state),
73
79
0 );
74
- notification_event_node
80
+ notification_event_node
75
81
= 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
+
76
99
77
100
if (!notification_event_node.is_valid ()) {
78
101
sl_log_debug (LOG_TAG,
@@ -84,6 +107,7 @@ static sl_status_t zwave_command_class_notification_update_state_event(
84
107
}
85
108
notification_event_node.set_reported (notification_event);
86
109
110
+
87
111
uint8_t state_event_param_len
88
112
= frame->properties1
89
113
& NOTIFICATION_REPORT_PROPERTIES1_EVENT_PARAMETERS_LENGTH_MASK_V4;
@@ -103,6 +127,10 @@ static sl_status_t zwave_command_class_notification_update_state_event(
103
127
// Length (state_event_param_len) is zero (attribute back to undefined)
104
128
int32_t state_event = frame->eventParameter1 ;
105
129
notification_event_param.set_reported (state_event);
130
+ sl_log_info (NOTIFICATION_TAG,
131
+ " Event: %u Param: %u" ,
132
+ notification_event,
133
+ state_event);
106
134
} else {
107
135
// No Event/state parameter byte added to the payload, we just undefine the
108
136
// value again.
@@ -160,6 +188,10 @@ static sl_status_t zwave_command_class_notification_report_cmd_handler(
160
188
= v1_alarm_type_node.add_node (ATTRIBUTE (V1_ALARM_LEVEL));
161
189
vl_alarm_level_node.set_reported (frame->v1AlarmLevel );
162
190
}
191
+ sl_log_info (NOTIFICATION_TAG,
192
+ " <V1 Type: %u> level: %u" ,
193
+ v1_alarm_type,
194
+ frame->v1AlarmLevel );
163
195
}
164
196
165
197
const uint8_t notification_type = frame->notificationType ;
@@ -417,6 +449,10 @@ static sl_status_t
417
449
attribute_store_add_node (ATTRIBUTE (SUPPORTED_STATES_OR_EVENTS),
418
450
notification_type);
419
451
}
452
+ else if (version > 1 )
453
+ {
454
+ attribute_store_add_node (ATTRIBUTE (STATE), notification_type);
455
+ }
420
456
}
421
457
}
422
458
@@ -698,6 +734,39 @@ void zwave_command_class_notification_on_version_attribute_update(
698
734
}
699
735
}
700
736
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
+ ¬ification_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
+
701
770
static sl_status_t zwave_command_class_notification_get (
702
771
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_len)
703
772
{
@@ -790,6 +859,9 @@ sl_status_t zwave_command_class_notification_init()
790
859
ATTRIBUTE (SUPPORTED_NOTIFICATION_TYPES),
791
860
nullptr ,
792
861
zwave_command_class_supported_notification_types_get);
862
+ attribute_resolver_register_rule (ATTRIBUTE (STATE),
863
+ nullptr ,
864
+ zwave_command_class_alarm_get);
793
865
attribute_resolver_register_rule (ATTRIBUTE (EVENT),
794
866
nullptr ,
795
867
zwave_command_class_notification_get);
0 commit comments