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
+53 -32
View File
@@ -48,6 +48,7 @@
#include "whois.h"
#include "rp.h"
#include "proplist.h"
#include "version.h"
/* some demo stuff needed */
#include "filename.h"
#include "handlers.h"
@@ -999,32 +1000,34 @@ EPICS_STATES ProcessRPMData(
return nextState;
}
void PrintUsage(
)
static void print_usage(char *filename)
{
printf
("bacepics -- Generates Full EPICS file, including Object and Property List \n");
printf("Usage: \n");
printf
(" bacepics [-v] [-d] [-p sport] [-t target_mac [-n dnet]] device-instance \n");
printf(" -v: show values instead of '?' \n");
printf(" -d: show only device object properties\n");
printf
(" -p: Use sport for \"my\" port, instead of 0xBAC0 (BACnet/IP only) \n");
printf(" Allows you to communicate with a localhost target. \n");
printf
(" -t: declare target's MAC instead of using Who-Is to bind to \n");
printf
(" device-instance. Format is \"C0:A8:00:18:BA:C0\" (as usual) \n");
printf(" Use \"7F:00:00:01:BA:C0\" for loopback testing \n");
printf(" -n: specify target's DNET if not local BACnet network \n");
printf(" or on routed Virtual Network \n");
printf("Usage: %s [-v] [-d] [-p sport] [-t target_mac [-n dnet]]"
" device-instance\n", filename);
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
{
printf("Generates Full EPICS file, including Object and Property List\n");
printf("device-instance:\n"
"BACnet Device Object Instance number that you are\n"
"trying to communicate to. This number will be used\n"
"to try and bind with the device using Who-Is and\n"
"I-Am services.\n");
printf("\n");
printf
("You can redirect the output to a .tpi file for VTS use,\n");
printf(" eg, bacepics -v 2701876 > epics-2701876.tpi \n");
printf("-v: show values instead of '?' \n");
printf("-d: show only device object properties\n");
printf("-p: Use sport for \"my\" port. 0xBAC0 is default.\n");
printf(" Allows you to communicate with a localhost target.\n");
printf("-t: declare target's MAC instead of using Who-Is to bind to \n");
printf(" device-instance. Format is \"C0:A8:00:18:BA:C0\"\n");
printf(" Use \"7F:00:00:01:BA:C0\" for loopback testing \n");
printf("-n: specify target's DNET if not local BACnet network \n");
printf(" or on routed Virtual Network \n");
printf("\n");
exit(0);
printf("You can redirect the output to a .tpi file for VTS use,\n");
printf("e.g., bacepics 2701876 > epics-2701876.tpi \n");
}
int CheckCommandLineArgs(
@@ -1033,12 +1036,28 @@ int CheckCommandLineArgs(
{
int i;
bool bFoundTarget = false;
/* FIXME: handle multi homed systems - use an argument passed to the datalink_init() */
int argi = 0;
char *filename = NULL;
/* print help if not enough arguments */
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) {
fprintf(stdout, "Error: Must provide a device-instance \n\n");
PrintUsage(); /* Will exit */
print_usage(filename);
exit(0);
}
for (i = 1; i < argc; i++) {
char *anArg = argv[i];
@@ -1094,12 +1113,13 @@ int CheckCommandLineArgs(
} else
printf("ERROR: invalid Target MAC %s \n",
argv[i]);
/* And fall through to PrintUsage */
/* And fall through to print_usage */
}
/* Either break or fall through, as above */
/* break; */
default:
PrintUsage();
print_usage(filename);
exit(0);
break;
}
} else {
@@ -1109,20 +1129,21 @@ int CheckCommandLineArgs(
fprintf(stdout,
"Error: device-instance=%u - it must be less than %u\n",
Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1);
PrintUsage();
print_usage(filename);
exit(0);
}
bFoundTarget = true;
}
}
if (!bFoundTarget) {
fprintf(stdout, "Error: Must provide a device-instance \n\n");
PrintUsage(); /* Will exit */
print_usage(filename);
exit(0);
}
return 0; /* All OK if we reach here */
}
void PrintHeading(
)
{