Added --version and --help command line options to some demo applications.

This commit is contained in:
skarg
2014-08-15 13:21:20 +00:00
parent ccad9165c5
commit e7d04a2379
8 changed files with 517 additions and 280 deletions
+43 -15
View File
@@ -39,6 +39,7 @@
#include "apdu.h"
#include "device.h"
#include "datalink.h"
#include "version.h"
/* some demo stuff needed */
#define DEBUG_ENABLED 0
#include "debug.h"
@@ -75,7 +76,7 @@ static void MyAbortHandler(
(void) src;
(void) invoke_id;
(void) server;
printf("BACnet Abort: %s\r\n", bactext_abort_reason_name(abort_reason));
printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason));
Error_Detected = true;
}
@@ -87,7 +88,7 @@ static void MyRejectHandler(
/* FIXME: verify src and invoke id */
(void) src;
(void) invoke_id;
printf("BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason));
printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason));
Error_Detected = true;
}
@@ -232,6 +233,27 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
{
printf("Usage: %s address [DNET ID Len Info]\n", filename);
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
{
printf("Send BACnet Initialize-Routing-Table message to a network\n"
"and wait for responses. Displays their network information.\n"
"\n" "address:\n"
"MAC address in xx:xx:xx:xx:xx:xx format or IP x.x.x.x:port\n"
"DNET ID Len Info:\n" "Port-info data:\n" " DNET:\n"
" Destination network number 0-65534\n" " ID:\n"
" Port Identifier number 0-255\n" " Info:\n"
" Octet string of data, up to 255 octets\n"
"To query the complete routing table, do not include any port-info.\n"
"To query using Initialize-Routing-Table message to 192.168.0.18:\n"
"%s 192.168.0.18:47808\n", filename);
}
static void address_parse(
BACNET_ADDRESS * dst,
int argc,
@@ -287,24 +309,30 @@ int main(
time_t last_seconds = 0;
time_t current_seconds = 0;
time_t timeout_seconds = 0;
int argi = 0;
char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
if (strcmp(argv[argi], "--help") == 0) {
print_usage(filename);
print_help(filename);
exit(0);
}
if (strcmp(argv[argi], "--version") == 0) {
printf("%s %s\n", filename, BACNET_VERSION_TEXT);
printf("Copyright (C) 2014 by Steve Karg and others.\n"
"This is free software; see the source for copying conditions.\n"
"There is NO warranty; not even for MERCHANTABILITY or\n"
"FITNESS FOR A PARTICULAR PURPOSE.\n");
exit(0);
}
}
if (argc < 2) {
printf("Usage: %s address [DNET ID Len Info]\r\n",
filename_remove_path(argv[0]));
print_usage(filename);
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\n" "address:\r\n"
"MAC address in xx:xx:xx:xx:xx:xx format or IP x.x.x.x:port\r\n"
"DNET ID Len Info:\r\n" "Port-info data:\r\n" " DNET:\r\n"
" Destination network number 0-65534\r\n" " ID:\r\n"
" Port Identifier number 0-255\r\n" " Info:\r\n"
" Octet string of data, up to 255 octets\r\n"
"To query the complete routing table, do not include any port-info.\r\n"
"To query using Initialize-Routing-Table message to 192.168.0.18:\r\n"
"%s 192.168.0.18:47808\r\n", filename_remove_path(argv[0]));
return 0;
}
/* decode the command line parameters */