From db3a8e63e7ada18f6e0379f886d4e447107f1736 Mon Sep 17 00:00:00 2001 From: Nenad Kljajic Date: Tue, 28 Nov 2023 08:26:28 +0100 Subject: [PATCH 1/3] GH-20: Fix support for COMMAND_CLASS_METER V1,V2 & V3 Fixes bug where Attribute [0x3208] Value can not get resolved for legacy devices. Size of ZW_METER_GET_V3_FRAME is smaller than size of ZW_METER_GET_V5_FRAME. Legacy device supporting COMMAND_CLASS_METER_V3 and below will ignore received V5 frames, because frame size is larger than expected. Signed-off-by: Nenad Kljajic --- .../src/zwave_command_class_meter_control.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/applications/zpc/components/zwave_command_classes/src/zwave_command_class_meter_control.c b/applications/zpc/components/zwave_command_classes/src/zwave_command_class_meter_control.c index ae1698f633..f92bfddd64 100644 --- a/applications/zpc/components/zwave_command_classes/src/zwave_command_class_meter_control.c +++ b/applications/zpc/components/zwave_command_classes/src/zwave_command_class_meter_control.c @@ -205,6 +205,9 @@ static sl_status_t zwave_command_class_meter_get(attribute_store_node_t node, attribute_store_node_t scale_node = attribute_store_get_first_parent_with_type(rate_type_node, ATTRIBUTE(SCALE)); + zwave_cc_version_t supporting_node_version + = zwave_command_class_get_version_from_node(node, COMMAND_CLASS_METER); + meter_scale_t scale = 0; attribute_store_get_reported(scale_node, &scale, sizeof(scale)); @@ -212,6 +215,11 @@ static sl_status_t zwave_command_class_meter_get(attribute_store_node_t node, get_frame->cmdClass = COMMAND_CLASS_METER_V6; get_frame->cmd = METER_GET; + if (supporting_node_version == 1) { + *frame_length = sizeof(ZW_METER_GET_FRAME); + return SL_STATUS_OK; + } + // Insert the rate type into the frame: get_frame->properties1 = (uint8_t)(rate_type << 6); if (scale < 7) { @@ -222,6 +230,11 @@ static sl_status_t zwave_command_class_meter_get(attribute_store_node_t node, get_frame->scale2 = (uint8_t)(scale - 8); } + if (supporting_node_version <= 3) { + *frame_length = sizeof(ZW_METER_GET_V3_FRAME); + return SL_STATUS_OK; + } + *frame_length = sizeof(ZW_METER_GET_V5_FRAME); return SL_STATUS_OK; } @@ -244,12 +257,10 @@ static sl_status_t zwave_command_class_meter_supported_get( = zwave_command_class_get_version_from_node(node, COMMAND_CLASS_METER); if (supporting_node_version == 1) { - ZW_METER_GET_V5_FRAME *get_frame = (ZW_METER_GET_V5_FRAME *)frame; - get_frame->cmdClass = COMMAND_CLASS_METER_V6; + ZW_METER_GET_FRAME *get_frame = (ZW_METER_GET_FRAME *)frame; + get_frame->cmdClass = COMMAND_CLASS_METER; get_frame->cmd = METER_GET; - get_frame->properties1 = 0; - get_frame->scale2 = 0; - *frame_length = sizeof(ZW_METER_GET_V5_FRAME); + *frame_length = sizeof(ZW_METER_GET_FRAME); return SL_STATUS_OK; } From 8acd3a1f38d3dd30d6a0ae0753526dada3b666c4 Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Thu, 9 Nov 2023 11:09:02 +0100 Subject: [PATCH 2/3] GH-14: Enable testing by default More to be tested Bug-SiliconLabs: UIC-3082 Bug-GitHub: https://github.com/rzr/UnifySDK/issues/3 Origin: https://github.com/rzr/UnifySDK/tree/GH-14/UIC-3082/phcoval/main Forwarded: https://github.com/SiliconLabs/UnifySDK/pull/26 Signed-off-by: Philippe Coval (cherry picked from commit 92f99dc49bd98c254df9b11ce89b721933aa46c4) Signed-off-by: Philippe Coval --- helper.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.mk b/helper.mk index 6487374ba0..2c930c08c7 100755 --- a/helper.mk +++ b/helper.mk @@ -156,7 +156,7 @@ zpc/build: zpc/configure build zpc/test: ${build_dir}/applications/zpc/components/zwave_command_classes/test/ ctest --test-dir ${<} -zpc/default: zpc/configure zpc/build +zpc/default: zpc/configure zpc/build zpc/test @date -u ### @rootfs is faster than docker for env check From dd870bdf0d92934c68fb0ec71b80da33024e29e9 Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Tue, 16 Jan 2024 16:57:45 +0100 Subject: [PATCH 3/3] GH-20: zpc: meter: Adjust tests to select matching versions of CC Bug-SiliconLabs: UIC-3082 Origin: https://github.com/rzr/UnifySDK/tree/GH-20/UIC-3082/phcoval/main Relate-to: https://github.com/nkljajic/UnifySDK/pull/1 Forwarded-SiliconLabs: task/UIC-3082/phcoval/GH-20/develop Signed-off-by: Philippe Coval --- .../zwave_command_class_meter_control_test.c | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/applications/zpc/components/zwave_command_classes/test/zwave_command_class_meter_control_test.c b/applications/zpc/components/zwave_command_classes/test/zwave_command_class_meter_control_test.c index 6a9b770b86..ecc048be82 100644 --- a/applications/zpc/components/zwave_command_classes/test/zwave_command_class_meter_control_test.c +++ b/applications/zpc/components/zwave_command_classes/test/zwave_command_class_meter_control_test.c @@ -255,7 +255,7 @@ void test_meter_supported_get_v1() { // Simulate a version 1 node. attribute_store_node_t version_node = attribute_store_add_node( - ZWAVE_CC_VERSION_ATTRIBUTE(COMMAND_CLASS_METER_V5), + ZWAVE_CC_VERSION_ATTRIBUTE(COMMAND_CLASS_METER), endpoint_id_node); const zwave_cc_version_t version = 1; @@ -270,7 +270,7 @@ void test_meter_supported_get_v1() received_frame, &received_frame_size); - const uint8_t expected_frame[] = {COMMAND_CLASS_METER_V5, METER_GET, 0, 0}; + const uint8_t expected_frame[] = {COMMAND_CLASS_METER, METER_GET}; TEST_ASSERT_EQUAL(sizeof(expected_frame), received_frame_size); TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_frame, received_frame, @@ -307,6 +307,15 @@ void test_meter_supported_get_v2() void test_meter_get_low_scale() { + // Simulate a version 2 node. + attribute_store_node_t version_node = attribute_store_add_node( + ZWAVE_CC_VERSION_ATTRIBUTE(COMMAND_CLASS_METER_V2), + endpoint_id_node); + + const zwave_cc_version_t version = 2; + attribute_store_set_reported(version_node, &version, sizeof(version)); + + attribute_store_node_t meter_type_node = attribute_store_add_node(ATTRIBUTE(TYPE), endpoint_id_node); const meter_type_t type = 3; @@ -328,7 +337,7 @@ void test_meter_get_low_scale() meter_get(value_node, received_frame, &received_frame_size)); const uint8_t expected_frame[] - = {COMMAND_CLASS_METER_V5, METER_GET, (rate_type << 6) | (scale << 3), 0}; + = {COMMAND_CLASS_METER_V2, METER_GET_V2, (rate_type << 6) | (scale << 3)}; TEST_ASSERT_EQUAL(sizeof(expected_frame), received_frame_size); TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_frame, received_frame, @@ -337,6 +346,14 @@ void test_meter_get_low_scale() void test_meter_get_high_scale() { + // Simulate a version 4 node. + attribute_store_node_t version_node = attribute_store_add_node( + ZWAVE_CC_VERSION_ATTRIBUTE(COMMAND_CLASS_METER_V4), + endpoint_id_node); + + const zwave_cc_version_t version = 4; + attribute_store_set_reported(version_node, &version, sizeof(version)); + attribute_store_node_t meter_type_node = attribute_store_add_node(ATTRIBUTE(TYPE), endpoint_id_node); const meter_type_t type = 1;