Feature/zeroing rx buffer remain (#90)

* Added zeroing rx buffer remain

* Added zeroing rx buffer remain

* Added safety margin for the rx-buffer in the different ports.

* Added safety margin for the receive buffer.

* Added DoxyGen comments.

* Fixed checking return value when calculating distance between opening and closing tag on multiple properties.
This commit is contained in:
Roy Schneider
2020-05-24 16:19:52 +02:00
committed by GitHub
parent 3818f3d844
commit 764e0e8448
16 changed files with 238 additions and 40 deletions
+12 -4
View File
@@ -926,10 +926,18 @@ bool bacapp_copy(BACNET_APPLICATION_DATA_VALUE *dest_value,
return status;
}
/* returns the length of data between an opening tag and a closing tag.
Expects that the first octet contain the opening tag.
Include a value property identifier for context specific data
such as the value received in a WriteProperty request */
/**
* @brief Returns the length of data between an opening tag and a closing tag.
* Expects that the first octet contain the opening tag.
* Include a value property identifier for context specific data
* such as the value received in a WriteProperty request.
*
* @param Pointer to the APDU buffer
* @param apdu_len_max Bytes valid in the buffer
* @param property ID of the propery to get the length for.
*
* @return Length in bytes or BACNET_STATUS_ERROR.
*/
int bacapp_data_len(
uint8_t *apdu, unsigned apdu_len_max, BACNET_PROPERTY_ID property)
{
+61 -1
View File
@@ -37,6 +37,11 @@
/** @file timestamp.c Encode/Decode BACnet Timestamps */
/** Set the sequence number in a timestamp structure.
*
* @param dest Pointer to the destination time stamp structure.
* @param sequenceNum Sequence number to be set into the time stamp.
*/
void bacapp_timestamp_sequence_set(BACNET_TIMESTAMP *dest, uint16_t sequenceNum)
{
if (dest) {
@@ -45,6 +50,12 @@ void bacapp_timestamp_sequence_set(BACNET_TIMESTAMP *dest, uint16_t sequenceNum)
}
}
/** Set a timestamp structure with the value given
* from a time structure.
*
* @param dest Pointer to the destination time stamp structure.
* @param btime Pointer to the BACNet time structure.
*/
void bacapp_timestamp_time_set(BACNET_TIMESTAMP *dest, BACNET_TIME *btime)
{
if (dest && btime) {
@@ -53,6 +64,12 @@ void bacapp_timestamp_time_set(BACNET_TIMESTAMP *dest, BACNET_TIME *btime)
}
}
/** Set a timestamp structure with the value given
* from a date/time structure.
*
* @param dest Pointer to the destination time stamp structure.
* @param bdateTime Pointer to the BACNet date/time structure.
*/
void bacapp_timestamp_datetime_set(
BACNET_TIMESTAMP *dest, BACNET_DATE_TIME *bdateTime)
{
@@ -62,6 +79,11 @@ void bacapp_timestamp_datetime_set(
}
}
/** Copy a timestamp depending of the tag it holds.
*
* @param dest Pointer to the destination time stamp structure.
* @param src Pointer to the source time stamp structure.
*/
void bacapp_timestamp_copy(BACNET_TIMESTAMP *dest, BACNET_TIMESTAMP *src)
{
if (dest && src) {
@@ -82,6 +104,14 @@ void bacapp_timestamp_copy(BACNET_TIMESTAMP *dest, BACNET_TIMESTAMP *src)
}
}
/** Encode a time stamp.
*
* @param apdu Pointer to the APDU buffer.
* @param value Pointer to the variable that holds
* the time stamp values to be encoded.
*
* @return Bytes encoded or 0 on error.
*/
int bacapp_encode_timestamp(uint8_t *apdu, BACNET_TIMESTAMP *value)
{
int len = 0; /* length of each encoding */
@@ -112,6 +142,17 @@ int bacapp_encode_timestamp(uint8_t *apdu, BACNET_TIMESTAMP *value)
return len;
}
/** Encode a time stamp for the given tag
* number, using an opening and closing tag.
*
* @param apdu Pointer to the APDU buffer.
* @param tag_number The tag number that shall
* hold the time stamp.
* @param value Pointer to the variable that holds
* the time stamp values to be encoded.
*
* @return Bytes encoded or 0 on error.
*/
int bacapp_encode_context_timestamp(
uint8_t *apdu, uint8_t tag_number, BACNET_TIMESTAMP *value)
{
@@ -129,6 +170,14 @@ int bacapp_encode_context_timestamp(
return apdu_len;
}
/** Decode a time stamp from the given buffer.
*
* @param apdu Pointer to the APDU buffer.
* @param value Pointer to the variable that shall
* take the time stamp values.
*
* @return Bytes decoded or -1 on error.
*/
int bacapp_decode_timestamp(uint8_t *apdu, BACNET_TIMESTAMP *value)
{
int len = 0;
@@ -136,7 +185,7 @@ int bacapp_decode_timestamp(uint8_t *apdu, BACNET_TIMESTAMP *value)
uint32_t len_value_type;
BACNET_UNSIGNED_INTEGER unsigned_value;
if (apdu) {
if (apdu && value) {
section_len = decode_tag_number_and_value(
&apdu[len], &value->tag, &len_value_type);
@@ -184,6 +233,17 @@ int bacapp_decode_timestamp(uint8_t *apdu, BACNET_TIMESTAMP *value)
return len;
}
/** Decode a time stamp and check for
* opening and closing tags.
*
* @param apdu Pointer to the APDU buffer.
* @param tag_number The tag number that shall
* hold the time stamp.
* @param value Pointer to the variable that shall
* take the time stamp values.
*
* @return Bytes decoded or -1 on error.
*/
int bacapp_decode_context_timestamp(
uint8_t *apdu, uint8_t tag_number, BACNET_TIMESTAMP *value)
{
+19 -14
View File
@@ -151,20 +151,25 @@ int wpm_decode_object_property(
(unsigned)(apdu_len - len), wp_data->object_property);
len++;
/* copy application data, check max lengh */
if (imax > (apdu_len - len)) {
imax = (apdu_len - len);
}
for (i = 0; i < imax; i++) {
wp_data->application_data[i] = apdu[len + i];
}
wp_data->application_data_len = imax;
len += imax;
if (len < apdu_len) {
len += decode_tag_number_and_value(
&apdu[len], &tag_number, &len_value);
/* closing tag 2 */
if ((tag_number != 2) && (decode_is_closing_tag(&apdu[len - 1]))) {
if (imax != BACNET_STATUS_ERROR) {
/* copy application data, check max lengh */
if (imax > (apdu_len - len)) {
imax = (apdu_len - len);
}
for (i = 0; i < imax; i++) {
wp_data->application_data[i] = apdu[len + i];
}
wp_data->application_data_len = imax;
len += imax;
if (len < apdu_len) {
len += decode_tag_number_and_value(
&apdu[len], &tag_number, &len_value);
/* closing tag 2 */
if ((tag_number != 2) && (decode_is_closing_tag(&apdu[len - 1]))) {
wp_data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
return BACNET_STATUS_REJECT;
}
} else {
wp_data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
return BACNET_STATUS_REJECT;
}