From 1097f6f2afc945e9aad49732c0733740ba9d449d Mon Sep 17 00:00:00 2001 From: Nenad Kljajic Date: Thu, 8 Jun 2023 09:34:18 +0200 Subject: [PATCH] Fix support for COMMAND_CLASS_METER V1,V2 & V3 Signed-off-by: Nenad Kljajic <43343836+nkljajic@users.noreply.github.com> --- .../src/zwave_command_class_meter_control.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 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 36af06283e..fbd1719a60 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 < 4) { + *frame_length = sizeof(ZW_METER_GET_V2_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; + ZW_METER_GET_FRAME *get_frame = (ZW_METER_GET_FRAME *)frame; get_frame->cmdClass = COMMAND_CLASS_METER_V6; 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; }