Skip to content

Commit 062518b

Browse files
authored
SWPROT-9430: Update Get Node NLS State SAPI command (#81)
* SWPROT-9430: Update Get Node NLS State SAPI command Origin: #81
1 parent c7e3e2f commit 062518b

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

applications/zpc/components/zpc_stdin/src/zpc_stdin_command_handling.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,16 +878,16 @@ static sl_status_t handle_get_nls_state(const handle_args_t &arg)
878878
zwave_node_id_t node_id
879879
= static_cast<zwave_node_id_t>(std::stoi(arg[1].c_str(), nullptr, 10));
880880
uint8_t nls_state = 0;
881-
sl_status_t status = zwapi_get_node_nls(node_id, &nls_state);
881+
uint8_t nls_support = 0;
882+
sl_status_t status = zwapi_get_node_nls(node_id, &nls_state, &nls_support);
882883
if (SL_STATUS_OK == status)
883884
{
884-
// TODO: Add commented condition below once related SAPI command is updated
885-
status = zwave_store_nls_state(node_id, nls_state, REPORTED_ATTRIBUTE) /* || zwave_store_nls_support(node_id, nls_support, REPORTED_ATTRIBUTE) */;
885+
status = zwave_store_nls_state(node_id, nls_state, REPORTED_ATTRIBUTE) || zwave_store_nls_support(node_id, nls_support, REPORTED_ATTRIBUTE);
886886
if (SL_STATUS_OK != status) {
887887
dprintf(out_stream, "Unable to store NLS state for Node ID: %d\n", node_id);
888888
return SL_STATUS_FAIL;
889889
}
890-
dprintf(out_stream, "Node ID %d, NLS state: %d\n", node_id, nls_state);
890+
dprintf(out_stream, "Node ID %d, NLS Support: %d, NLS state: %d\n", node_id, nls_support, nls_state);
891891
return SL_STATUS_OK;
892892
}
893893
else

applications/zpc/components/zpc_stdin/test/zpc_stdin_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ void test_handle_cc_versions_log()
333333
void test_handle_nls()
334334
{
335335
sl_status_t state;
336-
uint8_t nls_state = false;
336+
uint8_t nls_state = 0;
337+
uint8_t nls_support = 0;
337338

338339
state = uic_stdin_handle_command("zwave_enable_nls");
339340
TEST_ASSERT_EQUAL(SL_STATUS_FAIL, state);
@@ -345,8 +346,9 @@ void test_handle_nls()
345346
state = uic_stdin_handle_command("zwave_get_nls_state");
346347
TEST_ASSERT_EQUAL(SL_STATUS_FAIL, state);
347348

348-
zwapi_get_node_nls_ExpectAndReturn(2, &nls_state, SL_STATUS_OK);
349+
zwapi_get_node_nls_ExpectAndReturn(2, &nls_state, &nls_support, SL_STATUS_OK);
349350
zwave_store_nls_state_ExpectAndReturn(2, nls_state, REPORTED_ATTRIBUTE, SL_STATUS_OK);
351+
zwave_store_nls_support_ExpectAndReturn(2, nls_support, REPORTED_ATTRIBUTE, SL_STATUS_OK);
350352
state = uic_stdin_handle_command("zwave_get_nls_state 2");
351353
TEST_ASSERT_EQUAL(SL_STATUS_OK, state);
352354
}

applications/zpc/components/zwave/zwave_transports/s2/src/zwave_s2_network.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,21 @@ void zwave_s2_network_init()
139139
zwave_s2_log_security_keys(SL_LOG_INFO);
140140
#endif
141141

142+
uint8_t nls_support = 0;
142143
uint8_t nls_state = 0;
143144
zwave_node_id_t node_id = zwave_network_management_get_node_id();
144-
sl_status_t status = zwapi_get_node_nls(node_id, &nls_state);
145+
sl_status_t status = zwapi_get_node_nls(node_id, &nls_state, &nls_support);
145146
if (status != SL_STATUS_OK) {
146147
sl_log_error(LOG_TAG, "Unable to read NLS state for Node ID: %d\n", node_id);
147148
return;
148149
}
149150

150-
sl_log_info(LOG_TAG, "NLS state %s for Node ID: %d\n", nls_state == 1 ? "active" : "not active", node_id);
151+
sl_log_info(LOG_TAG, "NLS %s, NLS %s for Node ID: %d\n", nls_support == 0 ? "not supported" : "supported", nls_state == 0 ? "not active" : "active", node_id);
151152

152153
S2_load_nls_state(s2_ctx, nls_state);
153-
status = zwave_store_nls_state(node_id, nls_state, REPORTED_ATTRIBUTE);
154+
status = zwave_store_nls_state(node_id, nls_state, REPORTED_ATTRIBUTE) || zwave_store_nls_support(node_id, nls_support, REPORTED_ATTRIBUTE);
154155
if (status != SL_STATUS_OK) {
155-
sl_log_error(LOG_TAG, "Unable to store NLS state in attribute store for Node ID: %d\n", node_id);
156+
sl_log_error(LOG_TAG, "Unable to store NLS state/support in attribute store for Node ID: %d\n", node_id);
156157
}
157158
}
158159

