From 09ef609f431c70d0fa99617cf1b479cef9d3f5df Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Thu, 22 Apr 2004 15:56:59 +0000 Subject: [PATCH] Use epicsTime (instead of tsDefs); improved timestamp format and behaviour; fixed compiler warnings. --- src/catools/caget.c | 1 - src/catools/cainfo.c | 8 +-- src/catools/camonitor.c | 13 ++--- src/catools/tool_lib.c | 122 +++++++++++++++++++--------------------- src/catools/tool_lib.h | 17 +++++- 5 files changed, 80 insertions(+), 81 deletions(-) diff --git a/src/catools/caget.c b/src/catools/caget.c index 282284db6..6755355bb 100644 --- a/src/catools/caget.c +++ b/src/catools/caget.c @@ -21,7 +21,6 @@ #include #include -#include #include #include diff --git a/src/catools/cainfo.c b/src/catools/cainfo.c index f4a2f2706..81b85c9b1 100644 --- a/src/catools/cainfo.c +++ b/src/catools/cainfo.c @@ -18,10 +18,7 @@ #include #include -#include -#include -#include #include #include @@ -45,10 +42,9 @@ void usage (void) /*+************************************************************************** * - * Function: caget + * Function: cainfo * - * Description: Issue read requests, wait for incoming data - * and print the data according to the selected format + * Description: Print CA info data or call ca_client_status * * Arg(s) In: pvs - Pointer to an array of pv structures * nPvs - Number of elements in the pvs array diff --git a/src/catools/camonitor.c b/src/catools/camonitor.c index b0ec2766d..fc8244274 100644 --- a/src/catools/camonitor.c +++ b/src/catools/camonitor.c @@ -20,8 +20,6 @@ #include #include -#include -#include #include #include @@ -159,14 +157,13 @@ int camonitor (pv *pvs, int nPvs, unsigned long reqElems) pvs[n].status = ECA_DISCONN; } } - if (!nConn) return 1; /* No connection? We're done. */ + if (nConn) /* Wait for callbacks */ - /* ---------------- */ - while (1) - ca_pend_event(timeout); - - return 0; + /* ------------------ */ + while (1) ca_pend_event(timeout); + else + return 1; /* No connection? We're done. */ } diff --git a/src/catools/tool_lib.c b/src/catools/tool_lib.c index bf7259c13..3969bbad2 100644 --- a/src/catools/tool_lib.c +++ b/src/catools/tool_lib.c @@ -23,26 +23,28 @@ #define epicsAlarmGLOBAL #include #undef epicsAlarmGLOBAL -#include +#include #include #include "tool_lib.h" /* Time stamps for program start, previous value (used for relative resp. * incremental times with monitors) */ -static TS_STAMP tsStart, tsPrevious; +static epicsTimeStamp tsStart, tsPrevious; static int tsInit = 0; /* Flag: Timestamps init'd */ -static int firstStampPrinted = 0; /* Flag: First timestamp already printed */ -TimeT tsType = absolute; /* Timestamp type flag (-q or -Q option) */ +TimeT tsType = absolute; /* Timestamp type flag (-riI options) */ IntFormatT outType = dec; /* For -0.. output format option */ -char dblFormatStr[30] = "%g"; /* Format string to print doubles (see -e -f option) */ +char dblFormatStr[30] = "%g"; /* Format string to print doubles (-efg options) */ +char timeFormatStr[30] = "%Y-%m-%d %H:%M:%S.%06f"; /* Time format string */ int charAsNr = 0; /* used for -n option - get DBF_CHAR as number */ double timeout = 1.0; /* wait time default (see -w option) */ +#define TIMETEXTLEN 28 /* Length of timestamp text buffer */ + void sprint_long (char *ret, long val) @@ -164,10 +166,8 @@ char *val2str (const void *v, unsigned type, int index) #define FMT_TIME \ " Timestamp: %s" -#define ARGS_TIME(T) \ - tsStampToText( &(((struct T *)value)->stamp), \ - TS_TEXT_MMDDYY, \ - timeText) +#define ARGS_TIME(T) \ + timeText #define FMT_STS \ " Status: %s\n" \ @@ -177,13 +177,17 @@ char *val2str (const void *v, unsigned type, int index) stat_to_str(((struct T *)value)->status), \ sevr_to_str(((struct T *)value)->severity) +#define ARGS_STS_UNSIGNED(T) \ + stat_to_str_unsigned(((struct T *)value)->status), \ + sevr_to_str_unsigned(((struct T *)value)->severity) + #define FMT_ACK \ " Ack transient?: %s\n" \ " Ack severity: %s" -#define ARGS_ACK(T) \ - ((struct T *)value)->ackt ? "YES" : "NO", \ - sevr_to_str(((struct T *)value)->acks) +#define ARGS_ACK(T) \ + ((struct T *)value)->ackt ? "YES" : "NO", \ + sevr_to_str_unsigned(((struct T *)value)->acks) #define FMT_UNITS \ " Units: %s" @@ -229,9 +233,11 @@ char *val2str (const void *v, unsigned type, int index) FMT_STS, \ ARGS_STS(T)) -#define PRN_DBR_TIME(T) \ - sprintf(str, \ - FMT_TIME "\n" FMT_STS, \ +#define PRN_DBR_TIME(T) \ + epicsTimeToStrftime(timeText, TIMETEXTLEN, timeFormatStr, \ + &(((struct T *)value)->stamp)); \ + sprintf(str, \ + FMT_TIME "\n" FMT_STS, \ ARGS_TIME(T), ARGS_STS(T)) #define PRN_DBR_GR(T,F,FMT) \ @@ -257,7 +263,7 @@ char *val2str (const void *v, unsigned type, int index) #define PRN_DBR_STSACK(T) \ sprintf(str, \ FMT_STS "\n" FMT_ACK, \ - ARGS_STS(T), ARGS_ACK(T)) + ARGS_STS_UNSIGNED(T), ARGS_ACK(T)) #define PRN_DBR_X_ENUM(T) \ n = ((struct T *)value)->no_str; \ @@ -285,7 +291,7 @@ char *val2str (const void *v, unsigned type, int index) char *dbr2str (const void *value, unsigned type) { static char str[DBR_PRINT_BUFFER_SIZE]; - char timeText[28]; + char timeText[TIMETEXTLEN]; int n, i; switch (type) { @@ -346,14 +352,6 @@ char *dbr2str (const void *value, unsigned type) return str; } -/* tsDef.h: TsDiffAsDouble macro defined in 3.13 is no longer available in 3.14 */ -double tsDiffDbl(TS_STAMP *ts1, TS_STAMP * ts2) -{ - double tdiff; - tdiff = ( ((double) ts1->nsec) - ((double)ts2->nsec)) / 1000000000.; - tdiff += ((double) ts1->secPastEpoch) - ((double)ts2->secPastEpoch); - return tdiff; -} /*+************************************************************************** @@ -369,54 +367,42 @@ double tsDiffDbl(TS_STAMP *ts1, TS_STAMP * ts2) **************************************************************************-*/ #define PRN_TIME_VAL_STS(TYPE,TYPE_ENUM) \ - if (!tsInit) \ - { /* Initialize start timestamp */ \ - tsStart = tsPrevious = ((struct TYPE *)value)->stamp; \ - tsInit = 1; \ - } \ + printAbs = 0; \ \ switch (tsType) { \ case relative: \ - if (pv->firstStampPrinted) \ - { \ - printf("%10.4fs ", tsDiffDbl( &(((struct TYPE *)value)->stamp), \ - &tsStart) ); \ - } else { /* First stamp is always absolute */ \ - printf("%s ", tsStampToText(&(((struct TYPE *)value)->stamp), \ - TS_TEXT_MMDDYY, timeText)); \ - pv->firstStampPrinted = 1; \ - } \ + ptsRef = &tsStart; \ break; \ case incremental: \ - if (firstStampPrinted) \ - { \ - printf("%10.4fs ", tsDiffDbl( &(((struct TYPE *)value)->stamp), \ - &tsPrevious) ); \ - } else { /* First stamp is always absolute */ \ - printf("%s ", tsStampToText(&(((struct TYPE *)value)->stamp), \ - TS_TEXT_MMDDYY, timeText)); \ - firstStampPrinted = 1; \ - } \ + ptsRef = &tsPrevious; \ break; \ case incrementalByChan: \ - if (pv->firstStampPrinted) \ - { \ - printf("%10.4fs ", tsDiffDbl( &(((struct TYPE *)value)->stamp), \ - &pv->tsPrevious) ); \ - } else { /* First stamp is always absolute */ \ - printf("%s ", tsStampToText(&(((struct TYPE *)value)->stamp), \ - TS_TEXT_MMDDYY, timeText)); \ - pv->firstStampPrinted = 1; \ - } \ + ptsRef = &pv->tsPrevious; \ + break; \ + default : \ + printAbs = 1; \ + } \ + \ + if (pv->firstStampPrinted) \ + { \ + printf("%10.4fs ", epicsTimeDiffInSeconds( \ + &(((struct TYPE *)value)->stamp), ptsRef) ); \ + } else { /* First stamp is always absolute */ \ + printAbs = 1; \ + pv->firstStampPrinted = 1; \ + } \ + \ + if (tsType == incrementalByChan) \ pv->tsPrevious = ((struct TYPE *)value)->stamp; \ - break; \ - default : /* Absolute */ \ - printf("%s ", tsStampToText( &(((struct TYPE *)value)->stamp), \ - TS_TEXT_MMDDYY, timeText)); \ - break; \ + \ + if (printAbs) { \ + epicsTimeToStrftime(timeText, TIMETEXTLEN, timeFormatStr, \ + &(((struct TYPE *)value)->stamp)); \ + printf("%s ", timeText); \ } \ \ tsPrevious = ((struct TYPE *)value)->stamp; \ + \ /* Print Values */ \ for (i=0; ivalue; + epicsTimeStamp *ptsRef = &tsStart; + + if (!tsInit) /* Initialize start timestamp */ + { + epicsTimeGetCurrent(&tsStart); + tsPrevious = tsStart; + tsInit = 1; + } printf("%-30s ", pv->name); if (pv->status == ECA_DISCONN) diff --git a/src/catools/tool_lib.h b/src/catools/tool_lib.h index fb806923b..e3ec254f0 100644 --- a/src/catools/tool_lib.h +++ b/src/catools/tool_lib.h @@ -19,7 +19,7 @@ #ifndef INCLtool_libh #define INCLtool_libh -#include +#include /* Convert status and severity to strings */ #define stat_to_str(stat) \ @@ -30,6 +30,19 @@ ((stat) >= 0 && (stat) <= (signed)lastEpicsAlarmSev) ? \ epicsAlarmSeverityStrings[stat] : "??" +#define stat_to_str_unsigned(stat) \ + ((stat) <= lastEpicsAlarmCond) ? \ + epicsAlarmConditionStrings[stat] : "??" + +#define sevr_to_str_unsigned(stat) \ + ((stat) <= lastEpicsAlarmSev) ? \ + epicsAlarmSeverityStrings[stat] : "??" + +/* The different versions are necessary because stat and sevr are + * defined unsigned in CA's DBR_STSACK structure and signed in all the + * others. Some compilers generate warnings if you check an unsigned + * being >=0 */ + #define CA_PRIORITY 50 /* CA priority */ #define DEFAULT_TIMEOUT 1.0 /* Default CA timeout */ @@ -52,7 +65,7 @@ typedef struct unsigned long reqElems; int status; void* value; - TS_STAMP tsPrevious; + epicsTimeStamp tsPrevious; int firstStampPrinted; } pv;