Bugfix/read range trend log buffer (#947)

* Fixed ReadRange app to read and pretty-print a Trend Log log-buffer
This commit is contained in:
Steve Karg
2025-03-25 10:32:11 -05:00
committed by GitHub
parent 0c45b50574
commit 6f7f3649a5
88 changed files with 1637 additions and 69 deletions
+42 -21
View File
@@ -18,6 +18,7 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/debug.h"
/** @file h_rr_a.c Handles Read Range Acknowledgments. */
@@ -32,24 +33,49 @@ static void PrintReadRangeData(BACNET_READ_RANGE_DATA *data)
uint8_t *application_data;
int application_data_len;
bool first_value = true;
#if PRINT_ENABLED
bool print_brace = false;
#endif
if (data) {
debug_printf_stdout(
"%s #%lu\r\n", bactext_object_type_name(data->object_type),
(unsigned long)data->object_instance);
debug_printf_stdout("{\r\n");
if ((data->object_property < 512) ||
(data->object_property > 4194303)) {
/* Enumerated values 0-511 and 4194304+ are reserved
for definition by ASHRAE.*/
debug_printf_stdout(
" %s", bactext_property_name(data->object_property));
} else {
/* Enumerated values 512-4194303 may be used
by others subject to the procedures and
constraints described in Clause 23. */
debug_printf_stdout(
" proprietary %u", (unsigned)data->object_property);
}
if (data->array_index == BACNET_ARRAY_ALL) {
debug_printf_stdout(": ");
} else {
debug_printf_stdout("[%lu]: ", (unsigned long)data->array_index);
}
application_data = data->application_data;
application_data_len = data->application_data_len;
/* FIXME: what if application_data_len is bigger than 255? */
/* value? need to loop until all of the len is gone... */
/* loop until all of the len is gone... */
for (;;) {
len = bacapp_decode_application_data(
application_data, (uint8_t)application_data_len, &value);
len = bacapp_decode_known_array_property(
application_data, (uint8_t)application_data_len, &value,
data->object_type, data->object_property, data->array_index);
if (len < 0) {
/* error decoding */
break;
}
if (!first_value) {
debug_printf_stdout(" ");
}
if (first_value && (len < application_data_len)) {
first_value = false;
#if PRINT_ENABLED
fprintf(stdout, "{");
debug_printf_stdout("{");
print_brace = true;
#endif
}
#ifdef BACAPP_PRINT_ENABLED
object_value.object_type = data->object_type;
@@ -64,9 +90,7 @@ static void PrintReadRangeData(BACNET_READ_RANGE_DATA *data)
application_data += len;
application_data_len -= len;
/* there's more! */
#if PRINT_ENABLED
fprintf(stdout, ",");
#endif
debug_printf_stdout(",\r\n");
} else {
break;
}
@@ -74,12 +98,10 @@ static void PrintReadRangeData(BACNET_READ_RANGE_DATA *data)
break;
}
}
#if PRINT_ENABLED
if (print_brace) {
fprintf(stdout, "}");
debug_printf_stdout("}");
}
fprintf(stdout, "\r\n");
#endif
debug_printf_stdout("\r\n}\r\n");
}
}
@@ -95,12 +117,11 @@ void handler_read_range_ack(
(void)src;
(void)service_data; /* we could use these... */
len = rr_ack_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
fprintf(stderr, "Received ReadRange Ack!\n");
#endif
if (len > 0) {
PrintReadRangeData(&data);
} else {
#if PRINT_ENABLED
fprintf(stderr, "Received ReadRange Ack!\n");
#endif
}
}