apps - allow text strings for object-type and property arguments. (#8)
The existing method of calling various example apps requires the user to know the enumeration value for the object-type and property values. This patch enhances to allow the object-type and property arguments to be specified as strings, using the strings as defined in the spec. It does not remove the old behaviour. Current: bacrp 1234 3 1 85 New: bacrp 1234 binary-input 1 present-value This change does not currently apply to the property arguments of the readm and writem applications.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "bacnet/indtext.h"
|
||||
#include "bacnet/bacenum.h"
|
||||
#include "bacnet/bactext.h"
|
||||
@@ -42,6 +43,30 @@
|
||||
static const char *ASHRAE_Reserved_String = "Reserved for Use by ASHRAE";
|
||||
static const char *Vendor_Proprietary_String = "Vendor Proprietary Value";
|
||||
|
||||
/* Search for a text value first based on the corresponding text list, then by
|
||||
* attempting to convert to an integer value. */
|
||||
static bool bactext_strtol_index(INDTEXT_DATA *istring, const char *search_name, unsigned *found_index)
|
||||
{
|
||||
char *endptr;
|
||||
long value;
|
||||
|
||||
if (indtext_by_istring(istring, search_name, found_index) == true) {
|
||||
return true;
|
||||
} else {
|
||||
value = strtol(search_name, &endptr, 0);
|
||||
if (endptr == search_name) {
|
||||
/* No digits found */
|
||||
return false;
|
||||
} else if (*endptr != '\0') {
|
||||
/* Extra text found */
|
||||
return false;
|
||||
} else {
|
||||
*found_index = (unsigned)value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_confirmed_service_names[] = {
|
||||
{ SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, "Acknowledge-Alarm" },
|
||||
{ SERVICE_CONFIRMED_COV_NOTIFICATION, "COV-Notification" },
|
||||
@@ -206,6 +231,12 @@ bool bactext_object_type_index(const char *search_name, unsigned *found_index)
|
||||
bacnet_object_type_names, search_name, found_index);
|
||||
}
|
||||
|
||||
bool bactext_object_type_strtol(const char *search_name, unsigned *found_index)
|
||||
{
|
||||
return bactext_strtol_index(
|
||||
bacnet_object_type_names, search_name, found_index);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_property_names[] = {
|
||||
/* FIXME: use the enumerations from bacenum.h */
|
||||
{ PROP_ACKED_TRANSITIONS, "acked-transitions" },
|
||||
@@ -660,6 +691,12 @@ bool bactext_property_index(const char *search_name, unsigned *found_index)
|
||||
return indtext_by_istring(bacnet_property_names, search_name, found_index);
|
||||
}
|
||||
|
||||
bool bactext_property_strtol(const char *search_name, unsigned *found_index)
|
||||
{
|
||||
return bactext_strtol_index(
|
||||
bacnet_property_names, search_name, found_index);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_engineering_unit_names[] = {
|
||||
{ UNITS_SQUARE_METERS, "square-meters" },
|
||||
{ UNITS_SQUARE_FEET, "square-feet" },
|
||||
|
||||
@@ -55,6 +55,9 @@ extern "C" {
|
||||
bool bactext_object_type_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index);
|
||||
bool bactext_object_type_strtol(
|
||||
const char *search_name,
|
||||
unsigned *found_index);
|
||||
const char *bactext_notify_type_name(
|
||||
unsigned index);
|
||||
const char *bactext_event_type_name(
|
||||
@@ -67,6 +70,9 @@ extern "C" {
|
||||
bool bactext_property_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index);
|
||||
bool bactext_property_strtol(
|
||||
const char *search_name,
|
||||
unsigned *found_index);
|
||||
const char *bactext_engineering_unit_name(
|
||||
unsigned index);
|
||||
bool bactext_engineering_unit_index(
|
||||
|
||||
Reference in New Issue
Block a user