Adding Init Routing Table message client.

This commit is contained in:
skarg
2008-08-23 11:40:14 +00:00
parent e75eaf0973
commit 2b38e1ec77
3 changed files with 51 additions and 93 deletions
+6 -6
View File
@@ -141,11 +141,11 @@ void Send_I_Am_Router_To_Network(
/* */ /* */
void Send_Initialize_Routing_Table( void Send_Initialize_Routing_Table(
BACNET_ROUTER_PORT *router_port_list) BACNET_ADDRESS *dst,
BACNET_ROUTER_PORT *router_port_list)
{ {
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
uint8_t number_of_ports = 0; uint8_t number_of_ports = 0;
@@ -179,11 +179,11 @@ void Send_Initialize_Routing_Table(
router_port = router_port->next; router_port = router_port->next;
} }
} }
/* Init Routing Table shall always be transmitted with #if PRINT_ENABLED
a broadcast MAC address. */ fprintf(stderr, "Send Initialize-Routing-Table message\n");
datalink_get_broadcast_address(&dest); #endif
bytes_sent = bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(dst, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
+42 -86
View File
@@ -50,6 +50,9 @@
/* buffer used for receive */ /* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* target address */
static BACNET_ADDRESS Target_Router_Address;
static BACNET_ROUTER_PORT *Target_Router_Port_List;
static bool Error_Detected = false; static bool Error_Detected = false;
@@ -175,7 +178,7 @@ static void Init_DataLink(
if (bbmd_address) { if (bbmd_address) {
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("NPDU: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd(bbmd_address, bbmd_port, bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
@@ -186,129 +189,82 @@ static void Init_DataLink(
static void address_parse(BACNET_ADDRESS *dst, int argc, char *argv[]) static void address_parse(BACNET_ADDRESS *dst, int argc, char *argv[])
{ {
long device_id = 0;
int dnet = 0;
int max_apdu = 0;
unsigned mac[6]; unsigned mac[6];
unsigned port;
int count = 0; int count = 0;
int index = 0; int index = 0;
if (argc > 0) { if (argc > 0) {
count = count =
sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], sscanf(argv[0], "%u.%u.%u.%u:%u", &mac[0],
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); &mac[1], &mac[2], &mac[3], &port);
dst->mac_len = count; if (count == 5) {
for (index = 0; index < MAX_MAC_LEN; index++) { dst->mac_len = 6;
if (index < count) { for (index = 0; index < 4; index++) {
dst->mac[index] = mac[index]; dst->mac[index] = mac[index];
} else {
dst->mac[index] = 0;
} }
} encode_unsigned16(&dst->mac[4], port);
} } else {
if (argc > 1) { count =
count = sscanf(argv[1], "%d", &dnet); sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0],
dst->net = dnet;
}
if (dnet) {
if (argc > 2) {
count =
sscanf(argv[2], "%x:%x:%x:%x:%x:%x", &mac[0],
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
dst->len = count; dst->mac_len = count;
for (index = 0; index < MAX_MAC_LEN; index++) { for (index = 0; index < MAX_MAC_LEN; index++) {
if (index < count) { if (index < count) {
dst->adr[index] = mac[index]; dst->mac[index] = mac[index];
} else { } else {
dst->adr[index] = 0; dst->mac[index] = 0;
} }
} }
} else {
fprintf(stderr,"A non-zero DNET requires a DADR.\r\n");
}
} else {
src.len = 0;
for (index = 0; index < MAX_MAC_LEN; index++) {
src.adr[index] = 0;
} }
} }
dst->net = 0;
dst->len = 0;
for (index = 0; index < MAX_MAC_LEN; index++) {
dst->adr[index] = 0;
}
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
BACNET_ADDRESS src = {
0}; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */
time_t total_seconds = 0;
time_t elapsed_seconds = 0;
time_t last_seconds = 0;
time_t current_seconds = 0;
time_t timeout_seconds = 0;
if (argc < 2) { if (argc < 2) {
printf("Usage: %s number-of-ports\r\n", printf("Usage: %s address number-of-ports [DNET ID Len Info]\r\n",
filename_remove_path(argv[0])); filename_remove_path(argv[0]));
return 0; return 0;
} }
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("Send BACnet Initialize-Routing-Table message to a network\r\n" printf("Send BACnet Initialize-Routing-Table message to a network\r\n"
"and wait for responses. Displays their network information.\r\n" "and wait for responses. Displays their network information.\r\n"
"\r\nDNET:\r\n" "\r\n"
"BACnet destination network number 0-65534\r\n" "address:\r\n"
"To send a Who-Is-Router-To-Network request to DNET 86:\r\n" "MAC address in xx:xx:xx:xx:xx:xx format or IP x.x.x.x:port\r\n"
"%s 86\r\n" "number-of-ports:\r\n"
"To send a Who-Is-Router-To-Network request to all devices\r\n" "Number of ports to update along with port-info data\r\n"
"use the following command:\r\n" "To query the complete routing table, use 0.\r\n"
"%s -1\r\n", "To query using Initialize-Routing-Table message to 192.168.0.18:\r\n"
filename_remove_path(argv[0]), "%s 192.168.0.18:47808 0\r\n",
filename_remove_path(argv[0])); filename_remove_path(argv[0]));
return 0; return 0;
} }
/* decode the command line parameters */ /* decode the command line parameters */
if (argc > 1) { address_parse(&Target_Router_Address, argc-1, &argv[1]);
Target_Router_Network = strtol(argv[1], NULL, 0); if (argc > 2) {
if (Target_Router_Network >= 65535) { /* FIXME: add port info parse */
fprintf(stderr, /* BACNET_ROUTER_PORT *router_port_list
"DNET=%u - it must be less than %u\r\n", Target_Router_Port_List
Target_Router_Network, 65535); ports_parse(&router_port[0], argc-2, &argv[2]);
return 1; Target_Router_Port_List = router_port[0];
} */
} }
/* setup my info */ /* setup my info */
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
Init_Service_Handlers(); Init_Service_Handlers();
address_init(); address_init();
Init_DataLink(); Init_DataLink();
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = apdu_timeout() / 1000;
/* send the request */ /* send the request */
Send_Who_Is_Router_To_Network(Target_Router_Network); Send_Initialize_Routing_Table(
/* loop forever */ &Target_Router_Address,
for (;;) { Target_Router_Port_List);
/* increment timer - exit if timed out */
current_seconds = time(NULL);
/* returns 0 bytes on timeout */
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
/* process */
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
}
if (Error_Detected)
break;
/* increment timer - exit if timed out */
elapsed_seconds = current_seconds - last_seconds;
if (elapsed_seconds) {
#if defined(BACDL_BIP) && BBMD_ENABLED
bvlc_maintenance_timer(elapsed_seconds);
#endif
}
total_seconds += elapsed_seconds;
if (total_seconds > timeout_seconds)
break;
/* keep track of time for next check */
last_seconds = current_seconds;
}
return 0; return 0;
} }
+3 -1
View File
@@ -30,6 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include "bacdef.h" #include "bacdef.h"
#include "apdu.h" #include "apdu.h"
#include "npdu.h"
#include "bacapp.h" #include "bacapp.h"
#include "bacenum.h" #include "bacenum.h"
@@ -114,7 +115,8 @@ extern "C" {
void Send_I_Am_Router_To_Network( void Send_I_Am_Router_To_Network(
const int DNET_list[]); const int DNET_list[]);
void Send_Initialize_Routing_Table( void Send_Initialize_Routing_Table(
BACNET_ROUTER_PORT *router_port_list); BACNET_ADDRESS *dst,
BACNET_ROUTER_PORT *router_port_list);
void Send_Initialize_Routing_Table_Ack( void Send_Initialize_Routing_Table_Ack(
BACNET_ROUTER_PORT *router_port_list); BACNET_ROUTER_PORT *router_port_list);