Skip to content

Commit 57c3867

Browse files
committed
Added better debug to bacnet property value read and write. Fixed the array element option.
1 parent e3f3977 commit 57c3867

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

zephyr/subsys/bacnet_shell/bacnet_shell_property.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ int bacnet_shell_property_parse(
117117
}
118118
err = bacnet_shell_object_type_instance_parse(
119119
sh, argc, argv, object_type, object_instance);
120-
/* property can have [] to denote array */
121120
if (isalpha(argv[3][0])) {
122-
/* choose a property by name */
123-
scan_count = sscanf(argv[3], "%79s[%u]", name, &array_value);
121+
/* choose a property by name with optional [] to denote array */
122+
scan_count = sscanf(argv[3], "%79[^[][%u]", name, &array_value);
124123
if (scan_count < 1) {
125124
shell_error(sh, "parse: missing property: %s.", argv[3]);
126125
return -EINVAL;
@@ -312,6 +311,27 @@ static int cmd_json_print_key_error(
312311
return 0;
313312
}
314313

314+
static int cmd_json_print_property_value_tag(
315+
const struct shell *sh,
316+
const char *property,
317+
unsigned long array_index,
318+
unsigned long priority,
319+
unsigned long value_tag,
320+
const char *value_string,
321+
bool success,
322+
const char *append)
323+
{
324+
shell_print(
325+
sh,
326+
"{\"%s\": {\"array-index\": %lu}, {\"priority\": %lu}, "
327+
"{\"value-tag\": \"%s\"}, {\"value\": \"%s\"}, {\"success\": %s}}%s",
328+
property, array_index, priority,
329+
bactext_application_tag_name(value_tag), value_string,
330+
success ? "true" : "false", append);
331+
332+
return 0;
333+
}
334+
315335
static char *
316336
bactext_name(const char *name, unsigned long value, char *buffer, size_t size)
317337
{
@@ -598,13 +618,10 @@ static int cmd_value(const struct shell *sh, size_t argc, char **argv)
598618
status =
599619
bacapp_parse_application_data(value.tag, value_string, &value);
600620
}
601-
#ifdef BACNET_SHELL_PROPERTY_DEBUG
602-
shell_print(
603-
sh, "Parsed %s-%u %s %s -> tag=%u %s",
604-
bactext_object_type_name(object_type), object_instance,
605-
bactext_property_name(object_property), value_string, value.tag,
606-
status ? "successfully" : "unsuccessfully");
607-
#endif
621+
/* convert the property identifier into a string */
622+
bactext_name(
623+
bactext_property_name_default(object_property, NULL),
624+
object_property, property_name, sizeof(property_name));
608625
if (status) {
609626
apdu_len = bacapp_encode_data(apdu, &value);
610627
if (apdu_len) {
@@ -613,15 +630,10 @@ static int cmd_value(const struct shell *sh, size_t argc, char **argv)
613630
wpdata.application_data_len = apdu_len;
614631
memcpy(&wpdata.application_data, apdu, apdu_len);
615632
status = Device_Write_Property(&wpdata);
616-
bactext_name(
617-
bactext_property_name_default(wpdata.object_property, NULL),
618-
wpdata.object_property, property_name,
619-
sizeof(property_name));
620633
if (status) {
621-
cmd_json_print_key_error(
622-
sh, property_name,
623-
bactext_error_class_name(ERROR_CLASS_PROPERTY),
624-
bactext_error_code_name(ERROR_CODE_SUCCESS), "");
634+
cmd_json_print_property_value_tag(
635+
sh, property_name, array_index, priority, value.tag,
636+
value_string, status, "");
625637
} else {
626638
cmd_json_print_key_error(
627639
sh, property_name,
@@ -634,6 +646,10 @@ static int cmd_value(const struct shell *sh, size_t argc, char **argv)
634646
bactext_error_class_name(ERROR_CLASS_PROPERTY),
635647
bactext_error_code_name(ERROR_CODE_UNEXPECTED_DATA), "");
636648
}
649+
} else {
650+
cmd_json_print_property_value_tag(
651+
sh, property_name, array_index, priority, value.tag,
652+
value_string, status, "");
637653
}
638654
}
639655

0 commit comments

Comments
 (0)