Fixed compile warnings and BACnet priority array decoding (#712)

* Fixed network port warning for unused static function.

* Fixed BACnetPriorityArray decoding in bacapp module

* Fixed epics print of BACnetDateTime complex data.
This commit is contained in:
Steve Karg
2024-08-06 14:10:03 -05:00
committed by GitHub
parent a1d91dbeb1
commit 1be0aa39b9
3 changed files with 85 additions and 32 deletions
+77 -29
View File
@@ -500,7 +500,7 @@ int bacapp_encode_application_data(
#if defined(BACAPP_SHED_LEVEL) #if defined(BACAPP_SHED_LEVEL)
case BACNET_APPLICATION_TAG_SHED_LEVEL: case BACNET_APPLICATION_TAG_SHED_LEVEL:
/* BACnetShedLevel */ /* BACnetShedLevel */
apdu_len = bacnet_shed_level_encode(apdu, apdu_len = bacnet_shed_level_encode(apdu,
&value->type.Shed_Level); &value->type.Shed_Level);
break; break;
#endif #endif
@@ -794,7 +794,7 @@ int bacapp_decode_application_data_len(uint8_t *apdu, unsigned apdu_size)
tag_len = bacnet_tag_decode(apdu, apdu_size, &tag); tag_len = bacnet_tag_decode(apdu, apdu_size, &tag);
if (tag_len > 0) { if (tag_len > 0) {
len += tag_len; len += tag_len;
decode_len = bacnet_application_data_length(tag.number, decode_len = bacnet_application_data_length(tag.number,
tag.len_value_type); tag.len_value_type);
len += decode_len; len += decode_len;
} }
@@ -1035,9 +1035,8 @@ int bacapp_decode_generic_property(
} }
#endif #endif
#if defined(BACAPP_COMPLEX_TYPES)
/** /**
* @brief Decode BACnetPriorityValue complex data * @brief Decode BACnetPriorityValue complex data - one element only
* *
* BACnetPriorityValue ::= CHOICE { * BACnetPriorityValue ::= CHOICE {
* null NULL, * null NULL,
@@ -1067,36 +1066,63 @@ static int decode_priority_array_value(
uint8_t *apdu, uint8_t *apdu,
unsigned apdu_size, unsigned apdu_size,
BACNET_APPLICATION_DATA_VALUE *value, BACNET_APPLICATION_DATA_VALUE *value,
BACNET_OBJECT_TYPE object_type, BACNET_OBJECT_TYPE object_type)
BACNET_PROPERTY_ID property)
{ {
int apdu_len = 0; int apdu_len = 0;
int len = 0; int len = 0;
#if defined(BACAPP_COMPLEX_TYPES)
BACNET_APPLICATION_TAG tag = MAX_BACNET_APPLICATION_TAG;
if (bacnet_is_opening_tag_number(apdu, apdu_size, 0, &len)) { if (bacnet_is_opening_tag_number(apdu, apdu_size, 0, &len)) {
/* Contextual Abstract-syntax & type */ /* constructed-value [0] ABSTRACT-SYNTAX.&Type */
apdu_len += len; apdu_len += len;
len = bacapp_decode_known_property( /* adjust application tag for complex types */
&apdu[apdu_len], apdu_size - apdu_len, value, object_type, if (object_type == OBJECT_COLOR) {
property); /* Properties using BACnetxyColor */
if (len < 0) { tag = BACNET_APPLICATION_TAG_XY_COLOR;
return BACNET_STATUS_ERROR; } else if (
(object_type == OBJECT_DATETIME_PATTERN_VALUE) ||
(object_type == OBJECT_DATETIME_VALUE)) {
/* Properties using BACnetDateTime */
tag = BACNET_APPLICATION_TAG_DATETIME;
}
if (tag != MAX_BACNET_APPLICATION_TAG) {
len = bacapp_decode_application_tag_value(
&apdu[apdu_len], apdu_size - apdu_len, tag, value);
if (len < 0) {
return BACNET_STATUS_ERROR;
}
apdu_len += len;
} }
apdu_len += len;
if (!bacnet_is_closing_tag_number( if (!bacnet_is_closing_tag_number(
&apdu[apdu_len], apdu_size - apdu_len, 0, &len)) { &apdu[apdu_len], apdu_size - apdu_len, 0, &len)) {
return BACNET_STATUS_ERROR; return BACNET_STATUS_ERROR;
} }
apdu_len += len; apdu_len += len;
} else { } else if (bacnet_is_opening_tag_number(apdu, apdu_size, 1, &len)) {
apdu_len = bacapp_decode_known_property( /* datetime [1] BACnetDateTime */
&apdu[apdu_len], apdu_size - apdu_len, value, object_type, apdu_len += len;
property); /* adjust application tag for complex types */
tag = BACNET_APPLICATION_TAG_DATETIME;
len = bacapp_decode_application_tag_value(
&apdu[apdu_len], apdu_size - apdu_len, tag, value);
if (len < 0) {
return BACNET_STATUS_ERROR;
}
apdu_len += len;
if (!bacnet_is_closing_tag_number(
&apdu[apdu_len], apdu_size - apdu_len, 1, &len)) {
return BACNET_STATUS_ERROR;
}
apdu_len += len;
} else
#endif
{
apdu_len = bacapp_decode_application_data(apdu, apdu_size, value);
} }
return apdu_len; return apdu_len;
} }
#endif
/** /**
* @brief Determine a pseudo application tag for a known property * @brief Determine a pseudo application tag for a known property
@@ -1601,7 +1627,7 @@ int bacapp_decode_known_property(
tagged values, but sometimes encoded as abstract syntax or complex tagged values, but sometimes encoded as abstract syntax or complex
data values */ data values */
apdu_len = decode_priority_array_value( apdu_len = decode_priority_array_value(
apdu, apdu_size, value, object_type, PROP_PRESENT_VALUE); apdu, apdu_size, value, object_type);
} else { } else {
/* Complex or primitive value? /* Complex or primitive value?
Lookup the complex values using their object type and property */ Lookup the complex values using their object type and property */
@@ -1871,7 +1897,7 @@ int bacapp_snprintf_shed_level(
char *str, size_t str_len, BACNET_SHED_LEVEL *value) char *str, size_t str_len, BACNET_SHED_LEVEL *value)
{ {
int length = 0; int length = 0;
switch (value->type) { switch (value->type) {
case BACNET_SHED_TYPE_PERCENT: case BACNET_SHED_TYPE_PERCENT:
length = bacapp_snprintf( length = bacapp_snprintf(
@@ -2235,6 +2261,34 @@ static int bacapp_snprintf_object_id(
} }
#endif #endif
#if defined (BACAPP_DATETIME)
/**
* @brief Print a value to a string for EPICS
* @param str - destination string, or NULL for length only
* @param str_len - length of the destination string, or 0 for length only
* @param value - value to print
* @return number of characters written
*/
static int
bacapp_snprintf_datetime(char *str, size_t str_len, BACNET_DATE_TIME *value)
{
int ret_val = 0;
int slen = 0;
slen = bacapp_snprintf(str, str_len, "{");
ret_val += bacapp_snprintf_shift(slen, &str, &str_len);
slen = bacapp_snprintf_date(str, str_len, &value->date);
ret_val += bacapp_snprintf_shift(slen, &str, &str_len);
slen = bacapp_snprintf(str, str_len, "-");
ret_val += bacapp_snprintf_shift(slen, &str, &str_len);
slen = bacapp_snprintf_time(str, str_len, &value->time);
ret_val += bacapp_snprintf_shift(slen, &str, &str_len);
ret_val += bacapp_snprintf(str, str_len, "}");
return ret_val;
}
#endif
#if defined(BACAPP_DATERANGE) || defined(BACAPP_CALENDAR_ENTRY) #if defined(BACAPP_DATERANGE) || defined(BACAPP_CALENDAR_ENTRY)
/** /**
* @brief Print a value to a string for EPICS * @brief Print a value to a string for EPICS
@@ -3082,14 +3136,8 @@ int bacapp_snprintf_value(
#endif #endif
#if defined(BACAPP_DATETIME) #if defined(BACAPP_DATETIME)
case BACNET_APPLICATION_TAG_DATETIME: case BACNET_APPLICATION_TAG_DATETIME:
slen = bacapp_snprintf_date( ret_val = bacapp_snprintf_datetime(
str, str_len, &value->type.Date_Time.date); str, str_len, &value->type.Date_Time);
ret_val += bacapp_snprintf_shift(slen, &str, &str_len);
slen = bacapp_snprintf(str, str_len, "-");
ret_val += bacapp_snprintf_shift(slen, &str, &str_len);
slen = bacapp_snprintf_time(
str, str_len, &value->type.Date_Time.time);
ret_val += slen;
break; break;
#endif #endif
#if defined(BACAPP_DATERANGE) #if defined(BACAPP_DATERANGE)
@@ -3524,7 +3572,7 @@ bool bacnet_scale_from_ascii(BACNET_SCALE *value, const char *argv)
status = true; status = true;
} }
} }
} }
if (!status) { if (!status) {
count = sscanf(argv, "%u", &integer_scale); count = sscanf(argv, "%u", &integer_scale);
if (count == 1) { if (count == 1) {
-2
View File
@@ -1176,8 +1176,6 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
unsigned int object_index = 0; unsigned int object_index = 0;
int len = 0; int len = 0;
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value;
/* build here in case of error in time half of datetime */
BACNET_DATE start_date;
debug_printf("Load_Control_Write_Property(wp_data=%p)\n", wp_data); debug_printf("Load_Control_Write_Property(wp_data=%p)\n", wp_data);
if (wp_data == NULL) { if (wp_data == NULL) {
+8 -1
View File
@@ -2904,7 +2904,9 @@ static bool Network_Port_FD_BBMD_Address_Write(
return status; return status;
} }
#endif
#if (BBMD_CLIENT_ENABLED)
/** /**
* @brief Write the FD Subscription Lifetime * @brief Write the FD Subscription Lifetime
* @param object_instance [in] BACnet network port object instance number * @param object_instance [in] BACnet network port object instance number
@@ -3525,9 +3527,11 @@ bool Network_Port_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
#else #else
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
#endif
#endif #endif
break; break;
case PROP_FD_SUBSCRIPTION_LIFETIME: case PROP_FD_SUBSCRIPTION_LIFETIME:
#if (BBMD_CLIENT_ENABLED)
if (write_property_type_valid( if (write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_UNSIGNED_INT)) { wp_data, &value, BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
status = Network_Port_FD_Subscription_Lifetime_Write( status = Network_Port_FD_Subscription_Lifetime_Write(
@@ -3537,8 +3541,11 @@ bool Network_Port_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
} }
break; #else
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
#endif #endif
break;
default: default:
if (Property_List_Member( if (Property_List_Member(
wp_data->object_instance, wp_data->object_property)) { wp_data->object_instance, wp_data->object_property)) {