Merged printf-record branch

Adds three new record types: printf, lsi and lso.
Provides device support for all three.
This commit is contained in:
Andrew Johnson
2013-10-03 14:04:03 -07:00
21 changed files with 1919 additions and 201 deletions

View File

@@ -30,6 +30,8 @@ dbRecStd_SRCS += devEventSoft.c
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
@@ -38,6 +40,7 @@ dbRecStd_SRCS += devMbboDirectSoft.c
dbRecStd_SRCS += devMbboDirectSoftRaw.c
dbRecStd_SRCS += devMbboSoft.c
dbRecStd_SRCS += devMbboSoftRaw.c
dbRecStd_SRCS += devPrintfSoft.c
dbRecStd_SRCS += devSASoft.c
dbRecStd_SRCS += devSiSoft.c
dbRecStd_SRCS += devSoSoft.c
@@ -55,12 +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 += devSoStdio.c
dbRecStd_SRCS += devStdio.c
dbRecStd_SRCS += asSubRecordFunctions.c

42
src/std/dev/devLsiSoft.c Normal file
View File

@@ -0,0 +1,42 @@
/*************************************************************************\
* 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 Input soft device support
*
* Author: Andrew Johnson
* Date: 2012-11-28
*/
#include "dbAccess.h"
#include "epicsTime.h"
#include "link.h"
#include "lsiRecord.h"
#include "epicsExport.h"
static long init_record(lsiRecord *prec)
{
dbLoadLinkLS(&prec->inp, prec->val, prec->sizv, &prec->len);
return 0;
}
static long read_string(lsiRecord *prec)
{
long status = dbGetLinkLS(&prec->inp, prec->val, prec->sizv, &prec->len);
if (!status &&
prec->tsel.type == CONSTANT &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(&prec->inp, &prec->time);
return status;
}
lsidset devLsiSoft = {
5, NULL, NULL, init_record, NULL, read_string
};
epicsExportAddress(dset, devLsiSoft);

26
src/std/dev/devLsoSoft.c Normal file
View File

@@ -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);

View File

@@ -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);

View File

@@ -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.
\*************************************************************************/
/* $Revision-Id$ */
/*
* Author: Andrew Johnson
* Date: 28 Sept 2012
*/
#include "dbAccess.h"
#include "printfRecord.h"
#include "epicsExport.h"
static long write_string(printfRecord *prec)
{
return dbPutLinkLS(&prec->out, prec->val, prec->len);
}
printfdset devPrintfSoft = {
5, NULL, NULL, NULL, NULL, write_string
};
epicsExportAddress(dset, devPrintfSoft);

View File

@@ -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: 28 Sept 2012
*/
#include "alarm.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "printfRecord.h"
#include "epicsExport.h"
static long write_string(printfRecord *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;
}
printfdset devPrintfSoftCallback = {
5, NULL, NULL, NULL, NULL, write_string
};
epicsExportAddress(dset, devPrintfSoftCallback);

View File

@@ -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 <stdio.h>
#include <string.h>
#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);

View File

@@ -9,10 +9,13 @@ device(event,CONSTANT,devEventSoft,"Soft Channel")
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")
device(mbboDirect,CONSTANT,devMbboDirectSoft,"Soft Channel")
device(printf,CONSTANT,devPrintfSoft,"Soft Channel")
device(stringin,CONSTANT,devSiSoft,"Soft Channel")
device(stringout,CONSTANT,devSoSoft,"Soft Channel")
device(subArray,CONSTANT,devSASoft,"Soft Channel")
@@ -34,10 +37,12 @@ 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")
device(mbboDirect,CONSTANT,devMbboDirectSoftCallback,"Async Soft Channel")
device(printf,CONSTANT,devPrintfSoftCallback,"Async Soft Channel")
device(stringin,CONSTANT,devSiSoftCallback,"Async Soft Channel")
device(stringout,CONSTANT,devSoSoftCallback,"Async Soft Channel")
@@ -49,6 +54,8 @@ 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")
device(bi, INST_IO, devBiDbState, "Db State")

212
src/std/dev/devStdio.c Normal file
View File

@@ -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 <stdio.h>
#include <string.h>
#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);