added secure BACnet primitive datatype encode functions. (#643)
* added secure BACnet primitive datatype encode functions.
This commit is contained in:
+389
-16
@@ -477,6 +477,51 @@ int bacnet_tag_number_decode(
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode a BACnet BACnet Tag Number and Value
|
||||
* as defined in clause 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param tag - tag value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_tag_encode(uint8_t *apdu, uint32_t apdu_size, BACNET_TAG *tag)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (!tag) {
|
||||
return 0;
|
||||
}
|
||||
if (tag->application) {
|
||||
apdu_len = encode_tag(NULL, tag->number, false, tag->len_value_type);
|
||||
} else if (tag->context) {
|
||||
apdu_len = encode_tag(NULL, tag->number, true, tag->len_value_type);
|
||||
} else if (tag->opening) {
|
||||
apdu_len = encode_opening_tag(NULL, tag->number);
|
||||
} else if (tag->closing) {
|
||||
apdu_len = encode_closing_tag(NULL, tag->number);
|
||||
}
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
if (tag->application) {
|
||||
apdu_len =
|
||||
encode_tag(apdu, tag->number, false, tag->len_value_type);
|
||||
} else if (tag->context) {
|
||||
apdu_len = encode_tag(apdu, tag->number, true, tag->len_value_type);
|
||||
} else if (tag->opening) {
|
||||
apdu_len = encode_opening_tag(apdu, tag->number);
|
||||
} else if (tag->closing) {
|
||||
apdu_len = encode_closing_tag(apdu, tag->number);
|
||||
}
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decode the BACnet Tag Number and Value
|
||||
* as defined in clause 20.2.1 General Rules For Encoding BACnet Tags
|
||||
@@ -1052,6 +1097,33 @@ bool decode_boolean(uint32_t len_value)
|
||||
return boolean_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged boolean value.
|
||||
* From clause 20.2.3 Encoding of a Boolean Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags.
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode.
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_boolean_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, bool value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_boolean(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_boolean(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decode the Boolean Value when application encoded
|
||||
* From clause 20.2.3 Encoding of a Boolean Value
|
||||
@@ -1257,7 +1329,7 @@ int decode_bitstring(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param len_value - number of bytes in the unsigned value encoding
|
||||
* @param value - the unsigned value decoded
|
||||
* @param value - value to decode into
|
||||
*
|
||||
* @return number of bytes decoded, or zero if errors occur
|
||||
*/
|
||||
@@ -1296,6 +1368,33 @@ int bacnet_bitstring_decode(uint8_t *apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet bit string value.
|
||||
* From clause 20.2.10 Encoding of a Bit String Value.
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode.
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_bitstring_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_BIT_STRING *value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_bitstring(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_bitstring(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes from bytes into a BACnet bit string value.
|
||||
* From clause 20.2.10 Encoding of a Bit String Value.
|
||||
@@ -1342,7 +1441,7 @@ int bacnet_bitstring_application_decode(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the character string value decoded
|
||||
* @param value - decoded value, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, or zero if tag number mismatch, or
|
||||
* #BACNET_STATUS_ERROR (-1) if malformed
|
||||
@@ -1567,7 +1666,7 @@ int decode_object_id(
|
||||
* @param apdu - buffer of data to be decoded
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param object_type - decoded object type, if decoded
|
||||
* @param object_instance - decoded object instance, if decoded
|
||||
* @param instance - decoded object instance, if decoded
|
||||
*
|
||||
* @return the number of apdu bytes consumed, or 0 if apdu is too small
|
||||
*/
|
||||
@@ -1588,6 +1687,37 @@ int bacnet_object_id_decode(uint8_t *apdu,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet object identifier value.
|
||||
* From clause 20.2.14 Encoding of an Object Identifier Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_object_id_application_encode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_size,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_object_id(NULL, object_type, object_instance);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len =
|
||||
encode_application_object_id(apdu, object_type, object_instance);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decode the BACnet Object Identifier Value when application encoded
|
||||
* as defined in clause 20.2.14 Encoding of an Object Identifier Value
|
||||
@@ -1878,7 +2008,7 @@ int encode_context_octet_string(
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param len_value - number of bytes in the unsigned value encoding, may be
|
||||
* zero
|
||||
* @param value - the unsigned value decoded, or NULL for length
|
||||
* @param value - the value decoded, or NULL for length
|
||||
*
|
||||
* @return number of bytes decoded (0..N), or BACNET_STATUS_ERROR on error
|
||||
*/
|
||||
@@ -1960,6 +2090,33 @@ int decode_context_octet_string(
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Octet String Value
|
||||
* From clause 20.2.8 Encoding of an Octet String Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_octet_string_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_OCTET_STRING *value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_octet_string(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_octet_string(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes from bytes into a BACnet Octet String application encoding
|
||||
* from clause 20.2.8 Encoding of an Octet String Value
|
||||
@@ -2006,7 +2163,7 @@ int bacnet_octet_string_application_decode(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the octet string value decoded, or NULL for length
|
||||
* @param value - the value decoded, or NULL for length
|
||||
*
|
||||
* @return number of bytes decoded, or zero if tag number mismatch, or
|
||||
* #BACNET_STATUS_ERROR (-1) if malformed
|
||||
@@ -2171,7 +2328,7 @@ int encode_context_character_string(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param len_value - number of bytes in the unsigned value encoding
|
||||
* @param value - the unsigned value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, or zero if errors occur
|
||||
*/
|
||||
@@ -2220,6 +2377,33 @@ int decode_character_string(
|
||||
return bacnet_character_string_decode(apdu, apdu_size, len_value, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Character String value
|
||||
* From clause 20.2.9 Encoding of a Character String Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_character_string_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_CHARACTER_STRING *value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_character_string(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_character_string(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes from bytes into a BACnet Character String value
|
||||
* from clause 20.2.9 Encoding of a Character String Value
|
||||
@@ -2266,7 +2450,7 @@ int bacnet_character_string_application_decode(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the character string value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, or zero if tag number mismatch, or
|
||||
* #BACNET_STATUS_ERROR (-1) if malformed
|
||||
@@ -2335,7 +2519,7 @@ int decode_context_character_string(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param len_value - number of bytes in the unsigned value encoding
|
||||
* @param value - the unsigned value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, or zero if errors occur
|
||||
*/
|
||||
@@ -2429,7 +2613,7 @@ int bacnet_unsigned_decode(uint8_t *apdu,
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the unsigned value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, zero if wrong tag number,
|
||||
* or #BACNET_STATUS_ERROR (-1) if malformed
|
||||
@@ -2463,6 +2647,33 @@ int bacnet_unsigned_context_decode(uint8_t *apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Unsigned value
|
||||
* From clause 20.2.4 Encoding of an Unsigned Integer Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_unsigned_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_UNSIGNED_INTEGER value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_unsigned(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_unsigned(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes from bytes into a BACnet Unsigned value
|
||||
* from clause 20.2.4 Encoding of an Unsigned Integer Value
|
||||
@@ -2696,6 +2907,33 @@ int decode_enumerated(uint8_t *apdu, uint32_t len_value, uint32_t *value)
|
||||
return bacnet_enumerated_decode(apdu, apdu_size, len_value, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Enumerated value
|
||||
* From clause 20.2.11 Encoding of an Enumerated Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - bit string value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_enumerated_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, uint32_t value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_enumerated(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_enumerated(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes from bytes into a BACnet Enumerated value
|
||||
* from clause 20.2.11 Encoding of an Enumerated Value
|
||||
@@ -2957,6 +3195,33 @@ int bacnet_signed_context_decode(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Signed Integer Value
|
||||
* From clause 20.2.5 Encoding of a Signed Integer Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_signed_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, int32_t value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_signed(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_signed(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decode the BACnet Signed Integer Value when application encoded
|
||||
* as defined in clause 20.2.5 Encoding of a Signed Integer Value
|
||||
@@ -3183,7 +3448,7 @@ int encode_context_real(uint8_t *apdu, uint8_t tag_number, float value)
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param len_value - number of bytes in the unsigned value encoding
|
||||
* @param value - the signed value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, or zero if errors occur
|
||||
*/
|
||||
@@ -3207,7 +3472,7 @@ int bacnet_real_decode(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the signed value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, zero if wrong tag number,
|
||||
* or error (-1) if malformed
|
||||
@@ -3238,6 +3503,33 @@ int bacnet_real_context_decode(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Real Number Value
|
||||
* From clause 20.2.6 Encoding of a Real Number Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_real_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, float value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_real(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_real(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decode an application tagged single precision floating value
|
||||
* From clause 20.2.6 Encoding of a Real Number Value
|
||||
@@ -3364,7 +3656,7 @@ int encode_context_double(uint8_t *apdu, uint8_t tag_number, double value)
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param len_value - number of bytes in the unsigned value encoding
|
||||
* @param value - the signed value decoded
|
||||
* @param value - the value decoded
|
||||
*
|
||||
* @return number of bytes decoded, or zero if errors occur
|
||||
*/
|
||||
@@ -3388,7 +3680,7 @@ int bacnet_double_decode(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the signed value decoded
|
||||
* @param value - the value decoded
|
||||
*
|
||||
* @return number of bytes decoded, zero if wrong tag number,
|
||||
* or error (-1) if malformed
|
||||
@@ -3419,6 +3711,33 @@ int bacnet_double_context_decode(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged Double Precision Real Number Value
|
||||
* From clause 20.2.7 Encoding of a Double Precision Real Number Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_double_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, double value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_double(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_double(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decode an application tagged double precision floating value.
|
||||
* From clause 20.2.7 Encoding of a Double Precision Real Number Value
|
||||
@@ -3567,7 +3886,7 @@ int encode_context_time(uint8_t *apdu, uint8_t tag_number, BACNET_TIME *btime)
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param len_value - number of bytes encoded
|
||||
* @param value - the unsigned value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, or zero if errors occur
|
||||
*/
|
||||
@@ -3598,7 +3917,7 @@ int bacnet_time_decode(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the unsigned value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, zero if wrong tag number,
|
||||
* or error (-1) if malformed
|
||||
@@ -3629,6 +3948,33 @@ int bacnet_time_context_decode(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Time Value
|
||||
* From clause 20.2.13 Encoding of a Time Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_time_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_TIME *value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_time(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_time(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes from bytes into a BACnet Time Value application encoded
|
||||
* from clause 20.2.13 Encoding of a Time Value
|
||||
@@ -3942,7 +4288,7 @@ int bacnet_date_decode(
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_size - number of bytes in the buffer to decode
|
||||
* @param tag_value - context tag number expected
|
||||
* @param value - the unsigned value decoded
|
||||
* @param value - the value decoded, if decoded
|
||||
*
|
||||
* @return number of bytes decoded, zero if wrong tag number,
|
||||
* or error (-1) if malformed
|
||||
@@ -3973,6 +4319,33 @@ int bacnet_date_context_decode(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode an application tagged BACnet Date Value
|
||||
* From clause 20.2.12 Encoding of a Date Value
|
||||
* and 20.2.1 General Rules for Encoding BACnet Tags
|
||||
*
|
||||
* @param apdu - buffer to hold the data to be encoded, or NULL for length
|
||||
* @param apdu_size - number of bytes in the buffer
|
||||
* @param value - value to encode
|
||||
*
|
||||
* @return returns the number of apdu bytes consumed,
|
||||
* or 0 if apdu_size is too small to fit the data
|
||||
*/
|
||||
int bacnet_date_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_DATE *value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
apdu_len = encode_application_date(NULL, value);
|
||||
if (apdu_len > apdu_size) {
|
||||
apdu_len = 0;
|
||||
} else {
|
||||
apdu_len = encode_application_date(apdu, value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes from bytes into a BACnet Date Value application encoded
|
||||
* From clause 20.2.12 Encoding of a Date Value
|
||||
|
||||
+68
-10
@@ -73,6 +73,9 @@ BACNET_STACK_EXPORT
|
||||
int encode_opening_tag(uint8_t *apdu, uint8_t tag_number);
|
||||
BACNET_STACK_EXPORT
|
||||
int encode_closing_tag(uint8_t *apdu, uint8_t tag_number);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_tag_encode(uint8_t *apdu, uint32_t apdu_size, BACNET_TAG *tag);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_tag_decode(uint8_t *apdu, uint32_t apdu_size, BACNET_TAG *tag);
|
||||
|
||||
@@ -152,9 +155,13 @@ BACNET_STACK_EXPORT
|
||||
BACNET_STACK_DEPRECATED("Use bacnet_boolean_context_decode() instead")
|
||||
int decode_context_boolean2(
|
||||
uint8_t *apdu, uint8_t tag_number, bool *boolean_value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_boolean_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, bool value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_boolean_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, bool *boolean_value);
|
||||
uint8_t *apdu, uint32_t apdu_len_max, bool *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_boolean_context_decode(uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
@@ -181,11 +188,16 @@ int bacnet_bitstring_decode(uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint32_t len_value,
|
||||
BACNET_BIT_STRING *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_bitstring_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_BIT_STRING *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_bitstring_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, BACNET_BIT_STRING *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_bitstring_context_decode(uint8_t *apdu,
|
||||
int bacnet_bitstring_context_decode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint8_t tag_value,
|
||||
BACNET_BIT_STRING *value);
|
||||
@@ -204,6 +216,9 @@ BACNET_STACK_EXPORT
|
||||
int bacnet_real_context_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, uint8_t tag_value, float *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_real_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, float value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_real_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, float *value);
|
||||
|
||||
@@ -222,6 +237,9 @@ BACNET_STACK_EXPORT
|
||||
int bacnet_double_context_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, uint8_t tag_value, double *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_double_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, double value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_double_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, double *value);
|
||||
|
||||
@@ -257,13 +275,22 @@ int bacnet_object_id_decode(uint8_t *apdu,
|
||||
uint32_t len_value,
|
||||
BACNET_OBJECT_TYPE *object_type,
|
||||
uint32_t *instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_object_id_application_decode(uint8_t *apdu,
|
||||
int bacnet_object_id_application_encode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_size,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_object_id_application_decode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
BACNET_OBJECT_TYPE *object_type,
|
||||
uint32_t *object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_object_id_context_decode(uint8_t *apdu,
|
||||
int bacnet_object_id_context_decode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint8_t tag_value,
|
||||
BACNET_OBJECT_TYPE *object_type,
|
||||
@@ -290,11 +317,16 @@ int bacnet_octet_string_decode(uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint32_t len_value,
|
||||
BACNET_OCTET_STRING *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_octet_string_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_OCTET_STRING *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_octet_string_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, BACNET_OCTET_STRING *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_octet_string_context_decode(uint8_t *apdu,
|
||||
int bacnet_octet_string_context_decode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint8_t tag_value,
|
||||
BACNET_OCTET_STRING *value);
|
||||
@@ -327,11 +359,16 @@ int bacnet_character_string_decode(uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint32_t len_value,
|
||||
BACNET_CHARACTER_STRING *char_string);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_character_string_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_CHARACTER_STRING *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_character_string_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, BACNET_CHARACTER_STRING *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_character_string_context_decode(uint8_t *apdu,
|
||||
int bacnet_character_string_context_decode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint8_t tag_value,
|
||||
BACNET_CHARACTER_STRING *value);
|
||||
@@ -356,11 +393,16 @@ int bacnet_unsigned_decode(uint8_t *apdu,
|
||||
uint32_t apdu_max_len,
|
||||
uint32_t len_value,
|
||||
BACNET_UNSIGNED_INTEGER *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_unsigned_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_UNSIGNED_INTEGER value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_unsigned_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, BACNET_UNSIGNED_INTEGER *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_unsigned_context_decode(uint8_t *apdu,
|
||||
int bacnet_unsigned_context_decode(
|
||||
uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint8_t tag_number,
|
||||
BACNET_UNSIGNED_INTEGER *value);
|
||||
@@ -377,15 +419,19 @@ int decode_signed(uint8_t *apdu, uint32_t len_value, int32_t *value);
|
||||
BACNET_STACK_DEPRECATED("Use bacnet_signed_context_decode() instead")
|
||||
BACNET_STACK_EXPORT
|
||||
int decode_context_signed(uint8_t *apdu, uint8_t tag_number, int32_t *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_signed_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, uint32_t len_value, int32_t *value);
|
||||
uint8_t *apdu, uint32_t apdu_size, uint32_t len_value, int32_t *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_signed_context_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, uint8_t tag_value, int32_t *value);
|
||||
uint8_t *apdu, uint32_t apdu_size, uint8_t tag_value, int32_t *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_signed_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, int32_t value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_signed_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, int32_t *value);
|
||||
uint8_t *apdu, uint32_t apdu_size, int32_t *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int encode_bacnet_enumerated(uint8_t *apdu, uint32_t value);
|
||||
@@ -404,6 +450,11 @@ int decode_context_enumerated(
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_enumerated_decode(
|
||||
uint8_t *apdu, uint32_t apdu_max_len, uint32_t len_value, uint32_t *value);
|
||||
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_enumerated_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, uint32_t value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_enumerated_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, uint32_t *value);
|
||||
@@ -442,6 +493,9 @@ int bacnet_time_context_decode(uint8_t *apdu,
|
||||
uint8_t tag_value,
|
||||
BACNET_TIME *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_time_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_TIME *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_time_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, BACNET_TIME *value);
|
||||
|
||||
@@ -468,6 +522,10 @@ int bacnet_date_decode(uint8_t *apdu,
|
||||
uint32_t apdu_len_max,
|
||||
uint32_t len_value,
|
||||
BACNET_DATE *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_date_application_encode(
|
||||
uint8_t *apdu, uint32_t apdu_size, BACNET_DATE *value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_date_application_decode(
|
||||
uint8_t *apdu, uint32_t apdu_len_max, BACNET_DATE *value);
|
||||
|
||||
@@ -82,7 +82,7 @@ extern bool Routed_Device_Write_Property_Local(
|
||||
/* may be overridden by outside table */
|
||||
static object_functions_t *Object_Table;
|
||||
|
||||
/* clang format off */
|
||||
/* clang-format off */
|
||||
static object_functions_t My_Object_Table[] = {
|
||||
{ OBJECT_DEVICE, NULL /* Init - don't init Device or it will recourse! */,
|
||||
Device_Count, Device_Index_To_Instance,
|
||||
@@ -381,7 +381,7 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
|
||||
};
|
||||
/* clang format on */
|
||||
/* clang-format on */
|
||||
|
||||
/** Glue function to let the Device object, when called by a handler,
|
||||
* lookup which Object type needs to be invoked.
|
||||
@@ -476,7 +476,7 @@ void Device_Objects_Property_List(BACNET_OBJECT_TYPE object_type,
|
||||
return;
|
||||
}
|
||||
|
||||
/* clang format off */
|
||||
/* clang-format off */
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Device_Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
|
||||
@@ -506,7 +506,7 @@ static const int Device_Properties_Optional[] = {
|
||||
static const int Device_Properties_Proprietary[] = {
|
||||
-1
|
||||
};
|
||||
/* clang format on */
|
||||
/* clang-format on */
|
||||
|
||||
void Device_Property_Lists(
|
||||
const int **pRequired, const int **pOptional, const int **pProprietary)
|
||||
|
||||
@@ -1601,7 +1601,7 @@ unsigned property_list_special_count(
|
||||
/* standard properties that are arrays
|
||||
but not necessary supported in every object */
|
||||
|
||||
/* clang format off */
|
||||
/* clang-format off */
|
||||
static const int Properties_BACnetARRAY[] = {
|
||||
PROP_AUTHENTICATION_FACTORS, PROP_ASSIGNED_ACCESS_RIGHTS,
|
||||
PROP_PRIORITY_ARRAY, PROP_VALUE_SOURCE_ARRAY, PROP_COMMAND_TIME_ARRAY,
|
||||
@@ -1622,7 +1622,7 @@ static const int Properties_BACnetARRAY[] = {
|
||||
PROP_STAGES, PROP_STAGE_NAMES, PROP_TARGET_REFERENCES,
|
||||
PROP_MONITORED_OBJECTS, PROP_TAGS, -1
|
||||
};
|
||||
/* clang format on */
|
||||
/* clang-format on */
|
||||
|
||||
/**
|
||||
* Function that returns the list of Required properties
|
||||
|
||||
Reference in New Issue
Block a user