From 1ceb26eeb848843b81c5366175cc1a9810e05030 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 Apr 2020 12:13:28 -0700 Subject: [PATCH] add utag filter --- modules/database/src/std/filters/Makefile | 1 + .../database/src/std/filters/filters.dbd.pod | 2 + modules/database/src/std/filters/utag.c | 99 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 modules/database/src/std/filters/utag.c diff --git a/modules/database/src/std/filters/Makefile b/modules/database/src/std/filters/Makefile index ee6a0ae68..b02999403 100644 --- a/modules/database/src/std/filters/Makefile +++ b/modules/database/src/std/filters/Makefile @@ -16,6 +16,7 @@ dbRecStd_SRCS += dbnd.c dbRecStd_SRCS += arr.c dbRecStd_SRCS += sync.c dbRecStd_SRCS += decimate.c +dbRecStd_SRCS += utag.c HTMLS += filters.html diff --git a/modules/database/src/std/filters/filters.dbd.pod b/modules/database/src/std/filters/filters.dbd.pod index 27e356f83..ae43b3c2f 100644 --- a/modules/database/src/std/filters/filters.dbd.pod +++ b/modules/database/src/std/filters/filters.dbd.pod @@ -285,3 +285,5 @@ once every minute: ... =cut + +registrar(utagInitialize) diff --git a/modules/database/src/std/filters/utag.c b/modules/database/src/std/filters/utag.c new file mode 100644 index 000000000..4f19947d0 --- /dev/null +++ b/modules/database/src/std/filters/utag.c @@ -0,0 +1,99 @@ +/*************************************************************************\ +* Copyright (c) 2020 Michael Davidsaver +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +typedef struct { + epicsInt32 mask, value; + int first; +} utagPvt; + +static const +chfPluginArgDef opts[] = { + chfInt32(utagPvt, mask, "M", 0, 1), + chfInt32(utagPvt, value, "V", 0, 1), + chfPluginArgEnd +}; + +static void * allocPvt(void) +{ + utagPvt *pvt; + pvt = calloc(1, sizeof(utagPvt)); + pvt->mask = 0xffffffff; + return pvt; +} + +static void freePvt(void *pvt) +{ + free(pvt); +} + +static int parse_ok(void *raw) +{ + utagPvt *pvt = (utagPvt*)raw; + pvt->first = 1; + return 0; +} + +static db_field_log* filter(void* raw, dbChannel *chan, db_field_log *pfl) +{ + utagPvt *pvt = (utagPvt*)raw; + epicsInt32 utag = pfl->type==dbfl_type_rec ? dbChannelRecord(chan)->utag : pfl->utag; + int drop = (utag&pvt->mask)!=pvt->value; + + if(pfl->ctx!=dbfl_context_event || pfl->mask&DBE_PROPERTY) { + /* never drop for reads, or property events */ + + } else if(pvt->first) { + /* never drop first */ + pvt->first = 0; + + } else if(drop) { + db_delete_field_log(pfl); + pfl = NULL; + } + + return pfl; +} + +static void channelRegisterPre(dbChannel *chan, void *pvt, + chPostEventFunc **cb_out, void **arg_out, db_field_log *probe) +{ + *cb_out = filter; + *arg_out = pvt; +} + +static void channel_report(dbChannel *chan, void *raw, int level, const unsigned short indent) +{ + utagPvt *pvt = (utagPvt*)raw; + printf("%*sutag : mask=0x%08x value=0x%08x\n", indent, "", (epicsUInt32)pvt->mask, (epicsUInt32)pvt->value); +} + +static const +chfPluginIf pif = { + allocPvt, + freePvt, + NULL, /* parse_error */ + parse_ok, /* parse_ok */ + NULL, /* channel_open */ + channelRegisterPre, + NULL, /* channelRegisterPost */ + channel_report, + NULL, /* channel_close */ +}; + +static +void utagInitialize(void) +{ + chfPluginRegister("utag", &pif, opts); +} +epicsExportRegistrar(utagInitialize);