Changed Object Table from a global to a local variable and added a Device function to initialize it.

This commit is contained in:
skarg
2010-12-13 03:41:55 +00:00
parent 20ca252a8d
commit 8f1e8d82cd
19 changed files with 151 additions and 121 deletions
+4 -3
View File
@@ -52,9 +52,9 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
/* buffer used for receive */ /* buffer used for receive */
@@ -122,6 +122,7 @@ void MyDeviceCommunicationControlSimpleAckHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -63,7 +63,7 @@
* @{ */ * @{ */
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -270,6 +270,7 @@ void MyReadPropertyMultipleAckHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
#if BAC_ROUTING #if BAC_ROUTING
+22 -21
View File
@@ -22,7 +22,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
*********************************************************************/ *********************************************************************/
/** /**
* Code for this project began with code from the demo/server project and * Code for this project began with code from the demo/server project and
* Paul Chapman's vmac project. * Paul Chapman's vmac project.
*/ */
@@ -82,7 +82,7 @@
/*@{*/ /*@{*/
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{ANALOG_INPUT_OBJ_FUNCTIONS}, {ANALOG_INPUT_OBJ_FUNCTIONS},
{ANALOG_OUTPUT_OBJ_FUNCTIONS}, {ANALOG_OUTPUT_OBJ_FUNCTIONS},
@@ -114,7 +114,7 @@ int DNET_list[2] = {
/** Initialize the Device Objects and each of the child Object instances. /** Initialize the Device Objects and each of the child Object instances.
* @param first_object_instance Set the first (gateway) Device to this * @param first_object_instance Set the first (gateway) Device to this
instance number, and subsequent devices to incremented values. instance number, and subsequent devices to incremented values.
*/ */
void Devices_Init( void Devices_Init(
@@ -123,29 +123,29 @@ void Devices_Init(
int i; int i;
char nameText[MAX_DEV_NAME_LEN]; char nameText[MAX_DEV_NAME_LEN];
char descText[MAX_DEV_DESC_LEN]; char descText[MAX_DEV_DESC_LEN];
/* Gateway Device has already been initialized. /* Gateway Device has already been initialized.
* But give it a better Description. */ * But give it a better Description. */
Routed_Device_Set_Description(DEV_DESCR_GATEWAY, strlen(DEV_DESCR_GATEWAY)); Routed_Device_Set_Description(DEV_DESCR_GATEWAY, strlen(DEV_DESCR_GATEWAY));
/* Now initialize the remote Device objects. */ /* Now initialize the remote Device objects. */
for ( i = 1; i < MAX_NUM_DEVICES; i++ ) for ( i = 1; i < MAX_NUM_DEVICES; i++ )
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
_snprintf( nameText, MAX_DEV_NAME_LEN, "%s %d", _snprintf( nameText, MAX_DEV_NAME_LEN, "%s %d",
DEV_NAME_BASE, i+1); DEV_NAME_BASE, i+1);
_snprintf( descText, MAX_DEV_DESC_LEN, "%s %d", _snprintf( descText, MAX_DEV_DESC_LEN, "%s %d",
DEV_DESCR_REMOTE, i); DEV_DESCR_REMOTE, i);
#else #else
snprintf( nameText, MAX_DEV_NAME_LEN, "%s %d", snprintf( nameText, MAX_DEV_NAME_LEN, "%s %d",
DEV_NAME_BASE, i+1); DEV_NAME_BASE, i+1);
snprintf( descText, MAX_DEV_DESC_LEN, "%s %d", snprintf( descText, MAX_DEV_DESC_LEN, "%s %d",
DEV_DESCR_REMOTE, i); DEV_DESCR_REMOTE, i);
#endif #endif
Add_Routed_Device( (first_object_instance+i), nameText, descText ); Add_Routed_Device( (first_object_instance+i), nameText, descText );
} }
} }
@@ -155,14 +155,15 @@ void Devices_Init(
static void Init_Service_Handlers( static void Init_Service_Handlers(
uint32_t first_object_instance ) uint32_t first_object_instance )
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Routing_Device_Init( first_object_instance ); Routing_Device_Init( first_object_instance );
/* we need to handle who-is to support dynamic device binding /* we need to handle who-is to support dynamic device binding
* For the gateway, we want the routing handlers, and we will use the * For the gateway, we want the routing handlers, and we will use the
* unicast variety so we can get back through switches to different subnets */ * unicast variety so we can get back through switches to different subnets */
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
handler_who_is_unicast_for_routing); handler_who_is_unicast_for_routing);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS,
handler_who_has_for_routing); handler_who_has_for_routing);
/* set the handler for all the services we don't implement */ /* set the handler for all the services we don't implement */
/* It is required to send the proper reject message... */ /* It is required to send the proper reject message... */
@@ -203,7 +204,7 @@ static void Init_Service_Handlers(
* The gateway has already gotten the normal address (eg, PC's IP for BIP) and * The gateway has already gotten the normal address (eg, PC's IP for BIP) and
* the remote devices get * the remote devices get
* - For BIP, the IP address reversed, and 4th byte equal to index. * - For BIP, the IP address reversed, and 4th byte equal to index.
* (Eg, 11.22.33.44 for the gateway becomes 44.33.22.01 for the first remote * (Eg, 11.22.33.44 for the gateway becomes 44.33.22.01 for the first remote
* device.) This is sure to be unique! The port number stays the same. * device.) This is sure to be unique! The port number stays the same.
* - For MS/TP, [Steve inserts a good idea here] * - For MS/TP, [Steve inserts a good idea here]
*/ */
@@ -216,7 +217,7 @@ void Initialize_Device_Addresses( )
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
struct in_addr *netPtr; /* Lets us cast to this type */ struct in_addr *netPtr; /* Lets us cast to this type */
uint8_t *gatewayMac = NULL; uint8_t *gatewayMac = NULL;
uint32_t myAddr = bip_get_addr(); uint32_t myAddr = bip_get_addr();
pDev = Get_Routed_Device_Object( i ); pDev = Get_Routed_Device_Object( i );
gatewayMac = pDev->bacDevAddr.mac; /* Keep pointer to the main MAC */ gatewayMac = pDev->bacDevAddr.mac; /* Keep pointer to the main MAC */
memcpy( pDev->bacDevAddr.mac, &myAddr, 4 ); memcpy( pDev->bacDevAddr.mac, &myAddr, 4 );
@@ -226,7 +227,7 @@ void Initialize_Device_Addresses( )
#elif defined(BACDL_MSTP) #elif defined(BACDL_MSTP)
/* Todo: */ /* Todo: */
pDev->bacDevAddr.mac_len = 2; pDev->bacDevAddr.mac_len = 2;
#else #else
#error "No support for this Data Link Layer type " #error "No support for this Data Link Layer type "
#endif #endif
/* broadcast an I-Am on startup */ /* broadcast an I-Am on startup */
@@ -247,7 +248,7 @@ void Initialize_Device_Addresses( )
pDev->bacDevAddr.net = VIRTUAL_DNET; pDev->bacDevAddr.net = VIRTUAL_DNET;
memcpy( &pDev->bacDevAddr.adr[0], &pDev->bacDevAddr.mac[0], 6 ); memcpy( &pDev->bacDevAddr.adr[0], &pDev->bacDevAddr.mac[0], 6 );
pDev->bacDevAddr.len = 6; pDev->bacDevAddr.len = 6;
printf( " - Routed device [%d] ID %u at %s \n", i, printf( " - Routed device [%d] ID %u at %s \n", i,
pDev->bacObj.Object_Instance_Number, inet_ntoa( *netPtr ) ); pDev->bacObj.Object_Instance_Number, inet_ntoa( *netPtr ) );
#elif defined(BACDL_MSTP) #elif defined(BACDL_MSTP)
/* Todo: set MS/TP net and port #s */ /* Todo: set MS/TP net and port #s */
@@ -327,11 +328,11 @@ int main(
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
/* broadcast an I-am-router-to-network on startup */ /* broadcast an I-am-router-to-network on startup */
printf( "Remote Network DNET Number %d \n", DNET_list[0] ); printf( "Remote Network DNET Number %d \n", DNET_list[0] );
Send_I_Am_Router_To_Network( DNET_list ); Send_I_Am_Router_To_Network( DNET_list );
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* input */ /* input */
+2 -1
View File
@@ -47,7 +47,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -90,6 +90,7 @@ void MyRejectHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -49,7 +49,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -220,6 +220,7 @@ static void My_NPDU_Handler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+41 -30
View File
@@ -64,14 +64,14 @@ extern bool Routed_Device_Write_Property_Local(
/* Defined in user application; /* Defined in user application;
object functions for all included BACnet objects */ object functions for all included BACnet objects */
extern object_functions_t Object_Table[]; static object_functions_t *Object_Table;
/** Glue function to let the Device object, when called by a handler, /** Glue function to let the Device object, when called by a handler,
* lookup which Object type needs to be invoked. * lookup which Object type needs to be invoked.
* @ingroup ObjHelpers * @ingroup ObjHelpers
* @param Object_Type [in] The type of BACnet Object the handler wants to access. * @param Object_Type [in] The type of BACnet Object the handler wants to access.
* @return Pointer to the group of object helper functions that implement this * @return Pointer to the group of object helper functions that implement this
* type of Object. * type of Object.
*/ */
static struct object_functions *Device_Objects_Find_Functions( static struct object_functions *Device_Objects_Find_Functions(
BACNET_OBJECT_TYPE Object_Type) BACNET_OBJECT_TYPE Object_Type)
@@ -93,11 +93,11 @@ static struct object_functions *Device_Objects_Find_Functions(
/** Try to find a rr_info_function helper function for the requested object type. /** Try to find a rr_info_function helper function for the requested object type.
* @ingroup ObjIntf * @ingroup ObjIntf
* *
* @param object_type [in] The type of BACnet Object the handler wants to access. * @param object_type [in] The type of BACnet Object the handler wants to access.
* @return Pointer to the object helper function that implements the * @return Pointer to the object helper function that implements the
* ReadRangeInfo function, Object_RR_Info, for this type of Object on * ReadRangeInfo function, Object_RR_Info, for this type of Object on
* success, else a NULL pointer if the type of Object isn't supported * success, else a NULL pointer if the type of Object isn't supported
* or doesn't have a ReadRangeInfo function. * or doesn't have a ReadRangeInfo function.
*/ */
rr_info_function Device_Objects_RR_Info( rr_info_function Device_Objects_RR_Info(
@@ -209,9 +209,9 @@ bool Device_Reinitialize(
default: default:
break; break;
} }
/* Note: you could use a mix of state /* Note: you could use a mix of state
and password to multiple things */ and password to multiple things */
/* note: you probably want to restart *after* the /* note: you probably want to restart *after* the
simple ack has been sent from the return handler simple ack has been sent from the return handler
so just set a flag from here */ so just set a flag from here */
status = true; status = true;
@@ -308,7 +308,7 @@ static char Description[MAX_DEV_DESC_LEN + 1] = "server";
static BACNET_TIME Local_Time; /* rely on OS, if there is one */ static BACNET_TIME Local_Time; /* rely on OS, if there is one */
static BACNET_DATE Local_Date; /* rely on OS, if there is one */ static BACNET_DATE Local_Date; /* rely on OS, if there is one */
/* NOTE: BACnet UTC Offset is inverse of common practice. /* NOTE: BACnet UTC Offset is inverse of common practice.
If your UTC offset is -5hours of GMT, If your UTC offset is -5hours of GMT,
then BACnet UTC offset is +5hours. then BACnet UTC offset is +5hours.
BACnet UTC offset is expressed in minutes. */ BACnet UTC offset is expressed in minutes. */
static int32_t UTC_Offset = 5 * 60; static int32_t UTC_Offset = 5 * 60;
@@ -353,11 +353,11 @@ uint32_t Device_Index_To_Instance(
uint32_t Device_Object_Instance_Number( uint32_t Device_Object_Instance_Number(
void) void)
{ {
#ifdef BAC_ROUTING #ifdef BAC_ROUTING
return Routed_Device_Object_Instance_Number(); return Routed_Device_Object_Instance_Number();
#else #else
return Object_Instance_Number; return Object_Instance_Number;
#endif #endif
} }
bool Device_Set_Object_Instance_Number( bool Device_Set_Object_Instance_Number(
@@ -466,7 +466,7 @@ int Device_Set_System_Status(
break; break;
/* Don't allow outsider set this - it should probably /* Don't allow outsider set this - it should probably
* be set if the device config is incomplete or * be set if the device config is incomplete or
* corrupted or perhaps after some sort of operator * corrupted or perhaps after some sort of operator
* wipe operation. * wipe operation.
*/ */
@@ -632,7 +632,7 @@ void Device_Set_Database_Revision(
Database_Revision = revision; Database_Revision = revision;
} }
/* /*
* Shortcut for incrementing database revision as this is potentially * Shortcut for incrementing database revision as this is potentially
* the most common operation if changing object names and ids is * the most common operation if changing object names and ids is
* implemented. * implemented.
@@ -798,16 +798,16 @@ static void Update_Current_Time(
#endif #endif
/* /*
struct tm struct tm
int tm_sec Seconds [0,60]. int tm_sec Seconds [0,60].
int tm_min Minutes [0,59]. int tm_min Minutes [0,59].
int tm_hour Hour [0,23]. int tm_hour Hour [0,23].
int tm_mday Day of month [1,31]. int tm_mday Day of month [1,31].
int tm_mon Month of year [0,11]. int tm_mon Month of year [0,11].
int tm_year Years since 1900. int tm_year Years since 1900.
int tm_wday Day of week [0,6] (Sunday =0). int tm_wday Day of week [0,6] (Sunday =0).
int tm_yday Day of year [0,365]. int tm_yday Day of year [0,365].
int tm_isdst Daylight Savings flag. int tm_isdst Daylight Savings flag.
*/ */
#if defined(_MSC_VER) #if defined(_MSC_VER)
time(&tTemp); time(&tTemp);
@@ -1081,7 +1081,7 @@ int Device_Read_Property_Local(
/** Looks up the requested Object and Property, and encodes its Value in an APDU. /** Looks up the requested Object and Property, and encodes its Value in an APDU.
* @ingroup ObjIntf * @ingroup ObjIntf
* If the Object or Property can't be found, sets the error class and code. * If the Object or Property can't be found, sets the error class and code.
* *
* @param rpdata [in,out] Structure with the desired Object and Property info * @param rpdata [in,out] Structure with the desired Object and Property info
* on entry, and APDU message on return. * on entry, and APDU message on return.
* @return The length of the APDU on success, else BACNET_STATUS_ERROR * @return The length of the APDU on success, else BACNET_STATUS_ERROR
@@ -1285,7 +1285,7 @@ bool Device_Write_Property_Local(
* if allowed. * if allowed.
* If the Object or Property can't be found, sets the error class and code. * If the Object or Property can't be found, sets the error class and code.
* @ingroup ObjIntf * @ingroup ObjIntf
* *
* @param wp_data [in,out] Structure with the desired Object and Property info * @param wp_data [in,out] Structure with the desired Object and Property info
* and new Value on entry, and APDU message on return. * and new Value on entry, and APDU message on return.
* @return True on success, else False if there is an error. * @return True on success, else False if there is an error.
@@ -1321,6 +1321,17 @@ bool Device_Write_Property(
return (status); return (status);
} }
/** Initialize the group of object helper functions for any supported Object.
* @ingroup ObjIntf
* @param object_table [in,out] array of structure with object functions.
* Each Child Object must provide some implementation of each of these
* functions in order to properly support the default handlers.
*/
void Device_Initialize_Object_Functions(
object_functions_t *object_table)
{
Object_Table = object_table;
}
/** Initialize the Device Object and each of its child Object instances. /** Initialize the Device Object and each of its child Object instances.
* @ingroup ObjIntf * @ingroup ObjIntf
@@ -1388,11 +1399,11 @@ bool DeviceGetRRInfo(
* that need access to local data in this file. * that need access to local data in this file.
****************************************************************************/ ****************************************************************************/
/** Initialize the first of our array of Devices with the main Device's /** Initialize the first of our array of Devices with the main Device's
* information, and then swap out some of the Device object functions and * information, and then swap out some of the Device object functions and
* replace with ones appropriate for routing. * replace with ones appropriate for routing.
* @ingroup ObjIntf * @ingroup ObjIntf
* @param first_object_instance Set the first (gateway) Device to this * @param first_object_instance Set the first (gateway) Device to this
instance number. instance number.
*/ */
void Routing_Device_Init( void Routing_Device_Init(
@@ -1404,7 +1415,7 @@ void Routing_Device_Init(
Device_Init(); Device_Init();
/* Initialize with our preset strings */ /* 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. */ /* Now substitute our routed versions of the main object functions. */
pDevObject = &Object_Table[0]; pDevObject = &Object_Table[0];
pDevObject->Object_Index_To_Instance = Routed_Device_Index_To_Instance; pDevObject->Object_Index_To_Instance = Routed_Device_Index_To_Instance;
+2 -1
View File
@@ -51,7 +51,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -185,6 +185,7 @@ static void LocalIAmHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -54,7 +54,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -149,6 +149,7 @@ void My_Read_Property_Ack_Handler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -55,7 +55,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -194,6 +194,7 @@ void My_Read_Property_Multiple_Ack_Handler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -52,7 +52,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -120,6 +120,7 @@ void MyReinitializeDeviceSimpleAckHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -66,7 +66,7 @@
#endif #endif
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{ANALOG_INPUT_OBJ_FUNCTIONS}, {ANALOG_INPUT_OBJ_FUNCTIONS},
{ANALOG_OUTPUT_OBJ_FUNCTIONS}, {ANALOG_OUTPUT_OBJ_FUNCTIONS},
@@ -101,6 +101,7 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is to support dynamic device binding */ /* we need to handle who-is to support dynamic device binding */
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
+2 -1
View File
@@ -47,7 +47,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -92,6 +92,7 @@ void MyRejectHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+3 -2
View File
@@ -51,7 +51,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -59,8 +59,9 @@ object_functions_t Object_Table[] = {
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
/* handle i-am to support binding to other devices */ /* handle i-am to support binding to other devices */
+2 -1
View File
@@ -51,7 +51,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -95,6 +95,7 @@ void MyRejectHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+3 -2
View File
@@ -50,7 +50,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -95,8 +95,9 @@ void MyRejectHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* Note: this applications doesn't need to handle who-is /* Note: this applications doesn't need to handle who-is
it is confusing for the user! */ it is confusing for the user! */
/* set the handler for all the services we don't implement /* set the handler for all the services we don't implement
It is required to send the proper reject message... */ It is required to send the proper reject message... */
+2 -1
View File
@@ -52,7 +52,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -175,6 +175,7 @@ void My_NPDU_Handler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -51,7 +51,7 @@
#include "dlenv.h" #include "dlenv.h"
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -139,6 +139,7 @@ static void LocalIAmHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+2 -1
View File
@@ -57,7 +57,7 @@
#endif #endif
/* All included BACnet objects */ /* All included BACnet objects */
object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
}; };
@@ -140,6 +140,7 @@ void MyWritePropertySimpleAckHandler(
static void Init_Service_Handlers( static void Init_Service_Handlers(
void) void)
{ {
Device_Initialize_Object_Functions(&Object_Table[0]);
Device_Init(); Device_Init();
/* we need to handle who-is /* we need to handle who-is
to support dynamic device binding to us */ to support dynamic device binding to us */
+52 -50
View File
@@ -100,8 +100,8 @@ typedef unsigned (
*object_iterate_function) ( *object_iterate_function) (
unsigned current_index); unsigned current_index);
/** Defines the group of object helper functions for any supported Object. /** Defines the group of object helper functions for any supported Object.
* @ingroup ObjHelpers * @ingroup ObjHelpers
* Each Object must provide some implementation of each of these helpers * Each Object must provide some implementation of each of these helpers
* in order to properly support the handlers. Eg, the ReadProperty handler * in order to properly support the handlers. Eg, the ReadProperty handler
* handler_read_property() relies on the instance of Object_Read_Property * handler_read_property() relies on the instance of Object_Read_Property
@@ -134,45 +134,45 @@ typedef struct object_functions {
typedef struct commonBacObj_s typedef struct commonBacObj_s
{ {
/** The BACnet type of this object (ie, what class is this object from?). /** The BACnet type of this object (ie, what class is this object from?).
* This property, of type BACnetObjectType, indicates membership in a * This property, of type BACnetObjectType, indicates membership in a
* particular object type class. Each inherited class will be of one type. * particular object type class. Each inherited class will be of one type.
*/ */
BACNET_OBJECT_TYPE mObject_Type; BACNET_OBJECT_TYPE mObject_Type;
/** The instance number for this class instance. */ /** The instance number for this class instance. */
uint32_t Object_Instance_Number; uint32_t Object_Instance_Number;
/** Object Name; must be unique. /** Object Name; must be unique.
* This property, of type CharacterString, shall represent a name for * This property, of type CharacterString, shall represent a name for
* the object that is unique within the BACnet Device that maintains it. * the object that is unique within the BACnet Device that maintains it.
*/ */
char Object_Name[MAX_DEV_NAME_LEN]; char Object_Name[MAX_DEV_NAME_LEN];
} COMMON_BAC_OBJECT; } COMMON_BAC_OBJECT;
/** Structure to define the Properties of Device Objects which distinguish /** Structure to define the Properties of Device Objects which distinguish
* one instance from another. * one instance from another.
* This structure only defines fields for properties that are unique to * This structure only defines fields for properties that are unique to
* a given Device object. The rest may be fixed in device.c or hard-coded * a given Device object. The rest may be fixed in device.c or hard-coded
* into the read-property encoding. * into the read-property encoding.
* This may be useful for implementations which manage multiple Devices, * This may be useful for implementations which manage multiple Devices,
* eg, a Gateway. * eg, a Gateway.
*/ */
typedef struct devObj_s typedef struct devObj_s
{ {
/** The BACnet Device Address for this device; ->len depends on DLL type. */ /** The BACnet Device Address for this device; ->len depends on DLL type. */
BACNET_ADDRESS bacDevAddr; BACNET_ADDRESS bacDevAddr;
/** Structure for the Object Properties common to all Objects. */
COMMON_BAC_OBJECT bacObj;
/** Device Description. */
char Description[MAX_DEV_DESC_LEN];
/** The upcounter that shows if the Device ID or object structure has changed. */ /** Structure for the Object Properties common to all Objects. */
uint32_t Database_Revision; COMMON_BAC_OBJECT bacObj;
/** Device Description. */
char Description[MAX_DEV_DESC_LEN];
/** The upcounter that shows if the Device ID or object structure has changed. */
uint32_t Database_Revision;
} DEVICE_OBJECT_DATA; } DEVICE_OBJECT_DATA;
@@ -182,6 +182,8 @@ extern "C" {
void Device_Init( void Device_Init(
void); void);
void Device_Initialize_Object_Functions(
object_functions_t *object_table);
bool Device_Reinitialize( bool Device_Reinitialize(
BACNET_REINITIALIZE_DEVICE_DATA * rd_data); BACNET_REINITIALIZE_DEVICE_DATA * rd_data);
@@ -309,31 +311,31 @@ extern "C" {
* in the build (lib/Makefile). * in the build (lib/Makefile).
*/ */
void Routing_Device_Init( void Routing_Device_Init(
uint32_t first_object_instance ); uint32_t first_object_instance );
uint16_t Add_Routed_Device( uint16_t Add_Routed_Device(
uint32_t Object_Instance, uint32_t Object_Instance,
const char * Object_Name, const char * Object_Name,
const char * Description ); const char * Description );
DEVICE_OBJECT_DATA * Get_Routed_Device_Object( DEVICE_OBJECT_DATA * Get_Routed_Device_Object(
int idx ); int idx );
BACNET_ADDRESS * Get_Routed_Device_Address( BACNET_ADDRESS * Get_Routed_Device_Address(
int idx ); int idx );
void routed_get_my_address( void routed_get_my_address(
BACNET_ADDRESS * my_address); BACNET_ADDRESS * my_address);
bool Routed_Device_Address_Lookup( bool Routed_Device_Address_Lookup(
int idx, int idx,
uint8_t address_len, uint8_t address_len,
uint8_t * mac_adress ); uint8_t * mac_adress );
bool Routed_Device_GetNext( bool Routed_Device_GetNext(
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
int * DNET_list, int * DNET_list,
int * cursor ); int * cursor );
bool Routed_Device_Is_Valid_Network( bool Routed_Device_Is_Valid_Network(
uint16_t dest_net, uint16_t dest_net,
int * DNET_list ); int * DNET_list );
uint32_t Routed_Device_Index_To_Instance( uint32_t Routed_Device_Index_To_Instance(
unsigned index); unsigned index);
@@ -356,7 +358,7 @@ extern "C" {
void); void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */