From edafb56273d4eb9fc6f49ae240fb36a714046cb6 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Wed, 30 Jul 2014 10:37:10 +0200 Subject: [PATCH] std/filters: make dbnd filter use recGblCheckDeadband() --- src/std/filters/dbnd.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/std/filters/dbnd.c b/src/std/filters/dbnd.c index 3147c088f..36c852b2b 100644 --- a/src/std/filters/dbnd.c +++ b/src/std/filters/dbnd.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -56,17 +57,11 @@ static int parse_ok(void *pvt) return 0; } -static void shiftval (myStruct *my, double val) { - my->last = val; - if (my->mode == 1) - my->hyst = val * my->cval/100.; -} - static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) { myStruct *my = (myStruct*) pvt; long status; - double val, delta; - short drop = 0; + double val; + unsigned send = 1; /* * Only scalar values supported - strings, arrays, and conversion errors @@ -81,19 +76,14 @@ static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) { status = dbFastGetConvertRoutine[pfl->field_type][DBR_DOUBLE] (localAddr.pfield, (void*) &val, &localAddr); if (!status) { - if (isnan(my->last)) { - shiftval(my, val); - } else { - delta = fabs(my->last - val); - if (delta <= my->hyst) { - drop = 1; - } else { - shiftval(my, val); - } + send = 0; + recGblCheckDeadband(&my->last, val, my->hyst, &send, 1); + if (send && my->mode == 1) { + my->hyst = val * my->cval/100.; } } } - if (drop) { + if (!send) { db_delete_field_log(pfl); return NULL; } else return pfl;