diff --git a/src/std/dev/Makefile b/src/std/dev/Makefile index f4f8f690f..6bdbbd997 100644 --- a/src/std/dev/Makefile +++ b/src/std/dev/Makefile @@ -31,6 +31,7 @@ dbRecStd_SRCS += devHistogramSoft.c dbRecStd_SRCS += devLiSoft.c dbRecStd_SRCS += devLoSoft.c dbRecStd_SRCS += devLsiSoft.c +dbRecStd_SRCS += devLsoSoft.c dbRecStd_SRCS += devMbbiDirectSoft.c dbRecStd_SRCS += devMbbiDirectSoftRaw.c dbRecStd_SRCS += devMbbiSoft.c @@ -57,14 +58,14 @@ dbRecStd_SRCS += devAoSoftCallback.c dbRecStd_SRCS += devBoSoftCallback.c dbRecStd_SRCS += devCalcoutSoftCallback.c dbRecStd_SRCS += devLoSoftCallback.c +dbRecStd_SRCS += devLsoSoftCallback.c dbRecStd_SRCS += devMbboSoftCallback.c dbRecStd_SRCS += devMbboDirectSoftCallback.c dbRecStd_SRCS += devPrintfSoftCallback.c dbRecStd_SRCS += devSoSoftCallback.c dbRecStd_SRCS += devTimestamp.c -dbRecStd_SRCS += devPrintfStdio.c -dbRecStd_SRCS += devSoStdio.c +dbRecStd_SRCS += devStdio.c dbRecStd_SRCS += asSubRecordFunctions.c diff --git a/src/std/dev/devLsoSoft.c b/src/std/dev/devLsoSoft.c new file mode 100644 index 000000000..02079a053 --- /dev/null +++ b/src/std/dev/devLsoSoft.c @@ -0,0 +1,26 @@ +/*************************************************************************\ +* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* Long String Output soft device support + * + * Author: Andrew Johnson + * Date: 2012-11-29 + */ + +#include "dbAccess.h" +#include "lsoRecord.h" +#include "epicsExport.h" + +static long write_string(lsoRecord *prec) +{ + return dbPutLinkLS(&prec->out, prec->val, prec->len); +} + +lsodset devLsoSoft = { + 5, NULL, NULL, NULL, NULL, write_string +}; +epicsExportAddress(dset, devLsoSoft); diff --git a/src/std/dev/devLsoSoftCallback.c b/src/std/dev/devLsoSoftCallback.c new file mode 100644 index 000000000..4ab7ead9d --- /dev/null +++ b/src/std/dev/devLsoSoftCallback.c @@ -0,0 +1,51 @@ +/*************************************************************************\ +* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* $Revision-Id$ */ +/* + * Author: Andrew Johnson + * Date: 30 Nov 2012 + */ + +#include "alarm.h" +#include "dbAccess.h" +#include "recGbl.h" +#include "lsoRecord.h" +#include "epicsExport.h" + +static long write_string(lsoRecord *prec) +{ + struct link *plink = &prec->out; + int dtyp = dbGetLinkDBFtype(plink); + long len = prec->len; + long status; + + if (prec->pact || dtyp < 0) + return 0; + + if (dtyp != DBR_CHAR && dtyp != DBF_UCHAR) { + dtyp = DBR_STRING; + len = 1; + } + + if (plink->type != CA_LINK) + return dbPutLink(plink, dtyp, prec->val, len); + + status = dbCaPutLinkCallback(plink, dtyp, prec->val, len, + dbCaCallbackProcess, plink); + if (status) { + recGblSetSevr(prec, LINK_ALARM, INVALID_ALARM); + return status; + } + + prec->pact = TRUE; + return 0; +} + +lsodset devLsoSoftCallback = { + 5, NULL, NULL, NULL, NULL, write_string +}; +epicsExportAddress(dset, devLsoSoftCallback); diff --git a/src/std/dev/devPrintfStdio.c b/src/std/dev/devPrintfStdio.c deleted file mode 100644 index bf14ed817..000000000 --- a/src/std/dev/devPrintfStdio.c +++ /dev/null @@ -1,105 +0,0 @@ -/*************************************************************************\ -* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne -* National Laboratory. -* EPICS BASE is distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. -\*************************************************************************/ - -/* $Revision-Id$ */ - -#include -#include - -#include "dbCommon.h" -#include "devSup.h" -#include "errlog.h" -#include "recGbl.h" -#include "recSup.h" -#include "printfRecord.h" -#include "epicsExport.h" - -typedef int (*PRINTFFUNC)(const char *fmt, ...); - -static int stderrPrintf(const char *fmt, ...); -static int logPrintf(const char *fmt, ...); - - -static struct outStream { - const char *name; - PRINTFFUNC print; -} outStreams[] = { - {"stdout", printf}, - {"stderr", stderrPrintf}, - {"errlog", logPrintf}, - {NULL, NULL} -}; - -static int stderrPrintf(const char *fmt, ...) { - va_list pvar; - int retval; - - va_start(pvar, fmt); - retval = vfprintf(stderr, fmt, pvar); - va_end (pvar); - - return retval; -} - -static int logPrintf(const char *fmt, ...) { - va_list pvar; - int retval; - - va_start(pvar, fmt); - retval = errlogVprintf(fmt, pvar); - va_end (pvar); - - return retval; -} - -static long add(dbCommon *pcommon) { - printfRecord *prec = (printfRecord *) pcommon; - struct outStream *pstream; - - if (prec->out.type != INST_IO) - return S_dev_badOutType; - - for (pstream = outStreams; pstream->name; ++pstream) { - if (strcmp(prec->out.value.instio.string, pstream->name) == 0) { - prec->dpvt = pstream; - return 0; - } - } - prec->dpvt = NULL; - return -1; -} - -static long del(dbCommon *pcommon) { - printfRecord *prec = (printfRecord *) pcommon; - - prec->dpvt = NULL; - return 0; -} - -static struct dsxt dsxtSoStdio = { - add, del -}; - -static long init(int pass) -{ - if (pass == 0) devExtend(&dsxtSoStdio); - return 0; -} - -static long write_string(printfRecord *prec) -{ - struct outStream *pstream = (struct outStream *)prec->dpvt; - if (pstream) - pstream->print("%s\n", prec->val); - return 0; -} - -/* Create the dset for devSoStdio */ -printfdset devPrintfStdio = { - 5, NULL, init, NULL, NULL, write_string -}; -epicsExportAddress(dset, devPrintfStdio); diff --git a/src/std/dev/devSoStdio.c b/src/std/dev/devSoStdio.c deleted file mode 100644 index e7a2f738a..000000000 --- a/src/std/dev/devSoStdio.c +++ /dev/null @@ -1,108 +0,0 @@ -/*************************************************************************\ -* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne -* National Laboratory. -* EPICS BASE is distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. -\*************************************************************************/ - -/* $Revision-Id$ */ - -#include -#include - -#include "dbCommon.h" -#include "devSup.h" -#include "errlog.h" -#include "recGbl.h" -#include "recSup.h" -#include "stringoutRecord.h" -#include "epicsExport.h" - -typedef int (*PRINTFFUNC)(const char *fmt, ...); - -static int stderrPrintf(const char *fmt, ...); -static int logPrintf(const char *fmt, ...); - - -static struct outStream { - const char *name; - PRINTFFUNC print; -} outStreams[] = { - {"stdout", printf}, - {"stderr", stderrPrintf}, - {"errlog", logPrintf}, - {NULL, NULL} -}; - -static int stderrPrintf(const char *fmt, ...) { - va_list pvar; - int retval; - - va_start(pvar, fmt); - retval = vfprintf(stderr, fmt, pvar); - va_end (pvar); - - return retval; -} - -static int logPrintf(const char *fmt, ...) { - va_list pvar; - int retval; - - va_start(pvar, fmt); - retval = errlogVprintf(fmt, pvar); - va_end (pvar); - - return retval; -} - -static long add(dbCommon *pcommon) { - stringoutRecord *prec = (stringoutRecord *) pcommon; - struct outStream *pstream; - - if (prec->out.type != INST_IO) - return S_dev_badOutType; - - for (pstream = outStreams; pstream->name; ++pstream) { - if (strcmp(prec->out.value.instio.string, pstream->name) == 0) { - prec->dpvt = pstream; - return 0; - } - } - prec->dpvt = NULL; - return -1; -} - -static long del(dbCommon *pcommon) { - stringoutRecord *prec = (stringoutRecord *) pcommon; - - prec->dpvt = NULL; - return 0; -} - -static struct dsxt dsxtSoStdio = { - add, del -}; - -static long init(int pass) -{ - if (pass == 0) devExtend(&dsxtSoStdio); - return 0; -} - -static long write_string(stringoutRecord *prec) -{ - struct outStream *pstream = (struct outStream *)prec->dpvt; - if (pstream) - pstream->print("%s\n", prec->val); - return 0; -} - -/* Create the dset for devSoStdio */ -static struct { - dset common; - DEVSUPFUN write; -} devSoStdio = { - {5, NULL, init, NULL, NULL}, write_string -}; -epicsExportAddress(dset, devSoStdio); diff --git a/src/std/dev/devSoft.dbd b/src/std/dev/devSoft.dbd index babad358a..d6cb14de9 100644 --- a/src/std/dev/devSoft.dbd +++ b/src/std/dev/devSoft.dbd @@ -10,6 +10,7 @@ device(histogram,CONSTANT,devHistogramSoft,"Soft Channel") device(longin,CONSTANT,devLiSoft,"Soft Channel") device(longout,CONSTANT,devLoSoft,"Soft Channel") device(lsi,CONSTANT,devLsiSoft,"Soft Channel") +device(lso,CONSTANT,devLsoSoft,"Soft Channel") device(mbbi,CONSTANT,devMbbiSoft,"Soft Channel") device(mbbiDirect,CONSTANT,devMbbiDirectSoft,"Soft Channel") device(mbbo,CONSTANT,devMbboSoft,"Soft Channel") @@ -36,6 +37,7 @@ device(bo,CONSTANT,devBoSoftCallback,"Async Soft Channel") device(calcout,CONSTANT,devCalcoutSoftCallback,"Async Soft Channel") device(longin,CONSTANT,devLiSoftCallback,"Async Soft Channel") device(longout,CONSTANT,devLoSoftCallback,"Async Soft Channel") +device(lso,CONSTANT,devLsoSoftCallback,"Async Soft Channel") device(mbbi,CONSTANT,devMbbiSoftCallback,"Async Soft Channel") device(mbbiDirect,CONSTANT,devMbbiDirectSoftCallback,"Async Soft Channel") device(mbbo,CONSTANT,devMbboSoftCallback,"Async Soft Channel") @@ -52,6 +54,7 @@ device(bo, INST_IO,devBoGeneralTime,"General Time") device(longin, INST_IO,devLiGeneralTime,"General Time") device(stringin,INST_IO,devSiGeneralTime,"General Time") +device(lso,INST_IO,devLsoStdio,"stdio") device(printf,INST_IO,devPrintfStdio,"stdio") device(stringout,INST_IO,devSoStdio,"stdio") diff --git a/src/std/dev/devStdio.c b/src/std/dev/devStdio.c new file mode 100644 index 000000000..a4ebd64e7 --- /dev/null +++ b/src/std/dev/devStdio.c @@ -0,0 +1,212 @@ +/*************************************************************************\ +* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* $Revision-Id$ */ + +#include +#include + +#include "dbCommon.h" +#include "devSup.h" +#include "errlog.h" +#include "recGbl.h" +#include "recSup.h" +#include "lsoRecord.h" +#include "printfRecord.h" +#include "stringoutRecord.h" +#include "epicsExport.h" + +typedef int (*PRINTFFUNC)(const char *fmt, ...); + +static int stderrPrintf(const char *fmt, ...); +static int logPrintf(const char *fmt, ...); + + +static struct outStream { + const char *name; + PRINTFFUNC print; +} outStreams[] = { + {"stdout", printf}, + {"stderr", stderrPrintf}, + {"errlog", logPrintf}, + {NULL, NULL} +}; + +static int stderrPrintf(const char *fmt, ...) { + va_list pvar; + int retval; + + va_start(pvar, fmt); + retval = vfprintf(stderr, fmt, pvar); + va_end (pvar); + + return retval; +} + +static int logPrintf(const char *fmt, ...) { + va_list pvar; + int retval; + + va_start(pvar, fmt); + retval = errlogVprintf(fmt, pvar); + va_end (pvar); + + return retval; +} + + +/* lso device support */ + +static long add_lso(dbCommon *pcommon) { + lsoRecord *prec = (lsoRecord *) pcommon; + struct outStream *pstream; + + if (prec->out.type != INST_IO) + return S_dev_badOutType; + + for (pstream = outStreams; pstream->name; ++pstream) { + if (strcmp(prec->out.value.instio.string, pstream->name) == 0) { + prec->dpvt = pstream; + return 0; + } + } + prec->dpvt = NULL; + return -1; +} + +static long del_lso(dbCommon *pcommon) { + lsoRecord *prec = (lsoRecord *) pcommon; + + prec->dpvt = NULL; + return 0; +} + +static struct dsxt dsxtLsoStdio = { + add_lso, del_lso +}; + +static long init_lso(int pass) +{ + if (pass == 0) devExtend(&dsxtLsoStdio); + return 0; +} + +static long write_lso(lsoRecord *prec) +{ + struct outStream *pstream = (struct outStream *)prec->dpvt; + if (pstream) + pstream->print("%s\n", prec->val); + return 0; +} + +lsodset devLsoStdio = { + 5, NULL, init_lso, NULL, NULL, write_lso +}; +epicsExportAddress(dset, devLsoStdio); + + +/* printf device support */ + +static long add_printf(dbCommon *pcommon) { + printfRecord *prec = (printfRecord *) pcommon; + struct outStream *pstream; + + if (prec->out.type != INST_IO) + return S_dev_badOutType; + + for (pstream = outStreams; pstream->name; ++pstream) { + if (strcmp(prec->out.value.instio.string, pstream->name) == 0) { + prec->dpvt = pstream; + return 0; + } + } + prec->dpvt = NULL; + return -1; +} + +static long del_printf(dbCommon *pcommon) { + printfRecord *prec = (printfRecord *) pcommon; + + prec->dpvt = NULL; + return 0; +} + +static struct dsxt dsxtPrintfStdio = { + add_printf, del_printf +}; + +static long init_printf(int pass) +{ + if (pass == 0) devExtend(&dsxtPrintfStdio); + return 0; +} + +static long write_printf(printfRecord *prec) +{ + struct outStream *pstream = (struct outStream *)prec->dpvt; + if (pstream) + pstream->print("%s\n", prec->val); + return 0; +} + +printfdset devPrintfStdio = { + 5, NULL, init_printf, NULL, NULL, write_printf +}; +epicsExportAddress(dset, devPrintfStdio); + + +/* stringout device support */ + +static long add_stringout(dbCommon *pcommon) { + stringoutRecord *prec = (stringoutRecord *) pcommon; + struct outStream *pstream; + + if (prec->out.type != INST_IO) + return S_dev_badOutType; + + for (pstream = outStreams; pstream->name; ++pstream) { + if (strcmp(prec->out.value.instio.string, pstream->name) == 0) { + prec->dpvt = pstream; + return 0; + } + } + prec->dpvt = NULL; + return -1; +} + +static long del_stringout(dbCommon *pcommon) { + stringoutRecord *prec = (stringoutRecord *) pcommon; + + prec->dpvt = NULL; + return 0; +} + +static struct dsxt dsxtSoStdio = { + add_stringout, del_stringout +}; + +static long init_stringout(int pass) +{ + if (pass == 0) devExtend(&dsxtSoStdio); + return 0; +} + +static long write_stringout(stringoutRecord *prec) +{ + struct outStream *pstream = (struct outStream *)prec->dpvt; + if (pstream) + pstream->print("%s\n", prec->val); + return 0; +} + +static struct { + dset common; + DEVSUPFUN write; +} devSoStdio = { + {5, NULL, init_stringout, NULL, NULL}, write_stringout +}; +epicsExportAddress(dset, devSoStdio);