Skip to content

Commit 32c88ec

Browse files
Copilotrzr
authored andcommitted
Fix beam_250ms and beam_1000ms flags always set to true
Problem: The beam_250ms and beam_1000ms fields in zwapi_tx_report_t are incorrectly parsed from the Z-Wave module response, causing both flags to always be reported as true regardless of whether beaming was actually used during transmission. Root Cause: In applications/zpc/components/zwave_api/src/zwapi_protocol_rx_dispatch.c at lines 428-429, the code uses bitwise OR (|) operator instead of bitwise AND (&) operator when extracting beam flags from the received byte. The OR operator sets the bits instead of testing them, resulting in non-zero (true) values regardless of the actual bit state in the received data. These buggy lines were introduced in ver_1.0.2_cert-123-g914bebeb30. Solution: Changed the bitwise operations to correctly test the bit flags: txStatusReport.beam_1000ms = (*p & (1 << 6)) != 0; // Test bit 6 txStatusReport.beam_250ms = (*p & (1 << 5)) != 0; // Test bit 5 Testing: Added comprehensive test cases covering all beam flag combinations to verify the flags now correctly reflect the actual beaming usage from the Z-Wave module response. Co-authored-by: 198982749+Copilot@users.noreply.github.com Origin: #150 Thanks-to: Umer Qureshi @umer-iapts Relate-to: #149 Bug-SiliconLabs: UIC-1061 Bug-SiliconLabs: UIC-1294
1 parent 5575a08 commit 32c88ec

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ void zwave_api_protocol_rx_dispatch(uint8_t *pData, uint16_t len)
425425
txStatusReport.last_route_repeaters[3] = *p++;
426426

427427
// Byte 16, beam and last route speed
428-
txStatusReport.beam_1000ms = (*p) | (1 << 6);
429-
txStatusReport.beam_250ms = (*p) | (1 << 5);
428+
txStatusReport.beam_1000ms = (*p & (1 << 6)) != 0;
429+
txStatusReport.beam_250ms = (*p & (1 << 5)) != 0;
430430
txStatusReport.last_route_speed = (*p++) & 0x7;
431431

432432
txStatusReport.routing_attempts = *p++;

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,63 @@ void test_zwapi_protocol_rx_dispatch_protocol_cc_encryption_request()
522522
TEST_ASSERT_EQUAL(1,
523523
zwapi_protocol_cc_encryption_request_test_function_call_count);
524524
}
525+
526+
void test_zwapi_protocol_rx_dispatch_beam_flags_both_false()
527+
{
528+
// Test with beam flags both false (bit 5 and 6 clear: 0x00)
529+
zwave_api_get_callbacks_IgnoreAndReturn(&test_zwapi_callbacks);
530+
zwapi_send_data_callback = &zwapi_send_data_test_callback;
531+
uint8_t frame[] = {0x1D, 0x00, 0x13, 0x00, 0x00, 0x12, 0x23, 0x05, 0xCF, 0x7D,
532+
0x7F, 0x6F, 0x7F, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
533+
0x00, 0x01, 0x00, 0x00}; // Byte 20 = 0x00 (no beam flags set)
534+
zwave_api_protocol_rx_dispatch(frame, sizeof(frame));
535+
536+
TEST_ASSERT_EQUAL(1, zwapi_send_data_test_callback_call_count);
537+
TEST_ASSERT_EQUAL(false, received_tx_report.beam_1000ms);
538+
TEST_ASSERT_EQUAL(false, received_tx_report.beam_250ms);
539+
}
540+
541+
void test_zwapi_protocol_rx_dispatch_beam_flags_250ms_only()
542+
{
543+
// Test with only beam_250ms flag set (bit 5 set: 0x20)
544+
zwave_api_get_callbacks_IgnoreAndReturn(&test_zwapi_callbacks);
545+
zwapi_send_data_callback = &zwapi_send_data_test_callback;
546+
uint8_t frame[] = {0x1D, 0x00, 0x13, 0x00, 0x00, 0x12, 0x23, 0x05, 0xCF, 0x7D,
547+
0x7F, 0x6F, 0x7F, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
548+
0x20, 0x01, 0x00, 0x00}; // Byte 20 = 0x20 (bit 5 set)
549+
zwave_api_protocol_rx_dispatch(frame, sizeof(frame));
550+
551+
TEST_ASSERT_EQUAL(1, zwapi_send_data_test_callback_call_count);
552+
TEST_ASSERT_EQUAL(false, received_tx_report.beam_1000ms);
553+
TEST_ASSERT_EQUAL(true, received_tx_report.beam_250ms);
554+
}
555+
556+
void test_zwapi_protocol_rx_dispatch_beam_flags_1000ms_only()
557+
{
558+
// Test with only beam_1000ms flag set (bit 6 set: 0x40)
559+
zwave_api_get_callbacks_IgnoreAndReturn(&test_zwapi_callbacks);
560+
zwapi_send_data_callback = &zwapi_send_data_test_callback;
561+
uint8_t frame[] = {0x1D, 0x00, 0x13, 0x00, 0x00, 0x12, 0x23, 0x05, 0xCF, 0x7D,
562+
0x7F, 0x6F, 0x7F, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
563+
0x40, 0x01, 0x00, 0x00}; // Byte 20 = 0x40 (bit 6 set)
564+
zwave_api_protocol_rx_dispatch(frame, sizeof(frame));
565+
566+
TEST_ASSERT_EQUAL(1, zwapi_send_data_test_callback_call_count);
567+
TEST_ASSERT_EQUAL(true, received_tx_report.beam_1000ms);
568+
TEST_ASSERT_EQUAL(false, received_tx_report.beam_250ms);
569+
}
570+
571+
void test_zwapi_protocol_rx_dispatch_beam_flags_both_true()
572+
{
573+
// Test with both beam flags set (bits 5 and 6 set: 0x60)
574+
zwave_api_get_callbacks_IgnoreAndReturn(&test_zwapi_callbacks);
575+
zwapi_send_data_callback = &zwapi_send_data_test_callback;
576+
uint8_t frame[] = {0x1D, 0x00, 0x13, 0x00, 0x00, 0x12, 0x23, 0x05, 0xCF, 0x7D,
577+
0x7F, 0x6F, 0x7F, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
578+
0x60, 0x01, 0x00, 0x00}; // Byte 20 = 0x60 (bits 5 and 6 set)
579+
zwave_api_protocol_rx_dispatch(frame, sizeof(frame));
580+
581+
TEST_ASSERT_EQUAL(1, zwapi_send_data_test_callback_call_count);
582+
TEST_ASSERT_EQUAL(true, received_tx_report.beam_1000ms);
583+
TEST_ASSERT_EQUAL(true, received_tx_report.beam_250ms);
584+
}

0 commit comments

Comments
 (0)