From c5773eafb435b7241350e30889f88c3691d0dd2f Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Fri, 14 Nov 2008 13:03:25 +0000 Subject: [PATCH] Added -p option to specify CA priority. --- src/catools/caget.c | 14 ++++++++++++-- src/catools/cainfo.c | 14 ++++++++++++-- src/catools/camonitor.c | 14 ++++++++++++-- src/catools/caput.c | 14 ++++++++++++-- src/catools/tool_lib.c | 3 ++- src/catools/tool_lib.h | 4 ++-- 6 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/catools/caget.c b/src/catools/caget.c index 2a62a8ccf..ae9a333c0 100644 --- a/src/catools/caget.c +++ b/src/catools/caget.c @@ -52,6 +52,7 @@ void usage (void) "Channel Access options:\n" " -w : Wait time, specifies CA timeout, default is %f second(s)\n" " -c: Asynchronous get (use ca_get_callback and wait for completion)\n" + " -p : CA priority (0-%u, default 0=lowest)\n" "Format options:\n" " Default output format is \"name value\"\n" " -t: Terse mode - print only value, without name\n" @@ -87,7 +88,7 @@ void usage (void) " -0b: Print as binary number\n" "\nExample: caget -a -f8 my_channel another_channel\n" " (uses wide output format, doubles are printed as %%f with precision of 8)\n\n" - , DEFAULT_TIMEOUT); + , DEFAULT_TIMEOUT, CA_PRIORITY_MAX); } @@ -348,7 +349,7 @@ int main (int argc, char *argv[]) setvbuf(stdout,NULL,_IOLBF,BUFSIZ); /* Set stdout to line buffering */ - while ((opt = getopt(argc, argv, ":taicnhse:f:g:#:d:0:w:")) != -1) { + while ((opt = getopt(argc, argv, ":taicnhse:f:g:#:d:0:w:p:")) != -1) { switch (opt) { case 'h': /* Print usage */ usage(); @@ -402,6 +403,15 @@ int main (int argc, char *argv[]) count = 0; } break; + case 'p': /* CA priority */ + if (sscanf(optarg,"%u", &caPriority) != 1) + { + fprintf(stderr, "'%s' is not a valid CA priority " + "- ignored. ('caget -h' for help.)\n", optarg); + caPriority = DEFAULT_CA_PRIORITY; + } + if (caPriority > CA_PRIORITY_MAX) caPriority = CA_PRIORITY_MAX; + break; case 's': /* Select string dbr for floating type data */ floatAsString = 1; break; diff --git a/src/catools/cainfo.c b/src/catools/cainfo.c index 4a73ab83d..2a295145e 100644 --- a/src/catools/cainfo.c +++ b/src/catools/cainfo.c @@ -37,8 +37,9 @@ void usage (void) "Channel Access options:\n" " -w : Wait time, specifies CA timeout, default is %f second(s)\n" " -s : Call ca_client_status with the specified interest level\n" + " -p : CA priority (0-%u, default 0=lowest)\n" "\nExample: cainfo my_channel another_channel\n\n" - , DEFAULT_TIMEOUT); + , DEFAULT_TIMEOUT, CA_PRIORITY_MAX); } @@ -133,7 +134,7 @@ int main (int argc, char *argv[]) setvbuf(stdout,NULL,_IOLBF,BUFSIZ); /* Set stdout to line buffering */ - while ((opt = getopt(argc, argv, ":nhw:s:")) != -1) { + while ((opt = getopt(argc, argv, ":nhw:s:p:")) != -1) { switch (opt) { case 'h': /* Print usage */ usage(); @@ -154,6 +155,15 @@ int main (int argc, char *argv[]) statLevel = 0; } break; + case 'p': /* CA priority */ + if (sscanf(optarg,"%u", &caPriority) != 1) + { + fprintf(stderr, "'%s' is not a valid CA priority " + "- ignored. ('caget -h' for help.)\n", optarg); + caPriority = DEFAULT_CA_PRIORITY; + } + if (caPriority > CA_PRIORITY_MAX) caPriority = CA_PRIORITY_MAX; + break; case '?': fprintf(stderr, "Unrecognized option: '-%c'. ('caget -h' for help.)\n", diff --git a/src/catools/camonitor.c b/src/catools/camonitor.c index 04bf1e58c..844db9c25 100644 --- a/src/catools/camonitor.c +++ b/src/catools/camonitor.c @@ -44,6 +44,7 @@ void usage (void) " -w : Wait time, specifies CA timeout, default is %f second(s)\n" " -m : Specify CA event mask to use, with being any combination of\n" " 'v' (value), 'a' (alarm), 'l' (log). Default: va\n" + " -p : CA priority (0-%u, default 0=lowest)\n" "Timestamps:\n" " Default: Print absolute timestamps (as reported by CA server)\n" " -t : Specify timestamp source(s) and type, with containing\n" @@ -71,7 +72,7 @@ void usage (void) " -0b: Print as binary number\n" "\nExample: camonitor -f8 my_channel another_channel\n" " (doubles are printed as %%f with precision of 8)\n\n" - , DEFAULT_TIMEOUT); + , DEFAULT_TIMEOUT, CA_PRIORITY_MAX); } @@ -208,7 +209,7 @@ int main (int argc, char *argv[]) setvbuf(stdout,NULL,_IOLBF,BUFSIZ); /* Set stdout to line buffering */ - while ((opt = getopt(argc, argv, ":nhm:se:f:g:#:d:0:w:t:")) != -1) { + while ((opt = getopt(argc, argv, ":nhm:se:f:g:#:d:0:w:t:p:")) != -1) { switch (opt) { case 'h': /* Print usage */ usage(); @@ -252,6 +253,15 @@ int main (int argc, char *argv[]) reqElems = 0; } break; + case 'p': /* CA priority */ + if (sscanf(optarg,"%u", &caPriority) != 1) + { + fprintf(stderr, "'%s' is not a valid CA priority " + "- ignored. ('caget -h' for help.)\n", optarg); + caPriority = DEFAULT_CA_PRIORITY; + } + if (caPriority > CA_PRIORITY_MAX) caPriority = CA_PRIORITY_MAX; + break; case 'm': /* Select CA event mask */ eventMask = 0; { diff --git a/src/catools/caput.c b/src/catools/caput.c index da4d236a6..cf042466d 100644 --- a/src/catools/caput.c +++ b/src/catools/caput.c @@ -57,6 +57,7 @@ void usage (void) "Channel Access options:\n" " -w : Wait time, specifies CA timeout, default is %f second(s)\n" " -c: Asynchronous put (use ca_put_callback and wait for completion)\n" + " -p : CA priority (0-%u, default 0=lowest)\n" "Format options:\n" " -t: Terse mode - print only sucessfully written value, without name\n" " -l: Long mode \"name timestamp value stat sevr\" (read PVs as DBR_TIME_xxx)\n" @@ -69,7 +70,7 @@ void usage (void) " Value format: number of requested values, then list of values\n" "\nExample: caput my_channel 1.2\n" " (puts 1.2 to my_channel)\n\n" - , DEFAULT_TIMEOUT); + , DEFAULT_TIMEOUT, CA_PRIORITY_MAX); } @@ -252,7 +253,7 @@ int main (int argc, char *argv[]) setvbuf(stdout,NULL,_IOLBF,BUFSIZ); /* Set stdout to line buffering */ putenv("POSIXLY_CORRECT="); /* Behave correct on GNU getopt systems */ - while ((opt = getopt(argc, argv, ":cnlhats#:w:")) != -1) { + while ((opt = getopt(argc, argv, ":cnlhats#:w:p:")) != -1) { switch (opt) { case 'h': /* Print usage */ usage(); @@ -293,6 +294,15 @@ int main (int argc, char *argv[]) count = 0; } break; + case 'p': /* CA priority */ + if (sscanf(optarg,"%u", &caPriority) != 1) + { + fprintf(stderr, "'%s' is not a valid CA priority " + "- ignored. ('caget -h' for help.)\n", optarg); + caPriority = DEFAULT_CA_PRIORITY; + } + if (caPriority > CA_PRIORITY_MAX) caPriority = CA_PRIORITY_MAX; + break; case '?': fprintf(stderr, "Unrecognized option: '-%c'. ('caput -h' for help.)\n", diff --git a/src/catools/tool_lib.c b/src/catools/tool_lib.c index 1db0a5503..9b761729f 100644 --- a/src/catools/tool_lib.c +++ b/src/catools/tool_lib.c @@ -46,6 +46,7 @@ char timeFormatStr[30] = "%Y-%m-%d %H:%M:%S.%06f"; /* Time format string */ int enumAsNr = 0; /* used for -n option - get DBF_ENUM as number */ double caTimeout = 1.0; /* wait time default (see -w option) */ +capri caPriority = DEFAULT_CA_PRIORITY; /* CA Priority */ #define TIMETEXTLEN 28 /* Length of timestamp text buffer */ @@ -528,7 +529,7 @@ int create_pvs (pv* pvs, int nPvs, caCh *pCB) result = ca_create_channel (pvs[n].name, pCB, &pvs[n], - CA_PRIORITY, + caPriority, &pvs[n].chid); if (result != ECA_NORMAL) { fprintf(stderr, "CA error %s occurred while trying " diff --git a/src/catools/tool_lib.h b/src/catools/tool_lib.h index f811dfb2d..07c663bbd 100644 --- a/src/catools/tool_lib.h +++ b/src/catools/tool_lib.h @@ -44,7 +44,7 @@ * being >=0 */ -#define CA_PRIORITY 50 /* CA priority */ +#define DEFAULT_CA_PRIORITY 0 /* Default CA priority */ #define DEFAULT_TIMEOUT 1.0 /* Default CA timeout */ @@ -79,7 +79,7 @@ extern IntFormatT outType; /* Flag used for -0.. output format option */ extern int enumAsNr; /* Used for -n option (get DBF_ENUM as number) */ extern double caTimeout; /* Wait time default (see -w option) */ extern char dblFormatStr[]; /* Format string to print doubles (see -e -f option) */ - +extern capri caPriority; /* CA priority */ extern char *val2str (const void *v, unsigned type, int index); extern char *dbr2str (const void *value, unsigned type);