Added ability to send Local Broadcast UnconfirmedPrivateTransfer using 'dnet=n' argument in place of device-instance argument.

This commit is contained in:
skarg
2012-07-11 19:13:09 +00:00
parent 5244c2368a
commit 3e3298496a
+18 -6
View File
@@ -59,6 +59,7 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* converted command line arguments */ /* converted command line arguments */
static bool Target_Broadcast; static bool Target_Broadcast;
static uint16_t Target_DNET;
static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE;
static uint16_t Target_Vendor_Identifier = 260; static uint16_t Target_Vendor_Identifier = 260;
static uint32_t Target_Service_Number = 0; static uint32_t Target_Service_Number = 0;
@@ -151,7 +152,7 @@ int main(
0 0
}; /* address where message came from */ }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 10; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
time_t elapsed_seconds = 0; time_t elapsed_seconds = 0;
time_t last_seconds = 0; time_t last_seconds = 0;
@@ -171,8 +172,8 @@ int main(
if (argc < 6) { if (argc < 6) {
filename = filename_remove_path(argv[0]); filename = filename_remove_path(argv[0]);
printf("Usage: %s device-instance vendor-id service-number " printf("Usage: %s <device-instance|broadcast|dnet=> vendor-id"
"tag value [tag value...]\r\n", filename); " service-number tag value [tag value...]\r\n", filename);
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("device-instance:\r\n" printf("device-instance:\r\n"
"BACnet Device Object Instance number that you are\r\n" "BACnet Device Object Instance number that you are\r\n"
@@ -180,7 +181,8 @@ int main(
"to try and bind with the device using Who-Is and\r\n" "to try and bind with the device using Who-Is and\r\n"
"I-Am services. For example, if you were transferring to\r\n" "I-Am services. For example, if you were transferring to\r\n"
"Device Object 123, the device-instance would be 123.\r\n" "Device Object 123, the device-instance would be 123.\r\n"
"For Broadcast, use the word broadcast.\r\n" "For Global Broadcast, use the word 'broadcast'.\r\n"
"For Local Broadcast to a particular DNET n, use 'dnet=n'.\r\n"
"\r\n" "vendor_id:\r\n" "\r\n" "vendor_id:\r\n"
"the unique vendor identification code for the type of\r\n" "the unique vendor identification code for the type of\r\n"
"vendor proprietary service to be performed.\r\n" "\r\n" "vendor proprietary service to be performed.\r\n" "\r\n"
@@ -210,6 +212,10 @@ int main(
/* decode the command line parameters */ /* decode the command line parameters */
if (strcmp(argv[1], "broadcast") == 0) { if (strcmp(argv[1], "broadcast") == 0) {
Target_Broadcast = true; Target_Broadcast = true;
Target_DNET = BACNET_BROADCAST_NETWORK;
} else if (strncmp(argv[1],"dnet=",5) == 0) {
Target_Broadcast = true;
Target_DNET = strtol(&argv[1][5], NULL, 0);
} else { } else {
Target_Device_Object_Instance = strtol(argv[1], NULL, 0); Target_Device_Object_Instance = strtol(argv[1], NULL, 0);
} }
@@ -281,6 +287,7 @@ int main(
last_seconds = time(NULL); last_seconds = time(NULL);
if (Target_Broadcast) { if (Target_Broadcast) {
datalink_get_broadcast_address(&Target_Address); datalink_get_broadcast_address(&Target_Address);
Target_Address.net = Target_DNET;
found = true; found = true;
timeout_seconds = 0; timeout_seconds = 0;
} else { } else {
@@ -324,8 +331,13 @@ int main(
private_data.serviceNumber = Target_Service_Number; private_data.serviceNumber = Target_Service_Number;
Send_UnconfirmedPrivateTransfer(&Target_Address, Send_UnconfirmedPrivateTransfer(&Target_Address,
&private_data); &private_data);
printf("Sent PrivateTransfer. Waiting %u seconds.\r\n", printf("Sent PrivateTransfer.");
(unsigned) (timeout_seconds - elapsed_seconds)); if (timeout_seconds) {
printf(" Waiting %u seconds.\r\n",
(unsigned) (timeout_seconds - elapsed_seconds));
} else {
printf("\r\n");
}
sent_message = true; sent_message = true;
} else { } else {
if (elapsed_seconds > timeout_seconds) { if (elapsed_seconds > timeout_seconds) {