applications/zpc/components/zwave/zwave_transports/s2/test/zwave_s2_network_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static void
7878
void test_s2_network_init()
7979
{
8080
uint8_t nls_state = false;
81+
uint8_t nls_support = false;
8182

8283
S2_destroy_Expect(s2_ctx);
8384
s2_inclusion_init_IgnoreAndReturn(true);
@@ -87,7 +88,7 @@ void test_s2_network_init()
8788

8889
zwapi_memory_get_buffer_IgnoreAndReturn(SL_STATUS_OK);
8990

90-
zwapi_get_node_nls_ExpectAndReturn(1, &nls_state, SL_STATUS_OK);
91+
zwapi_get_node_nls_ExpectAndReturn(1, &nls_state, &nls_support, SL_STATUS_OK);
9192
S2_load_nls_state_Ignore();
9293

9394
zwave_s2_network_init();

applications/zpc/components/zwave_api/include/zwapi_protocol_controller.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,11 @@ sl_status_t zwapi_enable_node_nls(const zwave_node_id_t nodeId);
10491049
* @brief Get the NLS State of the node in the controller NVM
10501050
*
10511051
* @param nodeId the node ID
1052+
* @param nls_state NLS state pointer to be filled
1053+
* @param nls_support NLS support pointer to be filled
10521054
*
10531055
*/
1054-
sl_status_t zwapi_get_node_nls(const zwave_node_id_t nodeId, uint8_t* nls_state);
1056+
sl_status_t zwapi_get_node_nls(const zwave_node_id_t nodeId, uint8_t* nls_state, uint8_t* nls_support);
10551057

10561058
/**
10571059
* @brief Get the NLS State of the nodes of a network in the controller NVM

applications/zpc/components/zwave_api/src/zwapi_protocol_controller.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,8 @@ sl_status_t zwapi_enable_node_nls(const zwave_node_id_t nodeId)
810810

811811
sl_status_t zwapi_get_node_nls(
812812
const zwave_node_id_t nodeId,
813-
uint8_t* nls_state)
813+
uint8_t* nls_state,
814+
uint8_t* nls_support)
814815
{
815816
uint8_t response_length = 0;
816817
uint8_t index = 0;
@@ -826,8 +827,12 @@ sl_status_t zwapi_get_node_nls(
826827

827828
if (send_command_status == SL_STATUS_OK && response_length > IDX_DATA)
828829
{
829-
*nls_state = response_buffer[IDX_DATA];
830-
return SL_STATUS_OK;
830+
*nls_support = response_buffer[IDX_DATA];
831+
*nls_state = response_buffer[IDX_DATA + 1];
832+
if (((*nls_support != 0) && (*nls_support != 1)) || ((*nls_state != 0) && (*nls_state != 1))) {
833+
return SL_STATUS_FAIL;
834+
}
835+
return SL_STATUS_OK;
831836
}
832837

833838
return SL_STATUS_FAIL;

applications/zpc/components/zwave_api/test/zwapi_protocol_controller_test.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,18 @@ void test_zwapi_enable_node_nls(void)
6565
void test_zwapi_get_node_nls(void)
6666
{
6767
zwave_node_id_t node_id = 2;
68+
uint8_t nls_supported = 1;
6869
uint8_t nls_enabled = 1;
6970
uint8_t response_buffer[] = {0x04 /* length = len(payload) + 3 */,
7071
0x01 /* type: response */,
7172
FUNC_ID_ZW_GET_NODE_NLS_STATE /* cmd */,
73+
nls_supported,
7274
nls_enabled /* payload */};
73-
uint8_t response_length = 4;
75+
uint8_t response_length = 5;
7476
uint8_t payload_buffer[] = {0x02};
7577
uint8_t payload_buffer_length = 1;
7678
uint8_t node_nls_state = 99;
79+
uint8_t node_nls_support = 99;
7780

7881
zwapi_session_send_frame_with_response_ExpectAndReturn(
7982
FUNC_ID_ZW_GET_NODE_NLS_STATE,
@@ -90,7 +93,7 @@ void test_zwapi_get_node_nls(void)
9093
zwapi_session_send_frame_with_response_ReturnThruPtr_response_len(
9194
&response_length);
9295

93-
TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_get_node_nls(node_id, &node_nls_state));
96+
TEST_ASSERT_EQUAL(SL_STATUS_OK, zwapi_get_node_nls(node_id, &node_nls_state, &node_nls_support));
9497
TEST_ASSERT_EQUAL(nls_enabled, node_nls_state);
9598
}
9699

0 commit comments

Comments
 (0)