From 7bda1300849f9a28f488400a4069e09b3644b552 Mon Sep 17 00:00:00 2001 From: zimoch Date: Mon, 29 Aug 2011 15:12:57 +0000 Subject: [PATCH] new function to add scan rates to ioc --- Makefile | 1 + addScan.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ addScan.dbd | 1 + 3 files changed, 105 insertions(+) create mode 100644 addScan.c create mode 100644 addScan.dbd diff --git a/Makefile b/Makefile index 5d61202..fc48928 100644 --- a/Makefile +++ b/Makefile @@ -6,5 +6,6 @@ BUILDCLASSES += Linux SOURCES += require.c SOURCES += listRecords.c SOURCES += updateMenuConvert.c +SOURCES += addScan.c SOURCES_vxWorks += bootNotify.c SOURCES_vxWorks += iocCheck.c diff --git a/addScan.c b/addScan.c new file mode 100644 index 0000000..1ee14b1 --- /dev/null +++ b/addScan.c @@ -0,0 +1,103 @@ +/* addScan.c +* +* add a new scan rate to the ioc +* +* $Author: zimoch $ +* +* $Source: /cvs/G/DRV/misc/addScan.c,v $ +* +*/ + +#include +#include +#include +#include +#include +#include +#ifdef BASE_VERSION +#define EPICS_3_13 +extern DBBASE *pdbbase; +#else +#define EPICS_3_14 +#include +#include +#endif + + +int addScan (char* ratestr) +{ + dbMenu *menuScan; + int l, i, j, nChoice; + char **papChoiceName; + char **papChoiceValue; + double rate, r; + char dummy; + char *name; + + if (interruptAccept) + { + fprintf(stderr, "addScan: Can add a scan period only before iocInit!\n"); + return -1; + } + if (!ratestr || sscanf (ratestr, "%lf%c", &rate, &dummy) != 1 || rate <= 0) + { + fprintf(stderr, "addScan: Argument '%s' must be a number > 0\n", ratestr); + return -1; + } + menuScan = dbFindMenu(pdbbase,"menuScan"); + nChoice = menuScan->nChoice; + for (i=SCAN_1ST_PERIODIC; i < nChoice; i++) + { + r = strtod(menuScan->papChoiceValue[i], NULL); + if (r == rate) + { + fprintf(stderr, "addScan: rate %s already available\n", menuScan->papChoiceValue[i]); + return 0; + } + if (r < rate) break; + } + papChoiceName=dbCalloc(nChoice+1,sizeof(char*)); + papChoiceValue=dbCalloc(nChoice+1,sizeof(char*)); + for (j=0; j < i; j++) + { + papChoiceName[j] = menuScan->papChoiceName[j]; + papChoiceValue[j] = menuScan->papChoiceValue[j]; + } + name = ratestr; + while (name[0]=='0') name++; + l = strlen(name); + papChoiceValue[i] = dbCalloc(l+16,1); + strcpy(papChoiceValue[i], name); + strcpy(papChoiceValue[i]+l, " second"); + for (j=i; j < nChoice; j++) + { + papChoiceName[j+1] = menuScan->papChoiceName[j]; + papChoiceValue[j+1] = menuScan->papChoiceValue[j]; + } + free(menuScan->papChoiceName); + free(menuScan->papChoiceValue); + menuScan->papChoiceName=papChoiceName; + menuScan->papChoiceValue=papChoiceValue; + menuScan->nChoice = nChoice+1; + return 0; +} + +#ifdef EPICS_3_14 +static const iocshArg addScanArg0 = { "rate", iocshArgString }; +static const iocshArg * const addScanArgs[1] = { &addScanArg0 }; +static const iocshFuncDef addScanDef = { "addScan", 1, addScanArgs }; +static void addScanFunc (const iocshArgBuf *args) +{ + addScan(args[0].sval); +} +static void addScanRegister(void) +{ + static int firstTime = 1; + if (firstTime) { + iocshRegister (&addScanDef, addScanFunc); + firstTime = 0; + } +} +epicsExportRegistrar(addScanRegister); +#endif + diff --git a/addScan.dbd b/addScan.dbd new file mode 100644 index 0000000..147c8b0 --- /dev/null +++ b/addScan.dbd @@ -0,0 +1 @@ +registrar(addScanRegister)