From e3f59fd5c291591863732062c10bce1c59a4fe87 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 12 Nov 2012 13:45:23 -0600 Subject: [PATCH] Support variable array size Added LEN field and get_array_info() routine. Removed len arg from device support write_string() routine. Modified device support to match. --- src/std/dev/devPrintfSoft.c | 4 ++-- src/std/dev/devPrintfSoftCallback.c | 3 ++- src/std/dev/devPrintfStdio.c | 2 +- src/std/rec/printfRecord.c | 21 +++++++++++++++------ src/std/rec/printfRecord.dbd | 4 ++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/std/dev/devPrintfSoft.c b/src/std/dev/devPrintfSoft.c index f88db01ec..4ed16ae15 100644 --- a/src/std/dev/devPrintfSoft.c +++ b/src/std/dev/devPrintfSoft.c @@ -14,7 +14,7 @@ #include "printfRecord.h" #include "epicsExport.h" -static long write_string(printfRecord *prec, size_t len) +static long write_string(printfRecord *prec) { struct link *plink = &prec->out; int dtyp = dbGetLinkDBFtype(plink); @@ -23,7 +23,7 @@ static long write_string(printfRecord *prec, size_t len) return 0; /* Not connected */ if (dtyp == DBR_CHAR || dtyp == DBF_UCHAR) - return dbPutLink(plink, dtyp, prec->val, len); + return dbPutLink(plink, dtyp, prec->val, prec->len); return dbPutLink(plink, DBR_STRING, prec->val, 1); } diff --git a/src/std/dev/devPrintfSoftCallback.c b/src/std/dev/devPrintfSoftCallback.c index 09eb2494d..7f9314d9e 100644 --- a/src/std/dev/devPrintfSoftCallback.c +++ b/src/std/dev/devPrintfSoftCallback.c @@ -16,10 +16,11 @@ #include "printfRecord.h" #include "epicsExport.h" -static long write_string(printfRecord *prec, size_t len) +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) diff --git a/src/std/dev/devPrintfStdio.c b/src/std/dev/devPrintfStdio.c index b109c750f..bf14ed817 100644 --- a/src/std/dev/devPrintfStdio.c +++ b/src/std/dev/devPrintfStdio.c @@ -90,7 +90,7 @@ static long init(int pass) return 0; } -static long write_string(printfRecord *prec, size_t len) +static long write_string(printfRecord *prec) { struct outStream *pstream = (struct outStream *)prec->dpvt; if (pstream) diff --git a/src/std/rec/printfRecord.c b/src/std/rec/printfRecord.c index 155df803c..5dfe557af 100644 --- a/src/std/rec/printfRecord.c +++ b/src/std/rec/printfRecord.c @@ -55,7 +55,7 @@ else \ flags |= F_BADLNK -static size_t doPrintf(printfRecord *prec) +static void doPrintf(printfRecord *prec) { const char *pfmt = prec->fmt; DBLINK *plink = &prec->inp0; @@ -288,7 +288,7 @@ static size_t doPrintf(printfRecord *prec) } } *pval++ = 0; /* Terminate the VAL string */ - return pval - prec->val; + prec->len = pval - prec->val; } @@ -327,13 +327,12 @@ static long init_record(printfRecord *prec, int pass) static long process(printfRecord *prec) { int pact = prec->pact; - size_t len = 0; printfdset *pdset; long status = 0; epicsUInt16 events; if (!pact) { - len = doPrintf(prec); + doPrintf(prec); prec->udf = FALSE; recGblGetTimeStamp(prec); @@ -344,7 +343,7 @@ static long process(printfRecord *prec) if (pdset && pdset->number >= 5 && pdset->write_string) { - status = pdset->write_string(prec, len); + status = pdset->write_string(prec); /* Asynchronous if device support set pact */ if (!pact && prec->pact) @@ -356,6 +355,7 @@ static long process(printfRecord *prec) /* Post monitor */ events = recGblResetAlarms(prec); db_post_events(prec, prec->val, events | DBE_VALUE | DBE_LOG); + db_post_events(prec, &prec->len, events | DBE_VALUE | DBE_LOG); /* Wrap up */ recGblFwdLink(prec); @@ -381,6 +381,15 @@ static long cvt_dbaddr(DBADDR *paddr) return 0; } +static long get_array_info(DBADDR *paddr, long *no_elements, long *offset) +{ + printfRecord *prec = (printfRecord *) paddr->precord; + + *no_elements = prec->len; + *offset = 0; + return 0; +} + /* Create Record Support Entry Table */ @@ -391,7 +400,7 @@ static long cvt_dbaddr(DBADDR *paddr) #define special NULL #define get_value NULL /* cvt_dbaddr */ -#define get_array_info NULL +/* get_array_info */ #define put_array_info NULL #define get_units NULL #define get_precision NULL diff --git a/src/std/rec/printfRecord.dbd b/src/std/rec/printfRecord.dbd index 2a1bf0be3..f45022f23 100644 --- a/src/std/rec/printfRecord.dbd +++ b/src/std/rec/printfRecord.dbd @@ -33,6 +33,10 @@ recordtype(printf) { interest(1) initial("41") } + field(LEN,DBF_ULONG) { + prompt("Length of VAL") + special(SPC_NOMOD) + } field(OUT,DBF_OUTLINK) { prompt("Output Specification") promptgroup(GUI_OUTPUT)