From 39ed279872880fe392db83c4208204037cbdd7f4 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Thu, 2 Mar 2000 19:14:35 +0000 Subject: [PATCH] cvtBpt.c moved from src/bpt to here --- src/db/Makefile | 1 + src/db/cvtBpt.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 src/db/cvtBpt.c diff --git a/src/db/Makefile b/src/db/Makefile index d5f822b8f..9e4239c3a 100644 --- a/src/db/Makefile +++ b/src/db/Makefile @@ -55,6 +55,7 @@ LIBSRCS += callback.c LIBSRCS += dbCa.c LIBSRCS += initHooks.c LIBSRCS += dbcar.c +LIBSRCS += cvtBpt.c OBJS_IOC += iocInit diff --git a/src/db/cvtBpt.c b/src/db/cvtBpt.c new file mode 100644 index 000000000..7a0c1d610 --- /dev/null +++ b/src/db/cvtBpt.c @@ -0,0 +1,168 @@ +/* $Id$ */ + +/* cvtBpt.c - Convert using breakpoint table + * + * Author: Marty Kraimer + * Date: 04OCT95 + * This is adaptation of old bldCvtTable + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * + * Modification Log: + * ----------------- + * 01 04OCT95 mrk Taken from old bldCvtTable + */ +#include +#include +#include + +#include "ellLib.h" +#include "dbBase.h" +#include "dbStaticLib.h" +#include "dbAccess.h" +#include "epicsPrint.h" + +#define epicsExportSharedSymbols +#include "cvtTable.h" + +static brkTable *findBrkTable(short linr) +{ + dbMenu *pdbMenu; + + pdbMenu = dbFindMenu(pdbbase,"menuConvert"); + if(!pdbMenu) { + epicsPrintf("findBrkTable: menuConvert does not exist\n"); + return(0); + } + if(linr<0 || linr>=pdbMenu->nChoice) { + epicsPrintf("findBrkTable linr %d but menuConvert has %d choices\n", + linr,pdbMenu->nChoice); + return(0); + } + return(dbFindBrkTable(pdbbase,pdbMenu->papChoiceValue[linr])); +} + +long epicsShareAPI cvtRawToEngBpt(double *pval,short linr,short init, void **ppbrk, + short *plbrk) +{ + double val=*pval; + long status=0; + brkTable *pbrkTable; + brkInt *pInt; + brkInt *pnxtInt; + short lbrk; + int number; + + + if(linr < 2) return(-1); + if(init==TRUE || *ppbrk == NULL) { /*must find breakpoint table*/ + pbrkTable = findBrkTable(linr); + if(!pbrkTable) return(S_dbLib_badField); + *ppbrk = (void *)pbrkTable; + /* Just start at the beginning */ + *plbrk=0; + } + pbrkTable = (struct brkTable *)*ppbrk; + number = pbrkTable->number; + lbrk = *plbrk; + /*make sure we dont go off end of table*/ + if( (lbrk+1) >= number ) lbrk--; + pInt = pbrkTable->papBrkInt[lbrk]; + pnxtInt = pbrkTable->papBrkInt[lbrk+1]; + /* find entry for increased value */ + while( (pnxtInt->raw) <= val ) { + lbrk++; + pInt = pbrkTable->papBrkInt[lbrk]; + if( lbrk >= number-1) { + status=1; + break; + } + pnxtInt = pbrkTable->papBrkInt[lbrk+1]; + } + while( (pInt->raw) > val) { + if(lbrk==0) { + status=1; + break; + } + lbrk--; + pInt = pbrkTable->papBrkInt[lbrk]; + } + *plbrk = lbrk; + *pval = pInt->eng + (val - pInt->raw) * pInt->slope; + return(status); +} + +long epicsShareAPI cvtEngToRawBpt(double *pval,short linr,short init, + void **ppbrk,short *plbrk) +{ + double val=*pval; + long status=0; + brkTable *pbrkTable; + brkInt *pInt; + brkInt *pnxtInt; + short lbrk; + int number; + + + if(linr < 2) return(-1); + if(init==TRUE || *ppbrk == NULL) { /*must find breakpoint table*/ + pbrkTable = findBrkTable(linr); + if(!pbrkTable) return(S_dbLib_badField); + *ppbrk = (void *)pbrkTable; + /* Just start at the beginning */ + *plbrk=0; + } + pbrkTable = (struct brkTable *)*ppbrk; + number = pbrkTable->number; + lbrk = *plbrk; + /*make sure we dont go off end of table*/ + if( (lbrk+1) >= number ) lbrk--; + pInt = pbrkTable->papBrkInt[lbrk]; + pnxtInt = pbrkTable->papBrkInt[lbrk+1]; + /* find entry for increased value */ + while( (pnxtInt->eng) <= val ) { + lbrk++; + pInt = pbrkTable->papBrkInt[lbrk]; + if( lbrk >= number-1) { + status=1; + break; + } + pnxtInt = pbrkTable->papBrkInt[lbrk+1]; + } + while( (pInt->eng) > val) { + if(lbrk==0) { + status=1; + break; + } + lbrk--; + pInt = pbrkTable->papBrkInt[lbrk]; + } + if(pInt->slope!=0){ + *plbrk = lbrk; + *pval = pInt->raw + (val - pInt->eng) / pInt->slope; + } + else { + return(status); + } + return(0); +}