diff --git a/bacnet-stack/Makefile b/bacnet-stack/Makefile index d799ff1e..a9665011 100644 --- a/bacnet-stack/Makefile +++ b/bacnet-stack/Makefile @@ -20,6 +20,7 @@ SRCS = ports/linux/main.c \ handlers.c \ bacdcode.c \ bacapp.c \ + bacprop.c \ bigend.c \ whois.c \ iam.c \ diff --git a/bacnet-stack/bacprop.c b/bacnet-stack/bacprop.c new file mode 100644 index 00000000..c1e41031 --- /dev/null +++ b/bacnet-stack/bacprop.c @@ -0,0 +1,106 @@ +/*####COPYRIGHTBEGIN#### + ------------------------------------------- + Copyright (C) 2005 John Goulah + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to + The Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA. + + As a special exception, if other files instantiate templates or + use macros or inline functions from this file, or you compile + this file and link it with other works to produce a work based + on this file, this file does not by itself cause the resulting + work to be covered by the GNU General Public License. However + the source code for this file must still be made available in + accordance with section (3) of the GNU General Public License. + + This exception does not invalidate any other reasons why a work + based on this file might be covered by the GNU General Public + License. + ------------------------------------------- +####COPYRIGHTEND####*/ +#include +#include +#include +#include "bacprop.h" + +PROP_TAG_DATA bacnet_object_device_property_tag_map[] = { + {PROP_OBJECT_IDENTIFIER, BACNET_APPLICATION_TAG_OBJECT_ID}, + {PROP_OBJECT_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_OBJECT_TYPE, BACNET_APPLICATION_TAG_ENUMERATED}, + {PROP_SYSTEM_STATUS, BACNET_APPLICATION_TAG_ENUMERATED}, + {PROP_VENDOR_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_VENDOR_IDENTIFIER, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_MODEL_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_FIRMWARE_REVISION, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_APPLICATION_SOFTWARE_VERSION, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_PROTOCOL_VERSION, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_PROTOCOL_CONFORMANCE_CLASS, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_PROTOCOL_SERVICES_SUPPORTED, BACNET_APPLICATION_TAG_BIT_STRING}, + {PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, BACNET_APPLICATION_TAG_BIT_STRING}, + {PROP_MAX_APDU_LENGTH_ACCEPTED, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_SEGMENTATION_SUPPORTED, BACNET_APPLICATION_TAG_ENUMERATED}, + {PROP_APDU_TIMEOUT, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_NUMBER_OF_APDU_RETRIES, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + { 0, 0 } +}; + +/* FIXME: BACNET_APPLICATION_TAG_NULL = 0, + FIXME: PROP_ACKED_TRANSITIONS = 0, + perhaps since none of the properties uses the NULL tag, + we could use that as the list terminator, rather than the + property==0. Either that, or start using signed int and + pass a -1 as the list terminator. */ +unsigned bacprop_tag_by_index_default( + PROP_TAG_DATA *data_list, + unsigned index, + unsigned default_ret) +{ + unsigned pUnsigned = 0; + + if (data_list) + { + while (data_list->prop_id) + { + if (data_list->prop_id == index) + { + pUnsigned = data_list->tag_id; + break; + } + data_list++; + } + } + + return pUnsigned?pUnsigned:default_ret; +} + +/* FIXME: how do we know when we don't have a match? Maybe use signed return, + or return a boolean and pass the return value as an argument. */ +unsigned bacprop_property_tag(BACNET_OBJECT_TYPE type, unsigned prop) +{ + switch (type) + { + case OBJECT_DEVICE: + return bacprop_tag_by_index_default( + bacnet_object_device_property_tag_map, + prop, + 0); + default: + fprintf(stderr, "Unsupported object type"); + break; + } + + return 0; +} diff --git a/bacnet-stack/bacprop.h b/bacnet-stack/bacprop.h new file mode 100644 index 00000000..993e159f --- /dev/null +++ b/bacnet-stack/bacprop.h @@ -0,0 +1,62 @@ +/*####COPYRIGHTBEGIN#### + ------------------------------------------- + Copyright (C) 2005 John Goulah + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to + The Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA. + + As a special exception, if other files instantiate templates or + use macros or inline functions from this file, or you compile + this file and link it with other works to produce a work based + on this file, this file does not by itself cause the resulting + work to be covered by the GNU General Public License. However + the source code for this file must still be made available in + accordance with section (3) of the GNU General Public License. + + This exception does not invalidate any other reasons why a work + based on this file might be covered by the GNU General Public + License. + ------------------------------------------- +####COPYRIGHTEND####*/ +#ifndef BACPROP_H +#define BACPROP_H + +#include +#include +#include "bacenum.h" + +typedef struct +{ + unsigned prop_id; /* index number that matches the text */ + unsigned tag_id; /* text pair - use NULL to end the list */ +} PROP_TAG_DATA; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +unsigned bacprop_tag_by_index_default( + PROP_TAG_DATA *data_list, + unsigned index, + unsigned default_ret); + +unsigned bacprop_property_tag(BACNET_OBJECT_TYPE type, unsigned prop); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/bacnet-stack/bactext.c b/bacnet-stack/bactext.c index f1469947..87ca63e9 100644 --- a/bacnet-stack/bactext.c +++ b/bacnet-stack/bactext.c @@ -39,46 +39,6 @@ static const char *ASHRAE_Reserved_String = "Reserved for Use by ASHRAE"; static const char *Vendor_Proprietary_String = "Vendor Proprietary Value"; - -PROP_TAG_DATA bacnet_object_device_property_tag_map[] = { - {PROP_OBJECT_IDENTIFIER, BACNET_APPLICATION_TAG_OBJECT_ID}, - {PROP_OBJECT_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, - {PROP_OBJECT_TYPE, BACNET_APPLICATION_TAG_ENUMERATED}, - {PROP_SYSTEM_STATUS, BACNET_APPLICATION_TAG_ENUMERATED}, - {PROP_VENDOR_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, - {PROP_VENDOR_IDENTIFIER, BACNET_APPLICATION_TAG_UNSIGNED_INT}, - {PROP_MODEL_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, - {PROP_FIRMWARE_REVISION, BACNET_APPLICATION_TAG_CHARACTER_STRING}, - {PROP_APPLICATION_SOFTWARE_VERSION, BACNET_APPLICATION_TAG_CHARACTER_STRING}, - {PROP_PROTOCOL_VERSION, BACNET_APPLICATION_TAG_UNSIGNED_INT}, - {PROP_PROTOCOL_CONFORMANCE_CLASS, BACNET_APPLICATION_TAG_UNSIGNED_INT}, - {PROP_PROTOCOL_SERVICES_SUPPORTED, BACNET_APPLICATION_TAG_BIT_STRING}, - {PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, BACNET_APPLICATION_TAG_BIT_STRING}, - {PROP_MAX_APDU_LENGTH_ACCEPTED, BACNET_APPLICATION_TAG_UNSIGNED_INT}, - {PROP_SEGMENTATION_SUPPORTED, BACNET_APPLICATION_TAG_ENUMERATED}, - {PROP_APDU_TIMEOUT, BACNET_APPLICATION_TAG_UNSIGNED_INT}, - {PROP_NUMBER_OF_APDU_RETRIES, BACNET_APPLICATION_TAG_UNSIGNED_INT}, - { 0, 0 } -}; - -unsigned bactext_property_tag(BACNET_OBJECT_TYPE type, unsigned prop) -{ - switch (type) - { - case OBJECT_DEVICE: - return indtext_tag_by_index_default( - bacnet_object_device_property_tag_map, - prop, - 0); - break; - default: - fprintf(stderr, "Unsupported object type"); - break; - } - - return 0; -} - INDTEXT_DATA bacnet_confirmed_service_names[] = { { SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, "Acknowledge-Alarm" }, { SERVICE_CONFIRMED_COV_NOTIFICATION, "COV-Notification" }, diff --git a/bacnet-stack/bactext.h b/bacnet-stack/bactext.h index 146fc036..1476ad17 100644 --- a/bacnet-stack/bactext.h +++ b/bacnet-stack/bactext.h @@ -52,11 +52,7 @@ const char *bactext_reject_reason_name(int index); const char *bactext_abort_reason_name(int index); const char *bactext_error_class_name(int index); const char *bactext_error_code_name(int index); - unsigned bactext_property_id(const char* name); - -unsigned bactext_property_tag(BACNET_OBJECT_TYPE type, unsigned prop); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bacnet-stack/indtext.c b/bacnet-stack/indtext.c index 7d5321a9..2c64d82c 100644 --- a/bacnet-stack/indtext.c +++ b/bacnet-stack/indtext.c @@ -145,29 +145,6 @@ const char *indtext_by_index_default( return pString?pString:default_string; } -unsigned indtext_tag_by_index_default( - PROP_TAG_DATA *data_list, - unsigned index, - unsigned default_ret) -{ - unsigned pUnsigned = 0; - - if (data_list) - { - while (data_list->prop_id) - { - if (data_list->prop_id == index) - { - pUnsigned = data_list->tag_id; - break; - } - data_list++; - } - } - - return pUnsigned?pUnsigned:default_ret; -} - const char *indtext_by_index_split_default( INDTEXT_DATA *data_list, int index, diff --git a/bacnet-stack/indtext.h b/bacnet-stack/indtext.h index 3c5d0d71..3e9596ef 100644 --- a/bacnet-stack/indtext.h +++ b/bacnet-stack/indtext.h @@ -45,21 +45,10 @@ typedef struct const char *pString; /* text pair - use NULL to end the list */ } INDTEXT_DATA; -typedef struct -{ - unsigned prop_id; /* index number that matches the text */ - unsigned tag_id; /* text pair - use NULL to end the list */ -} PROP_TAG_DATA; - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -unsigned indtext_tag_by_index_default( - PROP_TAG_DATA *data_list, - unsigned index, - unsigned default_ret); - /* Searches for a matching string and returns the index to the string in the parameter found_index. If the string is not found, false is returned