From a595bdb4b5d39c7dc1fee9e00c60b49be5cca6f2 Mon Sep 17 00:00:00 2001 From: tbrennan3 Date: Wed, 24 Nov 2010 22:04:02 +0000 Subject: [PATCH] Resolved more code where we didn't need to define separate BAC_ROUTING functionality, since the npdu_encode_pdu() will do the right thing if our source address is for the gateway (root device), because src->net and/or src->len will be 0. For the important Device_Object_Instance_Number(), will redirect to the Routed_Device_Object_Instance_Number() function if this is a routing build. This leaves only the Who-Is and Who-Has handlers to be dealt with. --- bacnet-stack/demo/handler/h_cov.c | 4 ---- bacnet-stack/demo/handler/h_whohas.c | 8 -------- bacnet-stack/demo/handler/s_cov.c | 9 ++------- bacnet-stack/demo/handler/s_iam.c | 17 +++-------------- bacnet-stack/demo/handler/s_ihave.c | 9 ++------- bacnet-stack/demo/handler/s_ts.c | 20 ++++---------------- bacnet-stack/demo/handler/s_uevent.c | 8 +------- bacnet-stack/demo/handler/s_upt.c | 10 ++-------- bacnet-stack/demo/handler/s_whohas.c | 20 ++++---------------- bacnet-stack/demo/handler/s_whois.c | 9 +-------- bacnet-stack/demo/object/device.c | 4 ++++ bacnet-stack/demo/object/gw_device.c | 12 +++++++----- 12 files changed, 30 insertions(+), 100 deletions(-) diff --git a/bacnet-stack/demo/handler/h_cov.c b/bacnet-stack/demo/handler/h_cov.c index c1eac71d..456e3f09 100644 --- a/bacnet-stack/demo/handler/h_cov.c +++ b/bacnet-stack/demo/handler/h_cov.c @@ -334,11 +334,7 @@ static bool cov_send_request( /* load the COV data structure for outgoing message */ cov_data.subscriberProcessIdentifier = cov_subscription->subscriberProcessIdentifier; -#if BAC_ROUTING - cov_data.initiatingDeviceIdentifier = Routed_Device_Object_Instance_Number(); -#else cov_data.initiatingDeviceIdentifier = Device_Object_Instance_Number(); -#endif cov_data.monitoredObjectIdentifier.type = cov_subscription->monitoredObjectIdentifier.type; cov_data.monitoredObjectIdentifier.instance = diff --git a/bacnet-stack/demo/handler/h_whohas.c b/bacnet-stack/demo/handler/h_whohas.c index 602e358f..5fadd8f9 100644 --- a/bacnet-stack/demo/handler/h_whohas.c +++ b/bacnet-stack/demo/handler/h_whohas.c @@ -83,11 +83,7 @@ void handler_who_has( Device_Valid_Object_Name(object_name, &object_type, &object_instance); if (found) -#if BAC_ROUTING - Send_I_Have(Routed_Device_Object_Instance_Number(), -#else Send_I_Have(Device_Object_Instance_Number(), -#endif (BACNET_OBJECT_TYPE) object_type, object_instance, object_name); } else { @@ -96,11 +92,7 @@ void handler_who_has( Device_Valid_Object_Id(data.object.identifier.type, data.object.identifier.instance); if (object_name) -#if BAC_ROUTING - Send_I_Have(Routed_Device_Object_Instance_Number(), -#else Send_I_Have(Device_Object_Instance_Number(), -#endif (BACNET_OBJECT_TYPE) data.object.identifier.type, data.object.identifier.instance, object_name); } diff --git a/bacnet-stack/demo/handler/s_cov.c b/bacnet-stack/demo/handler/s_cov.c index 4a7b01d0..0b60e6f3 100644 --- a/bacnet-stack/demo/handler/s_cov.c +++ b/bacnet-stack/demo/handler/s_cov.c @@ -52,20 +52,15 @@ int ucov_notify_encode_pdu( { int len = 0; int pdu_len = 0; -#if BAC_ROUTING BACNET_ADDRESS my_address; + datalink_get_my_address(&my_address); - my_address = *Get_Routed_Device_Address(-1); -#endif /* unconfirmed is a broadcast */ datalink_get_broadcast_address(dest); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data); -#else - pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data); -#endif + /* encode the APDU portion of the packet */ len = ucov_notify_encode_apdu(&buffer[pdu_len], cov_data); pdu_len += len; diff --git a/bacnet-stack/demo/handler/s_iam.c b/bacnet-stack/demo/handler/s_iam.c index bc29f5fe..149dede1 100644 --- a/bacnet-stack/demo/handler/s_iam.c +++ b/bacnet-stack/demo/handler/s_iam.c @@ -56,23 +56,16 @@ int iam_encode_pdu( { int len = 0; int pdu_len = 0; -#if BAC_ROUTING BACNET_ADDRESS my_address; + datalink_get_my_address(&my_address); - my_address = *Get_Routed_Device_Address(-1); -#endif datalink_get_broadcast_address(dest); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data); - /* encode the APDU portion of the packet */ - len = iam_encode_apdu(&buffer[pdu_len], Routed_Device_Object_Instance_Number(), -#else - pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data); + /* encode the APDU portion of the packet */ len = iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(), -#endif MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); pdu_len += len; @@ -146,12 +139,8 @@ int iam_unicast_encode_pdu( npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data); /* encode the APDU portion of the packet */ -#if BAC_ROUTING - apdu_len = iam_encode_apdu(&buffer[npdu_len], Routed_Device_Object_Instance_Number(), -#else apdu_len = iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(), -#endif - MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); + MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); pdu_len = npdu_len + apdu_len; return pdu_len; diff --git a/bacnet-stack/demo/handler/s_ihave.c b/bacnet-stack/demo/handler/s_ihave.c index 2253f10d..00ca896c 100644 --- a/bacnet-stack/demo/handler/s_ihave.c +++ b/bacnet-stack/demo/handler/s_ihave.c @@ -65,11 +65,9 @@ void Send_I_Have( int bytes_sent = 0; BACNET_I_HAVE_DATA data; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif + datalink_get_my_address(&my_address); /* if we are forbidden to send, don't send! */ if (!dcc_communication_enabled()) return; @@ -77,11 +75,8 @@ void Send_I_Have( datalink_get_broadcast_address(&dest); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data); -#else - pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data); -#endif + /* encode the APDU portion of the packet */ data.device_id.type = OBJECT_DEVICE; data.device_id.instance = device_id; diff --git a/bacnet-stack/demo/handler/s_ts.c b/bacnet-stack/demo/handler/s_ts.c index 8f7e06c1..ac1fb323 100644 --- a/bacnet-stack/demo/handler/s_ts.c +++ b/bacnet-stack/demo/handler/s_ts.c @@ -54,25 +54,19 @@ void Send_TimeSync( BACNET_ADDRESS dest; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif if (!dcc_communication_enabled()) return; /* we could use unicast or broadcast */ datalink_get_broadcast_address(&dest); + datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data); -#else - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data); -#endif + /* encode the APDU portion of the packet */ len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime); @@ -96,25 +90,19 @@ void Send_TimeSyncUTC( BACNET_ADDRESS dest; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif if (!dcc_communication_enabled()) return; /* we could use unicast or broadcast */ datalink_get_broadcast_address(&dest); + datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data); -#else - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data); -#endif + /* encode the APDU portion of the packet */ pdu_len = timesync_utc_encode_apdu(&Handler_Transmit_Buffer[0], bdate, btime); diff --git a/bacnet-stack/demo/handler/s_uevent.c b/bacnet-stack/demo/handler/s_uevent.c index 669e8e96..9ec00a66 100644 --- a/bacnet-stack/demo/handler/s_uevent.c +++ b/bacnet-stack/demo/handler/s_uevent.c @@ -49,18 +49,12 @@ int Send_UEvent_Notify( int pdu_len = 0; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif + datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(buffer, dest, &my_address, &npdu_data); -#else - pdu_len = npdu_encode_pdu(buffer, dest, NULL, &npdu_data); -#endif /* encode the APDU portion of the packet */ len = uevent_notify_encode_apdu(&buffer[pdu_len], data); pdu_len += len; diff --git a/bacnet-stack/demo/handler/s_upt.c b/bacnet-stack/demo/handler/s_upt.c index 21f8e014..b16967d9 100644 --- a/bacnet-stack/demo/handler/s_upt.c +++ b/bacnet-stack/demo/handler/s_upt.c @@ -53,22 +53,16 @@ void Send_UnconfirmedPrivateTransfer( int pdu_len = 0; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif - if (!dcc_communication_enabled()) return; + datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, &npdu_data); -#else - pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, NULL, &npdu_data); -#endif + /* encode the APDU portion of the packet */ len = uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], diff --git a/bacnet-stack/demo/handler/s_whohas.c b/bacnet-stack/demo/handler/s_whohas.c index 5417c354..05a2569a 100644 --- a/bacnet-stack/demo/handler/s_whohas.c +++ b/bacnet-stack/demo/handler/s_whohas.c @@ -66,25 +66,19 @@ void Send_WhoHas_Name( int bytes_sent = 0; BACNET_WHO_HAS_DATA data; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif /* if we are forbidden to send, don't send! */ if (!dcc_communication_enabled()) return; /* Who-Has is a global broadcast */ datalink_get_broadcast_address(&dest); + datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data); -#else - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data); -#endif + /* encode the APDU portion of the packet */ data.low_limit = low_limit; data.high_limit = high_limit; @@ -126,25 +120,19 @@ void Send_WhoHas_Object( int bytes_sent = 0; BACNET_WHO_HAS_DATA data; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif /* if we are forbidden to send, don't send! */ if (!dcc_communication_enabled()) return; /* Who-Has is a global broadcast */ datalink_get_broadcast_address(&dest); + datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data); -#else - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data); -#endif + /* encode the APDU portion of the packet */ data.low_limit = low_limit; data.high_limit = high_limit; diff --git a/bacnet-stack/demo/handler/s_whois.c b/bacnet-stack/demo/handler/s_whois.c index 403361e0..7de51436 100644 --- a/bacnet-stack/demo/handler/s_whois.c +++ b/bacnet-stack/demo/handler/s_whois.c @@ -65,21 +65,14 @@ void Send_WhoIs_To_Network( int pdu_len = 0; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; -#if BAC_ROUTING BACNET_ADDRESS my_address; - my_address = *Get_Routed_Device_Address(-1); -#endif + datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); -#if BAC_ROUTING pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, &my_address, &npdu_data); -#else - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, NULL, &npdu_data); -#endif /* encode the APDU portion of the packet */ len = whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit, diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index 1c1242c4..2a2094df 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -353,7 +353,11 @@ uint32_t Device_Index_To_Instance( uint32_t Device_Object_Instance_Number( void) { +#if BAC_ROUTING + return Routed_Device_Object_Instance_Number(); +#else return Object_Instance_Number; +#endif } bool Device_Set_Object_Instance_Number( diff --git a/bacnet-stack/demo/object/gw_device.c b/bacnet-stack/demo/object/gw_device.c index cb37bb4c..f85ec4f1 100644 --- a/bacnet-stack/demo/object/gw_device.c +++ b/bacnet-stack/demo/object/gw_device.c @@ -175,6 +175,8 @@ BACNET_ADDRESS * Get_Routed_Device_Address( return NULL; } + + /** Get the currently active BACnet address. * This is an implementation of the datalink_get_my_address() template for * devices with routing. @@ -459,11 +461,11 @@ bool Routed_Device_Write_Property_Local( /* methods to manipulate the data */ -/** Return the Object Instance number for our (single) Device Object. - * This is a key function, widely invoked by the handler code, since - * it provides "our" (ie, local) address. - * @ingroup ObjIntf - * @return The Instance number used in the BACNET_OBJECT_ID for the Device. +/** Return the Object Instance number for the currently active Device Object. + * This is an overload of the important, widely used + * Device_Object_Instance_Number() function. + * + * @return The Instance number of the currently active Device. */ uint32_t Routed_Device_Object_Instance_Number( void)