From 59831e8eaa79f8d57fd0beab6964f3964f316518 Mon Sep 17 00:00:00 2001 From: tbrennan3 Date: Mon, 22 Aug 2011 19:49:25 +0000 Subject: [PATCH] Fixed up Device_Object_Name_Copy(). Revised Routed_Device_Name() and Add_Routed_Device() to use BACNET_CHARACTER_STRING. --- bacnet-stack/demo/object/device.c | 35 ++++++++++------------------ bacnet-stack/demo/object/device.h | 20 +++++++++------- bacnet-stack/demo/object/gw_device.c | 15 ++++++------ 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index ade0b7f3..221aae93 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -132,7 +132,7 @@ static object_functions_t Object_Table[] = { Load_Control_Index_To_Instance, Load_Control_Valid_Instance, Load_Control_Object_Name, Load_Control_Read_Property, Load_Control_Write_Property, Load_Control_Property_Lists, - NULL, NULL, NULL}, { + NULL, NULL, NULL, NULL}, { OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init, Multistate_Output_Count, Multistate_Output_Index_To_Instance, @@ -160,7 +160,7 @@ static object_functions_t Object_Table[] = { NULL, NULL, NULL, NULL}, { #endif MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL} }; @@ -863,7 +863,7 @@ bool Device_Valid_Object_Name( /** Determine if we have an object of this type and instance number. * @param object_type [in] The desired BACNET_OBJECT_TYPE * @param object_instance [in] The object instance number to be looked up. - * @return The Object Name or else NULL if not found + * @return True if found, else False if no such Object in this device. */ bool Device_Valid_Object_Id( int object_type, @@ -880,34 +880,23 @@ bool Device_Valid_Object_Id( return status; } -/** copy a child object object_name value. - * @param object_type [out] The BACNET_OBJECT_TYPE of the matching Object. - * @param object_instance [out] The object instance number of the matching Object. - * @param object_name [in] The desired Object Name to look for. +/** Copy a child object's object_name value, given its ID. + * @param object_type [in] The BACNET_OBJECT_TYPE of the child Object. + * @param object_instance [in] The object instance number of the child Object. + * @param object_name [out] The Object Name found for this child Object. * @return True on success or else False if not found. */ bool Device_Object_Name_Copy( - int object_type, + BACNET_OBJECT_TYPE object_type, uint32_t object_instance, BACNET_CHARACTER_STRING * object_name) { struct object_functions *pObject = NULL; bool found = false; - int type = 0; - uint32_t instance; - unsigned max_objects = 0, i = 0; - bool check_id = false; - max_objects = Device_Object_List_Count(); - for (i = 0; i < max_objects; i++) { - check_id = Device_Object_List_Identifier(i, &type, &instance); - if (check_id) { - pObject = Device_Objects_Find_Functions(type); - if ((pObject != NULL) && (pObject->Object_Name != NULL)) { - found = pObject->Object_Name(instance, object_name); - break; - } - } + pObject = Device_Objects_Find_Functions(object_type); + if ((pObject != NULL) && (pObject->Object_Valid_Instance != NULL)) { + found = pObject->Object_Name(object_instance, object_name); } return found; @@ -1633,7 +1622,7 @@ void Routing_Device_Init( struct object_functions *pDevObject = NULL; /* Initialize with our preset strings */ - Add_Routed_Device(first_object_instance, My_Object_Name, Description); + Add_Routed_Device(first_object_instance, &My_Object_Name, Description); /* Now substitute our routed versions of the main object functions. */ pDevObject = &Object_Table[0]; diff --git a/bacnet-stack/demo/object/device.h b/bacnet-stack/demo/object/device.h index e8583aa9..8c84eeb5 100644 --- a/bacnet-stack/demo/object/device.h +++ b/bacnet-stack/demo/object/device.h @@ -66,10 +66,11 @@ typedef uint32_t( /** Provides the BACnet Object_Name for a given object instance of this type. * @ingroup ObjHelpers - * @param [in] The object instance number to be looked up. - * @return Pointer to a string containing the unique Object_Name. This string - * is temporary and should be copied upon the return. It is - * allocated by the system and does not need to be freed. + * @param object_instance [in] The object instance number to be looked up. + * @param object_name [in,out] Pointer to a character_string structure that + * will hold a copy of the object name if this is a valid object_instance. + * @return True if the object_instance is valid and object_name has been + * filled with a copy of the Object's name. */ typedef bool( *object_name_function) @@ -254,9 +255,9 @@ extern "C" { BACNET_CHARACTER_STRING * object_name); bool Device_Set_Object_Name( BACNET_CHARACTER_STRING * object_name); - /* copy a child object name */ + /* Copy a child object name, given its ID. */ bool Device_Object_Name_Copy( - int object_type, + BACNET_OBJECT_TYPE object_type, uint32_t object_instance, BACNET_CHARACTER_STRING * object_name); @@ -352,7 +353,7 @@ extern "C" { uint16_t Add_Routed_Device( uint32_t Object_Instance, - const char *Object_Name, + BACNET_CHARACTER_STRING *Object_Name, const char *Description); DEVICE_OBJECT_DATA *Get_Routed_Device_Object( int idx); @@ -378,8 +379,9 @@ extern "C" { unsigned index); bool Routed_Device_Valid_Object_Instance_Number( uint32_t object_id); - char *Routed_Device_Name( - uint32_t object_instance); + bool Routed_Device_Name( + uint32_t object_instance, + BACNET_CHARACTER_STRING * object_name); uint32_t Routed_Device_Object_Instance_Number( void); bool Routed_Device_Set_Object_Instance_Number( diff --git a/bacnet-stack/demo/object/gw_device.c b/bacnet-stack/demo/object/gw_device.c index 13f82670..3d06ba64 100644 --- a/bacnet-stack/demo/object/gw_device.c +++ b/bacnet-stack/demo/object/gw_device.c @@ -116,7 +116,7 @@ uint16_t iCurrent_Device_Idx = 0; */ uint16_t Add_Routed_Device( uint32_t Object_Instance, - const char *sObject_Name, + BACNET_CHARACTER_STRING *sObject_Name, const char *sDescription) { int i = Num_Managed_Devices; @@ -127,8 +127,8 @@ uint16_t Add_Routed_Device( pDev->bacObj.mObject_Type = OBJECT_DEVICE; pDev->bacObj.Object_Instance_Number = Object_Instance; if (sObject_Name != NULL) - Routed_Device_Set_Object_Name(CHARACTER_UTF8, sObject_Name, - strlen(sObject_Name)); + Routed_Device_Set_Object_Name(sObject_Name->encoding, + sObject_Name->value, sObject_Name->length); else Routed_Device_Set_Object_Name(CHARACTER_UTF8, "No Name", strlen("No Name")); @@ -401,12 +401,13 @@ bool Routed_Device_Valid_Object_Instance_Number( return bResult; } -char *Routed_Device_Name( - uint32_t object_instance) +bool Routed_Device_Name( + uint32_t object_instance, + BACNET_CHARACTER_STRING * object_name) { DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; if (object_instance == pDev->bacObj.Object_Instance_Number) { - return pDev->bacObj.Object_Name; + return characterstring_init_ansi(object_name, pDev->bacObj.Object_Name); } return NULL; @@ -550,7 +551,7 @@ bool Routed_Device_Set_Object_Instance_Number( bool Routed_Device_Set_Object_Name( uint8_t encoding, const char *value, - size_t length); + size_t length) { bool status = false; /*return value */ DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];