The aSub record $(prefix):ARRAY:PARSE
processes input waveform $(prefix):ARRAY:1
that has 10 elements, generates an array of 20 elements, and writes it to output waveform $(prefix):ARRAY:2
.
1. In xxxApp/Db/
1.1 array.db
record(waveform, "$(prefix):ARRAY:1")
{
field(DESC, "Input array")
field(DTYP, "stream")
field(INP, "@array.proto read_int_array(read_array, $(prefix)) vs") # read array using protocol read_int_array
field(NELM, "10")
field(FTVL, "USHORT")
field(FLNK, "$(prefix):ARRAY:PARSE")
}
record(aSub, "$(prefix):ARRAY:PARSE")
{
field(SNAM, "arrayProc") # name of the processing function
field(INPA, "$(prefix):ARRAY:1 NPP NMS") # input record
field(FTA, "USHORT") # data type of elements in the input record
field(NOA, "10") # number of elements in the input record
field(OUTA, "$(prefix):ARRAY:2") # output record
field(FTVA, "USHORT") # data type of elements in the output record
field(NOVA, "20") # number of elements in the output record
}
record(waveform, "$(prefix):ARRAY:2")
{
field(NELM, "20")
field(FTVL, "USHORT")
}
1.2 Makefile
DB += array.db
2. In xxxApp/src/
2.1 arrayProc.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <registryFunction.h>
#include <aSubRecord.h>
#include <epicsExport.h>
#include <dbDefs.h>
#include <waveformRecord.h>
#include <dbAccess.h>
#include <dbFldTypes.h>
#include <epicsTime.h>
static long arrayProc(aSubRecord *prec)
{
unsigned short * data_raw = (unsigned short*)prec->a; // point to input record
unsigned short *data = (unsigned short*)prec->vala; // point to output record
DBLINK * plink;
DBADDR * paddr;
waveformRecord * pwf;
plink = &prec->outa;
if(DB_LINK != plink->type)
return -1;
paddr = (DBADDR*)plink->value.pv_link.pvt;
pwf = (waveformRecord *)paddr->precord;
pwf->nelm = 20;
for (int i=0; i<10; i++)
{
data[i] = 2 * data_raw[i];
data[i+10] = 3 * data_raw[i];
}
return 0;
}
epicsRegisterFunction(arrayProc);
2.2 arrayProc.h
extern long arrayProc(aSubRecord *prec);
2.3 array.dbd
function(arrayProc)
2.4 Makefile
...
maia_DBD += array.dbd
...
maia_SRCS += arrayProc.c
...