From 839344649e49452f195df14c680dabcd33361b62 Mon Sep 17 00:00:00 2001 From: hadaq Date: Mon, 4 Apr 2011 13:34:36 +0000 Subject: [PATCH] Default environment vars added. Sergey. --- ebctrl/ioc/ebctrlApp/src/errbitstat.c | 40 ++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/ebctrl/ioc/ebctrlApp/src/errbitstat.c b/ebctrl/ioc/ebctrlApp/src/errbitstat.c index 6294e02..d17d3fd 100644 --- a/ebctrl/ioc/ebctrlApp/src/errbitstat.c +++ b/ebctrl/ioc/ebctrlApp/src/errbitstat.c @@ -19,6 +19,8 @@ int errbitstatDebug; #define MAXERRS 11 +#define ERRBITLOG 0 +#define ERRBITWAIT 30 typedef struct TheErrMsgS { int bit; @@ -38,6 +40,42 @@ TheErrMsg errMsgs[] = { {26, "Ethernet error"}, {27, "Timing trigger error"} }; +static int env2int(char *envName) +{ + /* + * Convert Epics environment variable (ascii to int) + */ + int retVal = 0; + char *envVar; + + if(! strcmp(envName, "ERRBITLOG")){ + envVar = getenv(envName); + + if(envVar == NULL){ + retVal = ERRBITLOG; + + if(errbitstatDebug) + printf(" errbitstat.c: env var %s is not set! Default to %i\n", envName, retVal); + } + } + else if(! strcmp(envName, "ERRBITWAIT")){ + envVar = getenv(envName); + + if(envVar == NULL){ + retVal = ERRBITWAIT; + + if(errbitstatDebug) + printf(" errbitstat.c: env var %s is not set! Default to %i\n", envName, retVal); + } + } + else{ + if(errbitstatDebug) + printf(" errbitstat.c: env var %s is not known! Default to %i\n", envName, retVal); + } + + return retVal; +} + static void errbit2logger( const uint32_t errbit, const uint32_t errbitstat, int nrOfErrWord, const int subsys ) { int i, j; @@ -163,7 +201,7 @@ long errbitstat_proc( struct genSubRecord *pgsub ) * ERRBITLOG = 0/1 (log via syslog (off/on)) * ERRBITWAIT = wait time in seconds */ - if(atoi(getenv("ERRBITLOG")) && ((int)dT > atoi(getenv("ERRBITWAIT")))){ + if(env2int("ERRBITLOG") && ((int)dT > env2int("ERRBITWAIT"))){ errbit2logger(*out[i], *out[i+5], i, j); t0 = t; } -- 2.43.0