Followed Steve's good recommendation, and made routed_get_my_address() be a variant of datalink_get_my_address() just when routing is in use. Haven't done anything about the sending functions yet.

Renamed Lookup_Routed_Device_Address() as Routed_Device_Address_Lookup(), and replaced it in the routed npdu handler with a function that finds the "next" gateway or routed device, as per the destination address.  (Less tied to the specifics of the gw_device.c implementation.)
Fixed a few build warnings (eg, %zu for size_t arguments).
Until we improve the makefile system, I've enabled BAC_ROUTING in config.h
This commit is contained in:
tbrennan3
2010-11-24 20:44:32 +00:00
parent db5dea31e7
commit 22c14fccad
37 changed files with 131 additions and 151 deletions
-4
View File
@@ -69,11 +69,7 @@ void handler_alarm_ack(
BACNET_ADDRESS my_address;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
+1 -5
View File
@@ -118,11 +118,7 @@ void handler_atomic_read_file(
fprintf(stderr, "Received Atomic-Read-File Request!\n");
#endif
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
@@ -174,7 +170,7 @@ void handler_atomic_read_file(
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "Too Big To Send (%d >= %d). Sending Abort!\n",
fprintf(stderr, "Too Big To Send (%d >= %zu). Sending Abort!\n",
data.type.stream.requestedOctetCount,
octetstring_capacity(&data.fileData));
#endif
+1 -5
View File
@@ -96,11 +96,7 @@ void handler_atomic_write_file(
fprintf(stderr, "Received AtomicWriteFile Request!\n");
#endif
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
@@ -132,7 +128,7 @@ void handler_atomic_write_file(
} else if (data.access == FILE_STREAM_ACCESS) {
if (bacfile_write_stream_data(&data)) {
#if PRINT_ENABLED
fprintf(stderr, "AWF: Stream offset %d, %d bytes\n",
fprintf(stderr, "AWF: Stream offset %d, %zu bytes\n",
data.type.stream.fileStartPosition,
octetstring_length(&data.fileData));
#endif
-8
View File
@@ -326,11 +326,7 @@ static bool cov_send_request(
#if PRINT_ENABLED
fprintf(stderr, "COVnotification: requested\n");
#endif
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &cov_subscription->dest,
@@ -528,11 +524,7 @@ void handler_cov_subscribe(
/* initialize a common abort code */
cov_data.error_code = ABORT_REASON_SEGMENTATION_NOT_SUPPORTED;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -103,11 +103,7 @@ void handler_device_communication_control(
BACNET_ADDRESS my_address;
/* encode the NPDU portion of the reply packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -72,11 +72,7 @@ void handler_get_event_information(
int valid_event = 0;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -54,11 +54,7 @@ void handler_lso(
BACNET_ADDRESS my_address;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
+2
View File
@@ -46,6 +46,8 @@
* and passing the remaining bytes to the apdu_handler.
* @note The routing (except src) and NCPI information, including
* npdu_data->data_expecting_reply, are discarded.
* @see routing_npdu_handler
*
* @ingroup MISCHNDLR
*
* @param src [out] Returned with routing source information if the NPDU
-4
View File
@@ -231,11 +231,7 @@ void handler_conf_private_trans(
/* encode the NPDU portion of the response packet as it will be needed */
/* no matter what the outcome. */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -77,11 +77,7 @@ void handler_reinitialize_device(
BACNET_ADDRESS my_address;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
+9 -22
View File
@@ -197,30 +197,16 @@ static void routed_apdu_handler(
uint8_t * apdu,
uint16_t apdu_len)
{
int dnet = DNET_list[0]; /* Get the DNET of our virtual network */
int i;
int cursor = 0; /* Starting hint */
bool bGotOne = false;
/* First, see if it's for the main Gateway Device, either because
* there's no routing info or else its a BACnet broadcast.
*/
if ( (dest->net == 0 ) || (dest->net == BACNET_BROADCAST_NETWORK)) {
/* Handle like a normal, non-routed access of the Gateway Device.
* But first, make sure our internal access is pointing at
* that Device in our table by telling it "no routing info" : */
Lookup_Routed_Device_Address( 0, 0, NULL );
apdu_handler(src, apdu, apdu_len);
while ( Routed_Device_GetNext( dest, DNET_list, &cursor ) ) {
apdu_handler(src, apdu, apdu_len);
bGotOne = true;
if ( cursor < 0 ) /* If no more matches, */
break; /* We don't need to keep looking */
}
/* Now check for our virtual DNET or BACnet broadcast, and check
* against each of our virtually routed Devices.
* If we get a match, have it handle the APDU.
* For broadcasts, all Devices get a chance at it.
*/
if ((dest->net == dnet) || (dest->net == BACNET_BROADCAST_NETWORK)) {
for ( i = 1; i < MAX_NUM_DEVICES; i++ ) {
if ( Lookup_Routed_Device_Address( i, dest->len, dest->adr ) )
apdu_handler(src, apdu, apdu_len);
}
} else if ( dest->net != 0 ) {
if ( !bGotOne ) {
/* We don't know how to reach this one */
Send_Reject_Message_To_Network( src, NETWORK_REJECT_NO_ROUTE, dest->net );
}
@@ -237,6 +223,7 @@ static void routed_apdu_handler(
* destination.
* - Errors in decoding.
* @note The npdu_data->data_expecting_reply status is discarded.
* @see npdu_handler
* @ingroup NMRC
*
* @param src [out] Returned with routing source information if the NPDU
-4
View File
@@ -83,11 +83,7 @@ void handler_read_property(
/* configure default error code as an abort since it is common */
rpdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -204,11 +204,7 @@ void handler_read_property_multiple(
/* jps_debug - see if we are utilizing all the buffer */
/* memset(&Handler_Transmit_Buffer[0], 0xff, sizeof(Handler_Transmit_Buffer)); */
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -104,11 +104,7 @@ void handler_read_range(
data.error_class = ERROR_CLASS_OBJECT;
data.error_code = ERROR_CODE_UNKNOWN_OBJECT;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -75,11 +75,7 @@ void handler_write_property(
BACNET_ADDRESS my_address;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -65,11 +65,7 @@ void handler_unrecognized_service(
(void) service_len;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
-4
View File
@@ -73,11 +73,7 @@ uint8_t Send_Alarm_Acknowledgement(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -79,11 +79,7 @@ uint8_t Send_Atomic_Read_File_Stream(
data.type.stream.fileStartPosition = fileStartPosition;
data.type.stream.requestedOctetCount = requestedOctetCount;
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -80,11 +80,7 @@ uint8_t Send_Atomic_Write_File_Stream(
status = octetstring_copy(&data.fileData, fileData);
if (status) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
-4
View File
@@ -70,11 +70,7 @@ uint8_t Send_CEvent_Notify(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -127,11 +127,7 @@ uint8_t Send_COV_Subscribe(
}
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -83,11 +83,7 @@ uint8_t Send_Device_Communication_Control_Request(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -141,11 +141,7 @@ int iam_unicast_encode_pdu(
memcpy(dest, src, sizeof(BACNET_ADDRESS));
dest->net = 0;
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
-4
View File
@@ -73,11 +73,7 @@ uint8_t Send_Life_Safety_Operation_Data(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -78,11 +78,7 @@ uint8_t Send_Private_Transfer_Request(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -80,11 +80,7 @@ uint8_t Send_Reinitialize_Device_Request(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -72,11 +72,7 @@ uint8_t Send_ReadRange_Request(
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -86,11 +86,7 @@ uint8_t Send_Read_Property_Request(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
-4
View File
@@ -81,11 +81,7 @@ uint8_t Send_Read_Property_Multiple_Request(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&pdu[0], &dest, &my_address, &npdu_data);
/* encode the APDU portion of the packet */
-4
View File
@@ -77,11 +77,7 @@ uint8_t Send_Write_Property_Request_Data(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
#if BAC_ROUTING
my_address = *Get_Routed_Device_Address(-1);
#else
datalink_get_my_address(&my_address);
#endif
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,