Fix wrong calculation of frames in bacapp_data_len (#491)
* Fixed wrong calculation of data length. In cases when 2 sets of opening & closing tags (first opening tag context tag is 3, second is 0) were sent, one of the frames wasn't added, and the resulted sum was wrong * Added unit test for case with two sets of opening & closing tags
This commit is contained in:
@@ -1546,6 +1546,8 @@ int bacapp_data_len(
|
|||||||
} else if (tag_number == opening_tag_number) {
|
} else if (tag_number == opening_tag_number) {
|
||||||
total_len_enable = true;
|
total_len_enable = true;
|
||||||
opening_tag_number_counter++;
|
opening_tag_number_counter++;
|
||||||
|
} else {
|
||||||
|
total_len_enable = true;
|
||||||
}
|
}
|
||||||
} else if (bacnet_is_closing_tag(apdu, apdu_len_max)) {
|
} else if (bacnet_is_closing_tag(apdu, apdu_len_max)) {
|
||||||
len = bacnet_tag_number_and_value_decode(
|
len = bacnet_tag_number_and_value_decode(
|
||||||
|
|||||||
@@ -811,6 +811,23 @@ static void testBACnetApplicationDataLength(void)
|
|||||||
/* verify the length of the data inside the opening/closing tags */
|
/* verify the length of the data inside the opening/closing tags */
|
||||||
len = bacapp_data_len(&apdu[0], apdu_len, PROP_REQUESTED_SHED_LEVEL);
|
len = bacapp_data_len(&apdu[0], apdu_len, PROP_REQUESTED_SHED_LEVEL);
|
||||||
zassert_equal(test_len, len, NULL);
|
zassert_equal(test_len, len, NULL);
|
||||||
|
|
||||||
|
/* 7. context opening & closing tag */
|
||||||
|
test_len = 0;
|
||||||
|
apdu_len = 0;
|
||||||
|
len = encode_opening_tag(&apdu[apdu_len], 3);
|
||||||
|
apdu_len += len;
|
||||||
|
len = encode_opening_tag(&apdu[apdu_len], 0);
|
||||||
|
apdu_len += len;
|
||||||
|
test_len += len;
|
||||||
|
len = encode_closing_tag(&apdu[apdu_len], 0);
|
||||||
|
apdu_len += len;
|
||||||
|
test_len += len;
|
||||||
|
len = encode_closing_tag(&apdu[apdu_len], 3);
|
||||||
|
apdu_len += len;
|
||||||
|
/* verify the length of the data inside the opening/closing tags */
|
||||||
|
len = bacapp_data_len(&apdu[0], apdu_len, PROP_WEEKLY_SCHEDULE);
|
||||||
|
zassert_equal(test_len, len, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user