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(
BACNET_ROUTER_PORT *router_port_list)
BACNET_ADDRESS *dst,
BACNET_ROUTER_PORT *router_port_list)
{
int len = 0;
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
uint8_t number_of_ports = 0;
@@ -179,11 +179,11 @@ void Send_Initialize_Routing_Table(
router_port = router_port->next;
}
}
/* Init Routing Table shall always be transmitted with
a broadcast MAC address. */
datalink_get_broadcast_address(&dest);
#if PRINT_ENABLED
fprintf(stderr, "Send Initialize-Routing-Table message\n");
#endif
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
datalink_send_pdu(dst, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
+42 -86
View File
@@ -50,6 +50,9 @@
/* buffer used for receive */
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;
@@ -175,7 +178,7 @@ static void Init_DataLink(
if (bbmd_address) {
struct in_addr addr;
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);
bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_timetolive_seconds);
@@ -186,129 +189,82 @@ static void Init_DataLink(
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 port;
int count = 0;
int index = 0;
if (argc > 0) {
count =
sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0],
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
dst->mac_len = count;
for (index = 0; index < MAX_MAC_LEN; index++) {
if (index < count) {
sscanf(argv[0], "%u.%u.%u.%u:%u", &mac[0],
&mac[1], &mac[2], &mac[3], &port);
if (count == 5) {
dst->mac_len = 6;
for (index = 0; index < 4; index++) {
dst->mac[index] = mac[index];
} else {
dst->mac[index] = 0;
}
}
}
if (argc > 1) {
count = sscanf(argv[1], "%d", &dnet);
dst->net = dnet;
}
if (dnet) {
if (argc > 2) {
count =
sscanf(argv[2], "%x:%x:%x:%x:%x:%x", &mac[0],
encode_unsigned16(&dst->mac[4], port);
} else {
count =
sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0],
&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++) {
if (index < count) {
dst->adr[index] = mac[index];
dst->mac[index] = mac[index];
} 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[]) {
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) {
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]));
return 0;
}
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("Send BACnet Initialize-Routing-Table message to a network\r\n"
"and wait for responses. Displays their network information.\r\n"
"\r\nDNET:\r\n"
"BACnet destination network number 0-65534\r\n"
"To send a Who-Is-Router-To-Network request to DNET 86:\r\n"
"%s 86\r\n"
"To send a Who-Is-Router-To-Network request to all devices\r\n"
"use the following command:\r\n"
"%s -1\r\n",
filename_remove_path(argv[0]),
"\r\n"
"address:\r\n"
"MAC address in xx:xx:xx:xx:xx:xx format or IP x.x.x.x:port\r\n"
"number-of-ports:\r\n"
"Number of ports to update along with port-info data\r\n"
"To query the complete routing table, use 0.\r\n"
"To query using Initialize-Routing-Table message to 192.168.0.18:\r\n"
"%s 192.168.0.18:47808 0\r\n",
filename_remove_path(argv[0]));
return 0;
}
/* decode the command line parameters */
if (argc > 1) {
Target_Router_Network = strtol(argv[1], NULL, 0);
if (Target_Router_Network >= 65535) {
fprintf(stderr,
"DNET=%u - it must be less than %u\r\n",
Target_Router_Network, 65535);
return 1;
}
address_parse(&Target_Router_Address, argc-1, &argv[1]);
if (argc > 2) {
/* FIXME: add port info parse */
/* BACNET_ROUTER_PORT *router_port_list
Target_Router_Port_List
ports_parse(&router_port[0], argc-2, &argv[2]);
Target_Router_Port_List = router_port[0];
*/
}
/* setup my info */
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
Init_Service_Handlers();
address_init();
Init_DataLink();
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = apdu_timeout() / 1000;
/* send the request */
Send_Who_Is_Router_To_Network(Target_Router_Network);
/* loop forever */
for (;;) {
/* 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;
}
Send_Initialize_Routing_Table(
&Target_Router_Address,
Target_Router_Port_List);
return 0;
}
+3 -1
View File
@@ -30,6 +30,7 @@
#include <stdio.h>
#include "bacdef.h"
#include "apdu.h"
#include "npdu.h"
#include "bacapp.h"
#include "bacenum.h"
@@ -114,7 +115,8 @@ extern "C" {
void Send_I_Am_Router_To_Network(
const int DNET_list[]);
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(
BACNET_ROUTER_PORT *router_port_list);